Initial work on trying to move responsibility for GState to Opal.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/branches/gstateless-opal@36943 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Ivan Vučica 2013-08-04 14:46:55 +00:00
parent 9d76857b5a
commit 12ad85addf
7 changed files with 304 additions and 114 deletions

View file

@ -1,3 +1,24 @@
2013-08-04 Ivan Vucica <ivan@vucica.net>
* Source/opal/GNUmakefile:
* Source/opal/OpalContext+Drawing.m:
* Headers/opal/OpalContext+Drawing.h:
* Source/opal/OpalGState.m:
* Headers/opal/OpalGState.h:
Moved core from separate class OpalGState to class category
OpalContext(Drawing).
Added NULL_CGCTX_CHECK().
Implementing -DPScompositerect::::: in place of -compositerect:op:.
Copied a few methods from GSContext into DrawingGSCReplicas class.
* Source/opal/OpalContext.m:
* Headers/opal/OpalContext.h:
OpalContext now subclasses NSGraphicsContext and not GSContext.
ADded relevant initialization methods.
* Headers/opal/OpalSurface.h:
Fixed a warning.
2013-08-02 Ivan Vucica <ivan@vucica.net>
* Source/opal/OpalContext.m:

View file

@ -1,5 +1,5 @@
/*
OpalGState.h
OpalContext+Drawing.h
Copyright (C) 2013 Free Software Foundation, Inc.
@ -25,17 +25,11 @@
Boston, MA 02110-1301, USA.
*/
#import "gsc/GSGState.h"
#import "opal/OpalContext.h"
@class OpalSurface;
@interface OpalGState : GSGState
{
OpalSurface * _opalSurface;
}
@interface OpalContext(Drawing)
- (void) DPSinitclip;
- (void) DPSinitgraphics;
- (void) DPSclip;
- (void) DPSfill;
- (void) DPSimage: (NSAffineTransform *)matrix
@ -49,11 +43,13 @@
: (BOOL)hasAlpha
: (NSString *)colorSpaceName
: (const unsigned char *const[5])data;
/*
- (void) compositeGState: (OpalGState *)source
fromRect: (NSRect)srcRect
toPoint: (NSPoint)destPoint
op: (NSCompositingOperation)op
fraction: (CGFloat)delta;
*/
- (void) compositerect: (NSRect)aRect
op: (NSCompositingOperation)op;
- (void) GSSetSurface: (OpalSurface *)opalSurface
@ -61,6 +57,7 @@
: (int)y;
@end
@interface OpalGState (Accessors)
@interface OpalContext (DrawingAccessors)
- (CGContextRef) cgContext;
@end

View file

@ -30,11 +30,18 @@
#import "gsc/GSContext.h"
@interface OpalContext : GSContext
@class GSDisplayServer;
@class OpalSurface;
@interface OpalContext : NSGraphicsContext
{
GSDisplayServer * _server;
OpalSurface * _opalSurface;
int _backGStateStackHeight;
BOOL _isScreen; // TODO: probably belongs in OpalSurface
}
+ (void) initializeBackend;
+ (Class) GStateClass;
//+ (Class) GStateClass;
- (void) GSSetDevice: (void *)device
: (int)x
: (int)y;

View file

@ -39,6 +39,7 @@
- (struct _gswindow_device_t *) device;
- (CGContextRef) cgContext;
- (void) createCGContexts;
- (BOOL) isDrawingToScreen;
@end
@interface OpalSurface (DebugExtensions)

View file

@ -31,8 +31,8 @@ SUBPROJECT_NAME=opal
# The Objective-C source files to be compiled
opal_OBJC_FILES = OpalSurface.m \
OpalFontInfo.m \
OpalGState.m \
OpalContext.m \
OpalContext+Drawing.m \
OpalFontEnumerator.m \
OpalFaceInfo.m \
OpalPSSurface.m \

View file

@ -1,5 +1,5 @@
/*
OpalGState.m
OpalContext+Drawing.m
Copyright (C) 2013 Free Software Foundation, Inc.
@ -28,35 +28,47 @@
#import <CoreGraphics/CoreGraphics.h>
#import <X11/Xlib.h>
#import <AppKit/NSGraphics.h> // NS*ColorSpace
#import "opal/OpalGState.h"
#import <AppKit/NSBitmapImageRep.h> // NSBitmapImageRep
#import "opal/OpalContext+Drawing.h"
#import "opal/OpalSurface.h"
#import "x11/XGServerWindow.h"
#define CGCTX [self cgContext]
#define NULL_CGCTX_CHECK(what) \
if(![_opalSurface cgContext]) \
{ \
NSLog(@"%p: No CG context while in %s", self, __PRETTY_FUNCTION__); \
return what; \
}
@implementation OpalGState
@implementation OpalContext(Drawing)
// MARK: Minimum required methods
// MARK: -
- (void) DPSinitclip
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NULL_CGCTX_CHECK();
OPContextResetClip(CGCTX);
}
- (void) DPSclip
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NULL_CGCTX_CHECK();
CGContextClip(CGCTX);
}
- (void) DPSfill
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NULL_CGCTX_CHECK();
CGContextFillPath(CGCTX);
}
@ -73,8 +85,9 @@
: (NSString *)colorSpaceName
: (const unsigned char *const[5])data
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NULL_CGCTX_CHECK();
// This depends on CGAffineTransform and NSAffineTransformStruct having
// the same in-memory layout.
// Here's an elementary check if that is true.
@ -144,14 +157,14 @@ NSLog(@" : samplesperpixel = %d", samplesPerPixel);
CGImageRelease(img);
CGContextRestoreGState(CGCTX);
}
/*
- (void) compositeGState: (OpalGState *)source
fromRect: (NSRect)srcRect
toPoint: (NSPoint)destPoint
op: (NSCompositingOperation)op
fraction: (CGFloat)delta
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
#if 1
CGContextSaveGState(CGCTX);
CGContextSetRGBFillColor(CGCTX, 1, 1, 0, 1);
@ -171,14 +184,22 @@ NSLog(@" : samplesperpixel = %d", samplesPerPixel);
CGImageRelease(backingImage);
#endif
}
- (void) compositerect: (NSRect)aRect
op: (NSCompositingOperation)op
*/
- (void) DPScompositerect: (CGFloat)x
: (CGFloat)y
: (CGFloat)w
: (CGFloat)h
: (NSCompositingOperation)op
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s - %@", self, [self class], __PRETTY_FUNCTION__, NSStringFromRect(aRect));
NSRect aRect = NSMakeRect(x, y, w, h);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s - %@", self, [self class], __PRETTY_FUNCTION__, NSStringFromRect(aRect));
NULL_CGCTX_CHECK();
CGContextSaveGState(CGCTX);
[self DPSinitmatrix];
//[self DPSinitmatrix];
CGContextFillRect(CGCTX, CGRectMake(aRect.origin.x, [_opalSurface device]->buffer_height - aRect.origin.y,
aRect.size.width, aRect.size.height));
CGContextRestoreGState(CGCTX);
@ -188,56 +209,35 @@ NSLog(@" : samplesperpixel = %d", samplesPerPixel);
: (NSInteger)size
: (CGFloat)offset
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
// TODO: stub
}
- (void) DPSstroke
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
CGContextStrokePath(CGCTX);
}
- (void) DPSsetlinejoin: (int)linejoin
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
// TODO: stub
}
- (void) DPSsetlinecap: (int)linecap
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
// TODO: stub
}
- (void) DPSsetmiterlimit: (CGFloat)miterlimit
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
// TODO: stub
}
@end
// MARK: Initialization methods
// MARK: -
@implementation OpalGState (InitializationMethods)
/* SOME NOTES:
- GState approximates a cairo context: a drawing state.
- Surface approximates a cairo surface: a place to draw things.
- CGContext seems to be a mix of these two: surface + state.
Should we unite these two somehow? Can we unite these two somehow?
Possibly not. We still need to support bitmap contexts, pdf contexts
etc which contain both state and contents.
So, we will still need surfaces (containing CGContexts, hence including
state) and GState as a wrapper around whatever context happens to be
the current one.
*/
/**
Makes the specified surface active in the current graphics state,
@ -247,7 +247,7 @@ NSLog(@" : samplesperpixel = %d", samplesPerPixel);
: (int)x
: (int)y
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
if(_opalSurface != opalSurface)
{
@ -256,6 +256,7 @@ NSLog(@" : samplesperpixel = %d", samplesPerPixel);
[old release];
}
NSLog(@"Set surface to %p", _opalSurface);
[self setOffset: NSMakePoint(x, y)];
[self DPSinitgraphics];
}
@ -263,7 +264,7 @@ NSLog(@" : samplesperpixel = %d", samplesPerPixel);
: (int *)x
: (int *)y
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
return _opalSurface;
}
@ -272,9 +273,7 @@ NSLog(@" : samplesperpixel = %d", samplesPerPixel);
**/
- (void) DPSinitgraphics
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
[super DPSinitgraphics];
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
[_opalSurface createCGContexts];
/*
@ -291,14 +290,14 @@ NSLog(@" : samplesperpixel = %d", samplesPerPixel);
// MARK: Accessors
// MARK: -
@implementation OpalGState (Accessors)
@implementation OpalContext (DrawingAccessors)
- (CGContextRef) cgContext
{
if (!_opalSurface)
NSDebugMLLog(@"OpalGState", @"No OpalSurface");
NSDebugMLLog(@"OpalContextDrawing", @"No OpalSurface");
else if (![_opalSurface cgContext])
NSDebugMLLog(@"OpalGState", @"No OpalSurface CGContext");
NSDebugMLLog(@"OpalContextDrawing", @"No OpalSurface CGContext");
return [_opalSurface cgContext];
}
@ -307,11 +306,11 @@ NSLog(@" : samplesperpixel = %d", samplesPerPixel);
// MARK: Non-required methods
// MARK: -
static CGFloat theAlpha = 1.; // TODO: removeme
@implementation OpalGState (NonrequiredMethods)
@implementation OpalContext (DrawingNonrequiredMethods)
- (void) DPSsetrgbcolor: (CGFloat)r : (CGFloat)g : (CGFloat)b
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
const CGFloat alpha = 1; // TODO: is this correct?
if(!CGCTX)
@ -321,34 +320,44 @@ static CGFloat theAlpha = 1.; // TODO: removeme
}
- (void) DPSrectfill: (CGFloat)x : (CGFloat)y : (CGFloat)w : (CGFloat)h
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s - rect %g %g %g %g", self, [self class], __PRETTY_FUNCTION__, x, y, w, h);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s - rect %g %g %g %g", self, [self class], __PRETTY_FUNCTION__, x, y, w, h);
NULL_CGCTX_CHECK();
CGContextFillRect(CGCTX, CGRectMake(x, y, w, h));
}
- (void) DPSrectclip: (CGFloat)x : (CGFloat)y : (CGFloat)w : (CGFloat)h
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s - %g %g %g %g", self, [self class], __PRETTY_FUNCTION__, x, y, w, h);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s - %g %g %g %g", self, [self class], __PRETTY_FUNCTION__, x, y, w, h);
NULL_CGCTX_CHECK();
[self DPSinitclip];
CGContextClipToRect(CGCTX, CGRectMake(x, y, w, h));
}
- (void) DPSsetgray: (CGFloat)gray
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NULL_CGCTX_CHECK();
const CGFloat alpha = 1; // TODO: is this correct?
CGContextSetGrayFillColor(CGCTX, gray, alpha);
}
- (void) DPSsetalpha: (CGFloat)a
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s - alpha %g", self, [self class], __PRETTY_FUNCTION__, a);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s - alpha %g", self, [self class], __PRETTY_FUNCTION__, a);
NULL_CGCTX_CHECK();
CGContextSetAlpha(CGCTX, a);
theAlpha = a;
}
- (void)DPSinitmatrix
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NULL_CGCTX_CHECK();
OPContextSetIdentityCTM(CGCTX);
#if 0
@ -356,49 +365,56 @@ static CGFloat theAlpha = 1.; // TODO: removeme
CGContextTranslateCTM(CGCTX, 0, [_opalSurface device]->buffer_height);
CGContextScaleCTM(CGCTX, 1, -1);
#endif
[super DPSinitmatrix];
}
- (void)DPSconcat: (const CGFloat *)m
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s - %g %g %g %g %g %g", self, [self class], __PRETTY_FUNCTION__, m[0], m[1], m[2], m[3], m[4], m[5]);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s - %g %g %g %g %g %g", self, [self class], __PRETTY_FUNCTION__, m[0], m[1], m[2], m[3], m[4], m[5]);
CGContextConcatCTM(CGCTX, CGAffineTransformMake(
m[0], m[1], m[2],
m[3], m[4], m[5]));
[super DPSconcat:m];
}
- (void)DPSscale: (CGFloat)x
: (CGFloat)y
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
NULL_CGCTX_CHECK();
CGContextScaleCTM(CGCTX, x, y);
}
- (void)DPStranslate: (CGFloat)x
: (CGFloat)y
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s - x %g y %g", self, [self class], __PRETTY_FUNCTION__, x, y);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s - x %g y %g", self, [self class], __PRETTY_FUNCTION__, x, y);
NULL_CGCTX_CHECK();
CGContextTranslateCTM(CGCTX, x, y);
[super DPStranslate:x:y];
}
- (void) DPSmoveto: (CGFloat) x
: (CGFloat) y
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
NULL_CGCTX_CHECK();
CGContextMoveToPoint(CGCTX, x, y);
}
- (void) DPSlineto: (CGFloat) x
: (CGFloat) y
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
NULL_CGCTX_CHECK();
CGContextAddLineToPoint(CGCTX, x, y);
}
- (void) setOffset: (NSPoint)theOffset
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, theOffset.x, theOffset.y);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, theOffset.x, theOffset.y);
NULL_CGCTX_CHECK();
#if 1
if (CGCTX != nil)
@ -427,7 +443,7 @@ static CGFloat theAlpha = 1.; // TODO: removeme
/*
- (void) setColor: (device_color_t *)color state: (color_state_t)cState
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
[super setColor: color
state: cState];
@ -447,8 +463,10 @@ static CGFloat theAlpha = 1.; // TODO: removeme
*/
- (NSAffineTransform *) GSCurrentCTM
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NULL_CGCTX_CHECK(nil);
CGAffineTransform cgCTM = CGContextGetCTM(CGCTX);
NSAffineTransform * affineTransform = [NSAffineTransform transform];
@ -465,53 +483,53 @@ static CGFloat theAlpha = 1.; // TODO: removeme
}
- (void) flushGraphics
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
CGContextFlush(CGCTX);
[_opalSurface handleExpose:CGRectMake(0, 0, 1024, 1024)];
}
- (void) DPSgsave
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
#warning Opal bug: nil ctx should 'only' print a warning instead of crashing
if (CGCTX)
CGContextSaveGState(CGCTX);
}
- (void) DPSgrestore
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
#warning Opal bug: nil ctx should 'only' print a warning instead of crashing
if (CGCTX)
CGContextRestoreGState(CGCTX);
}
- (void *) saveClip
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
CGRect * r = calloc(sizeof(CGRect), 1);
*r = CGContextGetClipBoundingBox(CGCTX);
return r;
}
- (void) restoreClip: (void *)savedClip
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
OPContextResetClip(CGCTX);
CGContextClipToRect(CGCTX, *(CGRect *)savedClip);
free(savedClip);
}
- (void) DPSeoclip
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
CGContextEOClip(CGCTX);
}
- (void) DPSeofill
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
CGContextEOFillPath(CGCTX);
}
- (void) DPSshow: (const char *)s
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
CGContextSaveGState(CGCTX);
CGContextSetRGBFillColor(CGCTX, 0, 1, 0, 1);
@ -520,7 +538,7 @@ static CGFloat theAlpha = 1.; // TODO: removeme
}
- (void) GSShowText: (const char *)s : (size_t) length
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
/*
const char * s2 = calloc(s, length+1);
strcpy(s2, s);
@ -533,7 +551,7 @@ static CGFloat theAlpha = 1.; // TODO: removeme
}
- (void) GSShowGlyphsWithAdvances: (const NSGlyph *)glyphs : (const NSSize *)advances : (size_t) length
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
CGContextSaveGState(CGCTX);
CGContextSetRGBFillColor(CGCTX, 0, 1, 0, 1);
CGContextFillRect(CGCTX, CGRectMake(0, 0, 12, length * 12));
@ -544,7 +562,7 @@ static CGFloat theAlpha = 1.; // TODO: removeme
- (void) DPSrlineto: (CGFloat) x
: (CGFloat) y
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
CGContextAddRelativeLine(CGCTX, x, y);
}
@ -554,9 +572,10 @@ static CGFloat theAlpha = 1.; // TODO: removeme
- (void) DPScurrentpoint: (CGFloat *)x
: (CGFloat *)y
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
CGPoint currentPoint = CGContextGetPathCurrentPoint(CGCTX);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, currentPoint.x, currentPoint.y);
*x = currentPoint.x;
*y = currentPoint.y;
}
@ -565,7 +584,7 @@ static CGFloat theAlpha = 1.; // TODO: removeme
// MARK: Non-required unimplemented methods
// MARK: -
@implementation OpalGState (NonrequiredUnimplementedMethods)
@implementation OpalContext (DrawingNonrequiredUnimplementedMethods)
/*
Methods that follow have not been implemented.
@ -579,17 +598,17 @@ static CGFloat theAlpha = 1.; // TODO: removeme
- (void) DPSsetlinewidth: (CGFloat) width
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
}
- (void) DPSsetgstate: (NSInteger) gst
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
abort();
NSDebugLLog(@"OpalContextDrawing", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSLog(@"Warning: application tried to set gstate directly");
}
@end
@implementation OpalGState (Unused)
@implementation OpalContext (DrawingUnused)
- (void) _setPath
{
@ -633,3 +652,80 @@ static CGFloat theAlpha = 1.; // TODO: removeme
@end
@implementation OpalContext (DrawingGSCReplicas)
- (void) GSDrawImage: (NSRect) rect : (void *) imageref
{
NSBitmapImageRep *bitmap;
unsigned char *data[5];
bitmap = (NSBitmapImageRep*)imageref;
if (![self isCompatibleBitmap: bitmap])
{
NSInteger bitsPerSample = 8;
BOOL isPlanar = NO;
NSInteger samplesPerPixel = [bitmap hasAlpha] ? 4 : 3;
NSString *colorSpaceName = NSCalibratedRGBColorSpace;
NSBitmapImageRep *new;
new = [bitmap _convertToFormatBitsPerSample: bitsPerSample
samplesPerPixel: samplesPerPixel
hasAlpha: [bitmap hasAlpha]
isPlanar: isPlanar
colorSpaceName: colorSpaceName
bitmapFormat: 0
bytesPerRow: 0
bitsPerPixel: 0];
if (new == nil)
{
NSLog(@"Could not convert bitmap data");
return;
}
bitmap = new;
}
[bitmap getBitmapDataPlanes: data];
[self NSDrawBitmap: rect : [bitmap pixelsWide] : [bitmap pixelsHigh]
: [bitmap bitsPerSample] : [bitmap samplesPerPixel]
: [bitmap bitsPerPixel] : [bitmap bytesPerRow] : [bitmap isPlanar]
: [bitmap hasAlpha] : [bitmap colorSpaceName]
: (const unsigned char**)data];
}
- (void) NSDrawBitmap: (NSRect) rect : (NSInteger) pixelsWide : (NSInteger) pixelsHigh
: (NSInteger) bitsPerSample : (NSInteger) samplesPerPixel
: (NSInteger) bitsPerPixel : (NSInteger) bytesPerRow : (BOOL) isPlanar
: (BOOL) hasAlpha : (NSString *) colorSpaceName
: (const unsigned char *const [5]) data
{
NSAffineTransform *trans;
NSSize scale;
// Compute the transformation matrix
scale = NSMakeSize(NSWidth(rect) / pixelsWide,
NSHeight(rect) / pixelsHigh);
trans = [NSAffineTransform transform];
[trans translateToPoint: rect.origin];
[trans scaleXBy: scale.width yBy: scale.height];
/* This does essentially what the DPS...image operators do, so
as to avoid an extra method call */
[self DPSimage: trans
: pixelsWide : pixelsHigh
: bitsPerSample : samplesPerPixel
: bitsPerPixel : bytesPerRow
: isPlanar
: hasAlpha : colorSpaceName
: data];
}
- (BOOL) isCompatibleBitmap: (NSBitmapImageRep*)bitmap
{
return ([bitmap bitmapFormat] == 0);
}
- (void) GSSetCTM: (NSAffineTransform *)ctm
{
/* TODO: unimplemented */
}
@end

View file

@ -29,29 +29,78 @@
#import "opal/OpalFontInfo.h"
#import "opal/OpalFontEnumerator.h"
#import "opal/OpalSurface.h"
#import "opal/OpalGState.h"
#import "gsc/GSStreamContext.h"
#define OGSTATE ((OpalGState *)gstate)
#define OGSTATE self //((OpalGState *)gstate)
@implementation OpalContext
+ (void) initializeBackend
{
NSDebugLLog(@"OpalContext", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
[NSGraphicsContext setDefaultContextClass: self];
[GSFontEnumerator setDefaultClass: [OpalFontEnumerator class]];
[GSFontInfo setDefaultClass: [OpalFontInfo class]];
}
+ (Class) GStateClass
- (id) initWithContextInfo: (NSDictionary *)info
{
return [OpalGState class];
NSDebugLLog(@"OpalContext", @"%p (%@): %s - info %@", self, [self class], __PRETTY_FUNCTION__, info);
NSString *contextType;
NSZone *z = [self zone];
contextType = [info objectForKey:
NSGraphicsContextRepresentationFormatAttributeName];
if (([object_getClass(self) handlesPS] == NO) && contextType
&& [contextType isEqual: NSGraphicsContextPSFormat])
{
/* Don't call self, since we aren't initialized */
[super dealloc];
return [[GSStreamContext allocWithZone: z] initWithContextInfo: info];
}
self = [super initWithContextInfo: info];
if (!self)
return nil;
// Special handling for window drawing
id dest;
dest = [info objectForKey: NSGraphicsContextDestinationAttributeName];
if ((dest != nil) && [dest isKindOfClass: [NSWindow class]])
{
/* A context is only associated with one server. Do not retain
the server, however */
_server = GSCurrentServer();
[_server setWindowdevice: [(NSWindow*)dest windowNumber]
forContext: self];
}
if ([[info objectForKey: NSDeviceIsScreen] boolValue])
{
_isScreen = YES;
}
// TODO: we may want to create a default OpalSurface, in case GSSetDevice is not called
[self DPSinitgraphics];
[self DPSinitclip];
return self;
}
+ (BOOL) handlesPS
{
// TODO
return NO;
}
- (void) GSSetDevice: (void *)device
: (int)x
: (int)y
{
NSDebugLLog(@"OpalContext", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
OpalSurface *surface;
surface = [[OpalSurface alloc] initWithDevice: device];
@ -65,28 +114,21 @@
- (BOOL) isDrawingToScreen
{
if (_isScreen) // TODO: should not be needed
return YES;
OpalSurface *surface = nil;
[OGSTATE GSCurrentSurface: &surface : NULL : NULL];
return [surface isDrawingToScreen];
}
- (void) DPSgsave
{
[super DPSgsave];
[OGSTATE DPSgsave];
}
- (void) DPSgrestore
{
[super DPSgrestore];
[OGSTATE DPSgrestore];
}
/**
This handles 'expose' event notifications that arrive from
X11.
*/
+ (void) handleExposeRect: (NSRect)rect forDriver: (void *)driver
{
NSDebugLLog(@"OpalContext", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
if ([(id)driver isKindOfClass: [OpalSurface class]])
{
[(OpalSurface *)driver handleExposeRect: rect];
@ -116,3 +158,29 @@
@end
@implementation OpalContext(GSCReplicas)
/* This section includes replicas of methods implemented in GSContext. */
- (NSInteger) GSDefineGState
{
/* TODO: in GSContext this inserts a new graphics state on top of a stack. */
return _backGStateStackHeight++;
}
- (void) GSUndefineGState: (NSInteger)gst
{
/* TODO: in GSContext this pops a graphics state from the stack.
Sadly, it might also pop gstate from elsewhere on the stack. */
if(_backGStateStackHeight-1 != gst)
NSLog(@"%s: trying to pop something apart from the top of the gstate stack", __PRETTY_FUNCTION__);
_backGStateStackHeight--;
}
- (void) GSReplaceGState: (NSInteger)gst
{
/* In GSContext, this allows replacing a graphics state from a stack.
We can't do this in Opal. */
NSLog(@"Warning: App or library performed a call to %s.",
__PRETTY_FUNCTION__);
if(_backGStateStackHeight-1 != gst)
NSLog(@"%s: trying to replace gstate not on top of the stack", __PRETTY_FUNCTION__);
}
@end