109dbbe93SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 309dbbe93SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 409dbbe93SAndrew Rist * or more contributor license agreements. See the NOTICE file 509dbbe93SAndrew Rist * distributed with this work for additional information 609dbbe93SAndrew Rist * regarding copyright ownership. The ASF licenses this file 709dbbe93SAndrew Rist * to you under the Apache License, Version 2.0 (the 809dbbe93SAndrew Rist * "License"); you may not use this file except in compliance 909dbbe93SAndrew Rist * with the License. You may obtain a copy of the License at 1009dbbe93SAndrew Rist * 1109dbbe93SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1209dbbe93SAndrew Rist * 1309dbbe93SAndrew Rist * Unless required by applicable law or agreed to in writing, 1409dbbe93SAndrew Rist * software distributed under the License is distributed on an 1509dbbe93SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1609dbbe93SAndrew Rist * KIND, either express or implied. See the License for the 1709dbbe93SAndrew Rist * specific language governing permissions and limitations 1809dbbe93SAndrew Rist * under the License. 1909dbbe93SAndrew Rist * 2009dbbe93SAndrew Rist *************************************************************/ 2109dbbe93SAndrew Rist 2209dbbe93SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_basegfx.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx> 28cdf0e10cSrcweir #include <rtl/ustring.hxx> 29cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////// 32cdf0e10cSrcweir 33cdf0e10cSrcweir namespace basegfx 34cdf0e10cSrcweir { exportToSvg(const B2DHomMatrix & rMatrix)35cdf0e10cSrcweir ::rtl::OUString exportToSvg( const B2DHomMatrix& rMatrix ) 36cdf0e10cSrcweir { 37cdf0e10cSrcweir rtl::OUStringBuffer aStrBuf; 38cdf0e10cSrcweir aStrBuf.appendAscii("matrix("); 39cdf0e10cSrcweir 40cdf0e10cSrcweir aStrBuf.append(rMatrix.get(0,0)); 41cdf0e10cSrcweir aStrBuf.appendAscii(", "); 42cdf0e10cSrcweir 43cdf0e10cSrcweir aStrBuf.append(rMatrix.get(1,0)); 44cdf0e10cSrcweir aStrBuf.appendAscii(", "); 45cdf0e10cSrcweir 46cdf0e10cSrcweir aStrBuf.append(rMatrix.get(0,1)); 47cdf0e10cSrcweir aStrBuf.appendAscii(", "); 48cdf0e10cSrcweir 49cdf0e10cSrcweir aStrBuf.append(rMatrix.get(1,1)); 50cdf0e10cSrcweir aStrBuf.appendAscii(", "); 51cdf0e10cSrcweir 52cdf0e10cSrcweir aStrBuf.append(rMatrix.get(0,2)); 53cdf0e10cSrcweir aStrBuf.appendAscii(", "); 54cdf0e10cSrcweir 55cdf0e10cSrcweir aStrBuf.append(rMatrix.get(1,2)); 56cdf0e10cSrcweir aStrBuf.appendAscii(")"); 57cdf0e10cSrcweir 58cdf0e10cSrcweir return aStrBuf.makeStringAndClear(); 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir namespace tools 62cdf0e10cSrcweir { createSinCosOrthogonal(double & o_rSin,double & o_rCos,double fRadiant)63cdf0e10cSrcweir void createSinCosOrthogonal(double& o_rSin, double& o_rCos, double fRadiant) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir if( fTools::equalZero( fmod( fRadiant, F_PI2 ) ) ) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir // determine quadrant 68cdf0e10cSrcweir const sal_Int32 nQuad( 69cdf0e10cSrcweir (4 + fround( 4/F_2PI*fmod( fRadiant, F_2PI ) )) % 4 ); 70cdf0e10cSrcweir switch( nQuad ) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir case 0: // -2pi,0,2pi 73cdf0e10cSrcweir o_rSin = 0.0; 74cdf0e10cSrcweir o_rCos = 1.0; 75cdf0e10cSrcweir break; 76cdf0e10cSrcweir 77cdf0e10cSrcweir case 1: // -3/2pi,1/2pi 78cdf0e10cSrcweir o_rSin = 1.0; 79cdf0e10cSrcweir o_rCos = 0.0; 80cdf0e10cSrcweir break; 81cdf0e10cSrcweir 82cdf0e10cSrcweir case 2: // -pi,pi 83cdf0e10cSrcweir o_rSin = 0.0; 84cdf0e10cSrcweir o_rCos = -1.0; 85cdf0e10cSrcweir break; 86cdf0e10cSrcweir 87cdf0e10cSrcweir case 3: // -1/2pi,3/2pi 88cdf0e10cSrcweir o_rSin = -1.0; 89cdf0e10cSrcweir o_rCos = 0.0; 90cdf0e10cSrcweir break; 91cdf0e10cSrcweir 92cdf0e10cSrcweir default: 93cdf0e10cSrcweir OSL_ENSURE( false, "createSinCos: Impossible case reached" ); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir } 96cdf0e10cSrcweir else 97cdf0e10cSrcweir { 98cdf0e10cSrcweir // TODO(P1): Maybe use glibc's sincos here (though 99cdf0e10cSrcweir // that's kinda non-portable...) 100cdf0e10cSrcweir o_rSin = sin(fRadiant); 101cdf0e10cSrcweir o_rCos = cos(fRadiant); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir } 104cdf0e10cSrcweir createScaleB2DHomMatrix(double fScaleX,double fScaleY)105cdf0e10cSrcweir B2DHomMatrix createScaleB2DHomMatrix(double fScaleX, double fScaleY) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir B2DHomMatrix aRetval; 108cdf0e10cSrcweir const double fOne(1.0); 109cdf0e10cSrcweir 110cdf0e10cSrcweir if(!fTools::equal(fScaleX, fOne)) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir aRetval.set(0, 0, fScaleX); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir if(!fTools::equal(fScaleY, fOne)) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir aRetval.set(1, 1, fScaleY); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir return aRetval; 121cdf0e10cSrcweir } 122cdf0e10cSrcweir createShearXB2DHomMatrix(double fShearX)123cdf0e10cSrcweir B2DHomMatrix createShearXB2DHomMatrix(double fShearX) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir B2DHomMatrix aRetval; 126cdf0e10cSrcweir 127cdf0e10cSrcweir if(!fTools::equalZero(fShearX)) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir aRetval.set(0, 1, fShearX); 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir return aRetval; 133cdf0e10cSrcweir } 134cdf0e10cSrcweir createShearYB2DHomMatrix(double fShearY)135cdf0e10cSrcweir B2DHomMatrix createShearYB2DHomMatrix(double fShearY) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir B2DHomMatrix aRetval; 138cdf0e10cSrcweir 139cdf0e10cSrcweir if(!fTools::equalZero(fShearY)) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir aRetval.set(1, 0, fShearY); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir return aRetval; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir createRotateB2DHomMatrix(double fRadiant)147cdf0e10cSrcweir B2DHomMatrix createRotateB2DHomMatrix(double fRadiant) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir B2DHomMatrix aRetval; 150cdf0e10cSrcweir 151cdf0e10cSrcweir if(!fTools::equalZero(fRadiant)) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir double fSin(0.0); 154cdf0e10cSrcweir double fCos(1.0); 155cdf0e10cSrcweir 156cdf0e10cSrcweir createSinCosOrthogonal(fSin, fCos, fRadiant); 157cdf0e10cSrcweir aRetval.set(0, 0, fCos); 158cdf0e10cSrcweir aRetval.set(1, 1, fCos); 159cdf0e10cSrcweir aRetval.set(1, 0, fSin); 160cdf0e10cSrcweir aRetval.set(0, 1, -fSin); 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir return aRetval; 164cdf0e10cSrcweir } 165cdf0e10cSrcweir createTranslateB2DHomMatrix(double fTranslateX,double fTranslateY)166cdf0e10cSrcweir B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir B2DHomMatrix aRetval; 169cdf0e10cSrcweir 170cdf0e10cSrcweir if(!(fTools::equalZero(fTranslateX) && fTools::equalZero(fTranslateY))) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir aRetval.set(0, 2, fTranslateX); 173cdf0e10cSrcweir aRetval.set(1, 2, fTranslateY); 174cdf0e10cSrcweir } 175cdf0e10cSrcweir 176cdf0e10cSrcweir return aRetval; 177cdf0e10cSrcweir } 178cdf0e10cSrcweir createScaleShearXRotateTranslateB2DHomMatrix(double fScaleX,double fScaleY,double fShearX,double fRadiant,double fTranslateX,double fTranslateY)179cdf0e10cSrcweir B2DHomMatrix createScaleShearXRotateTranslateB2DHomMatrix( 180cdf0e10cSrcweir double fScaleX, double fScaleY, 181cdf0e10cSrcweir double fShearX, 182cdf0e10cSrcweir double fRadiant, 183cdf0e10cSrcweir double fTranslateX, double fTranslateY) 184cdf0e10cSrcweir { 185cdf0e10cSrcweir const double fOne(1.0); 186cdf0e10cSrcweir 187cdf0e10cSrcweir if(fTools::equal(fScaleX, fOne) && fTools::equal(fScaleY, fOne)) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir /// no scale, take shortcut 190cdf0e10cSrcweir return createShearXRotateTranslateB2DHomMatrix(fShearX, fRadiant, fTranslateX, fTranslateY); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir else 193cdf0e10cSrcweir { 194cdf0e10cSrcweir /// scale used 195cdf0e10cSrcweir if(fTools::equalZero(fShearX)) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir /// no shear 198cdf0e10cSrcweir if(fTools::equalZero(fRadiant)) 199cdf0e10cSrcweir { 200cdf0e10cSrcweir /// no rotate, take shortcut 201cdf0e10cSrcweir return createScaleTranslateB2DHomMatrix(fScaleX, fScaleY, fTranslateX, fTranslateY); 202cdf0e10cSrcweir } 203cdf0e10cSrcweir else 204cdf0e10cSrcweir { 205cdf0e10cSrcweir /// rotate and scale used, no shear 206cdf0e10cSrcweir double fSin(0.0); 207cdf0e10cSrcweir double fCos(1.0); 208cdf0e10cSrcweir 209cdf0e10cSrcweir createSinCosOrthogonal(fSin, fCos, fRadiant); 210cdf0e10cSrcweir 211cdf0e10cSrcweir B2DHomMatrix aRetval( 212cdf0e10cSrcweir /* Row 0, Column 0 */ fCos * fScaleX, 213cdf0e10cSrcweir /* Row 0, Column 1 */ fScaleY * -fSin, 214cdf0e10cSrcweir /* Row 0, Column 2 */ fTranslateX, 215cdf0e10cSrcweir /* Row 1, Column 0 */ fSin * fScaleX, 216cdf0e10cSrcweir /* Row 1, Column 1 */ fScaleY * fCos, 217cdf0e10cSrcweir /* Row 1, Column 2 */ fTranslateY); 218cdf0e10cSrcweir 219cdf0e10cSrcweir return aRetval; 220cdf0e10cSrcweir } 221cdf0e10cSrcweir } 222cdf0e10cSrcweir else 223cdf0e10cSrcweir { 224cdf0e10cSrcweir /// scale and shear used 225cdf0e10cSrcweir if(fTools::equalZero(fRadiant)) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir /// scale and shear, but no rotate 228cdf0e10cSrcweir B2DHomMatrix aRetval( 229cdf0e10cSrcweir /* Row 0, Column 0 */ fScaleX, 230cdf0e10cSrcweir /* Row 0, Column 1 */ fScaleY * fShearX, 231cdf0e10cSrcweir /* Row 0, Column 2 */ fTranslateX, 232cdf0e10cSrcweir /* Row 1, Column 0 */ 0.0, 233cdf0e10cSrcweir /* Row 1, Column 1 */ fScaleY, 234cdf0e10cSrcweir /* Row 1, Column 2 */ fTranslateY); 235cdf0e10cSrcweir 236cdf0e10cSrcweir return aRetval; 237cdf0e10cSrcweir } 238cdf0e10cSrcweir else 239cdf0e10cSrcweir { 240cdf0e10cSrcweir /// scale, shear and rotate used 241cdf0e10cSrcweir double fSin(0.0); 242cdf0e10cSrcweir double fCos(1.0); 243cdf0e10cSrcweir 244cdf0e10cSrcweir createSinCosOrthogonal(fSin, fCos, fRadiant); 245cdf0e10cSrcweir 246cdf0e10cSrcweir B2DHomMatrix aRetval( 247cdf0e10cSrcweir /* Row 0, Column 0 */ fCos * fScaleX, 248cdf0e10cSrcweir /* Row 0, Column 1 */ fScaleY * ((fCos * fShearX) - fSin), 249cdf0e10cSrcweir /* Row 0, Column 2 */ fTranslateX, 250cdf0e10cSrcweir /* Row 1, Column 0 */ fSin * fScaleX, 251cdf0e10cSrcweir /* Row 1, Column 1 */ fScaleY * ((fSin * fShearX) + fCos), 252cdf0e10cSrcweir /* Row 1, Column 2 */ fTranslateY); 253cdf0e10cSrcweir 254cdf0e10cSrcweir return aRetval; 255cdf0e10cSrcweir } 256cdf0e10cSrcweir } 257cdf0e10cSrcweir } 258cdf0e10cSrcweir } 259cdf0e10cSrcweir createShearXRotateTranslateB2DHomMatrix(double fShearX,double fRadiant,double fTranslateX,double fTranslateY)260cdf0e10cSrcweir B2DHomMatrix createShearXRotateTranslateB2DHomMatrix( 261cdf0e10cSrcweir double fShearX, 262cdf0e10cSrcweir double fRadiant, 263cdf0e10cSrcweir double fTranslateX, double fTranslateY) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir if(fTools::equalZero(fShearX)) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir /// no shear 268cdf0e10cSrcweir if(fTools::equalZero(fRadiant)) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir /// no shear, no rotate, take shortcut 271cdf0e10cSrcweir return createTranslateB2DHomMatrix(fTranslateX, fTranslateY); 272cdf0e10cSrcweir } 273cdf0e10cSrcweir else 274cdf0e10cSrcweir { 275cdf0e10cSrcweir /// no shear, but rotate used 276cdf0e10cSrcweir double fSin(0.0); 277cdf0e10cSrcweir double fCos(1.0); 278cdf0e10cSrcweir 279cdf0e10cSrcweir createSinCosOrthogonal(fSin, fCos, fRadiant); 280cdf0e10cSrcweir 281cdf0e10cSrcweir B2DHomMatrix aRetval( 282cdf0e10cSrcweir /* Row 0, Column 0 */ fCos, 283cdf0e10cSrcweir /* Row 0, Column 1 */ -fSin, 284cdf0e10cSrcweir /* Row 0, Column 2 */ fTranslateX, 285cdf0e10cSrcweir /* Row 1, Column 0 */ fSin, 286cdf0e10cSrcweir /* Row 1, Column 1 */ fCos, 287cdf0e10cSrcweir /* Row 1, Column 2 */ fTranslateY); 288cdf0e10cSrcweir 289cdf0e10cSrcweir return aRetval; 290cdf0e10cSrcweir } 291cdf0e10cSrcweir } 292cdf0e10cSrcweir else 293cdf0e10cSrcweir { 294cdf0e10cSrcweir /// shear used 295cdf0e10cSrcweir if(fTools::equalZero(fRadiant)) 296cdf0e10cSrcweir { 297cdf0e10cSrcweir /// no rotate, but shear used 298cdf0e10cSrcweir B2DHomMatrix aRetval( 299cdf0e10cSrcweir /* Row 0, Column 0 */ 1.0, 300cdf0e10cSrcweir /* Row 0, Column 1 */ fShearX, 301cdf0e10cSrcweir /* Row 0, Column 2 */ fTranslateX, 302cdf0e10cSrcweir /* Row 1, Column 0 */ 0.0, 303cdf0e10cSrcweir /* Row 1, Column 1 */ 1.0, 304cdf0e10cSrcweir /* Row 1, Column 2 */ fTranslateY); 305cdf0e10cSrcweir 306cdf0e10cSrcweir return aRetval; 307cdf0e10cSrcweir } 308cdf0e10cSrcweir else 309cdf0e10cSrcweir { 310cdf0e10cSrcweir /// shear and rotate used 311cdf0e10cSrcweir double fSin(0.0); 312cdf0e10cSrcweir double fCos(1.0); 313cdf0e10cSrcweir 314cdf0e10cSrcweir createSinCosOrthogonal(fSin, fCos, fRadiant); 315cdf0e10cSrcweir 316cdf0e10cSrcweir B2DHomMatrix aRetval( 317cdf0e10cSrcweir /* Row 0, Column 0 */ fCos, 318cdf0e10cSrcweir /* Row 0, Column 1 */ (fCos * fShearX) - fSin, 319cdf0e10cSrcweir /* Row 0, Column 2 */ fTranslateX, 320cdf0e10cSrcweir /* Row 1, Column 0 */ fSin, 321cdf0e10cSrcweir /* Row 1, Column 1 */ (fSin * fShearX) + fCos, 322cdf0e10cSrcweir /* Row 1, Column 2 */ fTranslateY); 323cdf0e10cSrcweir 324cdf0e10cSrcweir return aRetval; 325cdf0e10cSrcweir } 326cdf0e10cSrcweir } 327cdf0e10cSrcweir } 328cdf0e10cSrcweir createScaleTranslateB2DHomMatrix(double fScaleX,double fScaleY,double fTranslateX,double fTranslateY)329cdf0e10cSrcweir B2DHomMatrix createScaleTranslateB2DHomMatrix( 330cdf0e10cSrcweir double fScaleX, double fScaleY, 331cdf0e10cSrcweir double fTranslateX, double fTranslateY) 332cdf0e10cSrcweir { 333cdf0e10cSrcweir const double fOne(1.0); 334cdf0e10cSrcweir 335cdf0e10cSrcweir if(fTools::equal(fScaleX, fOne) && fTools::equal(fScaleY, fOne)) 336cdf0e10cSrcweir { 337cdf0e10cSrcweir /// no scale, take shortcut 338cdf0e10cSrcweir return createTranslateB2DHomMatrix(fTranslateX, fTranslateY); 339cdf0e10cSrcweir } 340cdf0e10cSrcweir else 341cdf0e10cSrcweir { 342cdf0e10cSrcweir /// scale used 343cdf0e10cSrcweir if(fTools::equalZero(fTranslateX) && fTools::equalZero(fTranslateY)) 344cdf0e10cSrcweir { 345cdf0e10cSrcweir /// no translate, but scale. 346cdf0e10cSrcweir B2DHomMatrix aRetval; 347cdf0e10cSrcweir 348cdf0e10cSrcweir aRetval.set(0, 0, fScaleX); 349cdf0e10cSrcweir aRetval.set(1, 1, fScaleY); 350cdf0e10cSrcweir 351cdf0e10cSrcweir return aRetval; 352cdf0e10cSrcweir } 353cdf0e10cSrcweir else 354cdf0e10cSrcweir { 355cdf0e10cSrcweir /// translate and scale 356cdf0e10cSrcweir B2DHomMatrix aRetval( 357cdf0e10cSrcweir /* Row 0, Column 0 */ fScaleX, 358cdf0e10cSrcweir /* Row 0, Column 1 */ 0.0, 359cdf0e10cSrcweir /* Row 0, Column 2 */ fTranslateX, 360cdf0e10cSrcweir /* Row 1, Column 0 */ 0.0, 361cdf0e10cSrcweir /* Row 1, Column 1 */ fScaleY, 362cdf0e10cSrcweir /* Row 1, Column 2 */ fTranslateY); 363cdf0e10cSrcweir 364cdf0e10cSrcweir return aRetval; 365cdf0e10cSrcweir } 366cdf0e10cSrcweir } 367cdf0e10cSrcweir } 368cdf0e10cSrcweir createRotateAroundPoint(double fPointX,double fPointY,double fRadiant)369cdf0e10cSrcweir B2DHomMatrix createRotateAroundPoint( 370cdf0e10cSrcweir double fPointX, double fPointY, 371cdf0e10cSrcweir double fRadiant) 372cdf0e10cSrcweir { 373cdf0e10cSrcweir B2DHomMatrix aRetval; 374cdf0e10cSrcweir 375cdf0e10cSrcweir if(!fTools::equalZero(fRadiant)) 376cdf0e10cSrcweir { 377cdf0e10cSrcweir double fSin(0.0); 378cdf0e10cSrcweir double fCos(1.0); 379cdf0e10cSrcweir 380cdf0e10cSrcweir createSinCosOrthogonal(fSin, fCos, fRadiant); 381cdf0e10cSrcweir 382cdf0e10cSrcweir aRetval.set3x2( 383cdf0e10cSrcweir /* Row 0, Column 0 */ fCos, 384cdf0e10cSrcweir /* Row 0, Column 1 */ -fSin, 385cdf0e10cSrcweir /* Row 0, Column 2 */ (fPointX * (1.0 - fCos)) + (fSin * fPointY), 386cdf0e10cSrcweir /* Row 1, Column 0 */ fSin, 387cdf0e10cSrcweir /* Row 1, Column 1 */ fCos, 388cdf0e10cSrcweir /* Row 1, Column 2 */ (fPointY * (1.0 - fCos)) - (fSin * fPointX)); 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir return aRetval; 392cdf0e10cSrcweir } 393*d8ed516eSArmin Le Grand 394*d8ed516eSArmin Le Grand /// special for the case to map from source range to target range createSourceRangeTargetRangeTransform(const B2DRange & rSourceRange,const B2DRange & rTargetRange)395*d8ed516eSArmin Le Grand B2DHomMatrix createSourceRangeTargetRangeTransform( 396*d8ed516eSArmin Le Grand const B2DRange& rSourceRange, 397*d8ed516eSArmin Le Grand const B2DRange& rTargetRange) 398*d8ed516eSArmin Le Grand { 399*d8ed516eSArmin Le Grand B2DHomMatrix aRetval; 400*d8ed516eSArmin Le Grand 401*d8ed516eSArmin Le Grand if(&rSourceRange == &rTargetRange) 402*d8ed516eSArmin Le Grand { 403*d8ed516eSArmin Le Grand return aRetval; 404*d8ed516eSArmin Le Grand } 405*d8ed516eSArmin Le Grand 406*d8ed516eSArmin Le Grand if(!fTools::equalZero(rSourceRange.getMinX()) || !fTools::equalZero(rSourceRange.getMinY())) 407*d8ed516eSArmin Le Grand { 408*d8ed516eSArmin Le Grand aRetval.set(0, 2, -rSourceRange.getMinX()); 409*d8ed516eSArmin Le Grand aRetval.set(1, 2, -rSourceRange.getMinY()); 410*d8ed516eSArmin Le Grand } 411*d8ed516eSArmin Le Grand 412*d8ed516eSArmin Le Grand const double fSourceW(rSourceRange.getWidth()); 413*d8ed516eSArmin Le Grand const double fSourceH(rSourceRange.getHeight()); 414*d8ed516eSArmin Le Grand const bool bDivX(!fTools::equalZero(fSourceW) && !fTools::equal(fSourceW, 1.0)); 415*d8ed516eSArmin Le Grand const bool bDivY(!fTools::equalZero(fSourceH) && !fTools::equal(fSourceH, 1.0)); 416*d8ed516eSArmin Le Grand const double fScaleX(bDivX ? rTargetRange.getWidth() / fSourceW : rTargetRange.getWidth()); 417*d8ed516eSArmin Le Grand const double fScaleY(bDivY ? rTargetRange.getHeight() / fSourceH : rTargetRange.getHeight()); 418*d8ed516eSArmin Le Grand 419*d8ed516eSArmin Le Grand if(!fTools::equalZero(fScaleX) || !fTools::equalZero(fScaleY)) 420*d8ed516eSArmin Le Grand { 421*d8ed516eSArmin Le Grand aRetval.scale(fScaleX, fScaleY); 422*d8ed516eSArmin Le Grand } 423*d8ed516eSArmin Le Grand 424*d8ed516eSArmin Le Grand if(!fTools::equalZero(rTargetRange.getMinX()) || !fTools::equalZero(rTargetRange.getMinY())) 425*d8ed516eSArmin Le Grand { 426*d8ed516eSArmin Le Grand aRetval.translate( 427*d8ed516eSArmin Le Grand rTargetRange.getMinX(), 428*d8ed516eSArmin Le Grand rTargetRange.getMinY()); 429*d8ed516eSArmin Le Grand } 430*d8ed516eSArmin Le Grand 431*d8ed516eSArmin Le Grand return aRetval; 432*d8ed516eSArmin Le Grand } 433*d8ed516eSArmin Le Grand 434cdf0e10cSrcweir } // end of namespace tools 435cdf0e10cSrcweir } // end of namespace basegfx 436cdf0e10cSrcweir 437cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////// 438cdf0e10cSrcweir // eof 439