st_theme_node_lookup_time(): Extract function to get the value from the CRTerm

Also, add a test for time values.
parent 2366867d
......@@ -667,6 +667,31 @@ st_theme_node_lookup_double (StThemeNode *node,
return result;
}
static GetFromTermResult
get_time_from_term (CRTerm *term,
double *value)
{
int factor = 1;
if (term->type != TERM_NUMBER)
{
return VALUE_NOT_FOUND;
}
if (term->content.num->type != NUM_TIME_S &&
term->content.num->type != NUM_TIME_MS)
{
return VALUE_NOT_FOUND;
}
if (term->content.num->type == NUM_TIME_S)
factor = 1000;
*value = factor * term->content.num->val;
return VALUE_FOUND;
}
/**
* st_theme_node_lookup_time:
* @node: a #StThemeNode
......@@ -703,26 +728,20 @@ st_theme_node_lookup_time (StThemeNode *node,
if (strcmp (decl->property->stryng->str, property_name) == 0)
{
CRTerm *term = decl->value;
int factor = 1;
if (term->type != TERM_NUMBER)
continue;
if (term->content.num->type != NUM_TIME_S &&
term->content.num->type != NUM_TIME_MS)
continue;
if (term->content.num->type == NUM_TIME_S)
factor = 1000;
*value = factor * term->content.num->val;
result = TRUE;
break;
GetFromTermResult result = get_time_from_term (decl->value, value);
if (result == VALUE_FOUND)
{
return TRUE;
}
else if (result == VALUE_INHERIT)
{
inherit = TRUE;
break;
}
}
}
if (!result && inherit && node->parent_node)
if (inherit && node->parent_node)
result = st_theme_node_lookup_time (node->parent_node, property_name, inherit, value);
return result;
......
......@@ -259,6 +259,26 @@ test_double (void)
g_assert_cmpfloat (value, ==, 42.0);
}
static void
test_time (void)
{
double value;
test = "time";
value = 0.0;
g_assert (st_theme_node_lookup_time (group1, "time-s", FALSE, &value));
g_assert_cmpfloat (value, ==, 42000.0);
value = 0.0;
g_assert (st_theme_node_lookup_time (group1, "time-ms", FALSE, &value));
g_assert_cmpfloat (value, ==, 42000.0);
value = 0.0;
g_assert (st_theme_node_lookup_time (text1, "time-s", TRUE, &value));
g_assert_cmpfloat (value, ==, 42000.0);
}
static void
test_lengths (void)
{
......@@ -603,6 +623,7 @@ main (int argc, char **argv)
test_defaults ();
test_double ();
test_time ();
test_lengths ();
test_classes ();
test_type_inheritance ();
......
......@@ -17,11 +17,15 @@ stage {
font-feature-settings: "tnum";
double-prop: 42.0;
time-s: 42s;
time-ms: 42000ms;
}
#text1 {
background-image: inherit;
double-prop: inherit;
time-s: inherit;
}
.special-text {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment