1
1
#include " test_container.h"
2
2
#include " Font.h"
3
+ #include " litehtml/types.h"
4
+ #include < fstream>
5
+ #include < sstream>
3
6
#define CANVAS_ITY_IMPLEMENTATION
4
7
#include " canvas_ity.hpp"
5
- string readfile (string filename);
8
+
9
+ string readfile (string filename)
10
+ {
11
+ std::stringstream ss;
12
+ std::ifstream (filename) >> ss.rdbuf ();
13
+ return ss.str ();
14
+ }
6
15
7
16
//
8
17
// canvas_ity adapters
@@ -54,7 +63,7 @@ void clip_rect(canvas& cvs, rect r)
54
63
}
55
64
56
65
// without scaling
57
- void draw_image (canvas& cvs, int x, int y, const Bitmap& bmp)
66
+ void draw_image (canvas& cvs, pixel_t x, pixel_t y, const Bitmap& bmp)
58
67
{
59
68
cvs.draw_image ((byte*)bmp.data .data (), bmp.width , bmp.height , bmp.width * 4 , (float )x, (float )y, (float )bmp.width , (float )bmp.height );
60
69
}
@@ -87,24 +96,24 @@ void fill_polygon(canvas& cvs, vector<xy> points, color color)
87
96
// test_container implementation
88
97
//
89
98
90
- uint_ptr test_container::create_font (const char * font_families, int size, int weight, font_style /* italic */ , unsigned int /* decoration */ , font_metrics* fm)
99
+ uint_ptr test_container::create_font (const font_description& descr, const document*, litehtml:: font_metrics* fm)
91
100
{
92
101
Font* font = 0 ;
93
- string_vector fonts = split_string (font_families , " ," , " " , " " );
102
+ string_vector fonts = split_string (descr. family , " ," , " " , " " );
94
103
for (auto name : fonts)
95
104
{
96
- font = Font::create (name, size, weight);
105
+ font = Font::create (name, ( int ) descr. size , descr. weight );
97
106
if (font) break ;
98
107
}
99
108
if (!font)
100
- font = Font::create (get_default_font_name (), size, weight);
109
+ font = Font::create (get_default_font_name (), ( int ) descr. size , descr. weight );
101
110
102
111
if (fm) *fm = *font;
103
112
104
113
return (uint_ptr)font;
105
114
}
106
115
107
- int test_container::text_width (const char * text, uint_ptr hFont)
116
+ pixel_t test_container::text_width (const char * text, uint_ptr hFont)
108
117
{
109
118
Font* font = (Font*)hFont;
110
119
return font->text_width (text);
@@ -113,11 +122,11 @@ int test_container::text_width(const char* text, uint_ptr hFont)
113
122
void test_container::draw_text (uint_ptr hdc, const char * text, uint_ptr hFont, web_color color, const position& pos)
114
123
{
115
124
Font* font = (Font*)hFont;
116
- font->draw_text (*(canvas*)hdc, text, color, pos.x , pos.y );
125
+ font->draw_text (*(canvas*)hdc, text, color, ( int ) pos.x , ( int ) pos.y );
117
126
}
118
127
119
- int test_container::pt_to_px (int pt) const { return pt * 96 / 72 ; }
120
- int test_container::get_default_font_size () const { return 16 ; }
128
+ pixel_t test_container::pt_to_px (pixel_t pt) const { return pt * 96 / 72 ; }
129
+ pixel_t test_container::get_default_font_size () const { return 16 ; }
121
130
const char * test_container::get_default_font_name () const { return " Terminus" ; }
122
131
123
132
void test_container::draw_solid_fill (uint_ptr hdc, const background_layer& layer, const web_color& color)
@@ -128,7 +137,7 @@ void test_container::draw_solid_fill(uint_ptr hdc, const background_layer& layer
128
137
129
138
void test_container::draw_borders (uint_ptr hdc, const borders& borders, const position& pos, bool /* root*/ )
130
139
{
131
- canvas img (pos.width , pos.height );
140
+ canvas img (( int ) pos.width , ( int ) pos.height );
132
141
img.global_composite_operation = lighter;
133
142
134
143
/*
@@ -223,15 +232,15 @@ void test_container::import_css(string& text, const string& url, string& baseurl
223
232
text = readfile (baseurl);
224
233
}
225
234
226
- void test_container::get_client_rect (position& client) const
235
+ void test_container::get_viewport (position& client) const
227
236
{
228
- client = {0 , 0 , width, height};
237
+ client = {0 , 0 , ( pixel_t ) width, ( pixel_t ) height};
229
238
}
230
239
231
240
void test_container::get_media_features (media_features& media) const
232
241
{
233
242
position client;
234
- get_client_rect (client);
243
+ get_viewport (client);
235
244
media.type = media_type_screen;
236
245
media.width = client.width ;
237
246
media.height = client.height ;
@@ -251,18 +260,18 @@ void test_container::get_image_size(const char* src, const char* baseurl, size&
251
260
{
252
261
string url = make_url (src, baseurl);
253
262
auto & img = images[url];
254
- sz = {img.width , img.height };
263
+ sz = {( pixel_t ) img.width , ( pixel_t ) img.height };
255
264
}
256
265
257
266
void draw_image_pattern (canvas& cvs, const background_layer& bg, const Bitmap& img)
258
267
{
259
268
cvs.save ();
260
269
clip_rect (cvs, bg.clip_box );
261
270
262
- int x = bg.origin_box .x ;
263
- int y = bg.origin_box .y ;
264
- int w = bg.origin_box .width ;
265
- int h = bg.origin_box .height ;
271
+ pixel_t x = bg.origin_box .x ;
272
+ pixel_t y = bg.origin_box .y ;
273
+ pixel_t w = bg.origin_box .width ;
274
+ pixel_t h = bg.origin_box .height ;
266
275
267
276
switch (bg.repeat )
268
277
{
@@ -286,7 +295,7 @@ void draw_image_pattern(canvas& cvs, const background_layer& bg, const Bitmap& i
286
295
while (x > bg.clip_box .left ()) x -= w;
287
296
while (y > bg.clip_box .top ()) y -= h;
288
297
for (; x < bg.clip_box .right (); x += w)
289
- for (int _y = y; _y < bg.clip_box .bottom (); _y += h)
298
+ for (pixel_t _y = y; _y < bg.clip_box .bottom (); _y += h)
290
299
draw_image (cvs, {x, _y, w, h}, img);
291
300
break ;
292
301
}
@@ -330,14 +339,14 @@ void set_gradient(canvas& cvs, const background_layer::conic_gradient& gradient,
330
339
template <class Gradient >
331
340
void draw_gradient (uint_ptr hdc, const background_layer& bg, const Gradient& gradient)
332
341
{
333
- int x = bg.origin_box .x ;
334
- int y = bg.origin_box .y ;
335
- int w = bg.origin_box .width ;
336
- int h = bg.origin_box .height ;
342
+ pixel_t x = bg.origin_box .x ;
343
+ pixel_t y = bg.origin_box .y ;
344
+ pixel_t w = bg.origin_box .width ;
345
+ pixel_t h = bg.origin_box .height ;
337
346
338
- canvas img (w, h);
347
+ canvas img (( int ) w, ( int ) h);
339
348
340
- set_gradient (img, gradient, x, y);
349
+ set_gradient (img, gradient, ( int ) x, ( int ) y);
341
350
342
351
for (auto cs : gradient.color_points )
343
352
add_color_stop (img, fill_style, cs.offset , cs.color , cs.hint );
0 commit comments