diff --git a/.gitignore b/.gitignore index bc115012..3b90d3af 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ testStrokeLine testLinearGradient testRadialGradient testGradientTransform +testSvg +testSvg2 diff --git a/inc/tizenvg.h b/inc/tizenvg.h index abb08d67..c62dda2f 100644 --- a/inc/tizenvg.h +++ b/inc/tizenvg.h @@ -71,6 +71,7 @@ enum class TVG_EXPORT StrokeJoin { Bevel = 0, Round, Miter }; enum class TVG_EXPORT FillSpread { Pad = 0, Reflect, Repeat }; enum class TVG_EXPORT CanvasEngine { Sw = 0, Gl }; + struct Point { float x, y; @@ -282,6 +283,9 @@ public: Result push(std::unique_ptr paint) noexcept; Result reserve(uint32_t size) noexcept; + Result load(const std::string& path, float w, float h, bool lazy = false) noexcept; + Result save(const std::string& path) noexcept; + Result rotate(float degree) noexcept override; Result scale(float factor) noexcept override; Result translate(float x, float y) noexcept override; diff --git a/src/lib/tvgScene.cpp b/src/lib/tvgScene.cpp index 1ce0ada4..c0939332 100644 --- a/src/lib/tvgScene.cpp +++ b/src/lib/tvgScene.cpp @@ -107,4 +107,27 @@ Result Scene::bounds(float* x, float* y, float* w, float* h) const noexcept return Result::Success; } + +Result Scene::load(const std::string& path, float w, float h, bool lazy) noexcept +{ + if (path.empty()) return Result::InvalidArguments; + + auto impl = pImpl.get(); + if (!impl) return Result::MemoryCorruption; + + return impl->load(path, w, h, lazy); +} + + +Result Scene::save(const std::string& path) noexcept +{ + if (path.empty()) return Result::InvalidArguments; + + auto impl = pImpl.get(); + if (!impl) return Result::MemoryCorruption; + + return impl->save(path); +} + + #endif /* _TVG_SCENE_CPP_ */ \ No newline at end of file diff --git a/src/lib/tvgSceneImpl.h b/src/lib/tvgSceneImpl.h index 2c92d5b5..5ba8d510 100644 --- a/src/lib/tvgSceneImpl.h +++ b/src/lib/tvgSceneImpl.h @@ -191,6 +191,16 @@ struct Scene::Impl return true; } + + Result load(const string& path, float w, float h, bool lazy) + { + return Result::Success; + } + + Result save(const string& path) + { + return Result::Success; + } }; #endif //_TVG_SCENE_IMPL_H_ \ No newline at end of file diff --git a/test/makefile b/test/makefile index 431fa665..8dce9e9b 100644 --- a/test/makefile +++ b/test/makefile @@ -15,3 +15,5 @@ all: gcc -o testLinearGradient testLinearGradient.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` gcc -o testRadialGradient testRadialGradient.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` gcc -o testGradientTransform testGradientTransform.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` + gcc -o testSvg testSvg.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` + gcc -o testSvg2 testSvg2.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` diff --git a/test/testSvg.cpp b/test/testSvg.cpp new file mode 100644 index 00000000..dea96a2e --- /dev/null +++ b/test/testSvg.cpp @@ -0,0 +1,63 @@ +#include +#include + +using namespace std; + +#define WIDTH 800 +#define HEIGHT 800 + +static uint32_t buffer[WIDTH * HEIGHT]; + +void tvgtest() +{ + //Initialize TizenVG Engine + tvg::Initializer::init(tvg::CanvasEngine::Sw); + + //Create a Canvas + auto canvas = tvg::SwCanvas::gen(); + canvas->target(buffer, WIDTH, WIDTH, HEIGHT); + + /* Create a SVG scene, keep original size, + You can pass 0 x 0 size for lazying loading in this case. + scene->load("sample.svg", 0, 0, true); */ + auto scene = tvg::Scene::gen(); + scene->load("sample.svg"); + canvas->push(move(scene)); + + canvas->draw(); + canvas->sync(); + + //Terminate TizenVG Engine + tvg::Initializer::term(tvg::CanvasEngine::Sw); +} + +void +win_del(void *data, Evas_Object *o, void *ev) +{ + elm_exit(); +} + + +int main(int argc, char **argv) +{ + tvgtest(); + + //Show the result using EFL... + elm_init(argc, argv); + + Eo* win = elm_win_util_standard_add(NULL, "TizenVG Test"); + evas_object_smart_callback_add(win, "delete,request", win_del, 0); + + Eo* img = evas_object_image_filled_add(evas_object_evas_get(win)); + evas_object_image_size_set(img, WIDTH, HEIGHT); + evas_object_image_data_set(img, buffer); + evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(img); + + elm_win_resize_object_add(win, img); + evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT); + evas_object_show(win); + + elm_run(); + elm_shutdown(); +} diff --git a/test/testSvg2.cpp b/test/testSvg2.cpp new file mode 100644 index 00000000..4714db6b --- /dev/null +++ b/test/testSvg2.cpp @@ -0,0 +1,67 @@ +#include +#include + +using namespace std; + +#define WIDTH 800 +#define HEIGHT 800 + +static uint32_t buffer[WIDTH * HEIGHT]; + +void tvgtest() +{ + //Initialize TizenVG Engine + tvg::Initializer::init(tvg::CanvasEngine::Sw); + + //Create a Canvas + auto canvas = tvg::SwCanvas::gen(); + canvas->target(buffer, WIDTH, WIDTH, HEIGHT); + + //Create a SVG scene, keep aspect ratio to width/2 with lazy loading + auto scene = tvg::Scene::gen(); + scene->load("sample.svg", WIDTH/2, 0, true); + canvas->push(move(scene)); + + //Create a SVG scene, keep aspect ratio to height/2 with lazy loading + auto scene2 = tvg::Scene::gen(); + scene2->load("sample.svg", 0, HEIGHT/2, true); + scene2->translate(WIDTH/2, HEIGHT/2); + canvas->push(move(scene2)); + + canvas->draw(); + canvas->sync(); + + //Terminate TizenVG Engine + tvg::Initializer::term(tvg::CanvasEngine::Sw); +} + +void +win_del(void *data, Evas_Object *o, void *ev) +{ + elm_exit(); +} + + +int main(int argc, char **argv) +{ + tvgtest(); + + //Show the result using EFL... + elm_init(argc, argv); + + Eo* win = elm_win_util_standard_add(NULL, "TizenVG Test"); + evas_object_smart_callback_add(win, "delete,request", win_del, 0); + + Eo* img = evas_object_image_filled_add(evas_object_evas_get(win)); + evas_object_image_size_set(img, WIDTH, HEIGHT); + evas_object_image_data_set(img, buffer); + evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(img); + + elm_win_resize_object_add(win, img); + evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT); + evas_object_show(win); + + elm_run(); + elm_shutdown(); +}