Fallback fonts and bold text #263

Closed
oli-g opened this Issue Aug 2, 2011 · 24 comments

Comments

Projects
None yet
9 participants

oli-g commented Aug 2, 2011

Hello guys, I'm dealing with an annoying bug: in my code I have this fragment that sets fallback fonts:

pdf.font_families.update("Calibri" => { 
    :normal => "/Library/Fonts/Microsoft/Calibri.ttf",
    :italic => "/Library/Fonts/Microsoft/Calibri Italic.ttf",
    :bold => "/Library/Fonts/Microsoft/Calibri Bold.ttf",
    :bold_italic => "/Library/Fonts/Microsoft/Calibri Bold Italic.ttf"
})
pdf.fallback_fonts ["Times-Roman", "Calibri"]

I try to print some bold text (not only free text, but in tables, too), but the text loses the style info and is not printed in bold. However, the fallback font works correctly.

If I comment out pdf.fallback_fonts ["Times-Roman", "Calibri"], the text is displayed correctly in bold...

Am I doing something wrong? Is this commit dealing with this problem?

Thank you guys, and keep the good work.

Member

Bluejade commented Aug 5, 2011

Thank you for pointing this out. Fallback support doesn't take the
style portion of a font family into consideration. A kludgy workaround
for now, if you are replacing in solid bold text (this won't work if
you are switching between bold and plain within a block of text),
would be to set bold-only font families that you use as fallback fonts
for bold sections. For example:

pdf.font_families.update("CalibriBold" => {
:normal => "/Library/Fonts/Microsoft/Calibri Bold.ttf"
})
pdf.fallback_fonts ["CalibriBold"]

Like I said, it is a kludge, but it might get you through the immediate problem.

Cheers,

Daniel

oli-g closed this Aug 5, 2011

oli-g commented Aug 5, 2011

Hello Daniel, thank you for the quick response.
I'm going to tell you my exact situation, hoping that you can provide me a workaround for my problem: thank you for the workaround you provide me, but unfortunately it does not solve my issue.

I'm printing math quizzes, so I need to have support for characters such as ⁵, π, etc....
I print these pdfs without touching fonts, because the prawn default font (Helvetica) is the exact font of these documents.
With Helvetica I print some texts in bold, such as the title, the column headers, etc....

But Helvetica does not suppor the glyphes I need, so I configured the Calibri fallback font to print them when present in the question content.
Now... the problem is that all bold text (in Helvetica) is now printed as normal. Glyphes in questions content are displayed correctly.

So, in order to let you understand: I don't want to print things in bold with the Calibri fallback font, but I want that the bold text printed in Helvetica stays bold.

I tried to apply the previous workaround you give me, but no way.... bold text keep to be displayed as normal.
Thank you for the feedback.

Giannicola

oli-g reopened this Aug 5, 2011

Member

Bluejade commented Aug 5, 2011

I'm printing math quizzes, so I need to have support for characters such as ⁵, π, etc....
I print these pdfs without touching fonts, because the prawn default font (Helvetica) is the exact font of these documents.
With Helvetica I print some texts in bold, such as the title, the column headers, etc....

But Helvetica does not suppor the glyphes I need, so I configured the Calibri fallback font to print them when present in the question content.

What happens when you define the fallback font simply as:
pdf.fallback_fonts ["Calibri"]

Thank You,

Daniel

oli-g commented Sep 1, 2011

Nothing changed... The bold text in Helvetica is printed as normal....
The problem is:

  • If I don't set a fallback font, most glyphes are displayed as _ (because the default Helvetica font does not have them);
  • If I set a fallback font, bold text in Helvetica is printed incorrectly as normal.

Thank you for the support! Please tell me if you want some code.

Member

Bluejade commented Sep 5, 2011

Nothing changed... The bold text in Helvetica is printed as normal....
The problem is:

  • If I don't set a fallback font, most glyphes are displayed as _ (because the default Helvetica font does not have them);
  • If I set a fallback font, bold text in Helvetica is printed incorrectly as normal.

Thank you for the support! Please tell me if you want some code.

Yes please, if you have a minimum case that reproduces the problem,
then that will help me look into it.

Thank You,

Daniel

oli-g commented Sep 6, 2011

Check it out: fork this repository. The app reflects the situation where I am in my real application. I used ruby 1.9.2-p180 and rails 3.0.7.
Let me know if you have some problem or if I can help you in some ways...
Thank you

Giannicola

Member

Bluejade commented Sep 10, 2011

Check it out: fork this repository. The app reflect the situation where I am in my real application. I used ruby 1.9.2-p180 and rails 3.0.7.
Let me know if you have some problem or if I can help you in some ways...
Thank you
Giannicola

Hello Giannicola,

Instead of relying on the fallback font, you can set font at the
fragment level (even a single character). Check out Text > Advanced
Styling > Formatted text (page 50) in the manual:
http://prawn.majesticseacreature.com/manual.pdf

Otherwise, if you can extract the code into a stand-alone example with
hard-coded data, then that would be more helpful than an entire Rails
app.

Cheers,

Daniel

oli-g commented Sep 12, 2011

Unfortunately I can't go that way, because I want to print in Calibri only glyphes: how to tell Prawn to use Calibri only for printing glyphes?

By the way, this is a simplier ruby app: just bundle install and ruby prawn_issue_263_bis.rb

Thank you for your support! I really appreciate it.

oli-g commented Sep 27, 2011

Hello Daniel, any news? Can I help in some way?

Member

Bluejade commented Sep 27, 2011

Hello Giannicola,

My apologies for the delay. How about this?:
Bluejade/prawn_issue_263_bis@f71c7f5

That is documented on page 84 of the manual:
http://prawn.majesticseacreature.com/manual.pdf

Best Regards,

Daniel

On Tue, Sep 27, 2011 at 6:57 AM, Giannicola Olivadoti
reply@reply.github.com
wrote:

Hello Daniel, any news? Can I help in some way?

Reply to this email directly or view it on GitHub:
https://github.com/sandal/prawn/issues/263#issuecomment-2209894

oli-g commented Sep 27, 2011

You're right, now it works. But I think it's a workaround, the problem remains, because row(0).column(1).font_style = :bold is correct, and it's even more elegant than writing inline markup in the strings.
So I don't know if we can close this issue or not.
By the way, I thank you very much for the help!

Member

Bluejade commented Sep 30, 2011

True. Brad is far more familiar with table code than I am...Brad, what do you think about this? (and apologies for passing the buck)

Giannicola's simplified example is helpful:
https://github.com/oli-g/prawn_issue_263_bis

bradediger was assigned Oct 11, 2011

I am also experiencing the issue, and it is not related to tables.

I am using
@pdf.text_box "Some text all ascii", :fallback_fonts =>['DroidFallback'], :style=>:bold
When fallback font is specified, the text is not bolded.
Unfortunately I can't use inline_format as #text_box does not accept it as a valid option.

I have written small repro code here:
https://github.com/kmamykin/prawn_fallback_fonts_issue

Member

Bluejade commented Mar 14, 2012

Have you looked at formatted_text_box?

Ha, yes, was able to make it work. The https://github.com/kmamykin/prawn_fallback_fonts_issue repo is updated with what I did.
Thanks for pointing the workaround.

pbc commented Sep 12, 2012

is there any chance for fixing this issue any time soon?

I've added a to-do for myself to investigate it, but I'm on a couple deadlines that will prevent me from looking into this for a several weeks. If you or anyone else is interested, I think it should be an easy fix. Here are the notes I left for myself in the to-do entry:

Prawn fallback support with font family support: if a particular style has been registered with the font family, then attempt to set that style again when setting the fallback font. Check to see how this behaves when the current style has not been registered with the fallback font family. If it has not been, then fall back to the plain fallback font.

I too would like a fix for this, as its currently causing users to complain.

practicingruby removed the stale label Mar 17, 2014

Owner

practicingruby commented Mar 17, 2014

I don't know what the status is on this bug, but I'm re-opening so that hopefully someone will investigate and try to reproduce on 1.0.0.

It's still present.

practicingruby reopened this Jul 2, 2014

Owner

practicingruby commented Jul 2, 2014

@stefanneculai: can you try this fix and see if it solves the problem? #743

#743 fixes it.

Owner

practicingruby commented Jul 18, 2014

#743 has been merged. Thanks all, and sorry for the long delay.

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