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

📄 varbitmap.c

📁 有了操作系统、TCP/IP协议栈、文件系统
💻 C
📖 第 1 页 / 共 2 页
字号:
/*** $Id: varbitmap.c,v 1.37 2005/01/05 04:07:11 weiym Exp $** ** varbitmap.c: The Var Bitmap Font operation set.**** Copyright (C) 2003, 2004, 2005 Feynman Software** Copyright (C) 2000, 2001, 2002 Wei Yongming**** Create date: 2000/06/13*//*** 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 <string.h>#include <assert.h>#include "common.h"#ifdef _VBF_SUPPORT#include "minigui.h"#include "gdi.h"#include "endianrw.h"#include "misc.h"#ifdef HAVE_MMAP    #include <fcntl.h>    #include <unistd.h>    #include <sys/types.h>    #include <sys/mman.h>    #include <sys/stat.h>#endif#include "devfont.h"#include "varbitmap.h"#include "charset.h"#include "fontname.h"/*************** Variable bitmap font operations *********************************/static int get_char_width (LOGFONT* logfont, DEVFONT* devfont,                 const unsigned char* mchar, int len){    VBFINFO* vbf_info = VARFONT_INFO_P (devfont);    if (vbf_info->width == NULL)        return vbf_info->max_width;    assert (len == 1);    if (*mchar < vbf_info->first_char || *mchar > vbf_info->last_char)        return vbf_info->width [vbf_info->def_char - vbf_info->first_char];    return vbf_info->width [*mchar - vbf_info->first_char];}static int get_max_width (LOGFONT* logfont, DEVFONT* devfont){   return VARFONT_INFO_P (devfont)->max_width; }static int get_str_width (LOGFONT* logfont, DEVFONT* devfont,                 const unsigned char* mstr, int n, int cExtra){    int i;    int str_width;    VBFINFO* vbf_info = VARFONT_INFO_P (devfont);        if (vbf_info->width == NULL)        return n * (vbf_info->max_width + cExtra);    str_width = 0;    for (i = 0; i < n; i++) {        if (mstr [i] < vbf_info->first_char || mstr [i] > vbf_info->last_char)            str_width += vbf_info->width [vbf_info->def_char - vbf_info->first_char];        else            str_width += vbf_info->width [mstr[i] - vbf_info->first_char];        str_width += cExtra;    }    return str_width;}static int get_ave_width (LOGFONT* logfont, DEVFONT* devfont){    return VARFONT_INFO_P(devfont)->ave_width;}static int get_font_height (LOGFONT* logfont, DEVFONT* devfont){    return VARFONT_INFO_P (devfont)->height;}static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect){    return VARFONT_INFO_P (devfont)->height;}static int get_font_ascent (LOGFONT* logfont, DEVFONT* devfont){    return VARFONT_INFO_P (devfont)->height - VARFONT_INFO_P (devfont)->descent;}static int get_font_descent (LOGFONT* logfont, DEVFONT* devfont){    return VARFONT_INFO_P (devfont)->descent;}static size_t char_bitmap_size (LOGFONT* logfont, DEVFONT* devfont,                 const unsigned char* mchar, int len){    int width;    VBFINFO* vbf_info = VARFONT_INFO_P (devfont);    if (vbf_info->width == NULL)        width = vbf_info->max_width;    else if (*mchar < vbf_info->first_char || *mchar > vbf_info->last_char)        width = vbf_info->width [vbf_info->def_char - vbf_info->first_char];    else        width = vbf_info->width [*mchar - vbf_info->first_char];       return ((width + 7) >> 3) * vbf_info->height;}static size_t max_bitmap_size (LOGFONT* logfont, DEVFONT* devfont){    return (((size_t)VARFONT_INFO_P (devfont)->max_width + 7) >> 3)                 * VARFONT_INFO_P (devfont)->height;}static const void* get_char_bitmap (LOGFONT* logfont, DEVFONT* devfont,            const unsigned char* mchar, int len){    int offset;    unsigned char eff_char = *mchar;    VBFINFO* vbf_info = VARFONT_INFO_P (devfont);    if (*mchar < vbf_info->first_char || *mchar > vbf_info->last_char)        eff_char = vbf_info->def_char;    if (vbf_info->offset == NULL)        offset = (((size_t)vbf_info->max_width + 7) >> 3) * vbf_info->height                     * (eff_char - vbf_info->first_char);    else {        offset = vbf_info->offset [eff_char - vbf_info->first_char];#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN        if (vbf_info->font_size)            offset = ArchSwap16 (offset);#endif    }    return vbf_info->bits + offset;}static int get_char_bbox (LOGFONT* logfont, DEVFONT* devfont,            const unsigned char* mchar, int len,            int* px, int* py, int* pwidth, int* pheight){    int tempint;    VBFINFO* vbf_info = VARFONT_INFO_P (devfont);    if (vbf_info->version == 2)    {        int offset;        unsigned char eff_char = *mchar;        if (*mchar < vbf_info->first_char || *mchar > vbf_info->last_char)            eff_char = vbf_info->def_char;        offset = eff_char - vbf_info->first_char;            if (px)        {            tempint = vbf_info->bbox_x[offset];#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN            tempint = ArchSwap32(tempint);#endif            *px += tempint;        }        if (py)        {            tempint = vbf_info->bbox_y[offset];#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN            tempint = ArchSwap32(tempint);#endif            *py -= tempint;        }        if (pwidth)        {            tempint = vbf_info->bbox_w[offset];#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN            tempint = ArchSwap32(tempint);#endif            *pwidth = tempint;        }        if (pheight)        {            tempint = vbf_info->bbox_h[offset];#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN            tempint = ArchSwap32(tempint);#endif            *pheight = tempint;        }    }    else    {        if(pwidth)            *pwidth     = get_char_width(logfont, devfont, mchar, len);        if(pheight)            *pheight    = vbf_info->height;        if(py)            *py        -= get_font_ascent(logfont, devfont);        //if(px)        //    *px = 0;    }    return pwidth?*pwidth:-1;}static void get_char_advance (LOGFONT* logfont, DEVFONT* devfont,                const unsigned char* mchar, int len,                 int* px, int* py){    int width = get_char_width(logfont, devfont, mchar, len);    //printf("x %d, y %d, width %d\n", *px, *py, width);	*px += width;}/**************************** Global data ************************************/static FONTOPS var_bitmap_font_ops = {    get_char_width,    get_str_width,    get_ave_width,    get_max_width,    get_font_height,    get_font_size,    get_font_ascent,    get_font_descent,    char_bitmap_size,    max_bitmap_size,    get_char_bitmap,    NULL,    NULL,    get_char_bbox,    get_char_advance,    NULL,    NULL};/******************* In-core var bitmap fonts ********************************/static VBFINFO* incore_vbfonts [] = {#ifdef _INCOREFONT_SANSSERIF    &vbf_SansSerif11x13,#endif#ifdef _INCOREFONT_COURIER    &vbf_Courier8x13,#endif#ifdef _INCOREFONT_SYMBOL    &vbf_symb12,#endif#ifdef _INCOREFONT_VGAS    &vbf_VGAOEM8x8,    &vbf_Terminal8x12,    &vbf_System14x16,    &vbf_Fixedsys8x15,#endif#ifdef _INCOREFONT_HELV    &vbf_helvR16,    &vbf_helvR21,    &vbf_helvR27,#endif};#define NR_VBFONTS  (sizeof (incore_vbfonts) /sizeof (VBFINFO*))static DEVFONT* incore_vbf_dev_font;static CHARSETOPS* vbfGetCharsetOps (VBFINFO* vbfont){    int count = 0;    const char* font_name = vbfont->name;    while (*font_name) {        if (*font_name == '-') count ++;        if (count == 4) break;        font_name ++;    }    if (*font_name != '-') return NULL;    font_name ++;    return GetCharsetOps (font_name);}BOOL InitIncoreVBFonts (void){    int i;    if ((incore_vbf_dev_font = malloc (NR_VBFONTS * sizeof (DEVFONT))) == NULL)        return FALSE;

⌨️ 快捷键说明

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