void SVGFitToViewBox::parseViewBox(const String& str) { double x = 0, y = 0, w = 0, h = 0; const UChar* c = str.characters(); const UChar* end = c + str.length(); Document* doc = contextElement()->document(); skipOptionalSpaces(c, end); if (!(parseNumber(c, end, x) && parseNumber(c, end, y) && parseNumber(c, end, w) && parseNumber(c, end, h, false))) { doc->accessSVGExtensions()->reportWarning("Problem parsing viewBox=\"" + str + "\""); return; } if (w < 0.0) // check that width is positive doc->accessSVGExtensions()->reportError("A negative value for ViewBox width is not allowed"); else if (h < 0.0) // check that height is positive doc->accessSVGExtensions()->reportError("A negative value for ViewBox height is not allowed"); else { skipOptionalSpaces(c, end); if (c < end) // nothing should come after the last, fourth number doc->accessSVGExtensions()->reportWarning("Problem parsing viewBox=\"" + str + "\""); else setViewBoxBaseValue(FloatRect(x, y, w, h)); } }
void SVGViewSpec::setViewBoxString(const String& viewBox) { float x, y, w, h; const UChar* c = viewBox.characters(); const UChar* end = c + viewBox.length(); if (!parseViewBox(c, end, x, y, w, h, false)) return; setViewBoxBaseValue(FloatRect(x, y, w, h)); }
void SVGViewSpec::setViewBoxString(const String& viewBoxStr) { FloatRect viewBox; const UChar* c = viewBoxStr.characters(); const UChar* end = c + viewBoxStr.length(); if (!parseViewBox(m_contextElement->document(), c, end, viewBox, false)) return; setViewBoxBaseValue(viewBox); }
bool SVGFitToViewBox::parseAttribute(Document* document, Attribute* attr) { if (attr->name() == SVGNames::viewBoxAttr) { FloatRect viewBox; if (!attr->value().isNull()) parseViewBox(document, attr->value(), viewBox); setViewBoxBaseValue(viewBox); return true; } else if (attr->name() == SVGNames::preserveAspectRatioAttr) { SVGPreserveAspectRatio preserveAspectRatio; preserveAspectRatio.parse(attr->value()); setPreserveAspectRatioBaseValue(preserveAspectRatio); return true; } return false; }
bool SVGFitToViewBox::parseMappedAttribute(MappedAttribute* attr) { if (attr->name() == SVGNames::viewBoxAttr) { float x = 0.0f, y = 0.0f, w = 0.0f, h = 0.0f; const UChar* c = attr->value().characters(); const UChar* end = c + attr->value().length(); if (parseViewBox(c, end, x, y, w, h)) setViewBoxBaseValue(FloatRect(x, y, w, h)); return true; } else if (attr->name() == SVGNames::preserveAspectRatioAttr) { const UChar* c = attr->value().characters(); const UChar* end = c + attr->value().length(); preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end); return true; } return false; }
bool SVGViewSpec::parseViewSpec(const String& viewSpec) { const UChar* currViewSpec = viewSpec.deprecatedCharacters(); const UChar* end = currViewSpec + viewSpec.length(); if (currViewSpec >= end || !m_contextElement) return false; if (!skipString(currViewSpec, end, svgViewSpec, WTF_ARRAY_LENGTH(svgViewSpec))) return false; if (currViewSpec >= end || *currViewSpec != '(') return false; currViewSpec++; while (currViewSpec < end && *currViewSpec != ')') { if (*currViewSpec == 'v') { if (skipString(currViewSpec, end, viewBoxSpec, WTF_ARRAY_LENGTH(viewBoxSpec))) { if (currViewSpec >= end || *currViewSpec != '(') return false; currViewSpec++; FloatRect viewBox; if (!SVGFitToViewBox::parseViewBox(&m_contextElement->document(), currViewSpec, end, viewBox, false)) return false; setViewBoxBaseValue(viewBox); if (currViewSpec >= end || *currViewSpec != ')') return false; currViewSpec++; } else if (skipString(currViewSpec, end, viewTargetSpec, WTF_ARRAY_LENGTH(viewTargetSpec))) { if (currViewSpec >= end || *currViewSpec != '(') return false; const UChar* viewTargetStart = ++currViewSpec; while (currViewSpec < end && *currViewSpec != ')') currViewSpec++; if (currViewSpec >= end) return false; setViewTargetString(String(viewTargetStart, currViewSpec - viewTargetStart)); currViewSpec++; } else return false; } else if (*currViewSpec == 'z') { if (!skipString(currViewSpec, end, zoomAndPanSpec, WTF_ARRAY_LENGTH(zoomAndPanSpec))) return false; if (currViewSpec >= end || *currViewSpec != '(') return false; currViewSpec++; if (!parseZoomAndPan(currViewSpec, end, m_zoomAndPan)) return false; if (currViewSpec >= end || *currViewSpec != ')') return false; currViewSpec++; } else if (*currViewSpec == 'p') { if (!skipString(currViewSpec, end, preserveAspectRatioSpec, WTF_ARRAY_LENGTH(preserveAspectRatioSpec))) return false; if (currViewSpec >= end || *currViewSpec != '(') return false; currViewSpec++; SVGPreserveAspectRatio preserveAspectRatio; if (!preserveAspectRatio.parse(currViewSpec, end, false)) return false; setPreserveAspectRatioBaseValue(preserveAspectRatio); if (currViewSpec >= end || *currViewSpec != ')') return false; currViewSpec++; } else if (*currViewSpec == 't') { if (!skipString(currViewSpec, end, transformSpec, WTF_ARRAY_LENGTH(transformSpec))) return false; if (currViewSpec >= end || *currViewSpec != '(') return false; currViewSpec++; SVGTransformable::parseTransformAttribute(m_transform, currViewSpec, end, SVGTransformable::DoNotClearList); if (currViewSpec >= end || *currViewSpec != ')') return false; currViewSpec++; } else return false; if (currViewSpec < end && *currViewSpec == ';') currViewSpec++; } if (currViewSpec >= end || *currViewSpec != ')') return false; return true; }
bool SVGViewSpec::parseViewSpec(const String& viewSpec) { const UChar* currViewSpec = viewSpec.characters(); const UChar* end = currViewSpec + viewSpec.length(); if (currViewSpec >= end) return false; if (!skipString(currViewSpec, end, svgViewSpec, sizeof(svgViewSpec) / sizeof(UChar))) return false; if (currViewSpec >= end || *currViewSpec != '(' ) return false; currViewSpec++; while (currViewSpec < end && *currViewSpec != ')') { if (*currViewSpec == 'v') { if (skipString(currViewSpec, end, viewBoxSpec, sizeof(viewBoxSpec) / sizeof(UChar))) { if (currViewSpec >= end || *currViewSpec != '(') return false; currViewSpec++; float x, y, w, h; if (!parseViewBox(currViewSpec, end, x, y, w, h, false)) return false; setViewBoxBaseValue(FloatRect(x, y, w, h)); if (currViewSpec >= end || *currViewSpec != ')') return false; currViewSpec++; } else if (skipString(currViewSpec, end, viewTargetSpec, sizeof(viewTargetSpec) / sizeof(UChar))) { if (currViewSpec >= end || *currViewSpec != '(') return false; const UChar* viewTargetStart = ++currViewSpec; while (currViewSpec < end && *currViewSpec != ')') currViewSpec++; if (currViewSpec >= end) return false; setViewTargetString(String(viewTargetStart, currViewSpec - viewTargetStart)); currViewSpec++; } else return false; } else if (*currViewSpec == 'z') { if (!skipString(currViewSpec, end, zoomAndPanSpec, sizeof(zoomAndPanSpec) / sizeof(UChar))) return false; if (currViewSpec >= end || *currViewSpec != '(') return false; currViewSpec++; if (!parseZoomAndPan(currViewSpec, end)) return false; if (currViewSpec >= end || *currViewSpec != ')') return false; currViewSpec++; } else if (*currViewSpec == 'p') { if (!skipString(currViewSpec, end, preserveAspectRatioSpec, sizeof(preserveAspectRatioSpec) / sizeof(UChar))) return false; if (currViewSpec >= end || *currViewSpec != '(') return false; currViewSpec++; if (!preserveAspectRatioBaseValue()->parsePreserveAspectRatio(currViewSpec, end, false)) return false; if (currViewSpec >= end || *currViewSpec != ')') return false; currViewSpec++; } else if (*currViewSpec == 't') { if (!skipString(currViewSpec, end, transformSpec, sizeof(transformSpec) / sizeof(UChar))) return false; if (currViewSpec >= end || *currViewSpec != '(') return false; currViewSpec++; SVGTransformable::parseTransformAttribute(m_transform.get(), currViewSpec, end); if (currViewSpec >= end || *currViewSpec != ')') return false; currViewSpec++; } else return false; if (currViewSpec < end && *currViewSpec == ';') currViewSpec++; } if (currViewSpec >= end || *currViewSpec != ')') return false; return true; }
bool SVGViewSpec::parseViewSpec(const String& viewSpec) { const UChar* currViewSpec = viewSpec.characters(); const UChar* end = currViewSpec + viewSpec.length(); if (currViewSpec >= end) return false; if (!skipString(currViewSpec, end, svgViewSpec, sizeof(svgViewSpec) / sizeof(UChar))) return false; if (currViewSpec >= end || *currViewSpec != '(' ) return false; currViewSpec++; while (currViewSpec < end && *currViewSpec != ')') { if (*currViewSpec == 'v') { if (skipString(currViewSpec, end, viewBoxSpec, sizeof(viewBoxSpec) / sizeof(UChar))) { if (currViewSpec >= end || *currViewSpec != '(') return false; currViewSpec++; FloatRect viewBox; if (!parseViewBox(m_contextElement->document(), currViewSpec, end, viewBox, false)) return false; setViewBoxBaseValue(viewBox); if (currViewSpec >= end || *currViewSpec != ')') return false; currViewSpec++; } else if (skipString(currViewSpec, end, viewTargetSpec, sizeof(viewTargetSpec) / sizeof(UChar))) { if (currViewSpec >= end || *currViewSpec != '(') return false; const UChar* viewTargetStart = ++currViewSpec; while (currViewSpec < end && *currViewSpec != ')') currViewSpec++; if (currViewSpec >= end) return false; setViewTargetString(String(viewTargetStart, currViewSpec - viewTargetStart)); currViewSpec++; } else return false; } else if (*currViewSpec == 'z') { if (!skipString(currViewSpec, end, zoomAndPanSpec, sizeof(zoomAndPanSpec) / sizeof(UChar))) return false; if (currViewSpec >= end || *currViewSpec != '(') return false; currViewSpec++; if (!parseZoomAndPan(currViewSpec, end)) return false; if (currViewSpec >= end || *currViewSpec != ')') return false; currViewSpec++; } else if (*currViewSpec == 'p') { if (!skipString(currViewSpec, end, preserveAspectRatioSpec, sizeof(preserveAspectRatioSpec) / sizeof(UChar))) return false; if (currViewSpec >= end || *currViewSpec != '(') return false; currViewSpec++; bool result = false; setPreserveAspectRatioBaseValue(SVGPreserveAspectRatio::parsePreserveAspectRatio(currViewSpec, end, false, result)); if (!result) return false; if (currViewSpec >= end || *currViewSpec != ')') return false; currViewSpec++; } else if (*currViewSpec == 't') { if (!skipString(currViewSpec, end, transformSpec, sizeof(transformSpec) / sizeof(UChar))) return false; if (currViewSpec >= end || *currViewSpec != '(') return false; currViewSpec++; SVGTransformable::parseTransformAttribute(m_transform.get(), currViewSpec, end, SVGTransformable::DoNotClearList); if (currViewSpec >= end || *currViewSpec != ')') return false; currViewSpec++; } else return false; if (currViewSpec < end && *currViewSpec == ';') currViewSpec++; } if (currViewSpec >= end || *currViewSpec != ')') return false; return true; }