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 if (fl_entry_font_tag != NULL)
105 XtFree((char*) fl_entry_font_tag);
110 else if (!found_font_struct)
112 font_to_use = fl_entry_font;
113 found_font_struct = True;
116 } while (fl_entry != NULL);
118 XmFontListFreeFontContext(fl_context);
120 if (!found_font_set && !found_font_struct)
121 return (XtPointer)NULL;
123 return (XtPointer)font_to_use;
127 * Strip the font out of a give fontlist.
131 XmFontList font_list,
134 XmFontType type_return;
137 if (!font_list) return False;
139 font_data = get_font(font_list, &type_return);
144 new_font->cf_type = type_return;
146 if (type_return == XmFONT_IS_FONTSET)
147 new_font->f.cf_fontset = (XFontSet)font_data;
149 new_font->f.cf_font = (XFontStruct *)font_data;
155 * Determine the pixel size of the user font. Try to match a symbol
156 * font to that size. If one can't be found, return NULL, calling
157 * function will probably default to the user font.
165 unsigned long pixel_size;
166 Display *dpy = XtDisplay(w);
168 *font_name_ptr = font_name,
171 Atom pixel_atom = XmInternAtom(dpy, "PIXEL_SIZE", FALSE);
173 /* First get the pixel size from the User Font */
174 if (userfont->cf_type == XmFONT_IS_FONT) {
175 /* If we can't get the pixel size from the user font we
176 * default to a 12 pixel font.
178 if (!XGetFontProperty(userfont->f.cf_font, pixel_atom,
182 XFontStruct **font_struct_list;
183 char **font_name_list;
186 if (!(list_size = XFontsOfFontSet(userfont->f.cf_fontset,
191 if (!XGetFontProperty(font_struct_list[0],
198 /* See if the font exists */
200 "-dt-application-medium-r-normal--%ld-*-*-*-*-*-dtsymbol-*",
202 font_names = XListFonts(dpy, font_name, 1, &nnames);
207 "-*-symbol-medium-r-normal--%ld-*-*-*-*-*", pixel_size);
208 font_names = XListFonts(dpy, font_name, 1, &nnames);
211 /* Try again with the default size */
214 "-dt-application-medium-r-normal--%ld-*-*-*-*-*-dtsymbol-*",
216 font_names = XListFonts(dpy, font_name, 1, &nnames);
223 XFreeFontNames(font_names);
224 *fontname = XtNewString (font_name);