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

Printing recipes with Polish letters #729

Closed
krzyklo opened this issue Nov 3, 2013 · 10 comments · Fixed by #1010
Closed

Printing recipes with Polish letters #729

krzyklo opened this issue Nov 3, 2013 · 10 comments · Fixed by #1010

Comments

@krzyklo
Copy link

krzyklo commented Nov 3, 2013

When I am trying to print recipe, I get black squares instead of polish letters:

example

The same error as above exists in PDF document, which I get when I clik Print Preview.

In recipe view Polish letters are displayed correctly. To get correct export, I need to do Plain text export or HTML export, and then print resulting file, but it is annoying to exporting to file to print.
I didn't find any options to set encoding of PDF files...
Is someone could point me how to fix this annoying issue?

@ockham
Copy link
Collaborator

ockham commented Nov 7, 2013

I did a bit of research on this. Our PDF generating library, Reportlab, by default uses one of the so-called "Base 14" fonts (mostly Arial, Times Roman, and Courier in Regular, Bold, etc.), which do not have to be included in the PDF, as they're guaranteed to be available in all PDF viewers. Unfortunately, those fonts apparently do not include Latin-2 glyphs (i.e. Eastern European diacritics like ogoneks or hačeks).

To solve this, I've changed the code locally to use a custom font that covers those glyphs (as e.g. the FreeFont family does, i.e. FreeSans, FreeSerif, and FreeMono), which then gets embedded into the PDF, increasing its file size.

It worked, but in order to make this sort of hack available to all users, I need to

  1. either ship a "default" font with Gourmet (which would increase the package's file size)
  2. or rely on the existence of such a default font on every Gourmet user's system
  3. or enable users to select a font of their choice for PDF generation and printing

The latter option seems desirable, but it's probably a bit hard to translate a Pango font description (or whatever is returned by GTK's FontChooser) into something that Reportlab understands. (Easier if I fix #708)

I'll give this some more thought. Thanks for pointing this out to me anyway, and feel free to add your thoughts on this in the meantime.

@krzyklo
Copy link
Author

krzyklo commented Nov 7, 2013

Dear Ockham,
Thank you for in depth investigation of root cause responsible for this issue.
I agree with you that giving user freedom to choose font seems like the ultimate solution, but as you mentioned it is probably not easy to implement.
Personally I would be grateful, if you could describe how to modify the code locally, to use FreeSans font, and I will try to follow your instructions, to solve my problem for now.. (if this hack isn't too arcane ;-) )

@ockham
Copy link
Collaborator

ockham commented Nov 7, 2013

Here you go: https://gist.github.com/ockham/7362154
(You can of course play with the font settings in that self.styleSheet.add(...) line.)

@krzyklo
Copy link
Author

krzyklo commented Nov 7, 2013

Works like a charm now. Thank you very much!!!
For me issue is closed, but perhaps it would be good to find permanent solution for future.

@krzyklo krzyklo closed this as completed Nov 7, 2013
@ockham
Copy link
Collaborator

ockham commented Nov 7, 2013

Glad to help.
(I'm reopening the issue, in order to remind me to fix this permanently.)

@marmistrz
Copy link

Maybe a temporary solution to select the .ttf file via a file dialog (e.g. in the settings) would be feasible until a proper one is implemented?

@pabru
Copy link

pabru commented Mar 25, 2016

I propose detecting if non-Latin-2 characters are present in the recipe while exporting to PDF, and if that's detected, then embed a cut-down version of a font which includes only the character descriptions for the characters actually present in the document. I'm quite sure PDF allows you to do that.

If this option is chosen as default, it should be easy to use for non-technical users and save some space in the exported file at the same time. There could be extra options for advanced users to choose their own font and/or choose whether to embed the full or cut-down versions.

Any idea which parts of the source I should be looking at to get started?

@krzyklo
Copy link
Author

krzyklo commented Mar 11, 2017

Again the same issue in version 0.17.4, but this time the code in ../gourmet/plugins/import_export/ changed ,and gist from Ockham: https://gist.github.com/ockham/7362154 do not work anymore.
Would someone more familiar with the code could advice, where to modify the font settings, to stop getting this kind of error?
Kind Regards,

@krzyklo
Copy link
Author

krzyklo commented Jul 30, 2017

It is surprising, that no one could help with such regression like this.
Could anyone advice how to fix it?

@krzyklo
Copy link
Author

krzyklo commented Apr 10, 2020

In 2020 again, trying to print gives black squares, and the solution given by Ockham no longer applicable, as the way how files are organized are changed.
Could anyone explain, where to search in files for fontName settings?
Tried to grep for "fontName" but it not returned any hit.
It seems, that the way how page for print is generated changed completely.
Could anyone suggest where to change the font used for printing?

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

Successfully merging a pull request may close this issue.

4 participants