TrueType字符可以轻松拉伸吗? [英] Can TrueType chars easily be stretched?

查看:93
本文介绍了TrueType字符可以轻松拉伸吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要绘制的某些字符需要保持其宽度,但高度要可变地伸展.几年前,我们使用抗锯齿算法尝试了StretchBlt(),但是我对此结果感到不满意.速度较慢,但​​最重要的是,TrueType普通字符在图形和抗锯齿效果上要干净得多.我讨厌由于我们的刮痕"和抗锯齿而导致的质量下降.

为了保持TrueType的抗锯齿效果,是否可以直接使用字体的高度和宽度或通过上述以外的其他方式拉伸字符?还有其他建议吗?

图纸的质量必须一流.

谢谢.

第二次修改


[...]关于CreateFont() width参数的问题是,文档说这是字体字符的平均宽度[...].那么这是否意味着我(将不得不)只创建单字符字体(其中只有一个字符的字体),如果我走了那么远,width参数是否可以为我提供所需的精度?还有其他方法吗?[...]

第三和第四次修改

我仍然不明白指定lfWidth参数的含义,该参数记录为字体中字符的平均宽度".字符宽度各不相同,这是否会使我无法设置目标字符的精确宽度?字体不必具有相同宽度的字符就可以工作,还是有另一种方式可以做到这一点.

我是否仅使用自定义符号/字符的属性表来重新创建比率?或者,就像通过GetTextExtent()获取文本宽度一样简单.我想真正的问题是,当lfWidth设置为0时,如何获得该正常纵横比的句柄,以便我可以说从该正常宽度开始,然后从该宽度逐渐减小? ="h2_lin">解决方案

StretchBlt()与TrueType无关.反正不是直接的. StretchBlt()是用于将图像刷写到设备上下文中的函数.如果使用此功能输出文本,则已经将文本渲染到正变白的图像上,这意味着TrueType字体中包含的所有矢量信息都会丢失.

我建议您看一下CreateFont [Indirect]()/DrawString()/TextOut().确保查看一下CreateFont()的质量参数.


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(..);
}



替代解决方案(用于静态字体集合)
第一个答案已经给出了:)


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?

解决方案

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().


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 :)


这篇关于TrueType字符可以轻松拉伸吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆