From dfbf50683125344885c26d5d7407356d97f54651 Mon Sep 17 00:00:00 2001 From: Lucas Neves Date: Mon, 13 Nov 2017 21:19:03 +0000 Subject: Add support for new length units. --- docs/Bytecode | 13 ++++++++++ include/libcss/types.h | 53 +++++++++++++++++++++++++---------------- src/bytecode/bytecode.h | 13 ++++++++++ src/parse/properties/utils.c | 26 ++++++++++++++++++++ src/select/properties/helpers.c | 13 ++++++++++ 5 files changed, 98 insertions(+), 20 deletions(-) diff --git a/docs/Bytecode b/docs/Bytecode index e857193..f64656a 100644 --- a/docs/Bytecode +++ b/docs/Bytecode @@ -44,6 +44,19 @@ Length is a 32bit numeric value (as described above) and unit is as follows: 00000101 => mm 00000110 => pt 00000111 => pc + 00001000 => cap + 00001001 => ch + 00001010 => ic + 00001011 => rem + 00001100 => lh + 00001101 => rlh + 00001110 => vh + 00001111 => vw + 00010000 => vi + 00010001 => vb + 00010010 => vmin + 00010011 => vmax + 00010100 => q bit 8 set => percentage unit bits 9-31: MBZ diff --git a/include/libcss/types.h b/include/libcss/types.h index ffaf13c..4f35737 100644 --- a/include/libcss/types.h +++ b/include/libcss/types.h @@ -80,26 +80,39 @@ typedef uint32_t css_color; /* CSS unit */ typedef enum css_unit { - CSS_UNIT_PX = 0x0, - CSS_UNIT_EX = 0x1, - CSS_UNIT_EM = 0x2, - CSS_UNIT_IN = 0x3, - CSS_UNIT_CM = 0x4, - CSS_UNIT_MM = 0x5, - CSS_UNIT_PT = 0x6, - CSS_UNIT_PC = 0x7, - - CSS_UNIT_PCT = 0x8, /* Percentage */ - - CSS_UNIT_DEG = 0x9, - CSS_UNIT_GRAD = 0xa, - CSS_UNIT_RAD = 0xb, - - CSS_UNIT_MS = 0xc, - CSS_UNIT_S = 0xd, - - CSS_UNIT_HZ = 0xe, - CSS_UNIT_KHZ = 0xf + CSS_UNIT_PX = 0x00, + CSS_UNIT_EX = 0x01, + CSS_UNIT_EM = 0x02, + CSS_UNIT_IN = 0x03, + CSS_UNIT_CM = 0x04, + CSS_UNIT_MM = 0x05, + CSS_UNIT_PT = 0x06, + CSS_UNIT_PC = 0x07, + CSS_UNIT_CAP = 0x08, + CSS_UNIT_CH = 0x09, + CSS_UNIT_IC = 0x0a, + CSS_UNIT_REM = 0x0b, + CSS_UNIT_LH = 0x0c, + CSS_UNIT_RLH = 0x0d, + CSS_UNIT_VH = 0x0e, + CSS_UNIT_VW = 0x0f, + CSS_UNIT_VI = 0x10, + CSS_UNIT_VB = 0x11, + CSS_UNIT_VMIN = 0x12, + CSS_UNIT_VMAX = 0x13, + CSS_UNIT_Q = 0x14, + + CSS_UNIT_PCT = 0x15, /* Percentage */ + + CSS_UNIT_DEG = 0x16, + CSS_UNIT_GRAD = 0x17, + CSS_UNIT_RAD = 0x18, + + CSS_UNIT_MS = 0x19, + CSS_UNIT_S = 0x1a, + + CSS_UNIT_HZ = 0x1b, + CSS_UNIT_KHZ = 0x1c } css_unit; /** diff --git a/src/bytecode/bytecode.h b/src/bytecode/bytecode.h index 656d7a5..422f141 100644 --- a/src/bytecode/bytecode.h +++ b/src/bytecode/bytecode.h @@ -32,6 +32,19 @@ typedef enum unit { UNIT_MM = 5, UNIT_PT = 6, UNIT_PC = 7, + UNIT_CAP = 8, + UNIT_CH = 9, + UNIT_IC = 10, + UNIT_REM = 11, + UNIT_LH = 12, + UNIT_RLH = 13, + UNIT_VH = 14, + UNIT_VW = 15, + UNIT_VI = 16, + UNIT_VB = 17, + UNIT_VMIN = 18, + UNIT_VMAX = 19, + UNIT_Q = 20, UNIT_PCT = (1 << 8), diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c index 47b06e3..76b406b 100644 --- a/src/parse/properties/utils.c +++ b/src/parse/properties/utils.c @@ -1007,6 +1007,10 @@ css_error css__parse_unit_keyword(const char *ptr, size_t len, uint32_t *unit) if (len == 4) { if (strncasecmp(ptr, "grad", 4) == 0) *unit = UNIT_GRAD; + else if (strncasecmp(ptr, "vmin", 4) == 0) + *unit = UNIT_VMIN; + else if (strncasecmp(ptr, "vmax", 4) == 0) + *unit = UNIT_VMAX; else return CSS_INVALID; } else if (len == 3) { @@ -1016,6 +1020,12 @@ css_error css__parse_unit_keyword(const char *ptr, size_t len, uint32_t *unit) *unit = UNIT_DEG; else if (strncasecmp(ptr, "rad", 3) == 0) *unit = UNIT_RAD; + else if (strncasecmp(ptr, "cap", 3) == 0) + *unit = UNIT_CAP; + else if (strncasecmp(ptr, "rem", 3) == 0) + *unit = UNIT_REM; + else if (strncasecmp(ptr, "rlh", 3) == 0) + *unit = UNIT_RLH; else return CSS_INVALID; } else if (len == 2) { @@ -1039,11 +1049,27 @@ css_error css__parse_unit_keyword(const char *ptr, size_t len, uint32_t *unit) *unit = UNIT_PT; else if (strncasecmp(ptr, "pc", 2) == 0) *unit = UNIT_PC; + else if (strncasecmp(ptr, "ch", 2) == 0) + *unit = UNIT_CH; + else if (strncasecmp(ptr, "ic", 2) == 0) + *unit = UNIT_IC; + else if (strncasecmp(ptr, "lh", 2) == 0) + *unit = UNIT_LH; + else if (strncasecmp(ptr, "vh", 2) == 0) + *unit = UNIT_VH; + else if (strncasecmp(ptr, "vw", 2) == 0) + *unit = UNIT_VW; + else if (strncasecmp(ptr, "vi", 2) == 0) + *unit = UNIT_VI; + else if (strncasecmp(ptr, "vb", 2) == 0) + *unit = UNIT_VB; else return CSS_INVALID; } else if (len == 1) { if (strncasecmp(ptr, "s", 1) == 0) *unit = UNIT_S; + else if (strncasecmp(ptr, "q", 1) == 0) + *unit = UNIT_Q; else return CSS_INVALID; } else diff --git a/src/select/properties/helpers.c b/src/select/properties/helpers.c index 36c3cba..5893919 100644 --- a/src/select/properties/helpers.c +++ b/src/select/properties/helpers.c @@ -29,6 +29,19 @@ css_unit css__to_css_unit(uint32_t u) case UNIT_MM: return CSS_UNIT_MM; case UNIT_PT: return CSS_UNIT_PT; case UNIT_PC: return CSS_UNIT_PC; + case UNIT_CAP: return CSS_UNIT_CAP; + case UNIT_CH: return CSS_UNIT_CH; + case UNIT_IC: return CSS_UNIT_IC; + case UNIT_REM: return CSS_UNIT_REM; + case UNIT_LH: return CSS_UNIT_LH; + case UNIT_RLH: return CSS_UNIT_RLH; + case UNIT_VH: return CSS_UNIT_VH; + case UNIT_VW: return CSS_UNIT_VW; + case UNIT_VI: return CSS_UNIT_VI; + case UNIT_VB: return CSS_UNIT_VB; + case UNIT_VMIN: return CSS_UNIT_VMIN; + case UNIT_VMAX: return CSS_UNIT_VMAX; + case UNIT_Q: return CSS_UNIT_Q; case UNIT_PCT: return CSS_UNIT_PCT; case UNIT_DEG: return CSS_UNIT_DEG; case UNIT_GRAD: return CSS_UNIT_GRAD; -- cgit v1.2.3