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

📄 drawtext.c

📁 在ecos 下mingui 的移植开发
💻 C
📖 第 1 页 / 共 2 页
字号:
//// $Id: drawtext.c,v 1.16 2000/09/04 08:57:39 weiym Exp $// // drawtext.c: Low level text drawing.// // Copyright (C) 1999, 2000, WEI Yongming.//// Copyright (C) 2000, BluePoint Software.// Author: WEI Yongming.//// Current maintainer: WEI Yongming.///***  This library is free software; you can redistribute it and/or**  modify it under the terms of the GNU Library General Public**  License as published by the Free Software Foundation; either**  version 2 of the License, or (at your option) any later version.****  This library 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**  Library General Public License for more details.****  You should have received a copy of the GNU Library General Public**  License along with this library; if not, write to the Free**  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,**  MA 02111-1307, USA*/// Create date: 2000/06/15//// Modify records:////  Who             When        Where       For What                Status//-----------------------------------------------------------------------------//// TODO://#include <stdio.h>#include <stdlib.h>#include <pthread.h>#include <semaphore.h>#include "common.h"#include "gdi.h"#include "window.h"#include "cliprect.h"#include "gal.h"#include "internals.h"#include "dc.h"#include "drawtext.h"static BYTE* buffer;static size_t buf_size;BOOL InitTextBitmapBuffer (void){    return TRUE;}static BYTE* get_buffer (size_t size){    if (size <= buf_size) return buffer;    buf_size = ((size + 31) >> 5) << 5;#if 0    fprintf (stderr, "buf_size: %d.\n", buf_size);#endif    buffer = realloc (buffer, buf_size);    return buffer;}static void free_buffer (void){    free (buffer);    buffer = NULL;    buf_size = 0;}void TermTextBitmapBuffer (void){    free_buffer ();}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 int expand_char_pixmap (PDC pdc, int w, int h, const BYTE* bits,             BYTE* expanded, BOOL erasebg, int bold, int italic, int cols){    gal_color pal [5];    gal_pixel pixel [5];    int i, x, y;    int b = 0;    BYTE* line;    int bpp = GAL_BytesPerPixel (pdc->gc);    int line_bytes = bpp * (w + bold + italic);    GAL_UnmapPixel (pdc->gc, pdc->bkcolor, pal);    GAL_UnmapPixel (pdc->gc, pdc->textcolor, pal + 4);    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_MapColor (pdc->gc, pal + i);    }    line = expanded;    switch (bpp) {    case 1:        for (y = 0; y < h; y++) {            expanded = line;            if (erasebg) {                if (italic) x = (h - y) >> 1;                else x = 0;                for (; 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 (erasebg || b != 0) {                    *expanded = pixel [b];                    if (bold)                    *(expanded + 1) = pixel [b];                }                expanded++;            }            bits += cols;            line += line_bytes;        }    break;    case 2:        for (y = 0; y < h; y++) {            expanded = line;            if (erasebg) {                if (italic) x = ((h - y) >> 1) << 1;                else x = 0;                for (; x < (w + bold + italic) << 1; x += 2) {                    *(ushort *) (expanded + x) = pixel [0];                }            }            if (italic)                expanded += ((h - y) >> 1) << 1;            for (x = 0; x < w; x++) {                b = *(bits+x);                if (erasebg || b != 0) {                    *(ushort *) expanded = pixel [b];                    if (bold)                        *(ushort *)(expanded + 2) = pixel [b];                }                expanded += 2;            }            bits += cols;            line += line_bytes;        }    break;    case 3:        for (y = 0; y < h; y++) {            expanded = line;            if (erasebg) {                if (italic) x = ((h - y) >> 1 * 3);                else x = 0;                for (; x < (w + bold + italic) * 3; x += 3) {                    *(ushort *) (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 (erasebg || b != 0) {                    *(ushort *) expanded = pixel[b];                    *(expanded + 2) = pixel[b] >> 16;                    if (bold) {                        *(ushort *)(expanded + 3) = pixel[b];                        *(expanded + 5) = pixel[b] >> 16;                    }                }                                expanded += 3;            }            bits += cols;            line += line_bytes;        }    break;    case 4:        for (y = 0; y < h; y++) {            expanded = line;            if (erasebg) {                if (italic) x = ((h - y) >> 1) << 2;                else x = 0;                for (; x < (w + bold + italic) << 2; x += 4) {                    *(uint *) (expanded + x)= pixel [0];                }            }            if (italic)                expanded += ((h - y) >> 1) << 2;            for (x = 0; x < w; x++) {                b = *bits++;                if (erasebg || b != 0) {                    *(uint *) expanded = pixel[b];                    if (bold)                        *(uint *) (expanded + 4) = pixel[b];                }                expanded += 4;            }            line += line_bytes;        }    }    return line_bytes;}static int expand_char_bitmap (int w, int h,             const BYTE* bits, int bpp, BYTE* expanded,             int bg, int fg, BOOL erasebg, int bold, int italic){    int x, y;    int b = 0;    BYTE* line;    int line_bytes = bpp * (w + bold + italic);    line = expanded;    switch (bpp) {    case 1:        for (y = 0; y < h; y++) {            expanded = line;            if (erasebg) {                if (italic) x = (h - y) >> 1;                else x = 0;                for (; 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 += line_bytes;        }    break;    case 2:        for (y = 0; y < h; y++) {            expanded = line;            if (erasebg) {                if (italic) x = ((h - y) >> 1) << 1;                else x = 0;                for (; x < (w + bold + italic) << 1; x += 2) {                    *(ushort *) (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)))) {                    *(ushort *) expanded = fg;                    if (bold)                        *(ushort *)(expanded + 2) = fg;                }                expanded += 2;            }            line += line_bytes;        }    break;    case 3:        for (y = 0; y < h; y++) {            expanded = line;            if (erasebg) {                if (italic) x = ((h - y) >> 1 * 3);                else x = 0;                for (; x < (w + bold + italic) * 3; x += 3) {                    *(ushort *) (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)))) {                    *(ushort *) expanded = fg;                    *(expanded + 2) = fg >> 16;                    if (bold) {                        *(ushort *)(expanded + 3) = fg;                        *(expanded + 5) = fg >> 16;                    }                }                                expanded += 3;            }            line += line_bytes;        }    break;    case 4:        for (y = 0; y < h; y++) {            expanded = line;            if (erasebg) {                if (italic) x = ((h - y) >> 1) << 2;                else x = 0;                for (; x < (w + bold + italic) << 2; x += 4) {                    *(uint *) (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)))) {                    *(uint *) expanded = fg;                    if (bold)                        *(uint *) (expanded + 4) = fg;                }                expanded += 4;            }            line += line_bytes;        }    }    return line_bytes;}static void fill_line_with_color (BYTE* line, int c, int w, int bpp){    int x;    switch (bpp) {    case 1:        for (x = 0; x < w; x ++)            *(line + x) = c;        break;    case 2:        for (x = 0; x < w << 1; x += 2)            *(ushort *) (line + x) = c;        break;    case 3:        for (x = 0; x < w * 3; x += 3) {            *(ushort *) (line + x) = c;            *(line + x + 2) = c >> 16;        }        break;

⌨️ 快捷键说明

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