📄 font.c
字号:
if (anchor & HCENTER) { xDest -= ((width) / 2); } yDest = y; if (anchor & BOTTOM) { yDest -= fontHeight; } if (anchor & BASELINE) { yDest -= fontHeight - fontDescent; } yLimit = fontHeight; xStart = 0; xCharSource = 0; yCharSource = 0; /* * Don't let a bad clip origin into the clip code or the may be * over or under writes of the destination buffer. * * Don't change the clip array that was passed in. */ if (clipX1 < 0) { clipX1 = 0; } if (clipY1 < 0) { clipY1 = 0; } diff = clipX2 - dest->width; if (diff > 0) { clipX2 -= diff; } diff = clipY2 - dest->height; if (diff > 0) { clipY2 -= diff; } if (clipX1 >= clipX2 || clipY1 >= clipY2) { /* Nothing to do. */ return; } /* Apply the clip region to the destination region */ diff = clipX1 - xDest; if (diff > 0) { width -= diff; xDest += diff; while (diff > 0 && n > 0) { int w = gx_port_get_charswidth(FONTPARAMS, charArray, 1); if (diff < w) { xStart = diff; break; } diff -= w; charArray++; n--; } if (n <= 0) { return; } } diff = (xDest + width) - clipX2; if (diff > 0) { width -= diff; while (diff > 0 && n > 0) { int w = gx_port_get_charswidth(FONTPARAMS, charArray+n-1, 1); if (diff < w) { break; } diff -= w; n--; } if (n <= 0) { return; } } diff = clipY1 - yDest; if (diff > 0) { yCharSource += diff; yDest += diff; } diff = (yDest + fontHeight) - clipY2; if (diff > 0) { yLimit -= diff; } if (width <= 0 || yCharSource >= yLimit || nCharsToSkip >= n) { /* Nothing to do. */ return; } widthRemaining = width; if (xStart != 0) { int startWidth; fontWidth = gx_port_get_charswidth(FONTPARAMS, charArray, 1); startWidth = fontWidth - xStart; /* Clipped, draw the right part of the first char. */ drawCharImpl(dest, charArray[nCharsToSkip], (gxj_pixel_type)pixel, xDest, yDest, xStart, yCharSource, fontWidth, yLimit, TheFontBitmap, TheFontBitmapSize, fontWidth, fontHeight); nCharsToSkip++; xDest += startWidth; widthRemaining -= startWidth; } /* Draw all the fully wide chars. */ for (i = nCharsToSkip; i < n; i++) { fontWidth = gx_port_get_charswidth(FONTPARAMS, charArray+i, 1); if (widthRemaining < fontWidth) { break; } // TODO: if the character is not clipped vertically, use // the compiled_glyph_drawer instead. drawCharImpl(dest, charArray[i], (gxj_pixel_type)pixel, xDest, yDest, 0, yCharSource, fontWidth, yLimit, TheFontBitmap, TheFontBitmapSize, fontWidth, fontHeight); widthRemaining -= fontWidth; xDest += fontWidth; } if (i < n && widthRemaining > 0) { fontWidth = gx_port_get_charswidth(FONTPARAMS, charArray+i, 1); /* Clipped, draw the left part of the last char. */ drawCharImpl(dest, charArray[i], (gxj_pixel_type)pixel, xDest, yDest, 0, yCharSource, widthRemaining, yLimit, TheFontBitmap, TheFontBitmapSize, fontWidth, fontHeight); }}/** * Obtains the ascent, descent and leading info for the font indicated. * * @param face The face of the font (Defined in <B>Font.java</B>) * @param style The style of the font (Defined in <B>Font.java</B>) * @param size The size of the font (Defined in <B>Font.java</B>) * @param ascent The font's ascent should be returned here. * @param descent The font's descent should be returned here. * @param leading The font's leading should be returned here. */voidgx_port_get_fontinfo(FONTPARAMS_PROTO, int *ascent, int *descent, int *leading) { REPORT_CALL_TRACE(LC_LOWUI, "LCDUIgetFontInfo()\n"); /* Surpress unused parameter warnings */ (void)face; (void)size; (void)style;#if USE_NATIVE_FONT { FastFontInfo *info = &systemFontInfo; *ascent = info->ascent; *descent = info->descent; *leading = info->leading; }#else *ascent = TheFontBitmap[FONT_ASCENT]; *descent = TheFontBitmap[FONT_DESCENT]; *leading = TheFontBitmap[FONT_LEADING];#endif}/** * Gets the advance width for the first n characters in charArray if * they were to be drawn in the font indicated by the parameters. * * <p> * <b>Reference:</b> * Related Java declaration: * <pre> * charWidth(C)I * </pre> * * @param face The font face to be used (Defined in <B>Font.java</B>) * @param style The font style to be used (Defined in * <B>Font.java</B>) * @param size The font size to be used. (Defined in <B>Font.java</B>) * @param charArray The string to be measured * @param n The number of character to be measured * @return The total advance width in pixels (a non-negative value) */intgx_port_get_charswidth(int face, int style, int size, const jchar *charArray, int n) {#if USE_NATIVE_FONT { HWND hwnd; HDC hdc; HFONT old; SIZE size; int w = 0; int i; FastFontInfo *info = &systemFontInfo; for (i=0; i<n; i++) { jchar c = charArray[i]; if (IS_FAST_GLYPH(c)) { w += (int)info->widths[FASTIDX(c)]; } else { break; } } if (i == n) { return w; } hwnd = (HWND)winceapp_get_window_handle(); hdc = GetDC(hwnd); if (hdc != NULL) { int retval; old = SelectObject(hdc, info->hfont); GetTextExtentPoint32W(hdc, charArray, n, &size); retval = size.cx; SelectObject(hdc, old); ReleaseDC(hwnd, hdc); return retval; } }#endif /* Surpress unused parameter warnings */ (void)face; (void)size; (void)style; (void)charArray; return n * TheFontBitmap[FONT_WIDTH];}int wince_init_fonts() {#if USE_NATIVE_FONT HFONT font; LOGFONT logfont; int height; int is_raster; int screenWidth = winceapp_get_screen_width(); int screenHeight = winceapp_get_screen_height(); BOOLEAN fPocketPC = TRUE; TCHAR szPlatform[80]; BOOLEAN bSmooth = FALSE; // Find out if this is a PocketPC or Smartphone platform if (SystemParametersInfo(SPI_GETPLATFORMTYPE, sizeof(szPlatform)/sizeof(TCHAR), szPlatform, 0)) { if (0 == wcsicmp(szPlatform, TEXT("smartphone"))) { fPocketPC = FALSE; } } printf("wince_init_fonts() Platform=%s, screenWidth=%d, screenHeight=%d\n", fPocketPC ? "PocketPC" : "Smartphone", screenWidth, screenHeight); // FIXME: the font size and raster-ness should be stored in a // configuration file so that it's easy to control without // recompilation. if (screenWidth > 320) { is_raster = 0; // FIXME: do not hard code height = 24; } else if (fPocketPC) { is_raster = 1; // FIXME: do not hard code height = 16; //set it to the value suite for your device } else { is_raster = 1; height = 16; } // Note: according to MSDN, "Windows CE 2.0 and later support systems // that use either TrueType or raster fonts, but not both. The OEM // chooses the font type, raster or TrueType, at system design time, // and the application cannot be change the font type." // // So if we are running on a phone without raster font support, we cannot // use bitmap caching (unless we don't use native font but use // the default font from JWC).#if 1 font = (HFONT)GetStockObject(SYSTEM_FONT); if (NULL == font) { printf("wince_init_fonts() ERROR! 0x%X calling GetStockObject()\n",GetLastError()); } SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &bSmooth, FALSE); if (bSmooth) { SystemParametersInfo(SPI_SETFONTSMOOTHING, 0, NULL, SPIF_UPDATEINIFILE); } GetObject(font, sizeof(LOGFONT), &logfont); logfont.lfHeight = height; logfont.lfOutPrecision = OUT_RASTER_PRECIS; logfont.lfQuality = DRAFT_QUALITY; font = CreateFontIndirect(&logfont);#else memset(&logfont, 0, sizeof(logfont)); logfont.lfHeight = height; logfont.lfWidth = 0; logfont.lfEscapement = 0; logfont.lfOrientation = 0; logfont.lfWeight = FW_NORMAL; logfont.lfItalic = 0; logfont.lfUnderline = 0; logfont.lfStrikeOut = 0; logfont.lfCharSet = DEFAULT_CHARSET; logfont.lfOutPrecision = OUT_RASTER_PRECIS; logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; logfont.lfQuality = DRAFT_QUALITY; logfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; logfont.lfFaceName[0] = 0; font = CreateFontIndirect(&logfont);#endif if (font == NULL) { printf("wince_init_fonts(): ERROR! font is NULL!\n"); return 0; } // FIXME: support fonts of other styles as well. init_font(&systemFontInfo, font, is_raster); if (bSmooth) { // restore to old value SystemParametersInfo(SPI_SETFONTSMOOTHING, bSmooth, NULL, SPIF_UPDATEINIFILE); } return 1;#else return 0;#endif}/* * Free the font resource used when the JVM app exits * IMPL_NOTE: call it when exiting from MIDP. *//*void javaImpl_font_finalize() { if (systemFontInfo.hfont!= NULL) { DeleteObject(systemFontInfo.hfont); systemFontInfo.hfont = NULL; } if (systemFontInfo.bitmaps != NULL) { free(systemFontInfo.bitmaps); systemFontInfo.bitmaps = NULL; }}*/#ifdef __cplusplus} // extern "C"#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -