⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 font.c

📁 This is a resource based on j2me embedded,if you dont understand,you can connection with me .
💻 C
📖 第 1 页 / 共 3 页
字号:
                int distance;                if (cursor == 0) {                    // Check if this scanline has a single pixel. If so,                    // we can save one instruction.                    int k;                    for (k=x+1; k<fontWidth; k++) {                        if (is_pixel_set(b[k])) {                            break;                        }                    }                    if (k == fontWidth) {                        // This scanline has only one pixel                        scratch_code[nextcode++] = strh(R1, R0, x*2);                        break;                    }                }                distance = x - cursor;                scratch_code[nextcode++] = strh_preindexed(R1, R0, distance*2);                cursor = x;            }        }        if (cursor > 0) {            scratch_code[nextcode++]= add_imm(R0, -cursor * sizeof(gxj_pixel_type));        }        if (y != maxY) {            scratch_code[nextcode++] = add(R0, R2);        }    }    scratch_code[nextcode++] = mov_imm(R0, fontWidth);    scratch_code[nextcode++] = mov(PC, LR);    func = (int*)pcsl_mem_malloc(sizeof(int) * nextcode);    memcpy(func, scratch_code, sizeof(int) * nextcode);    return func;}static int init_font(FastFontInfo *info, HFONT hfont, int is_raster) {    HWND hwnd = (HWND)winceapp_get_window_handle();    HDC hdc = GetDC(hwnd);    HFONT old;    TEXTMETRIC metric;    int i, height, totalWidth, maxWidth;    if (info == NULL) {        return 0;    }    if (hdc == NULL) {        printf("init_font() ERROR! hdc is NULL!\n");        return 0;    }    info->hfont = hfont;    info->is_raster = is_raster;    old = SelectObject(hdc, info->hfont);    // (1) Get the basic font information    if (!GetTextMetrics(hdc, &metric)) {        printf("init_font() ERROR! 0x%X calling GetTextMetrics()\n",               GetLastError());        return 0;    }    info->ascent  = metric.tmAscent;    info->descent = metric.tmDescent;    info->leading = metric.tmExternalLeading;    height = metric.tmAscent + metric.tmDescent;    totalWidth = 0;    maxWidth = 0;    // (2) Get the widths of each glyph, and also compute its bit offset.    for (i=MIN_FAST_GLYPH; i<MAX_FAST_GLYPH; i++) {        int width;        TCHAR c = (TCHAR)i;        SIZE size;        if (!GetTextExtentPoint32W(hdc, &c, 1, &size)) {            printf("init_font() ERROR! 0x%X calling GetTextExtentPoint32W()\n", GetLastError());        }        width = (int)size.cx;        info->widths[FASTIDX(i)] = (unsigned char)width;        info->bit_offsets[FASTIDX(i)] = height * totalWidth;        totalWidth += width;        if (maxWidth < width) {            maxWidth = width;        }    }    SelectObject(hdc, old);    ReleaseDC(hwnd, hdc);    if (maxWidth & 0x01) maxWidth++; //make it couple, so, the buf inisde  cache_bitmap_and_compile() will be 4-bytes aligned.    info->maxWidth = maxWidth;    if (is_raster) {        // (3) Cache the font bitmap and compile the hot glyphs        return cache_bitmap_and_compile(info, hfont, height, maxWidth,                                        totalWidth);    } else {        return 1;    }}static unsigned char BitMask[8] = {0x80,0x40,0x20,0x10,0x8,0x4,0x2,0x1};static void drawCharImpl(gxj_screen_buffer *sbuf,       jchar c,       gxj_pixel_type pixelColor,       int x, int y,       int xSource, int ySource, int xLimit, int yLimit,       unsigned char *fontbitmap, unsigned long mapLen,       int fontWidth, int fontHeight) {   unsigned int byte1, byte2;   register unsigned int bitmask;   int N;   unsigned long byteIndex;   int bitOffset, xSteps, yDestLimit;   unsigned long pixelIndex;   unsigned long firstPixelIndex;   register gxj_pixel_type *ptr;   int sbufWidth;   gxj_pixel_type *sbufPixelData;   int dstMask;   if (c == ' ') {       return; // hack -- let assume that space is always empty in all               // charsets.   }#if USE_NATIVE_FONT   if (IS_FAST_GLYPH(c)) {       firstPixelIndex = systemFontInfo.bit_offsets[FASTIDX(c)];       fontbitmap = systemFontInfo.bitmaps;       fontWidth = systemFontInfo.widths[FASTIDX(c)];   } else {       return;   }#else   firstPixelIndex = (FONT_DATA * 8) + (c * fontHeight * fontWidth);   if ((firstPixelIndex / 8) >= mapLen) {       /* this character is not supported. */       return;   }#endif   if (fontbitmap == NULL) {       return;   }   sbufWidth = sbuf->width;   sbufPixelData = sbuf->pixelData;   pixelIndex = firstPixelIndex + ySource * fontWidth + xSource;   pixelIndex -= fontWidth;   /* Number of pixels to draw in X direction (1-16) */   xSteps = xLimit - xSource;   /*    * This mask is to check if all the relevant bits in bitmask    * are zero. If so, we can skip the (unrolled) inner loop altogether.    * This happens frequently with lower-case ASCII characters.    */   dstMask = ((int)(1 << 31)) >> (16 + xSteps - 1);   dstMask &= 0x0000ffff;   yDestLimit = y + (yLimit - ySource);   N = y * sbufWidth + x + xSteps - 1;   for (; y < yDestLimit; y++, N += sbufWidth) {       ptr = &sbufPixelData[N];       pixelIndex += fontWidth;       byteIndex = pixelIndex / 8;       byte1 = (unsigned int)fontbitmap[byteIndex];       byte2 = (unsigned int)fontbitmap[byteIndex+1];       bitOffset = pixelIndex % 8;       bitmask = (byte1 << (8 + bitOffset)) | (byte2 << bitOffset);#define UNROLLED_STEP(n) \       if (bitmask & (1 << n)) { \          *ptr = pixelColor; \       } \       ptr --       if ((dstMask & bitmask) != 0) {           switch (xSteps) {           case 16: UNROLLED_STEP( 0);           case 15: UNROLLED_STEP( 1);           case 14: UNROLLED_STEP( 2);           case 13: UNROLLED_STEP( 3);           case 12: UNROLLED_STEP( 4);           case 11: UNROLLED_STEP( 5);           case 10: UNROLLED_STEP( 6);           case  9: UNROLLED_STEP( 7);           case  8: UNROLLED_STEP( 8);           case  7: UNROLLED_STEP( 9);           case  6: UNROLLED_STEP(10);           case  5: UNROLLED_STEP(11);           case  4: UNROLLED_STEP(12);           case  3: UNROLLED_STEP(13);           case  2: UNROLLED_STEP(14);           case  1: UNROLLED_STEP(15);           }       }   }} /* * Draws the first n characters specified using the current font, * color, and anchor point. * * <p> * <b>Reference:</b> * Related Java declaration: * <pre> *     drawString(Ljava/lang/String;III)V * </pre> * * @param pixel Device-dependent pixel value * @param clip Clipping information * @param dst Platform dependent destination information * @param dotted The stroke style to be used * @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 x The x coordinate of the anchor point * @param y The y coordinate of the anchor point * @param anchor The anchor point for positioning the text * @param charArray Pointer to the characters to be drawn * @param n The number of characters to be drawn */voidgx_port_draw_chars(jint pixel, const jshort *clip,                    gxj_screen_buffer *dest,                   int dotted,                   int face, int style, int size,                   int x, int y, int anchor,                    const jchar *charArray, int n) {    int i;    int xStart;    int xDest;    int yDest;    int width;    int yLimit;    int nCharsToSkip = 0;    int xCharSource;    int widthRemaining;    int yCharSource;    int fontWidth;    int fontHeight;    int fontDescent;    int clipX1 = clip[0];    int clipY1 = clip[1];    int clipX2 = clip[2];    int clipY2 = clip[3];    int diff;    REPORT_CALL_TRACE(LC_LOWUI, "LCDUIdrawChars()\n");    if (n <= 0) {        /* nothing to do */        return;    }    if (dest == NULL) {        printf("ERROR: gx_port_draw_chars(): dest == NULL!\n");        return;    }#if USE_NATIVE_FONT    {        HDC hdc;        FastFontInfo *info = &systemFontInfo;        if (info->is_raster &&            anchor == (TOP | LEFT) &&             clipX1 <= 0 && clipY1 <= 0 &&             clipX2 >= dest->width && clipY2 >= dest->height) {            int H = info->ascent + info->descent;            if (x >= 0 && y >= 0 && y + H < dest->height) {                int destWidth = dest->width;                gxj_pixel_type *d = &dest->pixelData[y * destWidth + x];                compiled_glyph_drawer drawer;                for (; n>0; n--, charArray++) {                    jchar c = *charArray;                    int W = info->widths[FASTIDX(c)];                    if (!IS_FAST_GLYPH(c)) {                        break;                    }                    if (x + W >= destWidth) {                        break;                    }                    drawer = info->drawers[FASTIDX(c)];                    if (drawer == NULL) {                        break;                    }                    (drawer)(d, pixel, destWidth*2);                    x += W;                    d += W;                }                if (n == 0) {                    return;                }            }        }        for (i=0; i<n; i++) {            jchar c = charArray[i];            if (!IS_FAST_GLYPH(c)) {                break;            }        }        if (i != n || !info->is_raster) {            printf("gx_port_draw_chars() USE THE SLOW WAY...\n");            // There is at least one glyph that we don't have cached bitmap            // data. Let's call Windows to draw it (slow!)            //            // Or, if the system doesn't use raster font, we must use            // ExtTextOut().            hdc = getScreenBufferHDC(dest->pixelData, dest->width,                                     dest->height);            if (hdc != NULL) {                RECT rect;                HFONT old;                rect.left   = clipX1;                rect.top    = clipY1;                rect.right  = clipX2;                rect.bottom = clipY2;                old = SelectObject(hdc,info->hfont);                SetTextAlign(hdc, CvtRef(anchor));                SetTextColor(hdc, RGB16TORGB24(pixel));                SetBkMode(hdc, TRANSPARENT);                ExtTextOut(hdc, x, y, ETO_CLIPPED, &rect, charArray, n, NULL);                SelectObject(hdc, old);                return;            }        }    }#endif//    REPORT_CALL_TRACE(LC_LOWUI, "LCDUIdrawChars()\n");//    if (n <= 0) {        /* nothing to do *///        return;//    }#if USE_NATIVE_FONT    fontHeight = systemFontInfo.ascent + systemFontInfo.descent;    fontDescent = systemFontInfo.descent;#else    fontHeight = TheFontBitmap[FONT_HEIGHT];    fontDescent = TheFontBitmap[FONT_DESCENT];#endif    width = gx_port_get_charswidth(FONTPARAMS, charArray, n);    xDest = x;    if (anchor & RIGHT) {        xDest -= width;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -