Windows API-getglyphoutline Function

Source: Internet
Author: User

Http://blog.163.com/lionyue@126/blog/static/107930712007111801736808/

 

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 C, _ 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) lp Void pvbuffer, _ in const mat2 * lpmat2); # ifdef Unicode # define getglyphoutline getglyphoutlinew # else # define getglyphoutline getglyphoutlinea # endif //! Unicode HDCIs the device handle. UcharIs the character to obtain the graphic data. FuformatIs the format for obtaining data. LpgmIs used to obtain character-related information. CjbufferIs the buffer size for storing character data. PvbufferIs the buffer for storing character data. Lpmat2Is the transformation matrix of 3*3. Example of calling a function: #001 // convert floating point data to a fixed floating point data. #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 model 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 // you can specify the characters to display.
#038 tchar chtext = L 'cai '; #039 #040 // obtain the size of the bytes required for this 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. #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 output result: 00000000000000010000000000000000000000001100000110000000000000000000000010000001100000000000000000000000100000011000011000000000111111111111111111111111000000000100000010000001100000000000000000000000100000011000000000000000000001001000000110000000000000000000011010000001000000000000000000000100000000000000000000000000000011000000010000001000000000000000111111110111111111000000000000001000001111000000110000000000000110000010001000011000000000000001010000100010000100000000000000010010011000100011000000000000001000110100000100100000000000000011001011000001101000000000000001011000110000001100000000000000100010001000000011000000000000000000100110000001011000000000000000001011011111111011000000000000000000100000000000011100000000000000011000000000000011110000000000001100000000000110011100000000000111111111111111110010000000000011000000001000000000000000000001000000000010000000000000000000000000010000100000000000000000000000001110001000110000000000000000000011000010000010000000000000000001100000100000111000000000000000110000001000000110000000000000011000100010000000110000000000001100000111100000001100000000000100000000111000000001000000000000000000000100000000000000000000

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.