Class: Ucode::Glyphs::EmbeddedFonts::Source
- Inherits:
-
Object
- Object
- Ucode::Glyphs::EmbeddedFonts::Source
- Defined in:
- lib/ucode/glyphs/embedded_fonts/source.rb
Overview
Locates the Code Charts PDF on disk and the directory where extracted font streams are cached.
PDF resolution order (first match wins):
1. Explicit `pdf:` argument.
2. `UCODE_CODE_CHARTS_PDF` environment variable.
3. Conventional `<gem_root>/CodeCharts.pdf`.
Per-block PDFs (preferred for incremental runs) can be supplied via the ‘pdf:` argument by the caller — typically the CLI.
Cache resolution order:
1. Explicit `cache_dir:` argument.
2. `UCODE_PDF_FONT_CACHE` environment variable.
3. Conventional `<gem_root>/data/pdf-fonts/`.
The cache holds one file per embedded font program, named after the BaseFont (e.g. ‘CIAIIP+Uni2000Generalpunctuation.ttf`). Re-runs skip extraction when the cached file is newer than the PDF.
Instance Attribute Summary collapse
-
#cache_dir ⇒ Object
readonly
Returns the value of attribute cache_dir.
-
#pdf_path ⇒ Object
readonly
Returns the value of attribute pdf_path.
Instance Method Summary collapse
-
#font_cache_path(base_font, extension) ⇒ Pathname
Cache path for the named font.
-
#initialize(pdf: nil, cache_dir: nil, env: ENV, gem_root: nil) ⇒ Source
constructor
A new instance of Source.
-
#pdf_to_s ⇒ String
Absolute path to the PDF, suitable for shelling out to ‘mutool`.
Constructor Details
#initialize(pdf: nil, cache_dir: nil, env: ENV, gem_root: nil) ⇒ Source
Returns a new instance of Source.
42 43 44 45 46 47 48 49 |
# File 'lib/ucode/glyphs/embedded_fonts/source.rb', line 42 def initialize(pdf: nil, cache_dir: nil, env: ENV, gem_root: nil) @pdf_path = resolve_pdf(pdf, env, gem_root) raise Ucode::EmbeddedFontsMissingError, "Code Charts PDF not found at #{@pdf_path}" unless @pdf_path&.exist? @cache_dir = resolve_cache(cache_dir, env, gem_root) @cache_dir.mkpath unless @cache_dir.exist? end |
Instance Attribute Details
#cache_dir ⇒ Object (readonly)
Returns the value of attribute cache_dir.
33 34 35 |
# File 'lib/ucode/glyphs/embedded_fonts/source.rb', line 33 def cache_dir @cache_dir end |
#pdf_path ⇒ Object (readonly)
Returns the value of attribute pdf_path.
33 34 35 |
# File 'lib/ucode/glyphs/embedded_fonts/source.rb', line 33 def pdf_path @pdf_path end |
Instance Method Details
#font_cache_path(base_font, extension) ⇒ Pathname
Returns cache path for the named font.
60 61 62 |
# File 'lib/ucode/glyphs/embedded_fonts/source.rb', line 60 def font_cache_path(base_font, extension) @cache_dir.join("#{base_font}#{extension}") end |
#pdf_to_s ⇒ String
Returns absolute path to the PDF, suitable for shelling out to ‘mutool`.
53 54 55 |
# File 'lib/ucode/glyphs/embedded_fonts/source.rb', line 53 def pdf_to_s @pdf_path.to_s end |