Exemple #1
0
_X_EXPORT FcPattern *
XftXlfdParse (const char *xlfd_orig, FcBool ignore_scalable, FcBool complete)
{
    FcPattern	*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;
    int		pixel;
    int		point;
    int		resx;
    int		resy;
    int		slant_value, weight_value;
    double	dpixel;

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

    if (!pixel)
	return NULL;

    pat = FcPatternCreate ();
    if (!pat)
	return NULL;

    save = (char *) malloc (strlen (foundry) + 1);

    if (!save) {
	FcPatternDestroy (pat);
	return NULL;
    }

    if (!FcPatternAddString (pat, XFT_XLFD, (FcChar8 *) xlfd_orig)) goto bail;

    XftSplitStr (foundry, save);
    if (save[0] && strcmp (save, "*") != 0)
	if (!FcPatternAddString (pat, FC_FOUNDRY, (FcChar8 *) save)) goto bail;

    XftSplitStr (family, save);
    if (save[0] && strcmp (save, "*") != 0)
	if (!FcPatternAddString (pat, FC_FAMILY, (FcChar8 *) save)) goto bail;

    weight_value = _XftMatchSymbolic (XftXlfdWeights, NUM_XLFD_WEIGHTS,
				      XftSplitStr (weight_name, save),
				      FC_WEIGHT_MEDIUM);
    if (!FcPatternAddInteger (pat, FC_WEIGHT, weight_value))
	goto bail;

    slant_value = _XftMatchSymbolic (XftXlfdSlants, NUM_XLFD_SLANTS,
				     XftSplitStr (slant, save),
				     FC_SLANT_ROMAN);
    if (!FcPatternAddInteger (pat, FC_SLANT, slant_value))
	goto bail;

    dpixel = (double) pixel;

    if (point > 0)
    {
	if (!FcPatternAddDouble (pat, FC_SIZE, ((double) point) / 10.0)) goto bail;
	if (pixel <= 0 && resy > 0)
	{
	    dpixel = (double) point * (double) resy / 720.0;
	}
    }

    if (dpixel > 0)
	if (!FcPatternAddDouble (pat, FC_PIXEL_SIZE, dpixel)) goto bail;

    free (save);
    return pat;

bail:
    free (save);
    FcPatternDestroy (pat);
    return NULL;
}
Exemple #2
0
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;
}