# Thread: QPainter and Freetype bitmap glyph rendering using fractional point coordinates

1. Beginner
Join Date
Apr 2010
Posts
1
Qt products
Platforms

## QPainter and Freetype bitmap glyph rendering using fractional point coordinates

Hi,

We are implementing WYSWYWG editor and writing Font Rendering Engine to comply our needs. We need glyph modifications at runtime and the same look and feel on different platforms, that's why we went implementing own Font Render engine (with Qt font engine we had several troubles with look and feel similarity).

Our layout is scalable that's why we need fractional point advances.

Trying to put glyph on QPainter canvas using drawImage() leads to discrete 1 pixel-based distance between glyphs.

Here's an screenshot of this Screenshot 2015-12-09 19.22.56.png.

I know the problem can be partially solved using sub-pixel positioning. Can you please help to extend this approach on QPainter usage (Antialisasing hint is turned on). I need some kind of algorithm to do it or proof it's not possible.

For now we don't use LCD sub-pixel-antialiased glyphs, just A8 glyphs for simplicity. We disabled hinting either.

How I understand this, how we try to implement this (please fix me if you see an error in algorithm, I'm just new to this):

drawTextRun(run) pseudo code:

0. pen=(0,0)
1. spp = calculateSubpixelPosition(pen) // round to 1/4 pixel fraction, so 3 different glyphs per 1 symbol
2. glyph = glyphCache.getGlyph(run[i], pixelSize, spp)
3. advance = glyph.getAdvance() // advance is in FRACTIONAL, like 8.345
4. painter.drawImage(QPointF(glyph.x, glyph.y), glyph.image); // When drawing image using fractional point coords QImage floors/rounds coordinates?!
5. painter.translate(QPointF(advance,0));
6. i = i+1, repeat from 2

getGlyph() creates 1 of 3 glyphs representations, calling FT_Outline_Translate() to move glyph to the right on 1/4*x fractions.

BUT drawImage still places image flooring/rounding fractional coordinates to int, so it ruins sub-pixel positioning work!

I'd be very grateful for any hint to solve this problem. We need this ASAP.

Thanks a lot for any hint/help on the issue!
Last edited by leaxdc; 9th December 2015 at 19:07.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.