void SVGImageElement::parseMappedAttribute(MappedAttribute *attr) { if (attr->name() == SVGNames::xAttr) setXBaseValue(SVGLength(LengthModeWidth, attr->value())); else if (attr->name() == SVGNames::yAttr) setYBaseValue(SVGLength(LengthModeHeight, attr->value())); else if (attr->name() == SVGNames::preserveAspectRatioAttr) { const UChar* c = attr->value().characters(); const UChar* end = c + attr->value().length(); preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end); } else if (attr->name() == SVGNames::widthAttr) { setWidthBaseValue(SVGLength(LengthModeWidth, attr->value())); addCSSProperty(attr, CSSPropertyWidth, attr->value()); if (widthBaseValue().value(this) < 0.0) document()->accessSVGExtensions()->reportError("A negative value for image attribute <width> is not allowed"); } else if (attr->name() == SVGNames::heightAttr) { setHeightBaseValue(SVGLength(LengthModeHeight, attr->value())); addCSSProperty(attr, CSSPropertyHeight, attr->value()); if (heightBaseValue().value(this) < 0.0) document()->accessSVGExtensions()->reportError("A negative value for image attribute <height> is not allowed"); } else { if (SVGTests::parseMappedAttribute(attr)) return; if (SVGLangSpace::parseMappedAttribute(attr)) return; if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) return; if (SVGURIReference::parseMappedAttribute(attr)) return; SVGStyledTransformableElement::parseMappedAttribute(attr); } }
bool SVGFitToViewBox::parseMappedAttribute(MappedAttribute* attr) { if (attr->name() == SVGNames::viewBoxAttr) { parseViewBox(attr->value()); return true; } else if (attr->name() == SVGNames::preserveAspectRatioAttr) { preserveAspectRatioBaseValue()->parsePreserveAspectRatio(attr->value()); 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; }
void SVGSVGElement::inheritViewAttributes(SVGViewElement* viewElement) { setUseCurrentView(true); if (viewElement->hasAttribute(SVGNames::viewBoxAttr)) currentView()->setViewBox(viewElement->viewBox()); else currentView()->setViewBox(viewBox()); SVGPreserveAspectRatio aspectRatio; if (viewElement->hasAttribute(SVGNames::preserveAspectRatioAttr)) aspectRatio = viewElement->preserveAspectRatioBaseValue(); else aspectRatio = preserveAspectRatioBaseValue(); currentView()->setPreserveAspectRatioBaseValue(aspectRatio); if (viewElement->hasAttribute(SVGNames::zoomAndPanAttr)) currentView()->setZoomAndPan(viewElement->zoomAndPan()); renderer()->setNeedsLayout(true); }
void SVGSVGElement::inheritViewAttributes(SVGViewElement* viewElement) { if (viewElement->hasAttribute(SVGNames::viewBoxAttr)) currentView()->setViewBoxBaseValue(viewElement->viewBox()); else currentView()->setViewBoxBaseValue(viewBox()); SVGPreserveAspectRatio aspectRatio; if (viewElement->hasAttribute(SVGNames::preserveAspectRatioAttr)) aspectRatio = viewElement->preserveAspectRatioBaseValue(); else aspectRatio = preserveAspectRatioBaseValue(); currentView()->setPreserveAspectRatioBaseValue(aspectRatio); if (viewElement->hasAttribute(SVGNames::zoomAndPanAttr)) currentView()->setZoomAndPan(viewElement->zoomAndPan()); if (RenderObject* object = renderer()) RenderSVGResource::markForLayoutAndParentResourceInvalidation(object); }
void SVGSVGElement::inheritViewAttributes(SVGViewElement* viewElement) { SVGViewSpec* view = currentView(); m_useCurrentView = true; if (viewElement->hasAttribute(SVGNames::viewBoxAttr)) view->setViewBoxBaseValue(viewElement->viewBox()); else view->setViewBoxBaseValue(viewBox()); if (viewElement->hasAttribute(SVGNames::preserveAspectRatioAttr)) view->setPreserveAspectRatioBaseValue(viewElement->preserveAspectRatioBaseValue()); else view->setPreserveAspectRatioBaseValue(preserveAspectRatioBaseValue()); if (viewElement->hasAttribute(SVGNames::zoomAndPanAttr)) view->setZoomAndPanBaseValue(viewElement->zoomAndPan()); else view->setZoomAndPanBaseValue(zoomAndPan()); }
String SVGViewSpec::preserveAspectRatioString() const { return SVGPropertyTraits<SVGPreserveAspectRatio>::toString(preserveAspectRatioBaseValue()); }
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; }
void SVGViewSpec::setPreserveAspectRatioString(const String& preserve) { const UChar* c = preserve.characters(); const UChar* end = c + preserve.length(); preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end); }