[PATCH] SVG import: keep aspect ratio when transforming viewbox to viewport

Christina Rossmanith ChrRossmanith at web.de
Sat Mar 17 14:06:22 PDT 2012


---
 filter/source/svg/svgreader.cxx |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/filter/source/svg/svgreader.cxx b/filter/source/svg/svgreader.cxx
index 5d46c7c..cd5da23 100644
--- a/filter/source/svg/svgreader.cxx
+++ b/filter/source/svg/svgreader.cxx
@@ -293,12 +293,13 @@ struct AnnotatingVisitor
                     maCurrState.maViewBox.getWidth() != 0.0 &&
                     maCurrState.maViewBox.getHeight() != 0.0 )
                 {
-                    // transform aViewBox into viewport, such that they
-                    // coincide
+                    // transform aViewBox into viewport, keep aspect ratio
                     aLocalTransform.translate(-maCurrState.maViewBox.getMinX(),
                                               -maCurrState.maViewBox.getMinY());
-                    aLocalTransform.scale(maCurrState.maViewport.getWidth()/maCurrState.maViewBox.getWidth(),
-                                          maCurrState.maViewport.getHeight()/maCurrState.maViewBox.getHeight());
+                    double scaleW = maCurrState.maViewport.getWidth()/maCurrState.maViewBox.getWidth();
+                    double scaleH = maCurrState.maViewport.getHeight()/maCurrState.maViewBox.getHeight();
+                    double scale = (scaleW < scaleH) ? scaleW : scaleH;
+                    aLocalTransform.scale(scale,scale);
                 }
                 maCurrState.maCTM = maCurrState.maCTM*maCurrState.maTransform*aLocalTransform;
 
-- 
1.7.4.1


--------------050005010603020709040805--


More information about the LibreOffice mailing list