summaryrefslogtreecommitdiff
path: root/test/select-auto.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-07-04 17:09:07 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-07-04 17:09:07 +0000
commit081c8b365001d9ec9df0f06ba5025dd621c8e4ec (patch)
treebeaa0c8a0243a2cb50e869282565033bcdcba6a6 /test/select-auto.c
parenta3105d297fa8bb6bc8728d60a21b662d867688ae (diff)
downloadlibcss-081c8b365001d9ec9df0f06ba5025dd621c8e4ec.tar.gz
libcss-081c8b365001d9ec9df0f06ba5025dd621c8e4ec.tar.bz2
Add callback to make client compute the font size.
Some progress towards computing absolute values. svn path=/trunk/libcss/; revision=8311
Diffstat (limited to 'test/select-auto.c')
-rw-r--r--test/select-auto.c67
1 files changed, 66 insertions, 1 deletions
diff --git a/test/select-auto.c b/test/select-auto.c
index fed6204..c52cb0a 100644
--- a/test/select-auto.c
+++ b/test/select-auto.c
@@ -116,6 +116,8 @@ static css_error node_presentational_hint(void *pw, void *node,
uint32_t property, css_hint *hint);
static css_error ua_default_for_property(void *pw, uint32_t property,
css_hint *hint);
+static css_error compute_font_size(void *pw, const css_hint *parent,
+ css_hint *size);
static css_select_handler select_handler = {
node_name,
@@ -138,7 +140,8 @@ static css_select_handler select_handler = {
node_is_focus,
node_is_lang,
node_presentational_hint,
- ua_default_for_property
+ ua_default_for_property,
+ compute_font_size
};
static void *myrealloc(void *data, size_t len, void *pw)
@@ -1110,3 +1113,65 @@ css_error ua_default_for_property(void *pw, uint32_t property, css_hint *hint)
return CSS_OK;
}
+css_error compute_font_size(void *pw, const css_hint *parent, css_hint *size)
+{
+ static css_hint_length sizes[] = {
+ { FLTTOFIX(6.75), CSS_UNIT_PT },
+ { FLTTOFIX(7.50), CSS_UNIT_PT },
+ { FLTTOFIX(9.75), CSS_UNIT_PT },
+ { FLTTOFIX(12.0), CSS_UNIT_PT },
+ { FLTTOFIX(13.5), CSS_UNIT_PT },
+ { FLTTOFIX(18.0), CSS_UNIT_PT },
+ { FLTTOFIX(24.0), CSS_UNIT_PT }
+ };
+ const css_hint_length *parent_size;
+
+ UNUSED(pw);
+
+ /* Grab parent size, defaulting to medium if none */
+ if (parent == NULL) {
+ parent_size = &sizes[CSS_FONT_SIZE_MEDIUM - 1];
+ } else {
+ assert(parent->status == CSS_FONT_SIZE_DIMENSION);
+ assert(parent->data.length.unit != CSS_UNIT_EM);
+ assert(parent->data.length.unit != CSS_UNIT_EX);
+ parent_size = &parent->data.length;
+ }
+
+ assert(size->status != CSS_FONT_SIZE_INHERIT);
+
+ if (size->status < CSS_FONT_SIZE_LARGER) {
+ /* Keyword -- simple */
+ size->data.length = sizes[size->status - 1];
+ } else if (size->status == CSS_FONT_SIZE_LARGER) {
+ /** \todo Step within table, if appropriate */
+ size->data.length.value =
+ FMUL(parent_size->value, FLTTOFIX(1.2));
+ size->data.length.unit = parent_size->unit;
+ } else if (size->status == CSS_FONT_SIZE_SMALLER) {
+ /** \todo Step within table, if appropriate */
+ size->data.length.value =
+ FMUL(parent_size->value, FLTTOFIX(1.2));
+ size->data.length.unit = parent_size->unit;
+ } else if (size->data.length.unit == CSS_UNIT_EM ||
+ size->data.length.unit == CSS_UNIT_EX) {
+ size->data.length.value =
+ FMUL(size->data.length.value, parent_size->value);
+
+ if (size->data.length.unit == CSS_UNIT_EX) {
+ size->data.length.value = FMUL(size->data.length.value,
+ FLTTOFIX(0.6));
+ }
+
+ size->data.length.unit = parent_size->unit;
+ } else if (size->data.length.unit == CSS_UNIT_PCT) {
+ size->data.length.value = FDIV(FMUL(size->data.length.value,
+ parent_size->value), FLTTOFIX(100));
+ size->data.length.unit = parent_size->unit;
+ }
+
+ size->status = CSS_FONT_SIZE_DIMENSION;
+
+ return CSS_OK;
+}
+