font rendering

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Suntor
Posts: 16
Joined: 2020-03-22T19:04:47-07:00
Authentication code: 1152

Re: font rendering

Post by Suntor »

magick wrote:
2020-03-31T05:43:59-07:00
We will investigate over the next week or two and see if we can resolve the problem.
Any good news?

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: font rendering

Post by magick »

None. The rendering code in ImageMagick looks good. Freetype does have an option to enable better hinting, disabled by default due to patent issues. That may help. If you find an app that does a better job with rendering that uses Freetype, let us know. We'll investigate further.

Suntor
Posts: 16
Joined: 2020-03-22T19:04:47-07:00
Authentication code: 1152

Re: font rendering

Post by Suntor »

magick wrote:
2020-04-14T05:28:12-07:00
Freetype does have an option to enable better hinting, disabled by default due to patent issues. That may help.
How can I use this «option»? A specific flag in the source code of ImageMagick to compile custom version? Or some command-line option in the regular one?

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: font rendering

Post by magick »

The flag is in the Freetype delegate library. Download, read the docs looking for the comment about patents, enable the FLAG as the suggest, build, and install. ImageMagick will then use the improve hinting when it renders.

Suntor
Posts: 16
Joined: 2020-03-22T19:04:47-07:00
Authentication code: 1152

Re: font rendering

Post by Suntor »

magick wrote:
2020-04-14T07:40:42-07:00
The flag is in the Freetype delegate library.
Ok. Thanks. And another question:

Code: Select all

[ImageMagick-7.0.10-2\ImageMagick\MagickCore\draw.c, 4697]
              beta=delta.x*(y-q->y)-delta.y*(x-q->x);
[ImageMagick-7.0.10-3\ImageMagick\MagickCore\draw.c, 4697]
              beta=delta.x*(y-q->y)-delta.y*(x-q->x)+MagickEpsilon;
Is this the only change that relates to improving the «mono font rendering»?

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: font rendering

Post by magick »

No. We had to add to enable the FT_LOAD_RENDER flag. The MagickEpsilon add was to avoid a numerical instability issue which cause certain thin lines to now be drawn when they should.

Suntor
Posts: 16
Joined: 2020-03-22T19:04:47-07:00
Authentication code: 1152

Re: font rendering

Post by Suntor »

magick wrote:
2020-04-14T10:48:12-07:00
We add to add to enable the FT_LOAD_RENDER flag.
Yes, I found it. Not in the v7.0.10-3, but in the next v7.0.10-4, with the «bounds.xMax == 0» label size fix in the same function.
It seems that only the fix («+MagickEpsilon») between v7.0.10-2 and v7.0.10-3 affects the font rendering (artifacts, like a «missing slash»), and there is no difference in font rendering between v7.0.10-3 and newer versions up to v7.0.10-6, despite the addition of the FT_LOAD_RENDER flag in v7.0.10-4.
Image

Suntor
Posts: 16
Joined: 2020-03-22T19:04:47-07:00
Authentication code: 1152

Re: font rendering

Post by Suntor »

Suntor wrote:
2020-04-15T01:55:27-07:00
...despite the addition of the FT_LOAD_RENDER flag in v7.0.10-4.
No. The flag FT_LOAD_RENDER affects drawing. This confusion arose because the source code was confused. The FT_LOAD_RENDER flag is not in the source ImageMagick-7.0.10-3.7z, but ImageMagick-7.0.10-3-Q16-x64-dll.exe contains it!

Suntor
Posts: 16
Joined: 2020-03-22T19:04:47-07:00
Authentication code: 1152

Re: font rendering

Post by Suntor »

Suntor wrote:
2020-03-31T01:14:24-07:00
ASCII character test (-annotate +2+15 @ascii.txt)...
Issue with shift of symbols. «Courier New»:
Image
and «Microsoft Sans Serif»:
Image

I found an error in the code due to which there was a shift of characters in mono mode. The problem was that the value bitmap->left was lost the next time point.x was assigned in the ft_pixel_mode_mono condition. So I changed one line (MagickCore\annotate.c, 1646) to fix it.
Image

And voila. Issue has disappeared.
Image
The «Courier New» font rendering result is identical to Notepad. Except for '\' and 'a' characters.

Image
The «Microsoft Sans Serif» font rendering result is identical to Notepad. Except for '78dgq' characters.

User avatar
dlemstra
Posts: 1625
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: font rendering

Post by dlemstra »

What happens when you change it to: point.x+=(origin.x >> 6);
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

Suntor
Posts: 16
Joined: 2020-03-22T19:04:47-07:00
Authentication code: 1152

Re: font rendering

Post by Suntor »

dlemstra wrote:
2020-04-29T12:36:30-07:00
What happens when you change it to: point.x+=(origin.x >> 6);
Compare the first two pictures, and the last two pictures in my post 2020-04-29T14:31:39+03:00. The issue appeared after adding the FT_LOAD_RENDER flag in v7.0.10-4. This results in incorrect character spacing and text distortion. Compare:
Image

User avatar
dlemstra
Posts: 1625
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: font rendering

Post by dlemstra »

Can you rerun your tests with 7.0.10-10? We made some font rendering fixes between those versions.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

Suntor
Posts: 16
Joined: 2020-03-22T19:04:47-07:00
Authentication code: 1152

Re: font rendering

Post by Suntor »

dlemstra wrote:
2020-04-30T03:34:09-07:00
Can you rerun your tests with 7.0.10-10? We made some font rendering fixes between those versions.
Yes. I downloaded and installed v7.0.10-10. The issue is the same. Need the code fix that I described above.

«Courier New» shifted symbols:
Image
«Microsoft Sans Serif» shifted symbols:
Image

Suntor
Posts: 16
Joined: 2020-03-22T19:04:47-07:00
Authentication code: 1152

Re: font rendering

Post by Suntor »

Suntor wrote:
2020-03-31T01:14:24-07:00

Code: Select all

for /l %i in (8,1,22) do @convert
	-font Microsoft-Sans-Serif -density 96 -pointsize %i +antialias
	label:"%i C:\\test.txt"
	test_%i.png

ren test_8.png test_08.png && ren test_9.png test_09.png && convert test_*.png -append test.png && del test_*.png
Can you fix this issue of merged 't' and '.' symbols? Started from v7.0.10-3 and up to v7.0.10-10:

Image

...by changing one line of code, as I showed earlier:
Suntor wrote:
2020-04-29T04:31:39-07:00
MagickCore\annotate.c, 1646
Image
Image

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: font rendering

Post by magick »

We added the patch as you recommended in the ImageMagick master branch. Thanks.

Locked