AffineTransform SVGSVGElement::viewBoxToViewTransform(float viewWidth, float viewHeight) const { FloatRect viewBoxRect; if (useCurrentView()) { if (currentView()) // what if we should use it but it is not set? viewBoxRect = currentView()->viewBox(); } else viewBoxRect = viewBox(); AffineTransform ctm = SVGFitToViewBox::viewBoxToViewTransform(viewBoxRect, preserveAspectRatio(), viewWidth, viewHeight); if (useCurrentView() && currentView()) return currentView()->transform()->concatenate().matrix() * ctm; return ctm; }
FloatRect SVGSVGElement::currentViewBoxRect() const { if (useCurrentView()) { if (SVGViewSpec* view = currentView()) // what if we should use it but it is not set? return view->viewBox(); return FloatRect(); } FloatRect useViewBox = viewBox(); if (!useViewBox.isEmpty()) return useViewBox; if (!renderer() || !renderer()->isSVGRoot()) return FloatRect(); if (!toRenderSVGRoot(renderer())->isEmbeddedThroughSVGImage()) return FloatRect(); Length intrinsicWidth = this->intrinsicWidth(); Length intrinsicHeight = this->intrinsicHeight(); if (!intrinsicWidth.isFixed() || !intrinsicHeight.isFixed()) return FloatRect(); // If no viewBox is specified but non-relative width/height values, then we // should always synthesize a viewBox if we're embedded through a SVGImage. return FloatRect(FloatPoint(), FloatSize(intrinsicWidth.calcFloatValue(0), intrinsicHeight.calcFloatValue(0))); }
FloatRect SVGSVGElement::currentViewBoxRect(CalculateViewBoxMode mode) const { // This method resolves length manually, w/o involving the render tree. This is desired, as getCTM()/getScreenCTM()/.. have to work without a renderer. SVGLengthContext lengthContext(this); // FIXME: The interaction of 'currentView' and embedding SVGs in other documents, is untested and unspecified. if (useCurrentView()) { if (SVGViewSpec* view = currentView()) // what if we should use it but it is not set? return view->viewBox(); return FloatRect(); } bool isEmbeddedThroughSVGImage = renderer() && renderer()->isSVGRoot() ? toRenderSVGRoot(renderer())->isEmbeddedThroughSVGImage() : false; bool hasFixedSize = width().unitType() != LengthTypePercentage && height().unitType() != LengthTypePercentage; FloatRect useViewBox = viewBox(); if (useViewBox.isEmpty()) { // If no viewBox is specified but non-relative width/height values, then we // should always synthesize a viewBox if we're embedded through a SVGImage. if (hasFixedSize && isEmbeddedThroughSVGImage) return FloatRect(0, 0, width().value(lengthContext), height().value(lengthContext)); return FloatRect(); } // If a viewBox is specified and non-relative width/height values, then the host document only // uses the width/height values to figure out the intrinsic size when embedding us, whereas the // embedded document sees specified viewBox only. if (hasFixedSize && mode == CalculateViewBoxInHostDocument) return FloatRect(0, 0, width().value(lengthContext), height().value(lengthContext)); return useViewBox; }
FloatRect SVGSVGElement::currentViewBoxRect() const { if (useCurrentView()) { if (SVGViewSpec* view = currentView()) // what if we should use it but it is not set? return view->viewBox(); return FloatRect(); } return viewBox(); }
AffineTransform SVGSVGElement::viewBoxToViewTransform(float viewWidth, float viewHeight) const { AffineTransform ctm = SVGFitToViewBox::viewBoxToViewTransform(currentViewBoxRect(), preserveAspectRatio(), viewWidth, viewHeight); if (useCurrentView() && currentView()) { AffineTransform transform; if (currentView()->transform().concatenate(transform)) ctm *= transform; } return ctm; }
TransformationMatrix SVGSVGElement::viewBoxToViewTransform(float viewWidth, float viewHeight) const { FloatRect viewBoxRect; if (useCurrentView()) { if (currentView()) // what if we should use it but it is not set? viewBoxRect = currentView()->viewBox(); } else viewBoxRect = viewBox(); if (!viewBoxRect.width() || !viewBoxRect.height()) return TransformationMatrix(); TransformationMatrix ctm = preserveAspectRatio()->getCTM(viewBoxRect.x(), viewBoxRect.y(), viewBoxRect.width(), viewBoxRect.height(), 0, 0, viewWidth, viewHeight); if (useCurrentView() && currentView()) return currentView()->transform()->concatenate().matrix() * ctm; return ctm; }