void SetFntNum(int32_t k, void* parent /* dvi/vf */) /* this routine is used to specify the font to be used in printing future characters */ { struct font_num *tfontnump=NULL; /* temporary font_num pointer */ switch (((struct font_entry*)parent)->type) { case FONT_TYPE_VF: tfontnump = ((struct font_entry*)parent)->vffontnump; break; case DVI_TYPE: tfontnump = ((struct dvi_data*)parent)->fontnump; } while (tfontnump != NULL && tfontnump->k != k) tfontnump = tfontnump->next; if (tfontnump == NULL) Fatal("font %d undefined", k); currentfont = tfontnump->fontp; if (currentfont->name==NULL) FontFind(currentfont); }
void LcdDisplayStr(u8 xStart, u8 yStart, u8 xEnd, u8 yEnd, FontType_Enum font, u8 align, const char *str, eat_bool update) { u8 x, y, ix, iy, cur_x, cur_x2, cur_y; u8 width, height; FontInfo_Struct fontInfo; const u8 *fontData; const char *p; if(font >= FONT_TYPE_NUM) return; if(str == NULL) return; if(xEnd < xStart) return; if(yEnd < yStart) return; /* 获取高度&宽度 */ p = str; width = 0; height = 0; while(*p != 0) { /* 取字库信息 */ fontData = FontFind(*p, font, &fontInfo); if(fontData != NULL) { width += fontInfo.width; #if defined(CHAR_SPACE_PIXEL) width += CHAR_SPACE_PIXEL; #endif if(fontInfo.height > height) height = fontInfo.height; } p++; } switch(align&LCD_ALIGN_V) { case LCD_ALIGN_V_UP: y = yStart; break; case LCD_ALIGN_V_DOWN: if((yStart+height) > yEnd) y = yStart; else y = yEnd-height-1; break; default: if((yStart+height) > yEnd) y = yStart; else y = yStart + ((yEnd - yStart - height) / 2); break; } switch(align&LCD_ALIGN_H) { case LCD_ALIGN_H_LEFT: x = xStart; break; case LCD_ALIGN_H_RIGHT: if((xStart+width) > xEnd) x = xStart; else x = xEnd-width-1; break; default: if((xStart+width) > xEnd) x = xStart; else x = xStart + ((xEnd - xStart - width) / 2); break; } LcdDisplayClear(xStart, yStart, xEnd, yEnd, EAT_FALSE); p = str; cur_x = x; while(*p != 0) { /* 取字库信息 */ fontData = FontFind(*p, font, &fontInfo); if(fontData != NULL) { /* 字库转换为显示数据 */ cur_y = y; for(iy=0; iy<fontInfo.height; iy++) { cur_x2 = cur_x; for(ix=0; ix<fontInfo.width; ix++) { if((fontData[iy*((fontInfo.width+7)/8) + ix/8] & (1<<(ix%8)))) { M_SetLcdDisplayData(cur_x2, cur_y); } else { M_ClearLcdDisplayData(cur_x2, cur_y); } cur_x2++; if(cur_x2 > xEnd) break; } cur_y++; if(cur_y > yEnd) break; } cur_x += fontInfo.width; #if defined(CHAR_SPACE_PIXEL) cur_x += CHAR_SPACE_PIXEL; #endif if(cur_x > xEnd) break; } p++; } if(update == EAT_TRUE) { LcdUpdate(xStart, yStart, xEnd, yEnd); } }