Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3584 sourcerer 1
/*
2
 * This file is part of LibCSS.
3
 * Licensed under the MIT License,
4
 *		  http://www.opensource.org/licenses/mit-license.php
5
 * Copyright 2009 John-Mark Bell 
6
 */
7
 
8
#include 
9
#include 
10
 
11
#include "bytecode/bytecode.h"
12
#include "bytecode/opcodes.h"
13
#include "parse/properties/properties.h"
14
#include "parse/properties/utils.h"
15
 
16
/**
17
 * Determine if a given voice-family ident is reserved
18
 *
19
 * \param c	 Parsing context
20
 * \param ident	 IDENT to consider
21
 * \return True if IDENT is reserved, false otherwise
22
 */
23
static bool voice_family_reserved(css_language *c, const css_token *ident)
24
{
25
	bool match;
26
 
27
	return (lwc_string_caseless_isequal(
28
			ident->idata, c->strings[MALE],
29
			&match) == lwc_error_ok && match) ||
30
		(lwc_string_caseless_isequal(
31
			ident->idata, c->strings[FEMALE],
32
			&match) == lwc_error_ok && match) ||
33
		(lwc_string_caseless_isequal(
34
			ident->idata, c->strings[CHILD],
35
			&match) == lwc_error_ok && match);
36
}
37
 
38
/**
39
 * Convert a voice-family token into a bytecode value
40
 *
41
 * \param c	 Parsing context
42
 * \param token	 Token to consider
43
 * \return Bytecode value
44
 */
45
static css_code_t voice_family_value(css_language *c, const css_token *token, bool first)
46
{
47
	uint16_t value;
48
	bool match;
49
 
50
	if (token->type == CSS_TOKEN_IDENT) {
51
		if ((lwc_string_caseless_isequal(
52
				token->idata, c->strings[MALE],
53
				&match) == lwc_error_ok && match))
54
			value = VOICE_FAMILY_MALE;
55
		else if ((lwc_string_caseless_isequal(
56
				token->idata, c->strings[FEMALE],
57
				&match) == lwc_error_ok && match))
58
			value = VOICE_FAMILY_FEMALE;
59
		else if ((lwc_string_caseless_isequal(
60
				token->idata, c->strings[CHILD],
61
				&match) == lwc_error_ok && match))
62
			value = VOICE_FAMILY_CHILD;
63
		else
64
			value = VOICE_FAMILY_IDENT_LIST;
65
	} else {
66
		value = VOICE_FAMILY_STRING;
67
	}
68
 
69
	return first ? buildOPV(CSS_PROP_VOICE_FAMILY, 0, value) : value;
70
}
71
 
72
/**
73
 * Parse voice-family
74
 *
75
 * \param c	  Parsing context
76
 * \param vector  Vector of tokens to process
77
 * \param ctx	  Pointer to vector iteration context
78
 * \param result  Pointer to location to receive resulting style
79
 * \return CSS_OK on success,
80
 *	 CSS_NOMEM on memory exhaustion,
81
 *	 CSS_INVALID if the input is not valid
82
 *
83
 * Post condition: \a *ctx is updated with the next token to process
84
 *		 If the input is invalid, then \a *ctx remains unchanged.
85
 */
86
css_error css__parse_voice_family(css_language *c,
87
		const parserutils_vector *vector, int *ctx,
88
		css_style *result)
89
{
90
	int orig_ctx = *ctx;
91
	css_error error;
92
	const css_token *token;
93
	bool match;
94
 
95
	/* [ IDENT+ | STRING ] [ ',' [ IDENT+ | STRING ] ]* | IDENT(inherit)
96
	 *
97
	 * In the case of IDENT+, any whitespace between tokens is collapsed to
98
	 * a single space
99
	 */
100
 
101
	token = parserutils_vector_iterate(vector, ctx);
102
	if (token == NULL || (token->type != CSS_TOKEN_IDENT &&
103
			token->type != CSS_TOKEN_STRING)) {
104
		*ctx = orig_ctx;
105
		return CSS_INVALID;
106
	}
107
 
108
	if (token->type == CSS_TOKEN_IDENT &&
109
			(lwc_string_caseless_isequal(
110
			token->idata, c->strings[INHERIT],
111
			&match) == lwc_error_ok && match)) {
112
		error = css_stylesheet_style_inherit(result, CSS_PROP_VOICE_FAMILY);
113
	} else {
114
		*ctx = orig_ctx;
115
 
116
		error = css__comma_list_to_style(c, vector, ctx,
117
				voice_family_reserved, voice_family_value,
118
				result);
119
		if (error != CSS_OK) {
120
			*ctx = orig_ctx;
121
			return error;
122
		}
123
 
124
		error = css__stylesheet_style_append(result, VOICE_FAMILY_END);
125
	}
126
 
127
	if (error != CSS_OK) {
128
		*ctx = orig_ctx;
129
		return error;
130
	}
131
 
132
	return CSS_OK;
133
}