Commit 0c140daf authored by Benjamin Otte's avatar Benjamin Otte

css: Implement support for angles

parent a63ff724
......@@ -546,14 +546,18 @@ _gtk_css_parser_read_number (GtkCssParser *parser,
GtkCssUnit unit;
GtkCssNumberParseFlags required_flags;
} units[] = {
{ "px", GTK_CSS_PX, GTK_CSS_PARSE_LENGTH },
{ "pt", GTK_CSS_PT, GTK_CSS_PARSE_LENGTH },
{ "em", GTK_CSS_EM, GTK_CSS_PARSE_LENGTH },
{ "ex", GTK_CSS_EX, GTK_CSS_PARSE_LENGTH },
{ "pc", GTK_CSS_PC, GTK_CSS_PARSE_LENGTH },
{ "in", GTK_CSS_IN, GTK_CSS_PARSE_LENGTH },
{ "cm", GTK_CSS_CM, GTK_CSS_PARSE_LENGTH },
{ "mm", GTK_CSS_MM, GTK_CSS_PARSE_LENGTH }
{ "px", GTK_CSS_PX, GTK_CSS_PARSE_LENGTH },
{ "pt", GTK_CSS_PT, GTK_CSS_PARSE_LENGTH },
{ "em", GTK_CSS_EM, GTK_CSS_PARSE_LENGTH },
{ "ex", GTK_CSS_EX, GTK_CSS_PARSE_LENGTH },
{ "pc", GTK_CSS_PC, GTK_CSS_PARSE_LENGTH },
{ "in", GTK_CSS_IN, GTK_CSS_PARSE_LENGTH },
{ "cm", GTK_CSS_CM, GTK_CSS_PARSE_LENGTH },
{ "mm", GTK_CSS_MM, GTK_CSS_PARSE_LENGTH },
{ "rad", GTK_CSS_RAD, GTK_CSS_PARSE_ANGLE },
{ "deg", GTK_CSS_DEG, GTK_CSS_PARSE_ANGLE },
{ "grad", GTK_CSS_GRAD, GTK_CSS_PARSE_ANGLE },
{ "turn", GTK_CSS_TURN, GTK_CSS_PARSE_ANGLE }
};
char *end, *unit;
......
......@@ -30,7 +30,8 @@ typedef enum /*< skip >*/ {
GTK_CSS_PARSE_PERCENT = (1 << 1),
GTK_CSS_PARSE_NUMBER = (1 << 2),
GTK_CSS_NUMBER_AS_PIXELS = (1 << 3),
GTK_CSS_PARSE_LENGTH = (1 << 4)
GTK_CSS_PARSE_LENGTH = (1 << 4),
GTK_CSS_PARSE_ANGLE = (1 << 5)
} GtkCssNumberParseFlags;
typedef struct _GtkCssParser GtkCssParser;
......
......@@ -76,6 +76,7 @@ _gtk_css_number_compute (GtkCssNumber *dest,
case GTK_CSS_PERCENT:
case GTK_CSS_NUMBER:
case GTK_CSS_PX:
case GTK_CSS_DEG:
dest->value = src->value;
dest->unit = src->unit;
break;
......@@ -108,6 +109,18 @@ _gtk_css_number_compute (GtkCssNumber *dest,
dest->value = src->value * g_value_get_double (_gtk_style_context_peek_property (context, "font-size"));
dest->unit = GTK_CSS_PX;
break;
case GTK_CSS_RAD:
dest->value = 360 * src->value / (2 * G_PI);
dest->unit = GTK_CSS_DEG;
break;
case GTK_CSS_GRAD:
dest->value = 360 * src->value / 400.0;
dest->unit = GTK_CSS_DEG;
break;
case GTK_CSS_TURN:
dest->value = 360 * src->value;
dest->unit = GTK_CSS_DEG;
break;
}
}
......@@ -130,7 +143,11 @@ _gtk_css_number_print (const GtkCssNumber *number,
/* [GTK_CSS_PC] = */ "pc",
/* [GTK_CSS_IN] = */ "in",
/* [GTK_CSS_CM] = */ "cm",
/* [GTK_CSS_MM] = */ "mm"
/* [GTK_CSS_MM] = */ "mm",
/* [GTK_CSS_RAD] = */ "rad",
/* [GTK_CSS_DEG] = */ "deg",
/* [GTK_CSS_GRAD] = */ "grad",
/* [GTK_CSS_TURN] = */ "turn",
};
g_ascii_dtostr (buf, sizeof (buf), number->value);
......
......@@ -91,7 +91,12 @@ typedef enum /*< skip >*/ {
GTK_CSS_PC,
GTK_CSS_IN,
GTK_CSS_CM,
GTK_CSS_MM
GTK_CSS_MM,
/* CSS term: <angle> */
GTK_CSS_RAD,
GTK_CSS_DEG,
GTK_CSS_GRAD,
GTK_CSS_TURN
} GtkCssUnit;
typedef struct _GtkCssNumber GtkCssNumber;
......
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