Implement color handling in GSGState

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@13623 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 2002-05-10 15:06:17 +00:00
parent 72d35bd260
commit 98bfc99c36
16 changed files with 409 additions and 352 deletions

View file

@ -1,3 +1,21 @@
2002-05-09 Adam Fedor <fedor@gnu.org>
* Headers/gsc/GSGState.h: Add color and text ivars.
* Headers/winlib/WIN32GState.h: Idem.
* Headers/xlib/XGGState.h: Idem.
* Source/gsc/GSContext.m: Implement font/text methods.
* Source/gsc/GSGState.m (-setColor:state:) Implement
Implement color DPS and GS ops to use it.
Implement text/font ops.
* Source/winlib/WIN32GState.m (-setColor:state:) Implement.
Remove color ops (now in GSGState)
* Source/xlib/XGGState.m (-setColor:state:) Implement.
(-setAlphaColor:) New.
Remove color ops (now in GSGState)
2002-05-07 Adam Fedor <fedor@gnu.org>
* Source/gsc/GSStreamContext.m (-GSSetFont:): Don't flip

View file

@ -30,6 +30,7 @@
#include <AppKit/NSGraphicsContext.h> // needed for NSCompositingOperation
#include <Foundation/NSArray.h>
#include <Foundation/NSObject.h>
#include <gsc/gscolors.h>
@class NSAffineTransform;
@class NSBezierPath;
@ -40,15 +41,29 @@ typedef enum {
path_stroke, path_fill, path_eofill, path_clip, path_eoclip
} ctxt_object_t;
typedef enum {
COLOR_STROKE = 1,
COLOR_FILL = 2,
COLOR_BOTH = 3 /* COLOR_BOTH = COLOR_FILL || COLOR_STROKE */
} color_state_t;
@interface GSGState : NSObject
{
@public
GSContext *drawcontext;
NSAffineTransform *ctm;
NSPoint offset; /* Offset from Drawable origin */
NSBezierPath *path; /* current path */
NSFont *font;
NSBezierPath *path; /* Current path */
NSFont *font; /* Current font */
NSColor *fillColorS; /* Color(space) used for fill drawing */
NSColor *strokeColorS; /* Color(space) used for stroke drawing */
device_color_t fillColor; /* fill color */
device_color_t strokeColor; /* stroke color */
color_state_t cstate; /* state last time color was set */
float charSpacing;
NSAffineTransform *textCtm; /* Text transform - concat with ctm */
GSTextDrawingMode textMode;
BOOL viewIsFlipped;
}
@ -58,8 +73,7 @@ typedef enum {
- (void) setOffset: (NSPoint)theOffset;
- (NSPoint) offset;
- (void) setFont: (NSFont*)font;
- (NSFont*) currentFont;
- (void) setColor: (device_color_t)color state: (color_state_t)cState;
- (void) compositeGState: (GSGState *)source
fromRect: (NSRect)aRect

View file

@ -58,6 +58,17 @@
- (void) DPSxyshow: (const char*)s : (const float*)numarray : (int)size;
- (void) DPSyshow: (const char*)s : (const float*)numarray : (int)size;
- (void) GSSetCharacterSpacing: (float)extra;
- (void) GSSetFont: (NSFont*)font;
- (void) GSSetFontSize: (float)size;
- (NSAffineTransform *) GSGetTextCTM;
- (NSPoint) GSGetTextPosition;
- (void) GSSetTextCTM: (NSAffineTransform *)ctm;
- (void) GSSetTextDrawingMode: (GSTextDrawingMode)mode;
- (void) GSSetTextPosition: (NSPoint)loc;
- (void) GSShowText: (const char *)string : (size_t) length;
- (void) GSShowGlyphs: (const NSGlyph *)glyphs : (size_t) length;
/* ----------------------------------------------------------------------- */
/* Gstate operations */
/* ----------------------------------------------------------------------- */

View file

@ -1,8 +1,8 @@
/* xrtools - Color conversion routines and other low-level X support
/* gscolors - Color conversion routines
Copyright (C) 1995 Free Software Foundation, Inc.
Written by: Adam Fedor <fedor@boulder.colorado.edu>
Written by: Adam Fedor <fedor@gnu.org>
Date: Nov 1994
This file is part of the GNU Objective C User Interface Library.
@ -22,23 +22,27 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#ifndef _xrtools_h_INCLUDE
#define _xrtools_h_INCLUDE
#ifndef _gscolors_h_INCLUDE
#define _gscolors_h_INCLUDE
#define AINDEX 5
typedef enum {
gray_colorspace, rgb_colorspace, hsb_colorspace, cmyk_colorspace
} xr_device_colorspace_t;
} device_colorspace_t;
typedef struct _xr_device_color {
xr_device_colorspace_t space;
typedef struct _device_color {
device_colorspace_t space;
float field[6];
} xr_device_color_t;
} device_color_t;
/* Internal conversion of colors to pixels values */
extern xr_device_color_t xrColorToRGB(xr_device_color_t color);
extern xr_device_color_t xrColorToGray(xr_device_color_t color);
extern xr_device_color_t xrColorToCMYK(xr_device_color_t color);
extern xr_device_color_t xrColorToHSB(xr_device_color_t color);
extern device_color_t gsMakeColor(device_colorspace_t space,
float a, float b, float c, float d);
extern device_color_t gsColorToRGB(device_color_t color);
extern device_color_t gsColorToGray(device_color_t color);
extern device_color_t gsColorToCMYK(device_color_t color);
extern device_color_t gsColorToHSB(device_color_t color);
#endif

View file

@ -33,7 +33,8 @@
{
@public
HWND window;
COLORREF color;
COLORREF wfcolor;
COLORREF wscolor;
int joinStyle;
int lineCap;
float lineWidth;

View file

@ -31,7 +31,6 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "x11/XGServer.h"
#include "xlib/xrtools.h"
@class NSBezierPath;
@class NSFont;
@ -43,11 +42,11 @@
void *windevice;
XGDrawMechanism drawMechanism;
GC xgcntxt;
GC agcntxt;
XGCValues gcv;
Drawable draw;
Drawable alpha_buffer;
Region clipregion;
xr_device_color_t color;
BOOL drawingAlpha;
BOOL sharedGC; /* Do we own the GC or share it? */
@ -58,7 +57,6 @@
- (void) setGCValues: (XGCValues)values withMask: (int)mask;
- (void) setClipMask;
- (Region) xClipRegion;
- (void) setColor: (xr_device_color_t)acolor;
- (BOOL) hasDrawable;
- (BOOL) hasGraphicContext;
@ -67,9 +65,6 @@
- (GC) graphicContext;
- (NSRect) clipRect;
- (void) setFont: (NSFont*)font;
- (NSFont*) currentFont;
- (XPoint) viewPointToX: (NSPoint)aPoint;
- (XRectangle) viewRectToX: (NSRect)aRect;
- (XPoint) windowPointToX: (NSPoint)aPoint;

View file

@ -35,7 +35,6 @@
#include "x11/XGServer.h"
#include "xlib/XGContext.h"
#include "xlib/xrtools.h"
#include <AppKit/GSFontInfo.h>
/* Font function (defined in XGFontManager) */

View file

@ -43,10 +43,13 @@ GSGState.m \
GSStreamContext.m \
externs.m
gsc_C_FILES = gscolors.c
gsc_HEADER_FILES_DIR = ../../Headers/gsc
gsc_HEADER_FILES_INSTALL_DIR = gnustep/gsc
gsc_HEADER_FILES = \
gscolors.h \
GSContext.h \
GSGState.h \
GSGStateOps.h

View file

@ -317,54 +317,52 @@ static unsigned int unique_index = 0;
- (void) GSSetCharacterSpacing: (float)extra
{
[self notImplemented: _cmd];
[gstate GSSetCharacterSpacing: extra];
}
- (void) GSSetFont: (NSFont*)font
{
[gstate setFont: font];
[gstate GSSetFont: font];
}
- (void) GSSetFontSize: (float)size
{
[self notImplemented: _cmd];
[gstate GSSetFontSize: size];
}
- (NSAffineTransform *) GSGetTextCTM
{
[self notImplemented: _cmd];
return nil;
return [gstate GSGetTextCTM];
}
- (NSPoint) GSGetTextPosition
{
[self notImplemented: _cmd];
return NSMakePoint(0,0);
return [gstate GSGetTextPosition];
}
- (void) GSSetTextCTM: (NSAffineTransform *)ctm
{
[self notImplemented: _cmd];
[gstate GSSetTextCTM: ctm];
}
- (void) GSSetTextDrawingMode: (GSTextDrawingMode)mode
{
[self notImplemented: _cmd];
[gstate GSSetTextDrawingMode: mode];
}
- (void) GSSetTextPosition: (NSPoint)loc
{
[self notImplemented: _cmd];
[gstate GSSetTextPosition: loc];
}
- (void) GSShowText: (const char *)string : (size_t) length
{
[self notImplemented: _cmd];
[gstate GSShowText: string : length];
}
- (void) GSShowGlyphs: (const NSGlyph *)glyphs : (size_t) length
{
[self notImplemented: _cmd];
[gstate GSShowGlyphs: glyphs : length];
}
/* ----------------------------------------------------------------------- */

View file

@ -26,7 +26,9 @@
#include <Foundation/NSObjCRuntime.h>
#include <AppKit/NSAffineTransform.h>
#include <AppKit/NSBezierPath.h>
#include <AppKit/NSColor.h>
#include <AppKit/NSFont.h>
#include <AppKit/NSGraphics.h>
#include "gsc/GSContext.h"
#include "gsc/GSGState.h"
#include "math.h"
@ -37,6 +39,31 @@
path = [NSBezierPath new]; \
}
/* Just temporary until we improve NSColor */
@interface NSColor (PrivateColor)
+ colorWithValues: (float *)values colorSpaceName: colorSpace;
@end
@implementation NSColor (PrivateColor)
+ colorWithValues: (float *)values colorSpaceName: colorSpace
{
NSColor *color = nil;
if ([colorSpace isEqual: NSDeviceWhiteColorSpace])
color = [NSColor colorWithDeviceWhite: values[0] alpha: values[1]];
else if ([colorSpace isEqual: NSDeviceRGBColorSpace])
color = [NSColor colorWithDeviceRed: values[0] green: values[1]
blue: values[2] alpha: values[3]];
else if ([colorSpace isEqual: NSDeviceCMYKColorSpace])
color = [NSColor colorWithDeviceCyan: values[0] magenta: values[1]
yellow: values[2] black: values[3] alpha: values[4]];
else
DPS_ERROR(DPSundefined, @"Cannot convert colorspace");
return color;
}
@end
@implementation GSGState
/* Designated initializer. */
@ -46,9 +73,21 @@
drawcontext = drawContext;
ctm = [[NSAffineTransform allocWithZone: GSObjCZone(self)] init];
path = nil;
font = nil;
offset = NSMakePoint(0, 0);
path = nil;
font = nil;
/* Initialize colors. By default the same color is used for filling and
stroking unless fill and/or stroke color is set explicitly */
cstate = COLOR_BOTH;
fillColorS = nil;
strokeColorS = nil;
fillColor = gsMakeColor(gray_colorspace, 0, 0, 0, 0);
strokeColor = gsMakeColor(gray_colorspace, 0, 0, 0, 0);
charSpacing = 0;
textMode = GSTextFill;
textCtm = [[NSAffineTransform allocWithZone: GSObjCZone(self)] init];
return self;
}
@ -57,6 +96,9 @@
TEST_RELEASE(font);
TEST_RELEASE(path);
RELEASE(ctm);
RELEASE(textCtm);
RELEASE(fillColorS);
RELEASE(strokeColorS);
[super dealloc];
}
@ -67,11 +109,16 @@
if (path)
self->path = [path copyWithZone: zone];
self->ctm = [ctm copyWithZone: zone];
self->ctm = [ctm copyWithZone: zone];
self->textCtm = [ctm copyWithZone: zone];
// Just retain the font
// Just retain the other objects
if (font != nil)
RETAIN(font);
if (fillColorS != nil)
RETAIN(fillColorS);
if (strokeColorS != nil)
RETAIN(strokeColorS);
return self;
}
@ -83,18 +130,6 @@
return [new deepen];
}
- (void) setFont: (NSFont*)newFont
{
if (font == newFont)
return;
ASSIGN(font, newFont);
}
- (NSFont*) currentFont
{
return font;
}
- (void) setOffset: (NSPoint)theOffset
{
offset = theOffset;
@ -105,6 +140,22 @@
return offset;
}
/** Subclasses should override this method to be notified of changes
in the current color */
- (void) setColor: (device_color_t)color state: (color_state_t)cState
{
float alpha;
alpha = fillColor.field[AINDEX];
if (cState & COLOR_FILL)
fillColor = color;
fillColor.field[AINDEX] = alpha;
alpha = strokeColor.field[AINDEX];
if (cState & COLOR_STROKE)
strokeColor = color;
strokeColor.field[AINDEX] = alpha;
cstate = cState;
}
- (void) compositeGState: (GSGState *)source
fromRect: (NSRect)aRect
toPoint: (NSPoint)aPoint
@ -151,73 +202,138 @@
/* ----------------------------------------------------------------------- */
- (void) DPScurrentalpha: (float*)a
{
[self notImplemented: _cmd];
*a = fillColor.field[AINDEX];
}
- (void) DPScurrentcmykcolor: (float*)c : (float*)m : (float*)y : (float*)k
{
[self notImplemented: _cmd];
device_color_t new = fillColor;
new = gsColorToCMYK(new);
*c = new.field[0];
*m = new.field[1];
*y = new.field[2];
*k = new.field[3];
}
- (void) DPScurrentgray: (float*)gray
{
[self notImplemented: _cmd];
device_color_t gcolor;
gcolor = gsColorToGray(fillColor);
*gray = gcolor.field[0];
}
- (void) DPScurrenthsbcolor: (float*)h : (float*)s : (float*)b
{
[self notImplemented: _cmd];
device_color_t gcolor;
gcolor = gsColorToHSB(fillColor);
*h = gcolor.field[0]; *s = gcolor.field[1]; *b = gcolor.field[2];
}
- (void) DPScurrentrgbcolor: (float*)r : (float*)g : (float*)b
{
[self notImplemented: _cmd];
device_color_t gcolor;
gcolor = gsColorToRGB(fillColor);
*r = gcolor.field[0]; *g = gcolor.field[1]; *b = gcolor.field[2];
}
- (void) DPSsetalpha: (float)a
{
[self notImplemented: _cmd];
fillColor.field[AINDEX] = strokeColor.field[AINDEX] = a;
/* Is this necessary?
[self setColor: fillColor state: COLOR_FILL];
[self setColor: strokeColor state: COLOR_STROKE];
*/
}
- (void) DPSsetcmykcolor: (float)c : (float)m : (float)y : (float)k
{
[self notImplemented: _cmd];
[self setColor: gsMakeColor(cmyk_colorspace, c, m, y, k) state: COLOR_BOTH];
}
- (void) DPSsetgray: (float)gray
{
[self notImplemented: _cmd];
[self setColor: gsMakeColor(gray_colorspace, gray, 0, 0, 0) state: COLOR_BOTH];
}
- (void) DPSsethsbcolor: (float)h : (float)s : (float)b
{
[self notImplemented: _cmd];
[self setColor: gsMakeColor(hsb_colorspace, h, s, b, 0) state: COLOR_BOTH];
}
- (void) DPSsetrgbcolor: (float)r : (float)g : (float)b
{
[self notImplemented: _cmd];
[self setColor: gsMakeColor(rgb_colorspace, r, g, b, 0) state: COLOR_BOTH];
}
- (void) GSSetFillColorspace: (NSDictionary *)dict
{
[self notImplemented: _cmd];
float values[6];
NSString *colorSpace = [dict objectForKey: GSColorSpaceName];
if (fillColorS)
RELEASE(fillColorS);
memset(values, 0, sizeof(float)*6);
fillColorS = [NSColor colorWithValues: values colorSpaceName:colorSpace];
RETAIN(fillColorS);
[self setColor: gsMakeColor(rgb_colorspace, 0, 0, 0, 0) state: COLOR_FILL];
}
- (void) GSSetStrokeColorspace: (NSDictionary *)dict
{
[self notImplemented: _cmd];
float values[6];
NSString *colorSpace = [dict objectForKey: GSColorSpaceName];
if (strokeColorS)
RELEASE(strokeColorS);
memset(values, 0, sizeof(float)*6);
strokeColorS = [NSColor colorWithValues: values colorSpaceName:colorSpace];
RETAIN(strokeColorS);
[self setColor: gsMakeColor(rgb_colorspace, 0, 0, 0, 0) state: COLOR_STROKE];
}
- (void) GSSetFillColor: (float *)values
{
[self notImplemented: _cmd];
device_color_t dcolor;
NSColor *color;
NSString *colorSpace;
if (fillColorS == nil)
{
DPS_ERROR(DPSundefined, @"No fill colorspace defined, assume DeviceRGB");
colorSpace = NSDeviceRGBColorSpace;
}
else
colorSpace = [fillColorS colorSpaceName];
RELEASE(fillColorS);
fillColorS = [NSColor colorWithValues: values colorSpaceName:colorSpace];
RETAIN(fillColorS);
color = [fillColorS colorUsingColorSpaceName: NSDeviceRGBColorSpace];
[color getRed: &dcolor.field[0]
green: &dcolor.field[1]
blue: &dcolor.field[2]
alpha: &dcolor.field[AINDEX]];
[self setColor: dcolor state: COLOR_FILL];
}
- (void) GSSetStrokeColor: (float *)values
{
[self notImplemented: _cmd];
device_color_t dcolor;
NSColor *color;
NSString *colorSpace;
if (strokeColorS == nil)
{
DPS_ERROR(DPSundefined, @"No stroke colorspace defined, assume DeviceRGB");
colorSpace = NSDeviceRGBColorSpace;
}
else
colorSpace = [strokeColorS colorSpaceName];
RELEASE(strokeColorS);
strokeColorS = [NSColor colorWithValues: values colorSpaceName:colorSpace];
RETAIN(strokeColorS);
color = [strokeColorS colorUsingColorSpaceName: NSDeviceRGBColorSpace];
[color getRed: &dcolor.field[0]
green: &dcolor.field[1]
blue: &dcolor.field[2]
alpha: &dcolor.field[AINDEX]];
[self setColor: dcolor state: COLOR_STROKE];
}
/* ----------------------------------------------------------------------- */
@ -264,6 +380,62 @@
[self subclassResponsibility: _cmd];
}
- (void) GSSetCharacterSpacing: (float)extra
{
charSpacing = extra;
}
- (void) GSSetFont: (NSFont*)newFont
{
if (font == newFont)
return;
ASSIGN(font, newFont);
}
- (void) GSSetFontSize: (float)size
{
NSFont *newFont;
if (font == nil)
return;
newFont = [NSFont fontWithName: [font fontName] size: [font pointSize]];
[self GSSetFont: newFont];
}
- (NSAffineTransform *) GSGetTextCTM
{
return textCtm;
}
- (NSPoint) GSGetTextPosition
{
return [textCtm pointInMatrixSpace: NSMakePoint(0,0)];
}
- (void) GSSetTextCTM: (NSAffineTransform *)newCtm
{
ASSIGN(textCtm, newCtm);
}
- (void) GSSetTextDrawingMode: (GSTextDrawingMode)mode
{
textMode = mode;
}
- (void) GSSetTextPosition: (NSPoint)loc
{
[textCtm translateToPoint: loc];
}
- (void) GSShowText: (const char *)string : (size_t) length
{
[self subclassResponsibility: _cmd];
}
- (void) GSShowGlyphs: (const NSGlyph *)glyphs : (size_t) length
{
[self subclassResponsibility: _cmd];
}
/* ----------------------------------------------------------------------- */
/* Gstate operations */
@ -444,7 +616,8 @@
[path closePath];
}
- (void)DPScurveto: (float)x1 : (float)y1 : (float)x2 : (float)y2 : (float)x3 : (float)y3
- (void)DPScurveto: (float)x1 : (float)y1 : (float)x2 : (float)y2 : (float)x3
: (float)y3
{
NSPoint p1 = [ctm pointInMatrixSpace: NSMakePoint(x1, y1)];
NSPoint p2 = [ctm pointInMatrixSpace: NSMakePoint(x2, y2)];
@ -520,7 +693,8 @@
}
}
- (void)DPSrcurveto: (float)x1 : (float)y1 : (float)x2 : (float)y2 : (float)x3 : (float)y3
- (void)DPSrcurveto: (float)x1 : (float)y1 : (float)x2 : (float)y2 : (float)x3
: (float)y3
{
NSPoint p1 = [ctm deltaPointInMatrixSpace: NSMakePoint(x1, y1)];
NSPoint p2 = [ctm deltaPointInMatrixSpace: NSMakePoint(x2, y2)];

View file

@ -1,4 +1,4 @@
/* xrtools - Color conversion routines and other low-level X support
/* gscolors - Color conversion routines
Copyright (C) 1998 Free Software Foundation, Inc.
@ -26,12 +26,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "xlib/xrtools.h"
#include "gsc/gscolors.h"
xr_device_color_t
xrMakeColor(xr_device_colorspace_t space, float a, float b, float c, float d)
device_color_t
gsMakeColor(device_colorspace_t space, float a, float b, float c, float d)
{
xr_device_color_t color;
device_color_t color;
color.space = space;
color.field[0] = a;
color.field[1] = b;
@ -40,15 +40,15 @@ xrMakeColor(xr_device_colorspace_t space, float a, float b, float c, float d)
return color;
}
xr_device_color_t
xrGrayToRGB(xr_device_color_t color)
device_color_t
gsGrayToRGB(device_color_t color)
{
return xrMakeColor(rgb_colorspace, color.field[0], color.field[0],
return gsMakeColor(rgb_colorspace, color.field[0], color.field[0],
color.field[0], 0);
}
xr_device_color_t
xrHSBToRGB(xr_device_color_t color)
device_color_t
gsHSBToRGB(device_color_t color)
{
int i;
float h, s, v;
@ -60,7 +60,7 @@ xrHSBToRGB(xr_device_color_t color)
v = color.field[2];
if (s == 0)
return xrMakeColor(rgb_colorspace, v, v, v, 0);
return gsMakeColor(rgb_colorspace, v, v, v, 0);
h = h * 6;
i = (int)h;
@ -102,12 +102,12 @@ xrHSBToRGB(xr_device_color_t color)
blue = q;
break;
}
return xrMakeColor(rgb_colorspace, red, green, blue, 0);
return gsMakeColor(rgb_colorspace, red, green, blue, 0);
}
/* FIXME */
xr_device_color_t
xrCMYKToRGB(xr_device_color_t color)
device_color_t
gsCMYKToRGB(device_color_t color)
{
float c, m, y, k;
float red, green, blue;
@ -137,27 +137,27 @@ xrCMYKToRGB(xr_device_color_t color)
green = (m > white ? 0 : white - m);
blue = (y > white ? 0 : white - y);
}
return xrMakeColor(rgb_colorspace, red, green, blue, 0);
return gsMakeColor(rgb_colorspace, red, green, blue, 0);
}
xr_device_color_t
xrColorToRGB(xr_device_color_t color)
device_color_t
gsColorToRGB(device_color_t color)
{
xr_device_color_t new;
device_color_t new;
switch(color.space)
{
case gray_colorspace:
new = xrGrayToRGB(color);
new = gsGrayToRGB(color);
break;
case rgb_colorspace:
new = color;
break;
case hsb_colorspace:
new = xrHSBToRGB(color);
new = gsHSBToRGB(color);
break;
case cmyk_colorspace:
new = xrCMYKToRGB(color);
new = gsCMYKToRGB(color);
break;
default:
break;
@ -165,10 +165,10 @@ xrColorToRGB(xr_device_color_t color)
return new;
}
xr_device_color_t
xrColorToGray(xr_device_color_t color)
device_color_t
gsColorToGray(device_color_t color)
{
xr_device_color_t new;
device_color_t new;
new.space = gray_colorspace;
switch(color.space)
@ -178,7 +178,7 @@ xrColorToGray(xr_device_color_t color)
break;
case hsb_colorspace:
case cmyk_colorspace:
color = xrColorToRGB(color);
color = gsColorToRGB(color);
/* NO BREAK */
case rgb_colorspace:
new.field[0] =
@ -191,10 +191,10 @@ xrColorToGray(xr_device_color_t color)
}
/* FIXME: Not implemented */
xr_device_color_t
xrColorToCMYK(xr_device_color_t color)
device_color_t
gsColorToCMYK(device_color_t color)
{
xr_device_color_t new;
device_color_t new;
new.space = cmyk_colorspace;
switch(color.space)
@ -215,10 +215,10 @@ xrColorToCMYK(xr_device_color_t color)
}
/* FIXME: Not implemented */
xr_device_color_t
xrColorToHSB(xr_device_color_t color)
device_color_t
gsColorToHSB(device_color_t color)
{
xr_device_color_t new;
device_color_t new;
new.space = hsb_colorspace;
switch(color.space)

View file

@ -106,6 +106,16 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
return window;
}
- (void) setColor: (device_color_t)color state: (color_state_t)cState
{
[super setColor: color state: cState];
color = gsColorToRGB(color);
if (cState & COLOR_FILL)
wfcolor = RGB(color.field[0]*255, color.field[1]*255, color.field[2]*255);
if (cState & COLOR_STOKE)
wscolor = RGB(color.field[0]*255, color.field[1]*255, color.field[2]*255);
}
- (void) copyBits: (WIN32GState*)source fromRect: (NSRect)aRect
toPoint: (NSPoint)aPoint
{
@ -302,119 +312,6 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
@end
@implementation WIN32GState (ColorOps)
- (void)DPScurrentrgbcolor: (float *)r : (float *)g : (float *)b
{
*r = GetRValue(color) / 255;
*g = GetGValue(color) / 255;
*b = GetBValue(color) / 255;
}
- (void)DPSsetrgbcolor: (float)r : (float)g : (float)b
{
color = RGB(r*255, g*255, b*255);
// Use in pen and brush!!
}
- (void)DPScurrentcmykcolor: (float *)c : (float *)m : (float *)y : (float *)k
{
float alpha;
float r, g, b;
NSColor *c1, *c2;
[self DPScurrentrgbcolor: &r : &g : &b];
c1 = [NSColor colorWithDeviceRed: r green: g
blue: b alpha: 1.0];
c2 = [c1 colorUsingColorSpaceName: NSDeviceCMYKColorSpace];
[c2 getCyan: c magenta: m
yellow: y black: k
alpha: &alpha];
}
- (void)DPSsetcmykcolor: (float)c : (float)m : (float)y : (float)k
{
NSColor *c1, *c2;
c1 = [NSColor colorWithDeviceCyan: c
magenta: m
yellow: y
black: k
alpha: 1.0];
c2 = [c1 colorUsingColorSpaceName: NSDeviceRGBColorSpace];
[self DPSsetrgbcolor: [c2 redComponent] : [c2 greenComponent] :
[c2 blueComponent]];
}
- (void)DPScurrentgray: (float *)gray
{
float r, g, b;
NSColor *c1, *c2;
[self DPScurrentrgbcolor: &r : &g : &b];
c1 = [NSColor colorWithDeviceRed: r
green: g
blue: b
alpha: 1.0];
c2 = [c1 colorUsingColorSpaceName: NSDeviceWhiteColorSpace];
// Or 1.0 - x ???
*gray = [c2 whiteComponent];
}
- (void)DPSsetgray: (float)gray
{
NSColor *c1, *c2;
// Or 1.0 - x ???
c1 = [NSColor colorWithDeviceWhite: gray
alpha: 1.0];
c2 = [c1 colorUsingColorSpaceName: NSDeviceRGBColorSpace];
[self DPSsetrgbcolor: [c2 redComponent] : [c2 greenComponent] :
[c2 blueComponent]];
}
- (void)DPScurrenthsbcolor: (float *)h : (float *)s : (float *)b
{
float alpha;
float r, g, bl;
NSColor *c1;
[self DPScurrentrgbcolor: &r : &g : &bl];
c1 = [NSColor colorWithDeviceRed: r
green: g
blue: bl
alpha: 1.0];
[c1 getHue: h saturation: s
brightness: b alpha: &alpha];
}
- (void)DPSsethsbcolor: (float)h : (float)s : (float)b
{
NSColor *c1, *c2;
c1 = [NSColor colorWithDeviceHue: h
saturation: s
brightness: b
alpha: 1.0];
c2 = [c1 colorUsingColorSpaceName: NSDeviceRGBColorSpace];
[self DPSsetrgbcolor: [c2 redComponent] : [c2 greenComponent] :
[c2 blueComponent]];
}
- (void) DPSsetalpha: (float)a
{
}
- (void) DPScurrentalpha: (float *)alpha
{
}
@end
@implementation WIN32GState (PathOps)
- (void) _paintPath: (ctxt_object_t) drawType
@ -645,8 +542,8 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
{
[ctm makeIdentityMatrix];
DESTROY(path);
color = RGB(0*255, 0*255, 0*255);
fillColor = gsMakeColor(gray_colorspace, 0, 0, 0, 0);
[self setColor: fillColor state: COLOR_BOTH];
}
- (void) DPSsetdash: (const float*)pattern : (int)count : (float)phase
@ -725,7 +622,7 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
br.lbColor = color;
brush = CreateBrushIndirect(&br);
*/
brush = CreateSolidBrush(color);
brush = CreateSolidBrush(wfcolor);
oldBrush = SelectObject(hdc, brush);
switch (joinStyle)
@ -784,7 +681,7 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
SetMiterLimit(hdc, miterlimit, NULL);
SetTextColor(hdc, color);
SetTextColor(hdc, wfcolor);
SelectClipRgn(hdc, clipRegion);
}

View file

@ -36,9 +36,6 @@ include ../../config.make
SUBPROJECT_NAME=xlib
# The C source files to be compiled
xlib_C_FILES = xrtools.c
# The Objective-C source files to be compiled
xlib_OBJC_FILES = \
XGBitmapImageRep.m \

View file

@ -38,6 +38,7 @@
#include <X11/Xutil.h>
#include <Foundation/NSDebug.h>
#include "gsc/gscolors.h"
#include "xlib/XGPrivate.h"
/* Macros that make it easier to convert

View file

@ -42,7 +42,6 @@
#include "xlib/XGContext.h"
#include "xlib/XGPrivate.h"
#include "xlib/XGGState.h"
#include "xlib/xrtools.h"
#ifdef HAVE_XFT
#include "xlib/XftFontInfo.h"

View file

@ -33,7 +33,6 @@
#include "xlib/XGGState.h"
#include "xlib/XGContext.h"
#include "xlib/XGPrivate.h"
#include "xlib/xrtools.h"
#include "math.h"
#define XDPY (((RContext *)context)->dpy)
@ -49,10 +48,9 @@ static BOOL shouldDrawAlpha = YES;
if (sharedGC == YES) \
[self copyGraphicContext]
#define AINDEX 5
u_long
xrRGBToPixel(RContext* context, xr_device_color_t color)
xrRGBToPixel(RContext* context, device_color_t color)
{
XColor cc;
RColor rcolor;
@ -69,6 +67,7 @@ xrRGBToPixel(RContext* context, xr_device_color_t color)
- (void) _paintPath: (ctxt_object_t) drawType;
- (void) createGraphicContext;
- (void) copyGraphicContext;
- (void) setAlphaColor: (float)color;
@end
@implementation XGGState
@ -106,8 +105,8 @@ static Region emptyRegion;
drawMechanism = -1;
draw = 0;
alpha_buffer = 0;
color.field[AINDEX] = 1.0;
xgcntxt = None;
agcntxt = None;
return self;
}
@ -117,6 +116,8 @@ static Region emptyRegion;
{
XFreeGC(XDPY, xgcntxt);
}
if (agcntxt)
XFreeGC(XDPY, agcntxt);
if (clipregion)
XDestroyRegion(clipregion);
[super dealloc];
@ -130,6 +131,9 @@ static Region emptyRegion;
if (draw != 0)
[self copyGraphicContext];
/* Force a new one to be created */
agcntxt = None;
// Copy the clipregion
if (clipregion)
{
@ -235,19 +239,33 @@ static Region emptyRegion;
return region;
}
- (void) setColor: (xr_device_color_t)acolor;
- (void) setColor: (device_color_t)color state: (color_state_t)cState
{
float alpha = color.field[AINDEX];
color = acolor;
acolor = xrColorToRGB(acolor);
[super setColor: color state: cState];
if (context == NULL)
{
/* Window device isn't set yet */
return;
}
gcv.foreground = xrRGBToPixel(context, acolor);
color = gsColorToRGB(color);
gcv.foreground = xrRGBToPixel(context, color);
[self setGCValues: gcv withMask: GCForeground];
color.field[AINDEX] = alpha;
}
- (void) setAlphaColor: (float)value
{
device_color_t color;
if (context == NULL)
{
/* Window device isn't set yet */
return;
}
color = gsMakeColor(gray_colorspace, value, 0, 0, 0);
gcv.foreground = xrRGBToPixel(context, color);
if (agcntxt == None)
agcntxt = XCreateGC(XDPY, draw, GCForeground, &gcv);
else
XChangeGC(XDPY, agcntxt, GCForeground, &gcv);
}
- (void) setFont: (NSFont*)newFont
@ -387,18 +405,15 @@ static Region emptyRegion;
if (dest_win->alpha_buffer == 0
&& dest_win->type != NSBackingStoreNonretained)
{
xr_device_color_t old_color;
dest_win->alpha_buffer = XCreatePixmap(XDPY, draw,
NSWidth(dest_win->xframe),
NSHeight(dest_win->xframe),
dest_win->depth);
/* Fill alpha also (opaque by default) */
old_color = color;
[self DPSsetgray: 1];
XFillRectangle(XDPY, dest_win->alpha_buffer, xgcntxt, 0, 0,
[self setAlphaColor: 1];
XFillRectangle(XDPY, dest_win->alpha_buffer, agcntxt, 0, 0,
NSWidth(dest_win->xframe), NSHeight(dest_win->xframe));
[self setColor: old_color];
}
if (shouldDrawAlpha && dest_win->alpha_buffer != 0)
{
@ -826,17 +841,14 @@ static Region emptyRegion;
{
case path_stroke:
// Hack: Only draw when alpha is not zero
if (drawingAlpha == NO || color.field[AINDEX] != 0.0)
if (drawingAlpha == NO || strokeColor.field[AINDEX] != 0.0)
XDrawLines(XDPY, draw, xgcntxt, pts, count, CoordModeOrigin);
if (drawingAlpha)
{
xr_device_color_t old_color;
NSAssert(alpha_buffer, NSInternalInconsistencyException);
old_color = color;
[self DPSsetgray: color.field[AINDEX]];
XDrawLines(XDPY, alpha_buffer, xgcntxt, pts, count, CoordModeOrigin);
[self setColor: old_color];
[self setAlphaColor: strokeColor.field[AINDEX]];
XDrawLines(XDPY, alpha_buffer, agcntxt, pts, count, CoordModeOrigin);
}
break;
case path_eofill:
@ -845,19 +857,16 @@ static Region emptyRegion;
/* NO BREAK */
case path_fill:
// Hack: Only draw when alpha is not zero
if (drawingAlpha == NO || color.field[AINDEX] != 0.0)
if (drawingAlpha == NO || fillColor.field[AINDEX] != 0.0)
XFillPolygon(XDPY, draw, xgcntxt, pts, count, Complex,
CoordModeOrigin);
if (drawingAlpha)
{
xr_device_color_t old_color;
NSAssert(alpha_buffer, NSInternalInconsistencyException);
old_color = color;
[self DPSsetgray: color.field[AINDEX]];
XFillPolygon(XDPY, alpha_buffer, xgcntxt, pts, count, Complex,
[self setAlphaColor: fillColor.field[AINDEX]];
XFillPolygon(XDPY, alpha_buffer, agcntxt, pts, count, Complex,
CoordModeOrigin);
[self setColor: old_color];
}
if (gcv.fill_rule == EvenOddRule)
@ -1001,17 +1010,14 @@ static Region emptyRegion;
}
// Hack: Only draw when alpha is not zero
if (drawingAlpha == NO || color.field[AINDEX] != 0.0)
if (drawingAlpha == NO || fillColor.field[AINDEX] != 0.0)
XDrawSegments (XDPY, draw, xgcntxt, segments, nseg);
if (drawingAlpha)
{
xr_device_color_t old_color;
NSAssert (alpha_buffer, NSInternalInconsistencyException);
old_color = color;
[self DPSsetgray: color.field[AINDEX]];
XDrawSegments (XDPY, alpha_buffer, xgcntxt, segments, nseg);
[self setColor: old_color];
[self setAlphaColor: fillColor.field[AINDEX]];
XDrawSegments (XDPY, alpha_buffer, agcntxt, segments, nseg);
}
nseg = 0;
} // for y
@ -1176,85 +1182,17 @@ static Region emptyRegion;
@implementation XGGState (Ops)
- (void) DPScurrentalpha: (float *)alpha
{
if (alpha)
*alpha = color.field[AINDEX];
}
- (void)DPScurrentcmykcolor: (float *)c : (float *)m : (float *)y : (float *)k
{
xr_device_color_t new = color;
new = xrColorToCMYK(new);
*c = new.field[0];
*m = new.field[1];
*y = new.field[2];
*k = new.field[3];
}
- (void)DPSsetcmykcolor: (float)c : (float)m : (float)y : (float)k
{
color.space = cmyk_colorspace;
color.field[0] = c;
color.field[1] = m;
color.field[2] = y;
color.field[3] = k;
[self setColor:color];
}
- (void)DPScurrentgray: (float *)gray
{
xr_device_color_t gcolor;
gcolor = xrColorToGray(color);
*gray = gcolor.field[0];
}
- (void)DPScurrenthsbcolor: (float *)h : (float *)s : (float *)b
{
xr_device_color_t gcolor;
gcolor = xrColorToHSB(color);
*h = gcolor.field[0]; *s = gcolor.field[1]; *b = gcolor.field[2];
}
- (void)DPScurrentrgbcolor: (float *)r : (float *)g : (float *)b
{
xr_device_color_t gcolor;
gcolor = xrColorToRGB(color);
*r = gcolor.field[0]; *g = gcolor.field[1]; *b = gcolor.field[2];
}
- (void) DPSsetalpha: (float)a
{
gswindow_device_t *gs_win;
color.field[AINDEX] = a;
[super DPSsetalpha: a];
gs_win = (gswindow_device_t *)windevice;
if (!gs_win)
return;
if (a < 1.0)
if (fillColor.field[AINDEX] < 1.0)
[self _alphaBuffer: gs_win];
}
- (void)DPSsetgray: (float)gray
{
color.space = gray_colorspace;
color.field[0] = gray;
[self setColor: color];
}
- (void)DPSsethsbcolor: (float)h : (float)s : (float)b
{
color.space = hsb_colorspace;
color.field[0] = h; color.field[1] = s; color.field[2] = b;
[self setColor: color];
}
- (void)DPSsetrgbcolor: (float)r : (float)g : (float)b
{
color.space = rgb_colorspace;
color.field[0] = r; color.field[1] = g; color.field[2] = b;
[self setColor: color];
}
/* ----------------------------------------------------------------------- */
/* Text operations */
/* ----------------------------------------------------------------------- */
@ -1292,6 +1230,9 @@ typedef enum {
return;
}
if ((cstate & COLOR_FILL) == 0)
[self setColor: fillColor state: COLOR_FILL];
/* Use only delta transformations (no offset) */
len = strlen(s);
scale = [ctm sizeInMatrixSpace: NSMakeSize(1,1)];
@ -1305,22 +1246,19 @@ typedef enum {
xp = XGWindowPointToX(self, point);
width = [font_info widthOf: s+i lenght: 1];
// Hack: Only draw when alpha is not zero
if (drawingAlpha == NO || color.field[AINDEX] != 0.0)
if (drawingAlpha == NO || fillColor.field[AINDEX] != 0.0)
[font_info draw: s+i lenght: 1
onDisplay: XDPY drawable: draw
with: xgcntxt at: xp];
if (drawingAlpha)
{
xr_device_color_t old_color;
NSAssert(alpha_buffer, NSInternalInconsistencyException);
old_color = color;
[self DPSsetgray: color.field[AINDEX]];
[self setAlphaColor: fillColor.field[AINDEX]];
[font_info draw: s+i lenght: 1
onDisplay: XDPY drawable: alpha_buffer
with: xgcntxt at: xp];
[self setColor: old_color];
with: agcntxt at: xp];
}
/* Note we update the current point according to the current
transformation scaling, although the text isn't currently
@ -1401,28 +1339,27 @@ typedef enum {
DPS_WARN(DPSinvalidid, @"No Drawable defined for show");
return;
}
if ((cstate & COLOR_FILL) == 0)
[self setColor: fillColor state: COLOR_FILL];
len = strlen(s);
width = [font_info widthOf: s lenght: len];
xp = XGWindowPointToX(self, [path currentPoint]);
// Hack: Only draw when alpha is not zero
if (drawingAlpha == NO || color.field[AINDEX] != 0.0)
if (drawingAlpha == NO || fillColor.field[AINDEX] != 0.0)
[font_info draw: s lenght: len
onDisplay: XDPY drawable: draw
with: xgcntxt at: xp];
if (drawingAlpha)
{
xr_device_color_t old_color;
NSAssert(alpha_buffer, NSInternalInconsistencyException);
old_color = color;
[self DPSsetgray: color.field[AINDEX]];
[self setAlphaColor: fillColor.field[AINDEX]];
[font_info draw: s lenght: len
onDisplay: XDPY drawable: alpha_buffer
with: xgcntxt at: xp];
[self setColor: old_color];
with: agcntxt at: xp];
}
/* Note we update the current point according to the current
transformation scaling, although the text isn't currently
@ -1489,10 +1426,10 @@ typedef enum {
XDestroyRegion(clipregion);
clipregion = 0;
/* FIXME: reset the GC */
color.space = gray_colorspace;
color.field[0] = 0.0;
[self setColor: color];
color.field[AINDEX] = 1.0;
fillColor = gsMakeColor(gray_colorspace, 0, 0, 0, 0);
[self setColor: fillColor state: COLOR_BOTH];
fillColor.field[AINDEX] = 1.0;
strokeColor.field[AINDEX] = 1.0;
}
- (void)DPSsetdash: (const float *)pat : (int)size : (float)pat_offset
@ -1571,11 +1508,17 @@ typedef enum {
- (void)DPSeofill
{
if ((cstate & COLOR_FILL) == 0)
[self setColor: fillColor state: COLOR_FILL];
[self _paintPath: path_eofill];
}
- (void)DPSfill
{
if ((cstate & COLOR_FILL) == 0)
[self setColor: fillColor state: COLOR_FILL];
[self _paintPath: path_fill];
}
@ -1622,23 +1565,23 @@ typedef enum {
return;
}
if ((cstate & COLOR_FILL) == 0)
[self setColor: fillColor state: COLOR_FILL];
bounds = XGViewRectToX(self, NSMakeRect(x, y, w, h));
// Hack: Only draw when alpha is not zero
if (drawingAlpha == NO || color.field[AINDEX] != 0.0)
if (drawingAlpha == NO || fillColor.field[AINDEX] != 0.0)
XFillRectangle(XDPY, draw, xgcntxt,
bounds.x, bounds.y, bounds.width, bounds.height);
if (drawingAlpha)
{
/* Fill alpha also */
xr_device_color_t old_color;
NSAssert(alpha_buffer, NSInternalInconsistencyException);
old_color = color;
[self DPSsetgray: color.field[AINDEX]];
XFillRectangle(XDPY, alpha_buffer, xgcntxt,
[self setAlphaColor: fillColor.field[AINDEX]];
XFillRectangle(XDPY, alpha_buffer, agcntxt,
bounds.x, bounds.y, bounds.width, bounds.height);
[self setColor: old_color];
}
}
@ -1653,32 +1596,35 @@ typedef enum {
return;
}
if ((cstate & COLOR_STROKE) == 0)
[self setColor: fillColor state: COLOR_STROKE];
bounds = XGViewRectToX(self, NSMakeRect(x, y, w, h));
if (bounds.width > 0)
bounds.width--;
if (bounds.height > 0)
bounds.height--;
// Hack: Only draw when alpha is not zero
if (drawingAlpha == NO || color.field[AINDEX] != 0.0)
if (drawingAlpha == NO || strokeColor.field[AINDEX] != 0.0)
XDrawRectangle(XDPY, draw, xgcntxt,
bounds.x, bounds.y, bounds.width, bounds.height);
if (drawingAlpha)
{
/* Fill alpha also */
xr_device_color_t old_color;
NSAssert(alpha_buffer, NSInternalInconsistencyException);
old_color = color;
[self DPSsetgray: color.field[AINDEX]];
XDrawRectangle(XDPY, alpha_buffer, xgcntxt,
[self setAlphaColor: strokeColor.field[AINDEX]];
XDrawRectangle(XDPY, alpha_buffer, agcntxt,
bounds.x, bounds.y, bounds.width, bounds.height);
[self setColor: old_color];
}
}
- (void)DPSstroke
{
if ((cstate & COLOR_STROKE) == 0)
[self setColor: fillColor state: COLOR_STROKE];
[self _paintPath: path_stroke];
}