/* * Copyright (C) 1999 David Stes. * * 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include #define Object XtObject #define String XtString #include #undef Object #undef String #include "rtfwidget.h" #include "xfontchange.h" #include "richfont.h" #include "fontchange.h" #include "boldface.h" #include "italic.h" #include "fontsizechange.h" #include "richtext.h" #include "charscanner.h" @implementation XFontchange - setwidget:(Widget)w { widget = w; /* need this, because font prefs are set on a per widget basis */ return self; } - setxdisplay:(Display*)d { xdpy = d; return self; } - (BOOL)isEqual:b { /* implement this as YES so that RunArray -coalesce works */ /* it should ignore xfontchange stuff */ return YES; } - copy { return self; } - deepCopy { return self; } - free { return nil; } - setxfont:(XFontStruct *)f { font = f; return self; } static XFontStruct *trymatch(Display *d,id richfont,BOOL italic,BOOL boldface,int fs) { id fname; XFontStruct *f; fname = [richfont nameitalic:italic boldface:boldface fontsize:fs]; dbg("trying %s\n",[fname str]); f = XLoadQueryFont(d,[fname str]); [fname free]; return f; } static int findmatch(char **fontlist,int n,int fs) { int i; int min; int match = fs; for(i=0;i fs)?(s-fs):(fs-s); if (d==0) return fs; if (i==0 || d= 512 || n == 0 || !validxlfd(s)) return NULL; for(i=0,j=0,field=0;s[i]!='\0';i++) { t[j++] = s[i]; if (s[i] == '-') { field++; if (field == 8 /* point size */ && s[i+1] == '*') { i++; sprintf(&t[j],"%d",n); while (t[j] != '\0') j++; } } } t[j++] = '\0'; assert(field == 14); dbg("xloadquery %s\n",t); return XLoadQueryFont(dpy,t); } - (unsigned) hash { unsigned h = (italic)?0:1; h = (h << 1) | (boldface)?0:1; h = (h << 8) | (fontsize % 255); h = (h << 8) | (fontfamily % 255); return h; } - (BOOL)italic { return italic; } - (BOOL)boldface { return boldface; } - (int)fontfamily { return fontfamily; } - (int)fontsize { return fontsize; } - (BOOL)isEqual:x { if (self == x) return YES; if ([x isKindOf:XFontchange]) { return italic == [x italic] && boldface == [x boldface] && fontsize == [x fontsize] && fontfamily == [x fontfamily]; } else { /* this case may be important for RunArray -coalesce (not sure) */ return NO; } } - calcxfontfor:ats in:text { id f,g; int i,n; id fontset; int fontnum; /* for xfontchange it's the fontfamily that really matters */ fontsize = FONTSIZE; fontnum = [text defaultfont]; italic = NO; boldface = NO; fontset = [text xfontset]; /* cache on a per doc basis */ for(i=0,n=[ats size];i