Class: Ucode::Glyphs::EmbeddedFonts::ContentStreamCorrelator

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

Overview

Pillar 2 fallback: build a {codepoint => gid} map for a Type0 font whose PDF object graph has no /ToUnicode CMap stream.

Adapter for the mutool draw -F svg output format: parses <use> elements from the rendered PDF page SVG, partitions into labels and specimens by PDF font object ID (supplied via Config), then delegates matching to PositionalMatcher.

The SVG parsing (regex-based <use> extraction, HTML entity decoding) is the only piece of format-specific work here. The matching algorithm lives in PositionalMatcher and is shared with TraceCorrelator.

Defined Under Namespace

Classes: Config, Use

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ContentStreamCorrelator

Returns a new instance of ContentStreamCorrelator.

Parameters:



40
41
42
# File 'lib/ucode/glyphs/embedded_fonts/content_stream_correlator.rb', line 40

def initialize(config)
  @config = config
end

Instance Method Details

#correlate(svg) ⇒ Hash{Integer=>Integer}

Returns codepoint => gid. Empty if no clusters could be matched.

Parameters:

  • svg (String)

    rendered PDF page(s) as SVG markup. May contain multiple <svg> documents concatenated (one per page); the regex scan handles either case.

Returns:

  • (Hash{Integer=>Integer})

    codepoint => gid. Empty if no clusters could be matched.



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ucode/glyphs/embedded_fonts/content_stream_correlator.rb', line 49

def correlate(svg)
  uses = parse_uses(svg)
  return {} if uses.empty?

  labels, specimens = partition_uses(uses)
  return {} if labels.empty? || specimens.empty?

  PositionalMatcher.match(
    specimens.map { |u| to_position(u) },
    labels.map { |u| to_position(u) },
  )
end