aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-07-06 22:19:22 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-07-06 22:19:22 +0200
commit79dae260891d6fc2689d82907f8a11be65491776 (patch)
treec16c2050a62b7168d1879f543e31e074e70cc4ad /src
parent00478d5500000df83738d35da3360a89900ee22c (diff)
adjust CssLength
CssLength now stores px and mm values as pure integers similar to what dw::core::style::Length does.
Diffstat (limited to 'src')
-rw-r--r--src/css.hh59
1 files changed, 53 insertions, 6 deletions
diff --git a/src/css.hh b/src/css.hh
index ac9620dc..f948632f 100644
--- a/src/css.hh
+++ b/src/css.hh
@@ -51,14 +51,20 @@ typedef enum {
/*
* Lengths are represented as int in the following way:
*
+ * | <------ integer value ------> |
+ *
+ * +---+ - - - +---+---+- - - - - -+---+---+---+---+
+ * | integer part | type |
* +---+ - - - +---+---+- - - - - -+---+---+---+---+
* | integer part | decimal fraction | type |
* +---+ - - - +---+---+- - - - - -+---+---+---+---+
- * n-1 19 18 3 2 1 0
+ * n-1 15 14 3 2 1 0
*
* | <------ fixed point value ------> |
*
* where type is one of the CSS_LENGTH_TYPE_* values.
+ * CSS_LENGTH_TYPE_PX and CSS_LENGTH_TYPE_MM are stored as
+ * 29 bit signed integer, all other types as fixed point values.
*/
typedef int CssLength;
@@ -76,17 +82,58 @@ typedef enum {
} CssLengthType;
inline CssLength CSS_CREATE_LENGTH (float v, CssLengthType t) {
- return ((int) (v * (1 << 19)) & ~7 ) | t;
-}
-
-inline float CSS_LENGTH_VALUE (CssLength l) {
- return ((float)(l & ~7)) / (1 << 19);
+ static const int CSS_LENGTH_FRAC_MAX = (1 << (32 - 15 - 1)) - 1;
+ static const int CSS_LENGTH_INT_MAX = 1 << (32 - 4) - 1;
+ int iv;
+
+ switch (t) {
+ case CSS_LENGTH_TYPE_PX:
+ case CSS_LENGTH_TYPE_MM:
+ iv = (int) (v + 0.5);
+ if (iv > CSS_LENGTH_INT_MAX)
+ iv = CSS_LENGTH_INT_MAX;
+ else if (iv < -CSS_LENGTH_INT_MAX)
+ iv = -CSS_LENGTH_INT_MAX;
+ return iv << 3 | t;
+ case CSS_LENGTH_TYPE_EM:
+ case CSS_LENGTH_TYPE_EX:
+ case CSS_LENGTH_TYPE_PERCENTAGE:
+ case CSS_LENGTH_TYPE_RELATIVE:
+ if (v > CSS_LENGTH_FRAC_MAX)
+ v = CSS_LENGTH_FRAC_MAX;
+ else if (v < -CSS_LENGTH_FRAC_MAX)
+ v = -CSS_LENGTH_FRAC_MAX;
+ return ((int) (v * (1 << 15)) & ~7 ) | t;
+ case CSS_LENGTH_TYPE_AUTO:
+ return t;
+ default:
+ assert(false);
+ return CSS_LENGTH_TYPE_AUTO;
+ }
}
inline CssLengthType CSS_LENGTH_TYPE (CssLength l) {
return (CssLengthType) (l & 7);
}
+inline float CSS_LENGTH_VALUE (CssLength l) {
+ switch (CSS_LENGTH_TYPE(l)) {
+ case CSS_LENGTH_TYPE_PX:
+ case CSS_LENGTH_TYPE_MM:
+ return (float) (l >> 3);
+ case CSS_LENGTH_TYPE_EM:
+ case CSS_LENGTH_TYPE_EX:
+ case CSS_LENGTH_TYPE_PERCENTAGE:
+ case CSS_LENGTH_TYPE_RELATIVE:
+ return ((float)(l & ~7)) / (1 << 15);
+ case CSS_LENGTH_TYPE_AUTO:
+ return 0.0;
+ default:
+ assert(false);
+ return 0.0;
+ }
+}
+
typedef enum {
CSS_PROPERTY_BACKGROUND_ATTACHMENT,
CSS_PROPERTY_BACKGROUND_COLOR,