Home > Back-end >  To obtain the vera.ttf character outline related issues
To obtain the vera.ttf character outline related issues

Time:10-09

Himself with the following code to obtain the vera.ttf character outline, use vc6 run successfully, but the point is too little, cause the font is not very smooth, and the great spirit of advice on how to increase access points?

HDC HDC=pDC - & gt; GetSafeHdc ();

//create a font
CFont font;
VERIFY (the font. CreateFont (m_iFontHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, m_sFontFaceName));
CFont * pOldFont=pDC - & gt; SelectObject (& amp; The font);
//definition and initialize the transformation matrix
MAT2 MAT2;
Memset (& amp; Mat2, 0, sizeof (mat2));
Mat2. EM11=1;
Mat2. EM22=1;

GLYPHMETRICS metrics;//save the character information
DWORD dwDataSize=0;//initialize the character data buffer size

//...

//by function GetGlyphOutline () to determine the storage structure of spatial characters
DwDataSize=pDC - & gt; GetGlyphOutline (nChar GGO_NATIVE, & amp; The metrics, 0, NULL, & amp; Mat2);
If ((dwDataSize!=0) & amp; & (dwDataSize!=GDI_ERROR))
{
//create a save character data buffer size
LPBYTE pPixels=new BYTE [dwDataSize];
ASSERT (pPixels!=NULL);
PPixels TTPOLYGONHEADER * pHeader=(TTPOLYGONHEADER *);
DwDataSize=pDC - & gt; GetGlyphOutline (nChar GGO_NATIVE, & amp; The metrics, dwDataSize pPixels, & amp; Mat2);
While (dwDataSize & gt; 0)
{
//calculate the starting point of character contour, conversion coordinates
Int xOld=MapFXY (pHeader - & gt; PfxStart. X);
Int yOld=MapFXY (pHeader - & gt; PfxStart. Y);
//according to obtain the vera.ttf font structure character profile
: : MoveToEx (hDC, iXpos + xOld, iYpos - yOld, NULL);
TTPOLYCURVE * pCurrentCurve=(TTPOLYCURVE *) (pHeader + 1);
Int remainByte=pHeader - & gt; Cb - sizeof (TTPOLYGONHEADER);
While (remainByte & gt; 0)
{
CPoint lpPoint [1000].
CPoint bezi [2].
int index;
For (index=0; The index & lt; PCurrentCurve - & gt; CPFX; + + index)
{
LpPoint [index]. X=iXpos + MapFXY (pCurrentCurve - & gt; Apfx [index]. X);
LpPoint [index] y=iYpos - MapFXY (pCurrentCurve - & gt; Apfx [index] y);
}
The switch (pCurrentCurve - & gt; WType)
{
Case TT_PRIM_LINE:
Case TT_PRIM_QSPLINE:
For (index=0; The index & lt; PCurrentCurve - & gt; CPFX; Index++)
{
: : LineTo (hDC, lpPoint [index]. X, lpPoint [index] y);
}
break;
Default:
MessageBox (_T (" font does not support "));
break;
}
Int count=sizeof (TTPOLYCURVE) + (pCurrentCurve - & gt; CPFX - 1) * sizeof (POINTFX);
PCurrentCurve=(TTPOLYCURVE *) ((char *) pCurrentCurve + count);

RemainByte -=count;
}
: : LineTo (hDC, iXpos + xOld, iYpos - yOld);
DwDataSize -=pHeader - & gt; Cb.
PHeader=(TTPOLYGONHEADER *) ((char *) pHeader + pHeader - & gt; Cb);
}
The delete [] pPixels;
}
}
  • Related