Class: Fontisan::Type1::TTFToType1Converter
- Inherits:
-
Object
- Object
- Fontisan::Type1::TTFToType1Converter
- Defined in:
- lib/fontisan/type1/ttf_to_type1_converter.rb
Overview
TTF to Type 1 CharString Converter
[‘TTFToType1Converter`](lib/fontisan/type1/ttf_to_type1_converter.rb) converts TrueType glyphs to Type 1 CharStrings.
The conversion involves:
-
Converting quadratic curves (TrueType) to cubic curves (Type 1)
-
Scaling coordinates if needed
-
Generating Type 1 CharString commands
Constant Summary collapse
- HSTEM =
Type 1 CharString command codes
1- VSTEM =
3- VMOVETO =
4- RLINETO =
5- HLINETO =
6- VLINETO =
7- RRCURVETO =
8- CLOSEPATH =
9- CALLSUBR =
10- RETURN =
11- ESCAPE =
12- HSBW =
13- ENDCHAR =
14- RMOVETO =
21- HMOVETO =
22- VHCURVETO =
30- HVCURVETO =
31
Class Method Summary collapse
-
.convert(font, scaler, encoding) ⇒ Hash<Integer, String>
Convert TTF font to Type 1 CharStrings.
Instance Method Summary collapse
-
#convert ⇒ Hash<Integer, String>
Convert all glyphs to CharStrings.
-
#initialize(font, scaler, encoding) ⇒ TTFToType1Converter
constructor
A new instance of TTFToType1Converter.
Constructor Details
#initialize(font, scaler, encoding) ⇒ TTFToType1Converter
Returns a new instance of TTFToType1Converter.
51 52 53 54 55 56 |
# File 'lib/fontisan/type1/ttf_to_type1_converter.rb', line 51 def initialize(font, scaler, encoding) @font = font @scaler = scaler @encoding = encoding @charstrings = {} end |
Class Method Details
.convert(font, scaler, encoding) ⇒ Hash<Integer, String>
Convert TTF font to Type 1 CharStrings
47 48 49 |
# File 'lib/fontisan/type1/ttf_to_type1_converter.rb', line 47 def self.convert(font, scaler, encoding) new(font, scaler, encoding).convert end |
Instance Method Details
#convert ⇒ Hash<Integer, String>
Convert all glyphs to CharStrings
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/fontisan/type1/ttf_to_type1_converter.rb', line 61 def convert glyf_table = @font.table(Constants::GLYF_TAG) return {} unless glyf_table loca_table = @font.table(Constants::LOCA_TAG) head_table = @font.table(Constants::HEAD_TAG) maxp = @font.table(Constants::MAXP_TAG) num_glyphs = maxp&.num_glyphs || 0 num_glyphs.times do |gid| @charstrings[gid] = convert_glyph(glyf_table, loca_table, head_table, gid) end @charstrings end |