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



197
198
199
# File 'lib/acrofill/metrics.rb', line 197

def ascender
  @ascender
end

#bbox_bottomObject

Returns the value of attribute bbox_bottom

Returns:

  • (Object)

    the current value of bbox_bottom



197
198
199
# File 'lib/acrofill/metrics.rb', line 197

def bbox_bottom
  @bbox_bottom
end

#bbox_topObject

Returns the value of attribute bbox_top

Returns:

  • (Object)

    the current value of bbox_top



197
198
199
# File 'lib/acrofill/metrics.rb', line 197

def bbox_top
  @bbox_top
end

#descenderObject

Returns the value of attribute descender

Returns:

  • (Object)

    the current value of descender



197
198
199
# File 'lib/acrofill/metrics.rb', line 197

def descender
  @descender
end

#remapObject

Returns the value of attribute remap

Returns:

  • (Object)

    the current value of remap



197
198
199
# File 'lib/acrofill/metrics.rb', line 197

def remap
  @remap
end

#widthsObject

Returns the value of attribute widths

Returns:

  • (Object)

    the current value of widths



197
198
199
# File 'lib/acrofill/metrics.rb', line 197

def widths
  @widths
end

Instance Method Details

#ascent(size) ⇒ Object



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

def ascent(size) = ascender * size / 1000.0

#descent(size) ⇒ Object



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

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

#encode(text) ⇒ Object

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



199
200
201
202
203
# File 'lib/acrofill/metrics.rb', line 199

def encode(text)
  return text unless remap

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

#line_height(size) ⇒ Object



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

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.



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

def top(size) = bbox_top * size / 1000.0