Chlumsky / msdfgen

Multi-channel signed distance field generator
MIT License
3.9k stars 404 forks source link

Adding setVariationAxis for variable fonts #158

Closed themancalledjakob closed 2 years ago

themancalledjakob commented 2 years ago

Hey, first pull request here, I hope there is interest and I'm doing this right.

A very basic implementation of variable font axes. slightly inspired by godot and freetype docs.

There is a second pull request with a cli implementation for the main.cpp application in the making.

wdanilo commented 2 years ago

That's amazing! Supporting variable fonts would be incredibly useful. Is there plan for full variable fonts support sooner than latter @Chlumsky ? :)

themancalledjakob commented 2 years ago

hey @wdanilo in the meantime with my fork (branch cli-variable-fonts) you can set arbitrary amount of axes for a font, and so far it worked fine with all opentype fonts that I tried. Of course, though I tried to put the code at a spot that hopefully makes sense, @Chlumsky might prefer a different implementation, so it's not future proof.

Edit: Should there be issues with the implementation in this branch, I'd be very happy to work on it and send a new or adjusted PR.

wdanilo commented 2 years ago

@themancalledjakob that's amazing. @Chlumsky, what do you think of the implementation on the @themancalledjakob branch? :)

Chlumsky commented 2 years ago

Hello, I was on vacation but I will try to look at it this week. However, I think I'm going to change at least the name of the function, and I think there should be a way to find out the list of names that can be used.

themancalledjakob commented 2 years ago

hey, thanks for the reply and hope you had a nice vacation.

I think there should be a way to find out the list of names that can be used.

sure! There is also a way of not only putting out the list of names, but also the predefined masters with their corresponding axes coordinates.

It can be quite interesting, especially when a font has multiple axes and you want to know which versions are not interpolated. e.g.:

master(1): 
    coords: Weight(100.000000) hght(100.000000) 
master(2): 
    coords: Weight(200.000000) hght(100.000000) 
master(3): 
    coords: Weight(300.000000) hght(100.000000) 
master(4): 
    coords: Weight(400.000000) hght(100.000000) 
master(5): 
    coords: Weight(500.000000) hght(100.000000) 
master(6): 
    coords: Weight(600.000000) hght(100.000000) 
master(7): 
    coords: Weight(700.000000) hght(100.000000) 
master(8): 
    coords: Weight(800.000000) hght(100.000000) 
master(9): 
    coords: Weight(900.000000) hght(100.000000) 
master(10): 
    coords: Weight(900.000000) hght(200.000000) 
master(11): 
    coords: Weight(900.000000) hght(300.000000) 
master(12): 
    coords: Weight(900.000000) hght(400.000000) 
master(13): 
    coords: Weight(900.000000) hght(500.000000) 
master(14): 
    coords: Weight(900.000000) hght(600.000000) 
master(15): 
    coords: Weight(900.000000) hght(700.000000) 
master(16): 
    coords: Weight(900.000000) hght(800.000000) 
master(17): 
    coords: Weight(900.000000) hght(900.000000) 

this might avoid some confusion, since in the above example setting Weight to 100 and hght to 800 won't have any effect. There are quite some fonts which have these kind of quirks.

should that be then an option like -printmetrics but then -printvariations (or similar)?

However, I think I'm going to change at least the name of the function

Which name would you rather have for the function? I'd be happy to adjust it and send a new PR. Do you prefer a single PR, or a PR per change?

Chlumsky commented 2 years ago

I meant that there should be just a function to fetch all the possible axis names and value ranges, not that there should also be a command line option for it. I will also have to update the old Windows build because it uses an old FreeType library that is committed in the repo and it probably doesn't support variable fonts.

Please just do one pull request, I will then merge it into a new branch, clean it up to my liking and then release it.

themancalledjakob commented 2 years ago

I meant that there should be just a function to fetch all the possible axis names and value ranges, not that there should also be a command line option for it.

Got it. I will not touch the command line interface and just add the functions.

I will also have to update the old Windows build because it uses an old FreeType library that is committed in the repo and it probably doesn't support variable fonts

In both win32 and win64 libs in this repo the necessary functions and a reference to freetype-2.9.1 are present. Don't have a windows machine here to verify it, but chances are good that you don't need to update it. Would make sense, since variable font support was added roughly 5 years ago in freetype-2.8.

Please just do one pull request, I will then merge it into a new branch, clean it up to my liking and then release it.

Sounds great. I will be travelling today and have some time freed up for it during the weekend.

themancalledjakob commented 2 years ago

Hey @Chlumsky , sorry for the delay.

There is now a simple function to fetch all the possible axis names and value ranges. I hesitated a bit to introduce a struct for the axis, but don't see another way to avoid dealing with freetype's number types.

You said you'd like to adjust it as you please, but let me know if there is something you'd like me to do.

Chlumsky commented 2 years ago

@themancalledjakob Please see the feature-variable-fonts branch and let me know if you have any comments. The CLI is used as -varfont "myfont.ttf?var1=0.5&var2=1" 'A'

I have two concerns though: