Class: Ucode::Glyphs::EmbeddedFonts::FontEntry
- Inherits:
-
Object
- Object
- Ucode::Glyphs::EmbeddedFonts::FontEntry
- Defined in:
- lib/ucode/glyphs/embedded_fonts/font_entry.rb
Overview
Value object describing one Type0 font discovered in the Code Charts PDF, plus lazy accessors for its outline data.
A FontEntry is constructed by Catalog during the PDF walk and is the unit of work for the renderer. Each entry owns:
* identity — `base_font` name, font dict object number
* stream refs — object numbers of the FontDescriptor's
FontFile2 (TrueType) / FontFile3 (CFF) and the ToUnicode CMap
* `cid_to_gid_map` — `:identity` (gid == cid) or `:stream`
(we'd need to parse a separate map; not currently supported)
* `codepoint_to_gid` — the per-font map built from the parsed
ToUnicode CMap. Frozen.
The fontisan accessor is built lazily on first #accessor call, and the font program is extracted to the Source cache directory at the same point. Subsequent calls reuse the cached file unless the PDF is newer than the cache.
Instance Attribute Summary collapse
-
#base_font ⇒ Object
readonly
Returns the value of attribute base_font.
-
#cid_to_gid_map ⇒ Object
readonly
Returns the value of attribute cid_to_gid_map.
-
#codepoint_to_gid ⇒ Object
readonly
Returns the value of attribute codepoint_to_gid.
-
#font_obj_id ⇒ Object
readonly
Returns the value of attribute font_obj_id.
-
#fontfile_kind ⇒ Object
readonly
Returns the value of attribute fontfile_kind.
-
#fontfile_obj_id ⇒ Object
readonly
Returns the value of attribute fontfile_obj_id.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#tounicode_obj_id ⇒ Object
readonly
Returns the value of attribute tounicode_obj_id.
Instance Method Summary collapse
-
#accessor ⇒ Fontisan::GlyphAccessor
Lazy: extracts the font program to the cache (if missing or stale) and loads it via fontisan.
-
#cache_path ⇒ Pathname
Where the extracted font stream is cached.
-
#codepoints ⇒ Array<Integer>
Codepoints covered by this font.
-
#fontfile_extension ⇒ String
“.ttf” or “.cff” — cache file extension.
-
#gid_for(codepoint) ⇒ Integer?
GID for the codepoint in this font, or nil if the codepoint isn’t covered.
-
#initialize(base_font:, font_obj_id:, fontfile_obj_id:, fontfile_kind:, tounicode_obj_id:, cid_to_gid_map:, codepoint_to_gid:, source:) ⇒ FontEntry
constructor
A new instance of FontEntry.
-
#reset_accessor! ⇒ void
Force-clear the cached accessor and fontisan state.
Constructor Details
#initialize(base_font:, font_obj_id:, fontfile_obj_id:, fontfile_kind:, tounicode_obj_id:, cid_to_gid_map:, codepoint_to_gid:, source:) ⇒ FontEntry
Returns a new instance of FontEntry.
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ucode/glyphs/embedded_fonts/font_entry.rb', line 44 def initialize(base_font:, font_obj_id:, fontfile_obj_id:, fontfile_kind:, tounicode_obj_id:, cid_to_gid_map:, codepoint_to_gid:, source:) @base_font = base_font @font_obj_id = font_obj_id @fontfile_obj_id = fontfile_obj_id @fontfile_kind = fontfile_kind @tounicode_obj_id = tounicode_obj_id @cid_to_gid_map = cid_to_gid_map @codepoint_to_gid = codepoint_to_gid @source = source @accessor = nil end |
Instance Attribute Details
#base_font ⇒ Object (readonly)
Returns the value of attribute base_font.
32 33 34 |
# File 'lib/ucode/glyphs/embedded_fonts/font_entry.rb', line 32 def base_font @base_font end |
#cid_to_gid_map ⇒ Object (readonly)
Returns the value of attribute cid_to_gid_map.
32 33 34 |
# File 'lib/ucode/glyphs/embedded_fonts/font_entry.rb', line 32 def cid_to_gid_map @cid_to_gid_map end |
#codepoint_to_gid ⇒ Object (readonly)
Returns the value of attribute codepoint_to_gid.
32 33 34 |
# File 'lib/ucode/glyphs/embedded_fonts/font_entry.rb', line 32 def codepoint_to_gid @codepoint_to_gid end |
#font_obj_id ⇒ Object (readonly)
Returns the value of attribute font_obj_id.
32 33 34 |
# File 'lib/ucode/glyphs/embedded_fonts/font_entry.rb', line 32 def font_obj_id @font_obj_id end |
#fontfile_kind ⇒ Object (readonly)
Returns the value of attribute fontfile_kind.
32 33 34 |
# File 'lib/ucode/glyphs/embedded_fonts/font_entry.rb', line 32 def fontfile_kind @fontfile_kind end |
#fontfile_obj_id ⇒ Object (readonly)
Returns the value of attribute fontfile_obj_id.
32 33 34 |
# File 'lib/ucode/glyphs/embedded_fonts/font_entry.rb', line 32 def fontfile_obj_id @fontfile_obj_id end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
32 33 34 |
# File 'lib/ucode/glyphs/embedded_fonts/font_entry.rb', line 32 def source @source end |
#tounicode_obj_id ⇒ Object (readonly)
Returns the value of attribute tounicode_obj_id.
32 33 34 |
# File 'lib/ucode/glyphs/embedded_fonts/font_entry.rb', line 32 def tounicode_obj_id @tounicode_obj_id end |
Instance Method Details
#accessor ⇒ Fontisan::GlyphAccessor
Lazy: extracts the font program to the cache (if missing or stale) and loads it via fontisan. Memoized per FontEntry.
84 85 86 |
# File 'lib/ucode/glyphs/embedded_fonts/font_entry.rb', line 84 def accessor @accessor ||= build_accessor end |
#cache_path ⇒ Pathname
Returns where the extracted font stream is cached.
76 77 78 |
# File 'lib/ucode/glyphs/embedded_fonts/font_entry.rb', line 76 def cache_path @source.font_cache_path(@base_font, fontfile_extension) end |
#codepoints ⇒ Array<Integer>
Returns codepoints covered by this font.
66 67 68 |
# File 'lib/ucode/glyphs/embedded_fonts/font_entry.rb', line 66 def codepoints @codepoint_to_gid.keys end |
#fontfile_extension ⇒ String
Returns “.ttf” or “.cff” — cache file extension.
71 72 73 |
# File 'lib/ucode/glyphs/embedded_fonts/font_entry.rb', line 71 def fontfile_extension @fontfile_kind == :ttf ? ".ttf" : ".cff" end |
#gid_for(codepoint) ⇒ Integer?
Returns GID for the codepoint in this font, or nil if the codepoint isn’t covered.
61 62 63 |
# File 'lib/ucode/glyphs/embedded_fonts/font_entry.rb', line 61 def gid_for(codepoint) @codepoint_to_gid[codepoint] end |
#reset_accessor! ⇒ void
This method returns an undefined value.
Force-clear the cached accessor and fontisan state. Useful in long-running processes that walk many fonts.
92 93 94 |
# File 'lib/ucode/glyphs/embedded_fonts/font_entry.rb', line 92 def reset_accessor! @accessor = nil end |