Giter Club home page Giter Club logo

Comments (6)

zagiduller avatar zagiduller commented on August 19, 2024 1

I have the same issue with Nunito font https://fonts.google.com/specimen/Nunito
изображение

from freetype.

Zyl9393 avatar Zyl9393 commented on August 19, 2024

Same problem with SplineSansMono-Regular.ttf.

image

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.

Zyl9393 avatar Zyl9393 commented on August 19, 2024

Did some debugging using the letter d. Here it is in its broken form:

image

Here it is after rendering both contours of the letter separately and awkwardly pasting them on top of each other in MS Paint:

image

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.

egonelbre avatar egonelbre commented on August 19, 2024

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.

Zyl9393 avatar Zyl9393 commented on August 19, 2024

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.

neurozero avatar neurozero commented on August 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.