2
* This file is part of the DOM implementation for KDE.
4
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5
* (C) 1999 Antti Koivisto (koivisto@kde.org)
6
* (C) 2000 Simon Hausmann <hausmann@kde.org>
7
* Copyright (C) 2003, 2006 Apple Computer, Inc.
9
* This library is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU Library General Public
11
* License as published by the Free Software Foundation; either
12
* version 2 of the License, or (at your option) any later version.
14
* This library is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* Library General Public License for more details.
19
* You should have received a copy of the GNU Library General Public License
20
* along with this library; see the file COPYING.LIB. If not, write to
21
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22
* Boston, MA 02111-1307, USA.
26
#include "HTMLFontElement.h"
28
#include "CSSPropertyNames.h"
29
#include "CSSValueKeywords.h"
30
#include "HTMLNames.h"
36
using namespace HTMLNames;
38
HTMLFontElement::HTMLFontElement(Document* doc)
39
: HTMLElement(fontTag, doc)
43
HTMLFontElement::~HTMLFontElement()
47
// Allows leading spaces.
48
// Allows trailing nonnumeric characters.
49
// Returns 10 for any size greater than 9.
50
static bool parseFontSizeNumber(const String& s, int& size)
54
// Skip leading spaces.
55
while (DeprecatedChar(s[pos]).isSpace())
58
// Skip a plus or minus.
60
bool sawMinus = false;
64
} else if (s[pos] == '-') {
69
// Parse a single digit.
70
if (!Unicode::isDigit(s[pos]))
72
int num = Unicode::digitValue(s[pos++]);
74
// Check for an additional digit.
75
if (Unicode::isDigit(s[pos]))
83
// Don't return 0 (which means 3) or a negative number (which means the same as 1).
85
size = num == 1 ? 2 : 1;
93
bool HTMLFontElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
95
if (attrName == sizeAttr ||
96
attrName == colorAttr ||
97
attrName == faceAttr) {
102
return HTMLElement::mapToEntry(attrName, result);
105
bool HTMLFontElement::cssValueFromFontSizeNumber(const String& s, int& size)
108
if (!parseFontSizeNumber(s, num))
113
size = CSS_VAL_SMALL;
115
case 0: // treat 0 the same as 3, because people expect it to be between -1 and +1
117
size = CSS_VAL_MEDIUM;
120
size = CSS_VAL_LARGE;
123
size = CSS_VAL_X_LARGE;
126
size = CSS_VAL_XX_LARGE;
130
size = CSS_VAL__WEBKIT_XXX_LARGE;
132
size = CSS_VAL_X_SMALL;
137
void HTMLFontElement::parseMappedAttribute(MappedAttribute *attr)
139
if (attr->name() == sizeAttr) {
141
if (cssValueFromFontSizeNumber(attr->value(), size))
142
addCSSProperty(attr, CSS_PROP_FONT_SIZE, size);
143
} else if (attr->name() == colorAttr) {
144
addCSSColor(attr, CSS_PROP_COLOR, attr->value());
145
} else if (attr->name() == faceAttr) {
146
addCSSProperty(attr, CSS_PROP_FONT_FAMILY, attr->value());
148
HTMLElement::parseMappedAttribute(attr);
151
String HTMLFontElement::color() const
153
return getAttribute(colorAttr);
156
void HTMLFontElement::setColor(const String& value)
158
setAttribute(colorAttr, value);
161
String HTMLFontElement::face() const
163
return getAttribute(faceAttr);
166
void HTMLFontElement::setFace(const String& value)
168
setAttribute(faceAttr, value);
171
String HTMLFontElement::size() const
173
return getAttribute(sizeAttr);
176
void HTMLFontElement::setSize(const String& value)
178
setAttribute(sizeAttr, value);