Class: Pdfrb::FontLoader::Type3
- Inherits:
-
Object
- Object
- Pdfrb::FontLoader::Type3
- Defined in:
- lib/pdfrb/font_loader/type3.rb
Overview
Type3 font loader. Type3 fonts define glyphs as PDF drawing procedures (content streams) rather than outlines. Used for custom symbol sets and pixel-art fonts.
Each glyph is a (name, width, procedure) triple where the procedure is a content stream drawing in a 1000x1000 glyph grid. The loader emits a /Type /Font /Subtype /Type3 font dict with /CharProcs mapping glyph names to streams.
Defined Under Namespace
Classes: GlyphSpec
Instance Attribute Summary collapse
-
#bounding_box ⇒ Object
readonly
Returns the value of attribute bounding_box.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#glyphs ⇒ Object
readonly
Returns the value of attribute glyphs.
-
#matrix ⇒ Object
readonly
Returns the value of attribute matrix.
Instance Method Summary collapse
-
#build ⇒ Object
Build and return the Type3 font dictionary.
-
#initialize(document:, glyphs:, bounding_box:, matrix: nil) ⇒ Type3
constructor
A new instance of Type3.
Constructor Details
#initialize(document:, glyphs:, bounding_box:, matrix: nil) ⇒ Type3
Returns a new instance of Type3.
23 24 25 26 27 28 |
# File 'lib/pdfrb/font_loader/type3.rb', line 23 def initialize(document:, glyphs:, bounding_box:, matrix: nil) @document = document @glyphs = glyphs @bounding_box = bounding_box @matrix = matrix || [0.001, 0, 0, 0.001, 0, 0] end |
Instance Attribute Details
#bounding_box ⇒ Object (readonly)
Returns the value of attribute bounding_box.
16 17 18 |
# File 'lib/pdfrb/font_loader/type3.rb', line 16 def bounding_box @bounding_box end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
16 17 18 |
# File 'lib/pdfrb/font_loader/type3.rb', line 16 def document @document end |
#glyphs ⇒ Object (readonly)
Returns the value of attribute glyphs.
16 17 18 |
# File 'lib/pdfrb/font_loader/type3.rb', line 16 def glyphs @glyphs end |
#matrix ⇒ Object (readonly)
Returns the value of attribute matrix.
16 17 18 |
# File 'lib/pdfrb/font_loader/type3.rb', line 16 def matrix @matrix end |
Instance Method Details
#build ⇒ Object
Build and return the Type3 font dictionary. Each glyph procedure becomes an indirect stream object referenced from /CharProcs.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/pdfrb/font_loader/type3.rb', line 33 def build char_procs = {} widths = [] encoding = { Type: :Encoding, Differences: [] } glyphs.each_with_index do |glyph, i| code = 32 + i stream = document.add({ Length: glyph.procedure.bytesize }, type: Pdfrb::Model::Cos::Stream) stream.stream = glyph.procedure char_procs[glyph.name.to_sym] = Pdfrb::Model::Reference.new(stream.oid, stream.gen) widths[code] = glyph.width encoding[:Differences] << code << glyph.name.to_sym end document.add( { Type: :Font, Subtype: :Type3, FontBBox: bounding_box, FontMatrix: matrix, CharProcs: char_procs, Encoding: encoding, FirstChar: 32, LastChar: 31 + glyphs.length, Widths: widths, }, type: Pdfrb::Model::Type::Font ) end |