Changeset 152140 in webkit
- Timestamp:
- Jun 27, 2013 5:14:57 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r152138 r152140 1 2013-06-27 Frédéric Wang <fred.wang@free.fr> 2 3 Implement parsing of MathML lengths. 4 https://bugs.webkit.org/show_bug.cgi?id=118053 5 6 Reviewed by Chris Fleizach. 7 8 Add some reftests for mfrac@linethickness. Better tests for the parsing 9 of MathML lengths will be provided when mspace is implemented 10 (bug 115610) 11 12 * mathml/presentation/mfrac-linethickness1-expected-mismatch.html: Added. 13 * mathml/presentation/mfrac-linethickness1.html: Added. 14 * mathml/presentation/mfrac-linethickness2-expected.html: Added. 15 * mathml/presentation/mfrac-linethickness2.html: Added. 16 * mathml/presentation/mfrac-linethickness3-expected-mismatch.html: Added. 17 * mathml/presentation/mfrac-linethickness3.html: Added. 18 1 19 2013-06-27 Jessie Berlin <jberlin@apple.com> 2 20 -
trunk/Source/WebCore/ChangeLog
r152137 r152140 1 2013-06-27 Frédéric Wang <fred.wang@free.fr> 2 3 Implement parsing of MathML lengths. 4 https://bugs.webkit.org/show_bug.cgi?id=118053 5 6 Reviewed by Chris Fleizach. 7 8 A parsing function for MathML lengths, similar to Gecko's one, is 9 implemented. It is currently only used to parse mfrac@linethickness but 10 will be convenient to parse other MathML attributes in the future. 11 12 Tests: mathml/presentation/mfrac-linethickness1.html 13 mathml/presentation/mfrac-linethickness2.html 14 mathml/presentation/mfrac-linethickness3.html 15 16 * rendering/mathml/RenderMathMLBlock.cpp: add parsing functions 17 (WebCore::parseMathMLLength): parsing MathML Length (number unit) 18 (WebCore::parseNamedSpace): parsing MathML namedspaces 19 * rendering/mathml/RenderMathMLBlock.h: declare parsing functions 20 * rendering/mathml/RenderMathMLFraction.cpp: use the parsing function for linethickness 21 (WebCore::RenderMathMLFraction::updateFromElement): 22 1 23 2013-06-27 Anders Carlsson <andersca@apple.com> 2 24 -
trunk/Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp
r144744 r152140 34 34 #include "MathMLNames.h" 35 35 #include "RenderView.h" 36 #include <wtf/text/StringBuilder.h> 36 37 37 38 #if ENABLE(DEBUG_MATH_LAYOUT) … … 188 189 #endif // ENABLE(DEBUG_MATH_LAYOUT) 189 190 191 // 192 // The MathML specification says: 193 // (http://www.w3.org/TR/MathML/chapter2.html#fund.units) 194 // 195 // "Most presentation elements have attributes that accept values representing 196 // lengths to be used for size, spacing or similar properties. The syntax of a 197 // length is specified as 198 // 199 // number | number unit | namedspace 200 // 201 // There should be no space between the number and the unit of a length." 202 // 203 // "A trailing '%' represents a percent of the default value. The default 204 // value, or how it is obtained, is listed in the table of attributes for each 205 // element. [...] A number without a unit is intepreted as a multiple of the 206 // default value." 207 // 208 // "The possible units in MathML are: 209 // 210 // Unit Description 211 // em an em (font-relative unit traditionally used for horizontal lengths) 212 // ex an ex (font-relative unit traditionally used for vertical lengths) 213 // px pixels, or size of a pixel in the current display 214 // in inches (1 inch = 2.54 centimeters) 215 // cm centimeters 216 // mm millimeters 217 // pt points (1 point = 1/72 inch) 218 // pc picas (1 pica = 12 points) 219 // % percentage of default value" 220 // 221 // The numbers are defined that way: 222 // - unsigned-number: "a string of decimal digits with up to one decimal point 223 // (U+002E), representing a non-negative terminating decimal number (a type of 224 // rational number)" 225 // - number: "an optional prefix of '-' (U+002D), followed by an unsigned 226 // number, representing a terminating decimal number (a type of rational 227 // number)" 228 // 229 bool parseMathMLLength(const String& string, float& lengthValue, const RenderStyle* style, bool allowNegative) 230 { 231 String s = string.simplifyWhiteSpace(); 232 233 int stringLength = s.length(); 234 if (!stringLength) 235 return false; 236 237 if (parseMathMLNamedSpace(s, lengthValue, style, allowNegative)) 238 return true; 239 240 StringBuilder number; 241 String unit; 242 243 // This verifies whether the negative sign is there. 244 int i = 0; 245 UChar c = s[0]; 246 if (c == '-') { 247 number.append(c); 248 i++; 249 } 250 251 // This gathers up characters that make up the number. 252 bool gotDot = false; 253 for ( ; i < stringLength; i++) { 254 c = s[i]; 255 // The string is invalid if it contains two dots. 256 if (gotDot && c == '.') 257 return false; 258 if (c == '.') 259 gotDot = true; 260 else if (!isASCIIDigit(c)) { 261 unit = s.substring(i, stringLength - i); 262 // Some authors leave blanks before the unit, but that shouldn't 263 // be allowed, so don't simplifyWhitespace on 'unit'. 264 break; 265 } 266 number.append(c); 267 } 268 269 // Convert number to floating point 270 bool ok; 271 float floatValue = number.toString().toFloat(&ok); 272 if (!ok) 273 return false; 274 if (floatValue < 0 && !allowNegative) 275 return false; 276 277 if (unit.isEmpty()) { 278 // no explicit unit, this is a number that will act as a multiplier 279 lengthValue *= floatValue; 280 return true; 281 } 282 if (unit == "%") { 283 lengthValue *= floatValue / 100; 284 return true; 285 } 286 if (unit == "em") { 287 lengthValue = floatValue * style->font().size(); 288 return true; 289 } 290 if (unit == "ex") { 291 lengthValue = floatValue * style->fontMetrics().xHeight(); 292 return true; 293 } 294 if (unit == "px") { 295 lengthValue = floatValue; 296 return true; 297 } 298 if (unit == "pt") { 299 lengthValue = 4 / 3 * floatValue; 300 return true; 301 } 302 if (unit == "pc") { 303 lengthValue = (4 / 3 * floatValue) * 12; 304 return true; 305 } 306 if (unit == "in") { 307 lengthValue = 96 * floatValue; 308 return true; 309 } 310 if (unit == "cm") { 311 lengthValue = 96 * floatValue / 2.54; 312 return true; 313 } 314 if (unit == "mm") { 315 lengthValue = (96 * floatValue / 2.54) / 10; 316 return true; 317 } 318 319 // unexpected unit 320 return false; 321 } 322 323 bool parseMathMLNamedSpace(const String& string, float& lengthValue, const RenderStyle* style, bool allowNegative) 324 { 325 float length = 0; 326 // See if it is one of the namedspaces (ranging -7/18em, -6/18, ... 7/18em) 327 if (string == "veryverythinmathspace") 328 length = 1; 329 else if (string == "verythinmathspace") 330 length = 2; 331 else if (string == "thinmathspace") 332 length = 3; 333 else if (string == "mediummathspace") 334 length = 4; 335 else if (string == "thickmathspace") 336 length = 5; 337 else if (string == "verythickmathspace") 338 length = 6; 339 else if (string == "veryverythickmathspace") 340 length = 7; 341 else if (allowNegative) { 342 if (string == "negativeveryverythinmathspace") 343 length = -1; 344 else if (string == "negativeverythinmathspace") 345 length = -2; 346 else if (string == "negativethinmathspace") 347 length = -3; 348 else if (string == "negativemediummathspace") 349 length = -4; 350 else if (string == "negativethickmathspace") 351 length = -5; 352 else if (string == "negativeverythickmathspace") 353 length = -6; 354 else if (string == "negativeveryverythickmathspace") 355 length = -7; 356 } 357 if (length) { 358 lengthValue = length * style->font().size() / 18; 359 return true; 360 } 361 return false; 362 } 363 190 364 int RenderMathMLTable::firstLineBoxBaseline() const 191 365 { -
trunk/Source/WebCore/rendering/mathml/RenderMathMLBlock.h
r150312 r152140 128 128 }; 129 129 130 // Parsing functions for MathML Length values 131 bool parseMathMLLength(const String&, float&, const RenderStyle*, bool allowNegative = true); 132 bool parseMathMLNamedSpace(const String&, float&, const RenderStyle*, bool allowNegative = true); 130 133 } 131 134 -
trunk/Source/WebCore/rendering/mathml/RenderMathMLFraction.cpp
r151323 r152140 79 79 else if (equalIgnoringCase(thickness, "thick")) 80 80 m_lineThickness = gLineThick; 81 else { 82 bool converted = false; 83 int thicknessIntValue = thickness.toIntStrict(&converted); 84 if (converted) 85 m_lineThickness = thicknessIntValue; 86 } 81 else 82 // This function parses the thickness attribute using gLineMedium as 83 // the default value. If the parsing fails, m_lineThickness will not be 84 // modified i.e. the default value will be used. 85 parseMathMLLength(thickness, m_lineThickness, style(), false); 87 86 88 87 // Update the style for the padding of the denominator for the line thickness
Note: See TracChangeset
for help on using the changeset viewer.