Comments (6)
I have the same issue with Nunito font https://fonts.google.com/specimen/Nunito
from freetype.
Same problem with SplineSansMono-Regular.ttf
.
Looks like we need to do a deep dive into TTF specification. As far as I know, usually shapes should only cut negative space out of themselves, not other shapes. Maybe this is some obscure data structure problem, where multiple closed loops are defined in a single shape, or something like that?
from freetype.
Did some debugging using the letter d
. Here it is in its broken form:
Here it is after rendering both contours of the letter separately and awkwardly pasting them on top of each other in MS Paint:
This demonstrates that the contours are loaded correctly. The bug seems to be with how contours are blended. Specifically, the bulge of the letter d
is drawn first, and then the vertical bar, suggesting the bug is somewhere in the method Add1()
. (Add2()
was not invoked for the vertical bar, and Add3()
was not invoked at all; as far as I could figure out it is not used for true type fonts)
With a bit of luck, this leaves us with 100 lines of code to sift through. I'll come back to this another day.
from freetype.
My guess was that it's some winding thing... so, if you set Rasterizer.UseNonZeroWinding
then it renders correctly for WorkSans-Black
.
e.g. in https://github.com/golang/freetype/blob/master/truetype/face.go#L188 add a.r.UseNonZeroWinding = true
.
Note: I'm not sure whether there's some font or glyph property that should determine whether to use it; or whether it'll correctly work with alpha values.
from freetype.
I tried your solution, and you're correct. My take on Add1()
was a red herring. I found this documentation by Microsoft which explicitly states:
A point is considered to be an interior point of a glyph if it has a non-zero winding number.
I do not understand why one of these methods would work while the other one fails, but using the wrong one here is the cause of the problem. EDIT: I just realized, of course this does not work if multiple contours are considered at the same time. Basically, UseNonZeroWinding = false
allows contours to cut into each other. This also explains how out of two different TTF files which describe the same font one can work and one can fail: constructing the contours such that both methods succeed is totally possible, and some font sites seem to do exactly that to the files they serve, by whatever means.
On another note, I actually failed to to get your solution to work on my first attempt. freetype.Context
completely makes do without calling NewFace()
. With your suggested fix, one needs to call truetype.NewFace()
by oneself, then construct a *font.Drawer
the Go way and use that to draw.
from freetype.
The fix in the Goki fork works for me. It would be great to get this fix in the main implementation.
To be clear, this is a bug. Filled fonts should not be rendered with UseNonZeroWinding = false (which is the default in the Rasterizer)
The Montserrat Black font on Google fonts demonstrates the issue.
from freetype.
Related Issues (20)
- Should go.mod not be added to the project? HOT 1
- How to draw translucent strings? HOT 7
- how could i support pingfang.ttf font?
- Support for Arabic and Persian fonts HOT 1
- How can I rotate the words HOT 1
- truetype: parse TTF failed with "bad TTF version" HOT 9
- GPOS Support HOT 1
- how to get the length for font after draw HOT 1
- How to draw fonts with matrix transform? HOT 1
- Is this freetype implementation vulnerable to CVE-2020-15999 HOT 1
- don't include Luxi fonts in this package HOT 1
- how to set a font weight? HOT 1
- How to draw string in one line with different colors HOT 1
- discrepancy in scale factor conversion between freetype and truetype packages HOT 5
- range bug HOT 2
- Failing to rasterize non-latin character correctly HOT 1
- support MiterJoiner
- 字体渲染中文错误,仿宋gb2312 HOT 1
- License not recognized by go-licenses
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from freetype.