diff options
Diffstat (limited to 'xc/lib/Xft')
-rw-r--r-- | xc/lib/Xft/Imakefile | 31 | ||||
-rw-r--r-- | xc/lib/Xft/Xft.h | 182 | ||||
-rw-r--r-- | xc/lib/Xft/Xft.man | 201 | ||||
-rw-r--r-- | xc/lib/Xft/XftFreetype.h | 26 | ||||
-rw-r--r-- | xc/lib/Xft/xftcfg.c | 103 | ||||
-rw-r--r-- | xc/lib/Xft/xftcolor.c | 125 | ||||
-rw-r--r-- | xc/lib/Xft/xftcore.c | 26 | ||||
-rw-r--r-- | xc/lib/Xft/xftdraw.c | 162 | ||||
-rw-r--r-- | xc/lib/Xft/xftextent.c | 4 | ||||
-rw-r--r-- | xc/lib/Xft/xftfont.c | 34 | ||||
-rw-r--r-- | xc/lib/Xft/xftfreetype.c | 48 | ||||
-rw-r--r-- | xc/lib/Xft/xftglyphs.c | 56 | ||||
-rw-r--r-- | xc/lib/Xft/xftgram.y | 3 | ||||
-rw-r--r-- | xc/lib/Xft/xftint.h | 132 | ||||
-rw-r--r-- | xc/lib/Xft/xftlex.l | 53 | ||||
-rw-r--r-- | xc/lib/Xft/xftlist.c | 321 | ||||
-rw-r--r-- | xc/lib/Xft/xftname.c | 143 | ||||
-rw-r--r-- | xc/lib/Xft/xftpat.c | 14 | ||||
-rw-r--r-- | xc/lib/Xft/xftrender.c | 14 | ||||
-rw-r--r-- | xc/lib/Xft/xftxlfd.c | 93 |
20 files changed, 1278 insertions, 493 deletions
diff --git a/xc/lib/Xft/Imakefile b/xc/lib/Xft/Imakefile index 778a4b6fd..5082af006 100644 --- a/xc/lib/Xft/Imakefile +++ b/xc/lib/Xft/Imakefile @@ -1,4 +1,4 @@ -XCOMM $XFree86: xc/lib/Xft/Imakefile,v 1.4 2000/11/29 08:39:20 keithp Exp $ +XCOMM $XFree86: xc/lib/Xft/Imakefile,v 1.7 2000/12/01 03:27:57 keithp Exp $ #define DoNormalLib NormalLibXft #define DoSharedLib SharedLibXft @@ -13,8 +13,7 @@ XCOMM $XFree86: xc/lib/Xft/Imakefile,v 1.4 2000/11/29 08:39:20 keithp Exp $ #include <Threads.tmpl> -YFLAGS = -d -p XftConfig -LFLAGS = -PXftConfig -s +YFLAGS = -d #ifndef XftLibDir #define XftLibDir $(LIBDIR) @@ -29,25 +28,25 @@ XFTCONFIG=$(XFTLIBDIR)/XftConfig TYPE1DIR=XftType1Dir CONFIG_DEFS=-DXFT_TYPE1_DIR=\"$(TYPE1DIR)\" INCLUDES=$(FREETYPE2INCLUDES) -DEFINES=-DXFT_DEFAULT_PATH=\"$(XFTCONFIG)\" $(FREETYPE2DEFINES) -REQUIREDLIBS=$(LDPRELIBS) $(XRENDER) $(XLIB) $(FREETYPE2LIB) +DEFINES=-DXFT_DEFAULT_PATH=\"$(XFTCONFIG)\" $(FREETYPE2DEFINES) $(RENDERDEFINES) +REQUIREDLIBS=$(LDPRELIBS) $(XRENDERLIB) $(XLIB) $(FREETYPE2LIB) HEADERS = Xft.h XftFreetype.h - SRCS = xftcfg.c xftcore.c xftdbg.c xftdir.c xftdpy.c xftdraw.c \ - xftextent.c xftfont.c xftfreetype.c xftfs.c xftglyphs.c \ - xftgram.c xftinit.c xftlex.c xftmatch.c xftname.c xftpat.c \ - xftrender.c xftstr.c xftxlfd.c - - OBJS = xftcfg.o xftcore.o xftdbg.o xftdir.o xftdpy.o xftdraw.o \ - xftextent.o xftfont.o xftfreetype.o xftfs.o xftglyphs.o \ - xftgram.o xftinit.o xftlex.o xftmatch.o xftname.o xftpat.o \ - xftrender.o xftstr.o xftxlfd.o + SRCS = xftcfg.c xftcolor.c xftcore.c xftdbg.c xftdir.c xftdpy.c \ + xftdraw.c xftextent.c xftfont.c xftfreetype.c xftfs.c \ + xftglyphs.c xftgram.c xftinit.c xftlex.c xftlist.c xftmatch.c \ + xftname.c xftpat.c xftrender.c xftstr.c xftxlfd.c + + OBJS = xftcfg.o xftcolor.o xftcore.o xftdbg.o xftdir.o xftdpy.o \ + xftdraw.o xftextent.o xftfont.o xftfreetype.o xftfs.o \ + xftglyphs.o xftgram.o xftinit.o xftlex.o xftlist.o xftmatch.o \ + xftname.o xftpat.o xftrender.o xftstr.o xftxlfd.o #include <Library.tmpl> -LexFile(xftlex) -YaccFile(xftgram,$(YFLAGS)) +LexFilePrefix(xftlex,XftConfig) +YaccFilePrefix(xftgram,$(YFLAGS),XftConfig) #if DoSharedLib && SharedDataSeparation SpecialCObjectRule(sharedlib,NullParameter,$(SHLIBDEF)) diff --git a/xc/lib/Xft/Xft.h b/xc/lib/Xft/Xft.h index 38e48733e..618372f7a 100644 --- a/xc/lib/Xft/Xft.h +++ b/xc/lib/Xft/Xft.h @@ -1,5 +1,5 @@ /* - * $XFree86: xc/lib/Xft/Xft.h,v 1.4 2000/11/29 08:39:20 keithp Exp $ + * $XFree86: xc/lib/Xft/Xft.h,v 1.10 2000/12/03 19:03:22 keithp Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -51,6 +51,10 @@ #define XFT_SCALE "scale" /* double */ #define XFT_RENDER "render" /* Bool */ +/* specific to FreeType rasterizer */ +#define XFT_CHAR_WIDTH "charwidth" /* Int */ +#define XFT_CHAR_HEIGHT "charheight"/* Int */ + #define XFT_WEIGHT_LIGHT 0 #define XFT_WEIGHT_MEDIUM 100 #define XFT_WEIGHT_DEMIBOLD 180 @@ -113,21 +117,6 @@ typedef struct _XftFontSet { XftPattern **fonts; } XftFontSet; -XftFontSet * -XftFontSetCreate (void); - -void -XftFontSetDestroy (XftFontSet *s); - -Bool -XftFontSetAdd (XftFontSet *s, XftPattern *font); - -void -XftPatternPrint (XftPattern *p); - -XftPattern * -XftMatchFont (Display *dpy, int screen, XftPattern *pattern, XftResult *result); - typedef struct _XftFontStruct XftFontStruct; typedef struct _XftFont { @@ -149,21 +138,44 @@ typedef struct _XftFont { typedef struct _XftDraw XftDraw; -XftFont * -XftOpenFont (Display *dpy, XftPattern *pattern); +typedef struct _XftColor { + unsigned long pixel; + XRenderColor color; +} XftColor; -XftFont * -XftPatternOpenFont (Display *dpy, int screen, ...); - +typedef struct _XftObjectSet { + int nobject; + int sobject; + const char **objects; +} XftObjectSet; + +/* xftcfg.c */ Bool -XftDefaultSet (Display *dpy, XftPattern *defaults); +XftConfigSubstitute (XftPattern *p); -XftPattern * -XftNameParse (const char *name); +/* xftcolor.c */ +Bool +XftColorAllocName (Display *dpy, + Visual *visual, + Colormap cmap, + char *name, + XftColor *result); -XftFont * -XftNameOpenFont (Display *dpy, int screen, const char *name); +Bool +XftColorAllocValue (Display *dpy, + Visual *visual, + Colormap cmap, + XRenderColor *color, + XftColor *result); + +void +XftColorFree (Display *dpy, + Visual *visual, + Colormap cmap, + XftColor *color); + +/* xftcore.c */ /* xftdbg.c */ void XftValuePrint (XftValue v); @@ -179,6 +191,15 @@ XftFontSetPrint (XftFontSet *s); /* xftdir.c */ /* xftdpy.c */ +Bool +XftDefaultHasRender (Display *dpy); + +Bool +XftDefaultSet (Display *dpy, XftPattern *defaults); + +void +XftDefaultSubstitute (Display *dpy, int screen, XftPattern *pattern); + /* xftdraw.c */ XftDraw * @@ -188,11 +209,15 @@ XftDrawCreate (Display *dpy, Colormap colormap); void -XftDrawDestroy (XftDraw *d); +XftDrawChange (XftDraw *draw, + Drawable drawable); + +void +XftDrawDestroy (XftDraw *draw); void XftDrawString8 (XftDraw *d, - XRenderColor *color, + XftColor *color, XftFont *font, int x, int y, @@ -201,7 +226,7 @@ XftDrawString8 (XftDraw *d, void XftDrawString16 (XftDraw *draw, - XRenderColor *color, + XftColor *color, XftFont *font, int x, int y, @@ -210,15 +235,15 @@ XftDrawString16 (XftDraw *draw, void XftDrawString32 (XftDraw *draw, - XRenderColor *color, + XftColor *color, XftFont *font, int x, int y, - unsigned long *string, + unsigned int *string, int len); void XftDrawRect (XftDraw *d, - XRenderColor *color, + XftColor *color, int x, int y, unsigned int width, @@ -244,7 +269,7 @@ XftTextExtents16 (Display *dpy, void XftTextExtents32 (Display *dpy, XftFont *font, - unsigned long *string, + unsigned int *string, int len, XGlyphInfo *extents); @@ -261,12 +286,82 @@ XftFontOpen (Display *dpy, int screen, ...); XftFont * XftFontOpenName (Display *dpy, int screen, const char *name); +XftFont * +XftFontOpenXlfd (Display *dpy, int screen, const char *xlfd); + void XftFontClose (Display *dpy, XftFont *font); +Bool +XftGlyphExists (Display *dpy, XftFont *font, unsigned int glyph); + /* xftfreetype.c */ /* xftfs.c */ +XftFontSet * +XftFontSetCreate (void); + +void +XftFontSetDestroy (XftFontSet *s); + +Bool +XftFontSetAdd (XftFontSet *s, XftPattern *font); + +/* xftglyphs.c */ +/* see XftFreetype.h */ + +/* xftgram.y */ + +/* xftinit.c */ +Bool +XftInit (char *config); + +/* xftlex.l */ + +/* xftlist.c */ +XftObjectSet * +XftObjectSetCreate (void); + +Bool +XftObjectSetAdd (XftObjectSet *os, const char *object); + +void +XftObjectSetDestroy (XftObjectSet *os); + +XftObjectSet * +XftObjectSetVaBuild (const char *first, va_list va); + +XftObjectSet * +XftObjectSetBuild (const char *first, ...); + +XftFontSet * +XftListFontSets (XftFontSet **sets, + int nsets, + XftPattern *p, + XftObjectSet *os); + +XftFontSet * +XftListFontsPatternObjects (Display *dpy, + int screen, + XftPattern *pattern, + XftObjectSet *os); + +XftFontSet * +XftListFonts (Display *dpy, + int screen, + ...); + +/* xftmatch.c */ +XftPattern * +XftFontSetMatch (XftFontSet **sets, + int nsets, + XftPattern *p, + XftResult *result); + +/* xftname.c */ +XftPattern * +XftNameParse (const char *name); + /* xftpat.c */ XftPattern * XftPatternCreate (void); @@ -275,8 +370,17 @@ XftPattern * XftPatternDuplicate (XftPattern *p); void +XftValueDestroy (XftValue v); + +void +XftValueListDestroy (XftValueList *l); + +void XftPatternDestroy (XftPattern *p); +XftPatternElt * +XftPatternFind (XftPattern *p, const char *object, Bool insert); + Bool XftPatternAdd (XftPattern *p, const char *object, XftValue value, Bool append); @@ -316,4 +420,16 @@ XftPatternVaBuild (XftPattern *orig, va_list va); XftPattern * XftPatternBuild (XftPattern *orig, ...); +/* xftrender.c */ +/* see XftFreetype.h */ + +/* xftstr.c */ + +/* xftxlfd.c */ +XftPattern * +XftXlfdParse (const char *xlfd_orig, Bool ignore_scalable, Bool complete); + +XFontStruct * +XftCoreOpen (Display *dpy, XftPattern *pattern); + #endif /* _XFT_H_ */ diff --git a/xc/lib/Xft/Xft.man b/xc/lib/Xft/Xft.man index 449f87d54..0a71bc931 100644 --- a/xc/lib/Xft/Xft.man +++ b/xc/lib/Xft/Xft.man @@ -1,5 +1,5 @@ .\" -.\" $XFree86: xc/lib/Xft/Xft.man,v 1.1 2000/10/05 18:05:26 keithp Exp $ +.\" $XFree86: xc/lib/Xft/Xft.man,v 1.2 2000/11/30 06:59:45 keithp Exp $ .\" .\" Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. .\" @@ -39,107 +39,138 @@ library. .SH DATATYPES +.B XftPattern +holds a set of names with associated value lists; each name refers to a +property of a font. XftPatterns are used as inputs to the matching code as +well as holding information about specific fonts. + .B XftFont -is an opaque pointer to a font object containing references to both the X -server GlyphSet and the FreeType outline data. +contains general font metrics and a pointer to either the core XFontStruct +data or a structure holding FreeType and X Render Extension data. -.B XftFontName -contains matching information for accessing fonts. Each field is matched -with a bit in the mask indicating whether that field has valid data. +.B XftFontStruct +contains information about FreeType fonts used with the X Render Extension. -.Ds 0 -.TA .5i 3i -.ta .5i 3i -typedef struct _XftFontName { - unsigned long mask; - char *face; - char *encoding; - char *file; - int size; - int rotation; - int spacing; -} XftFontName; +.B XftFontSet +contains a list of XftPatterns. Internally Xft uses this data structure to +hold sets of fonts. Externally, Xft returns the results of listing fonts in +this format. -#define XftFontNameFace 0x1 -#define XftFontNameEncoding 0x2 -#define XftFontNameFile 0x4 -#define XftFontNameSize 0x8 -#define XftFontNameRotation 0x10 -#define XftFontNameSpacing 0x20 +.B XftObjectSet +holds a set of names and is used to specify which fields from fonts are +placed in the the list of returned patterns when listing fonts. -#define XftFontSpacingAny 0 -#define XftFontSpacingMono 1 -#define XftFontSpacingCell 2 +.B XftDraw +is an opaque object which holds information used to render to an X drawable +using either core protocol or the X Rendering extension. .SH FUNCTIONS -XftFont * -XftLoadFont (Display *dpy, XftFontName *name); - +.nf +XftFont * +XftFontOpen (Display *dpy, int screen, ...); +.fi +.B XftFontOpen +takes a list of pattern elements of the form (field, type, value) terminated +with a 0, matches that pattern against the available fonts and opens the +matching font. +.PP +Example: +.br + font = XftFontOpen (dpy, scr, + XFT_FAMILY, XftTypeString, "charter", + XFT_SIZE, XftTypeDouble, 12.0); +.PP +This opens the charter font at 12 points. The point size is automatically +converted to the correct pixel size based on the resolution of the monitor. +.PP +.nf void -XftFreeFont (Display *dpy, XftFont *font); - -int -XftFontAscent(Display *dpy, XftFont *font); - -int -XftFontDescent(Display *dpy, XftFont *font); - -int -XftFontHeight(Display *dpy, XftFont *font); - -int -XftFontMaxAdvanceWidth (Display *dpy, XftFont *font); - +XftTextExtents8 (Display *dpy, + XftFont *font, + unsigned char *string, + int len, + XGlyphInfo *extents); +.fi +.B XftTextExtents8 +computes the pixel extents of "string" when drawn with "font". +.PP +.nf +XftDraw * +XftDrawCreate (Display *dpy, + Drawable drawable, + Visual *visual, + Colormap colormap); +.fi +.B XtDrawCreate +creates a structure that can be used to render text and rectangles +to the screen. +.PP +.nf void -XftExtentsString (Display *dpy, - XftFont *font, - unsigned char *string, - int len, - XGlyphInfo *extents); - +XftDrawString8 (XftDraw *d, + XRenderColor *color, + XftFont *font, + int x, + int y, + unsigned char *string, + int len); +.fi +.B XftDrawString8 +draws "string" using "font" in "color" at "x, y". +.PP +.nf void -XftDrawString (Display *dpy, - Picture src, - XftFont *font, - Picture dst, - int srcx, - int srcy, - int x, - int y, - char *string, - int len); - +XftDrawRect (XftDraw *d, + XRenderColor *color, + int x, + int y, + unsigned int width, + unsigned int height); +.fi +.B XftDrawRect +fills a solid rectangle in the specified color. .SH XftConfig The .B XftConfig -file contains instructions for converting an XftFontName structure into -a usable set of glyphs. XftFontNames are refined through a series of -matching and editing steps. - -ents : ents ent - | - ; -ent : edit - | path - | dir +file contains configuration information for the Xft library consisting of +directories to look at for font information as well as instructions on +editing program specified font patterns before attempting to match the +available fonts. +.PP +.nf +config : "dir" STRING + | "include" STRING + | "includeif" STRING + | "match" tests "edit" edits ; -edit : MATCH patterns EDIT patterns +test : qual FIELD-NAME COMPARE CONSTANT ; -patterns: pattern patterns - | +qual : "any" + | "all" ; -pattern : FACE EQUAL STRING - | ENCODING EQUAL STRING - | FILE EQUAL STRING - | SIZE EQUAL NUMBER - | ROTATION EQUAL NUMBER - | SPACING EQUAL NUMBER +edit : FIELD-NAME ASSIGN expr SEMI ; -path : PATH STRING - ; -dir : DIR STRING - ; - +.fi +.PP +STRINGs are double-quote delimited. FIELD-NAMEs are identifiers, +ASSIGN is one of "=", "+=" or "=+". expr can contain the usual +arithmetic operators and can include FIELD-NAMEs. +.PP +"dir" adds a directory to the list of places Xft will look for fonts. +There is no particular order implied by the list; Xft treats all fonts about +the same. +.PP +"include" and "includeif" cause Xft to load more configuration parameters +from the indicated file. "includeif" doesn't elicit a complaint if the file +doesn't exist. If the file name begins with a '~' character, it refers to a +path relative to the home directory of the user. +.PP +If the tests in a "match" statement all match a user-specified pattern, the +pattern will be edited with the specified instructions. +.PP +Where ASSIGN is "=", the matching value in the pattern will be replaced by +the given expression. "+="/"=+" will prepend/append a new value to the list +of values for the indicated field. .SH RESTRICTIONS .B Xft diff --git a/xc/lib/Xft/XftFreetype.h b/xc/lib/Xft/XftFreetype.h index ca69287e3..8cd1e7dfd 100644 --- a/xc/lib/Xft/XftFreetype.h +++ b/xc/lib/Xft/XftFreetype.h @@ -1,5 +1,5 @@ /* - * $XFree86: xc/lib/Xft/XftFreetype.h,v 1.1 2000/11/29 08:39:20 keithp Exp $ + * $XFree86: xc/lib/Xft/XftFreetype.h,v 1.4 2000/12/02 10:02:04 keithp Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -45,11 +45,31 @@ struct _XftFontStruct { Bool monospace; int rgba; Bool antialias; + Bool encoded; /* use charmap */ XRenderPictFormat *format; XGlyphInfo **realized; int nrealized; }; +/* xftglyphs.c */ +void +XftGlyphLoad (Display *dpy, + XftFontStruct *font, + unsigned long *glyphs, + int nglyph); + +void +XftGlyphCheck (Display *dpy, + XftFontStruct *font, + unsigned long glyph, + unsigned long *missing, + int *nmissing); + +Bool +XftFreeTypeGlyphExists (Display *dpy, + XftFontStruct *font, + unsigned int glyph); + /* xftrender.c */ void @@ -71,7 +91,7 @@ XftRenderString32 (Display *dpy, Picture src, XftFontStruct *font, Picture dst, int srcx, int srcy, int x, int y, - unsigned long *string, int len); + unsigned int *string, int len); void XftRenderExtents8 (Display *dpy, @@ -90,7 +110,7 @@ XftRenderExtents16 (Display *dpy, void XftRenderExtents32 (Display *dpy, XftFontStruct *font, - unsigned long *string, + unsigned int *string, int len, XGlyphInfo *extents); diff --git a/xc/lib/Xft/xftcfg.c b/xc/lib/Xft/xftcfg.c index f362582da..9d15207eb 100644 --- a/xc/lib/Xft/xftcfg.c +++ b/xc/lib/Xft/xftcfg.c @@ -1,5 +1,5 @@ /* - * $XFree86: xc/lib/Xft/xftcfg.c,v 1.1 2000/11/29 08:39:21 keithp Exp $ + * $XFree86: xc/lib/Xft/xftcfg.c,v 1.4 2000/12/03 19:05:27 keithp Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -125,7 +125,7 @@ _XftConfigPromote (XftValue v) return v; } -static Bool +Bool _XftConfigCompareValue (XftValue m, XftOp op, XftValue v) @@ -414,6 +414,86 @@ _XftConfigEvaluate (XftPattern *p, XftExpr *e) return v; } +static Bool +_XftConfigAdd (XftValueList **head, + XftValueList *position, + Bool append, + XftValue value) +{ + XftValueList *new, **prev; + + new = (XftValueList *) malloc (sizeof (XftValueList)); + if (!new) + goto bail0; + + if (value.type == XftTypeString) + { + value.u.s = _XftSaveString (value.u.s); + if (!value.u.s) + goto bail1; + + } + new->value = value; + new->next = 0; + + if (append) + { + prev = &position->next; + } + else + { + for (prev = head; *prev; prev = &(*prev)->next) + { + if (*prev == position) + break; + } +#ifdef XFT_DEBUG + if (!*prev) + printf ("position not on list\n"); +#endif + } + +#ifdef XFT_DEBUG_EDIT + printf ("%s list before ", append ? "Append" : "Prepend"); + XftValueListPrint (*head); + printf ("\n"); +#endif + + new->next = *prev; + *prev = new; + +#ifdef XFT_DEBUG_EDIT + printf ("%s list after ", append ? "Append" : "Prepend"); + XftValueListPrint (*head); + printf ("\n"); +#endif + + return True; + +bail1: + free (new); +bail0: + return False; +} + +static void +_XftConfigDel (XftValueList **head, + XftValueList *position) +{ + XftValueList **prev; + + for (prev = head; *prev; prev = &(*prev)->next) + { + if (*prev == position) + { + *prev = position->next; + position->next = 0; + XftValueListDestroy (position); + break; + } + } +} + Bool XftConfigSubstitute (XftPattern *p) { @@ -453,7 +533,12 @@ XftConfigSubstitute (XftPattern *p) break; } if (t) + { +#ifdef XFT_DEBUG_EDIT + printf ("No match\n"); +#endif continue; + } #ifdef XFT_DEBUG_EDIT printf ("Substitute "); XftSubstPrint (s); @@ -470,8 +555,8 @@ XftConfigSubstitute (XftPattern *p) case XftOpAssign: if (t) { - XftValueDestroy (st[i].value->value); - st[i].value->value = v; + _XftConfigAdd (&st[i].elt->values, st[i].value, True, v); + _XftConfigDel (&st[i].elt->values, st[i].value); } else { @@ -480,10 +565,16 @@ XftConfigSubstitute (XftPattern *p) } break; case XftOpPrepend: - XftPatternAdd (p, e->field, v, False); + if (t) + _XftConfigAdd (&st[i].elt->values, st[i].value, False, v); + else + XftPatternAdd (p, e->field, v, False); break; case XftOpAppend: - XftPatternAdd (p, e->field, v, True); + if (t) + _XftConfigAdd (&st[i].elt->values, st[i].value, True, v); + else + XftPatternAdd (p, e->field, v, True); break; default: break; diff --git a/xc/lib/Xft/xftcolor.c b/xc/lib/Xft/xftcolor.c new file mode 100644 index 000000000..6443e00ec --- /dev/null +++ b/xc/lib/Xft/xftcolor.c @@ -0,0 +1,125 @@ +/* + * $XFree86: xc/lib/Xft/xftcolor.c,v 1.1 2000/12/01 03:27:57 keithp Exp $ + * + * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "xftint.h" + +Bool +XftColorAllocName (Display *dpy, + Visual *visual, + Colormap cmap, + char *name, + XftColor *result) +{ + XColor screen, exact; + + if (!XAllocNamedColor (dpy, cmap, name, &screen, &exact)) + { + /* XXX stick standard colormap stuff here */ + return False; + } + + result->pixel = screen.pixel; + result->color.red = exact.red; + result->color.green = exact.green; + result->color.blue = exact.blue; + result->color.alpha = 0xffff; + return True; +} + +static short +maskbase (unsigned long m) +{ + short i; + + if (!m) + return 0; + i = 0; + while (!(m&1)) + { + m>>=1; + i++; + } + return i; +} + +static short +masklen (unsigned long m) +{ + unsigned long y; + + y = (m >> 1) &033333333333; + y = m - y - ((y >>1) & 033333333333); + return (short) (((y + (y >> 3)) & 030707070707) % 077); +} + +Bool +XftColorAllocValue (Display *dpy, + Visual *visual, + Colormap cmap, + XRenderColor *color, + XftColor *result) +{ + if (visual->class == TrueColor) + { + int red_shift, red_len; + int green_shift, green_len; + int blue_shift, blue_len; + + red_shift = maskbase (visual->red_mask); + red_len = masklen (visual->red_mask); + green_shift = maskbase (visual->green_mask); + green_len = masklen (visual->green_mask); + blue_shift = maskbase (visual->blue_mask); + blue_len = masklen (visual->blue_mask); + result->pixel = (((color->red >> (16 - red_len)) << red_shift) | + ((color->green >> (16 - green_len)) << green_shift) | + ((color->blue >> (16 - blue_len)) << blue_shift)); + } + else + { + XColor xcolor; + + xcolor.red = color->red; + xcolor.green = color->green; + xcolor.blue = color->blue; + if (!XAllocColor (dpy, cmap, &xcolor)) + return False; + result->pixel = xcolor.pixel; + } + result->color.red = color->red; + result->color.green = color->green; + result->color.blue = color->blue; + result->color.alpha = 0xffff; + return True; +} + +void +XftColorFree (Display *dpy, + Visual *visual, + Colormap cmap, + XftColor *color) +{ + if (visual->class != TrueColor) + XFreeColors (dpy, cmap, &color->pixel, 1, 0); +} diff --git a/xc/lib/Xft/xftcore.c b/xc/lib/Xft/xftcore.c index 8360831af..692e17ad6 100644 --- a/xc/lib/Xft/xftcore.c +++ b/xc/lib/Xft/xftcore.c @@ -1,5 +1,5 @@ /* - * $XFree86: xc/lib/Xft/xftcore.c,v 1.1 2000/11/29 08:39:21 keithp Exp $ + * $XFree86: xc/lib/Xft/xftcore.c,v 1.3 2000/12/02 10:02:04 keithp Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -46,7 +46,7 @@ XftCoreConvert16 (unsigned short *string, } XChar2b * -XftCoreConvert32 (unsigned long *string, +XftCoreConvert32 (unsigned int *string, int len, XChar2b xcloc[XFT_CORE_N16LOCAL]) { @@ -128,7 +128,7 @@ XftCoreExtents16 (Display *dpy, void XftCoreExtents32 (Display *dpy, XFontStruct *fs, - unsigned long *string, + unsigned int *string, int len, XGlyphInfo *extents) { @@ -156,3 +156,23 @@ XftCoreExtents32 (Display *dpy, extents->yOff = 0; } +Bool +XftCoreGlyphExists (Display *dpy, + XFontStruct *fs, + unsigned int glyph) +{ + int direction; + int ascent, descent; + XCharStruct overall; + XChar2b xc; + + XftCoreConvert32 (&glyph, 1, &xc); + XTextExtents16 (fs, &xc, 1, &direction, + &ascent, &descent, &overall); + return (overall.lbearing != 0 || + overall.rbearing != 0 || + overall.width != 0 || + overall.ascent != 0 || + overall.descent != 0); +} + diff --git a/xc/lib/Xft/xftdraw.c b/xc/lib/Xft/xftdraw.c index f90c489c7..daeb09488 100644 --- a/xc/lib/Xft/xftdraw.c +++ b/xc/lib/Xft/xftdraw.c @@ -1,5 +1,5 @@ /* - * $XFree86: xc/lib/Xft/xftdraw.c,v 1.1 2000/11/29 08:39:22 keithp Exp $ + * $XFree86: xc/lib/Xft/xftdraw.c,v 1.4 2000/12/01 21:32:01 keithp Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -47,6 +47,22 @@ XftDrawCreate (Display *dpy, } void +XftDrawChange (XftDraw *draw, + Drawable drawable) +{ + draw->drawable = drawable; + if (draw->render_able) + { + XRenderPictFormat *format; + + XRenderFreePicture (draw->dpy, draw->render.pict); + format = XRenderFindVisualFormat (draw->dpy, draw->visual); + draw->render.pict = XRenderCreatePicture (draw->dpy, draw->drawable, + format, 0, 0); + } +} + +void XftDrawDestroy (XftDraw *draw) { if (draw->render_able) @@ -56,22 +72,14 @@ XftDrawDestroy (XftDraw *draw) XRenderFreePicture (draw->dpy, draw->render.fg_pict); } if (draw->core_set) - { - int i; - XFreeGC (draw->dpy, draw->core.draw_gc); - for (i = 0; i < CACHE_SIZE; i++) - if (draw->core.u.cache[i].use >= 0) - XFreeColors (draw->dpy, draw->colormap, - &draw->core.u.cache[i].pixel, 1, 0); - } free (draw); } Bool -XftDrawRenderPrepare (XftDraw *draw, - XRenderColor *color, - XftFont *font) +XftDrawRenderPrepare (XftDraw *draw, + XftColor *color, + XftFont *font) { if (!draw->render_set) { @@ -101,129 +109,39 @@ XftDrawRenderPrepare (XftDraw *draw, draw->render.fg_pix, pix_format, CPRepeat, &pa); - draw->render.fg_color.red = ~color->red; + draw->render.fg_color.red = ~color->color.red; } } if (!draw->render_able) return False; - if (memcmp (color, &draw->render.fg_color, sizeof (XRenderColor))) + if (memcmp (&color->color, &draw->render.fg_color, sizeof (XRenderColor))) { XRenderFillRectangle (draw->dpy, PictOpSrc, draw->render.fg_pict, - color, 0, 0, 1, 1); - draw->render.fg_color = *color; + &color->color, 0, 0, 1, 1); + draw->render.fg_color = color->color; } return True; } -static short -maskbase (unsigned long m) -{ - short i; - - if (!m) - return 0; - i = 0; - while (!(m&1)) - { - m>>=1; - i++; - } - return i; -} - -static short -masklen (unsigned long m) -{ - unsigned long y; - - y = (m >> 1) &033333333333; - y = m - y - ((y >>1) & 033333333333); - return (short) (((y + (y >> 3)) & 030707070707) % 077); -} - Bool -XftDrawCorePrepare (XftDraw *draw, - XRenderColor *color, - XftFont *font) +XftDrawCorePrepare (XftDraw *draw, + XftColor *color, + XftFont *font) { - int i; - unsigned long pixel; XGCValues gcv; if (!draw->core_set) { draw->core_set = True; - if (draw->visual->class == TrueColor) - { - draw->core.u.truecolor.red_shift = maskbase (draw->visual->red_mask); - draw->core.u.truecolor.red_len = masklen (draw->visual->red_mask); - draw->core.u.truecolor.green_shift = maskbase (draw->visual->green_mask); - draw->core.u.truecolor.green_len = masklen (draw->visual->green_mask); - draw->core.u.truecolor.blue_shift = maskbase (draw->visual->blue_mask); - draw->core.u.truecolor.blue_len = masklen (draw->visual->blue_mask); - } - else - { - for (i = 0; i < CACHE_SIZE; i++) - draw->core.u.cache[i].use = -1; - } - draw->core.draw_gc = XCreateGC (draw->dpy, draw->drawable, 0, 0); - } - if (draw->visual->class == TrueColor) - { - pixel = (((color->red >> (16 - draw->core.u.truecolor.red_len)) << - draw->core.u.truecolor.red_shift) | - ((color->green >> (16 - draw->core.u.truecolor.green_len)) << - draw->core.u.truecolor.green_shift) | - ((color->blue >> (16 - draw->core.u.truecolor.blue_len)) << - draw->core.u.truecolor.blue_shift)); - } - else - { - int oldest, newest; - int match; - XColor xcolor; - - oldest = newest = 0; - match = -1; - for (i = 1; i < CACHE_SIZE; i++) - { - if (draw->core.u.cache[i].use < draw->core.u.cache[oldest].use) - oldest = i; - if (draw->core.u.cache[i].use > draw->core.u.cache[newest].use) - newest = i; - if (draw->core.u.cache[i].use >= 0 && - !memcmp (&draw->core.u.cache[i].color, color, - sizeof (XRenderColor))) - match = i; - } - if (match < 0) - { - match = oldest; - if (draw->core.u.cache[match].use >= 0) - { - XFreeColors (draw->dpy, draw->colormap, - &draw->core.u.cache[match].pixel, 1, 0); - draw->core.u.cache[match].use = -1; - } - xcolor.red = color->red; - xcolor.green = color->green; - xcolor.blue = color->blue; - xcolor.flags = DoRed|DoGreen|DoBlue; - if (!XAllocColor (draw->dpy, draw->colormap, &xcolor)) - return False; - draw->core.u.cache[match].pixel = xcolor.pixel; - draw->core.u.cache[match].color = *color; - draw->core.u.cache[match].use = draw->core.u.cache[newest].use + 1; - } - else if (match != newest) - draw->core.u.cache[match].use = draw->core.u.cache[newest].use + 1; - pixel = draw->core.u.cache[match].pixel; + draw->core.fg = color->pixel; + gcv.foreground = draw->core.fg; + draw->core.draw_gc = XCreateGC (draw->dpy, draw->drawable, + GCForeground, &gcv); + } - XGetGCValues (draw->dpy, draw->core.draw_gc, GCForeground|GCFont, &gcv); - if (gcv.foreground != pixel) - XSetForeground (draw->dpy, draw->core.draw_gc, pixel); + if (draw->core.fg != color->pixel) + XSetForeground (draw->dpy, draw->core.draw_gc, color->pixel); if (font && gcv.font != font->u.core.font->fid) XSetFont (draw->dpy, draw->core.draw_gc, font->u.core.font->fid); return True; @@ -231,7 +149,7 @@ XftDrawCorePrepare (XftDraw *draw, void XftDrawString8 (XftDraw *draw, - XRenderColor *color, + XftColor *color, XftFont *font, int x, int y, @@ -255,7 +173,7 @@ XftDrawString8 (XftDraw *draw, void XftDrawString16 (XftDraw *draw, - XRenderColor *color, + XftColor *color, XftFont *font, int x, int y, @@ -283,11 +201,11 @@ XftDrawString16 (XftDraw *draw, void XftDrawString32 (XftDraw *draw, - XRenderColor *color, + XftColor *color, XftFont *font, int x, int y, - unsigned long *string, + unsigned int *string, int len) { if (font->core) @@ -311,7 +229,7 @@ XftDrawString32 (XftDraw *draw, void XftDrawRect (XftDraw *draw, - XRenderColor *color, + XftColor *color, int x, int y, unsigned int width, @@ -320,7 +238,7 @@ XftDrawRect (XftDraw *draw, if (XftDrawRenderPrepare (draw, color, 0)) { XRenderFillRectangle (draw->dpy, PictOpSrc, draw->render.pict, - color, x, y, width, height); + &color->color, x, y, width, height); } else { diff --git a/xc/lib/Xft/xftextent.c b/xc/lib/Xft/xftextent.c index 3a775bf21..ce1963cbc 100644 --- a/xc/lib/Xft/xftextent.c +++ b/xc/lib/Xft/xftextent.c @@ -1,5 +1,5 @@ /* - * $XFree86: xc/lib/Xft/xftextent.c,v 1.1 2000/11/29 08:39:22 keithp Exp $ + * $XFree86: xc/lib/Xft/xftextent.c,v 1.2 2000/12/01 21:32:02 keithp Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -61,7 +61,7 @@ XftTextExtents16 (Display *dpy, void XftTextExtents32 (Display *dpy, XftFont *font, - unsigned long *string, + unsigned int *string, int len, XGlyphInfo *extents) { diff --git a/xc/lib/Xft/xftfont.c b/xc/lib/Xft/xftfont.c index 5182d36ba..682c3cde2 100644 --- a/xc/lib/Xft/xftfont.c +++ b/xc/lib/Xft/xftfont.c @@ -1,5 +1,5 @@ /* - * $XFree86: xc/lib/Xft/xftfont.c,v 1.1 2000/11/29 08:39:22 keithp Exp $ + * $XFree86: xc/lib/Xft/xftfont.c,v 1.3 2000/12/02 10:02:04 keithp Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -165,6 +165,29 @@ XftFontOpenName (Display *dpy, int screen, const char *name) return font; } +XftFont * +XftFontOpenXlfd (Display *dpy, int screen, const char *xlfd) +{ + XftPattern *pat; + XftPattern *match; + XftResult result; + XftFont *font; + + pat = XftXlfdParse (xlfd, False, False); + if (!pat) + return 0; + match = XftFontMatch (dpy, screen, pat, &result); + XftPatternDestroy (pat); + if (!match) + return 0; + + font = XftFontOpenPattern (dpy, match); + if (!font) + XftPatternDestroy (match); + + return font; +} + void XftFontClose (Display *dpy, XftFont *font) { @@ -176,3 +199,12 @@ XftFontClose (Display *dpy, XftFont *font) XftPatternDestroy (font->pattern); free (font); } + +Bool +XftGlyphExists (Display *dpy, XftFont *font, unsigned int glyph) +{ + if (font->core) + return XftCoreGlyphExists (dpy, font->u.core.font, glyph); + else + return XftFreeTypeGlyphExists (dpy, font->u.ft.font, glyph); +} diff --git a/xc/lib/Xft/xftfreetype.c b/xc/lib/Xft/xftfreetype.c index 1519ab1a9..bf80f6414 100644 --- a/xc/lib/Xft/xftfreetype.c +++ b/xc/lib/Xft/xftfreetype.c @@ -1,5 +1,5 @@ /* - * $XFree86: xc/lib/Xft/xftfreetype.c,v 1.1 2000/11/29 08:39:22 keithp Exp $ + * $XFree86: xc/lib/Xft/xftfreetype.c,v 1.3 2000/12/03 19:03:22 keithp Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -35,6 +35,7 @@ XftFtEncoding xftFtEncoding[] = { { "iso10646-1", ft_encoding_unicode, }, { "iso8859-1", ft_encoding_unicode, }, { "adobe-fontspecific", ft_encoding_symbol, }, + { "glyphs-fontspecific",ft_encoding_none, }, }; #define NUM_FT_ENCODINGS (sizeof xftFtEncoding / sizeof xftFtEncoding[0]) @@ -127,6 +128,11 @@ XftFreeTypeQuery (const char *file, int id, int *count) } } + if (!XftPatternAddString (pat, XFT_ENCODING, + "glyphs-fontspecific")) + goto bail1; + + FT_Done_Face (face); return pat; @@ -147,7 +153,9 @@ XftFreeTypeOpen (Display *dpy, XftPattern *pattern) double size; int rgba; int spacing; + int char_width; Bool antialias; + Bool encoded; char *encoding_name; FT_Face face; XftFontStruct *font; @@ -194,6 +202,12 @@ XftFreeTypeOpen (Display *dpy, XftPattern *pattern) goto bail0; } + if (XftPatternGetInteger (pattern, XFT_CHAR_WIDTH, + 0, &char_width) != XftResultMatch) + { + char_width = 0; + } + if (antialias) { if (rgba) @@ -273,18 +287,24 @@ XftFreeTypeOpen (Display *dpy, XftPattern *pattern) break; } - for (charmap = 0; charmap < face->num_charmaps; charmap++) - if (face->charmaps[charmap]->encoding == encoding) - break; - - if (charmap == face->num_charmaps) - goto bail2; + if (encoding == ft_encoding_none) + encoded = False; + else + { + encoded = True; + for (charmap = 0; charmap < face->num_charmaps; charmap++) + if (face->charmaps[charmap]->encoding == encoding) + break; - error = FT_Set_Charmap(face, - face->charmaps[charmap]); + if (charmap == face->num_charmaps) + goto bail2; - if (error) - goto bail2; + error = FT_Set_Charmap(face, + face->charmaps[charmap]); + + if (error) + goto bail2; + } height = face->height; ascent = face->ascender; @@ -312,6 +332,11 @@ XftFreeTypeOpen (Display *dpy, XftPattern *pattern) font->max_advance_width = face->max_advance_width * font->size / (64 * div); font->monospace = (face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0; + if (char_width) + { + font->max_advance_width = char_width; + font->monospace = True; + } switch (XftPatternGetInteger (pattern, XFT_SPACING, 0, &spacing)) { case XftResultNoMatch: break; @@ -330,6 +355,7 @@ XftFreeTypeOpen (Display *dpy, XftPattern *pattern) font->nrealized = 0; font->rgba = rgba; font->antialias = antialias; + font->encoded = encoded; font->face = face; return font; diff --git a/xc/lib/Xft/xftglyphs.c b/xc/lib/Xft/xftglyphs.c index 1e99d4727..c400f821d 100644 --- a/xc/lib/Xft/xftglyphs.c +++ b/xc/lib/Xft/xftglyphs.c @@ -1,5 +1,5 @@ /* - * $XFree86: xc/lib/Xft/xftglyphs.c,v 1.1 2000/11/29 08:39:23 keithp Exp $ + * $XFree86: xc/lib/Xft/xftglyphs.c,v 1.3 2000/12/03 19:03:22 keithp Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -53,6 +53,7 @@ XftGlyphLoad (Display *dpy, #ifdef FREETYPE2 FT_Error error; FT_ULong charcode; + FT_UInt glyphindex; FT_GlyphSlot glyph; XGlyphInfo *gi; Glyph g; @@ -83,19 +84,45 @@ XftGlyphLoad (Display *dpy, while (nglyph--) { charcode = (FT_ULong) *glyphs++; - error = FT_Load_Char (font->face, charcode, 0/*|FT_LOAD_NO_HINTING */); + if (font->encoded) + { + glyphindex = FT_Get_Char_Index (font->face, charcode); + if (!glyphindex) + continue; + } + else + glyphindex = (FT_UInt) charcode; + error = FT_Load_Glyph (font->face, glyphindex, 0/*|FT_LOAD_NO_HINTING */); if (error) continue; -#define FLOOR(x) ((x) & -64) -#define CEIL(x) (((x)+63) & -64) -#define TRUNC(x) ((x) >> 6) +#define FLOOR(x) ((x) & -64) +#define CEIL(x) (((x)+63) & -64) +#define TRUNC(x) ((x) >> 6) +#define ROUND(x) (((x)+32) & -64) glyph = font->face->glyph; left = FLOOR( glyph->metrics.horiBearingX ); right = CEIL( glyph->metrics.horiBearingX + glyph->metrics.width ); width = TRUNC(right - left); + /* + * Try to keep monospace fonts ink-inside + */ + if (font->monospace) + { + if (TRUNC(right) > font->max_advance_width) + { + int adjust; + + adjust = right - (font->max_advance_width << 6); + if (adjust > left) + adjust = left; + left -= adjust; + right -= adjust; + width = font->max_advance_width; + } + } top = CEIL( glyph->metrics.horiBearingY ); bottom = FLOOR( glyph->metrics.horiBearingY - glyph->metrics.height ); @@ -204,9 +231,9 @@ XftGlyphLoad (Display *dpy, gi->x = -TRUNC(left); gi->y = TRUNC(top); if (font->monospace) - gi->xOff = font->face->max_advance_width * font->size / (64 * font->face->units_per_EM); + gi->xOff = font->max_advance_width; else - gi->xOff = ((glyph->metrics.horiAdvance + 0x20) >> 6); + gi->xOff = TRUNC(ROUND(glyph->metrics.horiAdvance)); gi->yOff = 0; g = charcode; @@ -330,3 +357,18 @@ XftGlyphCheck (Display *dpy, } #endif } + +Bool +XftFreeTypeGlyphExists (Display *dpy, + XftFontStruct *font, + unsigned int glyph) +{ +#ifdef FREETYPE2 + if (font->encoded) + return FT_Get_Char_Index (font->face, (FT_ULong) glyph) != 0; + else + return glyph && glyph <= font->face->num_glyphs; +#else + return False; +#endif +} diff --git a/xc/lib/Xft/xftgram.y b/xc/lib/Xft/xftgram.y index bcf7df2cd..bcf399a2a 100644 --- a/xc/lib/Xft/xftgram.y +++ b/xc/lib/Xft/xftgram.y @@ -1,5 +1,5 @@ /* - * $XFree86: xc/lib/Xft/xftgram.y,v 1.1 2000/11/29 08:39:23 keithp Exp $ + * $XFree86: xc/lib/Xft/xftgram.y,v 1.2 2000/11/30 23:30:00 dawes Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -25,6 +25,7 @@ %{ #include <stdlib.h> +#include <stdio.h> #include "xftint.h" %} diff --git a/xc/lib/Xft/xftint.h b/xc/lib/Xft/xftint.h index b4c305e60..cae06ebae 100644 --- a/xc/lib/Xft/xftint.h +++ b/xc/lib/Xft/xftint.h @@ -1,5 +1,5 @@ /* - * $XFree86: xc/lib/Xft/xftint.h,v 1.3 2000/11/29 08:39:23 keithp Exp $ + * $XFree86: xc/lib/Xft/xftint.h,v 1.8 2000/12/02 10:02:05 keithp Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -38,8 +38,6 @@ typedef struct _XftSymbolic { int value; } XftSymbolic; -#define CACHE_SIZE 3 - struct _XftDraw { Display *dpy; Drawable drawable; @@ -49,25 +47,14 @@ struct _XftDraw { Bool render_set; Bool render_able; struct { - Picture pict; - Pixmap fg_pix; - Picture fg_pict; + Picture pict; + Pixmap fg_pix; + Picture fg_pict; XRenderColor fg_color; } render; struct { - GC draw_gc; - union { - struct { - unsigned long pixel; - XRenderColor color; - int use; - } cache[CACHE_SIZE]; - struct { - short red_shift, red_len; - short green_shift, green_len; - short blue_shift, blue_len; - } truecolor; - } u; + GC draw_gc; + unsigned long fg; } core; }; @@ -152,7 +139,9 @@ Bool XftConfigAddEdit (XftTest *test, XftEdit *edit); Bool -XftConfigSubstitute (XftPattern *p); +_XftConfigCompareValue (XftValue m, + XftOp op, + XftValue v); /* xftcore.c */ @@ -164,7 +153,7 @@ XftCoreConvert16 (unsigned short *string, XChar2b xcloc[XFT_CORE_N16LOCAL]); XChar2b * -XftCoreConvert32 (unsigned long *string, +XftCoreConvert32 (unsigned int *string, int len, XChar2b xcloc[XFT_CORE_N16LOCAL]); @@ -185,10 +174,15 @@ XftCoreExtents16 (Display *dpy, void XftCoreExtents32 (Display *dpy, XFontStruct *fs, - unsigned long *string, + unsigned int *string, int len, XGlyphInfo *extents); +Bool +XftCoreGlyphExists (Display *dpy, + XFontStruct *fs, + unsigned int glyph); + /* xftdbg.c */ void XftOpPrint (XftOp op); @@ -210,12 +204,6 @@ Bool XftDirScan (XftFontSet *set, const char *dir); /* xftdpy.c */ -Bool -XftDefaultHasRender (Display *dpy); - -Bool -XftDefaultSet (Display *dpy, XftPattern *defaults); - int XftDefaultParseBool (char *v); @@ -231,19 +219,16 @@ XftDefaultGetDouble (Display *dpy, const char *object, int screen, double def); XftFontSet * XftDisplayGetFontSet (Display *dpy); -void -XftDefaultSubstitute (Display *dpy, int screen, XftPattern *pattern); - /* xftdraw.c */ Bool -XftDrawRenderPrepare (XftDraw *draw, - XRenderColor *color, - XftFont *font); +XftDrawRenderPrepare (XftDraw *draw, + XftColor *color, + XftFont *font); Bool -XftDrawCorePrepare (XftDraw *draw, - XRenderColor *color, - XftFont *font); +XftDrawCorePrepare (XftDraw *draw, + XftColor *color, + XftFont *font); /* xftextent.c */ /* xftfont.c */ @@ -258,28 +243,7 @@ void XftFreeTypeClose (Display *dpy, XftFontStruct *font); /* xftfs.c */ -XftFontSet * -XftFontSetCreate (void); - -void -XftFontSetDestroy (XftFontSet *s); - -Bool -XftFontSetAdd (XftFontSet *s, XftPattern *font); - /* xftglyphs.c */ -void -XftGlyphLoad (Display *dpy, - XftFontStruct *font, - unsigned long *glyphs, - int nglyph); - -void -XftGlyphCheck (Display *dpy, - XftFontStruct *font, - unsigned long glyph, - unsigned long *missing, - int *nmissing); /* xftgram.y */ int XftConfigparse (void); @@ -330,9 +294,6 @@ XftEditDestroy (XftEdit *e); Bool XftInitFtLibrary (void); -Bool -XftInit (char *config); - /* xftlex.l */ extern int XftConfigLineno; extern char *XftConfigFile; @@ -346,30 +307,39 @@ XftConfigLexFile(char *s); Bool XftConfigPushInput (char *s, Bool complain); -/* xftmatch.c */ -XftPattern * -XftFontSetMatch (XftFontSet **sets, - int nsets, - XftPattern *p, - XftResult *result); +/* xftlist.c */ +XftObjectSet * +_XftObjectSetVapBuild (const char *first, va_list *vap); -/* xftname.c */ Bool -XftNameConstant (char *string, int *result); +XftListValueCompare (XftValue v1, + XftValue v2); -XftPattern * -XftNameParse (const char *name); +Bool +XftListValueListCompare (XftValueList *v1orig, + XftValueList *v2orig, + XftQual qual); -/* xftpat.c */ +Bool +XftListMatch (XftPattern *p, + XftPattern *font, + XftQual qual); -void -XftValueDestroy (XftValue v); +Bool +XftListAppend (XftFontSet *s, + XftPattern *font, + XftObjectSet *os); -void -XftValueListDestroy (XftValueList *l); -XftPatternElt * -XftPatternFind (XftPattern *p, const char *object, Bool insert); +/* xftmatch.c */ + +/* xftname.c */ +Bool +XftNameConstant (char *string, int *result); + +/* xftpat.c */ +XftPattern * +_XftPatternVapBuild (XftPattern *orig, va_list *vap); /* xftrender.c */ @@ -396,13 +366,7 @@ int _XftMatchSymbolic (XftSymbolic *s, int n, const char *name, int def); /* xftxlfd.c */ -XftPattern * -XftXlfdParse (const char *xlfd_orig, Bool ignore_scalable); - Bool XftCoreAddFonts (XftFontSet *set, Display *dpy, Bool ignore_scalable); -XFontStruct * -XftCoreOpen (Display *dpy, XftPattern *pattern); - #endif /* _XFT_INT_H_ */ diff --git a/xc/lib/Xft/xftlex.l b/xc/lib/Xft/xftlex.l index 6c4641653..839ea04c0 100644 --- a/xc/lib/Xft/xftlex.l +++ b/xc/lib/Xft/xftlex.l @@ -1,6 +1,6 @@ %{ /* - * $XFree86: xc/lib/Xft/xftlex.l,v 1.1 2000/11/29 08:39:23 keithp Exp $ + * $XFree86: xc/lib/Xft/xftlex.l,v 1.2 2000/11/30 23:30:00 dawes Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -25,10 +25,29 @@ #include <string.h> #include "xftint.h" + #include "xftgram.h" int XftConfigLineno; + +static void _XftConfigSkipComment (void); + +static void _XftConfigSkipLine (void); + +static int _XftConfigPopInput (void); + +#define XFT_CONFIG_IN_DEEP 20 +FILE *XftConfigInStack[XFT_CONFIG_IN_DEEP]; +FILE **XftConfigInpt = XftConfigInStack + XFT_CONFIG_IN_DEEP; +FILE *XftConfigInput; +int XftConfigLinenos[XFT_CONFIG_IN_DEEP]; +int *XftConfigLinenopt = XftConfigLinenos + XFT_CONFIG_IN_DEEP; +char *XftConfigFile = ""; +char *XftConfigFileNames[XFT_CONFIG_IN_DEEP]; +char **XftConfigFileNamePt = XftConfigFileNames + XFT_CONFIG_IN_DEEP; +int XftConfigFiledeep = 0; + #undef YY_INPUT #define YY_INPUT(buf,result,max_size) \ @@ -69,30 +88,10 @@ static void unput (char c) { if (c == '\n') XftConfigLineno--; - ungetc (XftConfigInput, c); + ungetc (c, XftConfigInput); } #endif -#define XFT_CONFIG_IN_DEEP 20 -FILE *XftConfigInStack[XFT_CONFIG_IN_DEEP]; -FILE **XftConfigInpt = XftConfigInStack + XFT_CONFIG_IN_DEEP; -FILE *XftConfigInput; -int XftConfigLinenos[XFT_CONFIG_IN_DEEP]; -int *XftConfigLinenopt = XftConfigLinenos + XFT_CONFIG_IN_DEEP; -char *XftConfigFile = ""; -char *XftConfigFileNames[XFT_CONFIG_IN_DEEP]; -char **XftConfigFileNamePt = XftConfigFileNames + XFT_CONFIG_IN_DEEP; -int XftConfigFiledeep = 0; - -static void -_XftConfigSkipComment (void); - -static void -_XftConfigSkipLine (void); - -static int -_XftConfigPopInput (void); - %} %% "/\052" _XftConfigSkipComment(); @@ -126,21 +125,21 @@ all return ALL; "?" return QUEST; \"([^\n\"]|\\\")*\" { yytext[yyleng - 1] = '\0'; - XftConfiglval.sval = yytext+1; + yylval.sval = yytext+1; return STRING; } [0-9]+ { - XftConfiglval.ival = strtol (yytext, 0, 10); + yylval.ival = strtol (yytext, 0, 10); return INTEGER; } (([0-9]+((\.[0-9]*(\{[0-9]+\})?)?))|(\.[0-9]+)|(\.[0-9]*\{[0-9]+\}))(([Ee][-+]?[0-9]+)?) { - XftConfiglval.dval = strtod (yytext, 0); + yylval.dval = strtod (yytext, 0); return DOUBLE; } [a-zA-Z][0-9a-zA-Z_]* { - if (XftNameConstant (yytext, &XftConfiglval.ival)) + if (XftNameConstant (yytext, &yylval.ival)) return INTEGER; - XftConfiglval.sval = yytext; + yylval.sval = yytext; return NAME; } . ; diff --git a/xc/lib/Xft/xftlist.c b/xc/lib/Xft/xftlist.c new file mode 100644 index 000000000..1ee72bc05 --- /dev/null +++ b/xc/lib/Xft/xftlist.c @@ -0,0 +1,321 @@ +/* + * $XFree86: xc/lib/Xft/xftlist.c,v 1.1 2000/11/30 06:59:45 keithp Exp $ + * + * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stdlib.h> +#include "xftint.h" + +XftObjectSet * +XftObjectSetCreate (void) +{ + XftObjectSet *os; + + os = (XftObjectSet *) malloc (sizeof (XftObjectSet)); + if (!os) + return 0; + os->nobject = 0; + os->sobject = 0; + os->objects = 0; + return os; +} + +Bool +XftObjectSetAdd (XftObjectSet *os, const char *object) +{ + int s; + const char **objects; + + if (os->nobject == os->sobject) + { + s = os->sobject + 4; + if (os->objects) + objects = (const char **) realloc ((void *) os->objects, + s * sizeof (const char **)); + else + objects = (const char **) malloc (s * sizeof (const char **)); + if (!objects) + return False; + os->objects = objects; + os->sobject = s; + } + os->objects[os->nobject++] = object; + return True; +} + +void +XftObjectSetDestroy (XftObjectSet *os) +{ + if (os->objects) + free ((void *) os->objects); + free (os); +} + +XftObjectSet * +_XftObjectSetVapBuild (const char *first, va_list *vap) +{ + XftObjectSet *os; + const char *object; + va_list va = *vap; + + os = XftObjectSetCreate (); + if (!os) + goto bail0; + object = first; + while (object) + { + if (!XftObjectSetAdd (os, object)) + goto bail1; + object = va_arg (va, const char *); + } + *vap = va; + return os; +bail1: + XftObjectSetDestroy (os); +bail0: + return 0; +} + +XftObjectSet * +XftObjectSetVaBuild (const char *first, va_list va) +{ + return _XftObjectSetVapBuild (first, &va); +} + +XftObjectSet * +XftObjectSetBuild (const char *first, ...) +{ + va_list va; + XftObjectSet *os; + + va_start (va, first); + os = _XftObjectSetVapBuild (first, &va); + va_end (va); + return os; +} + +Bool +XftListValueCompare (XftValue v1, + XftValue v2) +{ + return _XftConfigCompareValue (v1, XftOpEqual, v2); +} + +Bool +XftListValueListCompare (XftValueList *v1orig, + XftValueList *v2orig, + XftQual qual) +{ + XftValueList *v1, *v2; + + for (v1 = v1orig; v1; v1 = v1->next) + { + for (v2 = v2orig; v2; v2 = v2->next) + { + if (_XftConfigCompareValue (v1->value, XftOpEqual, v2->value)) + { + if (qual == XftQualAny) + return True; + else + break; + } + } + if (qual == XftQualAll) + { + if (!v2) + return False; + } + } + if (qual == XftQualAll) + return True; + else + return False; +} + +/* + * True iff all objects in "p" match "font" + */ +Bool +XftListMatch (XftPattern *p, + XftPattern *font, + XftQual qual) +{ + int i; + XftPatternElt *e; + + for (i = 0; i < p->num; i++) + { + e = XftPatternFind (font, p->elts[i].object, False); + if (!e) + { + if (qual == XftQualAll) + continue; + else + return False; + } + if (!XftListValueListCompare (p->elts[i].values, e->values, qual)) + return False; + } + return True; +} + +Bool +XftListAppend (XftFontSet *s, + XftPattern *font, + XftObjectSet *os) +{ + int f; + int o; + XftPattern *l; + XftPatternElt *e; + XftValueList *v; + + for (f = 0; f < s->nfont; f++) + { + l = s->fonts[f]; + if (XftListMatch (l, font, XftQualAll)) + return True; + } + l = XftPatternCreate (); + if (!l) + goto bail0; + for (o = 0; o < os->nobject; o++) + { + e = XftPatternFind (font, os->objects[o], False); + if (e) + { + for (v = e->values; v; v = v->next) + { + if (!XftPatternAdd (l, os->objects[o], v->value, True)) + goto bail1; + } + } + } + if (!XftFontSetAdd (s, l)) + goto bail1; + return True; +bail1: + XftPatternDestroy (l); +bail0: + return False; +} + +XftFontSet * +XftListFontSets (XftFontSet **sets, + int nsets, + XftPattern *p, + XftObjectSet *os) +{ + XftFontSet *ret; + XftFontSet *s; + int f; + int set; + + ret = XftFontSetCreate (); + if (!ret) + goto bail0; + for (set = 0; set < nsets; set++) + { + s = sets[set]; + for (f = 0; f < s->nfont; f++) + { + if (XftListMatch (p, s->fonts[f], XftQualAny)) + { + if (!XftListAppend (ret, s->fonts[f], os)) + goto bail1; + } + } + } + return ret; +bail1: + XftFontSetDestroy (ret); +bail0: + return 0; +} + +XftFontSet * +XftListFontsPatternObjects (Display *dpy, + int screen, + XftPattern *pattern, + XftObjectSet *os) +{ + XftFontSet *sets[2]; + int nsets = 0; +#ifdef FREETYPE2 + Bool core, render; + XftResult result; +#endif + + if (!XftInit (0)) + return 0; + +#ifdef FREETYPE2 + render = core = False; + result = XftPatternGetBool (pattern, XFT_CORE, 0, &core); + if (result != XftResultMatch) + core = XftDefaultGetBool (dpy, XFT_CORE, screen, + !XftDefaultHasRender (dpy)); + + result = XftPatternGetBool (pattern, XFT_RENDER, 0, &render); + if (result != XftResultMatch) + render = XftDefaultGetBool (dpy, XFT_RENDER, screen, + XftDefaultHasRender (dpy)); + if (render) + { + if (XftInitFtLibrary ()) + { + sets[nsets] = _XftFontSet; + if (sets[nsets]) + nsets++; + } + } + if (core) +#endif + { + sets[nsets] = XftDisplayGetFontSet (dpy); + if (sets[nsets]) + nsets++; + } + return XftListFontSets (sets, nsets, pattern, os); +} + +XftFontSet * +XftListFonts (Display *dpy, + int screen, + ...) +{ + va_list va; + XftFontSet *fs; + XftObjectSet *os; + XftPattern *pattern; + const char *first; + + va_start (va, screen); + pattern = _XftPatternVapBuild (0, &va); + first = va_arg (va, const char *); + os = _XftObjectSetVapBuild (first, &va); + va_end (va); + fs = XftListFontsPatternObjects (dpy, screen, pattern, os); + XftPatternDestroy (pattern); + XftObjectSetDestroy (os); + return fs; +} diff --git a/xc/lib/Xft/xftname.c b/xc/lib/Xft/xftname.c index bf9ca0367..bd99f98fe 100644 --- a/xc/lib/Xft/xftname.c +++ b/xc/lib/Xft/xftname.c @@ -1,5 +1,5 @@ /* - * $XFree86: xc/lib/Xft/xftname.c,v 1.1 2000/11/29 08:39:23 keithp Exp $ + * $XFree86: xc/lib/Xft/xftname.c,v 1.4 2000/12/03 00:45:44 keithp Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -72,41 +72,52 @@ XftNameGetType (const char *object) typedef struct _XftConstant { const char *name; + const char *object; int value; } XftConstant; static XftConstant XftConstants[] = { - { "light", XFT_WEIGHT_LIGHT, }, - { "medium", XFT_WEIGHT_MEDIUM, }, - { "demibold", XFT_WEIGHT_DEMIBOLD, }, - { "bold", XFT_WEIGHT_BOLD, }, - { "black", XFT_WEIGHT_BLACK, }, - - { "roman", XFT_SLANT_ROMAN, }, - { "italic", XFT_SLANT_ITALIC, }, - { "oblique", XFT_SLANT_OBLIQUE, }, - - { "proportional", XFT_PROPORTIONAL, }, - { "mono", XFT_MONO, }, - { "charcell", XFT_CHARCELL, }, - - { "rgb", XFT_RGBA_RGB, }, - { "bgr", XFT_RGBA_BGR, }, + { "light", "weight", XFT_WEIGHT_LIGHT, }, + { "medium", "weight", XFT_WEIGHT_MEDIUM, }, + { "demibold", "weight", XFT_WEIGHT_DEMIBOLD, }, + { "bold", "weight", XFT_WEIGHT_BOLD, }, + { "black", "weight", XFT_WEIGHT_BLACK, }, + + { "roman", "slant", XFT_SLANT_ROMAN, }, + { "italic", "slant", XFT_SLANT_ITALIC, }, + { "oblique", "slant", XFT_SLANT_OBLIQUE, }, + + { "proportional", "spacing", XFT_PROPORTIONAL, }, + { "mono", "spacing", XFT_MONO, }, + { "charcell", "spacing", XFT_CHARCELL, }, + + { "rgb", "rgba", XFT_RGBA_RGB, }, + { "bgr", "rgba", XFT_RGBA_BGR, }, }; #define NUM_XFT_CONSTANTS (sizeof XftConstants/sizeof XftConstants[0]) +static XftConstant * +_XftNameConstantLookup (char *string) +{ + int i; + + for (i = 0; i < NUM_XFT_CONSTANTS; i++) + if (!strcmp (string, XftConstants[i].name)) + return &XftConstants[i]; + return 0; +} + Bool XftNameConstant (char *string, int *result) { - int i; + XftConstant *c; - for (i = 0; i < NUM_XFT_CONSTANTS; i++) - if (!strcmp (string, XftConstants[i].name)) - { - *result = XftConstants[i].value; - return True; - } + if ((c = _XftNameConstantLookup(string))) + { + *result = c->value; + return True; + } return False; } @@ -136,6 +147,25 @@ _XftNameConvert (XftType type, char *string) return v; } +static const char * +_XftNameFindNext (const char *cur, const char *delim, char *save, char *last) +{ + char c; + + while (*cur && !strchr (delim, *cur)) + { + c = *cur++; + if (isupper (c)) + c = tolower (c); + *save++ = c; + } + *save = 0; + *last = *cur; + if (*cur) + cur++; + return cur; +} + XftPattern * XftNameParse (const char *name) { @@ -143,8 +173,10 @@ XftNameParse (const char *name) XftPattern *pat; double d; char *e; + char delim; XftValue v; const XftObjectType *t; + XftConstant *c; save = malloc (strlen (name) + 1); if (!save) @@ -155,41 +187,58 @@ XftNameParse (const char *name) for (;;) { - name = _XftSplitValue (name, save); - if (!XftPatternAddString (pat, XFT_FAMILY, save)) - goto bail2; - if (*name != ',') + name = _XftNameFindNext (name, "-,:", save, &delim); + if (save[0]) + { + if (!XftPatternAddString (pat, XFT_FAMILY, save)) + goto bail2; + } + if (delim != ',') break; } - if (*name) + if (delim == '-') { - _XftSplitStr (name, save); - d = strtod (save, &e); - if (e != save) + for (;;) { - if (!XftPatternAddDouble (pat, XFT_SIZE, d)) - goto bail2; + name = _XftNameFindNext (name, "-,:", save, &delim); + d = strtod (save, &e); + if (e != save) + { + if (!XftPatternAddDouble (pat, XFT_SIZE, d)) + goto bail2; + } + if (delim != ',') + break; } - name = strchr (name, '-'); - if (name) - ++name; - while (name && *name) + } + while (delim == ':') + { + name = _XftNameFindNext (name, "=-:", save, &delim); + if (save[0]) { - name = _XftSplitField (name, save); - t = XftNameGetType (save); - if (*name == '=') + if (delim == '=' || delim == '-') { - do + t = XftNameGetType (save); + for (;;) { - name++; - name = _XftSplitValue (name, save); - if (t) + name = _XftNameFindNext (name, ":,", save, &delim); + if (save[0] && t) { v = _XftNameConvert (t->type, save); - XftPatternAdd (pat, t->object, v, True); + if (!XftPatternAdd (pat, t->object, v, True)) + goto bail2; } + if (delim != ',') + break; + } + } + else + { + if ((c = _XftNameConstantLookup (save))) + { + if (!XftPatternAddInteger (pat, c->object, c->value)) + goto bail2; } - while (*name == ','); } } } diff --git a/xc/lib/Xft/xftpat.c b/xc/lib/Xft/xftpat.c index 7d9caa151..2c8045bb0 100644 --- a/xc/lib/Xft/xftpat.c +++ b/xc/lib/Xft/xftpat.c @@ -1,5 +1,5 @@ /* - * $XFree86: xc/lib/Xft/xftpat.c,v 1.1 2000/11/29 08:39:23 keithp Exp $ + * $XFree86: xc/lib/Xft/xftpat.c,v 1.2 2000/11/30 06:59:45 keithp Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -339,8 +339,9 @@ bail0: } XftPattern * -XftPatternVaBuild (XftPattern *orig, va_list va) +_XftPatternVapBuild (XftPattern *orig, va_list *vap) { + va_list va = *vap; const char *object; XftValue v; XftPattern *p; @@ -377,6 +378,7 @@ XftPatternVaBuild (XftPattern *orig, va_list va) if (!XftPatternAdd (p, object, v, True)) goto bail; } + *vap = va; return p; bail: if (!orig) @@ -385,12 +387,18 @@ bail: } XftPattern * +XftPatternVaBuild (XftPattern *orig, va_list va) +{ + return _XftPatternVapBuild (orig, &va); +} + +XftPattern * XftPatternBuild (XftPattern *orig, ...) { va_list va; va_start (va, orig); - orig = XftPatternVaBuild (orig, va); + orig = _XftPatternVapBuild (orig, &va); va_end (va); return orig; } diff --git a/xc/lib/Xft/xftrender.c b/xc/lib/Xft/xftrender.c index e95d5bd8e..baa120a81 100644 --- a/xc/lib/Xft/xftrender.c +++ b/xc/lib/Xft/xftrender.c @@ -1,5 +1,5 @@ /* - * $XFree86: xc/lib/Xft/xftrender.c,v 1.2 2000/11/29 17:40:37 dawes Exp $ + * $XFree86: xc/lib/Xft/xftrender.c,v 1.3 2000/12/01 21:32:02 keithp Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -69,7 +69,7 @@ XftRenderString16 (Display *dpy, Picture src, XftGlyphLoad (dpy, font, missing, nmissing); XRenderCompositeString16 (dpy, PictOpOver, src, dst, font->format, font->glyphset, - srcx, srcy, x, y, (unsigned short *) string, len); + srcx, srcy, x, y, string, len); } void @@ -77,11 +77,11 @@ XftRenderString32 (Display *dpy, Picture src, XftFontStruct *font, Picture dst, int srcx, int srcy, int x, int y, - unsigned long *string, int len) + unsigned int *string, int len) { unsigned long missing[XFT_NMISSING]; int nmissing; - unsigned long *s; + unsigned int *s; int l; s = string; @@ -93,7 +93,7 @@ XftRenderString32 (Display *dpy, Picture src, XftGlyphLoad (dpy, font, missing, nmissing); XRenderCompositeString32 (dpy, PictOpOver, src, dst, font->format, font->glyphset, - srcx, srcy, x, y, (unsigned long *) string, len); + srcx, srcy, x, y, string, len); } void @@ -209,13 +209,13 @@ XftRenderExtents16 (Display *dpy, void XftRenderExtents32 (Display *dpy, XftFontStruct *font, - unsigned long *string, + unsigned int *string, int len, XGlyphInfo *extents) { unsigned long missing[XFT_NMISSING]; int nmissing; - unsigned long *s; + unsigned int *s; int l; XGlyphInfo *gi; int x, y; diff --git a/xc/lib/Xft/xftxlfd.c b/xc/lib/Xft/xftxlfd.c index 3e6c6e26a..8885dd2f1 100644 --- a/xc/lib/Xft/xftxlfd.c +++ b/xc/lib/Xft/xftxlfd.c @@ -1,5 +1,5 @@ /* - * $XFree86: xc/lib/Xft/xftxlfd.c,v 1.1 2000/11/29 08:39:24 keithp Exp $ + * $XFree86: xc/lib/Xft/xftxlfd.c,v 1.3 2000/12/02 10:02:06 keithp Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -47,7 +47,7 @@ static XftSymbolic XftXlfdSlants[] = { #define NUM_XLFD_SLANTS (sizeof XftXlfdSlants/sizeof XftXlfdSlants[0]) XftPattern * -XftXlfdParse (const char *xlfd_orig, Bool ignore_scalable) +XftXlfdParse (const char *xlfd_orig, Bool ignore_scalable, Bool complete) { XftPattern *pat; const char *xlfd = xlfd_orig; @@ -64,6 +64,7 @@ XftXlfdParse (const char *xlfd_orig, Bool ignore_scalable) int resx; int resy; int slant_value, weight_value; + double dpixel; if (*xlfd != '-') return 0; @@ -96,9 +97,14 @@ XftXlfdParse (const char *xlfd_orig, Bool ignore_scalable) return 0; if (!XftPatternAddString (pat, XFT_XLFD, xlfd_orig)) goto bail; - if (!XftPatternAddBool (pat, XFT_CORE, True)) goto bail; - if (!XftPatternAddString (pat, XFT_FOUNDRY, _XftSplitStr (foundry, save))) goto bail; - if (!XftPatternAddString (pat, XFT_FAMILY, _XftSplitStr (family, save))) 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), @@ -112,36 +118,54 @@ XftXlfdParse (const char *xlfd_orig, Bool ignore_scalable) if (!XftPatternAddInteger (pat, XFT_SLANT, slant_value)) goto bail; - /* - * 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; + 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 (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; + 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 (!style[0]) - strcat (style, "regular"); - if (!XftPatternAddString (pat, XFT_STYLE, style)) - goto bail; + if (dpixel > 0) + if (!XftPatternAddDouble (pat, XFT_PIXEL_SIZE, dpixel)) goto bail; - if (pixel) - if (!XftPatternAddDouble (pat, XFT_PIXEL_SIZE, (double) pixel)) goto bail; - - if (!XftPatternAddBool (pat, XFT_SCALABLE, pixel == 0)) goto bail; - - if (!XftPatternAddString (pat, XFT_ENCODING, _XftDownStr (registry, save))) goto bail; + _XftDownStr (registry, save); + if (registry[0] && !strchr (registry, '*')) + if (!XftPatternAddString (pat, XFT_ENCODING, save)) goto bail; free (save); return pat; @@ -169,15 +193,14 @@ XftCoreAddFonts (XftFontSet *set, Display *dpy, Bool ignore_scalable) ret = True; for (i = 0; ret && i < num; i++) { - font = XftXlfdParse (xlfds[i], ignore_scalable); + font = XftXlfdParse (xlfds[i], ignore_scalable, True); if (font) { -#if 0 - printf ("xlfd %s ", xlfds[i]); - XftPatternPrint (font); -#endif if (!XftFontSetAdd (set, font)) + { + XftPatternDestroy (font); ret = False; + } } } |