Class: TTFunk::Table::Glyf::PathBased

Inherits:
Object
  • Object
show all
Defined in:
lib/ttfunk/table/glyf/path_based.rb

Overview

TrueType-compatible representation of a CFF glyph.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, horizontal_metrics) ⇒ PathBased

Returns a new instance of PathBased.

Parameters:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ttfunk/table/glyf/path_based.rb', line 42

def initialize(path, horizontal_metrics)
  @path = path
  @horizontal_metrics = horizontal_metrics

  @x_min = 0
  @y_min = 0
  @x_max = horizontal_metrics.advance_width
  @y_max = 0

  path.commands.each do |command|
    cmd, x, y = command
    next if cmd == :close

    @x_min = x if x < @x_min
    @x_max = x if x > @x_max
    @y_min = y if y < @y_min
    @y_max = y if y > @y_max
  end

  @left_side_bearing = horizontal_metrics.left_side_bearing
  @right_side_bearing =
    horizontal_metrics.advance_width -
    @left_side_bearing -
    (@x_max - @x_min)
end

Instance Attribute Details

#horizontal_metricsTTFunk::Table::Hmtx::HorizontalMetric (readonly)

Glyph horizontal metrics.



14
15
16
# File 'lib/ttfunk/table/glyf/path_based.rb', line 14

def horizontal_metrics
  @horizontal_metrics
end

#left_side_bearingInteger, Float (readonly)

Left side bearing.

Returns:

  • (Integer, Float)


34
35
36
# File 'lib/ttfunk/table/glyf/path_based.rb', line 34

def left_side_bearing
  @left_side_bearing
end

#pathTTFunk::Table::Cff::Path (readonly)

Glyph outline.



10
11
12
# File 'lib/ttfunk/table/glyf/path_based.rb', line 10

def path
  @path
end

#right_side_bearingInteger, Float (readonly)

Rigth side bearing.

Returns:

  • (Integer, Float)


38
39
40
# File 'lib/ttfunk/table/glyf/path_based.rb', line 38

def right_side_bearing
  @right_side_bearing
end

#x_maxInteger, Float (readonly)

Maximum X.

Returns:

  • (Integer, Float)


26
27
28
# File 'lib/ttfunk/table/glyf/path_based.rb', line 26

def x_max
  @x_max
end

#x_minInteger, Float (readonly)

Minimum X.

Returns:

  • (Integer, Float)


18
19
20
# File 'lib/ttfunk/table/glyf/path_based.rb', line 18

def x_min
  @x_min
end

#y_maxInteger, Float (readonly)

Maximum Y.

Returns:

  • (Integer, Float)


30
31
32
# File 'lib/ttfunk/table/glyf/path_based.rb', line 30

def y_max
  @y_max
end

#y_minInteger, Float (readonly)

Minimum Y.

Returns:

  • (Integer, Float)


22
23
24
# File 'lib/ttfunk/table/glyf/path_based.rb', line 22

def y_min
  @y_min
end

Instance Method Details

#compound?false

Is this glyph compound?

Returns:

  • (false)


78
79
80
# File 'lib/ttfunk/table/glyf/path_based.rb', line 78

def compound?
  false
end

#number_of_contoursInteger

Number of contour.

Returns:

  • (Integer)


71
72
73
# File 'lib/ttfunk/table/glyf/path_based.rb', line 71

def number_of_contours
  path.number_of_contours
end