Skip to content

Commit

Permalink
* Source/opal/OpalGState.m: Add colour handling for all the different
Browse files Browse the repository at this point in the history
colour spaces.
  • Loading branch information
fredkiefer committed Jan 3, 2019
1 parent 059f42a commit fd84d37
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 48 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2019-01-04 Fred Kiefer <[email protected]>

* Source/opal/OpalGState.m: Add colour handling for all the
different colour spaces.

2018-12-31 Pavel Shlyak <[email protected]>

* Source/x11/convert.c: Don't leak memory on error handling
Expand Down
106 changes: 58 additions & 48 deletions Source/opal/OpalGState.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ static inline NSPoint _NSPointFromCGPoint(CGPoint cgpoint)

@implementation OpalGState

- (void) dealloc
{
RELEASE(_opalSurface);
RELEASE(_opGState);
[super dealloc];
}

- (id)copyWithZone: (NSZone *)zone
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
Expand Down Expand Up @@ -82,64 +89,63 @@ - (void) setOffset: (NSPoint)theOffset
[super setOffset: theOffset];
}

@end

@implementation OpalGState (Ops)

- (void) DPSsetalpha: (CGFloat)a
- (void) setColor: (device_color_t *)color state: (color_state_t)cState
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s - alpha %g", self, [self class], __PRETTY_FUNCTION__, a);
CGContextRef cgctx = CGCTX;

if (cgctx)
{
CGContextSetAlpha(cgctx, a);
}
[super DPSsetalpha: a];
}

- (void) DPSsetgray: (CGFloat)gray
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
CGContextRef cgctx = CGCTX;

const CGFloat alpha = 1.0; // TODO: is this correct?
if (cgctx)
{
CGContextSetGrayStrokeColor(cgctx, gray, alpha);
CGContextSetGrayFillColor(cgctx, gray, alpha);
}
[super DPSsetgray: gray];
}

- (void) DPSsetrgbcolor: (CGFloat)r : (CGFloat)g : (CGFloat)b
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
CGContextRef cgctx = CGCTX;
if (color->space == hsb_colorspace)
{
gsColorToRGB(color);
}

const CGFloat alpha = 1.0; // TODO: is this correct?
if (cgctx)
{
CGContextSetRGBStrokeColor(cgctx, r, g, b, alpha);
CGContextSetRGBFillColor(cgctx, r, g, b, alpha);
if (color->space == gray_colorspace)
{
if (cState & COLOR_STROKE)
{
CGContextSetGrayStrokeColor(cgctx, color->field[0], color->field[AINDEX]);
}
if (cState & COLOR_FILL)
{
CGContextSetGrayFillColor(cgctx, color->field[0], color->field[AINDEX]);
}
}
else if (color->space == rgb_colorspace)
{
if (cState & COLOR_STROKE)
{
CGContextSetRGBStrokeColor(cgctx, color->field[0], color->field[1],
color->field[2], color->field[AINDEX]);
}
if (cState & COLOR_FILL)
{
CGContextSetRGBFillColor(cgctx, color->field[0], color->field[1],
color->field[2], color->field[AINDEX]);
}
}
else if (color->space == cmyk_colorspace)
{
if (cState & COLOR_STROKE)
{
CGContextSetCMYKStrokeColor(cgctx, color->field[0], color->field[1],
color->field[2], color->field[3], color->field[AINDEX]);
}
if (cState & COLOR_FILL)
{
CGContextSetCMYKFillColor(cgctx, color->field[0], color->field[1],
color->field[2], color->field[3], color->field[AINDEX]);
}
}
}
[super DPSsetrgbcolor: r : g : b];
[super setColor: color state: cState];
}

- (void) DPSsetcmykcolor: (CGFloat)c : (CGFloat)m : (CGFloat)y : (CGFloat)k
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
CGContextRef cgctx = CGCTX;

const CGFloat alpha = 1.0; // TODO: is this correct?
if (cgctx)
{
CGContextSetCMYKFillColor(cgctx, c, m, y, k, alpha);
CGContextSetCMYKStrokeColor(cgctx, c, m, y, k, alpha);
}
[super DPSsetcmykcolor: c : m : y : k];
}
@end

@implementation OpalGState (Ops)

- (void) DPSshow: (const char *)s
{
Expand Down Expand Up @@ -1081,16 +1087,20 @@ @implementation OpalGState (PatternColor)
- (void *) saveClip
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
CGRect * r = calloc(sizeof(CGRect), 1);
CGRect *r = calloc(sizeof(CGRect), 1);
*r = CGContextGetClipBoundingBox(CGCTX);
return r;
}

- (void) restoreClip: (void *)savedClip
{
CGRect *r = (CGRect *)savedClip;
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
OPContextResetClip(CGCTX);
CGContextClipToRect(CGCTX, *(CGRect *)savedClip);
if (!CGRectIsNull(*r))
{
CGContextClipToRect(CGCTX, *r);
}
free(savedClip);
}

Expand Down

0 comments on commit fd84d37

Please sign in to comment.