test: Improve svg test
[platform/core/graphics/tizenvg.git] / test / testSvg.cpp
1 #include <thorvg.h>
2 #include <Elementary.h>
3
4 using namespace std;
5
6 #define WIDTH 800
7 #define HEIGHT 800
8
9 static uint32_t buffer[WIDTH * HEIGHT];
10
11 unique_ptr<tvg::SwCanvas> canvas = nullptr;
12 int count = 0;
13 static const int numberPerLine = 3;
14
15 static int x = 30;
16 static int y = 30;
17
18
19 void svgDirCallback(const char* name, const char* path, void* data)
20 {
21     auto scene = tvg::Scene::gen();
22     char buf[255];
23     sprintf(buf,"%s/%s", path, name);
24     scene->load(buf);
25     printf("SVG Load : %s\n", buf);
26     scene->translate(((WIDTH - (x * 2)) / numberPerLine) * (count % numberPerLine) + x, ((HEIGHT - (y * 2))/ numberPerLine) * (int)((float)count / (float)numberPerLine) + y);
27     canvas->push(move(scene));
28     count++;
29 }
30
31
32 void win_del(void* data, Evas_Object* o, void* ev)
33 {
34    elm_exit();
35 }
36
37
38 int main(int argc, char** argv)
39 {
40     //Initialize ThorVG Engine
41     tvg::Initializer::init(tvg::CanvasEngine::Sw);
42
43     //Create a Canvas
44     canvas = tvg::SwCanvas::gen();
45     canvas->target(buffer, WIDTH, WIDTH, HEIGHT);
46
47     //Draw white background
48     auto scene = tvg::Scene::gen();
49     auto shape1 = tvg::Shape::gen();
50     shape1->appendRect(0, 0, WIDTH, HEIGHT, 0);
51     shape1->fill(255, 255, 255, 255);
52     scene->push(move(shape1));
53     canvas->push(move(scene));
54
55     eina_file_dir_list("./svgs", EINA_TRUE, svgDirCallback, NULL);
56
57     canvas->draw();
58     canvas->sync();
59
60     //Show the result using EFL...
61     elm_init(argc, argv);
62
63     Eo* win = elm_win_util_standard_add(NULL, "ThorVG Test");
64     evas_object_smart_callback_add(win, "delete,request", win_del, 0);
65
66     Eo* img = evas_object_image_filled_add(evas_object_evas_get(win));
67     evas_object_image_size_set(img, WIDTH, HEIGHT);
68     evas_object_image_data_set(img, buffer);
69     evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
70     evas_object_show(img);
71
72     elm_win_resize_object_add(win, img);
73     evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT);
74     evas_object_show(win);
75
76     elm_run();
77     elm_shutdown();
78
79     //Terminate ThorVG Engine
80     tvg::Initializer::term(tvg::CanvasEngine::Sw);
81 }