diff --git a/CMakeLists.txt b/CMakeLists.txt index 37802d3..6c47ad7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,7 @@ dmod_add_library(${DMOD_MODULE_NAME} ${DMOD_MODULE_VERSION} src/style.c src/layout.c src/paint.c + src/svg.c src/script.c ) diff --git a/Makefile b/Makefile index d5f558a..519e4ca 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ DMOD_MODULE_VERSION=0.1 DMOD_AUTHOR_NAME=Patryk Kubiak # The list of C sources -DMOD_CSOURCES=src/dmvs_html.c src/html.c src/css.c src/tailwind.c src/style.c src/layout.c src/paint.c src/script.c +DMOD_CSOURCES=src/dmvs_html.c src/html.c src/css.c src/tailwind.c src/style.c src/layout.c src/paint.c src/svg.c src/script.c # The list of C++ sources DMOD_CXXSOURCES= diff --git a/README.md b/README.md index 1079b19..3e9ac91 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,9 @@ it works out at conversion and makes the view's variables and handlers. **HTML** - elements, attributes, text with character references, the end tags a page may leave out, `
" + "" + "" + "
" + "
")); + dmvsi_doc_t doc = convert(TEST_FILE("images.html"), "screen", 0, 0, &status); + DMOD_TEST_EXPECT_EQ(status, 0); + if (doc == NULL) + return; + + /* The : a file of its own, sized as its box, its viewBox and camelCase names kept */ + const dmvsi_node_t* svg = nth_image(doc, 0); + DMOD_TEST_EXPECT_TRUE(svg != NULL && svg->u.image.rect.w == DMVSI_PX(40) && svg->u.image.rect.h == DMVSI_PX(40)); + if (svg != NULL) + { + size_t n = strlen(svg->u.image.path); + DMOD_TEST_EXPECT_TRUE(n > 4 && strcmp(svg->u.image.path + n - 4, ".svg") == 0); + DMOD_TEST_EXPECT_TRUE(file_has(svg->u.image.path, "width=\"40\" height=\"40\" viewBox=\"0 0 10 10\"")); + DMOD_TEST_EXPECT_TRUE(file_has(svg->u.image.path, "")); + DMOD_TEST_EXPECT_TRUE(file_has(svg->u.image.path, "fill=\"#000000\"")); /* currentColor */ + } + + /* object-fit: cover - 100 x 50 into 40 x 40: 80 x 40, in the middle */ + const dmvsi_node_t* img = nth_image(doc, 1); + DMOD_TEST_EXPECT_TRUE(img != NULL && img->u.image.width == DMVSI_PX(80) && img->u.image.height == DMVSI_PX(40)); + DMOD_TEST_EXPECT_TRUE(img != NULL && img->u.image.flags == (DMVSI_IMAGE_CENTER | DMVSI_IMAGE_MIDDLE)); + + /* background: url() right bottom / contain, blurred - 40 x 20 at the bottom right, blur 4 px */ + const dmvsi_node_t* bg = nth_image(doc, 2); + DMOD_TEST_EXPECT_TRUE(bg != NULL && bg->u.image.width == DMVSI_PX(40) && bg->u.image.height == DMVSI_PX(20)); + DMOD_TEST_EXPECT_TRUE(bg != NULL && bg->u.image.flags == (DMVSI_IMAGE_RIGHT | DMVSI_IMAGE_BOTTOM)); + DMOD_TEST_EXPECT_TRUE(bg != NULL && bg->u.image.blur == DMVSI_PX(4)); + dmvsi_free(doc); +} + +DMOD_TEST_STEP(dmvs_html_converts_listeners) +{ + int status = -1; + DMOD_TEST_EXPECT_TRUE(write_file(TEST_FILE("listeners.html"), + "
" + "
" + "
")); + dmvsi_doc_t doc = convert(TEST_FILE("listeners.html"), "screen", 0, 0, &status); + DMOD_TEST_EXPECT_EQ(status, 0); + if (doc == NULL) + return; + const dmvsi_node_t* root = dmvsi_root(doc); + + /* forEach is unrolled: each tab is clicked with a handler of its own, and looks active by a variable */ + const dmvsi_node_t* a = group_named(root->first, "a"); + const dmvsi_node_t* b = group_named(root->first, "b"); + DMOD_TEST_EXPECT_TRUE(a != NULL && b != NULL && a->click != 0 && b->click != 0 && a->click != b->click); + if (a != NULL && b != NULL) + { + const dmvsi_action_t* acts = NULL; + uint32_t n = dmvsi_handler_actions(doc, b->click, &acts); + bool sets = false; + for (uint32_t i = 0; i < n; i++) + sets = sets || acts[i].kind == DMVSI_ACT_SET; + DMOD_TEST_EXPECT_TRUE(sets); + } + dmvsi_free(doc); +}