grlib中英文混合显示方法,汉字取模非常方便

2019-07-25 15:21发布

<i class="pstatus"> 本帖最后由 allyzc 于 2015-9-30 14:36 编辑 </i><br> <br> <font color="#000"><font face="微软雅黑"><font size="3">本方法从 “基于汉字字模的Stellaris+GUI控件驱动设计.pdf“&nbsp;&nbsp;修改。</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">建立hanzi16x16.c文件:</font></font></font><br> <br> <font color="#000"><font face="微软雅黑"><font size="3">一、在hanzi16x16.c定义汉字字模数据结构:</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">typedef struct{<br> &nbsp; &nbsp;&nbsp;&nbsp;const unsigned char data[32];<font color="#328712">//16*16的汉字占用32个字节</font><br> &nbsp; &nbsp;&nbsp;&nbsp;const unsigned char code[3];<font color="#328712">//汉字内码索引,包含,占用3个字节</font><br> }HanziTypeDef_16x16;<font color="#328712">//16*16汉字字模数据结构</font></font></font></font><br> <br> <font color="#000"><font face="微软雅黑"><font size="3">二、使用PCtoLCD2002制作汉字字模:</font></font></font><br> <br> <font color="#000"><font face="微软雅黑"><font size="3">设置软件取模格式:高位在前</font></font></font><br><p><img src="https://image.xiaopingtou.net/data/attach/191123/dNsreZg2.jpg" alt="111"></p><br> <br> <font color="#000"><font face="微软雅黑"><font size="3">汉字取模,如果汉字多可以使用如下文本的方式。</font></font></font><br><p><img src="https://image.xiaopingtou.net/data/attach/191123/5aRNaKq2.jpg" alt="222"></p><br> <br> <font color="#000"><font face="微软雅黑"><font size="3">三、在hanzi16x16.c文件定义保存字模的数组,直接把数据复制过来就好,不用做任何修改,非常方便。</font></font></font><p><img src="https://image.xiaopingtou.net/data/attach/191123/UdqsbA8Y.jpg" alt="333"><font color="#000000" face="微软雅黑" size="3"><br></font> <font color="#000"><font face="微软雅黑"><font size="3"> <ignore_js_op> </ignore_js_op></font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">四、制作所有英文ansi字模数组,注意格式如下</font></font></font><br><img src="https://image.xiaopingtou.net/data/attach/191123/4S5ptWLf.jpg" alt="444"><br> <font color="#000"><font face="微软雅黑"><font size="3">使用上面所说的文本方式,点击生成英文点阵字库</font></font></font><br><img src="https://image.xiaopingtou.net/data/attach/191123/Fi6j6KD4.jpg" alt="555"><br> <font color="#000"><font face="微软雅黑"><font size="3">在hanzi16x16.c文件定义保存所有英文ansi字模的数组,把点阵数据制过来就好</font></font></font><br><img src="https://image.xiaopingtou.net/data/attach/191123/w5cNYv4l.jpg" alt="666"><br> <font color="#000"><font face="微软雅黑"><font size="3"><font color="#AD0000">如图中红框注释部分编译不通过,要把“ ”里面编译器不认识的删除掉</font></font></font></font><br> <br> <font color="#000"><font face="微软雅黑"><font size="3">五、在grlib.h中的tFont结构体添加一个指向汉字的指针</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">typedef struct<br> {<br> &nbsp; &nbsp; //<br> &nbsp; &nbsp; //! The format of the font.&nbsp;&nbsp;Can be one of FONT_FMT_UNCOMPRESSED or<br> &nbsp; &nbsp; //! FONT_FMT_PIXEL_RLE.<br> &nbsp; &nbsp; //<br> &nbsp; &nbsp; uint8_t ui8Format;<br> <br> &nbsp; &nbsp; //<br> &nbsp; &nbsp; //! The maximum width of a character; this is the width of the widest<br> &nbsp; &nbsp; //! character in the font, though any individual character may be narrower<br> &nbsp; &nbsp; //! than this width.<br> &nbsp; &nbsp; //<br> &nbsp; &nbsp; uint8_t ui8MaxWidth;<font color="#328712">//这里我们用来保存汉字的宽</font><br> <br> &nbsp; &nbsp; //<br> &nbsp; &nbsp; //! The height of the character cell; this may be taller than the font data<br> &nbsp; &nbsp; //! for the characters (to provide inter-line spacing).<br> &nbsp; &nbsp; //<br> &nbsp; &nbsp; uint8_t ui8Height;<font color="#328712">//这里我们用来保存汉字的高 </font><br> <br> &nbsp; &nbsp; //<br> &nbsp; &nbsp; //! The offset between the top of the character cell and the baseline of<br> &nbsp; &nbsp; //! the glyph.&nbsp;&nbsp;The baseline is the bottom row of a capital letter, below<br> &nbsp; &nbsp; //! which only the descenders of the lower case letters occur.<br> &nbsp; &nbsp; //<br> &nbsp; &nbsp; uint8_t ui8Baseline;<br> <br> &nbsp; &nbsp; //<br> &nbsp; &nbsp; //! The offset within pui8Data to the data for each character in the font.<br> &nbsp; &nbsp; //<br> &nbsp; &nbsp; uint16_t pui16Offset[96];<font color="#328712">//这个我们用第一个元素保存有多少个汉字</font><br> <br> &nbsp; &nbsp; //<br> &nbsp; &nbsp; //! A pointer to the data for the font.<br> &nbsp; &nbsp; //<br> &nbsp; &nbsp; const uint8_t *pui8Data<font color="#328712">;//这里我们可以保存英文点阵的指针</font><br> &nbsp; &nbsp; //A pointer to the data for the Chinese font.<br> &nbsp; &nbsp; const uint8_t *CHFontdata;<font color="#AD0000">//这是我们添加的,</font><font color="#AD0000">添加在这里,添加一个指向汉字的指针 </font><br> }<br> tFont;</font></font></font><br> <br> <font color="#000"><font face="微软雅黑"><font size="3">六、设置一个判断标识符来区分当前字符是字母还是汉字, 因此在 grlib.h 中添加汉</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">字标识符:</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">// Indicates that the font data is stored in an uncompressed format.</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">#define FONT_FMT_UNCOMPRESSED 0x00 //</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">//!Indicates that the font data is stored using a pixel-based RLE format.</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">#define FONT_FMT_PIXEL_RLE 0x01</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">//Indicates that the font data is stored in Chinese format.</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">#define FONT_CH_STYLE 0x02</font></font></font><font color="#AD0000"><font face="微软雅黑"><font size="3">//添加在这里</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">七、在grlib.h 中字体声明</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">extern const tFont g_sFontCH16;<br> #define g_psFontCH16 (const tFont *)&amp;g_sFontCH16</font></font></font><br><img src="https://image.xiaopingtou.net/data/attach/191123/ArafwFge.jpg" alt="777"><br> <br> <font color="#000"><font face="微软雅黑"><font size="3">八、定义16*16的字体</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">//***********16x16 的汉字字体结构体***********//<br> const tFont g_sFontCH16=<br> {<br> &nbsp; &nbsp;&nbsp;&nbsp;FONT_CH_STYLE,<font color="#328712">//这里使用我们上面添加的汉字标识符</font><br> &nbsp; &nbsp;&nbsp;&nbsp;16,<font color="#328712">//宽16</font><br> &nbsp; &nbsp;&nbsp;&nbsp;16,<font color="#328712">//高16</font><br> &nbsp; &nbsp;&nbsp;&nbsp;16,<font color="#328712">//这个不知道用来干嘛,我们用不到,随便填</font><br> &nbsp; &nbsp;&nbsp;&nbsp;{(sizeof(Hanzi_16x16)/sizeof(HanziTypeDef_16x16))},<font color="#328712">//记录有多少个汉字,保存在这个数组的第一个元素</font><br> &nbsp; &nbsp;&nbsp;&nbsp;Ansi_8x16,<font color="#328712">//英文点阵指针</font><br> &nbsp; &nbsp;&nbsp;&nbsp;Hanzi_16x16[0].data,<font color="#328712">//汉字点阵指针,用Hanzi_16x16[0]表示指向第一个汉字</font><br> };</font></font></font><br> <br> <font color="#000"><font face="微软雅黑"><font size="3">九、在 Stellaris GUI 中控件的字符显示最终是调用函数 GrStringDraw 完成的,</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">其在 StellarisWaregrlibString.c 中进行了具体的实现。 因此, 在 GrStringDraw</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">中添加实现汉字显示的具体代码:</font></font></font><font color="#000"><font face="微软雅黑"><font size="3">if(pContext-&gt;psFont-&gt;ui8Format == FONT_CH_STYLE )<br> &nbsp; &nbsp; {<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;char *pString = (char *)pcString;<font color="#328712">//取得要显示字符串的指针</font><br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; while ( *pString )<font color="#328712">//判断字符串是否结束</font><br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; {<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if ( *pString &lt; 128 )<font color="#328712">//如果小128,则为字母</font><br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;{<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; LCD_Char_En(pContext, pString, i32X, i32Y);<font color="#328712">//显示一个字母</font><br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; pString += 1;<font color="#328712">//指针指向下一个</font><br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; i32X += (pContext-&gt;psFont-&gt;ui8MaxWidth/2);<font color="#328712">//这里显示的位置向右移动一个字母的宽度</font><br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;{<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;LCD_Char_Cn(pContext, pString, i32X, i32Y);<font color="#328712">//大于128则表示是汉字</font><br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;pString += 2;<font color="#328712">//为什么加2呢,因为汉字的保存就是保存汉字的内码,占用2个字节</font><br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;i32X += pContext-&gt;psFont-&gt;ui8MaxWidth;<font color="#328712">//这里显示的位置向右移动一个汉字的宽度</font> <br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; return;<br> &nbsp; &nbsp; }</font></font></font><br><br> <img src="https://image.xiaopingtou.net/data/attach/191123/MBs50PKq.jpg" alt="888"><br> <font color="#000"><font face="微软雅黑"><font size="3">十 、因为上面调用了函数LCD_Char_En(pContext, pString, i32X, i32Y);//在LCD上显示一个字母</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">所以在string.c中添加它的实现代码</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">void LCD_Char_En(const tContext *pContext, char *acsii, uint16_t x, uint16_t y)</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">{&nbsp; &nbsp;&nbsp; &nbsp; </font></font></font><br> </p><blockquote>uint8_t temp, t;<br> uint8_t xpos;<font color="#328712">//记录横向的字节标识</font><br> uint8_t ypos;<font color="#328712">//记录纵向的字节标识</font><br> <br> <font color="#328712">//一行中有多少个字节,8*16的英文,就是宽度为8,一个字节8位,刚好一个字节</font><br> <font color="#328712">//更直观应该是(pContext-&gt;psFont-&gt;ui8MaxWidth)/2/8,</font><br> uint8_t hByteSize = (pContext-&gt;psFont-&gt;ui8MaxWidth/16);<br> <br> <font color="#328712">//获取一个英文字模纵向多少有行,8*16的英文,就是16行</font><br> uint8_t vSize = pContext-&gt;psFont-&gt;ui8Height;<br> <br> <font color="#328712">//这里获取这次字母点阵第一个数据的地址,pui8Data就是上面保存英文点阵的指针</font><br> <font color="#328712">//pui8Data[(*acsii)*hByteSize*vSize]就是我们所需,为什么是(*acsii)*hByteSize*vSize</font><br> <font color="#328712">//在做英文字模时就是按acsii顺序排列的,如A即在65位置,</font><br> <font color="#328712">//如8*16英文,即65*横向所需字节1*纵向的行数16,之间的8*16个字节都是这个字母的数据</font><br> acsii = (char *)&amp;pContext-&gt;psFont-&gt;pui8Data[(*acsii)*hByteSize*vSize];<br> <br> for ( ypos = 0 ; ypos &lt; vSize; ypos++ )<br> {<br> </blockquote><blockquote><blockquote>for (xpos=0; xpos<hbytesize; xpos++)<="" blockquote=""><blockquote>{</blockquote></hbytesize;></blockquote><blockquote><blockquote><blockquote>temp = *acsii;<font color="#328712">//取得具体字节数据</font></blockquote></blockquote><blockquote><blockquote>for(t=0; t&lt;8; t++)</blockquote></blockquote><blockquote><blockquote>{</blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><blockquote>if(temp &amp; 0x80)</blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>{</blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>GrPixelDraw(pContext, x+(xpos*8)+t, y+ypos);<font color="#328712">//这个就是画点了</font></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>}</blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>temp &lt;&lt;= 1;</blockquote></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>}</blockquote></blockquote><blockquote><blockquote>acsii++;<font color="#328712">//指向下一个字节</font></blockquote></blockquote></blockquote><blockquote><blockquote>} </blockquote></blockquote><blockquote>}</blockquote><font color="#000"><font face="微软雅黑"><font size="3">}</font></font></font><br> <br> <font color="#000"><font face="微软雅黑"><font size="3">11、因为上面调用了函数LCD_Char_Cn(pContext, pString, i32X, i32Y);//在LCD上显示一个汉字</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">所以在string.c中添加它的实现代码,和上面的差不多</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">void LCD_Char_Cn(const tContext *pContext, char *hanzi, uint16_t x, uint16_t y)&nbsp; &nbsp; <br> {&nbsp; &nbsp;&nbsp; &nbsp;<br> &nbsp; &nbsp;&nbsp;&nbsp;uint8_t temp, t;<br> &nbsp; &nbsp;&nbsp;&nbsp;uint8_t xpos;<br> &nbsp; &nbsp;&nbsp;&nbsp;uint8_t ypos;</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">&nbsp; &nbsp;&nbsp;&nbsp;<font color="#328712">//下面的表示一个汉字字模所占的字节数,16*16的点阵</font></font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3"><font color="#328712">&nbsp; &nbsp;&nbsp;&nbsp;//就是纵向行数16*横向字节数2+汉字内码和即3=35个字节</font></font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3"><font color="#328712">&nbsp; &nbsp;&nbsp;&nbsp;//也就是上面定义的HanziTypeDef_16x16结构体的大小35</font><br> &nbsp; &nbsp;&nbsp;&nbsp;uint8_t hzASize = pContext-&gt;psFont-&gt;ui8Height*pContext-&gt;psFont-&gt;ui8MaxWidth/8+3;</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">&nbsp; &nbsp;&nbsp;&nbsp;<font color="#328712">//横向所需字节,如16*16的汉字,就是横向占用2个字节</font><br> &nbsp; &nbsp;&nbsp;&nbsp;uint8_t hByteSize = (pContext-&gt;psFont-&gt;ui8MaxWidth/8);<br> &nbsp; &nbsp;&nbsp;&nbsp;uint16_t hanziId = getHanziId(pContext, hanzi);//这里多了一个获取汉字的位置<br> <br> &nbsp; &nbsp;&nbsp;&nbsp;if ( hanziId == 0xffff )<br> &nbsp; &nbsp;&nbsp;&nbsp;{<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;return;<font color="#328712">//如果是0xffff,表示取不到汉字的位置,即没有这个汉字的字模,直接反回</font><br> &nbsp; &nbsp;&nbsp;&nbsp;}<br> &nbsp; &nbsp; <font color="#328712"> //这里获取这次汉字字模第一个数据的地址,如16*16的汉字</font></font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3"><font color="#328712">&nbsp; &nbsp;&nbsp;&nbsp;// 第5个汉字的字模第一个数据的地址 就是5*35的位置</font><br> &nbsp; &nbsp;&nbsp;&nbsp;hanzi = (char *)&amp;pContext-&gt;psFont-&gt;CHFontdata[hanziId*hzASize];</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">&nbsp; &nbsp;&nbsp;&nbsp;<font color="#328712">//上面的上英文的一样</font><br> &nbsp; &nbsp;&nbsp;&nbsp;for ( ypos = 0 ; ypos &lt; (pContext-&gt;psFont-&gt;ui8Height); ypos++ )<br> &nbsp; &nbsp;&nbsp;&nbsp;{<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; for (xpos=0; xpos<hbytesize; xpos++)<br=""> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; {<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;temp = *hanzi;<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;for(t=0; t&lt;8; t++)<br><!--8--> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;{<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(temp &amp; 0x80)<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; GrPixelDraw(pContext, x+(xpos*8)+t, y+ypos);<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;temp &lt;&lt;= 1;<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;hanzi++;<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br> &nbsp; &nbsp;&nbsp;&nbsp;}<br> &nbsp; &nbsp; <br> }</hbytesize;></font></font></font><br> <br> <font color="#000"><font face="微软雅黑"><font size="3">12、获取汉字位置uint16_t getHanziId(const tContext *pContext, char *hanzi)</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">所以在string.c中添加它的实现代码</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">uint16_t getHanziId(const tContext *pContext, char *hanzi)<br> {<br> &nbsp; &nbsp;&nbsp;&nbsp;uint16_t i = 0;</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">&nbsp;&nbsp;<font color="#328712">&nbsp; &nbsp;//表示一个汉字字模所占的字节数如16*16汉字即16*2+3=35了</font></font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">&nbsp; &nbsp;&nbsp;&nbsp;uint8_t hzASize = pContext-&gt;psFont-&gt;ui8Height*pContext-&gt;psFont-&gt;ui8MaxWidth/8+3;<br> &nbsp; &nbsp;&nbsp;&nbsp;<font color="#328712">//这里i从1开始,如果汉字内码2个都相同,即找到了汉字所在的位置</font></font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3"><font color="#328712">&nbsp; &nbsp;&nbsp;&nbsp;//为什么是-3,-2呢,比如第一个汉字35-3,35-2就是汉字内码的第一和第二个字节</font><br> &nbsp; &nbsp;&nbsp;&nbsp;for (i = 1; i &lt;= pContext-&gt;psFont-&gt;pui16Offset[0]; ++i)<br> &nbsp; &nbsp;&nbsp;&nbsp;{<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if ((hanzi[0] == pContext-&gt;psFont-&gt;CHFontdata[hzASize*i-3]) &amp;&amp;<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;(hanzi[1] == pContext-&gt;psFont-&gt;CHFontdata[hzASize*i-2]))<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; {<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;return i-1;<font color="#328712">//因为上面i从1开始,返回i-1,即数组下标是从0开始的</font><br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br> &nbsp; &nbsp;&nbsp;&nbsp;}<br> &nbsp; &nbsp;&nbsp;&nbsp;return 0xffff;<font color="#328712">//找不到所需的汉字</font><br> }</font></font></font><br> <br> <font color="#000"><font face="微软雅黑"><font size="3">附上效果图</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">GrContextFontSet(&amp;g_sContext, g_psFontCH16);</font></font></font><br> <font color="#000"><font face="微软雅黑"><font size="3">GrStringDraw(&amp;g_sContext, "检测到SD卡,正在读取", -1, 132, 89, 0);</font></font></font><br><img src="https://image.xiaopingtou.net/data/attach/191123/igF8Hr6T.jpg" alt="999"><br> <font color="#000"><font face="微软雅黑"><font size="3">附上PDF版:</font></font></font> <ignore_js_op> <img src="data/attach/1907/tr1f7jolrymw7z41xvgo65y8jwcxf3r1.jpg" border="0" class="vm" alt=""> <span style="white-space: nowrap" id="attach_510806" onmouseover="showMenu({'ctrlid':this.id,'pos':'12'})"> <a href="http://bbs.21ic.com/forum.php?mod=attachment&aid=NTEwODA2fGQ1ODRiNjQ0fDE1NjQwMzA5MjN8MHwxMTMwODI4" target="_blank">grlib中英文混合显示方法,汉字取模非常方便.pdf</a> <em class="xg1">(735.28 KB, 下载次数: 13)</em> </span> 2015-9-30 14:36 上传 点击文件名下载附件 </ignore_js_op> <br> <font color="#000"><font face="微软雅黑"><font size="3">源代码:pan.baidu.com/s/1c0whlOc</font></font></font><br> </blockquote><p><br></p><p></p><p><br></p>
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。