Here is the patch. Enjoy!
Derek
diff -cr gnustep-back-0.8.3/ChangeLog gnustep-back-0.8.3-zz/ChangeLog
*** gnustep-back-0.8.3/ChangeLog Thu Nov 21 19:19:12 2002
--- gnustep-back-0.8.3-zz/ChangeLog Mon Feb 24 20:19:34 2003
***************
*** 1,3 ****
--- 1,9 ----
+ 2003-02-21 Derek Zhou <[EMAIL PROTECTED]>
+
+ * Source/xlib/XGGState.m optimization for XFT2
+
+ * Source/xlib/XftFontInfo.m XFT2 and fontconfig
+
2002-11-21 Adam Fedor <[EMAIL PROTECTED]>
* Version: 0.8.3
diff -cr gnustep-back-0.8.3/Headers/xlib/XGGState.h gnustep-back-0.8.3-zz/Headers/xlib/XGGState.h
*** gnustep-back-0.8.3/Headers/xlib/XGGState.h Fri May 10 08:06:17 2002
--- gnustep-back-0.8.3-zz/Headers/xlib/XGGState.h Sun Feb 23 22:09:44 2003
***************
*** 25,35 ****
#ifndef _XGGState_h_INCLUDE
#define _XGGState_h_INCLUDE
#include <Foundation/NSArray.h>
#include <Foundation/NSObject.h>
#include "gsc/GSGState.h"
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
#include "x11/XGServer.h"
@class NSBezierPath;
--- 25,40 ----
#ifndef _XGGState_h_INCLUDE
#define _XGGState_h_INCLUDE
+ #include <X11/Xlib.h>
+ #include <X11/Xutil.h>
+ #ifdef HAVE_XFT
+ #define id xwindowsid
+ #include <X11/Xft/Xft.h>
+ #undef id
+ #endif
#include <Foundation/NSArray.h>
#include <Foundation/NSObject.h>
#include "gsc/GSGState.h"
#include "x11/XGServer.h"
@class NSBezierPath;
***************
*** 47,52 ****
--- 52,62 ----
Drawable draw;
Drawable alpha_buffer;
Region clipregion;
+ #ifdef HAVE_XFT
+ XftDraw *xft_draw;
+ XftDraw *xft_alpha_buffer;
+ XftColor xft_color;
+ #endif
BOOL drawingAlpha;
BOOL sharedGC; /* Do we own the GC or share it? */
***************
*** 69,74 ****
--- 79,88 ----
- (XRectangle) viewRectToX: (NSRect)aRect;
- (XPoint) windowPointToX: (NSPoint)aPoint;
- (XRectangle) windowRectToX: (NSRect)aRect;
+ #ifdef HAVE_XFT
+ - (XftDraw *) xftDrawForDrawable: (Drawable)drawable;
+ - (XftColor *) xftColor;
+ #endif
@end
diff -cr gnustep-back-0.8.3/Headers/xlib/XftFontInfo.h gnustep-back-0.8.3-zz/Headers/xlib/XftFontInfo.h
*** gnustep-back-0.8.3/Headers/xlib/XftFontInfo.h Wed Mar 27 15:45:33 2002
--- gnustep-back-0.8.3-zz/Headers/xlib/XftFontInfo.h Mon Feb 24 19:53:12 2003
***************
*** 31,40 ****
#define id xwindowsid
#include <X11/Xft/Xft.h>
#undef id
#include <AppKit/GSFontInfo.h>
! @interface XftFontInfo : GSFontInfo
{
XftFont *font_info;
}
--- 31,46 ----
#define id xwindowsid
#include <X11/Xft/Xft.h>
#undef id
+ #include <fontconfig/fontconfig.h>
#include <AppKit/GSFontInfo.h>
! @interface FcFontEnumerator : GSFontEnumerator
! {
! }
! @end
!
! @interface FcXftFontInfo : GSFontInfo
{
XftFont *font_info;
}
diff -cr gnustep-back-0.8.3/Source/xlib/GNUmakefile gnustep-back-0.8.3-zz/Source/xlib/GNUmakefile
*** gnustep-back-0.8.3/Source/xlib/GNUmakefile Wed Aug 28 09:58:28 2002
--- gnustep-back-0.8.3-zz/Source/xlib/GNUmakefile Mon Feb 24 19:52:35 2003
***************
*** 60,65 ****
--- 60,69 ----
XGGeometry.h \
XGGState.h
+ ifeq ($(WITH_XFT),yes)
+ xlib_HEADER_FILES += XftFontInfo.h
+ endif
+
-include GNUmakefile.preamble
include $(GNUSTEP_MAKEFILES)/subproject.make
diff -cr gnustep-back-0.8.3/Source/xlib/XGContext.m gnustep-back-0.8.3-zz/Source/xlib/XGContext.m
*** gnustep-back-0.8.3/Source/xlib/XGContext.m Mon Jun 3 19:21:35 2002
--- gnustep-back-0.8.3-zz/Source/xlib/XGContext.m Sun Feb 23 22:15:36 2003
***************
*** 69,91 ****
+ (void)initializeBackend
{
Class fontClass = Nil;
NSDebugLog(@"Initializing GNUstep xlib backend.\n");
[NSGraphicsContext setDefaultContextClass: [XGContext class]];
- [GSFontEnumerator setDefaultClass: [XGFontEnumerator class]];
#ifdef HAVE_XFT
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"GSFontAntiAlias"])
{
! fontClass = [XftFontInfo class];
}
#endif
if (fontClass == Nil)
{
fontClass = [XGFontInfo class];
}
[GSFontInfo setDefaultClass: fontClass];
}
- (id) initWithContextInfo: (NSDictionary *)info
--- 69,94 ----
+ (void)initializeBackend
{
Class fontClass = Nil;
+ Class fontEnumerator = Nil;
NSDebugLog(@"Initializing GNUstep xlib backend.\n");
[NSGraphicsContext setDefaultContextClass: [XGContext class]];
#ifdef HAVE_XFT
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"GSFontAntiAlias"])
{
! fontClass = [FcXftFontInfo class];
! fontEnumerator = [FcFontEnumerator class];
}
#endif
if (fontClass == Nil)
{
fontClass = [XGFontInfo class];
+ fontEnumerator = [XGFontEnumerator class];
}
[GSFontInfo setDefaultClass: fontClass];
+ [GSFontEnumerator setDefaultClass: fontEnumerator];
}
- (id) initWithContextInfo: (NSDictionary *)info
diff -cr gnustep-back-0.8.3/Source/xlib/XGGState.m gnustep-back-0.8.3-zz/Source/xlib/XGGState.m
*** gnustep-back-0.8.3/Source/xlib/XGGState.m Thu Oct 10 02:44:40 2002
--- gnustep-back-0.8.3-zz/Source/xlib/XGGState.m Mon Feb 24 20:26:44 2003
***************
*** 23,28 ****
--- 23,29 ----
*/
#include "config.h"
+ #include "xlib/XGGState.h"
#include <Foundation/NSObjCRuntime.h>
#include <AppKit/NSBezierPath.h>
#include <AppKit/NSFont.h>
***************
*** 30,37 ****
#include "xlib/XGGeometry.h"
#include "xlib/XGContext.h"
- #include "xlib/XGGState.h"
- #include "xlib/XGContext.h"
#include "xlib/XGPrivate.h"
#include "math.h"
--- 31,36 ----
***************
*** 101,112 ****
- initWithDrawContext: (GSContext *)drawContext
{
[super initWithDrawContext: drawContext];
-
drawMechanism = -1;
draw = 0;
alpha_buffer = 0;
xgcntxt = None;
agcntxt = None;
return self;
}
--- 100,114 ----
- initWithDrawContext: (GSContext *)drawContext
{
[super initWithDrawContext: drawContext];
drawMechanism = -1;
draw = 0;
alpha_buffer = 0;
xgcntxt = None;
agcntxt = None;
+ #ifdef HAVE_XFT
+ xft_draw = 0;
+ xft_alpha_buffer = 0;
+ #endif
return self;
}
***************
*** 120,125 ****
--- 122,133 ----
XFreeGC(XDPY, agcntxt);
if (clipregion)
XDestroyRegion(clipregion);
+ #ifdef HAVE_XFT
+ if (xft_draw)
+ XftDrawDestroy(xft_draw);
+ if (xft_alpha_buffer)
+ XftDrawDestroy(xft_alpha_buffer);
+ #endif
[super dealloc];
}
***************
*** 142,148 ****
XIntersectRegion(clipregion, clipregion, region);
self->clipregion = region;
}
!
return self;
}
--- 150,159 ----
XIntersectRegion(clipregion, clipregion, region);
self->clipregion = region;
}
! #ifdef HAVE_XFT
! xft_draw = 0;
! xft_alpha_buffer = 0;
! #endif
return self;
}
***************
*** 170,176 ****
}
}
! - (void) setDrawable: (Drawable)theDrawable;
{
draw = theDrawable;
}
--- 181,187 ----
}
}
! - (void) setDrawable: (Drawable)theDrawable
{
draw = theDrawable;
}
***************
*** 252,257 ****
--- 263,277 ----
gsColorToRGB(&c);
gcv.foreground = xrRGBToPixel(context, c);
[self setGCValues: gcv withMask: GCForeground];
+ #ifdef HAVE_XFT
+ {
+ xft_color.color.red = 65535. * c.field[0];
+ xft_color.color.green = 65535. * c.field[1];
+ xft_color.color.blue = 65535. * c.field[2];
+ xft_color.color.alpha = 0xffff; //TODO
+ xft_color.pixel = gcv.foreground;
+ }
+ #endif
}
- (void) setAlphaColor: (float)value
***************
*** 268,273 ****
--- 288,296 ----
agcntxt = XCreateGC(XDPY, draw, GCForeground, &gcv);
else
XChangeGC(XDPY, agcntxt, GCForeground, &gcv);
+ #ifdef HAVE_XFT
+ xft_color.color.alpha = 0xffff; //TODO
+ #endif
}
- (void) copyGraphicContext
***************
*** 1158,1163 ****
--- 1181,1218 ----
return XGWindowRectToX(self, aRect);
}
+ #ifdef HAVE_XFT
+ - (XftDraw *) xftDrawForDrawable: (Drawable)drawable
+ {
+ if (drawable == alpha_buffer && drawable!=0)
+ {
+ if (!xft_alpha_buffer) // make a XFT draw on the fly
+ xft_alpha_buffer = XftDrawCreate(XDPY, drawable,
+ DefaultVisual(XDPY, DefaultScreen(XDPY)),
+ DefaultColormap(XDPY, DefaultScreen(XDPY)));
+ // set up clipping
+ if(clipregion != None)
+ XftDrawSetClip(xft_alpha_buffer, clipregion);
+ return xft_alpha_buffer;
+ }
+ else
+ {
+ if (!xft_draw) // make a XFT draw on the fly
+ xft_draw = XftDrawCreate(XDPY, drawable,
+ DefaultVisual(XDPY, DefaultScreen(XDPY)),
+ DefaultColormap(XDPY, DefaultScreen(XDPY)));
+ // set up clipping
+ if(clipregion != None)
+ XftDrawSetClip(xft_draw, clipregion);
+ return xft_draw;
+ }
+ }
+ - (XftColor *) xftColor
+ {
+ return &xft_color;
+ }
+ #endif
+
@end
@implementation XGGState (Ops)
***************
*** 1338,1344 ****
[(XGFontInfo *)font draw: s lenght: len
onDisplay: XDPY drawable: alpha_buffer
with: agcntxt at: xp];
! }
/* Note we update the current point according to the current
transformation scaling, although the text isn't currently
scaled (FIXME). */
--- 1393,1399 ----
[(XGFontInfo *)font draw: s lenght: len
onDisplay: XDPY drawable: alpha_buffer
with: agcntxt at: xp];
! }
/* Note we update the current point according to the current
transformation scaling, although the text isn't currently
scaled (FIXME). */
diff -cr gnustep-back-0.8.3/Source/xlib/XftFontInfo.m gnustep-back-0.8.3-zz/Source/xlib/XftFontInfo.m
*** gnustep-back-0.8.3/Source/xlib/XftFontInfo.m Mon Oct 21 20:47:15 2002
--- gnustep-back-0.8.3-zz/Source/xlib/XftFontInfo.m Mon Feb 24 19:52:00 2003
***************
*** 5,10 ****
--- 5,14 ----
Copyright (C) 1996 Free Software Foundation, Inc.
+ Ported to XFT2 and fontconfig by:
+ Derek Zhou <[EMAIL PROTECTED]>
+ Date: Feb 2002
+
Author: Fred Kiefer <[EMAIL PROTECTED]>
Date: July 2001
***************
*** 39,76 ****
#include "xlib/XftFontInfo.h"
! /*
! * class global dictionary of existing fonts
! */
! static NSMutableDictionary *_globalFontDictionary = nil;
! @interface XftFontInfo (Private)
! - (BOOL) setupAttributes;
! - (XGlyphInfo *)xGlyphInfo: (NSGlyph) glyph;
@end
! @implementation XftFontInfo
- initWithFontName: (NSString*)name matrix: (const float *)fmatrix
{
[super init];
! ASSIGN(fontName, name);
! memcpy(matrix, fmatrix, sizeof(matrix));
!
! if (![self setupAttributes])
{
! RELEASE(self);
! return nil;
}
!
! return self;
}
- (void) dealloc
{
! if (font_info != NULL)
XftFontClose([XGServer currentXDisplay], (XftFont *)font_info);
[super dealloc];
}
--- 43,244 ----
#include "xlib/XftFontInfo.h"
! static NSMutableDictionary* allFonts;
! // just a warpper around a FcPattern, to make it a NSObject
! @interface FcFont : NSObject
! {
! FcPattern *aFont;
! }
! - initWithPattern:(FcPattern *)aFace;
! - (FcPattern *)font;
! @end
! @implementation FcFont
! - initWithPattern:(FcPattern *)aFace
! {
! [super init];
! aFont = aFace;
! FcPatternReference(aFace);
! return self;
! }
!
! - (FcPattern *)font
! {
! return aFont;
! }
!
! - (void) dealloc
! {
! FcPatternDestroy(aFont);
! [super dealloc];
! }
!
! @end
!
! @implementation FcFontEnumerator
!
! // Make a GNUStep style font descriptor from a FcPattern
! static NSArray *faFromFc(FcPattern *pat)
! {
! NSArray *fontArray;
! int weight, slant, spacing, nsweight;
! unsigned int nstraits = 0;
! char *family;
! NSMutableString *name, *style;
! if (FcPatternGetInteger (pat, FC_WEIGHT, 0, &weight) != FcResultMatch ||
! FcPatternGetInteger (pat, FC_SLANT, 0, &slant) != FcResultMatch ||
! FcPatternGetString (pat, FC_FAMILY, 0, (FcChar8 **) &family) != FcResultMatch)
! return (NSArray *)Nil;
! if (FcPatternGetInteger(pat, FC_SPACING, 0, &spacing) == FcResultMatch)
! if (spacing==FC_MONO || spacing==FC_CHARCELL)
! nstraits |= NSFixedPitchFontMask;
!
! name = [NSMutableString stringWithCapacity:100];
! style = [NSMutableString stringWithCapacity:100];
! [name appendString:[NSString stringWithCString:family]];
! switch (weight)
! {
! case FC_WEIGHT_LIGHT:
! [style appendString:@"Light"];
! nsweight = 3;
! break;
! case FC_WEIGHT_MEDIUM:
! nsweight = 6;
! break;
! case FC_WEIGHT_DEMIBOLD:
! [style appendString:@"Demibold"];
! nsweight = 7;
! break;
! case FC_WEIGHT_BOLD:
! [style appendString:@"Bold"];
! nsweight = 9;
! nstraits |= NSBoldFontMask;
! break;
! case FC_WEIGHT_BLACK:
! [style appendString:@"Black"];
! nsweight = 12;
! nstraits |= NSBoldFontMask;
! break;
! default:
! nsweight = 6;
! }
! switch (slant)
! {
! case FC_SLANT_ROMAN:
! break;
! case FC_SLANT_ITALIC:
! [style appendString:@"Italic"];
! nstraits |= NSItalicFontMask;
! break;
! case FC_SLANT_OBLIQUE:
! [style appendString:@"Oblique"];
! nstraits |= NSItalicFontMask;
! break;
! }
! if ([style length]>0)
! {
! [name appendString:@"-"];
! [name appendString:style];
! }
! else
! [style appendString:@"Roman"];
!
! fontArray = [NSArray arrayWithObjects:name, style,
! [NSNumber numberWithInt:nsweight],
! [NSNumber numberWithUnsignedInt:nstraits],
! Nil];
! return fontArray;
! }
!
! - (void) enumerateFontsAndFamilies
! {
! int i;
! FcPattern *pat = FcPatternCreate ();
! FcObjectSet *os = FcObjectSetBuild (FC_FAMILY, FC_SLANT, FC_WEIGHT, 0);
! FcFontSet *fs = FcFontList (0, pat, os);
! NSMutableDictionary *fcxft_allFontFamilies = [[NSMutableDictionary alloc] init];
! NSMutableDictionary *fcxft_allFonts = [[NSMutableDictionary alloc] init];
! NSMutableArray *fcxft_allFontNames = [[NSMutableArray alloc] init];
!
! FcPatternDestroy (pat);
! FcObjectSetDestroy (os);
!
! for (i=0; i < fs->nfont; i++)
! {
! char *family;
! NSString *familyString;
! NSMutableArray *familyArray;
! if (FcPatternGetString (fs->fonts[i], FC_FAMILY, 0, (FcChar8 **) &family) == FcResultMatch)
! {
! NSArray *fontArray;
! if ((fontArray = faFromFc(fs->fonts[i])))
! {
! FcFont *aFont;
! familyString = [NSString stringWithCString:family];
! if (!(familyArray = [fcxft_allFontFamilies objectForKey:familyString]))
! {
! familyArray = [[NSMutableArray alloc] init];
! [fcxft_allFontFamilies setObject:familyArray forKey:familyString];
! }
! NSDebugLog(@"fc enumerator: adding font: %@",[fontArray objectAtIndex:0]);
! [familyArray addObject:fontArray];
! aFont = [[FcFont alloc] initWithPattern:fs->fonts[i]];
! [fcxft_allFontNames addObject:[fontArray objectAtIndex:0]];
! [fcxft_allFonts setObject:aFont forKey: [fontArray objectAtIndex:0]];
! RELEASE(aFont);
! }
! }
! }
! FcFontSetDestroy (fs);
! ASSIGN(allFontNames, fcxft_allFontNames);
! ASSIGN(allFontFamilies, fcxft_allFontFamilies);
! ASSIGN(allFonts, fcxft_allFonts);
! }
!
! - (void) dealloc
! {
! RELEASE(allFontNames);
! RELEASE(allFonts);
! RELEASE(allFontFamilies);
! [super dealloc];
! }
@end
! @interface FcXftFontInfo (Private)
!
! - (BOOL) setupAttributesWithFcPattern:(FcPattern *)aFont;
! - (XGlyphInfo *)xGlyphInfo: (NSGlyph) glyph;
! @end
!
! @implementation FcXftFontInfo
- initWithFontName: (NSString*)name matrix: (const float *)fmatrix
{
+ FcFont *realFont = [allFonts objectForKey:name];
[super init];
! if (!realFont)
{
! NSString *aKey = [[allFonts allKeys] objectAtIndex:0];
! NSLog(@"Font: %@ not found!", name);
! NSLog(@"Using Font: %@ instead!", aKey);
! realFont = [allFonts objectForKey:aKey];
! ASSIGN(fontName, aKey);
}
! else
! ASSIGN(fontName, name);
! memcpy(matrix, fmatrix, sizeof(matrix));
! NSDebugLog(@"Try to load font: %@ at size %f", fontName, matrix[0]);
! if ([self setupAttributesWithFcPattern:[realFont font]])
! return self;
! else
! return Nil;
}
- (void) dealloc
{
! if (font_info)
XftFontClose([XGServer currentXDisplay], (XftFont *)font_info);
[super dealloc];
}
***************
*** 102,108 ****
// if per_char is NULL assume max bounds
if (!pc)
! return NSMakeSize((float)(font_info)->max_advance_width, 0);
return NSMakeSize((float)pc->xOff, (float)pc->yOff);
}
--- 270,276 ----
// if per_char is NULL assume max bounds
if (!pc)
! return NSMakeSize((float)(font_info->max_advance_width), 0.0);
return NSMakeSize((float)pc->xOff, (float)pc->yOff);
}
***************
*** 110,116 ****
- (NSRect) boundingRectForGlyph: (NSGlyph)glyph
{
XGlyphInfo *pc = [self xGlyphInfo: glyph];
-
// if per_char is NULL assume max bounds
if (!pc)
return NSMakeRect(0.0, 0.0,
--- 278,283 ----
***************
*** 125,131 ****
- (BOOL) glyphIsEncoded: (NSGlyph)glyph
{
return XftGlyphExists([XGServer currentXDisplay],
! (XftFont *)font_info, glyph);
}
- (NSGlyph) glyphWithName: (NSString*)glyphName
--- 292,298 ----
- (BOOL) glyphIsEncoded: (NSGlyph)glyph
{
return XftGlyphExists([XGServer currentXDisplay],
! font_info, glyph);
}
- (NSGlyph) glyphWithName: (NSString*)glyphName
***************
*** 157,171 ****
}
}
- /*
- - (float) pointSize
- {
- Display *xdpy = [XGServer currentXDisplay];
-
- return XGFontPointSize(xdpy, font_info);
- }
- */
-
- (void) drawString: (NSString*)string
onDisplay: (Display*) xdpy drawable: (Drawable) draw
with: (GC) xgcntxt at: (XPoint) xp
--- 324,329 ----
***************
*** 175,221 ****
int length = [d length];
const char *cstr = (const char*)[d bytes];
XftDraw *xftdraw;
! XftColor xftcolor;
! XColor dummyc;
! XGCValues values;
! XGGState *state = [(XGContext *)GSCurrentContext() currentGState];
! Region xregion = [state xClipRegion];
! int defaultScreen = DefaultScreen(xdpy);
! Colormap colmap = DefaultColormap(xdpy, defaultScreen);
/* ready to draw */
! xftdraw = XftDrawCreate(xdpy, draw,
! DefaultVisual(xdpy, defaultScreen),
! colmap);
if(xftdraw == NULL)
return;
/* sort out the drawing colour */
! XGetGCValues(xdpy, xgcntxt,
! GCForeground | GCBackground,
! &values);
!
! dummyc.pixel = values.foreground;
! XQueryColor(xdpy, colmap, &dummyc);
! xftcolor.color.red = dummyc.red;
! xftcolor.color.green = dummyc.green;
! xftcolor.color.blue = dummyc.blue;
! xftcolor.color.alpha = 0xffff;
! xftcolor.pixel = values.foreground;
- // set up clipping
- if(xregion != None)
- {
- XftDrawSetClip(xftdraw, xregion);
- XDestroyRegion(xregion);
- }
-
/* do it */
! XftDrawString16(xftdraw, &xftcolor, font_info,
! xp.x, xp.y, (XftChar16*)cstr, length);
!
! /* tidy up */
! XftDrawDestroy(xftdraw);
}
- (void) draw: (const char*) s lenght: (int) len
--- 333,357 ----
int length = [d length];
const char *cstr = (const char*)[d bytes];
XftDraw *xftdraw;
! XftColor *xftcolor;
! XGContext *context = (XGContext *)GSCurrentContext();
! XGGState *state = [context currentGState];
/* ready to draw */
! xftdraw = [state xftDrawForDrawable:draw];
if(xftdraw == NULL)
return;
/* sort out the drawing colour */
! xftcolor = [state xftColor];
/* do it */
! #ifdef HAVE_UTF8
! XftDrawStringUtf8(xftdraw, xftcolor, font_info,
! xp.x, xp.y, (XftChar8 *)cstr, length);
! #endif
! XftDrawString8(xftdraw, xftcolor, font_info,
! xp.x, xp.y, (XftChar8*)cstr, length);
}
- (void) draw: (const char*) s lenght: (int) len
***************
*** 224,280 ****
{
int length = strlen(s);
XftDraw *xftdraw;
! XftColor xftcolor;
! XColor dummyc;
! XGCValues values;
! XGGState *state = [(XGContext *)GSCurrentContext() currentGState];
! Region xregion = [state xClipRegion];
! int defaultScreen = DefaultScreen(xdpy);
! Colormap colmap = DefaultColormap(xdpy, defaultScreen);
/* ready to draw */
! xftdraw = XftDrawCreate(xdpy, draw,
! DefaultVisual(xdpy, defaultScreen),
! colmap);
! if(xftdraw == NULL)
! return;
/* sort out the drawing colour */
! XGetGCValues(xdpy, xgcntxt,
! GCForeground | GCBackground,
! &values);
!
! dummyc.pixel = values.foreground;
! XQueryColor(xdpy, colmap, &dummyc);
! xftcolor.color.red = dummyc.red;
! xftcolor.color.green = dummyc.green;
! xftcolor.color.blue = dummyc.blue;
! xftcolor.color.alpha = 0xffff;
! xftcolor.pixel = values.foreground;
!
! // set up clipping
! if(xregion != None)
! {
! XftDrawSetClip(xftdraw, xregion);
! XDestroyRegion(xregion);
! }
#ifdef HAVE_UTF8
/* do it */
if (NSUTF8StringEncoding == mostCompatibleStringEncoding)
{
! XftDrawStringUtf8(xftdraw, &xftcolor, font_info,
xp.x, xp.y, (XftChar8 *)s, length);
}
else
#endif
{
! XftDrawString8(xftdraw, &xftcolor, font_info,
! xp.x, xp.y, (XftChar8*)s, length);
}
-
- /* tidy up */
- XftDrawDestroy(xftdraw);
}
- (float) widthOf: (const char*) s lenght: (int) len
--- 360,388 ----
{
int length = strlen(s);
XftDraw *xftdraw;
! XftColor *xftcolor;
! XGContext *context = (XGContext *)GSCurrentContext();
! XGGState *state = [context currentGState];
/* ready to draw */
! xftdraw = [state xftDrawForDrawable:draw];
/* sort out the drawing colour */
! xftcolor = [state xftColor];
#ifdef HAVE_UTF8
/* do it */
if (NSUTF8StringEncoding == mostCompatibleStringEncoding)
{
! XftDrawStringUtf8(xftdraw, xftcolor, font_info,
xp.x, xp.y, (XftChar8 *)s, length);
}
else
#endif
{
! XftDrawString8(xftdraw, xftcolor, font_info,
! xp.x, xp.y, (XftChar8*)s, length);
}
}
- (float) widthOf: (const char*) s lenght: (int) len
***************
*** 305,410 ****
@end
! @implementation XftFontInfo (Private)
! - (BOOL) setupAttributes
{
Display *xdpy = [XGServer currentXDisplay];
- int defaultScreen = DefaultScreen(xdpy);
NSString *weightString;
! NSString *reg;
! long height;
! XftPattern *pattern;
! XftResult result;
! NSString *xfontname;
!
! char *xftTypeString;
! int xftTypeInt;
! NSArray *encoding;
if (!xdpy)
return NO;
!
! // Retrieve the XLFD matching the given fontName. DPS->X.
! xfontname = XGXFontName(fontName, matrix[0]);
!
! // Load Xft font and get font info structure.
! if ((xfontname == nil) ||
! (font_info = XftFontOpenXlfd(xdpy, defaultScreen, [xfontname cString])) == NULL)
! {
! NSLog(@"Selected font: %@ (%@) is not available.\n"
! @"Using system default font instead", fontName, xfontname);
!
! if ((font_info = XftFontOpen(xdpy, defaultScreen, 0)) == NULL)
! {
! NSLog(@"Unable to open fixed font");
! return NO;
! }
! }
! else
! NSDebugLog(@"Loaded font: %@", xfontname);
// Fill the afmDitionary and ivars
[fontDictionary setObject: fontName forKey: NSAFMFontName];
! pattern = font_info->pattern;
! result = XftPatternGetString(pattern, XFT_FAMILY, 0, &xftTypeString);
! if (result != XftResultTypeMismatch)
{
ASSIGN(familyName,
! [NSString stringWithCString: (const char*)xftTypeString]);
[fontDictionary setObject: familyName forKey: NSAFMFamilyName];
}
! result = XftPatternGetInteger(pattern, XFT_SPACING, 0, &xftTypeInt);
! if (result != XftResultTypeMismatch)
{
! isFixedPitch = (weight != 0);
}
!
! isBaseFont = NO;
! ascender = font_info->ascent;
! [fontDictionary setObject: [NSNumber numberWithFloat: ascender]
! forKey: NSAFMAscender];
! descender = -(font_info->descent);
! [fontDictionary setObject: [NSNumber numberWithFloat: descender]
! forKey: NSAFMDescender];
! fontBBox = NSMakeRect(
! (float)(0),
! (float)(0 - font_info->ascent),
! (float)(font_info->max_advance_width),
! (float)(font_info->ascent + font_info->descent));
! maximumAdvancement = NSMakeSize(font_info->max_advance_width,
! (font_info->ascent + font_info->descent));
! minimumAdvancement = NSMakeSize(0,0);
!
! result = XftPatternGetInteger(pattern, XFT_WEIGHT, 0, &xftTypeInt);
! if (result != XftResultTypeMismatch)
{
! switch (xftTypeInt)
{
! case 0:
weight = 3;
weightString = @"light";
break;
! case 100:
weight = 6;
weightString = @"medium";
break;
! case 180:
weight = 7;
weightString = @"demibold";
break;
! case 200:
weight = 9;
weightString = @"bold";
break;
! case 210:
weight = 12;
weightString = @"black";
break;
default:
// Don't know
! weight = 6;;
}
if (weightString != nil)
{
--- 413,482 ----
@end
! @implementation FcXftFontInfo (Private)
! - (BOOL) setupAttributesWithFcPattern:(FcPattern *)aFont
{
Display *xdpy = [XGServer currentXDisplay];
NSString *weightString;
! FcPattern *fontPattern = FcPatternDuplicate(aFont);
! FcPattern *pattern;
! FcResult fc_result;
! char *family;
! int fcspacing, fcweight, fcslant;
if (!xdpy)
return NO;
! // the only thing needs customization here is the size
! FcPatternAddDouble (fontPattern, FC_SIZE, (double)(matrix[0]));
! FcPatternAddBool (fontPattern, FC_AUTOHINT, FcTrue);
! // fcFont = FcFontRenderPrepare (0, fontPattern, aFont);
! pattern = XftFontMatch(xdpy, DefaultScreen(xdpy), fontPattern, &fc_result);
! // FcPatternDestroy(fcFont);
! // tide up
! FcPatternDestroy (fontPattern);
// Fill the afmDitionary and ivars
[fontDictionary setObject: fontName forKey: NSAFMFontName];
! if (FcPatternGetString(pattern, FC_FAMILY, 0, (FcChar8 **) &family) == FcResultMatch)
{
ASSIGN(familyName,
! [NSString stringWithCString: (const char*)family]);
[fontDictionary setObject: familyName forKey: NSAFMFamilyName];
}
! if (FcPatternGetInteger(pattern, FC_SPACING, 0, &fcspacing) == FcResultMatch)
{
! isFixedPitch = (fcspacing==FC_MONO || fcspacing==FC_CHARCELL);
}
! if (FcPatternGetInteger (pattern, FC_WEIGHT, 0, &fcweight) == FcResultMatch)
{
! switch (fcweight)
{
! case FC_WEIGHT_LIGHT:
weight = 3;
weightString = @"light";
break;
! case FC_WEIGHT_MEDIUM:
weight = 6;
weightString = @"medium";
break;
! case FC_WEIGHT_DEMIBOLD:
weight = 7;
weightString = @"demibold";
break;
! case FC_WEIGHT_BOLD:
weight = 9;
weightString = @"bold";
break;
! case FC_WEIGHT_BLACK:
weight = 12;
weightString = @"black";
break;
default:
// Don't know
! weight = 6;
! weightString = @"medium";
}
if (weightString != nil)
{
***************
*** 420,474 ****
if (isFixedPitch)
traits |= NSFixedPitchFontMask;
! result = XftPatternGetInteger(pattern, XFT_SLANT, 0, &xftTypeInt);
! if (result != XftResultTypeMismatch)
{
! if (xftTypeInt != 0)
! traits |= NSItalicFontMask;
! else
! traits |= NSUnitalicFontMask;
! }
!
! XftPatternGetString (pattern, XFT_ENCODING, 0, &xftTypeString);
! encodingScheme = [NSString stringWithCString: xftTypeString];
! encoding = [encodingScheme componentsSeparatedByString: @"-"];
! reg = [encoding objectAtIndex: 0];
! if (reg != nil)
! {
! if ([encoding count] > 1)
{
! NSString *enc = [encoding lastObject];
! mostCompatibleStringEncoding = GSEncodingForRegistry(reg, enc);
! if (mostCompatibleStringEncoding == GSUndefinedEncoding)
! mostCompatibleStringEncoding = NSASCIIStringEncoding;
! if (mostCompatibleStringEncoding == NSUnicodeStringEncoding)
! mostCompatibleStringEncoding = NSUTF8StringEncoding;
! RETAIN(encodingScheme);
! [fontDictionary setObject: encodingScheme
! forKey: NSAFMEncodingScheme];
! }
}
else
! encodingScheme = nil;
! /*
! height = XGFontPropULong(xdpy, font_info, XA_X_HEIGHT);
! if (height != 0)
! {
! xHeight = (float)height;
! [fontDictionary setObject: [NSNumber numberWithFloat: xHeight]
! forKey: NSAFMXHeight];
! }
!
! height = XGFontPropULong(xdpy, font_info, XA_CAP_HEIGHT);
! if (height != 0)
! {
! capHeight = (float)height;
! [fontDictionary setObject: [NSNumber numberWithFloat: capHeight]
! forKey: NSAFMCapHeight];
! }
! */
! // FIXME: italicAngle, underlinePosition, underlineThickness are not set.
! // Should use XA_ITALIC_ANGLE, XA_UNDERLINE_POSITION, XA_UNDERLINE_THICKNESS
return YES;
}
--- 492,547 ----
if (isFixedPitch)
traits |= NSFixedPitchFontMask;
! if (FcPatternGetInteger (pattern, FC_SLANT, 0, &fcslant) == FcResultMatch)
{
! switch (fcslant)
{
! case FC_SLANT_ROMAN:
! traits |= NSUnitalicFontMask;
! break;
! case FC_SLANT_ITALIC:
! traits |= NSItalicFontMask;
! break;
! case FC_SLANT_OBLIQUE:
! traits |= NSItalicFontMask;
! break;
! }
}
+
+ if ((font_info = XftFontOpenPattern (xdpy, pattern)))
+ NSDebugLog(@"Loaded font: %@", fontName);
else
! {
! NSDebugLog(@"Cannot load font: %@", fontName);
! return NO;
! }
!
! isBaseFont = NO;
! ascender = font_info->ascent;
! [fontDictionary setObject: [NSNumber numberWithFloat: ascender]
! forKey: NSAFMAscender];
! descender = -(font_info->descent);
! [fontDictionary setObject: [NSNumber numberWithFloat: descender]
! forKey: NSAFMDescender];
! capHeight = ascender - descender; // TODO
! xHeight = capHeight*0.6; //Errr... TODO
! fontBBox = NSMakeRect(
! (float)(0),
! (float)(0 - font_info->ascent),
! (float)(font_info->max_advance_width),
! (float)(font_info->ascent + font_info->descent));
! maximumAdvancement = NSMakeSize(font_info->max_advance_width,
! (font_info->ascent + font_info->descent));
! minimumAdvancement = NSMakeSize(0,0);
! // printf("h=%g a=%g d=%g max=(%g %g) (%g %g)+(%g %g)\n",
! // xHeight, ascender, descender,
! // maximumAdvancement.width, maximumAdvancement.height,
! // fontBBox.origin.x, fontBBox.origin.y,
! // fontBBox.size.width, fontBBox.size.height);
!
! /* TODO: somehow make gnustep-gui send unicode our way. utf8? ugly, but it works */
! mostCompatibleStringEncoding = NSUTF8StringEncoding;
! encodingScheme = @"iso10646-1";
return YES;
}
***************
*** 477,483 ****
static XGlyphInfo glyphInfo;
XftTextExtents32 ([XGServer currentXDisplay],
! (XftFont *)font_info,
&glyph,
1,
&glyphInfo);
--- 550,556 ----
static XGlyphInfo glyphInfo;
XftTextExtents32 ([XGServer currentXDisplay],
! font_info,
&glyph,
1,
&glyphInfo);
diff -cr gnustep-back-0.8.3/configure.ac gnustep-back-0.8.3-zz/configure.ac
*** gnustep-back-0.8.3/configure.ac Fri Nov 15 21:00:14 2002
--- gnustep-back-0.8.3-zz/configure.ac Mon Feb 24 19:31:44 2003
***************
*** 181,195 ****
CPPFLAGS="${GRAPHIC_CFLAGS} ${GRAPHIC_LFLAGS} ${CPPFLAGS}"
LIBS="${GRAPHIC_LIBS} ${LIBS}"
AC_CHECK_LIB(Xft, XftFontOpen, have_xft=yes, have_xft=no)
AC_CHECK_HEADER(X11/Xft/Xft.h)
if test "$have_xft" = yes -a "$ac_cv_header_X11_Xft_Xft_h" = yes; then
! GRAPHIC_LIBS="-lXft ${GRAPHIC_LIBS}"
WITH_XFT=yes
AC_DEFINE(HAVE_XFT,1,[Define if you have the Xft library])
AC_CHECK_LIB(Xft, XftDrawStringUtf8, have_utf8=yes, have_utf8=no)
if test "$have_utf8" = yes; then
AC_DEFINE(HAVE_UTF8,1,[Define if you have XftDrawStringUtf8])
fi
fi
CPPFLAGS="${save_header}"
LIBS="${save_libs}"
--- 181,199 ----
CPPFLAGS="${GRAPHIC_CFLAGS} ${GRAPHIC_LFLAGS} ${CPPFLAGS}"
LIBS="${GRAPHIC_LIBS} ${LIBS}"
AC_CHECK_LIB(Xft, XftFontOpen, have_xft=yes, have_xft=no)
+ AC_CHECK_LIB(fontconfig, FcPatternCreate, have_fc=yes, have_fc=no)
AC_CHECK_HEADER(X11/Xft/Xft.h)
+ AC_CHECK_HEADER(fontconfig/fontconfig.h)
if test "$have_xft" = yes -a "$ac_cv_header_X11_Xft_Xft_h" = yes; then
! if test "$have_fc" = yes -a "$ac_cv_header_fontconfig_fontconfig_h" = yes; then
! GRAPHIC_LIBS="-lXft -lfontconfig ${GRAPHIC_LIBS}"
WITH_XFT=yes
AC_DEFINE(HAVE_XFT,1,[Define if you have the Xft library])
AC_CHECK_LIB(Xft, XftDrawStringUtf8, have_utf8=yes, have_utf8=no)
if test "$have_utf8" = yes; then
AC_DEFINE(HAVE_UTF8,1,[Define if you have XftDrawStringUtf8])
fi
+ fi
fi
CPPFLAGS="${save_header}"
LIBS="${save_libs}"
_______________________________________________
Bug-gnustep mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-gnustep