1c76ae52dSmrg/* 2c76ae52dSmrg * Copyright © 2000 Keith Packard 3c76ae52dSmrg * 4c76ae52dSmrg * Permission to use, copy, modify, distribute, and sell this software and its 5c76ae52dSmrg * documentation for any purpose is hereby granted without fee, provided that 6c76ae52dSmrg * the above copyright notice appear in all copies and that both that 7c76ae52dSmrg * copyright notice and this permission notice appear in supporting 8c76ae52dSmrg * documentation, and that the name of Keith Packard not be used in 9c76ae52dSmrg * advertising or publicity pertaining to distribution of the software without 10c76ae52dSmrg * specific, written prior permission. Keith Packard makes no 11c76ae52dSmrg * representations about the suitability of this software for any purpose. It 12c76ae52dSmrg * is provided "as is" without express or implied warranty. 13c76ae52dSmrg * 14c76ae52dSmrg * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 15c76ae52dSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 16c76ae52dSmrg * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR 17c76ae52dSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 18c76ae52dSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 19c76ae52dSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 20c76ae52dSmrg * PERFORMANCE OF THIS SOFTWARE. 21c76ae52dSmrg */ 22c76ae52dSmrg 23c76ae52dSmrg#include "xftint.h" 24c76ae52dSmrg 25c76ae52dSmrg_X_EXPORT FcPattern * 26c76ae52dSmrgXftFontMatch (Display *dpy, 27c76ae52dSmrg int screen, 28c76ae52dSmrg _Xconst FcPattern *pattern, 29c76ae52dSmrg FcResult *result) 30c76ae52dSmrg{ 31c76ae52dSmrg FcPattern *new; 32c76ae52dSmrg FcPattern *match; 33c76ae52dSmrg 340d590c07Smrg if (!XftInit (NULL)) 350d590c07Smrg return NULL; 362836776bSmrg 37c76ae52dSmrg new = FcPatternDuplicate (pattern); 38c76ae52dSmrg if (!new) 390d590c07Smrg return NULL; 40c76ae52dSmrg 41c76ae52dSmrg if (XftDebug () & XFT_DBG_OPENV) 42c76ae52dSmrg { 43c76ae52dSmrg printf ("XftFontMatch pattern "); 44c76ae52dSmrg FcPatternPrint (new); 45c76ae52dSmrg } 460d590c07Smrg FcConfigSubstitute (NULL, new, FcMatchPattern); 47c76ae52dSmrg if (XftDebug () & XFT_DBG_OPENV) 48c76ae52dSmrg { 49c76ae52dSmrg printf ("XftFontMatch after FcConfig substitutions "); 50c76ae52dSmrg FcPatternPrint (new); 51c76ae52dSmrg } 52c76ae52dSmrg XftDefaultSubstitute (dpy, screen, new); 53c76ae52dSmrg if (XftDebug () & XFT_DBG_OPENV) 54c76ae52dSmrg { 55c76ae52dSmrg printf ("XftFontMatch after X resource substitutions "); 56c76ae52dSmrg FcPatternPrint (new); 57c76ae52dSmrg } 580d590c07Smrg 590d590c07Smrg match = FcFontMatch (NULL, new, result); 60c76ae52dSmrg if (XftDebug () & XFT_DBG_OPENV) 61c76ae52dSmrg { 62c76ae52dSmrg printf ("XftFontMatch result "); 63c76ae52dSmrg FcPatternPrint (match); 64c76ae52dSmrg } 65c76ae52dSmrg FcPatternDestroy (new); 66c76ae52dSmrg return match; 67c76ae52dSmrg} 68c76ae52dSmrg 69c76ae52dSmrg_X_EXPORT XftFont * 70c76ae52dSmrgXftFontOpen (Display *dpy, int screen, ...) 71c76ae52dSmrg{ 72c76ae52dSmrg va_list va; 73c76ae52dSmrg FcPattern *pat; 74c76ae52dSmrg FcPattern *match; 75c76ae52dSmrg FcResult result; 76c76ae52dSmrg XftFont *font; 77c76ae52dSmrg 78c76ae52dSmrg va_start (va, screen); 790d590c07Smrg pat = FcPatternVaBuild (NULL, va); 80c76ae52dSmrg va_end (va); 81c76ae52dSmrg if (!pat) 82c76ae52dSmrg { 83c76ae52dSmrg if (XftDebug () & XFT_DBG_OPEN) 84c76ae52dSmrg printf ("XftFontOpen: Invalid pattern argument\n"); 850d590c07Smrg return NULL; 86c76ae52dSmrg } 87c76ae52dSmrg match = XftFontMatch (dpy, screen, pat, &result); 88c76ae52dSmrg if (XftDebug () & XFT_DBG_OPEN) 89c76ae52dSmrg { 90c76ae52dSmrg printf ("Pattern "); 91c76ae52dSmrg FcPatternPrint (pat); 92c76ae52dSmrg if (match) 93c76ae52dSmrg { 94c76ae52dSmrg printf ("Match "); 95c76ae52dSmrg FcPatternPrint (match); 96c76ae52dSmrg } 97c76ae52dSmrg else 98c76ae52dSmrg printf ("No Match\n"); 99c76ae52dSmrg } 100c76ae52dSmrg FcPatternDestroy (pat); 101c76ae52dSmrg if (!match) 1020d590c07Smrg return NULL; 1032836776bSmrg 104c76ae52dSmrg font = XftFontOpenPattern (dpy, match); 105c76ae52dSmrg if (!font) 106c76ae52dSmrg { 107c76ae52dSmrg if (XftDebug () & XFT_DBG_OPEN) 108c76ae52dSmrg printf ("No Font\n"); 109c76ae52dSmrg FcPatternDestroy (match); 110c76ae52dSmrg } 111c76ae52dSmrg 112c76ae52dSmrg return font; 113c76ae52dSmrg} 114c76ae52dSmrg 115c76ae52dSmrg_X_EXPORT XftFont * 116c76ae52dSmrgXftFontOpenName (Display *dpy, int screen, const char *name) 117c76ae52dSmrg{ 118c76ae52dSmrg FcPattern *pat; 119c76ae52dSmrg FcPattern *match; 120c76ae52dSmrg FcResult result; 121c76ae52dSmrg XftFont *font; 122c76ae52dSmrg 123de3c0529Smrg pat = FcNameParse ((const FcChar8 *) name); 124c76ae52dSmrg if (XftDebug () & XFT_DBG_OPEN) 125c76ae52dSmrg { 126c76ae52dSmrg printf ("XftFontOpenName \"%s\": ", name); 127c76ae52dSmrg if (pat) 128c76ae52dSmrg FcPatternPrint (pat); 129c76ae52dSmrg else 130c76ae52dSmrg printf ("Invalid name\n"); 131c76ae52dSmrg } 1322836776bSmrg 133c76ae52dSmrg if (!pat) 1340d590c07Smrg return NULL; 135c76ae52dSmrg match = XftFontMatch (dpy, screen, pat, &result); 136c76ae52dSmrg if (XftDebug () & XFT_DBG_OPEN) 137c76ae52dSmrg { 138c76ae52dSmrg if (match) 139c76ae52dSmrg { 140c76ae52dSmrg printf ("Match "); 141c76ae52dSmrg FcPatternPrint (match); 142c76ae52dSmrg } 143c76ae52dSmrg else 144c76ae52dSmrg printf ("No Match\n"); 145c76ae52dSmrg } 146c76ae52dSmrg FcPatternDestroy (pat); 147c76ae52dSmrg if (!match) 1480d590c07Smrg return NULL; 1492836776bSmrg 150c76ae52dSmrg font = XftFontOpenPattern (dpy, match); 151c76ae52dSmrg if (!font) 152c76ae52dSmrg { 153c76ae52dSmrg if (XftDebug () & XFT_DBG_OPEN) 154c76ae52dSmrg printf ("No Font\n"); 155c76ae52dSmrg FcPatternDestroy (match); 156c76ae52dSmrg } 1572836776bSmrg 158c76ae52dSmrg return font; 159c76ae52dSmrg} 160c76ae52dSmrg 161c76ae52dSmrg_X_EXPORT XftFont * 162c76ae52dSmrgXftFontOpenXlfd (Display *dpy, int screen, const char *xlfd) 163c76ae52dSmrg{ 164c76ae52dSmrg FcPattern *pat; 165c76ae52dSmrg FcPattern *match; 166c76ae52dSmrg FcResult result; 167c76ae52dSmrg XftFont *font; 168c76ae52dSmrg 169c76ae52dSmrg pat = XftXlfdParse (xlfd, FcFalse, FcFalse); 170c76ae52dSmrg if (XftDebug () & XFT_DBG_OPEN) 171c76ae52dSmrg { 172c76ae52dSmrg printf ("XftFontOpenXlfd \"%s\": ", xlfd); 173c76ae52dSmrg if (pat) 174c76ae52dSmrg printf ("Invalid xlfd\n"); 175c76ae52dSmrg else 176c76ae52dSmrg FcPatternPrint (pat); 177c76ae52dSmrg } 1782836776bSmrg 179c76ae52dSmrg if (!pat) 1800d590c07Smrg return NULL; 181c76ae52dSmrg match = XftFontMatch (dpy, screen, pat, &result); 182c76ae52dSmrg if (XftDebug () & XFT_DBG_OPEN) 183c76ae52dSmrg { 184c76ae52dSmrg if (match) 185c76ae52dSmrg { 186c76ae52dSmrg printf ("Match "); 187c76ae52dSmrg FcPatternPrint (match); 188c76ae52dSmrg } 189c76ae52dSmrg else 190c76ae52dSmrg printf ("No Match\n"); 191c76ae52dSmrg } 192c76ae52dSmrg FcPatternDestroy (pat); 193c76ae52dSmrg if (!match) 1940d590c07Smrg return NULL; 1952836776bSmrg 196c76ae52dSmrg font = XftFontOpenPattern (dpy, match); 197c76ae52dSmrg if (!font) 198c76ae52dSmrg { 199c76ae52dSmrg if (XftDebug () & XFT_DBG_OPEN) 200c76ae52dSmrg printf ("No Font\n"); 201c76ae52dSmrg FcPatternDestroy (match); 202c76ae52dSmrg } 2032836776bSmrg 204c76ae52dSmrg return font; 205c76ae52dSmrg} 206c76ae52dSmrg 207