Sha256: 7bf64306f155a5ae95e382269e2a3d449b5f65f881b5ac661f9ab99873d1bb07

Contents?: true

Size: 1.48 KB

Versions: 26

Compression:

Stored size: 1.48 KB

Contents

$LOAD_PATH << "#{File.dirname(__FILE__)}/lib"
require "ttfunk"

def character_lookup(file, character)
  puts "character     : #{character}"

  character_code = character.unpack("U*").first
  puts "character code: #{character_code}"

  glyph_id = file.cmap.unicode.first[character_code]
  puts "glyph id      : #{glyph_id}"

  glyph = file.glyph_outlines.for(glyph_id)
  puts "glyph type    : %s" % glyph.class.name.split(/::/).last.downcase
  puts "glyph size    : %db" % glyph.raw.length
  puts "glyph bbox    : (%d,%d)-(%d,%d)" % [glyph.x_min, glyph.y_min, glyph.x_max, glyph.y_max]

  if glyph.compound?
    puts "components    : %d %s" % [glyph.glyph_ids.length, glyph.glyph_ids.inspect]
  end
end

file = TTFunk::File.open(ARGV.first || "data/fonts/DejaVuSans.ttf")

puts "-- FONT ------------------------------------"

puts "revision  : %08x" % file.header.font_revision
puts "name      : #{file.name.font_name.join(', ')}"
puts "family    : #{file.name.font_family.join(', ')}"
puts "subfamily : #{file.name.font_subfamily.join(', ')}"
puts "postscript: #{file.name.postscript_name}"

puts "-- FONT METRICS ----------------------------"

puts "units/em  : #{file.header.units_per_em}"
puts "ascent    : #{file.ascent}"
puts "descent   : #{file.descent}"
puts "line gap  : #{file.line_gap}"
puts "bbox      : (%d,%d)-(%d,%d)" % file.bbox

puts "-- SIMPLE CHARACTER -> GLYPH LOOKUP --------"
character_lookup(file, "\xE2\x98\x9C")

puts "-- COMPOUND CHARACTER -> GLYPH LOOKUP ------"
character_lookup(file, "ë")

Version data entries

26 entries across 26 versions & 9 rubygems

Version Path
davebenvenuti-prawn-0.11.1.pre vendor/ttfunk/example.rb
piglop-prawn-0.10.2.3 vendor/ttfunk/example.rb
piglop-prawn-0.10.2.2 vendor/ttfunk/example.rb
piglop-prawn-0.10.2.1 vendor/ttfunk/example.rb
glyph_imager-0.1.1 vendor/ttfunk/example.rb
prawn-0.11.1.pre vendor/ttfunk/example.rb
goodwill-prawn-edge-0.10.0 vendor/ttfunk/example.rb
alphasights-prawn-0.10.4 vendor/ttfunk/example.rb
alphasights-prawn-0.10.3 vendor/ttfunk/example.rb
alphasights-prawn-0.10.2 vendor/ttfunk/example.rb
alphasights-prawn-0.10.1 vendor/ttfunk/example.rb
glyph_imager-0.1.0 vendor/ttfunk/example.rb
prawn-core-0.8.4 vendor/ttfunk/example.rb
prawn-graph-0.0.2 vendor/prawn-core/vendor/ttfunk/example.rb
prawn-graph-0.0.1 vendor/prawn-core/vendor/ttfunk/example.rb
prawn-core-0.7.2 vendor/ttfunk/example.rb
prawn-core-0.7.1 vendor/ttfunk/example.rb
prawn-layout-0.3.2 vendor/prawn-core/vendor/ttfunk/example.rb
prawn-core-0.6.3 vendor/ttfunk/example.rb
prawn-core-0.6.2 vendor/ttfunk/example.rb