Sha256: b084e5233e0b2420ae5029703c195c1095bd69b59309af8ed9e5f6a63ba02566

Contents?: true

Size: 1.57 KB

Versions: 24

Compression:

Stored size: 1.57 KB

Contents

module Processing


  # Font object.
  #
  class Font

    # @private
    def initialize(font)
      @font = font
    end

    # Returns bounding box.
    #
    # @overload textBounds(str)
    # @overload textBounds(str, x, y)
    # @overload textBounds(str, x, y, fontSize)
    #
    # @param str      [String]  text to calculate bounding box
    # @param x        [Numeric] horizontal position of bounding box
    # @param y        [Numeric] vertical position of bounding box
    # @param fontSize [Numeric] font size
    #
    # @return [TextBounds] bounding box for text
    #
    def textBounds(str, x = 0, y = 0, fontSize = nil)
      f = fontSize ? Rays::Font.new(@font.name, fontSize) : @font
      TextBounds.new x, y, x + f.width(str), y + f.height
    end

    # Returns a string containing a human-readable representation of object.
    #
    # @return [String] inspected text
    #
    def inspect()
      "#<Processing::Font: name:'#{@font.name}' size:#{@font.size}>"
    end

  end# Font


  # Bounding box for text.
  #
  class TextBounds

    # Horizontal position
    #
    attr_reader :x

    # Vertical position
    #
    attr_reader :y

    # Width of bounding box
    #
    attr_reader :w

    # Height of bounding box
    #
    attr_reader :h

    # @private
    def initialize(x, y, w, h)
      @x, @y, @w, @h = x, y, w, h
    end

    # Returns a string containing a human-readable representation of object.
    #
    # @return [String] inspected text
    #
    def inspect()
      "#<Processing::TextBounds: x:#{x} y:#{y} w:#{w} h:#{h}>"
    end

  end# TextBounds


end# Processing

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
processing-0.5.31 lib/processing/font.rb
processing-0.5.30 lib/processing/font.rb
processing-0.5.29 lib/processing/font.rb
processing-0.5.28 lib/processing/font.rb
processing-0.5.27 lib/processing/font.rb
processing-0.5.26 lib/processing/font.rb
processing-0.5.25 lib/processing/font.rb
processing-0.5.24 lib/processing/font.rb
processing-0.5.23 lib/processing/font.rb
processing-0.5.22 lib/processing/font.rb
processing-0.5.21 lib/processing/font.rb
processing-0.5.20 lib/processing/font.rb
processing-0.5.19 lib/processing/font.rb
processing-0.5.18 lib/processing/font.rb
processing-0.5.17 lib/processing/font.rb
processing-0.5.16 lib/processing/font.rb
processing-0.5.14 lib/processing/font.rb
processing-0.5.13 lib/processing/font.rb
processing-0.5.12 lib/processing/font.rb
processing-0.5.11 lib/processing/font.rb