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
Workaround (fix?) for #603 encoding issue during line wrap #714
Conversation
I'm fairly sure that this is a bad behavior rather than a bug. The "built-in" fonts supported by PDF are only going to work for glyphs in the Windows 1252 character set, which is why we recommend against using them for any internationalized text. If you call But even if you DO use fallback fonts, you can probably avoid this problem by just using a TTF font rather than the built-in fonts for your default. I haven't had a chance to confirm that, but it's my suspicion. There is probably something weird going on with encodings for the default fonts too, which would cause this problem. |
It probably wasn't clear from my response, but to clarify I definitely would like to fix this issue, whether it's a bug or just a poorly defined behavior. I don't think the solution is to to transcode missing glyphs as you're doing in this pull request, because it should not be necessary. If this fixes the problem, I think it does so at the surface level. I want to either figure out where the root cause of the issue happens, or figure out whether this would actually be a safe way to solve this at the surface level. |
Here's an example of how to avoid this problem. Fallback fonts can be used if you want to use multiple TTF fonts that each contain different glyphs, but if you're just looking for internationalized text any TTF font that supports the characters you need will work fine: @pdf = Prawn::Document.new
@pdf.font_families.update("dejavu" => { :normal => "path/to/DejaVuSans.ttf" })
@pdf.font("dejavu")
@pdf.bounding_box([1, 1], :width => 90, :height => 50) do
broken_text = " Sample Text\nSAMPLE SAMPLE SAMPLEoddělení ZMĚN\nSAMPLE"
@pdf.text broken_text, :overflow => :shrink_to_fit
end |
@sandal to summarize:
correct? |
It's not necessary to use Or to really sum it up: Prawn is meant to be internationalization-friendly by default, you just need to provide UTF-8 aware fonts for it to use.
Agree! But the fix may not be "make the failing code sample work as-is". The fix will be "define the correct behavior, and make the APIs work consistently based on that definition". We need to find the root of the problem before figuring out the answer to that. |
I've verified that |
Closing this PR because I don't think it's going to be directly merged, but #729 references it so that we can come back and read the discussion when we get around to properly defining fallback font behavior. |
No issue since I started using |
@johnnyshields: Defining the behavior implies documenting it at the API doc / manual level, so yeah, it definitely will be. |
This PR contains @stayhero's test case which reproduces #603 and a workaround. I'm not sure this is the best way to solve the issue, would be great if someone more familiar with Prawn can help.
This issue is affecting many of my clients as we're generating non-English PDFs.