📄 fontdatac.c
字号:
/* * $Id: FontDataC.C,v 1.2 2000/05/07 12:26:10 fnevgeny Exp $ * * Copyright (c) 1993 HAL Computer Systems International, Ltd. * * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. * 1315 Dell Avenue * Campbell, CA 95008 * * Author: Greg Hilton * Contributors: Tom Lang, Frank Bieser, and others * * 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. * * http://www.gnu.org/copyleft/gpl.html * * 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. */#include <config.h>#include "FontDataC.h"#include "StrCase.h"#include "HalAppC.h"#include "CharC.h"extern int debug1, debug2;/*---------------------------------------------------------------------- * Constructors */FontDataC::FontDataC(){ Init();}FontDataC::FontDataC(const char *csname){ Init(); *this = csname;}/*---------------------------------------------------------------------- * Initialization method */voidFontDataC::Init(){ charSetNames.AllowDuplicates(FALSE); charSetNames.SetSorted(FALSE); charSetFonts.AllowDuplicates(TRUE); charSetFonts.SetSorted(FALSE); freeCharSet.AllowDuplicates(TRUE); freeCharSet.SetSorted(FALSE); pixels = 0; points = 0; normSpace = 0; endSpace = 0; superX = 0; superY = 0; subX = 0; subY = 0; underY = 0; underThick = 0; loaded = False; xfont = NULL; fid = halApp->fid; bigger = NULL; smaller = NULL; bold = NULL; nonBold = NULL; italic = NULL; nonItalic = NULL; freeBigger = False; freeSmaller = False; freeBold = False; freeItalic = False; freeNonBold = False; freeNonItalic = False;} // End Init/*---------------------------------------------------------------------- * Reset method */voidFontDataC::Reset(Boolean init){ if ( loaded && halApp->xRunning ) XFreeFont(halApp->display, xfont); if ( freeBigger && bigger != this ) delete bigger; if ( freeSmaller && smaller != this ) delete smaller; if ( freeBold && bold != this ) delete bold; if ( freeItalic && italic != this ) delete italic; if ( freeNonBold && nonBold != this ) delete nonBold; if ( freeNonItalic && nonItalic != this ) delete nonItalic; unsigned count = charSetFonts.size(); for (int i=0; i<count; i++) { if ( *freeCharSet[i] ) { FontDataC *data = (FontDataC*)*charSetFonts[i]; delete data; } } charSetFonts.removeAll(); charSetNames.removeAll(); freeCharSet.removeAll(); if ( init ) Init();} // End Reset/*---------------------------------------------------------------------- * Destructor */FontDataC::~FontDataC(){ Reset(False/*Don't init*/);}/*---------------------------------------------------------------------- * Assignment operator */FontDataC&FontDataC::operator=(FontDataC& that){ Reset(); name = that.name; foundry = that.foundry; family = that.family; weight = that.weight; slant = that.slant; setWidth = that.setWidth; addStyle = that.addStyle; pixelSize = that.pixelSize; pointSize = that.pointSize; resStr = that.resStr; spacing = that.spacing; avgWidth = that.avgWidth; charset = that.charset; pixels = that.pixels; points = that.points; normSpace = that.normSpace; endSpace = that.endSpace; superX = that.superX; superY = that.superY; subX = that.subX; subY = that.subY; underY = that.underY; underThick = that.underThick; xfont = that.xfont; fid = that.fid; bigger = that.bigger; smaller = that.smaller; bold = that.bold; italic = that.italic; nonBold = that.nonBold; nonItalic = that.nonItalic; loaded = False; freeBigger = False; freeSmaller = False; freeBold = False; freeItalic = False; freeNonBold = False; freeNonItalic = False;//// Copy alternate character sets// u_int count = that.charSetFonts.size(); int no = FALSE; for (int i=0; i<count; i++) { charSetFonts.add(*that.charSetFonts[i]); charSetNames.add(*that.charSetNames[i]); freeCharSet.add(no); } return *this;} // End assignment from FontDataC/*---------------------------------------------------------------------- * Assignment operator */FontDataC&FontDataC::operator=(const char *csname){ Reset(); name = csname; name.toLower(); DecodeName(); if ( name.size() == 0 || (xfont = XLoadQueryFont(halApp->display, name)) == NULL ) { xfont = halApp->font; fid = halApp->fid; loaded = False; } else { loaded = True; fid = xfont->fid; } GetProps(); return *this;} // End assignment from char*/*---------------------------------------------------------------------- * Method to expand a font name and extract the XFLD components */voidFontDataC::DecodeName(){ if ( name.size() == 0 ) return;//// Call XListFonts to expand the name to its full specification.// int actual; char **names = XListFonts(halApp->display, name, 1, &actual); if ( actual > 0 ) name = names[0]; else { StringC msg = "I could not find a font matching the name:\n\n"; msg += name + "\n\n"; msg += "You may wish to look in your resource files and change any\n"; msg += "references to this font."; halApp->PopupMessage(msg); name.Clear(); } if ( names ) XFreeFontNames(names);//// Extract the XFLD components if the name matches the pattern.// int dashCount = name.NumberOf('-'); if ( dashCount >= 13 ) { u_int start = 0; if ( name.StartsWith('-') ) start++; int which = 1; int pos = name.PosOf('-', start); int resStart; CharC range; while ( which <= 13 && pos >= start ) { range = name.Range(start, pos-start); switch(which) { case( 1): foundry = range; break; case( 2): family = range; break; case( 3): weight = range; break; case( 4): slant = range; break; case( 5): setWidth = range; break; case( 6): addStyle = range; break; case( 7): pixelSize = range; break; case( 8): pointSize = range; break; case( 9): resStart = start; break; case(10): resStr = name(resStart, pos-resStart); break; case(11): spacing = range; break; case(12): avgWidth = range; break; // Charset goes to end case(13): charset = name.Range(start, name.size()); break; } which++; start = pos+1; pos = name.PosOf('-', start); } // End for each part of font name StringC tmp = pixelSize; pixels = atoi(tmp); tmp = pointSize; points = atoi(tmp); } // End if pattern matches} // End DecodeName/*---------------------------------------------------------------------- * Method to get the properties for the specified font */voidFontDataC::GetProps(){ unsigned long propVal; if ( XGetFontProperty(xfont, XA_NORM_SPACE, &propVal) ) { normSpace = (unsigned)propVal; } else { normSpace = xfont->max_bounds.width; } if ( XGetFontProperty(xfont, XA_END_SPACE, &propVal) ) { endSpace = (unsigned)propVal; } else { endSpace = 2 * xfont->max_bounds.width; } if ( XGetFontProperty(xfont, XA_SUPERSCRIPT_X, &propVal) ) { superX = (int)propVal; } else { superX = 0; } if ( XGetFontProperty(xfont, XA_SUPERSCRIPT_Y, &propVal) ) { superY = (int)propVal; } else { superY = (xfont->ascent + xfont->descent)/(int)2; } if ( XGetFontProperty(xfont, XA_SUBSCRIPT_X, &propVal) ) { subX = (int)propVal; } else { subX = 0; } if ( XGetFontProperty(xfont, XA_SUBSCRIPT_Y, &propVal) ) { subY = (int)propVal; } else { subY = (xfont->ascent + xfont->descent)/(int)2; } if ( XGetFontProperty(xfont, XA_UNDERLINE_POSITION, &propVal) ) { underY = (int)propVal; } else { underY = -1; } if ( XGetFontProperty(xfont, XA_UNDERLINE_THICKNESS, &propVal) ) { underThick = (unsigned)propVal; } else { underThick = 1; }} // End GetFontProps/*---------------------------------------------------------------------- * Method to look build a font name pattern from the given parts. */#if 0voidFontDataC::BuildName(CharC foundryPart, CharC familyPart, CharC weightPart, CharC slantPart, CharC setWidthPart, CharC addStylePart, CharC pixelSizePart, CharC pointSizePart, CharC resPart, CharC spacingPart, CharC avgWidthPart, CharC charsetPart, StringC& fname){ fname = '-'; fname += foundryPart; fname += '-'; fname += familyPart; fname += '-'; fname += weightPart; fname += '-'; fname += slantPart; fname += '-'; fname += setWidthPart; fname += '-'; fname += addStylePart; fname += '-'; fname += pixelSizePart; fname += '-'; fname += pointSizePart; fname += '-'; fname += resPart; fname += '-'; fname += spacingPart; fname += '-'; fname += avgWidthPart; fname += '-'; fname += charsetPart;} // End BuildName#endif#define BuildName(foundryPart, familyPart, weightPart, slantPart, setWidthPart, addStylePart, pixelSizePart, pointSizePart, resPart, spacingPart, avgWidthPart, charsetPart, fname) \{ \ fname = '-'; \ fname += foundryPart; \ fname += '-'; \ fname += familyPart; \ fname += '-'; \ fname += weightPart; \ fname += '-'; \ fname += slantPart; \ fname += '-'; \ fname += setWidthPart; \ fname += '-'; \ fname += addStylePart; \ fname += '-'; \ fname += pixelSizePart; \ fname += '-'; \ fname += pointSizePart; \ fname += '-'; \ fname += resPart; \ fname += '-'; \ fname += spacingPart; \ fname += '-'; \ fname += avgWidthPart; \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -