-
-
Notifications
You must be signed in to change notification settings - Fork 704
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
Support font-variant: small-caps approximation #123
Comments
I could reproduce this. I just tested that we’re correctly setting |
Possibly this only works for fonts that have a small-caps variant, but I don’t know how to find one. |
I was thinking about that as well, but is it really necessary? I mean every font could be easily small-capitalized by capitalization and adjustment of font size. I am not sure though if that is how it works! |
Yes, that would be synthesizing the small-caps variant. I suspect that’s what browsers are doing when the font does not provide it directly. I suppose we could do it with a combination of text-transform and font-size. |
Yes, you're right, many softwares (including browsers) use caps with a smaller size instead of small caps when they are not available. That a crime against typography (real small caps characters keep the same weight as regular variants for a size, false small caps don't), but that's definitely not the worst. Small caps are available in a separate font file (just as bold and italic, Fontin is a good example) or via an OpenType feature (like ligatures and kerning tables, Libertine is a good example). Unfortunately, both solutions seem to be broken in WeasyPrint, even if the code looks OK. We have to figure out what's going on. |
By the way, creating a "false" small-caps variant fallback can be difficult, because I'm not sure that there's a way to know in Pango if a real small-caps variant exists. |
After playing with Pango and fontconfig, I now know that fontconfig is able to generate false small-caps, italic and bold fonts. I don't know exactly how it works, but I suppose that it could be included in WP. I'm ready to help anybody interested in this feature 😄. |
Hi liZe. I´m interesting in this feature |
Good to know!
Well… It's definitely true for "faux" bold and italic, and it's already included in WeasyPrint. But unfortunately, I can't find anything about small caps 😢. I don't know if it was just a dream, if I've seen small caps where there was just bold and italic, or if I had found something else… If anyone knows anything about that, I'd be glad to learn! |
If a font does not have a small cap variant, Weasyprint will not try to approximate one. This commit displays small caps characters in regular uppercase. ref: Kozea/WeasyPrint#123 ref: #2055
/*** fake small-caps to overcome bug ***/
.sc, .smallcaps, .small-caps {
/* font-variant: small-caps; */
text-transform: uppercase; font-size: 75%;
}
/* force uppercase inside faked small-caps:
<span class="sc"><span class="scu">C</span>aesar</span>
*/
.scu {
/* font-variant: small-caps; */
text-transform: uppercase; font-size: 133%;
}
/* .usc = uppercase to small-caps:
<span class="usc">SMALL CAPS</span>
<span class="usc"><span class="scu">C</span>AESAR</span>
*/
.usc {
/* text-transform: lowercase; font-variant: small-caps; */
text-transform: uppercase; font-size: 75%;
} Fake small caps may be a crime against typography, but what can you do when the style guide demands them? |
Thanks for that fake small-caps example. I'd really like to see this implemented natively, if possible. The markup required for surrounding all the true uppercase letters in a string with spans seems incredibly daunting for a publishing process we are trying to automate. Some other folks were looking at similar issues at some point: Automattic/node-canvas#894 |
For what it's worth, Pango does seem to support synthetic small caps these days. E.g., the following with pango-view does the right thing:
However, for reasons that I don't understand the naive approach of adding this to get_font_description() in text/fonts.py does not seem to work, giving me full-sized caps that overlap each other (as if the spacing for small caps was being used but not the actual small caps).
(with PANGO_VARIANT mapping 'small-caps' to PANGO_VARIANT_SMALL_CAPS). Example output: As compared to pango-view: I'm at a loss for debugging this but perhaps someone else has more insight. |
(To be more precise, Pango's synthetic small caps won't work on Mac until https://gitlab.gnome.org/GNOME/pango/-/issues/841 is resolved, but it seems to work on Linux at HEAD.) |
@xavidotron Thanks for your code, that was really useful. 😍 I opened #2345 with some code I only tested manually. Don’t hesitate to give some feedback and share your thought about it! (Bug 123 solved by PR 2345 would be fun.) |
Hi,
It is written in the documentation that I should report as a bug if some CSS 2.1 feature is not working. I found that the
font-variant: small-caps
CSS is not working (it works in the browser, but not in the rendered PDF).Hope this helps, regards, Sz'
The text was updated successfully, but these errors were encountered: