Windows API one-day training (90) getglyphoutline Function

Source: Internet
Author: User
Windows API one-day training (90) getglyphoutline Function

Because of the differences between Chinese and western cultures, the processing in electronic information is also very different. In English, only 26 letters are needed to display all the articles, in Chinese, more than 2000 basic characters are required. For some characters to be displayed in embedded software, you have to manually construct all the images. This is a big workload. If every manufacturer completes this task, obviously, it is impossible. Faced with the needs of a large number of embedded users, it is necessary to solve the problem of Chinese font graphics. After all, we often use Windows. The first thing we think of is how to extract the characters from the image and generate several font libraries we need. The following describes how to use the getglyphoutline function to obtain the graphic data of the displayed characters.

The getglyphoutline function declaration is as follows:

Wingdiapi DWORD winapi getglyphoutlinea (_ in HDC,
_ In uint uchar,
_ In uint fuformat,
_ Out lpglyphmetrics lpgm,
_ In DWORD cjbuffer,
_ Out_bcount_opt (cjbuffer) lpvoid pvbuffer,
_ In const mat2 * lpmat2
);
Wingdiapi DWORD winapi getglyphoutlinew (_ in HDC,
_ In uint uchar,
_ In uint fuformat,
_ Out lpglyphmetrics lpgm,
_ In DWORD cjbuffer,
_ Out_bcount_opt (cjbuffer) lpvoid pvbuffer,
_ In const mat2 * lpmat2
);
# Ifdef Unicode
# Define getglyphoutline getglyphoutlinew
# Else
# Define getglyphoutline getglyphoutlinea
# Endif //! Unicode

HDC is the device handle.
Uchar is a character used to obtain graphic data.
Fuformat is the format for obtaining data.
Lpgm is used to obtain character-related information.
Cjbuffer is the buffer size for storing character data.
Pvbuffer is the buffer for storing character data.
Lpmat2 is the transformation matrix of 3*3.

An example of calling a function is as follows:
#001 // convert floating point data to a fixed floating point number.
#002 fixed fixedfromdouble (double D)
#003 {
#004 long l;
#005 L = (long) (D * 65536l );
#006 return * (fixed *) & L;
#007}
#008
#009 // set the font image transformation matrix.
#010 void setmat (lpmat2 lpmat)
#011 {
#012 lpmat-> em11 = fixedfromdouble (2 );
#013 lpmat-> EM12 = fixedfromdouble (0 );
#014 lpmat-> em21 = fixedfromdouble (0 );
#015 lpmat-> em22 = fixedfromdouble (2 );
#016}
#017
#018 //
#019 // obtain the module information.
#020 // Cai junsheng 2007/12/16 QQ: 9073204 Shenzhen
#021 void testfontglyph (void)
#022 {
#023 // create a font.
#024 hfont = getfont ();
#025
#026 // set the font to the current device.
#027 HDC =: getdc (m_hwnd );
#028 hfont holdfont = (hfont) SelectObject (HDC, hfont );
#029
#030 // set the font image transformation matrix
#031 mat2 mat2;
#032 setmat (& mat2 );
#033
#034
#035 glyphmetrics GM;
#036
#037 // set the characters to be displayed.
#038 tchar chtext = L 'cai ';
#039
#040 // obtain the size of the byte required by the character graph.
#041 DWORD dwneedsize = getglyphoutline (HDC, chtext, ggo_bitmap, & GM, 0, null, & mat2 );
#042 if (dwneedsize> 0 & dwneedsize <0 xFFFF)
#043 {
#044 // allocate memory as needed.
#045 lpbyte lpbuf = (lpbyte) heapalloc (getprocessheap (), heap_zero_memory, dwneedsize );
#046 if (lpbuf)
#047 {
#048 // obtain the data of the character graph to the buffer zone.
#049 getglyphoutline (HDC, chtext, ggo_bitmap, & GM, dwneedsize, lpbuf, & mat2 );
#050
#051 // calculate the number of bytes occupied by each line of the graph.
#052 int nbytecount = (GM. gmblackboxx + 31)> 5) <2;
#053
#054 // display the data of each line of graphics.
#055 for (INT I = 0; I <GM. gmblackboxy; I ++)
#056 {
#057 //
#058 for (Int J = 0; j <nbytecount; j ++)
#059 {
#060
#061 byte btcode = lpbuf [I * nbytecount + J];
#062
#063 // output data of each vertex in bytes.
#064 for (int K = 0; k <8; k ++)
#065 {
#066
#067 if (btcode & (0x80> K ))
#068 {
#069
#070 outputdebugstring (_ T ("1 "));
#071}
#072 else
#073 {
#074 outputdebugstring (_ T ("0 "));
#075}
#076
#077}
#078
#079}
#080
#081 //
#082 outputdebugstring (_ T ("/R/N "));
#083}
#084
#085 //
#086 heapfree (getprocessheap (), 0, lpbuf );
#087}
#088}
#089
#090 //
#091 SelectObject (HDC, holdfont );
#092 deleteobject (hfont );
#093
#094 //
#095 releasedc (m_hwnd, HDC );
#096}
#097

The output result is as follows:
00000000000000010000000000000000
00000000110000011000000000000000
00000000100000011000000000000000
00000000100000011000011000000000
11111111111111111111111100000000
01000000100000011000000000000000
00000000100000011000000000000000
00000100100000011000000000000000
00000110100000010000000000000000
00000100000000000000000000000000
00001100000001000000100000000000
00001111111101111111110000000000
00001000001111000000110000000000
00011000001000100001100000000000
00010100001000100001000000000000
00010010011000100011000000000000
00100011010000010010000000000000
00110010110000011010000000000000
01011000110000001100000000000000
10001000100000001100000000000000
00001001100000010110000000000000
00001011011111111011000000000000
00000010000000000001110000000000
00000110000000000000111100000000
00001100000000000110011100000000
00011111111111111111001000000000
00110000000010000000000000000000
01000000000010000000000000000000
00000001000010000000000000000000
00000011100010001100000000000000
00000011000010000010000000000000
00000110000010000011100000000000
00001100000010000001100000000000
00011000100010000000110000000000
00110000011110000000110000000000
01000000001110000000010000000000
00000000000100000000000000000000

Related Article

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.