Class: TTFunk::Table::Cff::Charstring
- Inherits:
-
Object
- Object
- TTFunk::Table::Cff::Charstring
- Defined in:
- lib/ttfunk/table/cff/charstring.rb
Overview
CFF Charstring.
Constant Summary collapse
- CODE_MAP =
Type 2 charstring operators
{ 1 => :hstem, 3 => :vstem, 4 => :vmoveto, 5 => :rlineto, 6 => :hlineto, 7 => :vlineto, 8 => :rrcurveto, 10 => :callsubr, 12 => :flex_select, 14 => :endchar, 18 => :hstemhm, 19 => :hintmask, 20 => :cntrmask, 21 => :rmoveto, 22 => :hmoveto, 23 => :vstemhm, 24 => :rcurveline, 25 => :rlinecurve, 26 => :vvcurveto, 27 => :hhcurveto, 28 => :shortint, 29 => :callgsubr, 30 => :vhcurveto, 31 => :hvcurveto, }.freeze
- FLEX_CODE_MAP =
Type 2 Flex operators.
{ 35 => :flex, 34 => :hflex, 36 => :hflex1, 37 => :flex1, }.freeze
Instance Attribute Summary collapse
-
#glyph_id ⇒ Integer
readonly
Glyph ID.
-
#raw ⇒ String
readonly
Encoded charstring.
Instance Method Summary collapse
-
#glyph ⇒ TTFunk::Table::Glyf::PathBased
Get a TrueType-compatible glyph representation of this charstring.
-
#initialize(glyph_id, top_dict, font_dict, raw) ⇒ Charstring
constructor
A new instance of Charstring.
-
#path ⇒ TTFunk::Table::Cff::Path
Get path representation of this charstring.
-
#render(x: 0, y: 0, font_size: 72) ⇒ TTFunk::Table::Cff::Path
Get path representation of this charstring at the specified font size.
Constructor Details
#initialize(glyph_id, top_dict, font_dict, raw) ⇒ Charstring
Returns a new instance of Charstring.
Source Code
lib/ttfunk/table/cff/charstring.rb, line 56
56 | def initialize(glyph_id, top_dict, font_dict, raw) |
57 | @glyph_id = glyph_id |
58 | @top_dict = top_dict |
59 | @font_dict = font_dict |
60 | @raw = raw |
61 | |
62 | default_width_x = (@font_dict || @top_dict).private_dict.default_width_x |
63 | |
64 | @nominal_width_x = (@font_dict || @top_dict).private_dict.nominal_width_x |
65 | |
66 | @subrs = (@font_dict || @top_dict).private_dict.subr_index |
67 | @gsubrs = @top_dict.cff.global_subr_index |
68 | @subrs_bias = @subrs.bias if @subrs |
69 | @gsubrs_bias = @gsubrs.bias if @gsubrs |
70 | |
71 | @stack = [] |
72 | @data = raw.bytes |
73 | @index = 0 |
74 | @n_stems = 0 |
75 | @have_width = false |
76 | @open = false |
77 | @width = default_width_x |
78 | @x = 0 |
79 | @y = 0 |
80 | end
|
Instance Attribute Details
#glyph_id ⇒ Integer (readonly)
Glyph ID.
Source Code
lib/ttfunk/table/cff/charstring.rb, line 46
46 | def glyph_id |
47 | @glyph_id
|
48 | end
|
#raw ⇒ String (readonly)
Encoded charstring.
Source Code
lib/ttfunk/table/cff/charstring.rb, line 50
50 | def raw |
51 | @raw
|
52 | end
|
Instance Method Details
#glyph ⇒ TTFunk::Table::Glyf::PathBased
Get a TrueType-compatible glyph representation of this charstring.
Source Code
lib/ttfunk/table/cff/charstring.rb, line 96
96 | def glyph |
97 | @glyph ||= |
98 | begin
|
99 | horizontal_metrics = @top_dict.file.horizontal_metrics.for(glyph_id) |
100 | Glyf::PathBased.new(path, horizontal_metrics) |
101 | end
|
102 | end
|
#path ⇒ TTFunk::Table::Cff::Path
Get path representation of this charstring.
Source Code
lib/ttfunk/table/cff/charstring.rb, line 85
85 | def path |
86 | @path || begin |
87 | @path = Path.new |
88 | parse!
|
89 | @path
|
90 | end
|
91 | end
|
#render(x: 0, y: 0, font_size: 72) ⇒ TTFunk::Table::Cff::Path
Get path representation of this charstring at the specified font size.
Source Code
lib/ttfunk/table/cff/charstring.rb, line 110
110 | def render(x: 0, y: 0, font_size: 72) |
111 | path.render( |
112 | x: x, |
113 | y: y, |
114 | font_size: font_size, |
115 | units_per_em: @top_dict.file.header.units_per_em, |
116 | )
|
117 | end
|