示例#1
0
文件: xftdpy.c 项目: dikerex/theqvd
static XftPattern *
_XftDefaultInit (Display *dpy)
{
    XftPattern	*pat;

    pat = XftPatternCreate ();
    if (!pat)
	goto bail0;

    if (!_XftDefaultInitBool (dpy, pat, XFT_CORE))
	goto bail1;
    if (!_XftDefaultInitDouble (dpy, pat, XFT_SCALE))
	goto bail1;
    if (!_XftDefaultInitDouble (dpy, pat, XFT_DPI))
	goto bail1;
    if (!_XftDefaultInitBool (dpy, pat, XFT_RENDER))
	goto bail1;
    if (!_XftDefaultInitInteger (dpy, pat, XFT_RGBA))
	goto bail1;
    if (!_XftDefaultInitBool (dpy, pat, XFT_ANTIALIAS))
	goto bail1;
    if (!_XftDefaultInitBool (dpy, pat, XFT_MINSPACE))
	goto bail1;
    
    return pat;
    
bail1:
    XftPatternDestroy (pat);
bail0:
    return 0;
}
示例#2
0
status
ws_create_font(FontObj f, DisplayObj d)
{ XpceFontInfo xref;
  DisplayWsXref r = d->ws_ref;
  XftFont *xft = NULL;

  if ( !instanceOfObject(f->x_name, ClassCharArray) ||
       !isstrA(&f->x_name->data) )			/* HACK */
  { XftPattern *p = XftPatternCreate();
    XftPattern *match;
    FcResult fcrc;
    int i;
    char *fam;
    int mono = FALSE;
    Real  scale  = getClassVariableValueObject(f, NAME_scale);
    double fscale = (scale ? valReal(scale) : 1.0);

    if ( f->family == NAME_screen )
    { fam = "monospace";
      mono = TRUE;
    } else
      fam = strName(f->family);

    XftPatternAddString(p, XFT_FAMILY, fam);
    XftPatternAddDouble(p, XFT_PIXEL_SIZE, (double)valInt(f->points)*fscale);
    if ( f->style == NAME_italic )
      XftPatternAddInteger(p, XFT_SLANT, XFT_SLANT_ITALIC);
    else if ( f->style == NAME_roman )
      XftPatternAddInteger(p, XFT_SLANT, XFT_SLANT_ROMAN);
    else if ( f->style == NAME_bold )
      XftPatternAddInteger(p, XFT_WEIGHT, XFT_WEIGHT_BOLD);

    if ( mono )
    { DEBUG(NAME_font, Cprintf("Asking for fixed\n"));
      XftPatternAddInteger(p, XFT_SPACING, XFT_MONO);
    }

    if ( !(match = XftFontMatch(r->display_xref, r->screen, p, &fcrc)) )
    { DEBUG(NAME_font, Cprintf("XftFontMatch() failed. Calling replaceFont()\n"));
      return replaceFont(f, d);
    }

#ifdef HAVE_XFTNAMEUNPARSE
    DEBUG(NAME_font,
	  { char buf[1024];
	    XftNameUnparse(match, buf, sizeof(buf));
	    Cprintf("Match = '%s'\n", buf);
	  });
示例#3
0
文件: xftxlfd.c 项目: dikerex/theqvd
XftPattern *
XftXlfdParse (const char *xlfd_orig, Bool ignore_scalable, Bool complete)
{
    XftPattern	*pat;
    const char	*xlfd = xlfd_orig;
    const char	*foundry;
    const char	*family;
    const char	*weight_name;
    const char	*slant;
    const char	*registry;
    const char	*encoding;
    char	*save;
    char	style[128];
    int		pixel;
    int		point;
    int		resx;
    int		resy;
    int		slant_value, weight_value;
    double	dpixel;

    if (*xlfd != '-')
	return 0;
    if (!(xlfd = strchr (foundry = ++xlfd, '-'))) return 0;
    if (!(xlfd = strchr (family = ++xlfd, '-'))) return 0;
    if (!(xlfd = strchr (weight_name = ++xlfd, '-'))) return 0;
    if (!(xlfd = strchr (slant = ++xlfd, '-'))) return 0;
    if (!(xlfd = strchr (/* setwidth_name = */ ++xlfd, '-'))) return 0;
    if (!(xlfd = strchr (/* add_style_name = */ ++xlfd, '-'))) return 0;
    if (!(xlfd = _XftGetInt (++xlfd, &pixel))) return 0;
    if (!(xlfd = _XftGetInt (++xlfd, &point))) return 0;
    if (!(xlfd = _XftGetInt (++xlfd, &resx))) return 0;
    if (!(xlfd = _XftGetInt (++xlfd, &resy))) return 0;
    if (!(xlfd = strchr (/* spacing = */ ++xlfd, '-'))) return 0;
    if (!(xlfd = strchr (/* average_width = */ ++xlfd, '-'))) return 0;
    if (!(xlfd = strchr (registry = ++xlfd, '-'))) return 0;
    /* make sure no fields follow this one */
    if ((xlfd = strchr (encoding = ++xlfd, '-'))) return 0;

    if (ignore_scalable && !pixel)
	return 0;
    
    pat = XftPatternCreate ();
    if (!pat)
	return 0;
    
    save = (char *) malloc (strlen (foundry) + 1);
    
    if (!save)
	return 0;

    if (!XftPatternAddString (pat, XFT_XLFD, xlfd_orig)) goto bail;
    
    _XftSplitStr (foundry, save);
    if (save[0] && strcmp (save, "*") != 0)
	if (!XftPatternAddString (pat, XFT_FOUNDRY, save)) goto bail;
    
    _XftSplitStr (family, save);
    if (save[0] && strcmp (save, "*") != 0)
	if (!XftPatternAddString (pat, XFT_FAMILY, save)) goto bail;
    
    weight_value = _XftMatchSymbolic (XftXlfdWeights, NUM_XLFD_WEIGHTS,
				      _XftSplitStr (weight_name, save),
				      XFT_WEIGHT_MEDIUM);
    if (!XftPatternAddInteger (pat, XFT_WEIGHT, weight_value)) 
	goto bail;
    
    slant_value = _XftMatchSymbolic (XftXlfdSlants, NUM_XLFD_SLANTS,
				     _XftSplitStr (slant, save),
				     XFT_SLANT_ROMAN);
    if (!XftPatternAddInteger (pat, XFT_SLANT, slant_value)) 
	goto bail;
    
    dpixel = (double) pixel;
    
    if (complete)
    {
	/*
	 * Build a style name
	 */
	style[0] = '\0';
	switch (weight_value) {
	case XFT_WEIGHT_LIGHT: strcat (style, "light"); break;
	case XFT_WEIGHT_DEMIBOLD: strcat (style, "demibold"); break;
	case XFT_WEIGHT_BOLD: strcat (style, "bold"); break;
	case XFT_WEIGHT_BLACK: strcat (style, "black"); break;
	}
	if (slant_value != XFT_SLANT_ROMAN) {
	    if (style[0])
		strcat (style, " ");
	    switch (slant_value) {
	    case XFT_SLANT_ITALIC: strcat (style, "italic"); break;
	    case XFT_SLANT_OBLIQUE: strcat (style, "oblique"); break;
	    }
	}
	if (!style[0])
	    strcat (style, "Regular");
	
	if (!XftPatternAddString (pat, XFT_STYLE, style))
	    goto bail;
	if (!XftPatternAddBool (pat, XFT_SCALABLE, pixel == 0)) goto bail;
	if (!XftPatternAddBool (pat, XFT_CORE, True)) goto bail;
	if (!XftPatternAddBool (pat, XFT_ANTIALIAS, False)) goto bail;
    }
    else
    {
	if (point > 0)
	{
	    if (!XftPatternAddDouble (pat, XFT_SIZE, ((double) point) / 10.0)) goto bail;
	    if (pixel <= 0 && resy > 0)
	    {
		dpixel = (double) point * (double) resy / 720.0;
	    }
	}
    }
    
    if (dpixel > 0)
	if (!XftPatternAddDouble (pat, XFT_PIXEL_SIZE, dpixel)) goto bail;
    
    _XftDownStr (registry, save);
    if (registry[0] && !strchr (registry, '*'))
	if (!XftPatternAddString (pat, XFT_ENCODING, save)) goto bail;

    free (save);
    return pat;
    
bail:
    free (save);
    XftPatternDestroy (pat);
    return 0;
}
示例#4
0
TkFont *
TkpGetFontFromAttributes(
    TkFont *tkFontPtr,		/* If non-NULL, store the information in this
				 * existing TkFont structure, rather than
				 * allocating a new structure to hold the
				 * font; the existing contents of the font
				 * will be released. If NULL, a new TkFont
				 * structure is allocated. */
    Tk_Window tkwin,		/* For display where font will be used. */
    CONST TkFontAttributes *faPtr)
				/* Set of attributes to match. */
{
    XftPattern *pattern;
    int weight, slant;
    UnixFtFont *fontPtr;

#if DEBUG_FONTSEL
    printf("TkpGetFontFromAttributes %s-%d %d %d\n", faPtr->family,
	    faPtr->size, faPtr->weight, faPtr->slant);
#endif /* DEBUG_FONTSEL */
    pattern = XftPatternCreate();
    if (faPtr->family) {
	XftPatternAddString(pattern, XFT_FAMILY, faPtr->family);
    }
    if (faPtr->size > 0) {
	XftPatternAddDouble(pattern, XFT_SIZE, (double)faPtr->size);
    } else if (faPtr->size < 0) {
	XftPatternAddInteger(pattern, XFT_PIXEL_SIZE, -faPtr->size);
    } else {
	XftPatternAddDouble(pattern, XFT_SIZE, 12.0);
    }
    switch (faPtr->weight) {
    case TK_FW_NORMAL:
    default:
	weight = XFT_WEIGHT_MEDIUM;
	break;
    case TK_FW_BOLD:
	weight = XFT_WEIGHT_BOLD;
	break;
    }
    XftPatternAddInteger(pattern, XFT_WEIGHT, weight);
    switch (faPtr->slant) {
    case TK_FS_ROMAN:
    default:
	slant = XFT_SLANT_ROMAN;
	break;
    case TK_FS_ITALIC:
	slant = XFT_SLANT_ITALIC;
	break;
    case TK_FS_OBLIQUE:
	slant = XFT_SLANT_OBLIQUE;
	break;
    }
    XftPatternAddInteger(pattern, XFT_SLANT, slant);

    fontPtr = (UnixFtFont *) tkFontPtr;
    if (fontPtr != NULL) {
	FinishedWithFont(fontPtr);
    }
    fontPtr = InitFont(tkwin, pattern, fontPtr);
    if (!fontPtr) {
	return NULL;
    }
    return &fontPtr->font;
}
示例#5
0
TkFont *
TkpGetFontFromAttributes(
    TkFont *tkFontPtr,		/* If non-NULL, store the information in this
				 * existing TkFont structure, rather than
				 * allocating a new structure to hold the
				 * font; the existing contents of the font
				 * will be released. If NULL, a new TkFont
				 * structure is allocated. */
    Tk_Window tkwin,		/* For display where font will be used. */
    const TkFontAttributes *faPtr)
				/* Set of attributes to match. */
{
    XftPattern *pattern;
    int weight, slant;
    UnixFtFont *fontPtr;

#if DEBUG_FONTSEL
    printf("TkpGetFontFromAttributes %s-%d %d %d\n", faPtr->family,
	    faPtr->size, faPtr->weight, faPtr->slant);
#endif /* DEBUG_FONTSEL */
    pattern = XftPatternCreate();
    if (faPtr->family) {
	XftPatternAddString(pattern, XFT_FAMILY, faPtr->family);
    }
    if (faPtr->size > 0) {
	XftPatternAddDouble(pattern, XFT_SIZE, (double)faPtr->size);
    } else if (faPtr->size < 0) {
	XftPatternAddInteger(pattern, XFT_PIXEL_SIZE, -faPtr->size);
    } else {
	XftPatternAddDouble(pattern, XFT_SIZE, 12.0);
    }
    switch (faPtr->weight) {
    case TK_FW_NORMAL:
    default:
	weight = XFT_WEIGHT_MEDIUM;
	break;
    case TK_FW_BOLD:
	weight = XFT_WEIGHT_BOLD;
	break;
    }
    XftPatternAddInteger(pattern, XFT_WEIGHT, weight);
    switch (faPtr->slant) {
    case TK_FS_ROMAN:
    default:
	slant = XFT_SLANT_ROMAN;
	break;
    case TK_FS_ITALIC:
	slant = XFT_SLANT_ITALIC;
	break;
    case TK_FS_OBLIQUE:
	slant = XFT_SLANT_OBLIQUE;
	break;
    }
    XftPatternAddInteger(pattern, XFT_SLANT, slant);

    fontPtr = (UnixFtFont *) tkFontPtr;
    if (fontPtr != NULL) {
	FinishedWithFont(fontPtr);
    }
    fontPtr = InitFont(tkwin, pattern, fontPtr);

    /*
     * Hack to work around issues with weird issues with Xft/Xrender
     * connection. For details, see comp.lang.tcl thread starting from
     * <*****@*****.**>
     */

    if (!fontPtr) {
	XftPatternAddBool(pattern, XFT_RENDER, FcFalse);
	fontPtr = InitFont(tkwin, pattern, fontPtr);
    }

    if (!fontPtr) {
	FcPatternDestroy(pattern);
	return NULL;
    }

    fontPtr->font.fa.underline = faPtr->underline;
    fontPtr->font.fa.overstrike = faPtr->overstrike;
    return &fontPtr->font;
}