5
5
6
6
cairo_container::cairo_container (void )
7
7
{
8
- m_temp_dib.create (1 , 1 , true );
9
- m_font_link = NULL ;
8
+ m_temp_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 2 , 2 );
9
+ m_temp_cr = cairo_create (m_temp_surface);
10
+ m_font_link = NULL ;
10
11
CoCreateInstance (CLSID_CMultiLanguage, NULL , CLSCTX_ALL, IID_IMLangFontLink2, (void **) &m_font_link);
11
12
}
12
13
@@ -17,6 +18,8 @@ cairo_container::~cairo_container(void)
17
18
{
18
19
m_font_link->Release ();
19
20
}
21
+ cairo_surface_destroy (m_temp_surface);
22
+ cairo_destroy (m_temp_cr);
20
23
}
21
24
22
25
litehtml::uint_ptr cairo_container::create_font ( const wchar_t * faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm )
@@ -35,15 +38,17 @@ litehtml::uint_ptr cairo_container::create_font( const wchar_t* faceName, int si
35
38
36
39
if (fm)
37
40
{
38
- cairo_dev cr (&m_temp_dib );
41
+ cairo_save (m_temp_cr );
39
42
40
43
cairo_font_metrics cfm;
41
- fnt->get_metrics (cr , &cfm);
44
+ fnt->get_metrics (m_temp_cr , &cfm);
42
45
43
46
fm->ascent = cfm.ascent ;
44
47
fm->descent = cfm.descent ;
45
48
fm->height = cfm.height ;
46
49
fm->x_height = cfm.x_height ;
50
+
51
+ cairo_restore (m_temp_cr);
47
52
}
48
53
49
54
return (litehtml::uint_ptr) fnt;
@@ -61,15 +66,19 @@ void cairo_container::delete_font( litehtml::uint_ptr hFont )
61
66
int cairo_container::text_width ( const wchar_t * text, litehtml::uint_ptr hFont )
62
67
{
63
68
cairo_font* fnt = (cairo_font*) hFont;
64
- cairo_dev cr (&m_temp_dib);
65
-
66
- return fnt->text_width (cr, text);
69
+
70
+ cairo_save (m_temp_cr);
71
+ int ret = fnt->text_width (m_temp_cr, text);
72
+ cairo_restore (m_temp_cr);
73
+ return ret;
67
74
}
68
75
69
76
void cairo_container::draw_text ( litehtml::uint_ptr hdc, const wchar_t * text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos )
70
77
{
71
78
cairo_font* fnt = (cairo_font*) hFont;
72
- cairo_dev cr (get_dib (hdc));
79
+ cairo_t * cr = (cairo_t *) hdc;
80
+ cairo_save (cr);
81
+
73
82
apply_clip (cr);
74
83
75
84
cairo_font_metrics cfm;
@@ -78,15 +87,18 @@ void cairo_container::draw_text( litehtml::uint_ptr hdc, const wchar_t* text, li
78
87
int x = pos.left ();
79
88
int y = pos.bottom () - cfm.descent ;
80
89
81
- cr. set_color (color);
90
+ set_color (cr, color);
82
91
fnt->show_text (cr, x, y, text);
92
+
93
+ cairo_restore (cr);
83
94
}
84
95
85
96
void cairo_container::fill_rect ( litehtml::uint_ptr hdc, const litehtml::position& pos, const litehtml::web_color color, const litehtml::css_border_radius& radius )
86
97
{
87
98
if (hdc)
88
99
{
89
- cairo_dev cr ( get_dib (hdc) );
100
+ cairo_t * cr = (cairo_t *) hdc;
101
+ cairo_save (cr);
90
102
apply_clip (cr);
91
103
92
104
if (radius.top_left_x .val ())
@@ -118,8 +130,9 @@ void cairo_container::fill_rect( litehtml::uint_ptr hdc, const litehtml::positio
118
130
cairo_arc (cr, pos.left () + radius.bottom_left_x .val (), pos.bottom () - radius.bottom_left_x .val (), radius.bottom_left_x .val (), M_PI / 2.0 , M_PI);
119
131
}
120
132
121
- cr. set_color (color);
133
+ set_color (cr, color);
122
134
cairo_fill (cr);
135
+ cairo_restore (cr);
123
136
}
124
137
}
125
138
@@ -149,12 +162,12 @@ void cairo_container::draw_list_marker( litehtml::uint_ptr hdc, litehtml::list_s
149
162
{
150
163
case litehtml::list_style_type_circle:
151
164
{
152
- draw_ellipse (get_dib (hdc) , draw_x, draw_y, draw_width, draw_height, color, 1 );
165
+ draw_ellipse (( cairo_t *) hdc , draw_x, draw_y, draw_width, draw_height, color, 1 );
153
166
}
154
167
break ;
155
168
case litehtml::list_style_type_disc:
156
169
{
157
- fill_ellipse (get_dib (hdc) , draw_x, draw_y, draw_width, draw_height, color);
170
+ fill_ellipse (( cairo_t *) hdc , draw_x, draw_y, draw_width, draw_height, color);
158
171
}
159
172
break ;
160
173
case litehtml::list_style_type_square:
@@ -194,21 +207,24 @@ void cairo_container::get_image_size( const wchar_t* src, const wchar_t* baseurl
194
207
195
208
void cairo_container::draw_image ( litehtml::uint_ptr hdc, const wchar_t * src, const wchar_t * baseurl, const litehtml::position& pos )
196
209
{
197
- cairo_dev cr (get_dib (hdc));
210
+ cairo_t * cr = (cairo_t *) hdc;
211
+ cairo_save (cr);
198
212
apply_clip (cr);
199
213
200
214
std::wstring url;
201
215
make_url (src, baseurl, url);
202
216
images_map::iterator img = m_images.find (url.c_str ());
203
217
if (img != m_images.end ())
204
218
{
205
- cr. draw_image ( img->second , pos.x , pos.y , pos.width , pos.height );
219
+ draw_txdib (cr, img->second , pos.x , pos.y , pos.width , pos.height );
206
220
}
221
+ cairo_restore (cr);
207
222
}
208
223
209
224
void cairo_container::draw_background ( litehtml::uint_ptr hdc, const wchar_t * image, const wchar_t * baseurl, const litehtml::position& draw_pos, const litehtml::css_position& bg_pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment )
210
225
{
211
- cairo_dev cr (get_dib (hdc));
226
+ cairo_t * cr = (cairo_t *) hdc;
227
+ cairo_save (cr);
212
228
apply_clip (cr);
213
229
214
230
cairo_rectangle (cr, draw_pos.x , draw_pos.y , draw_pos.width , draw_pos.height );
@@ -257,7 +273,7 @@ void cairo_container::draw_background( litehtml::uint_ptr hdc, const wchar_t* im
257
273
switch (repeat)
258
274
{
259
275
case litehtml::background_repeat_no_repeat:
260
- cr. draw_image ( bgbmp, bg_x, bg_y, bgbmp->getWidth (), bgbmp->getHeight ());
276
+ draw_txdib (cr, bgbmp, bg_x, bg_y, bgbmp->getWidth (), bgbmp->getHeight ());
261
277
break ;
262
278
263
279
case litehtml::background_repeat_repeat_x:
@@ -282,6 +298,7 @@ void cairo_container::draw_background( litehtml::uint_ptr hdc, const wchar_t* im
282
298
cairo_pattern_destroy (pattern);
283
299
cairo_surface_destroy (img);
284
300
}
301
+ cairo_restore (cr);
285
302
}
286
303
287
304
void cairo_container::add_path_arc (cairo_t * cr, double x, double y, double rx, double ry, double a1, double a2, bool neg)
@@ -312,7 +329,8 @@ void cairo_container::add_path_arc(cairo_t* cr, double x, double y, double rx, d
312
329
313
330
void cairo_container::draw_borders ( litehtml::uint_ptr hdc, const litehtml::css_borders& borders, const litehtml::position& draw_pos )
314
331
{
315
- cairo_dev cr (get_dib (hdc));
332
+ cairo_t * cr = (cairo_t *) hdc;
333
+ cairo_save (cr);
316
334
apply_clip (cr);
317
335
318
336
int bdr_top = 0 ;
@@ -340,7 +358,7 @@ void cairo_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::css_
340
358
// draw right border
341
359
if (bdr_right)
342
360
{
343
- cr. set_color (borders.right .color );
361
+ set_color (cr, borders.right .color );
344
362
345
363
double r_top = borders.radius .top_right_x .val ();
346
364
double r_bottom = borders.radius .bottom_right_x .val ();
@@ -405,7 +423,7 @@ void cairo_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::css_
405
423
// draw bottom border
406
424
if (bdr_bottom)
407
425
{
408
- cr. set_color (borders.bottom .color );
426
+ set_color (cr, borders.bottom .color );
409
427
410
428
double r_left = borders.radius .bottom_left_x .val ();
411
429
double r_right = borders.radius .bottom_right_x .val ();
@@ -470,7 +488,7 @@ void cairo_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::css_
470
488
// draw top border
471
489
if (bdr_top)
472
490
{
473
- cr. set_color (borders.top .color );
491
+ set_color (cr, borders.top .color );
474
492
475
493
double r_left = borders.radius .top_left_x .val ();
476
494
double r_right = borders.radius .top_right_x .val ();
@@ -535,7 +553,7 @@ void cairo_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::css_
535
553
// draw left border
536
554
if (bdr_left)
537
555
{
538
- cr. set_color (borders.left .color );
556
+ set_color (cr, borders.left .color );
539
557
540
558
double r_top = borders.radius .top_left_x .val ();
541
559
double r_bottom = borders.radius .bottom_left_x .val ();
@@ -596,6 +614,7 @@ void cairo_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::css_
596
614
597
615
cairo_fill (cr);
598
616
}
617
+ cairo_restore (cr);
599
618
}
600
619
601
620
wchar_t cairo_container::toupper ( const wchar_t c )
@@ -647,35 +666,39 @@ void cairo_container::apply_clip( cairo_t* cr )
647
666
}
648
667
}
649
668
650
- void cairo_container::draw_ellipse ( simpledib::dib* dib , int x, int y, int width, int height, const litehtml::web_color& color, int line_width )
669
+ void cairo_container::draw_ellipse ( cairo_t * cr , int x, int y, int width, int height, const litehtml::web_color& color, int line_width )
651
670
{
652
- if (!dib) return ;
671
+ if (!cr) return ;
672
+ cairo_save (cr);
653
673
654
- cairo_dev cr (dib);
655
674
apply_clip (cr);
656
675
657
676
cairo_translate (cr, x + width / 2.0 , y + height / 2.0 );
658
677
cairo_scale (cr, width / 2.0 , height / 2.0 );
659
678
cairo_arc (cr, 0 , 0 , 1 , 0 , 2 * M_PI);
660
679
661
- cr. set_color (color);
680
+ set_color (cr, color);
662
681
cairo_set_line_width (cr, line_width);
663
682
cairo_stroke (cr);
683
+
684
+ cairo_restore (cr);
664
685
}
665
686
666
- void cairo_container::fill_ellipse ( simpledib::dib* dib , int x, int y, int width, int height, const litehtml::web_color& color )
687
+ void cairo_container::fill_ellipse ( cairo_t * cr , int x, int y, int width, int height, const litehtml::web_color& color )
667
688
{
668
- if (!dib) return ;
689
+ if (!cr) return ;
690
+ cairo_save (cr);
669
691
670
- cairo_dev cr (dib);
671
692
apply_clip (cr);
672
693
673
694
cairo_translate (cr, x + width / 2.0 , y + height / 2.0 );
674
695
cairo_scale (cr, width / 2.0 , height / 2.0 );
675
696
cairo_arc (cr, 0 , 0 , 1 , 0 , 2 * M_PI);
676
697
677
- cr. set_color (color);
698
+ set_color (cr, color);
678
699
cairo_fill (cr);
700
+
701
+ cairo_restore (cr);
679
702
}
680
703
681
704
void cairo_container::clear_images ()
@@ -695,6 +718,38 @@ const wchar_t* cairo_container::get_default_font_name()
695
718
return L" Times New Roman" ;
696
719
}
697
720
721
+ void cairo_container::draw_txdib ( cairo_t * cr, CTxDIB* bmp, int x, int y, int cx, int cy )
722
+ {
723
+ cairo_save (cr);
724
+
725
+ cairo_matrix_t flib_m;
726
+ cairo_matrix_init (&flib_m, 1 , 0 , 0 , -1 , 0 , 0 );
727
+
728
+ cairo_surface_t * img = NULL ;
729
+
730
+ CTxDIB rbmp;
731
+
732
+ if (cx != bmp->getWidth () || cy != bmp->getHeight ())
733
+ {
734
+ bmp->resample (cx, cy, &rbmp);
735
+ img = cairo_image_surface_create_for_data ((unsigned char *) rbmp.getBits (), CAIRO_FORMAT_ARGB32, rbmp.getWidth (), rbmp.getHeight (), rbmp.getWidth () * 4 );
736
+ cairo_matrix_translate (&flib_m, 0 , -rbmp.getHeight ());
737
+ cairo_matrix_translate (&flib_m, x, -y);
738
+ } else
739
+ {
740
+ img = cairo_image_surface_create_for_data ((unsigned char *) bmp->getBits (), CAIRO_FORMAT_ARGB32, bmp->getWidth (), bmp->getHeight (), bmp->getWidth () * 4 );
741
+ cairo_matrix_translate (&flib_m, 0 , -bmp->getHeight ());
742
+ cairo_matrix_translate (&flib_m, x, -y);
743
+ }
744
+
745
+ cairo_transform (cr, &flib_m);
746
+ cairo_set_source_surface (cr, img, 0 , 0 );
747
+ cairo_paint (cr);
748
+
749
+ cairo_restore (cr);
750
+ cairo_surface_destroy (img);
751
+ }
752
+
698
753
// ////////////////////////////////////////////////////////////////////////
699
754
700
755
cairo_dev::cairo_dev ( simpledib::dib* dib )
0 commit comments