Class: Arrolio::Font::TextEncoder
- Inherits:
-
Object
- Object
- Arrolio::Font::TextEncoder
- Defined in:
- lib/arrolio/font/text_encoder.rb
Overview
Converts a Unicode string into a 2-byte-big-endian glyph-ID sequence for an Identity-H-encoded CIDFont.
Instance Attribute Summary collapse
-
#embedder ⇒ Object
readonly
Returns the value of attribute embedder.
Instance Method Summary collapse
-
#encode(text) ⇒ Object
Returns a binary-encoded String of 2-byte GIDs for the codepoints in
text. -
#initialize(embedder) ⇒ TextEncoder
constructor
A new instance of TextEncoder.
Constructor Details
#initialize(embedder) ⇒ TextEncoder
Returns a new instance of TextEncoder.
10 11 12 |
# File 'lib/arrolio/font/text_encoder.rb', line 10 def initialize() @embedder = end |
Instance Attribute Details
#embedder ⇒ Object (readonly)
Returns the value of attribute embedder.
8 9 10 |
# File 'lib/arrolio/font/text_encoder.rb', line 8 def @embedder end |
Instance Method Details
#encode(text) ⇒ Object
Returns a binary-encoded String of 2-byte GIDs for the
codepoints in text. The renderer passes this to
canvas.text instead of the Unicode string.
17 18 19 20 21 22 23 24 25 |
# File 'lib/arrolio/font/text_encoder.rb', line 17 def encode(text) bytes = String.new.force_encoding(Encoding::BINARY) text.each_codepoint do |cp| gid = @embedder.subset_gid_for_codepoint(cp) bytes << (gid >> 8).chr(Encoding::BINARY) bytes << (gid & 0xff).chr(Encoding::BINARY) end bytes end |