diff --git a/spec/prawn/font_spec.rb b/spec/prawn/font_spec.rb index a890c907e..39326c3bf 100644 --- a/spec/prawn/font_spec.rb +++ b/spec/prawn/font_spec.rb @@ -670,4 +670,42 @@ def page_should_not_include_font(font) font_name = text.font_settings.first[:name].to_s.sub(/\w+\+/, 'subset+') expect(font_name).to eq 'subset+DustismoRoman' end + + it 'does not change width of unknown glyph' do + text_with_string_widths = Class.new(PDF::Inspector::Text) do + attr_reader :string_widths + + def initialize(*) + super + @string_widths = [] + end + + def show_text text, kerned = false + super + @string_widths << ((@state.current_font.unpack text).reduce(0) do |width, code| + width + (@state.current_font.glyph_width code) * @font_settings[-1][:size] / 1000.0 + end) + end + end + + pdf = Prawn::Document.new do + font_families.update( + 'DejaVu Sans' => { + normal: "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf", + bold: "#{Prawn::DATADIR}/fonts/DejaVuSans-Bold.ttf" + }, + ) + + # changing option to subset: false fixes issue (albeit using different behavior) + font 'DejaVu Sans', subset: true do + text '日本語end', inline_format: true + end + end + + rendered_pdf = pdf.render + #File.write '/tmp/debug.pdf', rendered_pdf + analyzed_pdf = text_with_string_widths.analyze(rendered_pdf) + expect(analyzed_pdf.string_widths.length).to eql(2) + expect(analyzed_pdf.string_widths[0]).to be > 0.0 + end end