summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--testfiles/src/object-style-test.cpp66
1 files changed, 65 insertions, 1 deletions
diff --git a/testfiles/src/object-style-test.cpp b/testfiles/src/object-style-test.cpp
index b23bc5e66..391c5874a 100644
--- a/testfiles/src/object-style-test.cpp
+++ b/testfiles/src/object-style-test.cpp
@@ -28,12 +28,19 @@ public:
rect { fill: #808080; opacity:0.5; }\
.extra { opacity:1.0; }\
.overload { fill: #d0d0d0 !important; stroke: #c0c0c0 !important; }\
+.font { font: italic bold 12px/30px Georgia, serif; }\
+.exsize { stroke-width: 1ex; }\
+.fosize { font-size: 15px; }\
</style>\
-<g style='fill:blue; stroke-width:2px'>\
+<g style='fill:blue; stroke-width:2px;font-size: 14px;'>\
<rect id='one' style='fill:red; stroke:green;'/>\
<rect id='two' style='stroke:green; stroke-width:4px;'/>\
<rect id='three' class='extra' style='fill: #cccccc;'/>\
<rect id='four' class='overload' style='fill:green;stroke:red !important;'/>\
+ <rect id='five' class='font' style='font: 15px arial, sans-serif;'/>/\
+ <rect id='six' style='stroke-width:1em;'/>\
+ <rect id='seven' class='exsize'/>\
+ <rect id='eight' class='fosize' style='stroke-width: 50%;'/>\
</g>\
</svg>";
doc = SPDocument::createNewDocFromMem(docString, static_cast<int>(strlen(docString)), false);
@@ -46,6 +53,9 @@ rect { fill: #808080; opacity:0.5; }\
SPDocument *doc;
};
+/*
+ * Test basic cascade values, that they are set correctly as we'd want to see them.
+ */
TEST_F(ObjectTest, Styles) {
ASSERT_TRUE(doc != nullptr);
ASSERT_TRUE(doc->getRoot() != nullptr);
@@ -88,6 +98,9 @@ TEST_F(ObjectTest, Styles) {
EXPECT_EQ(four->style->stroke_width.get_value(), Glib::ustring("2px"));
}
+/*
+ * Test the origin flag for each of the values, should indicate where it came from.
+ */
TEST_F(ObjectTest, StyleSource) {
ASSERT_TRUE(doc != nullptr);
ASSERT_TRUE(doc->getRoot() != nullptr);
@@ -127,5 +140,56 @@ TEST_F(ObjectTest, StyleSource) {
EXPECT_EQ(four->style->stroke.style_src, SP_STYLE_SRC_STYLE_PROP);
EXPECT_EQ(four->style->opacity.style_src, SP_STYLE_SRC_STYLE_SHEET);
EXPECT_EQ(four->style->stroke_width.style_src, SP_STYLE_SRC_STYLE_PROP);
+}
+
+/*
+ * Test the breaking up of the font property and recreation into seperate properties.
+ */
+TEST_F(ObjectTest, StyleFont) {
+ ASSERT_TRUE(doc != nullptr);
+ ASSERT_TRUE(doc->getRoot() != nullptr);
+
+ SPRoot *root = doc->getRoot();
+ ASSERT_TRUE(root->getRepr() != nullptr);
+ ASSERT_TRUE(root->hasChildren());
+
+ SPRect *five = dynamic_cast<SPRect *>(doc->getObjectById("five"));
+ ASSERT_TRUE(five != nullptr);
+
+ // Font property is ALWAYS unset as it's converted into specific font css properties
+ EXPECT_EQ(five->style->font.get_value(), Glib::ustring(""));
+ EXPECT_EQ(five->style->font_size.get_value(), Glib::ustring("12px"));
+ EXPECT_EQ(five->style->font_weight.get_value(), Glib::ustring("bold"));
+ EXPECT_EQ(five->style->font_style.get_value(), Glib::ustring("italic"));
+ EXPECT_EQ(five->style->font_family.get_value(), Glib::ustring("arial, sans-serif"));
+}
+
+/*
+ * Test the consumption of font dependant lengths in SPILength, e.g. EM, EX and % units
+ */
+TEST_F(ObjectTest, StyleFontSizes) {
+ ASSERT_TRUE(doc != nullptr);
+ ASSERT_TRUE(doc->getRoot() != nullptr);
+
+ SPRoot *root = doc->getRoot();
+ ASSERT_TRUE(root->getRepr() != nullptr);
+ ASSERT_TRUE(root->hasChildren());
+
+ SPRect *six = dynamic_cast<SPRect *>(doc->getObjectById("six"));
+ ASSERT_TRUE(six != nullptr);
+
+ EXPECT_EQ(six->style->stroke_width.get_value(), Glib::ustring("1em"));
+ EXPECT_EQ(six->style->stroke_width.computed, 14);
+
+ SPRect *seven = dynamic_cast<SPRect *>(doc->getObjectById("seven"));
+ ASSERT_TRUE(seven != nullptr);
+
+ EXPECT_EQ(seven->style->stroke_width.get_value(), Glib::ustring("1ex"));
+ EXPECT_EQ(seven->style->stroke_width.computed, 7);
+
+ SPRect *eight = dynamic_cast<SPRect *>(doc->getObjectById("eight"));
+ ASSERT_TRUE(eight != nullptr);
+ EXPECT_EQ(eight->style->stroke_width.get_value(), Glib::ustring("50%"));
+ EXPECT_EQ(eight->style->stroke_width.computed, 1); // Is this right?
}