Class: Acrofill::Metrics::Font

Inherits:
Struct
  • Object
show all
Defined in:
lib/acrofill/metrics.rb

Overview

Everything the appearance code needs about one resolved face. remap is a 256-entry code translation table, or nil when the font draws WinAnsi codes as they are.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ascenderObject

Returns the value of attribute ascender

Returns:

  • (Object)

    the current value of ascender



202
203
204
# File 'lib/acrofill/metrics.rb', line 202

def ascender
  @ascender
end

#bbox_bottomObject

Returns the value of attribute bbox_bottom

Returns:

  • (Object)

    the current value of bbox_bottom



202
203
204
# File 'lib/acrofill/metrics.rb', line 202

def bbox_bottom
  @bbox_bottom
end

#bbox_topObject

Returns the value of attribute bbox_top

Returns:

  • (Object)

    the current value of bbox_top



202
203
204
# File 'lib/acrofill/metrics.rb', line 202

def bbox_top
  @bbox_top
end

#code_widthsObject

Returns the value of attribute code_widths

Returns:

  • (Object)

    the current value of code_widths



202
203
204
# File 'lib/acrofill/metrics.rb', line 202

def code_widths
  @code_widths
end

#descenderObject

Returns the value of attribute descender

Returns:

  • (Object)

    the current value of descender



202
203
204
# File 'lib/acrofill/metrics.rb', line 202

def descender
  @descender
end

#remapObject

Returns the value of attribute remap

Returns:

  • (Object)

    the current value of remap



202
203
204
# File 'lib/acrofill/metrics.rb', line 202

def remap
  @remap
end

#widthsObject

Returns the value of attribute widths

Returns:

  • (Object)

    the current value of widths



202
203
204
# File 'lib/acrofill/metrics.rb', line 202

def widths
  @widths
end

Instance Method Details

#ascent(size) ⇒ Object



217
# File 'lib/acrofill/metrics.rb', line 217

def ascent(size) = ascender * size / 1000.0

#descent(size) ⇒ Object



219
# File 'lib/acrofill/metrics.rb', line 219

def descent(size) = -descender * size / 1000.0

#encode(text) ⇒ Object

Windows-1252 text as the byte codes this font draws it with.



205
206
207
208
209
# File 'lib/acrofill/metrics.rb', line 205

def encode(text)
  return text unless remap

  text.b.each_byte.map { |code| remap[code] }.pack('C*')
end

#line_height(size) ⇒ Object



224
# File 'lib/acrofill/metrics.rb', line 224

def line_height(size) = (bbox_top - bbox_bottom) * size / 1000.0

#top(size) ⇒ Object

Distance from the box top to the first baseline, and between rows.



222
# File 'lib/acrofill/metrics.rb', line 222

def top(size) = bbox_top * size / 1000.0

#width_of(text, size) ⇒ Object

Width of text at size points, in points. text is in this font's own codes (the output of #encode), so it is measured in that space.



213
214
215
# File 'lib/acrofill/metrics.rb', line 213

def width_of(text, size)
  Metrics.string_width(text, code_widths, size)
end