2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: Fonts.C /main/8 1997/09/04 08:06:26 mgreess $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company
26 * (c) Copyright 1993, 1994 International Business Machines Corp.
27 * (c) Copyright 1993, 1994 Novell, Inc.
28 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
30 * This code was borrowed from dtcm (Calendar Manager).
31 * Its purpose is to find a font in a particular family that is
32 * the same size as the user font being used.
37 #include <Xm/AtomMgr.h>
44 * Walk a font_list looking for a FontSet with the
45 * XmFONTLIST_DEFAULT_TAG set. If we fail to find a FontSet with this tag,
46 * return the first FontSet found. If we fail to find a FontSet return
47 * the first font found.
49 * This function returns either a XFontStruct or a XFontSet. The type can
50 * be determined by the value of type_return which will equal either
51 * XmFONT_IS_FONTSET or XmFONT_IS_FONT.
53 * The XFontStruct or XFontSet that is returned is not a copy and should
59 XmFontType *type_return)
61 XmFontContext fl_context;
62 XmFontListEntry fl_entry;
63 XtPointer fl_entry_font = NULL, font_to_use = NULL;
64 char *fl_entry_font_tag;
65 Boolean found_font_set = False,
66 found_font_struct = False,
69 *type_return = XmFONT_IS_FONT;
71 if (!XmFontListInitFontContext(&fl_context, font_list))
72 return (XtPointer)NULL;
76 fl_entry = XmFontListNextEntry(fl_context);
79 fl_entry_font = XmFontListEntryGetFont(fl_entry, type_return);
80 if (*type_return == XmFONT_IS_FONTSET)
82 fl_entry_font_tag = XmFontListEntryGetTag(fl_entry);
85 * Save the first font set found in-
86 * case the default tag is not set.
90 font_to_use = fl_entry_font;
91 found_font_set = True;
92 found_font_struct = True;
94 if (!strcmp(XmFONTLIST_DEFAULT_TAG, fl_entry_font_tag))
97 else if (!strcmp(XmFONTLIST_DEFAULT_TAG, fl_entry_font_tag))
99 /* Found right font set */
100 font_to_use = fl_entry_font;
104 XtFree((char*) fl_entry_font_tag);
109 else if (!found_font_struct)
111 font_to_use = fl_entry_font;
112 found_font_struct = True;
115 } while (fl_entry != NULL);
117 XmFontListFreeFontContext(fl_context);
119 if (!found_font_set && !found_font_struct)
120 return (XtPointer)NULL;
122 return (XtPointer)font_to_use;
126 * Strip the font out of a give fontlist.
130 XmFontList font_list,
133 XmFontType type_return;
136 if (!font_list) return False;
138 font_data = get_font(font_list, &type_return);
143 new_font->cf_type = type_return;
145 if (type_return == XmFONT_IS_FONTSET)
146 new_font->f.cf_fontset = (XFontSet)font_data;
148 new_font->f.cf_font = (XFontStruct *)font_data;
154 * Determine the pixel size of the user font. Try to match a symbol
155 * font to that size. If one can't be found, return NULL, calling
156 * function will probably default to the user font.
164 unsigned long pixel_size;
165 Display *dpy = XtDisplay(w);
167 *font_name_ptr = font_name,
170 Atom pixel_atom = XmInternAtom(dpy, "PIXEL_SIZE", FALSE);
172 /* First get the pixel size from the User Font */
173 if (userfont->cf_type == XmFONT_IS_FONT) {
174 /* If we can't get the pixel size from the user font we
175 * default to a 12 pixel font.
177 if (!XGetFontProperty(userfont->f.cf_font, pixel_atom,
181 XFontStruct **font_struct_list;
182 char **font_name_list;
185 if (!(list_size = XFontsOfFontSet(userfont->f.cf_fontset,
190 if (!XGetFontProperty(font_struct_list[0],
197 /* See if the font exists */
199 "-dt-application-medium-r-normal--%ld-*-*-*-*-*-dtsymbol-*",
201 font_names = XListFonts(dpy, font_name, 1, &nnames);
206 "-*-symbol-medium-r-normal--%ld-*-*-*-*-*", pixel_size);
207 font_names = XListFonts(dpy, font_name, 1, &nnames);
210 /* Try again with the default size */
213 "-dt-application-medium-r-normal--%ld-*-*-*-*-*-dtsymbol-*",
215 font_names = XListFonts(dpy, font_name, 1, &nnames);
222 XFreeFontNames(font_names);
223 *fontname = XtNewString (font_name);