Module: Ucode::Glyphs::EmbeddedFonts::TraceParser

Defined in:
lib/ucode/glyphs/embedded_fonts/trace_parser.rb

Overview

Parses the XML output of mutool trace <pdf> <page> into an array of TraceGlyph instances.

The trace XML uses a flat <span font="..."><g glyph="..." x="..." y="..." unicode="..."/> structure. Nokogiri walks the tree; the parser maps each <g> to a TraceGlyph, inheriting the font_name from the enclosing span.

Pure function — no I/O, no PDF access. Callers inject the XML string (typically from TraceRunner).

Class Method Summary collapse

Class Method Details

.parse(xml) ⇒ Array<TraceGlyph>

Returns one per <g> element; empty if the XML is empty or has no <g> elements.

Parameters:

  • xml (String)

    raw mutool trace XML

Returns:

  • (Array<TraceGlyph>)

    one per <g> element; empty if the XML is empty or has no <g> elements



23
24
25
26
27
28
# File 'lib/ucode/glyphs/embedded_fonts/trace_parser.rb', line 23

def parse(xml)
  return [] if xml.nil? || xml.strip.empty?

  doc = Nokogiri::XML(xml)
  doc.css("span").flat_map { |span| glyphs_in_span(span) }
end