📄 drawtext.c
字号:
/*
** $Id: drawtext.c,v 1.36 2004/07/19 07:59:01 snig 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 "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 (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;
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) {
*(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;
if (erasebg || b != 0) {
*(Uint16 *) expanded = pixel [b];
if (bold)
*(Uint16 *)(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) {
*(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;
if (erasebg || 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 += 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) {
*(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;
if (erasebg || b != 0) {
*(Uint32 *) expanded = pixel[b];
if (bold)
*(Uint32 *) (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) {
*(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 += 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) {
*(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 += 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) {
*(Uint32 *) (expanded + x)= bg;
}
}
if (italic)
expanded += ((h - y) >> 1) << 2;
for (x = 0; x < w; x++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -