3

I am trying to draw some text to a canvas, where the same font is used for all characters, but different font styles are used.

To give an example, let us say I want to draw a string to a canvas, with all vowels in bold and all consonants in regular. I also use different colors, but that is probably irrelevant for the problem I facing.

My approach is to anatomize my string and call DrawText in a loop. In each iteration I first call DrawText with DT_CALCRECT and then without. Else I am using the following flags: DT_SINGLELINE or DT_LEFT or DT_VCENTER

The problem I have is that I end up with:

enter image description here

As one can see the vertical centering performed by DrawText is not the same for bold and regular characters.

Any idea which avenue I should go, to have all characters, whether bold or regular at the same level?

  • 6
    When you change the font, you may have to use [`GetTextMetrics()`](https://msdn.microsoft.com/en-us/library/dd144941.aspx) to detect the new padding/alignment settings and adjust your drawing rectangle accordingly. Or maybe use [`SetTextAlign()`](https://msdn.microsoft.com/en-us/library/dd145091.aspx) to change how the text is drawn in relation to the rectangle. – Remy Lebeau Dec 10 '15 at 18:10
  • 2
    Try graphics32 and GR32_Text – David Heffernan Dec 10 '15 at 18:35
  • Remy, you are right about the Text metrics. I wrongly assumed that the bolding would not change the metrics, which is true sometimes but not always, probably less than often. :-) This explains the different centering. – Emmanuel Ichbiah Dec 10 '15 at 19:58

0 Answers0