📄 qpf.c
字号:
if ((nr_charsets = charsetGetCharsetsNumber (charsets)) > 1) { int j; for (j = 1; j < nr_charsets; j++) { char charset [LEN_FONT_NAME + 1]; CHARSETOPS* charset_ops; DEVFONT* new_devfont; charsetGetSpecificCharset (charsets, j, charset); if ((charset_ops = GetCharsetOps (charset)) == NULL) continue; new_devfont = calloc (1, sizeof (DEVFONT)); memcpy (new_devfont, qpf_dev_fonts + i, sizeof (DEVFONT)); new_devfont->charset_ops = charset_ops; if (new_devfont->charset_ops->bytes_maxlen_char > 1) AddMBDevFont (new_devfont); else AddSBDevFont (new_devfont); } } } return TRUE;error_load: fprintf (stderr, "GDI: Error in loading QPF fonts!\n"); for (i = 0; i < nr_fonts; i++) UnloadQPFont (qpf_infos + i); free (qpf_infos); free (qpf_dev_fonts); qpf_infos = NULL; qpf_dev_fonts = NULL; return FALSE;}void TermQPFonts (void){ int i; for (i = 0; i < nr_fonts; i++) UnloadQPFont (qpf_infos + i); free (qpf_infos); free (qpf_dev_fonts); qpf_infos = NULL; qpf_dev_fonts = NULL;}/*************** QPF font operations *********************************/static GLYPH* get_glyph (GLYPHTREE* tree, unsigned int ch){ if (ch < tree->min) { if (!tree->less) return NULL; return get_glyph (tree->less, ch); } else if ( ch > tree->max ) { if (!tree->more) { return NULL; } return get_glyph (tree->more, ch); } return &tree->glyph [ch - tree->min];}static int get_char_width (LOGFONT* logfont, DEVFONT* devfont, const unsigned char* mchar, int len){ unsigned int uc16; GLYPH* glyph; uc16 = (*devfont->charset_ops->conv_to_uc16) (mchar, len); glyph = get_glyph (QPFONT_INFO_P (devfont)->tree, uc16); if (glyph == NULL) { glyph = get_glyph (QPFONT_INFO_P (devfont)->tree, '?'); } return glyph->metrics->width;}static int get_str_width (LOGFONT* logfont, DEVFONT* devfont, const unsigned char* mstr, int len, int cExtra){ unsigned short uc16; GLYPH* glyph; int x = 0; while (len > 0) { int char_len = (*devfont->charset_ops->len_first_char) (mstr, len); uc16 = (*devfont->charset_ops->conv_to_uc16) (mstr, char_len); len -= char_len; mstr += char_len; glyph = get_glyph (QPFONT_INFO_P (devfont)->tree, uc16); if (glyph == NULL) { glyph = get_glyph (QPFONT_INFO_P (devfont)->tree, '?'); } x += glyph->metrics->advance; x += cExtra; } return x;}static int get_ave_width (LOGFONT* logfont, DEVFONT* devfont){ return QPFONT_INFO_P (devfont)->width;}static int get_max_width (LOGFONT* logfont, DEVFONT* devfont){ return QPFONT_INFO_P (devfont)->fm->maxwidth;}static int get_font_height (LOGFONT* logfont, DEVFONT* devfont){ return QPFONT_INFO_P (devfont)->fm->ascent + QPFONT_INFO_P (devfont)->fm->descent;}static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect){ return get_font_height (logfont, devfont);}static int get_font_ascent (LOGFONT* logfont, DEVFONT* devfont){ return QPFONT_INFO_P (devfont)->fm->ascent;}static int get_font_descent (LOGFONT* logfont, DEVFONT* devfont){ return QPFONT_INFO_P (devfont)->fm->descent;}static size_t char_bitmap_size (LOGFONT* logfont, DEVFONT* devfont, const unsigned char* mchar, int len){ unsigned int uc16; GLYPH* glyph; uc16 = (*devfont->charset_ops->conv_to_uc16) (mchar, len); glyph = get_glyph (QPFONT_INFO_P (devfont)->tree, uc16); if (glyph == NULL) { glyph = get_glyph (QPFONT_INFO_P (devfont)->tree, '?'); } return ((glyph->metrics->width + 7 ) >> 3) * glyph->metrics->height;}static size_t max_bitmap_size (LOGFONT* logfont, DEVFONT* devfont){ int max_width = QPFONT_INFO_P (devfont)->fm->maxwidth; int height = QPFONT_INFO_P (devfont)->fm->ascent + QPFONT_INFO_P (devfont)->fm->descent; return ((max_width + 7) >> 3) * height;}static const void* get_char_bitmap (LOGFONT* logfont, DEVFONT* devfont, const unsigned char* mchar, int len){ unsigned int uc16; GLYPH* glyph; uc16 = (*devfont->charset_ops->conv_to_uc16) (mchar, len); glyph = get_glyph (QPFONT_INFO_P (devfont)->tree, uc16); if (glyph == NULL) { glyph = get_glyph (QPFONT_INFO_P (devfont)->tree, '?'); } if (QPFONT_INFO_P (devfont)->fm->flags & FM_SMOOTH) { return NULL; } return glyph->data;#if 0 int i; int std_pitch, height; uchar *src, *dst; std_pitch = ((glyph->metrics->width + 7) >> 3); if (std_pitch == glyph->metrics->linestep) return glyph->data; height = glyph->metrics->height; if ((std_pitch * height) > QPFONT_INFO_P (devfont)->max_bmp_size) { return NULL; } src = glyph->data; dst = QPFONT_INFO_P (devfont)->std_bmp; for (i = 0; i < height; i++) { memcpy (dst, src, std_pitch); src += glyph->metrics->linestep; dst += std_pitch; } return QPFONT_INFO_P (devfont)->std_bmp;#endif}static const void* get_char_pixmap (LOGFONT* logfont, DEVFONT* devfont, const unsigned char* mchar, int len, int* pitch){ unsigned int uc16; GLYPH* glyph; uc16 = (*devfont->charset_ops->conv_to_uc16) (mchar, len); glyph = get_glyph (QPFONT_INFO_P (devfont)->tree, uc16); if (glyph == NULL) { glyph = get_glyph (QPFONT_INFO_P (devfont)->tree, '?'); } if (!(QPFONT_INFO_P (devfont)->fm->flags & FM_SMOOTH)) { return NULL; } *pitch = glyph->metrics->linestep; return glyph->data;}static int get_char_bbox (LOGFONT* logfont, DEVFONT* devfont, const unsigned char* mchar, int len, int* px, int* py, int* pwidth, int* pheight){ unsigned int uc16; GLYPH* glyph; uc16 = (*devfont->charset_ops->conv_to_uc16) (mchar, len); glyph = get_glyph (QPFONT_INFO_P (devfont)->tree, uc16); if (glyph == NULL) { glyph = get_glyph (QPFONT_INFO_P (devfont)->tree, '?'); } if (pwidth) *pwidth = glyph->metrics->width; if (pheight) *pheight = glyph->metrics->height; if (px) *px += glyph->metrics->bearingx; if (py) *py -= glyph->metrics->bearingy; return glyph->metrics->width;}static void get_char_advance (LOGFONT* logfont, DEVFONT* devfont, const unsigned char* mchar, int len, int* px, int* py){ unsigned int uc16; GLYPH* glyph; uc16 = (*devfont->charset_ops->conv_to_uc16) (mchar, len); glyph = get_glyph (QPFONT_INFO_P (devfont)->tree, uc16); if (glyph == NULL) { glyph = get_glyph (QPFONT_INFO_P (devfont)->tree, '?'); } *px += glyph->metrics->advance;}static DEVFONT* new_instance (LOGFONT* logfont, DEVFONT* devfont, BOOL need_sbc_font){ if (QPFONT_INFO_P (devfont)->fm->flags & FM_SMOOTH) { logfont->style |= FS_WEIGHT_BOOK; } return devfont;}/**************************** Global data ************************************/FONTOPS qpf_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, get_char_pixmap, NULL, get_char_bbox, get_char_advance, new_instance, NULL};#endif /* _QPF_SUPPORT */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -