Skip to content

Fix styled width_of when using TTFs. (Revised version of #822) - #827

Closed
practicingruby wants to merge 5 commits into
masterfrom
fix_width_of
Closed

Fix styled width_of when using TTFs. (Revised version of #822)#827
practicingruby wants to merge 5 commits into
masterfrom
fix_width_of

Conversation

@practicingruby

Copy link
Copy Markdown
Member

From @ernie:

Previously, width_of calculations on styled text were relying on the
document font's name attribute in order to look up the appropriate
font style. This doesn't work for TTF fonts, since the name is a full
path to a single style of font, and the Prawn must know about the font
family in order to find another style.

This update uses the family instead, which allows the width_of
calculations to work properly with TTFs, and doesn't appear to cause any
regressions based on existing specs.

ernie and others added 2 commits February 6, 2015 10:08
Previously, width_of calculations on styled text were relying on the
document font's `name` attribute in order to look up the appropriate
font style. This doesn't work for TTF fonts, since the name is a full
path to a single style of font, and the Prawn must know about the font
family in order to find another style.

This update uses the family instead, which allows the width_of
calculations to work properly with TTFs, and doesn't appear to cause any
regressions based on existing specs.
@practicingruby

Copy link
Copy Markdown
Member Author

@ernie:

I added a test to make sure that bold differed from plain DejaVuSans to help make sure we're not getting a false positive test result. I also removed what I believe to be an old and unnecessary default value (I can't think of why we'd want to use "Helvetica" if the font doesn't exist. It's our default font, but the font object should be present and the family can be read from it.)

Please test this against your production code and let me know if we're ready to :shipit:.

@ernie

ernie commented Feb 20, 2015

Copy link
Copy Markdown
Member

Thanks! And sorry, didn't realize it was safe to rely on font.family being available based on the previous code!

@practicingruby

Copy link
Copy Markdown
Member Author

@ernie: I'm not 100% certain it is safe, but the manual and tests pass, and if this breaks something I'd rather fix the root cause than rely on this weird default.

@ernie

ernie commented Feb 20, 2015

Copy link
Copy Markdown
Member

@practicingruby Also, yep, this looks to do the trick. Thanks again!

practicingruby pushed a commit that referenced this pull request Feb 20, 2015
Previously, width_of calculations on styled text were relying on the
document font's `name` attribute in order to look up the appropriate
font style. This doesn't work for TTF fonts, since the name is a full
path to a single style of font, and the Prawn must know about the font
family in order to find another style.

This update uses the family instead, which allows the width_of
calculations to work properly with TTFs, and doesn't appear to cause any
regressions based on existing specs.

(Squashed commit of #827)
@practicingruby

Copy link
Copy Markdown
Member Author

Squashed and merged in 13cd1c4 (there is a little bit of merge noise there, but it should be harmless)

@practicingruby

Copy link
Copy Markdown
Member Author

@ernie: Because your pull request was accepted, I've given you commit access to all of Prawn's repositories. Please read our contribution guidelines, and thanks for the patch!

tim-vandecasteele added a commit to Silverfin-Engineering/prawn that referenced this pull request Jun 3, 2017
@pointlessone
pointlessone deleted the fix_width_of branch December 30, 2020 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants