📄 rawbitmap.c
字号:
//// $Id: rawbitmap.c,v 1.15 2000/11/17 12:28:04 ymwei Exp $// // The Raw Bitmap Font operation set.//// rawbitmap.c// // Copyright (C) 2000, Wei Yongming.// Copyright (C) 2000, BluePoint Software.//// 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/13//// Modify records://// Who When Where For What Status//-----------------------------------------------------------------------------//// TODO://#include <stdio.h>#include <stdlib.h>#include <string.h>#include <pthread.h>#include <sys/stat.h>#include <sys/types.h>#include <fcntl.h>#include <unistd.h>#include "common.h"#include "minigui.h"#include "gdi.h"#ifdef HAVE_MMAP #include <sys/mman.h>#endif#include "charset.h"#include "devfont.h"#include "rawbitmap.h"#include "fontname.h"#ifndef lintstatic char fileid[] = "$Id: rawbitmap.c,v 1.15 2000/11/17 12:28:04 ymwei Exp $";#endif#ifdef _RBF_SUPPORT/********************** Load/Unload of raw bitmap font ***********************/BOOL LoadRawBitmapFont (const char* file, RBFINFO* RBFInfo){#ifdef HAVE_MMAP int fd;#else FILE* fp;#endif size_t size; size = ((RBFInfo->width + 7) >> 3) * RBFInfo->height * RBFInfo->nr_chars; RBFInfo->font_size = size;#ifdef HAVE_MMAP if ((fd = open (file, O_RDONLY)) < 0) return FALSE; if ((RBFInfo->font = mmap (NULL, size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) { close (fd); return FALSE; } close (fd);#else // Allocate memory for font data. if (!(RBFInfo->font = (char *)malloc (size)) ) return FALSE; // Open font file and read information to the system memory. if (!(fp = fopen (file, "rb"))) { return FALSE; } if (fread (RBFInfo->font, sizeof(char), size, fp) < size) { fclose(fp); return FALSE; } fclose(fp);#endif /* HAVE_MMAP */ return TRUE;}void UnloadRawBitmapFont (RBFINFO* RBFInfo){#ifdef HAVE_MMAP if (RBFInfo->font) munmap (RBFInfo->font, RBFInfo->font_size);#else free (RBFInfo->font);#endif}/********************** Init/Term of raw bitmap font ***********************/static int nr_fonts;static RBFINFO* rbf_infos;static DEVFONT* rbf_dev_fonts;#define SECTION_NAME "rawbitmapfonts"BOOL InitRawBitmapFonts (void){ int i; char font_name [LEN_DEVFONT_NAME + 1]; if (GetIntValueFromEtcFile (ETCFILEPATH, SECTION_NAME, "font_number", &nr_fonts) < 0 ) return FALSE; if ( nr_fonts < 1) return TRUE; rbf_infos = calloc (sizeof (RBFINFO), nr_fonts); rbf_dev_fonts = calloc (sizeof (DEVFONT), nr_fonts); if (rbf_infos == NULL || rbf_dev_fonts == NULL) { free (rbf_infos); free (rbf_dev_fonts); return FALSE; } for (i = 0; i < nr_fonts; i++) rbf_infos [i].font = NULL; for (i = 0; i < nr_fonts; i++) { char key [11]; char charset [LEN_FONT_NAME + 1]; char file [MAX_PATH + 1]; sprintf (key, "name%d", i); if (GetValueFromEtcFile (ETCFILEPATH, SECTION_NAME, key, font_name, LEN_DEVFONT_NAME) < 0 ) goto error_load; if (!fontGetCharsetFromName (font_name, charset)) { fprintf (stderr, "GDI: Invalid font name (charset): %s.\n", font_name); goto error_load; } if ((rbf_infos [i].charset_ops = GetCharsetOps (charset)) == NULL) { fprintf (stderr, "GDI: Not supported charset: %s.\n", charset); goto error_load; } if ((rbf_infos [i].width = fontGetWidthFromName (font_name)) == -1) { fprintf (stderr, "GDI: Invalid font name (width): %s.\n", font_name); goto error_load; } if ((rbf_infos [i].height = fontGetHeightFromName (font_name)) == -1) { fprintf (stderr, "GDI: Invalid font name (height): %s.\n", font_name); goto error_load; } rbf_infos [i].nr_chars = rbf_infos [i].charset_ops->nr_chars; sprintf (key, "fontfile%d", i); if (GetValueFromEtcFile (ETCFILEPATH, SECTION_NAME, key, file, MAX_PATH) < 0) goto error_load; if (!LoadRawBitmapFont (file, rbf_infos + i)) goto error_load; strncpy (rbf_dev_fonts[i].name, font_name, LEN_DEVFONT_NAME); rbf_dev_fonts[i].name [LEN_DEVFONT_NAME] = '\0'; rbf_dev_fonts[i].font_ops = &raw_bitmap_font_ops; rbf_dev_fonts[i].charset_ops = rbf_infos [i].charset_ops; rbf_dev_fonts[i].data = rbf_infos + i;#ifdef _DEBUG fprintf (stderr, "GDI: RBFDevFont %i: %s.\n", i, rbf_dev_fonts[i].name);#endif } for (i = 0; i < nr_fonts; i++) { if (rbf_infos [i].charset_ops->bytes_maxlen_char > 1) AddMBDevFont (rbf_dev_fonts + i); else AddSBDevFont (rbf_dev_fonts + i); } return TRUE;error_load: fprintf (stderr, "GDI: Error in loading raw bitmap fonts!\n"); for (i = 0; i < nr_fonts; i++) UnloadRawBitmapFont (rbf_infos + i); free (rbf_infos); free (rbf_dev_fonts); rbf_infos = NULL; rbf_dev_fonts = NULL; return FALSE;}void TermRawBitmapFonts (void){ int i; for (i = 0; i < nr_fonts; i++) UnloadRawBitmapFont (rbf_infos + i); free (rbf_infos); free (rbf_dev_fonts); rbf_infos = NULL; rbf_dev_fonts = NULL;}#endif /* _RBF_SUPPORT *//*************** Raw bitmap font operations *********************************/static int get_char_width (LOGFONT* logfont, DEVFONT* devfont, const unsigned char* mchar, int len){ return RBFONT_INFO_P (devfont)->width;}static int get_str_width (LOGFONT* logfont, DEVFONT* devfont, const unsigned char* mstr, int len, int cExtra){ int number; number = (*devfont->charset_ops->nr_chars_in_str) (mstr, len); return (RBFONT_INFO_P (devfont)->width + cExtra )* number;}static int get_ave_width (LOGFONT* logfont, DEVFONT* devfont){ return RBFONT_INFO_P (devfont)->width;}static int get_font_height (LOGFONT* logfont, DEVFONT* devfont){ return RBFONT_INFO_P (devfont)->height;}static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect){ return RBFONT_INFO_P (devfont)->height;}static int get_font_descent (LOGFONT* logfont, DEVFONT* devfont){ return 0;}static size_t char_bitmap_size (LOGFONT* logfont, DEVFONT* devfont, const unsigned char* mchar, int len){ return ((RBFONT_INFO_P (devfont)->width + 7) >> 3) * RBFONT_INFO_P (devfont)->height;}static size_t max_bitmap_size (LOGFONT* logfont, DEVFONT* devfont){ return ((RBFONT_INFO_P (devfont)->width + 7) >> 3) * RBFONT_INFO_P (devfont)->height;}static void* get_char_bitmap (LOGFONT* logfont, DEVFONT* devfont, const unsigned char* mchar, int len){ int bitmap_size; int offset; offset = (*devfont->charset_ops->char_offset) (mchar); if (offset >= RBFONT_INFO_P (devfont)->font_size) offset = (*devfont->charset_ops->char_offset) (devfont->charset_ops->def_char); bitmap_size = ((RBFONT_INFO_P (devfont)->width + 7) >> 3) * RBFONT_INFO_P (devfont)->height; return RBFONT_INFO_P (devfont)->font + bitmap_size * offset;}/**************************** Global data ************************************/FONTOPS raw_bitmap_font_ops = { get_char_width, get_str_width, get_ave_width, get_ave_width, // max_width same as ave_width get_font_height, get_font_size, get_font_height, // ascent same as height get_font_descent, char_bitmap_size, max_bitmap_size, get_char_bitmap, NULL, NULL, NULL, NULL, NULL};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -