1 |
/* GSGState - Generic graphic state |
2 |
|
3 |
Copyright (C) 1998 Free Software Foundation, Inc. |
4 |
|
5 |
Written by: Adam Fedor <fedor@gnu.org> |
6 |
Date: Mar 2002 |
7 |
|
8 |
This file is part of the GNU Objective C User Interface Library. |
9 |
|
10 |
This library is free software; you can redistribute it and/or |
11 |
modify it under the terms of the GNU Library General Public |
12 |
License as published by the Free Software Foundation; either |
13 |
version 2 of the License, or (at your option) any later version. |
14 |
|
15 |
This library is distributed in the hope that it will be useful, |
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 |
Library General Public License for more details. |
19 |
|
20 |
You should have received a copy of the GNU Library General Public |
21 |
License along with this library; if not, write to the Free |
22 |
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. |
23 |
*/ |
24 |
|
25 |
#include "config.h" |
26 |
#include <Foundation/NSObjCRuntime.h> |
27 |
#include <AppKit/NSAffineTransform.h> |
28 |
#include <AppKit/NSBezierPath.h> |
29 |
#include <AppKit/NSColor.h> |
30 |
#include <GNUstepGUI/GSFontInfo.h> |
31 |
#include <AppKit/NSGraphics.h> |
32 |
#include "gsc/GSContext.h" |
33 |
#include "gsc/GSGState.h" |
34 |
#include "math.h" |
35 |
|
36 |
#define CHECK_PATH \ |
37 |
if (!path) \ |
38 |
{ \ |
39 |
path = [NSBezierPath new]; \ |
40 |
} |
41 |
|
42 |
/* Just temporary until we improve NSColor */ |
43 |
@interface NSColor (PrivateColor) |
44 |
+ colorWithValues: (const float *)values colorSpaceName: colorSpace; |
45 |
@end |
46 |
|
47 |
@implementation NSColor (PrivateColor) |
48 |
+ colorWithValues: (const float *)values colorSpaceName: colorSpace |
49 |
{ |
50 |
NSColor *color = nil; |
51 |
if ([colorSpace isEqual: NSDeviceWhiteColorSpace]) |
52 |
color = [NSColor colorWithDeviceWhite: values[0] alpha: values[1]]; |
53 |
else if ([colorSpace isEqual: NSDeviceRGBColorSpace]) |
54 |
color = [NSColor colorWithDeviceRed: values[0] green: values[1] |
55 |
blue: values[2] alpha: values[3]]; |
56 |
else if ([colorSpace isEqual: NSDeviceCMYKColorSpace]) |
57 |
color = [NSColor colorWithDeviceCyan: values[0] magenta: values[1] |
58 |
yellow: values[2] black: values[3] alpha: values[4]]; |
59 |
else |
60 |
DPS_ERROR(DPSundefined, @"Cannot convert colorspace"); |
61 |
return color; |
62 |
} |
63 |
@end |
64 |
|
65 |
|
66 |
|
67 |
@implementation GSGState |
68 |
|
69 |
/* Designated initializer. */ |
70 |
- initWithDrawContext: (GSContext *)drawContext |
71 |
{ |
72 |
[super init]; |
73 |
|
74 |
drawcontext = drawContext; |
75 |
offset = NSMakePoint(0, 0); |
76 |
path = nil; |
77 |
font = nil; |
78 |
fillColorS = nil; |
79 |
strokeColorS = nil; |
80 |
[self DPSinitgraphics]; |
81 |
return self; |
82 |
} |
83 |
|
84 |
- (void) dealloc |
85 |
{ |
86 |
TEST_RELEASE(font); |
87 |
TEST_RELEASE(path); |
88 |
RELEASE(ctm); |
89 |
RELEASE(textCtm); |
90 |
RELEASE(fillColorS); |
91 |
RELEASE(strokeColorS); |
92 |
[super dealloc]; |
93 |
} |
94 |
|
95 |
- (id) deepen |
96 |
{ |
97 |
NSZone *zone = GSObjCZone(self); |
98 |
|
99 |
if (path) |
100 |
self->path = [path copyWithZone: zone]; |
101 |
|
102 |
self->ctm = [ctm copyWithZone: zone]; |
103 |
self->textCtm = [textCtm copyWithZone: zone]; |
104 |
|
105 |
// Just retain the other objects |
106 |
if (font != nil) |
107 |
RETAIN(font); |
108 |
if (fillColorS != nil) |
109 |
RETAIN(fillColorS); |
110 |
if (strokeColorS != nil) |
111 |
RETAIN(strokeColorS); |
112 |
|
113 |
return self; |
114 |
} |
115 |
|
116 |
- copyWithZone: (NSZone *)zone |
117 |
{ |
118 |
GSGState *new = (GSGState *)NSCopyObject(self, 0, zone); |
119 |
/* Do a deep copy since gstates are isolated from each other */ |
120 |
return [new deepen]; |
121 |
} |
122 |
|
123 |
- (void) setOffset: (NSPoint)theOffset |
124 |
{ |
125 |
offset = theOffset; |
126 |
} |
127 |
|
128 |
- (NSPoint) offset |
129 |
{ |
130 |
return offset; |
131 |
} |
132 |
|
133 |
/** Subclasses should override this method to be notified of changes |
134 |
in the current color */ |
135 |
- (void) setColor: (device_color_t *)color state: (color_state_t)cState |
136 |
{ |
137 |
float alpha; |
138 |
alpha = fillColor.field[AINDEX]; |
139 |
if (cState & COLOR_FILL) |
140 |
fillColor = *color; |
141 |
fillColor.field[AINDEX] = alpha; |
142 |
alpha = strokeColor.field[AINDEX]; |
143 |
if (cState & COLOR_STROKE) |
144 |
strokeColor = *color; |
145 |
strokeColor.field[AINDEX] = alpha; |
146 |
cstate = cState; |
147 |
} |
148 |
|
149 |
- (void) compositeGState: (GSGState *)source |
150 |
fromRect: (NSRect)aRect |
151 |
toPoint: (NSPoint)aPoint |
152 |
op: (NSCompositingOperation)op |
153 |
{ |
154 |
[self subclassResponsibility: _cmd]; |
155 |
} |
156 |
|
157 |
- (void) dissolveGState: (GSGState *)source |
158 |
fromRect: (NSRect)aRect |
159 |
toPoint: (NSPoint)aPoint |
160 |
delta: (float)delta |
161 |
{ |
162 |
[self subclassResponsibility: _cmd]; |
163 |
} |
164 |
|
165 |
- (void) compositerect: (NSRect)aRect |
166 |
op: (NSCompositingOperation)op |
167 |
{ |
168 |
[self subclassResponsibility: _cmd]; |
169 |
} |
170 |
|
171 |
- (NSPoint) pointInMatrixSpace: (NSPoint)aPoint |
172 |
{ |
173 |
return [ctm pointInMatrixSpace: aPoint]; |
174 |
} |
175 |
|
176 |
- (NSPoint) deltaPointInMatrixSpace: (NSPoint)aPoint |
177 |
{ |
178 |
return [ctm deltaPointInMatrixSpace: aPoint]; |
179 |
} |
180 |
|
181 |
- (NSRect) rectInMatrixSpace: (NSRect)rect |
182 |
{ |
183 |
return [ctm rectInMatrixSpace: rect]; |
184 |
} |
185 |
|
186 |
@end |
187 |
|
188 |
@implementation GSGState (Ops) |
189 |
|
190 |
/* ----------------------------------------------------------------------- */ |
191 |
/* Color operations */ |
192 |
/* ----------------------------------------------------------------------- */ |
193 |
- (void) DPScurrentalpha: (float*)a |
194 |
{ |
195 |
*a = fillColor.field[AINDEX]; |
196 |
} |
197 |
|
198 |
- (void) DPScurrentcmykcolor: (float*)c : (float*)m : (float*)y : (float*)k |
199 |
{ |
200 |
device_color_t new = fillColor; |
201 |
gsColorToCMYK(&new); |
202 |
*c = new.field[0]; |
203 |
*m = new.field[1]; |
204 |
*y = new.field[2]; |
205 |
*k = new.field[3]; |
206 |
} |
207 |
|
208 |
- (void) DPScurrentgray: (float*)gray |
209 |
{ |
210 |
device_color_t gcolor = fillColor; |
211 |
gsColorToGray(&gcolor); |
212 |
*gray = gcolor.field[0]; |
213 |
} |
214 |
|
215 |
- (void) DPScurrenthsbcolor: (float*)h : (float*)s : (float*)b |
216 |
{ |
217 |
device_color_t gcolor = fillColor; |
218 |
gsColorToHSB(&gcolor); |
219 |
*h = gcolor.field[0]; *s = gcolor.field[1]; *b = gcolor.field[2]; |
220 |
} |
221 |
|
222 |
- (void) DPScurrentrgbcolor: (float*)r : (float*)g : (float*)b |
223 |
{ |
224 |
device_color_t gcolor = fillColor; |
225 |
gsColorToRGB(&gcolor); |
226 |
*r = gcolor.field[0]; *g = gcolor.field[1]; *b = gcolor.field[2]; |
227 |
} |
228 |
|
229 |
#define CLAMP(x) \ |
230 |
if (x < 0.0) x = 0.0; \ |
231 |
if (x > 1.0) x = 1.0; |
232 |
|
233 |
- (void) DPSsetalpha: (float)a |
234 |
{ |
235 |
CLAMP(a) |
236 |
fillColor.field[AINDEX] = strokeColor.field[AINDEX] = a; |
237 |
[self setColor: &fillColor state: COLOR_FILL]; |
238 |
[self setColor: &strokeColor state: COLOR_STROKE]; |
239 |
} |
240 |
|
241 |
- (void) DPSsetcmykcolor: (float)c : (float)m : (float)y : (float)k |
242 |
{ |
243 |
device_color_t col; |
244 |
CLAMP(c) |
245 |
CLAMP(m) |
246 |
CLAMP(y) |
247 |
CLAMP(k) |
248 |
gsMakeColor(&col, cmyk_colorspace, c, m, y, k); |
249 |
[self setColor: &col state: COLOR_BOTH]; |
250 |
} |
251 |
|
252 |
- (void) DPSsetgray: (float)gray |
253 |
{ |
254 |
device_color_t col; |
255 |
CLAMP(gray) |
256 |
gsMakeColor(&col, gray_colorspace, gray, 0, 0, 0); |
257 |
[self setColor: &col state: COLOR_BOTH]; |
258 |
} |
259 |
|
260 |
- (void) DPSsethsbcolor: (float)h : (float)s : (float)b |
261 |
{ |
262 |
device_color_t col; |
263 |
CLAMP(h) |
264 |
CLAMP(s) |
265 |
CLAMP(b) |
266 |
gsMakeColor(&col, hsb_colorspace, h, s, b, 0); |
267 |
[self setColor: &col state: COLOR_BOTH]; |
268 |
} |
269 |
|
270 |
- (void) DPSsetrgbcolor: (float)r : (float)g : (float)b |
271 |
{ |
272 |
device_color_t col; |
273 |
CLAMP(r) |
274 |
CLAMP(g) |
275 |
CLAMP(b) |
276 |
gsMakeColor(&col, rgb_colorspace, r, g, b, 0); |
277 |
[self setColor: &col state: COLOR_BOTH]; |
278 |
} |
279 |
|
280 |
|
281 |
- (void) GSSetFillColorspace: (void *)spaceref |
282 |
{ |
283 |
device_color_t col; |
284 |
float values[6]; |
285 |
NSDictionary *dict = (NSDictionary *)spaceref; |
286 |
NSString *colorSpace = [dict objectForKey: GSColorSpaceName]; |
287 |
if (fillColorS) |
288 |
RELEASE(fillColorS); |
289 |
memset(values, 0, sizeof(float)*6); |
290 |
fillColorS = [NSColor colorWithValues: values colorSpaceName:colorSpace]; |
291 |
RETAIN(fillColorS); |
292 |
gsMakeColor(&col, rgb_colorspace, 0, 0, 0, 0); |
293 |
[self setColor: &col state: COLOR_FILL]; |
294 |
} |
295 |
|
296 |
- (void) GSSetStrokeColorspace: (void *)spaceref |
297 |
{ |
298 |
device_color_t col; |
299 |
float values[6]; |
300 |
NSDictionary *dict = (NSDictionary *)spaceref; |
301 |
NSString *colorSpace = [dict objectForKey: GSColorSpaceName]; |
302 |
if (strokeColorS) |
303 |
RELEASE(strokeColorS); |
304 |
memset(values, 0, sizeof(float)*6); |
305 |
strokeColorS = [NSColor colorWithValues: values colorSpaceName:colorSpace]; |
306 |
RETAIN(strokeColorS); |
307 |
gsMakeColor(&col, rgb_colorspace, 0, 0, 0, 0); |
308 |
[self setColor: &col state: COLOR_STROKE]; |
309 |
} |
310 |
|
311 |
- (void) GSSetFillColor: (const float *)values |
312 |
{ |
313 |
device_color_t dcolor; |
314 |
NSColor *color; |
315 |
NSString *colorSpace; |
316 |
if (fillColorS == nil) |
317 |
{ |
318 |
DPS_ERROR(DPSundefined, @"No fill colorspace defined, assume DeviceRGB"); |
319 |
colorSpace = NSDeviceRGBColorSpace; |
320 |
} |
321 |
else |
322 |
colorSpace = [fillColorS colorSpaceName]; |
323 |
RELEASE(fillColorS); |
324 |
fillColorS = [NSColor colorWithValues: values colorSpaceName:colorSpace]; |
325 |
RETAIN(fillColorS); |
326 |
color = [fillColorS colorUsingColorSpaceName: NSDeviceRGBColorSpace]; |
327 |
[color getRed: &dcolor.field[0] |
328 |
green: &dcolor.field[1] |
329 |
blue: &dcolor.field[2] |
330 |
alpha: &dcolor.field[AINDEX]]; |
331 |
[self setColor: &dcolor state: COLOR_FILL]; |
332 |
} |
333 |
|
334 |
- (void) GSSetStrokeColor: (const float *)values |
335 |
{ |
336 |
device_color_t dcolor; |
337 |
NSColor *color; |
338 |
NSString *colorSpace; |
339 |
if (strokeColorS == nil) |
340 |
{ |
341 |
DPS_ERROR(DPSundefined, @"No stroke colorspace defined, assume DeviceRGB"); |
342 |
colorSpace = NSDeviceRGBColorSpace; |
343 |
} |
344 |
else |
345 |
colorSpace = [strokeColorS colorSpaceName]; |
346 |
RELEASE(strokeColorS); |
347 |
strokeColorS = [NSColor colorWithValues: values colorSpaceName:colorSpace]; |
348 |
RETAIN(strokeColorS); |
349 |
color = [strokeColorS colorUsingColorSpaceName: NSDeviceRGBColorSpace]; |
350 |
[color getRed: &dcolor.field[0] |
351 |
green: &dcolor.field[1] |
352 |
blue: &dcolor.field[2] |
353 |
alpha: &dcolor.field[AINDEX]]; |
354 |
[self setColor: &dcolor state: COLOR_STROKE]; |
355 |
} |
356 |
|
357 |
/* ----------------------------------------------------------------------- */ |
358 |
/* Text operations */ |
359 |
/* ----------------------------------------------------------------------- */ |
360 |
- (void) DPSashow: (float)x : (float)y : (const char*)s |
361 |
{ |
362 |
[self subclassResponsibility: _cmd]; |
363 |
} |
364 |
|
365 |
- (void) DPSawidthshow: (float)cx : (float)cy : (int)c : (float)ax : (float)ay |
366 |
: (const char*)s |
367 |
{ |
368 |
[self subclassResponsibility: _cmd]; |
369 |
} |
370 |
|
371 |
- (void) DPScharpath: (const char*)s : (int)b |
372 |
{ |
373 |
[self subclassResponsibility: _cmd]; |
374 |
} |
375 |
|
376 |
- (void) DPSshow: (const char*)s |
377 |
{ |
378 |
[self subclassResponsibility: _cmd]; |
379 |
} |
380 |
|
381 |
- (void) DPSwidthshow: (float)x : (float)y : (int)c : (const char*)s |
382 |
{ |
383 |
[self subclassResponsibility: _cmd]; |
384 |
} |
385 |
|
386 |
- (void) DPSxshow: (const char*)s : (const float*)numarray : (int)size |
387 |
{ |
388 |
[self subclassResponsibility: _cmd]; |
389 |
} |
390 |
|
391 |
- (void) DPSxyshow: (const char*)s : (const float*)numarray : (int)size |
392 |
{ |
393 |
[self subclassResponsibility: _cmd]; |
394 |
} |
395 |
|
396 |
- (void) DPSyshow: (const char*)s : (const float*)numarray : (int)size |
397 |
{ |
398 |
[self subclassResponsibility: _cmd]; |
399 |
} |
400 |
|
401 |
- (void) GSSetCharacterSpacing: (float)extra |
402 |
{ |
403 |
charSpacing = extra; |
404 |
} |
405 |
|
406 |
- (void) GSSetFont: (GSFontInfo *)fontref |
407 |
{ |
408 |
if (font == fontref) |
409 |
return; |
410 |
ASSIGN(font, fontref); |
411 |
} |
412 |
|
413 |
- (void) GSSetFontSize: (float)size |
414 |
{ |
415 |
} |
416 |
|
417 |
- (NSAffineTransform *) GSGetTextCTM |
418 |
{ |
419 |
return textCtm; |
420 |
} |
421 |
|
422 |
- (NSPoint) GSGetTextPosition |
423 |
{ |
424 |
return [textCtm pointInMatrixSpace: NSMakePoint(0,0)]; |
425 |
} |
426 |
|
427 |
- (void) GSSetTextCTM: (NSAffineTransform *)newCtm |
428 |
{ |
429 |
ASSIGN(textCtm, newCtm); |
430 |
} |
431 |
|
432 |
- (void) GSSetTextDrawingMode: (GSTextDrawingMode)mode |
433 |
{ |
434 |
textMode = mode; |
435 |
} |
436 |
|
437 |
- (void) GSSetTextPosition: (NSPoint)loc |
438 |
{ |
439 |
[textCtm translateToPoint: loc]; |
440 |
} |
441 |
|
442 |
- (void) GSShowText: (const char *)string : (size_t) length |
443 |
{ |
444 |
[self subclassResponsibility: _cmd]; |
445 |
} |
446 |
|
447 |
- (void) GSShowGlyphs: (const NSGlyph *)glyphs : (size_t) length |
448 |
{ |
449 |
[self subclassResponsibility: _cmd]; |
450 |
} |
451 |
|
452 |
|
453 |
/* ----------------------------------------------------------------------- */ |
454 |
/* Gstate operations */ |
455 |
/* ----------------------------------------------------------------------- */ |
456 |
- (void) DPSinitgraphics |
457 |
{ |
458 |
DESTROY(path); |
459 |
DESTROY(font); |
460 |
DESTROY(fillColorS); |
461 |
DESTROY(strokeColorS); |
462 |
if (ctm) |
463 |
[ctm makeIdentityMatrix]; |
464 |
else |
465 |
ctm = [[NSAffineTransform allocWithZone: GSObjCZone(self)] init]; |
466 |
|
467 |
/* Initialize colors. By default the same color is used for filling and |
468 |
stroking unless fill and/or stroke color is set explicitly */ |
469 |
gsMakeColor(&fillColor, gray_colorspace, 0, 0, 0, 0); |
470 |
fillColor.field[AINDEX] = 1.0; |
471 |
strokeColor.field[AINDEX] = 1.0; |
472 |
[self setColor: &fillColor state: COLOR_BOTH]; |
473 |
|
474 |
charSpacing = 0; |
475 |
textMode = GSTextFill; |
476 |
if (textCtm) |
477 |
[textCtm makeIdentityMatrix]; |
478 |
else |
479 |
textCtm = [[NSAffineTransform allocWithZone: GSObjCZone(self)] init]; |
480 |
} |
481 |
|
482 |
- (void)DPScurrentflat: (float *)flatness |
483 |
{ |
484 |
if (path) |
485 |
*flatness = [path flatness]; |
486 |
else |
487 |
*flatness = 1.0; |
488 |
} |
489 |
|
490 |
- (void) DPScurrentlinecap: (int*)linecap |
491 |
{ |
492 |
[self subclassResponsibility: _cmd]; |
493 |
} |
494 |
|
495 |
- (void) DPScurrentlinejoin: (int*)linejoin |
496 |
{ |
497 |
[self subclassResponsibility: _cmd]; |
498 |
} |
499 |
|
500 |
- (void) DPScurrentlinewidth: (float*)width |
501 |
{ |
502 |
[self subclassResponsibility: _cmd]; |
503 |
} |
504 |
|
505 |
- (void) DPScurrentmiterlimit: (float*)limit |
506 |
{ |
507 |
[self subclassResponsibility: _cmd]; |
508 |
} |
509 |
|
510 |
- (NSPoint) currentPoint |
511 |
{ |
512 |
NSAffineTransform *ictm; |
513 |
NSPoint user; |
514 |
|
515 |
if (path == nil) |
516 |
{ |
517 |
return NSMakePoint(0, 0); |
518 |
} |
519 |
|
520 |
// This is rather slow, but it is not used very often |
521 |
ictm = [ctm copyWithZone: GSObjCZone(self)]; |
522 |
[ictm invert]; |
523 |
user = [ictm transformPoint: [path currentPoint]]; |
524 |
RELEASE(ictm); |
525 |
return user; |
526 |
} |
527 |
|
528 |
- (void)DPScurrentpoint: (float *)x : (float *)y |
529 |
{ |
530 |
NSPoint user; |
531 |
|
532 |
user = [self currentPoint]; |
533 |
*x = user.x; |
534 |
*y = user.y; |
535 |
} |
536 |
|
537 |
- (void) DPScurrentstrokeadjust: (int*)b |
538 |
{ |
539 |
[self subclassResponsibility: _cmd]; |
540 |
} |
541 |
|
542 |
- (void) DPSsetdash: (const float*)pat : (int)size : (float)offset |
543 |
{ |
544 |
[self subclassResponsibility: _cmd]; |
545 |
} |
546 |
|
547 |
- (void)DPSsetflat: (float)flatness |
548 |
{ |
549 |
if (path) |
550 |
[path setFlatness: flatness]; |
551 |
} |
552 |
|
553 |
- (void) DPSsetlinecap: (int)linecap |
554 |
{ |
555 |
[self subclassResponsibility: _cmd]; |
556 |
} |
557 |
|
558 |
- (void) DPSsetlinejoin: (int)linejoin |
559 |
{ |
560 |
[self subclassResponsibility: _cmd]; |
561 |
} |
562 |
|
563 |
- (void) DPSsetlinewidth: (float)width |
564 |
{ |
565 |
[self subclassResponsibility: _cmd]; |
566 |
} |
567 |
|
568 |
- (void) DPSsetmiterlimit: (float)limit |
569 |
{ |
570 |
[self subclassResponsibility: _cmd]; |
571 |
} |
572 |
|
573 |
- (void) DPSsetstrokeadjust: (int)b |
574 |
{ |
575 |
[self subclassResponsibility: _cmd]; |
576 |
} |
577 |
|
578 |
/* ----------------------------------------------------------------------- */ |
579 |
/* Matrix operations */ |
580 |
/* ----------------------------------------------------------------------- */ |
581 |
- (void)DPSconcat: (const float *)m |
582 |
{ |
583 |
[ctm concatenateWithMatrix: m]; |
584 |
} |
585 |
|
586 |
- (void)DPSinitmatrix |
587 |
{ |
588 |
[ctm makeIdentityMatrix]; |
589 |
} |
590 |
|
591 |
- (void)DPSrotate: (float)angle |
592 |
{ |
593 |
[ctm rotateByDegrees: angle]; |
594 |
} |
595 |
|
596 |
- (void)DPSscale: (float)x : (float)y |
597 |
{ |
598 |
[ctm scaleXBy: x yBy: y]; |
599 |
} |
600 |
|
601 |
- (void)DPStranslate: (float)x : (float)y |
602 |
{ |
603 |
[ctm translateToPoint: NSMakePoint(x, y)]; |
604 |
} |
605 |
|
606 |
- (NSAffineTransform *) GSCurrentCTM |
607 |
{ |
608 |
return AUTORELEASE([ctm copy]); |
609 |
} |
610 |
|
611 |
- (void) GSSetCTM: (NSAffineTransform *)newctm |
612 |
{ |
613 |
ASSIGN(ctm, newctm); |
614 |
} |
615 |
|
616 |
- (void) GSConcatCTM: (NSAffineTransform *)newctm |
617 |
{ |
618 |
[ctm concatenateWith: newctm]; |
619 |
} |
620 |
|
621 |
/* ----------------------------------------------------------------------- */ |
622 |
/* Paint operations */ |
623 |
/* ----------------------------------------------------------------------- */ |
624 |
- (void) DPSarc: (float)x : (float)y : (float)r : (float)angle1 : (float)angle2 |
625 |
{ |
626 |
NSBezierPath *newPath; |
627 |
|
628 |
newPath = [[NSBezierPath alloc] init]; |
629 |
if ((path != nil) && ([path elementCount] != 0)) |
630 |
{ |
631 |
[newPath lineToPoint: [self currentPoint]]; |
632 |
} |
633 |
[newPath appendBezierPathWithArcWithCenter: NSMakePoint(x, y) |
634 |
radius: r |
635 |
startAngle: angle1 |
636 |
endAngle: angle2 |
637 |
clockwise: NO]; |
638 |
[newPath transformUsingAffineTransform: ctm]; |
639 |
CHECK_PATH; |
640 |
[path appendBezierPath: newPath]; |
641 |
RELEASE(newPath); |
642 |
} |
643 |
|
644 |
- (void) DPSarcn: (float)x : (float)y : (float)r : (float)angle1 : (float)angle2 |
645 |
{ |
646 |
NSBezierPath *newPath; |
647 |
|
648 |
newPath = [[NSBezierPath alloc] init]; |
649 |
if ((path != nil) && ([path elementCount] != 0)) |
650 |
{ |
651 |
[newPath lineToPoint: [self currentPoint]]; |
652 |
} |
653 |
[newPath appendBezierPathWithArcWithCenter: NSMakePoint(x, y) |
654 |
radius: r |
655 |
startAngle: angle1 |
656 |
endAngle: angle2 |
657 |
clockwise: YES]; |
658 |
[newPath transformUsingAffineTransform: ctm]; |
659 |
CHECK_PATH; |
660 |
[path appendBezierPath: newPath]; |
661 |
RELEASE(newPath); |
662 |
} |
663 |
|
664 |
- (void)DPSarct: (float)x1 : (float)y1 : (float)x2 : (float)y2 : (float)r |
665 |
{ |
666 |
NSBezierPath *newPath; |
667 |
|
668 |
newPath = [[NSBezierPath alloc] init]; |
669 |
if ((path != nil) && ([path elementCount] != 0)) |
670 |
{ |
671 |
[newPath lineToPoint: [self currentPoint]]; |
672 |
} |
673 |
[newPath appendBezierPathWithArcFromPoint: NSMakePoint(x1, y1) |
674 |
toPoint: NSMakePoint(x2, y2) |
675 |
radius: r]; |
676 |
[newPath transformUsingAffineTransform: ctm]; |
677 |
CHECK_PATH; |
678 |
[path appendBezierPath: newPath]; |
679 |
RELEASE(newPath); |
680 |
} |
681 |
|
682 |
- (void) DPSclip |
683 |
{ |
684 |
[self subclassResponsibility: _cmd]; |
685 |
} |
686 |
|
687 |
- (void)DPSclosepath |
688 |
{ |
689 |
CHECK_PATH; |
690 |
[path closePath]; |
691 |
} |
692 |
|
693 |
- (void)DPScurveto: (float)x1 : (float)y1 : (float)x2 : (float)y2 : (float)x3 |
694 |
: (float)y3 |
695 |
{ |
696 |
NSPoint p1 = [ctm pointInMatrixSpace: NSMakePoint(x1, y1)]; |
697 |
NSPoint p2 = [ctm pointInMatrixSpace: NSMakePoint(x2, y2)]; |
698 |
NSPoint p3 = [ctm pointInMatrixSpace: NSMakePoint(x3, y3)]; |
699 |
|
700 |
CHECK_PATH; |
701 |
[path curveToPoint: p3 controlPoint1: p1 controlPoint2: p2]; |
702 |
} |
703 |
|
704 |
- (void) DPSeoclip |
705 |
{ |
706 |
[self subclassResponsibility: _cmd]; |
707 |
} |
708 |
|
709 |
- (void) DPSeofill |
710 |
{ |
711 |
[self subclassResponsibility: _cmd]; |
712 |
} |
713 |
|
714 |
- (void) DPSfill |
715 |
{ |
716 |
[self subclassResponsibility: _cmd]; |
717 |
} |
718 |
|
719 |
- (void)DPSflattenpath |
720 |
{ |
721 |
if (path) |
722 |
ASSIGN(path, [path bezierPathByFlatteningPath]); |
723 |
} |
724 |
|
725 |
- (void) DPSinitclip; |
726 |
{ |
727 |
[self subclassResponsibility: _cmd]; |
728 |
} |
729 |
|
730 |
- (void)DPSlineto: (float)x : (float)y |
731 |
{ |
732 |
NSPoint p = [ctm pointInMatrixSpace: NSMakePoint(x, y)]; |
733 |
|
734 |
CHECK_PATH; |
735 |
[path lineToPoint: p]; |
736 |
} |
737 |
|
738 |
- (void)DPSmoveto: (float)x : (float)y |
739 |
{ |
740 |
NSPoint p = [ctm pointInMatrixSpace: NSMakePoint(x, y)]; |
741 |
|
742 |
CHECK_PATH; |
743 |
[path moveToPoint: p]; |
744 |
} |
745 |
|
746 |
- (void)DPSnewpath |
747 |
{ |
748 |
if (path) |
749 |
[path removeAllPoints]; |
750 |
} |
751 |
|
752 |
- (void)DPSpathbbox: (float *)llx : (float *)lly : (float *)urx : (float *)ury |
753 |
{ |
754 |
if (path) |
755 |
{ |
756 |
NSRect rect = [path controlPointBounds]; |
757 |
|
758 |
// FIXME Should convert back to user space |
759 |
if (llx) |
760 |
*llx = NSMinX(rect); |
761 |
if (lly) |
762 |
*lly = NSMinY(rect); |
763 |
if (urx) |
764 |
*urx = NSMaxX(rect); |
765 |
if (ury) |
766 |
*ury = NSMaxY(rect); |
767 |
} |
768 |
} |
769 |
|
770 |
- (void)DPSrcurveto: (float)x1 : (float)y1 : (float)x2 : (float)y2 : (float)x3 |
771 |
: (float)y3 |
772 |
{ |
773 |
NSPoint p1 = [ctm deltaPointInMatrixSpace: NSMakePoint(x1, y1)]; |
774 |
NSPoint p2 = [ctm deltaPointInMatrixSpace: NSMakePoint(x2, y2)]; |
775 |
NSPoint p3 = [ctm deltaPointInMatrixSpace: NSMakePoint(x3, y3)]; |
776 |
|
777 |
CHECK_PATH; |
778 |
[path relativeCurveToPoint: p3 |
779 |
controlPoint1: p1 |
780 |
controlPoint2: p2]; |
781 |
} |
782 |
|
783 |
- (void) DPSrectclip: (float)x : (float)y : (float)w : (float)h |
784 |
{ |
785 |
NSRect rect = [ctm rectInMatrixSpace: NSMakeRect(x, y, w, h)]; |
786 |
NSBezierPath *oldPath = path; |
787 |
|
788 |
path = [NSBezierPath bezierPathWithRect: rect]; |
789 |
[self DPSclip]; |
790 |
path = oldPath; |
791 |
} |
792 |
|
793 |
- (void) DPSrectfill: (float)x : (float)y : (float)w : (float)h |
794 |
{ |
795 |
NSRect rect = [ctm rectInMatrixSpace: NSMakeRect(x, y, w, h)]; |
796 |
NSBezierPath *oldPath = path; |
797 |
|
798 |
path = [NSBezierPath bezierPathWithRect: rect]; |
799 |
[self DPSfill]; |
800 |
path = oldPath; |
801 |
} |
802 |
|
803 |
- (void) DPSrectstroke: (float)x : (float)y : (float)w : (float)h |
804 |
{ |
805 |
NSRect rect = [ctm rectInMatrixSpace: NSMakeRect(x, y, w, h)]; |
806 |
NSBezierPath *oldPath = path; |
807 |
|
808 |
path = [NSBezierPath bezierPathWithRect: rect]; |
809 |
[self DPSstroke]; |
810 |
path = oldPath; |
811 |
} |
812 |
|
813 |
- (void)DPSreversepath |
814 |
{ |
815 |
if (path) |
816 |
ASSIGN(path, [path bezierPathByReversingPath]); |
817 |
} |
818 |
|
819 |
- (void)DPSrlineto: (float)x : (float)y |
820 |
{ |
821 |
NSPoint p = [ctm deltaPointInMatrixSpace: NSMakePoint(x, y)]; |
822 |
|
823 |
CHECK_PATH; |
824 |
[path relativeLineToPoint: p]; |
825 |
} |
826 |
|
827 |
- (void)DPSrmoveto: (float)x : (float)y |
828 |
{ |
829 |
NSPoint p = [ctm deltaPointInMatrixSpace: NSMakePoint(x, y)]; |
830 |
|
831 |
CHECK_PATH; |
832 |
[path relativeMoveToPoint: p]; |
833 |
} |
834 |
|
835 |
- (void) DPSstroke; |
836 |
{ |
837 |
[self subclassResponsibility: _cmd]; |
838 |
} |
839 |
|
840 |
- (void) GSSendBezierPath: (NSBezierPath *)newpath |
841 |
{ |
842 |
int count; |
843 |
float pattern[10]; |
844 |
float phase; |
845 |
|
846 |
// Appending to the current path is a lot faster than copying! |
847 |
//ASSIGNCOPY(path, newpath); |
848 |
CHECK_PATH; |
849 |
[path removeAllPoints]; |
850 |
[path appendBezierPath: newpath]; |
851 |
[path transformUsingAffineTransform: ctm]; |
852 |
|
853 |
// The following should be moved down into the specific subclasses |
854 |
[self DPSsetlinewidth: [newpath lineWidth]]; |
855 |
[self DPSsetlinejoin: [newpath lineJoinStyle]]; |
856 |
[self DPSsetlinecap: [newpath lineCapStyle]]; |
857 |
[self DPSsetmiterlimit: [newpath miterLimit]]; |
858 |
[self DPSsetflat: [newpath flatness]]; |
859 |
|
860 |
[newpath getLineDash: pattern count: &count phase: &phase]; |
861 |
[self DPSsetdash: pattern : count : phase]; |
862 |
} |
863 |
|
864 |
- (void) GSRectClipList: (const NSRect *)rects : (int) count |
865 |
{ |
866 |
int i; |
867 |
NSRect union_rect; |
868 |
|
869 |
if (count == 0) |
870 |
return; |
871 |
|
872 |
/* |
873 |
The specification is not clear if the union of the rects |
874 |
should produce the new clip rect or if the outline of all rects |
875 |
should be used as clip path. |
876 |
*/ |
877 |
union_rect = rects[0]; |
878 |
for (i = 1; i < count; i++) |
879 |
union_rect = NSUnionRect(union_rect, rects[i]); |
880 |
|
881 |
[self DPSrectclip: NSMinX(union_rect) : NSMinY(union_rect) |
882 |
: NSWidth(union_rect) : NSHeight(union_rect)]; |
883 |
} |
884 |
|
885 |
|
886 |
- (void) GSRectFillList: (const NSRect *)rects : (int) count |
887 |
{ |
888 |
int i; |
889 |
for (i=0; i < count; i++) |
890 |
[self DPSrectfill: NSMinX(rects[i]) : NSMinY(rects[i]) |
891 |
: NSWidth(rects[i]) : NSHeight(rects[i])]; |
892 |
} |
893 |
|
894 |
- (void)DPSimage: (NSAffineTransform*) matrix |
895 |
: (int) pixelsWide : (int) pixelsHigh |
896 |
: (int) bitsPerSample : (int) samplesPerPixel |
897 |
: (int) bitsPerPixel : (int) bytesPerRow : (BOOL) isPlanar |
898 |
: (BOOL) hasAlpha : (NSString *) colorSpaceName |
899 |
: (const unsigned char *const [5]) data |
900 |
{ |
901 |
[self subclassResponsibility: _cmd]; |
902 |
} |
903 |
@end |
904 |
|
905 |
|