Class: TTFunk::Table::Cff::Charstring

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(glyph_id, top_dict, font_dict, raw) ⇒ Charstring

Returns a new instance of Charstring.

Parameters:

  • glyph_id (Integer)
  • top_dict (TTFunk::Table:Cff::TopDict)
  • font_dict (TTFunk::Table:Cff::FontDict)
  • raw (String)
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_idInteger (readonly)

Glyph ID.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/cff/charstring.rb, line 46
46
def glyph_id
47
  @glyph_id
48
end

#rawString (readonly)

Encoded charstring.

Returns:

  • (String)
Source Code
lib/ttfunk/table/cff/charstring.rb, line 50
50
def raw
51
  @raw
52
end

Instance Method Details

#glyphTTFunk::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

#pathTTFunk::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.

Parameters:

  • x (Integer, Float) (defaults to: 0)

    new horizontal position.

  • y (Integer, Float) (defaults to: 0)

    new vertical position.

  • font_size (Integer, Float) (defaults to: 72)

    font size.

Returns:

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