From 09a9840ea178e36e4dbbefe9ba4d437eab39c3ae Mon Sep 17 00:00:00 2001 From: Cameron Dutro Date: Tue, 27 Dec 2022 21:42:33 -0800 Subject: [PATCH] Allow embedding Type1C fonts, i.e. fonts with a CFF table. --- lib/prawn/fonts/ttf.rb | 15 +++++++++++---- spec/prawn_manual_spec.rb | 10 +++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/prawn/fonts/ttf.rb b/lib/prawn/fonts/ttf.rb index 587093350..d20af429d 100644 --- a/lib/prawn/fonts/ttf.rb +++ b/lib/prawn/fonts/ttf.rb @@ -309,7 +309,6 @@ def embed(reference, subset) descriptor = @document.ref!( Type: :FontDescriptor, FontName: basename.to_sym, - FontFile2: fontfile, FontBBox: bbox, Flags: pdf_flags, StemV: stem_v, @@ -351,8 +350,8 @@ def embed(reference, subset) range_blocks = ranges.reduce(+'') do |s, list| s << format( - "%d beginbfchar\n%s\nendbfchar\n", - lenght: list.length, + "%d beginbfchar\n%s\nendbfchar\n", + length: list.length, list: list.join("\n") ) end @@ -364,7 +363,6 @@ def embed(reference, subset) cmap.stream.compress! reference.data.update( - Subtype: :TrueType, BaseFont: basename.to_sym, FontDescriptor: descriptor, FirstChar: 32, @@ -372,6 +370,15 @@ def embed(reference, subset) Widths: @document.ref!(widths), ToUnicode: cmap ) + + if font.cff.exists? + fontfile.data.update(Subtype: :Type1C) + reference.data.update(Subtype: :Type1) + descriptor.data.update(FontFile3: fontfile) + else + reference.data.update(Subtype: :TrueType) + descriptor.data.update(FontFile2: fontfile) + end end UNICODE_CMAP_TEMPLATE = <<-STR.strip.gsub(/^\s*/, '') diff --git a/spec/prawn_manual_spec.rb b/spec/prawn_manual_spec.rb index b8086e025..f79e57c12 100644 --- a/spec/prawn_manual_spec.rb +++ b/spec/prawn_manual_spec.rb @@ -6,18 +6,18 @@ MANUAL_HASH = case RUBY_ENGINE when 'ruby' - '79248d58f9d89e44081da875fa15ad9a70cc07e9eaa4e8b706001044a3570e3f'\ - 'bc4b5ba3e1150868d88add3a43972265219d4d11c60cbbc1bebf50e7d26cdb60' + '2caaa75cc4c48b790e43263b4912f66dec759719e8d06ca2ba5604d94ee5cf9f'\ + '947ced53e1187c1f8aa59e63942075dabb7426c7df079d8a8d030051061c751e' when 'jruby' - '22cf478cc5563cf0283d239ca5e87df44151fb422b5fd426c3aec47ca1df44fa'\ - '7b3826131d65cadad5430a05ee812000ae9f9419d6bc5ba4024fdf6a799fc184' + '191b6f5bc9f6419e3f7c126bb570b783e65a033d0581e16ed2219b436e05063e'\ + '9d4edd8c94f183bbb4ca2a298a6d31dc4d6ae7bef30052074aeb725e8cf75314' end RSpec.describe Prawn do describe 'manual' do # JRuby's zlib is a bit quirky. It sometimes produces different output to # libzlib (used by MRI). It's still a proper deflate stream and can be - # decompressed just fine but for whatever reason compressin produses + # decompressed just fine but for whatever reason compression produces # different output. # # See: https://github.com/jruby/jruby/issues/4244