[gtk+/wip/css: 19/37] css: Implement support for angles



commit 8d9a223810600bb4b9046e9326032644d3f80fe1
Author: Benjamin Otte <otte redhat com>
Date:   Sun Jan 15 17:51:58 2012 +0100

    css: Implement support for angles

 gtk/gtkcssparser.c        |   20 ++++++++++++--------
 gtk/gtkcssparserprivate.h |    3 ++-
 gtk/gtkcsstypes.c         |   19 ++++++++++++++++++-
 gtk/gtkcsstypesprivate.h  |    7 ++++++-
 4 files changed, 38 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkcssparser.c b/gtk/gtkcssparser.c
index 6c36253..67637de 100644
--- a/gtk/gtkcssparser.c
+++ b/gtk/gtkcssparser.c
@@ -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;
 
diff --git a/gtk/gtkcssparserprivate.h b/gtk/gtkcssparserprivate.h
index e5661d5..39002a9 100644
--- a/gtk/gtkcssparserprivate.h
+++ b/gtk/gtkcssparserprivate.h
@@ -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;
diff --git a/gtk/gtkcsstypes.c b/gtk/gtkcsstypes.c
index 2cb8833..d714095 100644
--- a/gtk/gtkcsstypes.c
+++ b/gtk/gtkcsstypes.c
@@ -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);
diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h
index 493978f..94f0d3c 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -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;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]