-
Notifications
You must be signed in to change notification settings - Fork 279
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
Text union #532
Comments
It appears the A character in this font is created with 2 overlapped closed shapes. This is pretty unusual for a font. Typically the author would ensure the character is a union. It’s ok to have multiple closed geometriessuch as an O or “I” but the assumption is they’re not overlapping. So you’ll need to take the A model and find the chains in it. Then convert the chains to models, then combine the models with a union. I’m mobile right now but you should be able to find these functions in the documentation. |
Hi @danmarshall thanks for getting back to me. I managed to resolve the above. I've now encountered a separate issue related to chains. The
Post exportation using fill with either pdfkit or pdf-lib results in any outer chain filling over any inner chain. As I understand it makerjs is for outlines, and fill is out of scope. However, I'm unaware of any other javascript pdf libraries that support path data and noticed that |
Fill is not completely out of scope, because Maker.js is aware of winding order. See https://maker.js.org/docs/working-with-chains/#Find%20multiple%20chains This might be as simple as adding the options |
Hi @danmarshall thanks for the suggestion. I've tried combinations of fill rules and
Ideally, I'd like to use toSVGPathData and pdf-lib instead of pdfkit. |
Hi @lachlansmith , it makes sense, after thinking about it further, the existing code does not account for the nesting. Since the call you referenced uses chainToSVGPathData which does not descend into any nested/contained chains. I think it should work if the function would crawl the .contains recursively and return a union of all the svg. |
Hi @danmarshall thanks for your assistance. I managed to resolve the above by changing the fill rule from the default evenodd to nonzero. I'd would never have known about winding order unless you mentioned it.
I'm actually a bit confused why evenodd wasn't working here. The documentation you linked suggests evenodd should not cause fills over enclosed shapes. Changing the fill rule to nonzero seems contrary. |
Hi @danmarshall changing the fill rule wasn't the solution here. With almost all fonts I try there always seems to be at least one character not filling correctly.
At first, I thought I had this backwards. The documentation you linked suggests those two should be opposite. The toSVGPathData has likely been around for some time so forgive me when I ask is something going wrong here? Every font I try seems to break. |
For context - this is only happening in the PDF output, correct? |
This is happening with toSVGPathData output getting passed to either drawSvgPath from pdf-lib or doc.path().fill() from pdfkit. |
Example fonts: |
Also seems to be happening with some Google fonts: danmarshall/google-font-to-svg-path#30 |
Unfortunately, some fonts are degenerate, regarding each glyph having a closed geometry which is non-overlapping. Let's look at Bodoni Moda: Notice that with the glyphs This wasn't common some time ago, but now there seem to be many fonts assembled this way. I don't currently have a solution. One idea that springs to mind is to create a process to compare 2 bitmaps of a shape, one rendered with even-odd and the other with nonzero. If they differ, the shape is degenerate. 🤔 |
Fonts seem to be consistent within themselves. Perhaps you can store the fill rule associated with each font, then apply correspondingly? |
How does opentype.js approach this? The output of
Unfortunately, I'm not well versed enough with vector graphics to tackle this. I'd like to be. I'm going to have a dig around and see what conclusions can be drawn from the difference between makerjs output and opentype.js output. |
Hi @danmarshall this idea is probably just taking an awesome feature and crippling it. But it's an idea nonetheless. There seems to be an apparent loss of information here. Currently, glyphs are being destructured into paths and nested models. In the case of
For the purpose of preserving the font author's path data could glyph be introduced?
If destructuring remains desired, or vice versa, this could be exposed on
I can't imagine any other use case than [Glyph], but if it needed to be more general, simply [Path]. |
I had the same idea 😁 but I won't be adding it to the core code anytime soon, I'd need to rationalize it across the entire API first. |
Hi @danmarshall thanks for queueing this work up. What does MakerJs' timeline look like? MakerJs' covers all of my other basis. I'd much rather move forward when support is in place. Not asking for a date, but a general idea of when I can revisit this would be fantastic. |
@lachlansmith the timeline is quite long right now, as this is my fun side project and gets delayed for higher priorities. I have one pull request that is almost 2 years old now 🙁 |
Hi @danmarshall thanks for pointing me here. I understand the use case for maker js is to draw outlines and that fill happens post exportation. That's what I've done. However, due to the glyph parts the fill results in white spaces. Clearly demonstrated by an A.
My approach to resolving this would be to union the parts of the glyph. This doesn't seem to be exposed on
MakerJs.models.Text
. I planned to useMakerJs.model.combineUnion
on a glyphs child models, but the A glyph doesn't have child models. I assume this would negatively effect an "O". Am I missing something?The text was updated successfully, but these errors were encountered: