summaryrefslogtreecommitdiff
path: root/src/select/properties/voice_family.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/select/properties/voice_family.c')
-rw-r--r--src/select/properties/voice_family.c157
1 files changed, 157 insertions, 0 deletions
diff --git a/src/select/properties/voice_family.c b/src/select/properties/voice_family.c
new file mode 100644
index 0000000..efe60b4
--- /dev/null
+++ b/src/select/properties/voice_family.c
@@ -0,0 +1,157 @@
+/*
+ * This file is part of LibCSS
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#include "bytecode/bytecode.h"
+#include "bytecode/opcodes.h"
+#include "select/propset.h"
+#include "select/propget.h"
+#include "utils/utils.h"
+
+#include "select/properties/properties.h"
+#include "select/properties/helpers.h"
+
+css_error cascade_voice_family(uint32_t opv, css_style *style,
+ css_select_state *state)
+{
+ uint16_t value = 0;
+ lwc_string **voices = NULL;
+ uint32_t n_voices = 0;
+
+ if (isInherit(opv) == false) {
+ uint32_t v = getValue(opv);
+
+ while (v != VOICE_FAMILY_END) {
+ lwc_string *voice = NULL;
+ lwc_string **temp;
+
+ switch (v) {
+ case VOICE_FAMILY_STRING:
+ case VOICE_FAMILY_IDENT_LIST:
+ voice = *((lwc_string **)
+ style->bytecode);
+ advance_bytecode(style, sizeof(voice));
+ break;
+ case VOICE_FAMILY_MALE:
+ if (value == 0)
+ value = 1;
+ break;
+ case VOICE_FAMILY_FEMALE:
+ if (value == 0)
+ value = 1;
+ break;
+ case VOICE_FAMILY_CHILD:
+ if (value == 0)
+ value = 1;
+ break;
+ }
+
+ /* Only use family-names which occur before the first
+ * generic-family. Any values which occur after the
+ * first generic-family are ignored. */
+ /** \todo Do this at bytecode generation time? */
+ if (value == 0 && voice != NULL) {
+ temp = state->result->alloc(voices,
+ (n_voices + 1) * sizeof(lwc_string *),
+ state->result->pw);
+ if (temp == NULL) {
+ if (voices != NULL) {
+ state->result->alloc(voices, 0,
+ state->result->pw);
+ }
+ return CSS_NOMEM;
+ }
+
+ voices = temp;
+
+ voices[n_voices] = voice;
+
+ n_voices++;
+ }
+
+ v = *((uint32_t *) style->bytecode);
+ advance_bytecode(style, sizeof(v));
+ }
+ }
+
+ /* Terminate array with blank entry, if needed */
+ if (n_voices > 0) {
+ lwc_string **temp;
+
+ temp = state->result->alloc(voices,
+ (n_voices + 1) * sizeof(lwc_string *),
+ state->result->pw);
+ if (temp == NULL) {
+ state->result->alloc(voices, 0, state->result->pw);
+ return CSS_NOMEM;
+ }
+
+ voices = temp;
+
+ voices[n_voices] = NULL;
+ }
+
+ if (outranks_existing(getOpcode(opv), isImportant(opv), state,
+ isInherit(opv))) {
+ /** \todo voice-family */
+ if (n_voices > 0)
+ state->result->alloc(voices, 0, state->result->pw);
+ } else {
+ if (n_voices > 0)
+ state->result->alloc(voices, 0, state->result->pw);
+ }
+
+ return CSS_OK;
+}
+
+css_error set_voice_family_from_hint(const css_hint *hint,
+ css_computed_style *style)
+{
+ UNUSED(hint);
+ UNUSED(style);
+
+ return CSS_OK;
+}
+
+css_error initial_voice_family(css_select_state *state)
+{
+ UNUSED(state);
+
+ return CSS_OK;
+}
+
+css_error compose_voice_family(const css_computed_style *parent,
+ const css_computed_style *child,
+ css_computed_style *result)
+{
+ UNUSED(parent);
+ UNUSED(child);
+ UNUSED(result);
+
+ return CSS_OK;
+}
+
+uint32_t destroy_voice_family(void *bytecode)
+{
+ uint32_t consumed = sizeof(uint32_t);
+ uint32_t value = getValue(*((uint32_t*)bytecode));
+ bytecode = ((uint8_t*)bytecode) + sizeof(uint32_t);
+
+ while (value != VOICE_FAMILY_END) {
+ if (value == VOICE_FAMILY_STRING || value == VOICE_FAMILY_IDENT_LIST) {
+ lwc_string *str = *((lwc_string **)bytecode);
+ consumed += sizeof(lwc_string*);
+ bytecode = ((uint8_t*)bytecode) + sizeof(lwc_string*);
+ lwc_string_unref(str);
+ }
+
+ consumed += sizeof(uint32_t);
+ value = *((uint32_t*)bytecode);
+ bytecode = ((uint8_t*)bytecode) + sizeof(uint32_t);
+ }
+
+ return consumed;
+}