How remove extra spaces from character using QFontMetrics?
-
wrote on 18 Feb 2023, 09:48 last edited by
-
wrote on 19 Feb 2023, 09:44 last edited by
is there someone that can help me removing extra spaces from character?
-
wrote on 19 Feb 2023, 11:15 last edited by JonB
@zabitqt
I do not know what these extra spaces you show are/come from. Certainly I would not expect printingHello
in a font to produce as much spacing as that. There is a picture at int QFontMetrics::horizontalAdvance(QChar ch) const, but I don't think your spacing is to do with that? Suggest you provide a minimal compilable example. -
wrote on 20 Feb 2023, 08:47 last edited by
Smart people with knowledge of typography have decided this behavior long before computers were a thing. If you don't know typography it is a bad idea to change this.
Have a look at kerning and letter spacing inside the QFont class.
-
@zabitqt
I do not know what these extra spaces you show are/come from. Certainly I would not expect printingHello
in a font to produce as much spacing as that. There is a picture at int QFontMetrics::horizontalAdvance(QChar ch) const, but I don't think your spacing is to do with that? Suggest you provide a minimal compilable example. -
@JonB If I draw Hello I see it correctly but if I draw character per character I see a space between character.
-
@JonB If I draw Hello I see it correctly but if I draw character per character I see a space between character.
wrote on 21 Feb 2023, 07:32 last edited by@zabitqt said in How remove extra spaces from character using QFontMetrics?:
If I draw Hello I see it correctly but if I draw character per character I see a space between character.
This is because the font has embedded information how to adjust the distance between specific neighboring characters. If you draw them separately, this information is lost for the font renderer.
Here is the definition of kerning from Wikipedia:
In typography, kerning is the process of adjusting the spacing between characters in a proportional font, usually to achieve a visually pleasing result. Kerning adjusts the space between individual letterforms.
I am not sure if Qt provides any way to get to this kind of information. You can disable kerning (for a whole word and not individual letters) and see if you get the same result when you are drawing the letters separately. If this is the case you know that you need to further research kerning.
1/7