Class: Ucode::Glyphs::EmbeddedFonts::TraceGlyph

Inherits:
Struct
  • Object
show all
Defined in:
lib/ucode/glyphs/embedded_fonts/trace_glyph.rb

Overview

Value object for one glyph emitted by mutool trace.

Each <g> element in the trace XML maps to one TraceGlyph:

The font_name is inherited from the enclosing <span>:


  

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#font_nameObject

Returns the value of attribute font_name

Returns:

  • (Object)

    the current value of font_name



27
28
29
# File 'lib/ucode/glyphs/embedded_fonts/trace_glyph.rb', line 27

def font_name
  @font_name
end

#gidObject

Returns the value of attribute gid

Returns:

  • (Object)

    the current value of gid



27
28
29
# File 'lib/ucode/glyphs/embedded_fonts/trace_glyph.rb', line 27

def gid
  @gid
end

#unicodeObject

Returns the value of attribute unicode

Returns:

  • (Object)

    the current value of unicode



27
28
29
# File 'lib/ucode/glyphs/embedded_fonts/trace_glyph.rb', line 27

def unicode
  @unicode
end

#xObject

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



27
28
29
# File 'lib/ucode/glyphs/embedded_fonts/trace_glyph.rb', line 27

def x
  @x
end

#yObject

Returns the value of attribute y

Returns:

  • (Object)

    the current value of y



27
28
29
# File 'lib/ucode/glyphs/embedded_fonts/trace_glyph.rb', line 27

def y
  @y
end

Class Method Details

.name_match?(a, b) ⇒ Boolean

True when a and b resolve to the same normalized name. Treats nil as never matching (avoids accidental collision on missing names).

Parameters:

  • a (String, nil)
  • b (String, nil)

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/ucode/glyphs/embedded_fonts/trace_glyph.rb', line 52

def name_match?(a, b)
  return false if a.nil? || b.nil?

  normalize_name(a) == normalize_name(b)
end

.normalize_name(name) ⇒ String?

Returns the name truncated to the trace limit.

Parameters:

  • name (String, nil)

    a BaseFont name from mutool info or a trace-emitted font name

Returns:

  • (String, nil)

    the name truncated to the trace limit



39
40
41
42
43
# File 'lib/ucode/glyphs/embedded_fonts/trace_glyph.rb', line 39

def normalize_name(name)
  return nil if name.nil?

  name.length <= TRACE_NAME_LIMIT ? name : name[0, TRACE_NAME_LIMIT]
end