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

📄 drawtext.c

📁 ARM9-2410教学实验系统下Linux下minigui程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*** $Id: drawtext.c,v 1.31 2003/11/21 13:22:24 weiym Exp $** ** drawtext.c: Low level text drawing.** ** Copyright (C) 2003 Feynman Software.** Copyright (C) 1999 ~ 2002 WEI Yongming.**** Current maintainer: WEI Yongming.**** Create date: 2000/06/15*//*** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.**** This program is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the** GNU General Public License for more details.**** You should have received a copy of the GNU General Public License** along with this program; if not, write to the Free Software** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*//*** TODO:*/#include <stdio.h>#include <stdlib.h>#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "cliprect.h"#include "gal.h"#include "internals.h"#include "ctrlclass.h"#include "dc.h"#include "pixel_ops.h"#include "cursor.h"#include "drawtext.h"static BITMAP char_bmp;static size_t char_bits_size;BOOL InitTextBitmapBuffer (void){    return TRUE;}void TermTextBitmapBuffer (void){    free (char_bmp.bmBits);    char_bmp.bmBits = NULL;    char_bits_size = 0;}static void prepare_bitmap (PDC pdc, int w, int h){    Uint32 size = GAL_GetBoxSize (pdc->surface, w, h, &char_bmp.bmPitch);    char_bmp.bmType = BMP_TYPE_NORMAL;    char_bmp.bmBitsPerPixel = pdc->surface->format->BitsPerPixel;    char_bmp.bmBytesPerPixel = pdc->surface->format->BytesPerPixel;    char_bmp.bmWidth = w;    char_bmp.bmHeight = h;    if (size <= char_bits_size)        return;    char_bits_size = ((size + 31) >> 5) << 5;    char_bmp.bmBits = realloc (char_bmp.bmBits, char_bits_size);}void gdi_start_new_line (LOGFONT* log_font){    DEVFONT* sbc_devfont = log_font->sbc_devfont;    DEVFONT* mbc_devfont = log_font->mbc_devfont;    if (mbc_devfont) {        if (mbc_devfont->font_ops->start_str_output)            (*mbc_devfont->font_ops->start_str_output) (log_font, mbc_devfont);    }    if (sbc_devfont->font_ops->start_str_output)            (*sbc_devfont->font_ops->start_str_output) (log_font, sbc_devfont);}inline static int get_light (int fg, int bg){    return bg + (fg - bg) / 4;}inline static int get_medium (int fg, int bg){    return bg + (fg - bg) * 2 / 4;}inline static int get_dark (int fg, int bg){    return bg + (fg - bg) * 3 / 4;}static void expand_char_pixmap (PDC pdc, int w, int h, const BYTE* bits,             BYTE* expanded, int bold, int italic, int cols){    GAL_Color pal [5];    gal_pixel pixel [5];    int i, x, y;    int b = 0;    BYTE* line;    GAL_GetRGB (pdc->bkcolor, pdc->surface->format, &pal->r, &pal->g, &pal->b);    GAL_GetRGB (pdc->textcolor, pdc->surface->format, &pal[4].r, &pal[4].g, &pal[4].b);    pal [1].r = get_light  (pal [4].r, pal [0].r);    pal [1].g = get_light  (pal [4].g, pal [0].g);    pal [1].b = get_light  (pal [4].b, pal [0].b);    pal [2].r = get_medium (pal [4].r, pal [0].r);    pal [2].g = get_medium (pal [4].g, pal [0].g);    pal [2].b = get_medium (pal [4].b, pal [0].b);    pal [3].r = get_dark  (pal [4].r, pal [0].r);    pal [3].g = get_dark  (pal [4].g, pal [0].g);    pal [3].b = get_dark  (pal [4].b, pal [0].b);    for (i = 0; i < 5; i++) {        pixel [i] = GAL_MapRGB (pdc->surface->format, pal[i].r, pal[i].g, pal[i].b);    }    line = expanded;    switch (GAL_BytesPerPixel (pdc->surface)) {    case 1:        for (y = 0; y < h; y++) {            expanded = line;            for (x = 0; x < (w + bold + italic); x++) {                *(expanded + x) = pixel [0];            }            if (italic)                expanded += (h - y) >> 1;            for (x = 0; x < w; x++) {                b = *(bits+x);                if (b == 255) b = 4;                else if (b >= 128) b = 3;                else if (b >= 64) b = 2;                else if (b >= 32) b = 1;                else if (b >= 0) b = 0;                *expanded = pixel [b];                if (bold)                    *(expanded + 1) = pixel [b];                expanded++;            }            bits += cols;            line += char_bmp.bmPitch;        }    break;    case 2:        for (y = 0; y < h; y++) {            expanded = line;            for (x = 0; x < (w + bold + italic) << 1; x += 2) {                *(Uint16 *) (expanded + x) = pixel [0];            }            if (italic)                expanded += ((h - y) >> 1) << 1;            for (x = 0; x < w; x++) {                b = *(bits+x);                if (b == 255) b = 4;                else if (b >= 128) b = 3;                else if (b >= 64) b = 2;                else if (b >= 32) b = 1;                else if (b >= 0) b = 0;                *(Uint16 *) expanded = pixel [b];                if (bold)                    *(Uint16 *)(expanded + 2) = pixel [b];                expanded += 2;            }            bits += cols;            line += char_bmp.bmPitch;        }    break;    case 3:        for (y = 0; y < h; y++) {            expanded = line;            for (x = 0; x < (w + bold + italic) * 3; x += 3) {                *(Uint16 *) (expanded + x) = pixel [0];                *(expanded + x + 2) = pixel [0] >> 16;            }            if (italic)                expanded += 3 * ((h - y) >> 1);            for (x = 0; x < w; x++) {                b = *(bits+x);                if (b == 255) b = 4;                else if (b >= 128) b = 3;                else if (b >= 64) b = 2;                else if (b >= 32) b = 1;                else if (b >= 0) b = 0;                *(Uint16 *) expanded = pixel[b];                *(expanded + 2) = pixel[b] >> 16;                if (bold) {                    *(Uint16 *)(expanded + 3) = pixel[b];                    *(expanded + 5) = pixel[b] >> 16;                }                                expanded += 3;            }            bits += cols;            line += char_bmp.bmPitch;        }    break;    case 4:        for (y = 0; y < h; y++) {            expanded = line;            for (x = 0; x < (w + bold + italic) << 2; x += 4) {                *(Uint32 *) (expanded + x)= pixel [0];            }            if (italic)                expanded += ((h - y) >> 1) << 2;            for (x = 0; x < w; x++) {                b = *bits++;                if (b == 255) b = 4;                else if (b >= 128) b = 3;                else if (b >= 64) b = 2;                else if (b >= 32) b = 1;                else if (b >= 0) b = 0;                *(Uint32 *) expanded = pixel[b];                if (bold)                    *(Uint32 *) (expanded + 4) = pixel[b];                expanded += 4;            }            line += char_bmp.bmPitch;        }    }}static void expand_char_bitmap (int w, int h,             const BYTE* bits, int bpp, BYTE* expanded,             int bg, int fg, int bold, int italic){    int x, y;    int b = 0;    BYTE* line;    line = expanded;    switch (bpp) {    case 1:        for (y = 0; y < h; y++) {            expanded = line;            for (x = 0; x < (w + bold + italic); x++) {                *(expanded + x) = bg;            }            if (italic)                expanded += (h - y) >> 1;            for (x = 0; x < w; x++) {                if (x % 8 == 0)                    b = *bits++;                if ((b & (128 >> (x % 8)))) {                    *expanded = fg;                    if (bold)                        *(expanded + 1) = fg;                }                expanded++;            }            line += char_bmp.bmPitch;        }    break;    case 2:        for (y = 0; y < h; y++) {            expanded = line;            for (x = 0; x < (w + bold + italic) << 1; x += 2) {                *(Uint16 *) (expanded + x) = bg;            }            if (italic)                expanded += ((h - y) >> 1) << 1;            for (x = 0; x < w; x++) {                if (x % 8 == 0)                    b = *bits++;                if ((b & (128 >> (x % 8)))) {                    *(Uint16 *) expanded = fg;                    if (bold)                        *(Uint16 *)(expanded + 2) = fg;                }                expanded += 2;            }            line += char_bmp.bmPitch;        }    break;    case 3:        for (y = 0; y < h; y++) {            expanded = line;            for (x = 0; x < (w + bold + italic) * 3; x += 3) {                *(Uint16 *) (expanded + x) = bg;                *(expanded + x + 2) = bg >> 16;            }            if (italic)                expanded += 3 * ((h - y) >> 1);            for (x = 0; x < w; x++) {                if (x % 8 == 0)                    b = *bits++;                if ((b & (128 >> (x % 8)))) {                    *(Uint16 *) expanded = fg;                    *(expanded + 2) = fg >> 16;                    if (bold) {                        *(Uint16 *)(expanded + 3) = fg;                        *(expanded + 5) = fg >> 16;                    }                }                                expanded += 3;            }            line += char_bmp.bmPitch;        }    break;    case 4:        for (y = 0; y < h; y++) {            expanded = line;            for (x = 0; x < (w + bold + italic) << 2; x += 4) {                *(Uint32 *) (expanded + x)= bg;            }            if (italic)                expanded += ((h - y) >> 1) << 2;            for (x = 0; x < w; x++) {                if (x % 8 == 0)                    b = *bits++;                if ((b & (128 >> (x % 8)))) {                    *(Uint32 *) expanded = fg;                    if (bold)                        *(Uint32 *) (expanded + 4) = fg;                }                expanded += 4;            }            line += char_bmp.bmPitch;        }    }}/* return width of output */static void put_one_char (PDC pdc, LOGFONT* logfont, DEVFONT* devfont,                int* px, int* py, int h, int ascent, const char* mchar, int len){    const BYTE* bits;    int bbox_x = *px, bbox_y = *py;    int bbox_w, bbox_h, bold = 0, italic = 0;    int bpp, pitch = 0;    int old_x, old_y;    GAL_Rect fg_rect, bg_rect;    RECT rcOutput, rcTemp;        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        printf ("bbox of %c: %d, %d, %d, %d\n", *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 -= ascent;    }    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);

⌨️ 快捷键说明

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