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