Class: Fontisan::Tables::Cff::PrivateDictWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/tables/cff/private_dict_writer.rb

Overview

Builds CFF Private DICT with hint parameters

Private DICT contains font-level hint information used for rendering quality. This writer validates hint parameters against CFF spec limits and serializes them into binary DICT format.

Supported hint parameters:

  • blue_values: Alignment zones (max 14 values, pairs)

  • other_blues: Additional zones (max 10 values, pairs)

  • family_blues: Family alignment zones (max 14 values, pairs)

  • family_other_blues: Family zones (max 10 values, pairs)

  • std_hw: Standard horizontal stem width

  • std_vw: Standard vertical stem width

  • stem_snap_h: Horizontal stem snap widths (max 12)

  • stem_snap_v: Vertical stem snap widths (max 12)

  • blue_scale, blue_shift, blue_fuzz: Overshoot parameters

  • force_bold: Bold flag

  • language_group: 0=Latin, 1=CJK

Constant Summary collapse

HINT_LIMITS =

CFF specification limits for hint parameters

{
  blue_values: { max: 14, pairs: true },
  other_blues: { max: 10, pairs: true },
  family_blues: { max: 14, pairs: true },
  family_other_blues: { max: 10, pairs: true },
  stem_snap_h: { max: 12 },
  stem_snap_v: { max: 12 },
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(source_dict = nil) ⇒ PrivateDictWriter

Initialize writer with optional source Private DICT

Parameters:

  • source_dict (PrivateDict, nil) (defaults to: nil)

    Source to copy non-hint params from



40
41
42
43
# File 'lib/fontisan/tables/cff/private_dict_writer.rb', line 40

def initialize(source_dict = nil)
  @params = {}
  parse_source(source_dict) if source_dict
end

Instance Method Details

#serializeString

Serialize to binary DICT format

Returns:

  • (String)

    Binary DICT data



57
58
59
# File 'lib/fontisan/tables/cff/private_dict_writer.rb', line 57

def serialize
  DictBuilder.build(@params)
end

#sizeInteger

Get serialized size in bytes

Returns:

  • (Integer)

    Size in bytes



64
65
66
# File 'lib/fontisan/tables/cff/private_dict_writer.rb', line 64

def size
  serialize.bytesize
end

#update_hints(hint_params) ⇒ Object

Update hint parameters

Parameters:

  • hint_params (Hash)

    Hint parameters to add/update

Raises:

  • (ArgumentError)

    If parameters are invalid



49
50
51
52
# File 'lib/fontisan/tables/cff/private_dict_writer.rb', line 49

def update_hints(hint_params)
  validate!(hint_params)
  @params.merge!(hint_params.transform_keys(&:to_sym))
end