Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Certain characters I want to draw need to retain their width but stretch variably in height. A few years ago we tried StretchBlt() with an anti-aliasing algorithm but I was unhappy with the result; It was slower but most of all, the TrueType normal char had a much cleaner result in the drawing and the anti-aliasing. I hated losing a bit of quality with the degradation caused by our "blatting" and anti-aliasing.

Is it possible to stretch the character directly using font height and width or by some other means than mentioned above in order to keep TrueType's anti-aliasing? Any other suggestions?

The quality of drawing must be superb.

Thanks.

Second Edit


[...]The thing that throws me about CreateFont() width parameter is that the documentation says it's the average width of the font characters[...]. So does that mean I [would have to] just create single-character-fonts (fonts with only one character in them) and if I went that far, would the width parameter give me the precision I'm looking for? Are there any other ways to do it?[...]

Third and Fourth Edit

I still don't understand what it means to specify an lfWidth parameter which is documented as the "average width" of chars in the font. With varying character widths, won't that keep me from setting a precise width of a target character? Wouldn't the font have to have characters with all the same width for that to work or is there another way to do it.

Do I just use tables of attributes of the custom symbol/character to recreate the ratio? Or, is it as easy as getting the text width with GetTextExtent(). I guess the true question is, how do I get a handle on that normal aspect ratio, as when lfWidth is set to 0, so that I could, say start from that normal width and gradually decrease it from there?
Posted
Updated 22-Feb-10 0:02am
v5

StretchBlt() has nothing to do with TrueType. Not directly anyway. StretchBlt() is a function for blitting an image onto a device context. If you are outputting text using this function, you have already rendered the the text onto the image being blitted, meaning that all vector information contained in the TrueType font is lost.

I advise you to take a look at CreateFont[Indirect]()/DrawString()/TextOut(). Make sure you take a look at the quality-parameter for CreateFont().
 
Share this answer
 
void YourView::OnDraw(CDC* pDC, const CRect& cDrawRect)
{
...
  CFont cFontToDraw;
  CreateCalculatedFont(&cFontToDraw, pDC, cDrawRect);
  
  HGDIOBJ hOldFont = pDC->SelectObject(&cFontToDraw);
...
  pDC->DrawText(..);
...
  pDC->SelectObject(hOldFont);
  cFontToDraw.DeleteObject();
}

void YourView::CreateCalculatedFont(CFont* pcFontToCreate,
                                    CDC* pDC,
                                    const CRect& cDrawRect)
{
  // apply your low to calculate the size of font
  // by using of CDC::GetTextExtension(..) and cDrawRect
  // and create it:
  pcFontToCreate->CreateFontIndirect(..);
}


An alternative solution (for a statical font collection)
has been already given by the first answer :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900