Class: Fontisan::Optimizers::PatternAnalyzer::Pattern

Inherits:
Struct
  • Object
show all
Defined in:
lib/fontisan/optimizers/pattern_analyzer.rb

Overview

Pattern data structure representing a repeated CharString sequence

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bytesObject

Returns the value of attribute bytes

Returns:

  • (Object)

    the current value of bytes



27
28
29
# File 'lib/fontisan/optimizers/pattern_analyzer.rb', line 27

def bytes
  @bytes
end

#frequencyObject

Returns the value of attribute frequency

Returns:

  • (Object)

    the current value of frequency



27
28
29
# File 'lib/fontisan/optimizers/pattern_analyzer.rb', line 27

def frequency
  @frequency
end

#glyphsObject

Returns the value of attribute glyphs

Returns:

  • (Object)

    the current value of glyphs



27
28
29
# File 'lib/fontisan/optimizers/pattern_analyzer.rb', line 27

def glyphs
  @glyphs
end

#lengthObject

Returns the value of attribute length

Returns:

  • (Object)

    the current value of length



27
28
29
# File 'lib/fontisan/optimizers/pattern_analyzer.rb', line 27

def length
  @length
end

#positionsObject

Returns the value of attribute positions

Returns:

  • (Object)

    the current value of positions



27
28
29
# File 'lib/fontisan/optimizers/pattern_analyzer.rb', line 27

def positions
  @positions
end

#savingsObject

Returns the value of attribute savings

Returns:

  • (Object)

    the current value of savings



27
28
29
# File 'lib/fontisan/optimizers/pattern_analyzer.rb', line 27

def savings
  @savings
end

#stack_neutralObject

Returns the value of attribute stack_neutral

Returns:

  • (Object)

    the current value of stack_neutral



27
28
29
# File 'lib/fontisan/optimizers/pattern_analyzer.rb', line 27

def stack_neutral
  @stack_neutral
end

Instance Method Details

#call_overheadInteger

Calculate overhead for calling this pattern as a subroutine

Returns:

  • (Integer)

    byte overhead (callsubr + number + return)



38
39
40
# File 'lib/fontisan/optimizers/pattern_analyzer.rb', line 38

def call_overhead
  1 + number_size(frequency) + 1 # callsubr + number + return
end

#number_size(num) ⇒ Integer

Calculate CFF integer encoding size

Parameters:

  • n (Integer)

    number to encode

Returns:

  • (Integer)

    byte size of encoded number



45
46
47
48
49
50
51
# File 'lib/fontisan/optimizers/pattern_analyzer.rb', line 45

def number_size(num)
  return 1 if num >= -107 && num <= 107
  return 2 if num >= -1131 && num <= 1131
  return 3 if num >= -32768 && num <= 32767

  5
end