Font information from TTF fonts

Source: Internet
Author: User
Tags vector font

1. Introduction

Traditionally, the type information is usually obtained from the lattice font. However, a fatal disadvantage of lattice fonts is that the size of the font information is fixed, magnified fonts will produce serious sawtooth distortion. This paper introduces a method of obtaining the font information of characters directly from TTF fonts by VC, the obtained font information can reach an approximate infinite resolution, can choose 2, 5, 17 and 65, and so on a variety of gray level, and finally the font information stored as BMP bitmap file format, to facilitate the use of font information.

2, TTF Introduction

TTF is an outline font that Microsoft and Apple have launched together. TTF's main design idea is: Using a series of points to construct the contour, on the basis of a series of instructions to adjust, so that the contour line to smooth, so that good display results. TTF is a vector font, can be used to enlarge the font, rapid deformation and so on, the enlarged font is usually mellow, no sawtooth-shaped distortion. The use of vector fonts for font transformation, such as balance, scaling, rotation, tilt, etc., fast, small distortion, good results, can produce high-quality Chinese character output. Due to the popularity of Windows operating system, TTF has become the mainstream of font display, its resources are quite rich, on Windows itself with hundreds of TTF fonts, the network can be downloaded on the most of the font resources are TTF format. But the traditional dot matrix font, because of its relatively few resources, font size fixed single, in the zoom out is very difficult, the effect is not good, slow, the font monotonous, zigzag distortion serious, it is difficult to achieve aesthetic requirements. Therefore, the use of TTF font to replace the lattice font, in order to obtain more types, more resolution, more gray level of the type information, to meet the needs of the various information of the community, is very necessary.

3. Extract font information of characters in TTF fonts

First, select the TTF font library you want to use in the current DC (Device context) device contexts

CFont newfont;
  newfont.CreateFont(m_intHeight,
      0,
      m_intAngle,
      0,
      m_intBold,
      m_bCheckItalic,
      0,
      0,
      DEFAULT_CHARSET,
      OUT_CHARACTER_PRECIS,
      CLIP_CHARACTER_PRECIS,
      DEFAULT_QUALITY,
      DEFAULT_PITCH|FF_DONTCARE,
      m_strFontName); //m_strFontName为TTF字体名
//m_intHeight设置字体的高度,值越大,最终获取的字模的分辨率越高。
//m_intAngle设置字体的旋转角度,m_intBold设置字体的粗细程度
//m_bCheckItalic设置字体为斜体与否
  CDC* pdc=m_ctlDisplay.GetDC();//获取控件m_ctlDisplay的DC
  CFont *poldfont=pdc->SelectObject(&newfont);//将TTF字体对象选入控件m_ctlDisplay的DC中

Then the main use of Win32 API function Getglyphoutline () to extract the TTF font information

DWORD GetGlyphOutline(
 HDC hdc, // DC句柄
 UINT uChar, // 要提取字模的字符
 UINT uFormat, // 函数返回的信息格式
 LPGLYPHMETRICS lpgm, // GLYPHMETRICS结构的指针
 DWORD cbBuffer, // 接收缓存的大小
 LPVOID lpvBuffer, // 接收缓存的地址
 CONST MAT2 *lpmat2  // MAT2结构的指针
);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.