📄 devfont.c
字号:
//// $Id: devfont.c,v 1.11 2000/08/28 03:08:21 weiym Exp $// // Device fonts management.//// devfont.c// // Copyright (C) 2000, Wei Yongming.// Copyright (C) 2000, BluePoint Software.//// Current maintainer: Wei Yongming.// // Created by Wei Yongming, 2000/07/07///*** 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: 1999.01.03//// Modify records://// Who When Where For What Status//-----------------------------------------------------------------------------//// TODO://#include <stdio.h>#include <stdlib.h>#include <string.h>#include <pthread.h>#include "common.h"#include "minigui.h"#include "gdi.h"#include "sysfont.h"#include "charset.h"#include "devfont.h"#include "fontname.h"#include "rawbitmap.h"#include "varbitmap.h"#ifndef lintstatic char fileid[] = "$Id: devfont.c,v 1.11 2000/08/28 03:08:21 weiym Exp $";#endif/**************************** Global data ************************************/static DEVFONT* sb_dev_font_head;static DEVFONT* mb_dev_font_head;static int nr_sb_dev_fonts;static int nr_mb_dev_fonts;#define devfontAddSBCDevFont(head, new) \{ \ if (head == NULL) \ head = new; \ else { \ DEVFONT* tail; \ tail = head; \ while (tail->sbc_next) tail = tail->sbc_next; \ tail->sbc_next = new; \ } \ \ new->sbc_next = NULL; \}#define devfontAddMBCDevFont(head, new) \{ \ if (head == NULL) \ head = new; \ else { \ DEVFONT* tail; \ tail = head; \ while (tail->mbc_next) tail = tail->mbc_next; \ tail->mbc_next = new; \ } \ \ new->mbc_next = NULL; \}void AddSBDevFont (DEVFONT* dev_font){ devfontAddSBCDevFont (sb_dev_font_head, dev_font); dev_font->style = fontGetStyleFromName (dev_font->name); nr_sb_dev_fonts ++;}void AddMBDevFont (DEVFONT* dev_font){ devfontAddMBCDevFont (mb_dev_font_head, dev_font); dev_font->style = fontGetStyleFromName (dev_font->name); nr_mb_dev_fonts ++;}void ResetDevFont (void){ sb_dev_font_head = mb_dev_font_head = NULL; nr_sb_dev_fonts = 0; nr_mb_dev_fonts = 0;}#define MATCHED_TYPE 0x01#define MATCHED_FAMILY 0x02#define MATCHED_CHARSET 0x04DEVFONT* GetMatchedSBDevFont (LOGFONT* log_font){ DEVFONT* dev_font; int i; BYTE* match_bits = alloca (nr_sb_dev_fonts); char charset_req [LEN_FONT_NAME + 1]; int min_error; DEVFONT* matched_font; // is charset requested is a single byte charset? if (GetCharsetOps (log_font->charset)->bytes_maxlen_char > 1) { fontGetCharsetFromName (SysLogFont.sbc_devfont->name, charset_req); } else strcpy (charset_req, log_font->charset); i = 0; dev_font = sb_dev_font_head; while (dev_font) { int type_req; char family [LEN_FONT_NAME + 1]; char charset [LEN_FONT_NAME + 1]; // clear match_bits first. match_bits [i] = 0; // does match this font type? type_req = fontConvertFontType (log_font->type); if (type_req == FONT_TYPE_ALL) match_bits [i] |= MATCHED_TYPE; else if (type_req == fontGetFontTypeFromName (dev_font->name)) match_bits [i] |= MATCHED_TYPE; // does match this family? fontGetFamilyFromName (dev_font->name, family); if (strcasecmp (family, log_font->family) == 0) {#if 0 fprintf (stderr, "family: %s, requested: %s; ", family, log_font->family);#endif match_bits [i] |= MATCHED_FAMILY; } // does match this charset fontGetCharsetFromName (dev_font->name, charset); if (GetCharsetOps (charset) == GetCharsetOps (charset_req)) {#if 0 fprintf (stderr, "charset: %s, requested: %s.\n", charset, charset_req);#endif match_bits [i] |= MATCHED_CHARSET; } else { if (fontGetCompatibleCharsetFromName (dev_font->name, charset) && GetCharsetOps (charset) == GetCharsetOps (charset_req)) match_bits [i] |= MATCHED_CHARSET; } // FIXME: ignore style dev_font = dev_font->sbc_next; i ++; } min_error = FONT_MAX_SIZE; matched_font = NULL; dev_font = sb_dev_font_head; for (i = 0; i < nr_sb_dev_fonts; i++) { int error; if ((match_bits [i] & MATCHED_TYPE) && (match_bits [i] & MATCHED_FAMILY) && (match_bits [i] & MATCHED_CHARSET)) { error = abs (log_font->size - (*dev_font->font_ops->get_font_size) (log_font, dev_font, log_font->size)); if (min_error > error) { min_error = error; matched_font = dev_font; } } dev_font = dev_font->sbc_next; } if (matched_font) {#if 0 fprintf (stderr, "matched font: %s\n", matched_font->name);#endif return matched_font; } // check charset here. min_error = FONT_MAX_SIZE; dev_font = sb_dev_font_head; for (i = 0; i < nr_sb_dev_fonts; i++) { int error; if (match_bits [i] & MATCHED_CHARSET) { error = abs (log_font->size - (*dev_font->font_ops->get_font_size) (log_font, dev_font, log_font->size)); if (min_error > error) { min_error = error; matched_font = dev_font; } } dev_font = dev_font->sbc_next; }#if 0 fprintf (stderr, "select a font: %s\n", matched_font->name);#endif return matched_font;}DEVFONT* GetMatchedMBDevFont (LOGFONT* log_font){ DEVFONT* dev_font; int i; BYTE* match_bits = alloca (nr_mb_dev_fonts); char charset_req [LEN_FONT_NAME + 1]; int min_error; DEVFONT* matched_font; // is charset requested is a multiple-byte charset? if (GetCharsetOps (log_font->charset)->bytes_maxlen_char < 2) return NULL; strcpy (charset_req, log_font->charset); i = 0; dev_font = mb_dev_font_head; while (dev_font) { int type_req; char family [LEN_FONT_NAME + 1]; char charset [LEN_FONT_NAME + 1]; // clear match_bits first. match_bits [i] = 0; // does match this font type? type_req = fontConvertFontType (log_font->type); if (type_req == FONT_TYPE_ALL) match_bits [i] |= MATCHED_TYPE; else if (type_req == fontGetFontTypeFromName (dev_font->name)) match_bits [i] |= MATCHED_TYPE; // does match this family? fontGetFamilyFromName (dev_font->name, family); if (strcasecmp (family, log_font->family) == 0) {#if 0 fprintf (stderr, "family: %s, requested: %s; ", family, log_font->family);#endif match_bits [i] |= MATCHED_FAMILY; } // does match this charset fontGetCharsetFromName (dev_font->name, charset); if (GetCharsetOps (charset) == GetCharsetOps (charset_req)) {#if 0 fprintf (stderr, "charset: %s, requested: %s\n", charset, charset_req);#endif match_bits [i] |= MATCHED_CHARSET; } // FIXME: ignore style dev_font = dev_font->mbc_next; i ++; } matched_font = NULL; min_error = FONT_MAX_SIZE; dev_font = mb_dev_font_head; for (i = 0; i < nr_mb_dev_fonts; i++) { int error; if ((match_bits [i] & MATCHED_TYPE) && (match_bits [i] & MATCHED_FAMILY) && (match_bits [i] & MATCHED_CHARSET)) { error = abs (log_font->size - (*dev_font->font_ops->get_font_size) (log_font, dev_font, log_font->size)); if (min_error > error) { min_error = error; matched_font = dev_font; } } dev_font = dev_font->mbc_next; } if (matched_font) {#if 0 fprintf (stderr, "matched font: %s\n", matched_font->name);#endif return matched_font; } min_error = FONT_MAX_SIZE; dev_font = mb_dev_font_head; for (i = 0; i < nr_mb_dev_fonts; i++) { int error; if (match_bits [i] & MATCHED_CHARSET) { error = abs (log_font->size - (*dev_font->font_ops->get_font_size) (log_font, dev_font, log_font->size)); if (min_error > error) { min_error = error; matched_font = dev_font; } } dev_font = dev_font->mbc_next; }#if 0 fprintf (stderr, "select a font: %s\n", matched_font->name);#endif return matched_font;}#ifdef _DEBUGvoid dumpDevFonts (void){ int count = 0; DEVFONT* devfont; fprintf (stderr, "============= SBDevFonts ============\n"); devfont = sb_dev_font_head; while (devfont) { fprintf (stderr, " %d: %s, style: %#lx\n", count, devfont->name, devfont->style); devfont = devfont->sbc_next; count++; } fprintf (stderr, "========== End of SBDevFonts =========\n"); fprintf (stderr, "\n============= MBDevFonts ============\n"); devfont = mb_dev_font_head; while (devfont) { fprintf (stderr, " %d: %s, style: %#lx\n", count, devfont->name, devfont->style); devfont = devfont->mbc_next; count++; } fprintf (stderr, "========== End of MBDevFonts =========\n");}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -