Class: Fontisan::Models::BitmapGlyph

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

Overview

Bitmap glyph representation model

Represents a bitmap glyph from the CBDT/CBLC tables. Each glyph contains bitmap image data at a specific ppem size.

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

Examples:

Creating a bitmap glyph

glyph = BitmapGlyph.new
glyph.glyph_id = 42
glyph.ppem = 16
glyph.format = "PNG"
glyph.width = 16
glyph.height = 16
glyph.data_size = 256

Serializing to JSON

json = glyph.to_json
# {
#   "glyph_id": 42,
#   "ppem": 16,
#   "format": "PNG",
#   "width": 16,
#   "height": 16,
#   "data_size": 256
# }

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bit_depthInteger

Returns Bit depth (1, 2, 4, 8, 32).

Returns:

  • (Integer)

    Bit depth (1, 2, 4, 8, 32)



56
# File 'lib/fontisan/models/bitmap_glyph.rb', line 56

attribute :bit_depth, :integer

#data_offsetInteger

Returns Offset to bitmap data in CBDT table.

Returns:

  • (Integer)

    Offset to bitmap data in CBDT table



64
# File 'lib/fontisan/models/bitmap_glyph.rb', line 64

attribute :data_offset, :integer

#data_sizeInteger

Returns Size of bitmap data in bytes.

Returns:

  • (Integer)

    Size of bitmap data in bytes



60
# File 'lib/fontisan/models/bitmap_glyph.rb', line 60

attribute :data_size, :integer

#formatString

Returns Bitmap format (e.g., “PNG”, “JPEG”, “TIFF”).

Returns:

  • (String)

    Bitmap format (e.g., “PNG”, “JPEG”, “TIFF”)



44
# File 'lib/fontisan/models/bitmap_glyph.rb', line 44

attribute :format, :string

#glyph_idInteger

Returns Glyph ID.

Returns:

  • (Integer)

    Glyph ID



36
# File 'lib/fontisan/models/bitmap_glyph.rb', line 36

attribute :glyph_id, :integer

#heightInteger

Returns Bitmap height in pixels.

Returns:

  • (Integer)

    Bitmap height in pixels



52
# File 'lib/fontisan/models/bitmap_glyph.rb', line 52

attribute :height, :integer

#ppemInteger

Returns Pixels per em for this bitmap.

Returns:

  • (Integer)

    Pixels per em for this bitmap



40
# File 'lib/fontisan/models/bitmap_glyph.rb', line 40

attribute :ppem, :integer

#widthInteger

Returns Bitmap width in pixels.

Returns:

  • (Integer)

    Bitmap width in pixels



48
# File 'lib/fontisan/models/bitmap_glyph.rb', line 48

attribute :width, :integer

Instance Method Details

#color?Boolean

Check if this is a color bitmap (32-bit)

Returns:

  • (Boolean)

    True if 32-bit color



90
91
92
# File 'lib/fontisan/models/bitmap_glyph.rb', line 90

def color?
  bit_depth == 32
end

#color_depthString

Get the color depth description

Returns:

  • (String)

    Human-readable color depth



104
105
106
107
108
109
110
111
112
113
# File 'lib/fontisan/models/bitmap_glyph.rb', line 104

def color_depth
  case bit_depth
  when 1 then "1-bit (monochrome)"
  when 2 then "2-bit (4 colors)"
  when 4 then "4-bit (16 colors)"
  when 8 then "8-bit (256 colors)"
  when 32 then "32-bit (full color with alpha)"
  else "#{bit_depth}-bit"
  end
end

#dimensionsString

Get bitmap dimensions as string

Returns:

  • (String)

    Dimensions in “WxH” format



118
119
120
# File 'lib/fontisan/models/bitmap_glyph.rb', line 118

def dimensions
  "#{width}x#{height}"
end

#jpeg?Boolean

Check if this is a JPEG bitmap

Returns:

  • (Boolean)

    True if format is JPEG



76
77
78
# File 'lib/fontisan/models/bitmap_glyph.rb', line 76

def jpeg?
  format&.upcase == "JPEG"
end

#monochrome?Boolean

Check if this is a monochrome bitmap (1-bit)

Returns:

  • (Boolean)

    True if 1-bit monochrome



97
98
99
# File 'lib/fontisan/models/bitmap_glyph.rb', line 97

def monochrome?
  bit_depth == 1
end

#png?Boolean

Check if this is a PNG bitmap

Returns:

  • (Boolean)

    True if format is PNG



69
70
71
# File 'lib/fontisan/models/bitmap_glyph.rb', line 69

def png?
  format&.upcase == "PNG"
end

#tiff?Boolean

Check if this is a TIFF bitmap

Returns:

  • (Boolean)

    True if format is TIFF



83
84
85
# File 'lib/fontisan/models/bitmap_glyph.rb', line 83

def tiff?
  format&.upcase == "TIFF"
end