Class: Fontisan::Models::SvgGlyph

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/fontisan/models/svg_glyph.rb

Overview

SVG glyph representation model

Represents an SVG document for a glyph or range of glyphs from the SVG table. Each SVG document can cover multiple glyph IDs and may be compressed.

This model uses lutaml-model for structured serialization to YAML/JSON/XML.

Examples:

Creating an SVG glyph

svg_glyph = SvgGlyph.new
svg_glyph.glyph_id = 100
svg_glyph.start_glyph_id = 100
svg_glyph.end_glyph_id = 105
svg_glyph.svg_content = '<svg>...</svg>'
svg_glyph.compressed = false

Serializing to JSON

json = svg_glyph.to_json
# {
#   "glyph_id": 100,
#   "start_glyph_id": 100,
#   "end_glyph_id": 105,
#   "svg_content": "<svg>...</svg>",
#   "compressed": false
# }

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#compressedBoolean

Returns Whether the original data was gzip compressed.

Returns:

  • (Boolean)

    Whether the original data was gzip compressed



50
# File 'lib/fontisan/models/svg_glyph.rb', line 50

attribute :compressed, :boolean, default: -> { false }

#end_glyph_idInteger

Returns Last glyph ID in range covered by this SVG.

Returns:

  • (Integer)

    Last glyph ID in range covered by this SVG



42
# File 'lib/fontisan/models/svg_glyph.rb', line 42

attribute :end_glyph_id, :integer

#glyph_idInteger

Returns Primary glyph ID (usually same as start_glyph_id).

Returns:

  • (Integer)

    Primary glyph ID (usually same as start_glyph_id)



34
# File 'lib/fontisan/models/svg_glyph.rb', line 34

attribute :glyph_id, :integer

#start_glyph_idInteger

Returns First glyph ID in range covered by this SVG.

Returns:

  • (Integer)

    First glyph ID in range covered by this SVG



38
# File 'lib/fontisan/models/svg_glyph.rb', line 38

attribute :start_glyph_id, :integer

#svg_contentString

Returns SVG XML content (decompressed).

Returns:

  • (String)

    SVG XML content (decompressed)



46
# File 'lib/fontisan/models/svg_glyph.rb', line 46

attribute :svg_content, :string

Instance Method Details

#covers_multiple_glyphs?Boolean

Check if this SVG covers multiple glyphs

Returns:

  • (Boolean)

    True if range includes more than one glyph



70
71
72
# File 'lib/fontisan/models/svg_glyph.rb', line 70

def covers_multiple_glyphs?
  start_glyph_id != end_glyph_id
end

#glyph_rangeRange

Get glyph IDs covered by this SVG document

Returns:

  • (Range)

    Range of glyph IDs



55
56
57
# File 'lib/fontisan/models/svg_glyph.rb', line 55

def glyph_range
  start_glyph_id..end_glyph_id
end

#has_content?Boolean

Check if SVG content is present

Returns:

  • (Boolean)

    True if svg_content is not nil or empty



84
85
86
# File 'lib/fontisan/models/svg_glyph.rb', line 84

def has_content?
  !svg_content.nil? && !svg_content.empty?
end

#includes_glyph?(glyph_id) ⇒ Boolean

Check if this SVG covers a specific glyph ID

Parameters:

  • glyph_id (Integer)

    Glyph ID to check

Returns:

  • (Boolean)

    True if glyph is in range



63
64
65
# File 'lib/fontisan/models/svg_glyph.rb', line 63

def includes_glyph?(glyph_id)
  glyph_range.include?(glyph_id)
end

#num_glyphsInteger

Get the number of glyphs covered by this SVG

Returns:

  • (Integer)

    Number of glyphs in range



77
78
79
# File 'lib/fontisan/models/svg_glyph.rb', line 77

def num_glyphs
  end_glyph_id - start_glyph_id + 1
end