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
Pango #49
Pango #49
Conversation
This is very broken right now. Folks should hold off looking at it until I finish transitioning to Pango and sort out some major scaling problems. |
not just for querying extent. Handle Local FontSize by scaling before layout. This looks better, but it's possible we should implement both interpretations.
I added some debugging code to draw the extent rectangle around the text. I believe this branch fixes the issues described in #19, though Here's my test code: {-# LANGUAGE NoMonomorphismRestriction #-}
import Diagrams.Prelude
import Diagrams.Backend.Cairo.CmdLine
main = defaultMain $ example # centerXY # pad 1.1
-- For debugging, I've hacked the Cairo Backend to add a rectangle
-- around text, corresponding to the logical extent as reported by
-- Pango.
--
-- This mimics the test in
-- https://github.com/diagrams/diagrams-cairo/issues/19 , which we
-- can't currently reproduce because the `textLineBounded` API is
-- broken by Measure changes.
washington = text "Washington" # fontSizeL 1
is = replicate 10 'i'
is1 = text is # fontSizeL 1
is2 = text is # fontSizeL 2
isO = text is # fontSizeO 24
wsO = text (replicate 10 'w') # fontSizeO 24
isMono = text is # fontSizeO 14 # font "monospace"
washMono = text "Washington" # fontSizeO 24 # font "monospace"
example = vcat' (with & sep .~ 2) [washington, is1, is2, isO, wsO, isMono, washMono] # centerY <> square 16 |
I like good kerning, but multilingual support is what really pushed me to work on this. Here are some examples from the UTF-8 Sampler showing that Pango handles right-to-left scripts and joining characters. (From top: English, Hebrew, Hindi, Urdu) (Updated image with a proper Nastaleeq font.) |
Thanks again to @jeffreyrosenbluth and @fryguybob for sorting me out on use of I cannot reproduce #43, so I can't say if it's resolved. #19 seems resolved modulo the regression in Possibly we should remove |
I built the user manual with the pango branch and noticed a few things:
|
Thanks for doing that! The default font will depend on your system configuration. On Linux this is via Fontconfig. I don't know about MacOS. Diagrams just sets The default Those sound like bugs in |
Pango's origin is at upper left, so for (BoxAlignedText 0 1) we want an offset r2 (0,0). Cairo's origin is at baseline, so handling BaselineText used to be trivial.
Apparently the images above are the intended semantics; font hinting extrapolated to unreadably small sizes results in the overlap and weirder things. Practically, I suggest we make the default FontSize something non-Local, like @jeffreyrosenbluth I think you're right about serif fonts; the Fontconfig default is sans, but Pango must be requesting a serif when Diagrams doesn't request anything in particular. |
I'm fine with changing the default but I would prefer either |
Aha, I knew this would come around to bite us eventually. The problem is that (particularly in the case of There might be an argument for letting users control the two attributes separately; I don't know if there would be any need for that. In the meantime, however, how about just picking some "reasonable" font size (e.g. 12pt), and always choose that font size when rendering text, but applying an extra scaling factor to make the text the requested logical size? |
I think we've mentioned 3 possible semantics for
1 has the feature that you can illustrate how letterforms and kerning change nonlinearly. 1 & 2 have the advantage that scaling is always linear. That is, the output is always the same as if the text were converted to a Path before scaling. 2 & 3 have the advantage that text scaled to a reasonable size is legible. 3 has the feature that Local text will be laid out the same as Normalized or Output text at the same final size. All 3 admit non-uniform scaling, and should end up close to the same size. I favor option 3; I think it will look best and be least surprising. I think it's consistent with my intuition of 2 is clearly better than 1, but it introduces a slightly arbitrary constant, and I think it's most complicated to explain. Am I neglecting some diagrams that can be made with 2 but not with 3? |
With (1), calling the fact that you can illustrate how letterforms and kerning change nonlinearly a "feature" is a stretch. =) I think I agree (3) is the best approach, I hadn't considered that option before. I also don't like the arbitrary constant in (2). The only thing we would lose with (3) is that we can't use a single letter F to illustrate transformations in the user manual anymore, since, for example, applying |
layout text at final output size, apply tn, the Transformation normalized to avgScale 1 Revert "restore semantics of Local FontSize" This reverts commit d1a70cb. Conflicts: src/Diagrams/Backend/Cairo/Internal.hs
Aha! In that case (3) is indisputably the best option. |
This branch uses Pango for font layout instead of the toy API that ships with Cairo. I haven't started on
Cairo.Text
, yet, so this doesn't address #19. It may fix #43; I'm not sure.I also want to put together some examples that use non-Latin characters, BIDI, combining chars---all the nice stuff Pango should give us. Pending figuring out what's wrong with my Fontconfig.
I'm seeking advice on the right way to interleave Pango and Cairo functions. Pango returns in
IO
, rather than inCairo.Render
. I hacked the code together withunsafePerformIO
, which is obviously wrong.