KCanvasContainer {svg} at (0.50,0.50) size 479x359
KCanvasContainer {g} at (20,70) size 410x225 [transform={m=((1.00,0.00)(0.00,1.00)) t=(0.00,30.00)}]
KCanvasContainer {g} at (20,70) size 410x225
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 45x10
text run at (0,0) width 45: "Raster to fit"
KCanvasContainer {g} at (20,70) size 40x40 [transform={m=((1.00,0.00)(0.00,1.00)) t=(20.00,40.00)}]
RenderImage {image} at (0,0) size 40x40
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 42x10
text run at (0,0) width 42: "Viewport 1"
KCanvasContainer {g} at (10,150) size 0x0 [transform={m=((1.00,0.00)(0.00,1.00)) t=(10.00,120.00)}]
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 42x10
text run at (0,0) width 42: "Viewport 2"
KCanvasContainer {g} at (20,220) size 0x0 [transform={m=((1.00,0.00)(0.00,1.00)) t=(20.00,190.00)}]
KCanvasContainer {g} at (120,80) size 120x80 [transform={m=((1.00,0.00)(0.00,1.00)) t=(120.00,50.00)}]
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 112x10
text run at (0,0) width 112: "---------- meet --------------------"
KCanvasContainer {g} at (120,80) size 50x30
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 26x10
text run at (0,0) width 26: "xMin*"
RenderImage {image} at (0,0) size 50x30
KCanvasContainer {g} at (190,80) size 50x30 [transform={m=((1.00,0.00)(0.00,1.00)) t=(70.00,0.00)}]
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 26x10
text run at (0,0) width 26: "xMid*"
RenderImage {image} at (0,0) size 50x30
KCanvasContainer {g} at (120,130) size 50x30 [transform={m=((1.00,0.00)(0.00,1.00)) t=(0.00,50.00)}]
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 27x10
text run at (0,0) width 27: "xMax*"
RenderImage {image} at (0,0) size 50x30
KCanvasContainer {g} at (300,80) size 130x60 [transform={m=((1.00,0.00)(0.00,1.00)) t=(300.00,50.00)}]
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 124x10
text run at (0,0) width 124: "---------- meet ------------------------"
KCanvasContainer {g} at (300,80) size 30x60
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 27x10
text run at (0,0) width 27: "*YMin"
RenderImage {image} at (0,0) size 30x60
KCanvasContainer {g} at (350,80) size 30x60 [transform={m=((1.00,0.00)(0.00,1.00)) t=(50.00,0.00)}]
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 27x10
text run at (0,0) width 27: "*YMid"
RenderImage {image} at (0,0) size 30x60
KCanvasContainer {g} at (400,80) size 30x60 [transform={m=((1.00,0.00)(0.00,1.00)) t=(100.00,0.00)}]
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 28x10
text run at (0,0) width 28: "*YMax"
RenderImage {image} at (0,0) size 30x60
KCanvasContainer {g} at (120,215) size 130x60 [transform={m=((1.00,0.00)(0.00,1.00)) t=(120.00,185.00)}]
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 127x10
text run at (0,0) width 127: "---------- slice -------------------------"
KCanvasContainer {g} at (120,215) size 30x60
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 26x10
text run at (0,0) width 26: "xMin*"
RenderImage {image} at (0,0) size 30x60
KCanvasContainer {g} at (170,215) size 30x60 [transform={m=((1.00,0.00)(0.00,1.00)) t=(50.00,0.00)}]
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 26x10
text run at (0,0) width 26: "xMid*"
RenderImage {image} at (0,0) size 30x60
KCanvasContainer {g} at (220,215) size 30x60 [transform={m=((1.00,0.00)(0.00,1.00)) t=(100.00,0.00)}]
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 27x10
text run at (0,0) width 27: "xMax*"
RenderImage {image} at (0,0) size 30x60
KCanvasContainer {g} at (300,215) size 120x80 [transform={m=((1.00,0.00)(0.00,1.00)) t=(300.00,185.00)}]
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 115x10
text run at (0,0) width 115: "---------- slice ---------------------"
KCanvasContainer {g} at (300,215) size 50x30
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 27x10
text run at (0,0) width 27: "*YMin"
RenderImage {image} at (0,0) size 50x30
KCanvasContainer {g} at (370,215) size 50x30 [transform={m=((1.00,0.00)(0.00,1.00)) t=(70.00,0.00)}]
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 27x10
text run at (0,0) width 27: "*YMid"
RenderImage {image} at (0,0) size 50x30
KCanvasContainer {g} at (300,265) size 50x30 [transform={m=((1.00,0.00)(0.00,1.00)) t=(0.00,50.00)}]
- RenderSVGText {text} at (0,0) size 465x10
+ RenderSVGText {text} at (0,0) size 785x10
RenderText {TEXT} at (0,0) size 28x10
text run at (0,0) width 28: "*YMax"
RenderImage {image} at (0,0) size 50x30
- RenderSVGText {text} at (0,0) size 465x46
+ RenderSVGText {text} at (0,0) size 785x46
RenderText {TEXT} at (0,0) size 264x46
text run at (0,0) width 264: "$Revision: 1.1 $"
KCanvasItem {rect} at (0.50,0.50) size 479x359 [stroke={[type=SOLID] [color=#000000]}] [data="M1.00,1.00L479.00,1.00L479.00,359.00L1.00,359.00"]
#include "GraphicsContext.h"
#include "KCanvasMaskerQuartz.h"
+#include "SVGAnimatedPreserveAspectRatioImpl.h"
#include "KCanvasRenderingStyle.h"
#include "KCanvasResourcesQuartz.h"
#include "KRenderingDevice.h"
#include <kcanvas/KCanvas.h>
#include <kdom/core/AttrImpl.h>
+#include "SVGImageElementImpl.h"
+
+#include "ksvg.h"
+
namespace WebCore {
RenderSVGImage::RenderSVGImage(SVGImageElementImpl *impl)
{
}
+void RenderSVGImage::adjustRectsForAspectRatio(FloatRect& destRect, FloatRect& srcRect, SVGPreserveAspectRatioImpl *aspectRatio)
+{
+ float origDestWidth = destRect.width();
+ float origDestHeight = destRect.height();
+ if (aspectRatio->meetOrSlice() == SVG_MEETORSLICE_MEET) {
+ float widthToHeightMultiplier = srcRect.height() / srcRect.width();
+ if (origDestHeight > (origDestWidth * widthToHeightMultiplier)) {
+ destRect.setHeight(origDestWidth * widthToHeightMultiplier);
+ switch(aspectRatio->align()) {
+ case SVG_PRESERVEASPECTRATIO_XMINYMID:
+ case SVG_PRESERVEASPECTRATIO_XMIDYMID:
+ case SVG_PRESERVEASPECTRATIO_XMAXYMID:
+ destRect.setY(origDestHeight / 2 - destRect.height() / 2);
+ break;
+ case SVG_PRESERVEASPECTRATIO_XMINYMAX:
+ case SVG_PRESERVEASPECTRATIO_XMIDYMAX:
+ case SVG_PRESERVEASPECTRATIO_XMAXYMAX:
+ destRect.setY(origDestHeight - destRect.height());
+ break;
+ }
+ }
+ if (origDestWidth > (origDestHeight / widthToHeightMultiplier)) {
+ destRect.setWidth(origDestHeight / widthToHeightMultiplier);
+ switch(aspectRatio->align()) {
+ case SVG_PRESERVEASPECTRATIO_XMIDYMIN:
+ case SVG_PRESERVEASPECTRATIO_XMIDYMID:
+ case SVG_PRESERVEASPECTRATIO_XMIDYMAX:
+ destRect.setX(origDestWidth / 2 - destRect.width() / 2);
+ break;
+ case SVG_PRESERVEASPECTRATIO_XMAXYMIN:
+ case SVG_PRESERVEASPECTRATIO_XMAXYMID:
+ case SVG_PRESERVEASPECTRATIO_XMAXYMAX:
+ destRect.setX(origDestWidth - destRect.width());
+ break;
+ }
+ }
+ } else if (aspectRatio->meetOrSlice() == SVG_MEETORSLICE_SLICE) {
+ float widthToHeightMultiplier = srcRect.height() / srcRect.width();
+ // if the destination height is less than the height of the image we'll be drawing
+ if (origDestHeight < (origDestWidth * widthToHeightMultiplier)) {
+ float destToSrcMultiplier = srcRect.width() / destRect.width();
+ srcRect.setHeight(destRect.height() * destToSrcMultiplier);
+ switch(aspectRatio->align()) {
+ case SVG_PRESERVEASPECTRATIO_XMINYMID:
+ case SVG_PRESERVEASPECTRATIO_XMIDYMID:
+ case SVG_PRESERVEASPECTRATIO_XMAXYMID:
+ srcRect.setY(image()->height() / 2 - srcRect.height() / 2);
+ break;
+ case SVG_PRESERVEASPECTRATIO_XMINYMAX:
+ case SVG_PRESERVEASPECTRATIO_XMIDYMAX:
+ case SVG_PRESERVEASPECTRATIO_XMAXYMAX:
+ srcRect.setY(image()->height() - srcRect.height());
+ break;
+ }
+ }
+ // if the destination width is less than the width of the image we'll be drawing
+ if (origDestWidth < (origDestHeight / widthToHeightMultiplier)) {
+ float destToSrcMultiplier = srcRect.height() / destRect.height();
+ srcRect.setWidth(destRect.width() * destToSrcMultiplier);
+ switch(aspectRatio->align()) {
+ case SVG_PRESERVEASPECTRATIO_XMIDYMIN:
+ case SVG_PRESERVEASPECTRATIO_XMIDYMID:
+ case SVG_PRESERVEASPECTRATIO_XMIDYMAX:
+ srcRect.setX(image()->width() / 2 - srcRect.width() / 2);
+ break;
+ case SVG_PRESERVEASPECTRATIO_XMAXYMIN:
+ case SVG_PRESERVEASPECTRATIO_XMAXYMID:
+ case SVG_PRESERVEASPECTRATIO_XMAXYMAX:
+ srcRect.setX(image()->width() - srcRect.width());
+ break;
+ }
+ }
+ }
+}
+
void RenderSVGImage::paint(PaintInfo& paintInfo, int parentX, int parentY)
{
if (paintInfo.p->paintingDisabled() || (paintInfo.phase != PaintActionForeground) || style()->visibility() == HIDDEN)
translateForAttributes();
FloatRect boundingBox = relativeBBox(true);
- const KSVG::SVGRenderStyle *svgStyle = style()->svgStyle();
+ const SVGRenderStyle *svgStyle = style()->svgStyle();
if (KCanvasClipper *clipper = getClipperById(document(), svgStyle->clipPath().mid(1)))
clipper->applyClip(boundingBox);
if (filter)
filter->prepareFilter(boundingBox);
- RenderImage::paint(paintInfo, 0, 0);
-
+ int x = 0, y = 0;
+ if (!shouldPaint(paintInfo, x, y))
+ return;
+
+ SVGImageElementImpl *imageElt = static_cast<SVGImageElementImpl *>(node());
+
+ if (imageElt->preserveAspectRatio()->baseVal()->align() == SVG_PRESERVEASPECTRATIO_NONE)
+ RenderImage::paint(paintInfo, 0, 0);
+ else {
+ FloatRect destRect(m_x, m_y, contentWidth(), contentHeight());
+ FloatRect srcRect(0, 0, image()->width(), image()->height());
+ adjustRectsForAspectRatio(destRect, srcRect, imageElt->preserveAspectRatio()->baseVal());
+ paintInfo.p->drawFloatImage(image(),
+ destRect.x(), destRect.y(), destRect.width(), destRect.height(),
+ srcRect.x(), srcRect.y(), srcRect.width(), srcRect.height(),
+ Image::CompositeSourceOver);
+ }
+
if (filter)
filter->applyFilter(boundingBox);
-
+
// restore drawing state
if (shouldPopContext) {
device->popContext();