1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2018 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include "spv-css-parser.h"
24 #include "libpspp/str.h"
25 #include "output/pivot-table.h"
28 #include "gl/c-ctype.h"
29 #include "gl/xalloc.h"
30 #include "gl/xmemdup0.h"
45 enum css_token_type type;
50 css_skip_spaces (char *p)
56 else if (!strncmp (p, "<!--", 4))
58 else if (!strncmp (p, "-->", 3))
66 css_is_separator (unsigned char c)
68 return c_isspace (c) || strchr ("{}:;", c);
72 css_token_get (char **p_, struct css_token *token)
79 p = css_skip_spaces (p);
84 token->type = T_LCURLY;
89 token->type = T_RCURLY;
94 token->type = T_COLON;
99 token->type = T_SEMICOLON;
106 while (!css_is_separator (*p))
108 token->s = xmemdup0 (start, p - start);
114 css_decode_key_value (const char *key, const char *value,
115 struct font_style *font)
117 if (!strcmp (key, "font-weight"))
118 font->bold = !strcmp (value, "bold");
119 else if (!strcmp (key, "font-style"))
120 font->italic = !strcmp (value, "italic");
121 else if (!strcmp (key, "font-decoration"))
122 font->underline = !strcmp (value, "underline");
123 else if (!strcmp (key, "font-family"))
125 free (font->typeface);
126 font->typeface = xstrdup (value);
128 else if (!strcmp (key, "font-size"))
129 font->size = atoi (value) * 3 / 4;
131 /* fg_color, bg_color */
136 spv_parse_css_style (char *style, struct font_style *font)
138 *font = (struct font_style) FONT_STYLE_INITIALIZER;
141 struct css_token token = { .s = NULL };
142 css_token_get (&p, &token);
143 while (token.type != T_EOF)
145 if (token.type != T_ID || !strcmp (token.s, "p"))
147 css_token_get (&p, &token);
153 css_token_get (&p, &token);
155 if (token.type == T_COLON)
157 struct string value = DS_EMPTY_INITIALIZER;
160 css_token_get (&p, &token);
161 if (token.type != T_ID)
163 if (!ds_is_empty (&value))
164 ds_put_byte (&value, ' ');
165 ds_put_cstr (&value, token.s);
168 css_decode_key_value (key, ds_cstr (&value), font);