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

📄 drawtext.c

📁 libminigui-1.3.0.tar.gz。 miniGUI的库函数源代码!
💻 C
📖 第 1 页 / 共 2 页
字号:
    }    if (bits == NULL)        return;    fg_rect.x = bbox_x; fg_rect.y = bbox_y;    fg_rect.w = (bbox_w + bold + italic); fg_rect.h = bbox_h;    old_x = *px; old_y = *py;    if (devfont->font_ops->get_char_advance) {        (*devfont->font_ops->get_char_advance) (logfont, devfont, mchar, len, px, py);        if (pdc->bkmode != BM_TRANSPARENT && old_y == *py) {            bg_rect.y = *py - ascent;            bg_rect.h = h;            if (*px > old_x) {                bg_rect.x = old_x;                bg_rect.w = *px - old_x;            }            else {                bg_rect.x = *px;                bg_rect.w = old_x - *px;            }        }        else            bg_rect = fg_rect;    }    else {        *px += bbox_w + bold;        bg_rect = fg_rect;    }    rcOutput.left = MIN (fg_rect.x, bg_rect.x);    rcOutput.top = MIN (fg_rect.y, bg_rect.y);    rcOutput.right = rcOutput.left + MAX (fg_rect.w, bg_rect.w);    rcOutput.bottom = rcOutput.top + MAX (fg_rect.h, bg_rect.h);        if (!IntersectRect (&rcOutput, &rcOutput, &pdc->rc_output))        return;    rcTemp = pdc->rc_output;    pdc->rc_output = rcOutput;    ENTER_DRAWING (pdc);    pdc->step = 1;    pdc->cur_ban = NULL;    if (bg_rect.x != fg_rect.x || bg_rect.y != fg_rect.y            || bg_rect.w != fg_rect.w || bg_rect.h != fg_rect.h) {        pdc->cur_pixel = pdc->bkcolor;        _dc_fillbox_clip (pdc, &bg_rect);    }    bpp = GAL_BytesPerPixel (pdc->surface);    prepare_bitmap (pdc, (bbox_w + bold + italic), bbox_h);    if (pdc->bkmode == BM_TRANSPARENT || italic != 0) {        char_bmp.bmType = BMP_TYPE_COLORKEY;        char_bmp.bmColorKey = pdc->bkcolor;    }    else        char_bmp.bmType = BMP_TYPE_NORMAL;    if (logfont->style & FS_WEIGHT_BOOK            && devfont->font_ops->get_char_pixmap) {        expand_char_pixmap (pdc, bbox_w, bbox_h, bits, char_bmp.bmBits,                bold, italic, pitch);    }    else {        expand_char_bitmap (bbox_w, bbox_h, bits, bpp,                char_bmp.bmBits, pdc->bkcolor, pdc->textcolor, bold, italic);    }    pdc->cur_pixel = pdc->brushcolor;    pdc->skip_pixel = pdc->bkcolor;    _dc_fillbox_bmp_clip (pdc, &fg_rect, &char_bmp);    LEAVE_DRAWING (pdc);    pdc->rc_output = rcTemp;}static void draw_text_lines (PDC pdc, PLOGFONT logfont, int x1, int y1, int x2, int y2){    int h = logfont->size;    RECT eff_rc, rcOutput, rcTemp;    CLIPRECT* cliprect;    if (x1 == x2 && y1 == y2)        return;    SetRect (&rcOutput, x1, y1, x2, y2);    NormalizeRect (&rcOutput);    rcOutput.left -= 1;    rcOutput.top -= h;    rcOutput.right += 1;    rcOutput.bottom += 1;    rcTemp = pdc->rc_output;    pdc->rc_output = rcOutput;    ENTER_DRAWING (pdc);    pdc->cur_pixel = pdc->textcolor;    if (logfont->style & FS_UNDERLINE_LINE) {        cliprect = pdc->ecrgn.head;        while (cliprect) {            if (IntersectRect (&eff_rc, &pdc->rc_output, &cliprect->rc)                        && LineClipper (&eff_rc, &x1, &y1, &x2, &y2)) {                pdc->move_to (pdc, x1, y1);                LineGenerator (pdc, x1, y1, x2, y2, _dc_set_pixel_noclip);            }            cliprect = cliprect->next;       }    }     if (logfont->style & FS_STRUCKOUT_LINE) {        y1 -= h >> 1; y2 -= h >> 1;        cliprect = pdc->ecrgn.head;        while (cliprect) {            if (IntersectRect (&eff_rc, &pdc->rc_output, &cliprect->rc)                        && LineClipper (&eff_rc, &x1, &y1, &x2, &y2)) {                pdc->move_to (pdc, x1, y1);                LineGenerator (pdc, x1, y1, x2, y2, _dc_set_pixel_noclip);            }            cliprect = cliprect->next;        }    }    LEAVE_DRAWING (pdc);    pdc->rc_output = rcTemp;}/* 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;    int origy;    int sbc_height = (*sbc_devfont->font_ops->get_font_height) (pdc->pLogFont, sbc_devfont);    int sbc_ascent = (*sbc_devfont->font_ops->get_font_ascent) (pdc->pLogFont, sbc_devfont);    int mbc_height = 0;    int mbc_ascent = 0;    if (mbc_devfont) {        mbc_height = (*mbc_devfont->font_ops->get_font_height) (pdc->pLogFont, mbc_devfont);        mbc_ascent = (*mbc_devfont->font_ops->get_font_ascent) (pdc->pLogFont, mbc_devfont);    }    y += MAX (sbc_ascent, mbc_ascent); /* convert y-coordinate to baseline */    y += pdc->alExtra;    origx = x;    origy = y;    gdi_start_new_line (pdc->pLogFont);    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_ascent, 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_ascent, text, len_cur_char);        else            break;        left_bytes -= len_cur_char;        text += len_cur_char;        x += pdc->cExtra;    }    draw_text_lines (pdc, pdc->pLogFont, origx, origy, x, y);    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 origx, origy;    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 sbc_ascent = (*sbc_devfont->font_ops->get_font_ascent) (pdc->pLogFont, sbc_devfont);    int mbc_height = 0;    int mbc_ascent = 0;    if (mbc_devfont) {        mbc_height = (*mbc_devfont->font_ops->get_font_height) (pdc->pLogFont, mbc_devfont);        mbc_ascent = (*mbc_devfont->font_ops->get_font_ascent) (pdc->pLogFont, mbc_devfont);    }    y += MAX (sbc_ascent, mbc_ascent);    y += pdc->alExtra;    origx = x; origy = y;    tab_width = (*sbc_devfont->font_ops->get_ave_width) (pdc->pLogFont,                     sbc_devfont) * pdc->tabstop;    line_height = pdc->pLogFont->size + pdc->alExtra + pdc->blExtra;    gdi_start_new_line (pdc->pLogFont);    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_ascent, 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;                draw_text_lines (pdc, pdc->pLogFont, origx, origy, x, y);                origx = x; origy = y;                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_ascent, text, len_cur_char);                x += pdc->cExtra;                break;            }        else            break;       left_bytes -= len_cur_char;       text += len_cur_char;    }    draw_text_lines (pdc, pdc->pLogFont, origx, origy, x, y);    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* x, int* y){    int w;        if (devfont->font_ops->get_char_bbox) {        int oldx = *x;        (*devfont->font_ops->get_char_bbox) (logfont, devfont,                            mchar, len, NULL, NULL, NULL, NULL);        (*devfont->font_ops->get_char_advance) (logfont, devfont, mchar, len, x, y);        w = *x - oldx;    }    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 x = 0, y = 0;    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, &x, &y);                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, &x, &y);            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 x = 0, y = 0;    gdi_start_new_line (log_font);    size->cx = 0;    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, &x, &y);                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, &x, &y);                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 + -