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

📄 drawtext.c

📁 在ecos 下mingui 的移植开发
💻 C
📖 第 1 页 / 共 2 页
字号:
    case 4:        for (x = 0; x < w << 2; x += 4)            *(uint *) (line + x) = c;        break;    }}/* return width of output */static void put_one_char (PDC pdc, LOGFONT* logfont, DEVFONT* devfont,                int* px, int* py, int h, int descent, const char* mchar, int len){    const BYTE* bits;    BYTE* expanded;    int bbox_x = *px, bbox_y = *py;    int bbox_w, bbox_h, bold = 0, italic = 0;    int line_bytes;    int bpp, pitch = 0;    int old_x, old_y;        if (devfont->font_ops->get_char_bbox) {        (*devfont->font_ops->get_char_bbox) (logfont, devfont,                            mchar, len, &bbox_x, &bbox_y, &bbox_w, &bbox_h);#if 0        fprintf (stderr, "bbox of char '%c (%x)' is (%d, %d, %d, %d).\n", *mchar, *mchar,             bbox_x, bbox_y, bbox_w, bbox_h);#endif    }    else {        bbox_w = (*devfont->font_ops->get_char_width) (logfont, devfont,                 mchar, len);        bbox_h = h;        bbox_y += logfont->size - h + descent;    }    if (logfont->style & FS_WEIGHT_BOLD         && !(devfont->style & FS_WEIGHT_BOLD)) {        bold = 1;    }    if (logfont->style & FS_SLANT_ITALIC        && !(devfont->style & FS_SLANT_ITALIC)) {        italic = (bbox_h - 1) >> 1;    }    if (logfont->style & FS_WEIGHT_BOOK            && devfont->font_ops->get_char_pixmap) {        bits = (*devfont->font_ops->get_char_pixmap) (logfont, devfont,                 mchar, len, &pitch);    }    else {        bits = (*devfont->font_ops->get_char_bitmap) (logfont, devfont,                 mchar, len);    }    if (bits == NULL) {#if 0        fprintf (stderr, "error when get char bitmap: %c!\n", *mchar);#endif        return;    }    old_x = *px; old_y = *py;    if (devfont->font_ops->get_char_advance) {#if 0        fprintf (stderr, "pos of cur char (%c) is (%d, %d)!\n", *mchar, *px, *py);#endif        (*devfont->font_ops->get_char_advance) (logfont, devfont, px, py);#if 0        fprintf (stderr, "pos of next char is (%d, %d)!\n", *px, *py);#endif    /* erase background here */        if (pdc->bkmode != BM_TRANSPARENT && old_y == *py) {            int bk_x, bk_w;            if (*px > old_x) {                bk_x = old_x;                bk_w = *px - old_x;            }            else {                bk_x = *px;                bk_w = old_x - *px;            }            GAL_SetFgColor (pdc->gc, pdc->bkcolor);            GAL_FillBox (pdc->gc, bk_x, old_y, bk_w, h, pdc->bkcolor);         }    }    else        *px += bbox_w + bold;#if 0    if (devfont->font_ops->get_char_bbox || *mchar == 'A') {        int i, j, k, cols;        fprintf (stderr, "pos of char: (%d, %d)!\n", *px, *py);        fprintf (stderr, "bbox of char: (%d, %d, %d, %d)!\n", bbox_x, bbox_y, bbox_w, bbox_h);        cols = (bbox_w + 7)/8;        fprintf (stderr, "cols of char bitmap: (%d)!\n", cols);        for (i = 0; i < bbox_h; i++) {            for (j = 0; j < cols; j++) {                BYTE byte = *(bits + i * cols + j);                for (k = 0; k < 8; k++)                    if (byte & (0x80>>k))                        fprintf (stderr, "*");                    else                        fprintf (stderr, " ");            }            fprintf (stderr, "\n");        }    }#endif    bpp = GAL_BytesPerPixel (pdc->gc);    expanded = get_buffer ((bbox_w + bold + italic) * bbox_h * bpp);    if (pdc->bkmode == BM_TRANSPARENT || italic != 0)            GAL_GetBox (pdc->gc, bbox_x, bbox_y, (bbox_w + bold + italic), bbox_h, expanded);    if (logfont->style & FS_WEIGHT_BOOK            && devfont->font_ops->get_char_pixmap) {        line_bytes = expand_char_pixmap (pdc, bbox_w, bbox_h, bits, expanded,                pdc->bkmode != BM_TRANSPARENT, bold, italic, pitch);    }    else {        line_bytes = expand_char_bitmap (bbox_w, bbox_h, bits, bpp,                expanded, pdc->bkcolor, pdc->textcolor,                 pdc->bkmode != BM_TRANSPARENT, bold, italic);    }    if (!devfont->font_ops->get_char_bbox) {        if (logfont->style & FS_UNDERLINE_LINE) {            BYTE* line = expanded + line_bytes * (h - descent - 1);            fill_line_with_color (line, pdc->textcolor, bbox_w + bold + italic, bpp);        }        if (logfont->style & FS_STRUCKOUT_LINE) {            BYTE* line = expanded + line_bytes * ((h >> 1) - 1);            fill_line_with_color (line, pdc->textcolor, bbox_w + bold + italic, bpp);        }    }    GAL_PutBox (pdc->gc, bbox_x, bbox_y, (bbox_w + bold + italic), bbox_h, expanded);    if (devfont->font_ops->get_char_bbox) {        GAL_SetFgColor (pdc->gc, pdc->textcolor);        if (logfont->style & FS_UNDERLINE_LINE) {            GAL_Line (pdc->gc, old_x, old_y + h - descent, *px, *py + h - descent, pdc->textcolor);        }        if (logfont->style & FS_STRUCKOUT_LINE) {            GAL_Line (pdc->gc, old_x, old_y + (h >> 1), *px, *py + (h >> 1), pdc->textcolor);        }    }}/* return width of output */int gdi_strnwrite (PDC pdc, int x, int y, const char* text, int len){    DEVFONT* sbc_devfont = pdc->pLogFont->sbc_devfont;    DEVFONT* mbc_devfont = pdc->pLogFont->mbc_devfont;    int len_cur_char;    int left_bytes = len;    int origx = x;    int sbc_height = (*sbc_devfont->font_ops->get_font_height) (pdc->pLogFont, sbc_devfont);    int mbc_height = 0;    int sbc_descent = (*sbc_devfont->font_ops->get_font_descent) (pdc->pLogFont, sbc_devfont);    int mbc_descent = 0;    if (mbc_devfont) {        mbc_height = (*mbc_devfont->font_ops->get_font_height) (pdc->pLogFont, mbc_devfont);        mbc_descent = (*mbc_devfont->font_ops->get_font_descent) (pdc->pLogFont, mbc_devfont);    }    gdi_start_new_line (pdc->pLogFont);    y += pdc->alExtra;    while (left_bytes) {        if (mbc_devfont != NULL) {            len_cur_char = (*mbc_devfont->charset_ops->len_first_char) (text, left_bytes);            if (len_cur_char != 0) {                put_one_char (pdc, pdc->pLogFont, mbc_devfont, &x, &y,                                     mbc_height, mbc_descent, text, len_cur_char);                                left_bytes -= len_cur_char;                text += len_cur_char;                x += pdc->cExtra;                continue;            }        }        len_cur_char = (*sbc_devfont->charset_ops->len_first_char) (text, left_bytes);        if (len_cur_char != 0)            put_one_char (pdc, pdc->pLogFont, sbc_devfont, &x, &y,                                     sbc_height, sbc_descent, text, len_cur_char);        else            break;        left_bytes -= len_cur_char;        text += len_cur_char;        x += pdc->cExtra;    }    return x - origx;}int gdi_tabbedtextout (PDC pdc, int x, int y, const char* text, int len){    DEVFONT* sbc_devfont = pdc->pLogFont->sbc_devfont;    DEVFONT* mbc_devfont = pdc->pLogFont->mbc_devfont;    int len_cur_char;    int left_bytes = len;    int x_start = x, max_x = x;    int tab_width, line_height;    int sbc_height = (*sbc_devfont->font_ops->get_font_height) (pdc->pLogFont, sbc_devfont);    int mbc_height = 0;    int sbc_descent = (*sbc_devfont->font_ops->get_font_descent) (pdc->pLogFont, sbc_devfont);    int mbc_descent = 0;    if (mbc_devfont) {        mbc_height = (*mbc_devfont->font_ops->get_font_height) (pdc->pLogFont, mbc_devfont);        mbc_descent = (*mbc_devfont->font_ops->get_font_descent) (pdc->pLogFont, mbc_devfont);    }    gdi_start_new_line (pdc->pLogFont);    tab_width = (*sbc_devfont->font_ops->get_ave_width) (pdc->pLogFont,                     sbc_devfont) * pdc->nDefTabStop;    line_height = pdc->pLogFont->size + pdc->alExtra + pdc->blExtra;    y += pdc->alExtra;    while (left_bytes) {        if (mbc_devfont != NULL) {            len_cur_char = (*mbc_devfont->charset_ops->len_first_char) (text, left_bytes);            if (len_cur_char != 0) {                put_one_char (pdc, pdc->pLogFont, mbc_devfont, &x, &y,                                         mbc_height, mbc_descent, text, len_cur_char);                x += pdc->cExtra;                left_bytes -= len_cur_char;                text += len_cur_char;                continue;            }        }        len_cur_char = (*sbc_devfont->charset_ops->len_first_char) (text, left_bytes);        if (len_cur_char != 0)            switch (*text) {            case '\n':                y += line_height;            case '\r':                if (max_x < x) max_x = x;                x = x_start;            gdi_start_new_line (pdc->pLogFont);            break;            case '\t':                x = x_start + ((x - x_start) / tab_width + 1) * tab_width;                gdi_start_new_line (pdc->pLogFont);            break;            default:                put_one_char (pdc, pdc->pLogFont, sbc_devfont, &x, &y,                                         sbc_height, sbc_descent, text, len_cur_char);                x += pdc->cExtra;            }        else            break;       left_bytes -= len_cur_char;       text += len_cur_char;    }    if (max_x < x) max_x = x;    return max_x - x_start;}int gdi_width_one_char (LOGFONT* logfont, DEVFONT* devfont, const char* mchar, int len, int h){    int w;        if (devfont->font_ops->get_char_bbox) {        int x = 0, y = 0;        (*devfont->font_ops->get_char_bbox) (logfont, devfont,                            mchar, len, NULL, NULL, NULL, NULL);        (*devfont->font_ops->get_char_advance) (logfont, devfont, &x, &y);        w = x;    }    else        w = (*devfont->font_ops->get_char_width) (logfont, devfont, mchar, len);        if (logfont->style & FS_WEIGHT_BOLD         && !(devfont->style & FS_WEIGHT_BOLD)) {        w ++;    }    return w;}void gdi_get_TextOut_extent (PDC pdc, LOGFONT* log_font, const char* text, int len, SIZE* size){    DEVFONT* sbc_devfont = log_font->sbc_devfont;    DEVFONT* mbc_devfont = log_font->mbc_devfont;    int len_cur_char;    int left_bytes = len;    int sbc_height = (*sbc_devfont->font_ops->get_font_height) (log_font, sbc_devfont);    int mbc_height = 0;    if (mbc_devfont)        mbc_height = (*mbc_devfont->font_ops->get_font_height) (log_font, mbc_devfont);        gdi_start_new_line (log_font);    /* FIXME: cy is not the height when rotate font */    size->cy = log_font->size + pdc->alExtra + pdc->blExtra;    size->cx = 0;    while (left_bytes) {        if (mbc_devfont != NULL) {            len_cur_char = (*mbc_devfont->charset_ops->len_first_char) (text, left_bytes);            if (len_cur_char != 0) {                size->cx += gdi_width_one_char (log_font, mbc_devfont,                     text, len_cur_char, mbc_height);                size->cx += pdc->cExtra;                left_bytes -= len_cur_char;                text += len_cur_char;                continue;            }        }        len_cur_char = (*sbc_devfont->charset_ops->len_first_char) (text, left_bytes);        if (len_cur_char != 0) {            size->cx += gdi_width_one_char (log_font, sbc_devfont,                     text, len_cur_char, sbc_height);            size->cx += pdc->cExtra;        }        else            break;        left_bytes -= len_cur_char;        text += len_cur_char;    }}void gdi_get_TabbedTextOut_extent (PDC pdc, LOGFONT* log_font, int tab_stops,                const char* text, int len, SIZE* size, POINT* last_pos){    DEVFONT* sbc_devfont = log_font->sbc_devfont;    DEVFONT* mbc_devfont = log_font->mbc_devfont;    int len_cur_char;    int left_bytes = len;    int tab_width, line_height;    int last_line_width = 0;    int sbc_height = (*sbc_devfont->font_ops->get_font_height) (log_font, sbc_devfont);    int mbc_height = 0;    if (mbc_devfont)        mbc_height = (*mbc_devfont->font_ops->get_font_height) (log_font, mbc_devfont);    gdi_start_new_line (log_font);    size->cy = 0;    tab_width = (*sbc_devfont->font_ops->get_ave_width) (log_font, sbc_devfont)                    * tab_stops;    line_height = log_font->size + pdc->alExtra + pdc->blExtra;    while (left_bytes) {        if (mbc_devfont != NULL) {            len_cur_char = (*mbc_devfont->charset_ops->len_first_char) (text, left_bytes);            if (len_cur_char != 0) {                last_line_width += gdi_width_one_char (log_font, mbc_devfont,                     text, len_cur_char, mbc_height);                last_line_width += pdc->cExtra;                left_bytes -= len_cur_char;                text += len_cur_char;                continue;            }        }        len_cur_char = (*sbc_devfont->charset_ops->len_first_char) (text, left_bytes);        if (len_cur_char != 0)            switch (*text) {            case '\n':                size->cy += line_height;            case '\r':                if (last_line_width > size->cx)                    size->cx = last_line_width;                last_line_width = 0;                gdi_start_new_line (log_font);            break;            case '\t':                last_line_width = (last_line_width / tab_width + 1) * tab_width;                gdi_start_new_line (log_font);            break;            default:                last_line_width += gdi_width_one_char (log_font, sbc_devfont,                             text, len_cur_char, sbc_height);                last_line_width += pdc->cExtra;            }        else            break;        left_bytes -= len_cur_char;        text += len_cur_char;    }    if (last_line_width > size->cx)        size->cx = last_line_width;    if (last_pos) {        last_pos->x += last_line_width;        last_pos->y += size->cy - line_height;    }}

⌨️ 快捷键说明

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