1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
|
/* cairo - a vector graphics library with display and print output
*
* Copyright © 2004 Stuart Parmenter
*
* This library is free software; you can redistribute it and/or
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*
* The Original Code is the cairo graphics library.
*
* The Initial Developer of the Original Code is Stuart Parmenter.
*
* Contributor(s):
* Stuart Parmenter <pavlov@pavlov.net>
*/
extern "C" {
#include "cairoint.h"
}
/* export symbols, for cairo.dll only */
#pragma comment(linker, "/EXPORT:_cairo_create")
#pragma comment(linker, "/EXPORT:_cairo_reference")
#pragma comment(linker, "/EXPORT:_cairo_destroy")
#pragma comment(linker, "/EXPORT:_cairo_save")
#pragma comment(linker, "/EXPORT:_cairo_restore")
#pragma comment(linker, "/EXPORT:_cairo_copy")
#pragma comment(linker, "/EXPORT:_cairo_set_target_surface")
#pragma comment(linker, "/EXPORT:_cairo_set_target_image")
#ifdef CAIRO_HAS_PS_SURFACE
#pragma comment(linker, "/EXPORT:_cairo_set_target_ps")
#endif
#ifdef CAIRO_HAS_PS_SURFACE
#pragma comment(linker, "/EXPORT:_cairo_set_target_pdf")
#endif
#ifdef CAIRO_HAS_PNG_SURFACE
#pragma comment(linker, "/EXPORT:_cairo_set_target_png")
#endif
#ifdef CAIRO_HAS_GL_SURFACE
#pragma comment(linker, "/EXPORT:_cairo_set_target_gl")
#endif
#ifdef CAIRO_HAS_WIN32_SURFACE
#pragma comment(linker, "/EXPORT:_cairo_set_target_win32")
#endif
#pragma comment(linker, "/EXPORT:_cairo_set_operator")
#pragma comment(linker, "/EXPORT:_cairo_set_rgb_color")
#pragma comment(linker, "/EXPORT:_cairo_set_pattern")
#pragma comment(linker, "/EXPORT:_cairo_set_alpha")
#pragma comment(linker, "/EXPORT:_cairo_set_tolerance")
#pragma comment(linker, "/EXPORT:_cairo_set_fill_rule")
#pragma comment(linker, "/EXPORT:_cairo_set_line_width")
#pragma comment(linker, "/EXPORT:_cairo_set_line_cap")
#pragma comment(linker, "/EXPORT:_cairo_set_line_join")
#pragma comment(linker, "/EXPORT:_cairo_set_dash")
#pragma comment(linker, "/EXPORT:_cairo_set_miter_limit")
#pragma comment(linker, "/EXPORT:_cairo_set_line_cap")
#pragma comment(linker, "/EXPORT:_cairo_translate")
#pragma comment(linker, "/EXPORT:_cairo_scale")
#pragma comment(linker, "/EXPORT:_cairo_rotate")
#pragma comment(linker, "/EXPORT:_cairo_concat_matrix")
#pragma comment(linker, "/EXPORT:_cairo_set_matrix")
#pragma comment(linker, "/EXPORT:_cairo_default_matrix")
#pragma comment(linker, "/EXPORT:_cairo_identity_matrix")
#pragma comment(linker, "/EXPORT:_cairo_transform_point")
#pragma comment(linker, "/EXPORT:_cairo_transform_distance")
#pragma comment(linker, "/EXPORT:_cairo_inverse_transform_point")
#pragma comment(linker, "/EXPORT:_cairo_inverse_transform_distance")
#pragma comment(linker, "/EXPORT:_cairo_new_path")
#pragma comment(linker, "/EXPORT:_cairo_move_to")
#pragma comment(linker, "/EXPORT:_cairo_line_to")
#pragma comment(linker, "/EXPORT:_cairo_curve_to")
#pragma comment(linker, "/EXPORT:_cairo_arc")
#pragma comment(linker, "/EXPORT:_cairo_arc_negative")
#pragma comment(linker, "/EXPORT:_cairo_rel_move_to")
#pragma comment(linker, "/EXPORT:_cairo_rel_line_to")
#pragma comment(linker, "/EXPORT:_cairo_rel_curve_to")
#pragma comment(linker, "/EXPORT:_cairo_rectangle")
#pragma comment(linker, "/EXPORT:_cairo_close_path")
#pragma comment(linker, "/EXPORT:_cairo_stroke")
#pragma comment(linker, "/EXPORT:_cairo_fill")
#pragma comment(linker, "/EXPORT:_cairo_copy_page")
#pragma comment(linker, "/EXPORT:_cairo_show_page")
#pragma comment(linker, "/EXPORT:_cairo_in_stroke")
#pragma comment(linker, "/EXPORT:_cairo_in_fill")
#pragma comment(linker, "/EXPORT:_cairo_stroke_extents")
#pragma comment(linker, "/EXPORT:_cairo_fill_extents")
#pragma comment(linker, "/EXPORT:_cairo_init_clip")
#pragma comment(linker, "/EXPORT:_cairo_clip")
#pragma comment(linker, "/EXPORT:_cairo_select_font")
#pragma comment(linker, "/EXPORT:_cairo_scale_font")
#pragma comment(linker, "/EXPORT:_cairo_transform_font")
#pragma comment(linker, "/EXPORT:_cairo_show_text")
#pragma comment(linker, "/EXPORT:_cairo_show_glyphs")
#pragma comment(linker, "/EXPORT:_cairo_current_font")
#pragma comment(linker, "/EXPORT:_cairo_current_font_extents")
#pragma comment(linker, "/EXPORT:_cairo_set_font")
#pragma comment(linker, "/EXPORT:_cairo_text_extents")
#pragma comment(linker, "/EXPORT:_cairo_glyph_extents")
#pragma comment(linker, "/EXPORT:_cairo_text_path")
#pragma comment(linker, "/EXPORT:_cairo_glyph_path")
#pragma comment(linker, "/EXPORT:_cairo_font_reference")
#pragma comment(linker, "/EXPORT:_cairo_font_destroy")
#pragma comment(linker, "/EXPORT:_cairo_font_set_transform")
#pragma comment(linker, "/EXPORT:_cairo_font_current_transform")
/*#pragma comment(linker, "/EXPORT:_cairo_ft_font_create")
#pragma comment(linker, "/EXPORT:_cairo_ft_font_create_for_ft_face")
*/
#if 0
/* hmm, this function doesn't exist, but __cairo_ft_font_destroy does */
#pragma comment(linker, "/EXPORT:_cairo_ft_font_destroy")
#endif
/*
#pragma comment(linker, "/EXPORT:_cairo_ft_font_face")
#pragma comment(linker, "/EXPORT:_cairo_ft_font_pattern")
*/
#pragma comment(linker, "/EXPORT:_cairo_show_surface")
#pragma comment(linker, "/EXPORT:_cairo_current_operator")
#pragma comment(linker, "/EXPORT:_cairo_current_rgb_color")
#pragma comment(linker, "/EXPORT:_cairo_current_pattern")
#pragma comment(linker, "/EXPORT:_cairo_current_alpha")
#pragma comment(linker, "/EXPORT:_cairo_current_tolerance")
#pragma comment(linker, "/EXPORT:_cairo_current_point")
#pragma comment(linker, "/EXPORT:_cairo_current_fill_rule")
#pragma comment(linker, "/EXPORT:_cairo_current_line_width")
#pragma comment(linker, "/EXPORT:_cairo_current_line_cap")
#pragma comment(linker, "/EXPORT:_cairo_current_line_join")
#pragma comment(linker, "/EXPORT:_cairo_current_rgb_color")
#pragma comment(linker, "/EXPORT:_cairo_current_miter_limit")
#pragma comment(linker, "/EXPORT:_cairo_current_matrix")
#pragma comment(linker, "/EXPORT:_cairo_current_target_surface")
#pragma comment(linker, "/EXPORT:_cairo_current_path")
#pragma comment(linker, "/EXPORT:_cairo_current_path_flat")
#pragma comment(linker, "/EXPORT:_cairo_status")
#pragma comment(linker, "/EXPORT:_cairo_status_string")
#pragma comment(linker, "/EXPORT:_cairo_surface_create_for_image")
#pragma comment(linker, "/EXPORT:_cairo_surface_create_similar")
#pragma comment(linker, "/EXPORT:_cairo_surface_reference")
#pragma comment(linker, "/EXPORT:_cairo_surface_destroy")
#pragma comment(linker, "/EXPORT:_cairo_surface_set_repeat")
#pragma comment(linker, "/EXPORT:_cairo_surface_set_matrix")
#pragma comment(linker, "/EXPORT:_cairo_surface_get_matrix")
#pragma comment(linker, "/EXPORT:_cairo_surface_set_filter")
#pragma comment(linker, "/EXPORT:_cairo_surface_get_filter")
#pragma comment(linker, "/EXPORT:_cairo_image_surface_create")
#pragma comment(linker, "/EXPORT:_cairo_image_surface_create_for_data")
#pragma comment(linker, "/EXPORT:_cairo_pattern_create_for_surface")
#pragma comment(linker, "/EXPORT:_cairo_pattern_create_linear")
#pragma comment(linker, "/EXPORT:_cairo_pattern_create_radial")
#pragma comment(linker, "/EXPORT:_cairo_pattern_reference")
#pragma comment(linker, "/EXPORT:_cairo_pattern_destroy")
#pragma comment(linker, "/EXPORT:_cairo_pattern_add_color_stop")
#pragma comment(linker, "/EXPORT:_cairo_pattern_set_matrix")
#pragma comment(linker, "/EXPORT:_cairo_pattern_get_matrix")
#pragma comment(linker, "/EXPORT:_cairo_pattern_set_extend")
#pragma comment(linker, "/EXPORT:_cairo_pattern_get_extend")
#pragma comment(linker, "/EXPORT:_cairo_pattern_set_filter")
#pragma comment(linker, "/EXPORT:_cairo_pattern_get_filter")
#ifdef CAIRO_HAS_PS_SURFACE
#pragma comment(linker, "/EXPORT:_cairo_ps_surface_create")
#endif
#ifdef CAIRO_HAS_PNG_SURFACE
#pragma comment(linker, "/EXPORT:_cairo_png_surface_create")
#endif
#ifdef CAIRO_HAS_GL_SURFACE
#pragma comment(linker, "/EXPORT:_cairo_gl_surface_create")
#endif
#pragma comment(linker, "/EXPORT:_cairo_matrix_create")
#pragma comment(linker, "/EXPORT:_cairo_matrix_destroy")
#pragma comment(linker, "/EXPORT:_cairo_matrix_copy")
#pragma comment(linker, "/EXPORT:_cairo_matrix_set_identity")
#pragma comment(linker, "/EXPORT:_cairo_matrix_set_affine")
#pragma comment(linker, "/EXPORT:_cairo_matrix_get_affine")
#pragma comment(linker, "/EXPORT:_cairo_matrix_translate")
#pragma comment(linker, "/EXPORT:_cairo_matrix_scale")
#pragma comment(linker, "/EXPORT:_cairo_matrix_rotate")
#pragma comment(linker, "/EXPORT:_cairo_matrix_invert")
#pragma comment(linker, "/EXPORT:_cairo_matrix_multiply")
#pragma comment(linker, "/EXPORT:_cairo_matrix_transform_distance")
#pragma comment(linker, "/EXPORT:_cairo_matrix_transform_point")
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
extern const cairo_surface_backend_t cairo_win32_surface_backend;
cairo_surface_t *_cairo_win32_surface_create (HDC dc);
void
cairo_set_target_win32(cairo_t *cr, HDC dc)
{
cairo_surface_t *surface;
surface = _cairo_win32_surface_create(dc);
if (surface == NULL) {
cr->status = CAIRO_STATUS_NO_MEMORY;
return;
}
cairo_set_target_surface (cr, surface);
/* cairo_set_target_surface takes a reference, so we must destroy ours */
cairo_surface_destroy (surface);
}
typedef struct cairo_win32_surface {
cairo_surface_t base;
Graphics *gr;
Brush *brush;
} cairo_win32_surface_t;
static void
_cairo_win32_surface_erase(cairo_win32_surface_t *surface);
cairo_surface_t *
_cairo_win32_surface_create(HDC dc)
{
cairo_win32_surface_t *surface;
surface = (cairo_win32_surface_t*)malloc(sizeof(cairo_win32_surface_t));
if (surface == NULL)
return NULL;
surface->gr = new Graphics(dc);
surface->brush = NULL;
// surface->gr->TranslateTransform(-2000*2.5, -3000*2.2);
// surface->gr->ScaleTransform(20, 20);
surface->gr->SetSmoothingMode(SmoothingModeAntiAlias);
/* do pixmap creation, etc */
_cairo_surface_init(&surface->base, &cairo_win32_surface_backend);
_cairo_win32_surface_erase(surface);
return &surface->base;
}
static cairo_surface_t *
_cairo_win32_surface_create_similar(void *abstract_src,
cairo_format_t format,
int drawable,
int width,
int height)
{
return NULL;
}
static void
_cairo_win32_surface_destroy (void *abstract_surface)
{
cairo_win32_surface_t *surface = (cairo_win32_surface_t *)abstract_surface;
delete surface->gr;
delete surface->brush;
free(surface);
}
static void
_cairo_win32_surface_erase(cairo_win32_surface_t *surface)
{
surface->gr->Clear(Color(255, 0, 0, 0));
}
/* XXX: We should re-work this interface to return both X/Y ppi values. */
static double
_cairo_win32_surface_pixels_per_inch(void *abstract_surface)
{
cairo_win32_surface_t *surface = (cairo_win32_surface_t *)abstract_surface;
return surface->gr->GetDpiY();
}
static Image *
make_image(cairo_image_surface_t *image)
{
Rect r(0, 0, image->width, image->height);
Bitmap *b = new Bitmap(image->width, image->height, PixelFormat32bppPARGB);
BitmapData data;
b->LockBits(&r, ImageLockModeWrite, PixelFormat32bppPARGB, &data);
memcpy(data.Scan0, image->data, image->stride * image->height);
b->UnlockBits(&data);
return b;
}
static cairo_image_surface_t *
_cairo_win32_surface_get_image(void *abstract_surface)
{
cairo_win32_surface_t *surface = (cairo_win32_surface_t *)abstract_surface;
/* need to figure out how to get the data from a Graphics and turn it in to an Image */
return NULL;
}
static cairo_status_t
_cairo_win32_surface_set_image(void *abstract_surface,
cairo_image_surface_t *image)
{
cairo_win32_surface_t *surface = (cairo_win32_surface_t *)abstract_surface;
Image *img = make_image(image);
surface->gr->DrawImage(img, 0, 0);
delete img;
return CAIRO_STATUS_SUCCESS;
}
static cairo_status_t
_cairo_win32_surface_set_matrix(void *abstract_surface,
cairo_matrix_t *matrix)
{
cairo_win32_surface_t *surface = (cairo_win32_surface_t *)abstract_surface;
Matrix m((float)matrix->m[0][0], (float)matrix->m[1][0], (float)matrix->m[2][0],
(float)matrix->m[0][1], (float)matrix->m[1][1], (float)matrix->m[2][1]);
surface->gr->SetTransform(&m);
return CAIRO_STATUS_SUCCESS;
}
static cairo_status_t
_cairo_win32_surface_set_filter (void *abstract_surface,
cairo_filter_t filter)
{
cairo_win32_surface_t *surface = (cairo_win32_surface_t *)abstract_surface;
SmoothingMode mode;
switch (filter) {
case CAIRO_FILTER_FAST:
mode = SmoothingModeNone;
break;
case CAIRO_FILTER_GOOD:
case CAIRO_FILTER_BEST:
case CAIRO_FILTER_NEAREST:
case CAIRO_FILTER_BILINEAR:
case CAIRO_FILTER_GAUSSIAN:
default:
mode = SmoothingModeAntiAlias;
break;
}
surface->gr->SetSmoothingMode(mode);
return CAIRO_STATUS_SUCCESS;
}
static cairo_status_t
_cairo_win32_surface_set_repeat (void *abstract_surface,
int repeat)
{
/* what is this function supposed to do? */
cairo_win32_surface_t *surface = (cairo_win32_surface_t *)abstract_surface;
return (cairo_status_t)CAIRO_INT_STATUS_UNSUPPORTED;
}
static cairo_int_status_t
_cairo_win32_surface_composite(cairo_operator_t op,
cairo_surface_t *generic_src,
cairo_surface_t *generic_mask,
void *abstract_dst,
int src_x,
int src_y,
int mask_x,
int mask_y,
int dst_x,
int dst_y,
unsigned int width,
unsigned int height)
{
return CAIRO_INT_STATUS_UNSUPPORTED;
}
static cairo_int_status_t
_cairo_win32_surface_fill_rectangles(void *abstract_surface,
cairo_operator_t op,
const cairo_color_t *color,
cairo_rectangle_t *rects,
int num_rects)
{
cairo_win32_surface_t *surface = (cairo_win32_surface_t *)abstract_surface;
SolidBrush brush(Color(color->alpha_short, color->red_short, color->green_short, color->blue_short));
RectF *r = new RectF[num_rects]; /* should really allocate a small number here on the stack and use those if possible */
for (int i = 0; i < num_rects; ++i) {
r[i].X = rects[i].x;
r[i].Y = rects[i].y;
r[i].Width = rects[i].width;
r[i].Height = rects[i].height;
}
surface->gr->FillRectangles(&brush, r, num_rects);
delete[] r;
return (cairo_int_status_t)CAIRO_STATUS_SUCCESS;
}
static int
_cairo_win32_extract_rectangle (cairo_trapezoid_t *trap,
RectF *rect)
{
if (trap->left.p1.x == trap->left.p2.x &&
trap->right.p1.x == trap->right.p2.x &&
trap->left.p1.y == trap->right.p1.y &&
trap->left.p2.y == trap->right.p2.y) {
double x = _cairo_fixed_to_double (trap->left.p1.x);
double y = _cairo_fixed_to_double (trap->left.p1.y);
rect->X = (float)x;
rect->Y = (float)y;
rect->Width = (float)(_cairo_fixed_to_double(trap->right.p1.x) - x);
rect->Height = (float)(_cairo_fixed_to_double(trap->left.p2.y) - y);
return 1;
}
return 0;
}
static cairo_int_status_t
_cairo_win32_surface_composite_trapezoids (cairo_operator_t op,
cairo_surface_t *generic_src,
void *abstract_dst,
int x_src,
int y_src,
cairo_trapezoid_t *traps,
int num_traps)
{
cairo_win32_surface_t *surface = (cairo_win32_surface_t *)abstract_dst;
static int zzz = 0;
zzz += num_traps;
Image *img = NULL;
Brush *brush = NULL; /* i'd really like to not allocate this on the heap.. */
#define FIXED_TO_FLOAT(x) (float)_cairo_fixed_to_double((x))
/* ugh.. figure out if we're a "native" pattern or an image_surface pattern.. */
if (generic_src->backend == &cairo_win32_surface_backend) {
brush = ((cairo_win32_surface_t*)generic_src)->brush;
/* XXX move this outside so that TextureBrushes can take advantage of it */
/* Check to see if we can represent these traps as a rectangle. */
RectF rect;
if (num_traps == 1 && _cairo_win32_extract_rectangle(traps, &rect)) {
surface->gr->FillRectangle(brush, rect);
return (cairo_int_status_t)CAIRO_STATUS_SUCCESS;
}
} else {
/* I would really love to move this code in to create_pattern if possible */
img = make_image((cairo_image_surface_t*)generic_src);
brush = new TextureBrush(img);
// XXX this will probably break. Don't know why we have +1 and +2 offsets..
float xoff = (FIXED_TO_FLOAT(traps[0].left.p1.x) + 0.5f);
float yoff = (FIXED_TO_FLOAT(traps[0].left.p1.y) + 1.5f);
static_cast<TextureBrush*>(brush)->TranslateTransform((int)(-x_src + xoff),
(int)(-y_src + yoff));
}
CompositingMode mode;
switch (op) {
case CAIRO_OPERATOR_OVER:
mode = CompositingModeSourceOver;
break;
case CAIRO_OPERATOR_CLEAR:
mode = CompositingModeSourceCopy;
break;
case CAIRO_OPERATOR_SRC:
case CAIRO_OPERATOR_DST:
case CAIRO_OPERATOR_OVER_REVERSE:
case CAIRO_OPERATOR_IN:
case CAIRO_OPERATOR_IN_REVERSE:
case CAIRO_OPERATOR_OUT:
case CAIRO_OPERATOR_OUT_REVERSE:
case CAIRO_OPERATOR_ATOP:
case CAIRO_OPERATOR_ATOP_REVERSE:
case CAIRO_OPERATOR_XOR:
case CAIRO_OPERATOR_ADD:
case CAIRO_OPERATOR_SATURATE:
mode = CompositingModeSourceOver;
break;
}
surface->gr->SetCompositingMode(mode);
PointF points[4];
for (int i = 0; i < num_traps; ++i) {
float top = FIXED_TO_FLOAT(traps[i].top);
float bottom = FIXED_TO_FLOAT(traps[i].bottom);
/* left line */
points[0].X = FIXED_TO_FLOAT(traps[i].left.p1.x);
points[0].Y = FIXED_TO_FLOAT(traps[i].left.p1.y);
points[1].X = FIXED_TO_FLOAT(traps[i].left.p2.x);
points[1].Y = FIXED_TO_FLOAT(traps[i].left.p2.y);
/* right line */
points[2].X = FIXED_TO_FLOAT(traps[i].right.p2.x);
points[2].Y = FIXED_TO_FLOAT(traps[i].right.p2.y);
points[3].X = FIXED_TO_FLOAT(traps[i].right.p1.x);
points[3].Y = FIXED_TO_FLOAT(traps[i].right.p1.y);
surface->gr->FillPolygon(brush, points, 4);
//Pen p(Color(255,0,0,0), 1.0f/10.0f);
//surface->gr->DrawPolygon(&p, points, 4);
}
#undef FIXED_TO_FLOAT
delete img;
return (cairo_int_status_t)CAIRO_STATUS_SUCCESS;
}
static cairo_int_status_t
_cairo_win32_surface_copy_page (void *abstract_surface)
{
return CAIRO_INT_STATUS_UNSUPPORTED;
}
static cairo_int_status_t
_cairo_win32_surface_show_page (void *abstract_surface)
{
return CAIRO_INT_STATUS_UNSUPPORTED;
}
static cairo_int_status_t
_cairo_win32_surface_set_clip_region (void *abstract_surface,
pixman_region16_t *region)
{
cairo_win32_surface_t *surface = (cairo_win32_surface_t *)abstract_surface;
pixman_box16_t *box;
int n = pixman_region_num_rects(region);
if (n == 0)
return (cairo_int_status_t)CAIRO_STATUS_SUCCESS;
box = pixman_region_rects(region);
surface->gr->ResetClip();
for (int i = 0; i < n; ++i) {
Rect r(box[i].x1, box[i].y1, box[i].x2 - box[i].x1, box[i].y2 - box[i].y1);
surface->gr->SetClip(r, CombineModeUnion); /* do I need to do replace once and then union? */
}
return (cairo_int_status_t)CAIRO_STATUS_SUCCESS;
}
static cairo_int_status_t
_cairo_win32_surface_create_pattern (void *abstract_surface,
cairo_pattern_t *pattern,
cairo_box_t *box)
{
/* SOLID is easy -> SolidBrush
LINEAR we can only do a gradient from 1 color to another -> LinearGradientBrush
We should do this if thats all we need, otherwise use software.
RADIAL we can't really do it. Let it fall back to software I guess. */
/* in the case of PATTERN_SOLID, we really just want to create a brush and hand that back... */
if (pattern->type == CAIRO_PATTERN_SOLID) {
/* ugh, this surface creation code should _really_ live somewhere else */
cairo_win32_surface_t *src = (cairo_win32_surface_t*)malloc(sizeof(cairo_win32_surface_t));
if (src == NULL)
return CAIRO_INT_STATUS_UNSUPPORTED;
_cairo_surface_init(&src->base, &cairo_win32_surface_backend);
pattern->source = &src->base;
src->gr = NULL;
src->brush = new SolidBrush(Color(pattern->color.alpha_short,
pattern->color.red_short,
pattern->color.green_short,
pattern->color.blue_short));
return (cairo_int_status_t)CAIRO_STATUS_SUCCESS;
}
else if (pattern->type == CAIRO_PATTERN_LINEAR && pattern->n_stops == 2) {
/* ugh, this surface creation code should _really_ live somewhere else */
cairo_win32_surface_t *src = (cairo_win32_surface_t*)malloc(sizeof(cairo_win32_surface_t));
if (src == NULL)
return CAIRO_INT_STATUS_UNSUPPORTED;
_cairo_surface_init(&src->base, &cairo_win32_surface_backend);
pattern->source = &src->base;
src->gr = NULL;
RectF r((float)pattern->u.linear.point0.x,
(float)pattern->u.linear.point0.y,
((box->p2.x + 65535) >> 16) - (box->p1.x >> 16),
((box->p2.y + 65535) >> 16) - (box->p1.y >> 16));
src->brush = new LinearGradientBrush(r,
Color(pattern->stops[0].color_char[3],
pattern->stops[0].color_char[0],
pattern->stops[0].color_char[1],
pattern->stops[0].color_char[2]),
Color(pattern->stops[1].color_char[3],
pattern->stops[1].color_char[0],
pattern->stops[1].color_char[1],
pattern->stops[1].color_char[2]),
90.0, FALSE);
static_cast<LinearGradientBrush*>(src->brush)->TranslateTransform((float)pattern->source_offset.x,
(float)pattern->source_offset.y);
return (cairo_int_status_t)CAIRO_STATUS_SUCCESS;
}
else if (pattern->type == CAIRO_PATTERN_RADIAL) {
#if 0 /* XXX not sure this will work.. do we have to draw with FillPath() in order for this brush to work properly? */
/* use PathGradientBrush here */
/* ugh, this surface creation code should _really_ live somewhere else */
cairo_win32_surface_t *src = (cairo_win32_surface_t*)malloc(sizeof(cairo_win32_surface_t));
if (src == NULL)
return CAIRO_INT_STATUS_UNSUPPORTED;
_cairo_surface_init(&src->base, &cairo_win32_surface_backend);
pattern->source = &src->base;
src->gr = NULL;
PointF center(pattern->u.radial.center1.x, pattern->u.radial.center1.y);
GraphicsPath path;
path.AddEllipse(0, 0, 140, 70);
// Use the path to construct a brush.
PathGradientBrush *brush = new PathGradientBrush(&path);
src->brush = brush;
// Set the color at the center of the path to blue.
brush->SetCenterColor(Color(50, 100, 0, 255));
// Set the color along the entire boundary of the path to aqua.
Color colors[] = {Color(255, 0, 255, 255)};
int count = 1;
brush->SetSurroundColors(colors, &count);
brush->SetCenterPoint(center);
return (cairo_int_status_t)CAIRO_STATUS_SUCCESS;
#endif
}
return CAIRO_INT_STATUS_UNSUPPORTED;
}
static const cairo_surface_backend_t cairo_win32_surface_backend = {
_cairo_win32_surface_create_similar,
_cairo_win32_surface_destroy,
_cairo_win32_surface_pixels_per_inch,
_cairo_win32_surface_get_image,
_cairo_win32_surface_set_image,
_cairo_win32_surface_set_matrix,
_cairo_win32_surface_set_filter,
_cairo_win32_surface_set_repeat,
_cairo_win32_surface_composite,
_cairo_win32_surface_fill_rectangles,
_cairo_win32_surface_composite_trapezoids,
_cairo_win32_surface_copy_page,
_cairo_win32_surface_show_page,
_cairo_win32_surface_set_clip_region,
_cairo_win32_surface_create_pattern,
};
|