openFrameworks icon indicating copy to clipboard operation
openFrameworks copied to clipboard

ofTrueTypeFont rendering with different dpi

Open dimitre opened this issue 2 years ago • 6 comments

Just getting one subject that arised here https://github.com/openframeworks/openFrameworks/issues/4789#issuecomment-1122578943 to discuss in its own thread

ofTrueTypeFont::setGlobalDpi();

this function doesn't work as expected and letters are scaled.

I think maybe it worth taking a look at FreeType, there are some changes after 2.7.0, I'm not sure which version is being used in OF. https://news.ycombinator.com/item?id=12111747

dimitre avatar May 10 '22 19:05 dimitre

https://github.com/rougier/freetype-gl

dimitre avatar May 11 '22 11:05 dimitre

Yeah I have patched it in latest Apothecary

On Wed, 11 May 2022 at 21:50, Dimitre @.***> wrote:

https://github.com/rougier/freetype-gl

— Reply to this email directly, view it on GitHub https://github.com/openframeworks/openFrameworks/issues/6970#issuecomment-1123642065, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGK2HGMHR55ZGJNC63HVXTVJONGPANCNFSM5VSTSMSA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

danoli3 avatar May 11 '22 12:05 danoli3

@danoli3 yesterday I've updated here it is nice to add the parameter --without-brotli because it was trying to use the one from homebrew and failed, build well after this parameter

dimitre avatar May 11 '22 13:05 dimitre

Compiling now without brotli on all platforms, yeah that fixed a lot of issues

On Wed, 11 May 2022 at 23:27, Dimitre @.***> wrote:

@danoli3 https://github.com/danoli3 yesterday I've updated here it is nice to add the parameter --without-brotli because it was trying to use the one from homebrew and failed, build well after this parameter

— Reply to this email directly, view it on GitHub https://github.com/openframeworks/openFrameworks/issues/6970#issuecomment-1123761911, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGK2HC7HIQF4R52FYZYGXDVJOYTFANCNFSM5VSTSMSA . You are receiving this because you were mentioned.Message ID: @.***>

danoli3 avatar May 11 '22 15:05 danoli3

Ideas: we have to calculate two ratios for different ratios, like this:

	fontScale2 = 72.0/(float)settings.dpi;
	fontScale = (float)settings.dpi/72.0;

Let's say Retina will have 2.0 (double the pixels) and 0.5 (half the dimensions)

set a matrix transformation to scale the font

	matrix.xx = (FT_Fixed)( fontScale2 * 0x10000L );
	matrix.xy = (FT_Fixed)( 0 * 0x10000L );
	matrix.yx = (FT_Fixed)( 0 * 0x10000L );
	matrix.yy = (FT_Fixed)( fontScale2 * 0x10000L );
	FT_Set_Transform( face.get(), &matrix, NULL);

and scale the metrics too. The prototype worked more or less, but there is something about the vertical position of the glyphs that doesn't work well. I think y position is flipped or something.

I think maybe it worth checking this project too https://github.com/rougier/freetype-gl

dimitre avatar May 11 '22 22:05 dimitre

Awesome @dimitre! Any chance to share a coupe of screenshots? Would love to see the higher res fonts working.

ofTheo avatar May 17 '22 21:05 ofTheo