arklumpus / VectSharp

A light library for C# vector graphics
GNU Lesser General Public License v3.0
222 stars 22 forks source link

Spacing between letters seems to be wrong #73

Open manutiedra opened 5 hours ago

manutiedra commented 5 hours ago

I was trying to add some spacing between the letters using a non standard font family and it didn't shown as I expected.

Then I tried the standard font family and it also is not showing as I expected.

Here you can see what I've got using VectSharp:

image

The first font is https://fonts.google.com/specimen/Nova+Square The second one is FontFamily.StandardFontFamilies.HelveticaBold

If I do the same in illustrator, setting the tracking to a high value I've got this:

image

That looks a lot better.

I'm drawing the text with VectSharp using:

TextSpacing spacing = new TextSpacing(spacingScale, 0);
frameContent.FillText(xPos, yPos, text, font, color, spacing: spacing, textBaseline: TextBaselines.Middle);

Is the TextSpacing working as expected? How can I achieve spacing like illustrator does?

arklumpus commented 4 hours ago

Hi! You probably want to leave the scaling (first parameter to the TextSpacing constructor) to 1 and change the increment (i.e. the second parameter instead). For example:

TextSpacing spacing = new TextSpacing(1, 3);
frameContent.FillText(xPos, yPos, text, font, color, spacing: spacing, textBaseline: TextBaselines.Middle);

This is because if you change the increment, the amount of space that is added is the same for every letter (which is what you want); instead, if you change the scale, the amount of added space is proportional to the letter width (hence, less space is added after I than after A).

You can have a look at the interactive example here and see how it works!