4 * map dvi fonts to X fonts
8 #include <X11/IntrinsicP.h>
9 #include <X11/StringDefs.h>
13 #include "XFontName.h"
15 extern char *malloc ();
25 n
= malloc (strlen (s
) + 1);
32 LookupFontByPosition (dw
, position
)
38 for (f
= dw
->dvi
.fonts
; f
; f
=f
->next
)
39 if (f
->dvi_number
== position
)
44 static DviFontSizeList
*
45 LookupFontSizeBySize (f
, size
)
49 DviFontSizeList
*fs
, *best
= 0;
52 for (fs
= f
->sizes
; fs
; fs
=fs
->next
) {
53 if (fs
->size
<= size
&& fs
->size
>= bestsize
) {
62 SkipFontNameElement (n
)
71 # define SizePosition 8
72 # define EncodingPosition 13
75 ConvertFontNameToSize (n
)
80 for (i
= 0; i
< SizePosition
; i
++) {
81 n
= SkipFontNameElement (n
);
90 ConvertFontNameToEncoding (n
)
94 for (i
= 0; i
< EncodingPosition
; i
++) {
95 n
= SkipFontNameElement (n
);
103 InstallFontSizes (dw
, x_name
)
107 char fontNameString
[2048];
111 DviFontSizeList
*sizes
, *new;
113 unsigned int fontNameAttributes
;
115 if (!XParseFontName (x_name
, &fontName
, &fontNameAttributes
))
117 fontNameAttributes
&= ~(FontNamePixelSize
|FontNamePointSize
);
118 fontNameAttributes
|= FontNameResolutionX
;
119 fontNameAttributes
|= FontNameResolutionY
;
120 fontName
.ResolutionX
= dw
->dvi
.device_resolution
;
121 fontName
.ResolutionY
= dw
->dvi
.device_resolution
;
122 XFormatFontName (&fontName
, fontNameAttributes
, fontNameString
);
123 fonts
= XListFonts (XtDisplay (dw
), fontNameString
, 10000000, &count
);
125 for (i
= 0; i
< count
; i
++) {
126 if ((size
= ConvertFontNameToSize (fonts
[i
])) != -1) {
127 new = (DviFontSizeList
*) malloc (sizeof *new);
130 new->x_name
= savestr (fonts
[i
]);
131 new->doesnt_exist
= 0;
136 XFreeFontNames (fonts
);
141 DisposeFontSizes (fs
)
144 DviFontSizeList
*next
;
146 for (; fs
; fs
=next
) {
151 XFree ((char *)fs
->font
);
157 InstallFont (dw
, position
, dvi_name
, x_name
)
164 DviFontSizeList
*sizes
;
167 if (f
= LookupFontByPosition (dw
, position
)) {
169 * ignore gratuitous font loading
171 if (!strcmp (f
->dvi_name
, dvi_name
) &&
172 !strcmp (f
->x_name
, x_name
))
175 sizes
= InstallFontSizes (dw
, x_name
);
179 DisposeFontSizes (f
->sizes
);
185 sizes
= InstallFontSizes (dw
, x_name
);
188 f
= (DviFontList
*) malloc (sizeof (*f
));
189 f
->next
= dw
->dvi
.fonts
;
192 f
->dvi_name
= savestr (dvi_name
);
193 f
->x_name
= savestr (x_name
);
194 f
->dvi_number
= position
;
197 encoding
= ConvertFontNameToEncoding (f
->x_name
);
198 f
->char_map
= DviFindMap (encoding
);
202 * force requery of fonts
205 dw
->dvi
.font_number
= -1;
206 dw
->dvi
.cache
.font
= 0;
207 dw
->dvi
.cache
.font_number
= -1;
212 MapDviNameToXName (dw
, dvi_name
)
218 for (fm
= dw
->dvi
.font_map
; fm
; fm
=fm
->next
)
219 if (!strcmp (fm
->dvi_name
, dvi_name
))
225 MapXNameToDviName (dw
, x_name
)
231 for (fm
= dw
->dvi
.font_map
; fm
; fm
=fm
->next
)
232 if (!strcmp (fm
->x_name
, x_name
))
244 DviFontMap
*fm
, *new;
246 if (dw
->dvi
.font_map
)
247 DestroyFontMap (dw
->dvi
.font_map
);
249 m
= dw
->dvi
.font_map_string
;
252 while (*m
&& !isspace (*m
))
254 strncpy (dvi_name
, s
, m
-s
);
255 dvi_name
[m
-s
] = '\0';
259 while (*m
&& *m
!= '\n')
261 strncpy (x_name
, s
, m
-s
);
263 new = (DviFontMap
*) malloc (sizeof *new);
264 new->x_name
= savestr (x_name
);
265 new->dvi_name
= savestr (dvi_name
);
270 dw
->dvi
.font_map
= fm
;
273 DestroyFontMap (font_map
)
274 DviFontMap
*font_map
;
278 for (; font_map
; font_map
= next
) {
279 next
= font_map
->next
;
280 if (font_map
->x_name
)
281 free (font_map
->x_name
);
282 if (font_map
->dvi_name
)
283 free (font_map
->dvi_name
);
284 free ((char *) font_map
);
288 SetFontPosition (dw
, position
, dvi_name
, extra
)
292 char *extra
; /* unused */
296 x_name
= MapDviNameToXName (dw
, dvi_name
);
297 (void) InstallFont (dw
, position
, dvi_name
, x_name
);
301 QueryFont (dw
, position
, size
)
309 f
= LookupFontByPosition (dw
, position
);
311 return dw
->dvi
.default_font
;
312 fs
= LookupFontSizeBySize (f
, size
);
315 fs
->font
= XLoadQueryFont (XtDisplay (dw
), fs
->x_name
);
317 fs
->font
= dw
->dvi
.default_font
;
323 QueryFontMap (dw
, position
)
330 f
= LookupFontByPosition (dw
, position
);
337 LoadFont (dw
, position
, size
)
344 font
= QueryFont (dw
, position
, size
);
345 dw
->dvi
.font_number
= position
;
346 dw
->dvi
.font_size
= size
;
348 XSetFont (XtDisplay (dw
), dw
->dvi
.normal_GC
, font
->fid
);