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.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ttfunk/table/cff/charstring.rb', line 56 def initialize(glyph_id, top_dict, font_dict, raw) @glyph_id = glyph_id @top_dict = top_dict @font_dict = font_dict @raw = raw default_width_x = (@font_dict || @top_dict).private_dict.default_width_x @nominal_width_x = (@font_dict || @top_dict).private_dict.nominal_width_x @subrs = (@font_dict || @top_dict).private_dict.subr_index @gsubrs = @top_dict.cff.global_subr_index @subrs_bias = @subrs.bias if @subrs @gsubrs_bias = @gsubrs.bias if @gsubrs @stack = [] @data = raw.bytes @index = 0 @n_stems = 0 @have_width = false @open = false @width = default_width_x @x = 0 @y = 0 end |
Instance Attribute Details
#glyph_id ⇒ Integer (readonly)
Glyph ID.
46 47 48 |
# File 'lib/ttfunk/table/cff/charstring.rb', line 46 def glyph_id @glyph_id end |
#raw ⇒ String (readonly)
Encoded charstring.
50 51 52 |
# File 'lib/ttfunk/table/cff/charstring.rb', line 50 def raw @raw end |
Instance Method Details
#glyph ⇒ TTFunk::Table::Glyf::PathBased
Get a TrueType-compatible glyph representation of this charstring.
96 97 98 99 100 101 102 |
# File 'lib/ttfunk/table/cff/charstring.rb', line 96 def glyph @glyph ||= begin horizontal_metrics = @top_dict.file.horizontal_metrics.for(glyph_id) Glyf::PathBased.new(path, horizontal_metrics) end end |
#path ⇒ TTFunk::Table::Cff::Path
Get path representation of this charstring.
85 86 87 88 89 90 91 |
# File 'lib/ttfunk/table/cff/charstring.rb', line 85 def path @path || begin @path = Path.new parse! @path end end |
#render(x: 0, y: 0, font_size: 72) ⇒ TTFunk::Table::Cff::Path
Get path representation of this charstring at the specified font size.
110 111 112 113 114 115 116 117 |
# File 'lib/ttfunk/table/cff/charstring.rb', line 110 def render(x: 0, y: 0, font_size: 72) path.render( x: x, y: y, font_size: font_size, units_per_em: @top_dict.file.header.units_per_em, ) end |