This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
forked from prawnpdf/ttfunk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.rb
45 lines (33 loc) · 1.48 KB
/
example.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
$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, "ë")