-
Notifications
You must be signed in to change notification settings - Fork 88
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
Wrong horizontal character positioning in hello world examples #161
Comments
Thansk for the report. For the correct rendering, did you do it with freetype-py (i.e. do you have a fix ?) |
The full fix is probably something close to what I did here: hb-view.py was written to explicitly support Arabic and Hebrew fonts, where non-zero left-side bearing (and top/bottom-side bearings too) are common. That said, I think the original example works as it is, for a font that mostly have zero left-side bearing. For those who think they need non-zero leftside/topside bearings, like Arabic users, they know they need to add it anyway. I am more inclined to say add a new example using a different font - or even refer to my repo, instead of bloating the existing one. |
I basically changed this line: freetype-py/examples/hello-world.py Line 47 in 51ee6e1
to Z[y:y+h,x+left:x+w+left] += numpy.array(bitmap.buffer, dtype='ubyte').reshape(h,w) It worked for my case, but for negative
Well, my font and text was western, so I didn't know I had to add it. |
Arabic fonts have top/bottom bearings too. While I agree the example is limited, I think it is best to create a new example using a font with obviously non-zero left bearings. Perhaps one cursive font. |
A new example might help to show the problem. But as shown by @badicsalex, the simple hello-world rendering is wrong. I would add the left bearing with a comment warning this is not the correct way to do tue and redirect reader to your hb-view.py example. |
I wonder if any of the glyphs in "Hello World" has a non-zero leftside bearing, in the example font. That's basically my question. A future contributor might decide to "simplify" the code if it is all zeros. While working on the hb-view example (I thought of contributing that to freetype-py but it has extra dependencies on harfbuzz, which is another thing) , I remember there is a rather big omission to the hello world example - none of "Hello World" has a descender part below the baseline, so it does not allocate drawing space below the baseline. This is quite unusual - longer normal run of texts have a "g" or a "y". This (the example does not allocate drawing space below baseline, so "y", and "g" are cut off, if you put one in) probably could go in as a comment as well. |
In any case, the original lines I linked are dead code since the I think the above mentioned comments or something like a generic warning should be added at least, even if the code isn't touched for simplicity. |
@HinTak You're right. This |
I only found one other problem like this, in hello-vf.py . Most of the other examples seem to use the left side bearing value - or at least, not obviously not using it. Actually the left side bearings of the example are mostly non-zero - and illustrates the problem better than the Good Times font (most of them 1 or two pixels off) - the "!" at the end of "Hello World !" was off by 7 pixels. I did compare the result with hb-view.py (that gets the leftside bearings from harfbuzz instead of freetype). I re-check the descender comment - I think it probably concerns another example instead of hello-world. |
The left bearing is not used in these examples (pyright does complain about this):
freetype-py/examples/hello-world.py
Line 42 in 51ee6e1
freetype-py/examples/hello-world-cairo.py
Line 47 in 51ee6e1
And probably some other places. This should probably fixed, because it is common practice to start out from examples and build from there.
Example with the Good Times font; notice that the distance between
MP
andTI
are way off:The correct rendering looks like this:
The text was updated successfully, but these errors were encountered: