Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Really, really odd behaviour...? #972

Closed
Siyfion opened this issue Aug 9, 2016 · 26 comments
Closed

Really, really odd behaviour...? #972

Siyfion opened this issue Aug 9, 2016 · 26 comments

Comments

@Siyfion
Copy link

Siyfion commented Aug 9, 2016

I've created a label for print with some text and tables, etc. (Attached)

But there is a load of information at the bottom of the page (which if you try to select, you can see positionally) that simply does not appear at all.

I've opened up the PDF in Acrobat and if I so much as change one little thing, all of it then re-renders correctly (I assume Acrobat is "fixing" the issue on save)...

@practicingruby / @packetmonkey Any idea's would be great! As I'm currently a bit stuck helping a customer until I can understand this better!

uni309_YAPzvqyWS7Ek5BPFL_20160809-125327.pdf

@Siyfion
Copy link
Author

Siyfion commented Oct 20, 2016

And another odd one for you... Using a Google Font, renders some bits fine, others, not...

If you highlight the text, copy & paste it's all there, so it's a rendering / PDF issue rather than a data issue.

pla005_rXard8Sudm56Fwmhh_20161020-151229.pdf

@Siyfion
Copy link
Author

Siyfion commented Oct 20, 2016

@packetmonkey I could really use some help in figuring this out, otherwise I may have to switch away from Prawn, which I really don't want to do!

@pointlessone
Copy link
Member

Prawn does font subsetting as an optimization to keep your documents small. You may want to try and trace if it does it properly with your font. The code is in TTFunk gem. I don't have other ideas at the moment.

@Siyfion
Copy link
Author

Siyfion commented Oct 20, 2016

@pointlessone Thanks for the words of wisdom, I'll try to take a look, clearly something's gone nuts.

@Siyfion
Copy link
Author

Siyfion commented Oct 20, 2016

@pointlessone As a quick and dirty fix, is there a way to turn subsetting off?!

@pointlessone
Copy link
Member

@Siyfion I'm afraid, no. IIRC, it's not a removal of unused glyphs but rather import of the used ones. You may hack TTF to include all glyphs, or maybe even just use original font file instead of generating a subset. But I don't think there's a way to just turn subsetting off.

@Siyfion
Copy link
Author

Siyfion commented Oct 20, 2016

Damn. Well it's this font: https://fonts.google.com/specimen/Taviraj?selection.family=Taviraj

Is there a way to use font's in a pdf that can be retrieved from a url? Like a CSS import?

@pointlessone
Copy link
Member

Technically, PDF has means to reference external resources (including via URL). But I'm not sure if this is applicable specifically to fonts. Check out PDF Reference.

@gettalong
Copy link
Member

@Siyfion It would help if you could provide a small script that reproduces the error. As for external object streams specified via URLs: Yes, this should be possible, see section 7.11.5. However, I doubt that there would be much support for that feature.

@Siyfion
Copy link
Author

Siyfion commented Oct 25, 2016

@pointlessone @gettalong Minimal code reproduction done and attached. It's literally hello-world with a font and different character-set.
test.zip

@Siyfion
Copy link
Author

Siyfion commented Oct 26, 2016

@pointlessone & @gettalong
Or if people prefer no random zip file:

require "prawn"

Prawn::Document.generate("hello.pdf") do
  font("Taviraj/Taviraj-Regular.ttf") do
    text "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-=!@$%^&*()__+}"
  end
end

Outputs the following:

hello.pdf

@gettalong
Copy link
Member

@Siyfion I'm not that paranoid ;) So thanks for the ZIP-File.

What I can confirm right now is that the embedded font is not a valid TrueType font. When extracting the font stream and opening it with FontForge, it throws errors. However, if we replace the font with another one, like Roboto-Regular.ttf, everything works flawlessly.

Also, running ttfdump -t glyf FILE on the extracted font stream will give you an error after the second glyph (from 77). I think the problem comes from the Taviraj font using composite glyphs and ttfunk perhaps not properly supporting them but that is only a guess.

What you experience with Acrobat may be that Acrobat re-subsets the font on save and therefore everything works correctly.

@Siyfion
Copy link
Author

Siyfion commented Oct 28, 2016

@gettalong If I open the TTF in FontForge, I don't seem to get anything too out of the ordinary..?

@gettalong
Copy link
Member

@Siyfion Did you open the original TrueType font or the one embedded into the PDF file? The original one works fine but the embedded one is corrupt.

@Siyfion
Copy link
Author

Siyfion commented Oct 28, 2016

The original, surely that means that the font file I'm using is perfectly
fine and that it's the way it's being embedded that's at fault?

Simon Mansfield

On 28 October 2016 at 17:49:15, Thomas Leitner (notifications@github.com)
wrote:

@Siyfion https://github.com/Siyfion Did you open the original TrueType
font or the one embedded into the PDF file? The original one works fine but
the embedded one is corrupt.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#972 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAUqOFnjL6rhg8zTibd22qTR63iSKoKPks5q4ieLgaJpZM4Jf_6s
.

@gettalong
Copy link
Member

@Siyfion Yes, the original file also works correctly for me but not the embedded subset of the file and, as you said, this means that subsetting does not work for this file.

@Siyfion
Copy link
Author

Siyfion commented Oct 31, 2016

@gettalong So where does the error lie (in what piece of code?)

@gettalong
Copy link
Member

@Siyfion Didn't have to investigate further, but I guess it will be somewhere here: https://github.com/prawnpdf/ttfunk/blob/master/lib/ttfunk/table/glyf.rb

@Siyfion
Copy link
Author

Siyfion commented Nov 1, 2016

Wow, that's er... waaaay outside my comfort zone to try and debug/fix. Guess I'll have to wait until someone can take a proper look at it.

@gettalong
Copy link
Member

@Siyfion No problem, I think I will some time today to have a look.

@gettalong
Copy link
Member

@Siyfion I tracked down the problem after some lengthy investigation (I'm not that familiar with ttfunk myself) and have opened an issue (see prawnpdf/ttfunk#32) where you will also find the fix that you can apply to your ttfunk installation.

@Siyfion
Copy link
Author

Siyfion commented Nov 1, 2016

Awesome work! Thank you so much for looking into it!

Simon Mansfield

On 1 November 2016 at 21:27:48, Thomas Leitner (notifications@github.com)
wrote:

@Siyfion https://github.com/Siyfion I tracked down the problem after
some lengthy investigation (I'm not that familiar with ttfunk myself) and
have opened an issue (see prawnpdf/ttfunk#32
prawnpdf/ttfunk#32) where you will also find
the fix that you can apply to your ttfunk installation.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#972 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAUqONw7MIBWHHzxB7Ni-HthzePa-PoIks5q567UgaJpZM4Jf_6s
.

@Siyfion
Copy link
Author

Siyfion commented Nov 2, 2016

Confirmed that @gettalong's fix does indeed cure this issue. I'd like to get the change merged into the release if possible, as I'm sure this affects more than just one or two fonts!

@pointlessone
Copy link
Member

This issue is fixed in TTFunk 1.5.1. I will close it now. Feel free to reopen in case it doesn't work for you and you have new details.

@gettalong Thank you for the research you did on this issue.

@Siyfion
Copy link
Author

Siyfion commented Apr 19, 2017

@pointlessone & @gettalong, awesome work both of you. 👍

@swistak
Copy link

swistak commented Jan 21, 2022

For anyone who stumbles upon it and for some reason't can't easily upgrade to new version of prawn a workaround (from master) is:

unless Prawn::VERSION > '0.13'
  module TTFunk
    class Table
      class Loca
        # Backport from current master to fix https://github.com/prawnpdf/ttfunk/issues/32
        def self.encode(offsets)
          long_offsets =
            offsets.any? do |offset|
              short_offset = offset / 2
              short_offset * 2 != offset || short_offset > 0xffff
            end

          if long_offsets
            { type: 1, table: offsets.pack('N*') }
          else
            { type: 0, table: offsets.map { |o| o / 2 }.pack('n*') }
          end
        end
      end
    end
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants