24 #define FONT_EXAMINE_MAX 5000
25 #define KNOWN_ISO_VERSIONS 3
27 #if !defined(DEVEL_RELEASE)
41 #define PREFER_ISO10646
43 #if defined(DEVEL_RALF)
44 #if defined(PREFER_ISO10646)
47 #warning current iso setting: prefer ISO8859
48 #endif // PREFER_ISO10646
51 #if defined(PREFER_ISO10646)
54 static const char *known_iso_versions[
KNOWN_ISO_VERSIONS] = {
"ISO8859",
"ISO10646",
"*" };
58 {
"-adobe-times-medium-r-*--",
"Times",
NULp },
59 {
"-adobe-times-medium-i-*--",
"Times I",
NULp },
60 {
"-adobe-times-bold-r-*--",
"Times B",
NULp },
61 {
"-adobe-times-bold-i-*--",
"Times IB",
NULp },
62 {
"-schumacher-clean-medium-r-*--",
"Schumacher",
NULp },
63 {
"-schumacher-clean-medium-i-*--",
"Schumacher I",
NULp },
64 {
"-schumacher-clean-bold-r-*--",
"Schumacher B",
NULp },
65 {
"-schumacher-clean-bold-i-*--",
"Schumacher IB",
NULp },
66 {
"-*-urw bookman l-medium-r-*--",
"Bookman",
NULp },
67 {
"-*-urw bookman l-medium-i-*--",
"Bookman I",
NULp },
68 {
"-*-urw bookman l-bold-r-*--",
"Bookman B",
NULp },
69 {
"-*-urw bookman l-bold-i-*--",
"Bookman IB",
NULp },
70 {
"-adobe-courier-medium-r-*--",
"Courier",
NULp },
71 {
"-adobe-courier-medium-o-*--",
"Courier I",
NULp },
72 {
"-adobe-courier-bold-r-*--",
"Courier B",
NULp },
73 {
"-adobe-courier-bold-o-*--",
"Courier IB",
NULp },
74 {
"-adobe-helvetica-medium-r-*--",
"Helvetica",
NULp },
75 {
"-adobe-helvetica-medium-o-*--",
"Helvetica I",
NULp },
76 {
"-adobe-helvetica-bold-r-*--",
"Helvetica B",
NULp },
77 {
"-adobe-helvetica-bold-o-*--",
"Helvetica IB",
NULp },
78 {
"-*-liberation sans narrow-medium-r-*--",
"Liberation",
NULp },
79 {
"-*-liberation sans narrow-medium-o-*--",
"Liberation I",
NULp },
80 {
"-*-liberation sans narrow-bold-r-*--",
"Liberation B",
NULp },
81 {
"-*-liberation sans narrow-bold-o-*--",
"Liberation IB",
NULp },
82 {
"-adobe-new century schoolbook-medium-r-*--",
"Schoolbook",
NULp },
83 {
"-adobe-new century schoolbook-medium-i-*--",
"Schoolbook I",
NULp },
84 {
"-adobe-new century schoolbook-bold-r-*--",
"Schoolbook B",
NULp },
85 {
"-adobe-new century schoolbook-bold-i-*--",
"Schoolbook IB",
NULp },
86 {
"-*-lucidabright-medium-r-*--",
"LucidaBr",
NULp },
87 {
"-*-lucidabright-medium-i-*--",
"LucidaBr I",
NULp },
88 {
"-*-lucidabright-demibold-r-*--",
"LucidaBr B",
NULp },
89 {
"-*-lucidabright-demibold-i-*--",
"LucidaBr IB",
NULp },
90 {
"-*-symbol-medium-r-*--",
"Symbol",
NULp },
91 {
"-*-zapfchancery-medium-i-*--",
"zapfchancery",
NULp },
92 {
"-*-zapfdingbats-*-*-*--",
"zapfdingbats",
NULp },
98 {
"-*-lucida-medium-r-*-*-",
"Lucida",
NULp },
99 {
"-*-lucida-medium-i-*-*-",
"Lucida I",
NULp },
100 {
"-*-lucida-bold-r-*-*-",
"Lucida B",
NULp },
101 {
"-*-lucida-bold-i-*-*-",
"Lucida IB",
NULp },
102 {
"-*-lucidatypewriter-medium-r-*-*-",
"Lucida mono",
NULp },
103 {
"-*-lucidatypewriter-bold-r-*-*-",
"Lucida mono B",
NULp },
105 {
"-*-screen-medium-r-*-*-",
"Screen",
NULp },
106 {
"-*-screen-bold-r-*-*-",
"Screen B",
NULp },
107 {
"-*-clean-medium-r-*-*-",
"Clean",
NULp },
108 {
"-*-clean-bold-r-*-*-",
"Clean B",
NULp },
109 {
"-*-terminal-medium-r-*-*-",
"Terminal",
NULp },
110 {
"-*-terminal-bold-r-*-*-",
"Terminal B",
NULp },
112 {
"-*-dustismo-medium-r-*-*-",
"Dustismo",
NULp },
113 {
"-*-dustismo-bold-r-*-*-",
"Dustismo B",
NULp },
114 {
"-*-utopia-medium-r-*-*-",
"Utopia",
NULp },
115 {
"-*-utopia-bold-r-*-*-",
"Utopia B",
NULp },
116 {
"-*-dejavu sans-medium-r-*-*-",
"Dejavu",
NULp },
117 {
"-*-dejavu sans-bold-r-*-*-",
"Dejavu B",
NULp },
119 {
"-*-fixed-medium-r-*-*-",
"Fixed",
NULp },
120 {
"-*-fixed-bold-r-*-*-",
"Fixed B",
NULp },
121 {
"-*-dejavu sans mono-medium-r-*-*-",
"Dejavu mono",
NULp },
122 {
"-*-dejavu sans mono-bold-r-*-*-",
"Dejavu mono B",
NULp },
123 {
"-*-luxi mono-medium-r-*-*-",
"Luxi mono",
NULp },
124 {
"-*-luxi mono-bold-r-*-*-",
"Luxi mono B",
NULp },
125 {
"-*-nimbus mono l-medium-r-*-*-",
"Nimbus mono",
NULp },
126 {
"-*-nimbus mono l-bold-r-*-*-",
"Nimbus mono B",
NULp },
127 {
"-*-latin modern typewriter-medium-r-*-*-",
"Latin mono",
NULp },
128 {
"-*-latin modern typewriter-bold-r-*-*-",
"Latin mono B",
NULp },
130 {
"-*-terminus-medium-r-*-*-",
"Terminus",
NULp },
131 {
"-*-terminus-bold-r-*-*-",
"Terminus B",
NULp },
132 {
"-sony-fixed-medium-r-*-*-",
"SonyFixed",
NULp },
133 {
"-sony-fixed-bold-r-*-*-",
"SonyFixed B",
NULp },
134 {
"-mutt-clearlyu-medium-r-*-*-",
"MuttClearlyu",
NULp },
141 {
"Times-Roman", 0 },
142 {
"Times-Italic", 1 },
144 {
"Times-BoldItalic", 3 },
145 {
"AvantGarde-Book", 4 },
146 {
"AvantGarde-BookOblique", 5 },
147 {
"AvantGarde-Demi", 6 },
148 {
"AvantGarde-DemiOblique", 7 },
149 {
"Bookman-Light", 8 },
150 {
"Bookman-LightItalic", 9 },
151 {
"Bookman-Demi", 10 },
152 {
"Bookman-DemiItalic", 11 },
154 {
"Courier-Oblique", -13 },
155 {
"Courier-Bold", -14 },
156 {
"Courier-BoldOblique", -15 },
158 {
"Helvetica-Oblique", 17 },
159 {
"Helvetica-Bold", 18 },
160 {
"Helvetica-BoldOblique", 19 },
161 {
"Helvetica-Narrow", 20 },
162 {
"Helvetica-Narrow-Oblique", 21 },
163 {
"Helvetica-Narrow-Bold", 22 },
164 {
"Helvetica-Narrow-BoldOblique", 23 },
165 {
"NewCenturySchlbk-Roman", 24 },
166 {
"NewCenturySchlbk-Italic", 25 },
167 {
"NewCenturySchlbk-Bold", 26 },
168 {
"NewCenturySchlbk-BoldItalic", 27 },
169 {
"Palatino-Roman", 28 },
170 {
"Palatino-Italic", 29 },
171 {
"Palatino-Bold", 30 },
172 {
"Palatino-BoldItalic", 31 },
174 {
"ZapfChancery-MediumItalic", 33 },
175 {
"ZapfDingbats", 34 },
180 {
"LucidaSans", 16 },
181 {
"LucidaSans-Italic", 17 },
182 {
"LucidaSans-Bold", 18 },
183 {
"LucidaSans-BoldItalic", 19 },
184 {
"LucidaSansTypewriter", -12 },
185 {
"LucidaSansTypewriter-Bold", -14 },
188 {
"Screen-Bold", -18 },
190 {
"Clean-Bold", -14 },
192 {
"Terminal-Bold", -14 },
194 {
"AvantGarde-Book", 4 },
195 {
"AvantGarde-Demi", 6 },
196 {
"Palatino-Roman", 28 },
197 {
"Palatino-Bold", 30 },
198 {
"AvantGarde-Book", 4 },
199 {
"AvantGarde-Demi", 6 },
202 {
"Courier-Bold", -14 },
204 {
"Courier-Bold", -14 },
206 {
"Courier-Bold", -14 },
208 {
"Courier-Bold", -14 },
210 {
"Courier-Bold", -14 },
213 {
"Courier-Bold", -14 },
215 {
"Courier-Bold", -14 },
216 {
"Times-Roman", 0 },
222 #if defined(ASSERTION_USED)
227 if (xfig_fontnr<0) xfig_fontnr = -xfig_fontnr;
246 #define FONT_STRING_PARTS 14
250 const char *minus = strchr(fontname,
'-');
253 for (; minus; minus = strchr(minus+1,
'-'), ++count) {
255 minus_position[count] = minus-fontname;
264 int startpos = minus_position[idx]+1;
265 int endpos = (idx == (
FONT_STRING_PARTS-1) ? strlen(fontname) : minus_position[idx+1])-1;
266 int length = endpos-startpos+1;
267 char *
result =
new char[length+1];
269 memcpy(result, fontname+startpos, length);
285 size = atoi(sizeString);
286 if (size == 0 && strcmp(sizeString,
"0") != 0) {
289 delete [] sizeString;
293 fprintf(stderr,
"Error parsing size info from '%s' (%s)\n", fontname, error);
302 if (initialized)
return;
306 #if defined(ASSERTION_USED)
323 if ((fontlist = XListFonts(display, ps_fontinfo[1].
name, 1, &count))) {
328 #if defined(DUMP_FONT_LOOKUP)
329 printf(
"ps_fontinfo[f+1].name='%s'\n", ps_fontinfo[f+1].name);
330 #endif // DUMP_FONT_LOOKUP
332 XFreeFontNames(fontlist);
333 #if defined(DUMP_FONT_LOOKUP)
334 printf(
"Using OpenWindow fonts\n");
340 strcpy(templat, x_fontinfo[f].templat);
341 strcat(templat,
"0-0-*-*-*-*-*-*");
343 if ((fontlist = XListFonts(display, templat, 1, &count))) {
346 XFreeFontNames(fontlist);
351 #if defined(DUMP_FONT_LOOKUP)
352 printf(
"Using %s font for '%s' (templat='%s')\n",
is_scalable[f] ?
"scalable" :
"fixed", x_fontinfo[f].templat, templat);
353 #endif // DUMP_FONT_LOOKUP
358 struct found_font {
const char *fn;
int s; };
376 char *font_template =
GBS_global_string_copy(
"%s*-*-*-*-*-*-%s-*", x_fontinfo[f].templat, known_iso_versions[iso]);
379 fontlist[iso] = XListFonts(display, font_template,
FONT_EXAMINE_MAX, &count);
382 printf(
"Warning: Too many fonts found for '%s..%s' - ARB can't examine all fonts\n", x_fontinfo[f].templat, known_iso_versions[iso]);
385 for (
int c = 0; c<count; ++c) {
386 const char *fontname = fontlist[iso][c];
388 flist[found_fonts].fn = fontname;
389 flist[found_fonts].s = size;
397 #if defined(DUMP_FONT_LOOKUP)
398 printf(
"Considering %i fonts for '%s'\n", found_fonts, x_fontinfo[f].templat);
399 #endif // DUMP_FONT_LOOKUP
406 for (i = 0; i < found_fonts; i++) {
407 if (flist[i].
s == size)
break;
410 if (i < found_fonts && flist[i].
s == size) {
411 xfont *newfont = ARB_alloc<xfont>(1);
418 nf->fname = strdup(flist[i].fn);
426 xfont *newfont = ARB_alloc<xfont>(1);
435 #if defined(DUMP_FONT_LOOKUP)
437 printf(
"Fonts used for '%s':\n", x_fontinfo[f].templat);
439 printf(
"- %2i pt: '%s'\n", nf->
size, nf->
fname);
442 #endif // DUMP_FONT_LOOKUP
451 #if defined(DUMP_FONT_DETAILS)
452 static void dumpFontInformation(
xfont *xf) {
453 printf(
"Font information for '%s'", xf->
fname);
454 XFontStruct *xfs = xf->
fstruct;
457 printf(
"- max letter ascent = %2i\n", xfs->max_bounds.ascent);
458 printf(
"- max letter descent = %2i\n", xfs->max_bounds.descent);
459 printf(
"- max letter height = %2i\n", xfs->max_bounds.ascent + xfs->max_bounds.descent);
460 printf(
"- max letter width = %2i\n", xfs->max_bounds.width);
463 printf(
" (not available, font is not loaded)\n");
474 static bool lookfont(Display *tool_d,
int f,
int s,
int& found_size,
bool verboose,
bool only_query,
PIX_FONT *fontstPtr) {
482 xfont *newfont, *nf, *oldnf;
524 if (s < nf->size) fprintf(stderr,
"Font size %d not found, using larger %d point\n", s, nf->
size);
525 #if defined(DUMP_FONT_LOOKUP)
526 fprintf(stderr,
"Detected font %s\n", nf->
fname);
533 if (s > nf->
size) fprintf(stderr,
"Font size %d not found, using smaller %d point\n", s, nf->
size);
534 #if defined(DUMP_FONT_LOOKUP)
535 fprintf(stderr,
"Using font %s for size %d\n", nf->
fname, s);
545 if (!x_fontinfo[f].xfontlist) x_fontinfo[f].
xfontlist = newfont;
546 else oldnf->
next = newfont;
566 char *fontname =
GBS_global_string_copy(
"%s%d-*-*-*-*-*-%s-*", x_fontinfo[f].templat, s, known_iso_versions[iso]);
567 #if defined(DUMP_FONT_LOOKUP)
568 fprintf(stderr,
"Checking for '%s' (x_fontinfo[%i].templat='%s')\n", fontname, f, x_fontinfo[f].templat);
571 int matching_fonts_found;
572 char **matching_fonts = XListFonts(tool_d, fontname, 1, &matching_fonts_found);
574 if (matching_fonts) {
575 XFreeFontNames(matching_fonts);
577 nf->
fname = fontname;
588 bool font_found =
true;
595 #if defined(DUMP_FONT_LOOKUP)
596 if (verboose) fprintf(stderr,
"Loading font '%s'\n", nf->
fname);
600 fprintf(stderr,
"ARB fontpackage: Unexpectedly couldn't load font '%s', falling back to '%s' (f=%i, s=%i)\n", nf->
fname,
NORMAL_FONT, f, s);
609 #if defined(DUMP_FONT_DETAILS)
610 dumpFontInformation(nf);
613 found_size = nf->
size;
630 if (found_size<size) size = found_size;
631 if (found_size == size) available_sizes[size_count++] = size;
636 for (
int reverse = size_count/2-1; reverse >= 0; --reverse) {
637 int o = size_count-1-reverse;
640 int s = available_sizes[reverse];
641 available_sizes[reverse] = available_sizes[o];
642 available_sizes[o] =
s;
649 static char *
caps(
char *sentence) {
651 for (
int i = 0; sentence[i]; ++i) {
652 if (isalpha(sentence[i])) {
654 sentence[i] = toupper(sentence[i]);
675 const char *readable_fontname =
NULp;
676 struct _xfstruct& xf = x_fontinfo[font_nr];
681 if (strcmp(fontname,
"fixed") == 0) {
688 readable_fontname =
GBS_global_string(
"[%s - parse-error (%s)]", fontname, error);
713 readable_fontname = xf.
templat;
716 return readable_fontname;
730 return ps_fontinfo[font_nr+1].
xfontnum;
736 (cs->rbearing|cs->lbearing|cs->ascent|cs->descent) == 0;
739 inline void CI_GetCharInfo_1D(
const XFontStruct *fs,
unsigned col,
const XCharStruct *def,
const XCharStruct*& cs) {
741 aw_assert(fs->min_byte1 == 0 && fs->max_byte1 == 0);
742 if (col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) {
744 cs = &fs->min_bounds;
747 cs = &fs->per_char[col - fs->min_char_or_byte2];
761 inline void CI_GetCharInfo_2D(
const XFontStruct *fs,
unsigned row,
unsigned col,
const XCharStruct *def,
const XCharStruct*& cs) {
763 if (row >= fs->min_byte1 && row <= fs->max_byte1 &&
764 col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2)
767 cs = &fs->min_bounds;
770 cs = &fs->per_char[((row - fs->min_byte1) *
771 (fs->max_char_or_byte2 -
772 fs->min_char_or_byte2 + 1)) +
773 (col - fs->min_char_or_byte2)];
780 unsigned int r = (fs->default_char >> 8);
781 unsigned int c = (fs->default_char & 0xff);
794 if (fs->min_byte1 == 0 &&
795 col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) {
797 cs = &fs->min_bounds;
800 cs = &fs->per_char[(col - fs->min_char_or_byte2)];
806 void AW_GC_Xm::wm_set_font(
const AW_font font_nr,
const int size,
int *found_size) {
812 if (found_size) *found_size = found_font_size;
814 XSetFont(
get_common()->get_display(), gc, xfs->fid);
817 const XCharStruct *cs;
818 const XCharStruct *def;
819 bool singlerow = (xfs->max_byte1 == 0);
834 if (cs)
set_char_size(i, cs->ascent, cs->descent, cs->width);
841 wm_set_font(font_nr, size, found_size);
static const char * parseFontString(const char *fontname, int *minus_position)
void set_font(AW_font font_nr, int size, int *found_size)
const char * AW_get_font_specification(AW_font font_nr, bool &found)
#define AW_FONTINFO_CHAR_ASCII_MAX
static char * caps(char *sentence)
const char * GBS_global_string(const char *templat,...)
int AW_font_2_xfig(AW_font font_nr)
static bool is_scalable[AW_NUM_FONTS]
#define ARRAY_ELEMS(array)
#define AW_FONTINFO_CHAR_ASCII_MIN
static const char * known_iso_versions[KNOWN_ISO_VERSIONS]
#define FONT_STRING_PARTS
static struct _fstruct ps_fontinfo[]
TYPE * ARB_alloc(size_t nelem)
void CI_GetCharInfo_2D(const XFontStruct *fs, unsigned row, unsigned col, const XCharStruct *def, const XCharStruct *&cs)
void CI_GetDefaultInfo_2D(const XFontStruct *fs, const XCharStruct *&cs)
static bool lookfont(Display *tool_d, int f, int s, int &found_size, bool verboose, bool only_query, PIX_FONT *fontstPtr)
static struct _xfstruct x_fontinfo[]
void set_char_size(int i, int ascent, int descent, int width)
bool CI_NonExistChar(const XCharStruct *cs)
static void error(const char *msg)
static int parsesize(const char *fontname)
STATIC_ASSERT(ARRAY_ELEMS(x_fontinfo)==AW_NUM_FONTS)
#define ASSERT_TRUE(boolExpr)
void aw_root_init_font(Display *display)
static void check_ps_fontinfo_valid()
virtual int get_available_fontsizes(AW_font font_nr, int *available_sizes) const
void CI_GetDefaultInfo_1D(const XFontStruct *fs, const XCharStruct *&cs)
static int get_available_fontsizes(Display *tool_d, int f, int *available_sizes)
#define KNOWN_ISO_VERSIONS
static char * getParsedFontPart(const char *fontname, int *minus_position, int idx)
void CI_GetRowzeroCharInfo_2D(const XFontStruct *fs, unsigned col, const XCharStruct *def, const XCharStruct *&cs)
AW_common_Xm * get_common() const
void CI_GetCharInfo_1D(const XFontStruct *fs, unsigned col, const XCharStruct *def, const XCharStruct *&cs)
const char * AW_get_font_shortname(AW_font font_nr)
void set_no_char_size(int i)
char * GBS_global_string_copy(const char *templat,...)
GB_write_int const char s