1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_vcl.hxx" 30*cdf0e10cSrcweir #include <tools/debug.hxx> 31*cdf0e10cSrcweir #include <vcl/salbtype.hxx> 32*cdf0e10cSrcweir #include <vcl/regband.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include <algorithm> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir // ======================================================================= 38*cdf0e10cSrcweir // 39*cdf0e10cSrcweir // ImplRegionBand 40*cdf0e10cSrcweir // 41*cdf0e10cSrcweir // Jedes Band enthaelt die zwischen der enthaltenen Ober- und Untergrenze 42*cdf0e10cSrcweir // enthaltenen Rechtecke. Bei den Operationen Union, Intersect, XOr und 43*cdf0e10cSrcweir // Exclude werden immer Rechtecke der gleichen Hoehe ausgewerte; die 44*cdf0e10cSrcweir // Grenzen der Baender sind immer so zu waehlen, dasz dies moeglich ist. 45*cdf0e10cSrcweir // 46*cdf0e10cSrcweir // Die Rechtecke in den Baendern werden nach Moeglichkeit zusammengefaszt. 47*cdf0e10cSrcweir // 48*cdf0e10cSrcweir // Bei der Umwandlung von Polygonen werden alle Punkte des Polygons 49*cdf0e10cSrcweir // in die einzelnen Baender eingetragen (sie stehen fuer jedes Band als 50*cdf0e10cSrcweir // Punkte in einer Liste). Nach dem Eintragen der Punkte werden diese 51*cdf0e10cSrcweir // in Rechtecke umgewandelt und die Liste der Punkte geloescht. 52*cdf0e10cSrcweir // 53*cdf0e10cSrcweir // ----------------------------------------------------------------------- 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir ImplRegionBand::ImplRegionBand( long nTop, long nBottom ) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir // save boundaries 58*cdf0e10cSrcweir mnYTop = nTop; 59*cdf0e10cSrcweir mnYBottom = nBottom; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir // initialize lists 62*cdf0e10cSrcweir mpNextBand = NULL; 63*cdf0e10cSrcweir mpPrevBand = NULL; 64*cdf0e10cSrcweir mpFirstSep = NULL; 65*cdf0e10cSrcweir mpFirstBandPoint = NULL; 66*cdf0e10cSrcweir mbTouched = sal_False; 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir // ----------------------------------------------------------------------- 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir ImplRegionBand::ImplRegionBand( 72*cdf0e10cSrcweir const ImplRegionBand& rRegionBand, 73*cdf0e10cSrcweir const bool bIgnorePoints) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir // copy boundaries 76*cdf0e10cSrcweir mnYTop = rRegionBand.mnYTop; 77*cdf0e10cSrcweir mnYBottom = rRegionBand.mnYBottom; 78*cdf0e10cSrcweir mbTouched = rRegionBand.mbTouched; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir // initialisation 81*cdf0e10cSrcweir mpNextBand = NULL; 82*cdf0e10cSrcweir mpPrevBand = NULL; 83*cdf0e10cSrcweir mpFirstSep = NULL; 84*cdf0e10cSrcweir mpFirstBandPoint = NULL; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir // copy all elements of the list with separations 87*cdf0e10cSrcweir ImplRegionBandSep* pNewSep; 88*cdf0e10cSrcweir ImplRegionBandSep* pPrevSep = 0; 89*cdf0e10cSrcweir ImplRegionBandSep* pSep = rRegionBand.mpFirstSep; 90*cdf0e10cSrcweir while ( pSep ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir // create new and copy data 93*cdf0e10cSrcweir pNewSep = new ImplRegionBandSep; 94*cdf0e10cSrcweir pNewSep->mnXLeft = pSep->mnXLeft; 95*cdf0e10cSrcweir pNewSep->mnXRight = pSep->mnXRight; 96*cdf0e10cSrcweir pNewSep->mbRemoved = pSep->mbRemoved; 97*cdf0e10cSrcweir pNewSep->mpNextSep = NULL; 98*cdf0e10cSrcweir if ( pSep == rRegionBand.mpFirstSep ) 99*cdf0e10cSrcweir mpFirstSep = pNewSep; 100*cdf0e10cSrcweir else 101*cdf0e10cSrcweir pPrevSep->mpNextSep = pNewSep; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir pPrevSep = pNewSep; 104*cdf0e10cSrcweir pSep = pSep->mpNextSep; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir if ( ! bIgnorePoints) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir // Copy points. 110*cdf0e10cSrcweir ImplRegionBandPoint* pPoint = rRegionBand.mpFirstBandPoint; 111*cdf0e10cSrcweir ImplRegionBandPoint* pPrevPointCopy = NULL; 112*cdf0e10cSrcweir while (pPoint != NULL) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir ImplRegionBandPoint* pPointCopy = new ImplRegionBandPoint(); 115*cdf0e10cSrcweir pPointCopy->mnX = pPoint->mnX; 116*cdf0e10cSrcweir pPointCopy->mnLineId = pPoint->mnLineId; 117*cdf0e10cSrcweir pPointCopy->mbEndPoint = pPoint->mbEndPoint; 118*cdf0e10cSrcweir pPointCopy->meLineType = pPoint->meLineType; 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir if (pPrevPointCopy != NULL) 121*cdf0e10cSrcweir pPrevPointCopy->mpNextBandPoint = pPointCopy; 122*cdf0e10cSrcweir else 123*cdf0e10cSrcweir mpFirstBandPoint = pPointCopy; 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir pPrevPointCopy = pPointCopy; 126*cdf0e10cSrcweir pPoint = pPoint->mpNextBandPoint; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir // ----------------------------------------------------------------------- 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir ImplRegionBand::~ImplRegionBand() 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir DBG_ASSERT( mpFirstBandPoint == NULL, "ImplRegionBand::~ImplRegionBand -> pointlist not empty" ); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir // delete elements of the list 138*cdf0e10cSrcweir ImplRegionBandSep* pSep = mpFirstSep; 139*cdf0e10cSrcweir while ( pSep ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir ImplRegionBandSep* pTempSep = pSep->mpNextSep; 142*cdf0e10cSrcweir delete pSep; 143*cdf0e10cSrcweir pSep = pTempSep; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir // delete elements of the list 147*cdf0e10cSrcweir ImplRegionBandPoint* pPoint = mpFirstBandPoint; 148*cdf0e10cSrcweir while ( pPoint ) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir ImplRegionBandPoint* pTempPoint = pPoint->mpNextBandPoint; 151*cdf0e10cSrcweir delete pPoint; 152*cdf0e10cSrcweir pPoint = pTempPoint; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir // ----------------------------------------------------------------------- 157*cdf0e10cSrcweir // 158*cdf0e10cSrcweir // generate separations from lines and process union with existing 159*cdf0e10cSrcweir // separations 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir void ImplRegionBand::ProcessPoints() 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir // check Pointlist 164*cdf0e10cSrcweir ImplRegionBandPoint* pRegionBandPoint = mpFirstBandPoint; 165*cdf0e10cSrcweir while ( pRegionBandPoint ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir // within list? 168*cdf0e10cSrcweir if ( pRegionBandPoint && pRegionBandPoint->mpNextBandPoint ) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir // start/stop? 171*cdf0e10cSrcweir if ( pRegionBandPoint->mbEndPoint && pRegionBandPoint->mpNextBandPoint->mbEndPoint ) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir // same direction? -> remove next point! 174*cdf0e10cSrcweir if ( pRegionBandPoint->meLineType == pRegionBandPoint->mpNextBandPoint->meLineType ) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir ImplRegionBandPoint* pSaveRegionBandPoint = pRegionBandPoint->mpNextBandPoint; 177*cdf0e10cSrcweir pRegionBandPoint->mpNextBandPoint = pRegionBandPoint->mpNextBandPoint->mpNextBandPoint; 178*cdf0e10cSrcweir delete pSaveRegionBandPoint; 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir // continue with next element in the list 184*cdf0e10cSrcweir pRegionBandPoint = pRegionBandPoint->mpNextBandPoint; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir pRegionBandPoint = mpFirstBandPoint; 188*cdf0e10cSrcweir while ( pRegionBandPoint && pRegionBandPoint->mpNextBandPoint ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir Union( pRegionBandPoint->mnX, pRegionBandPoint->mpNextBandPoint->mnX ); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir ImplRegionBandPoint* pNextBandPoint = pRegionBandPoint->mpNextBandPoint->mpNextBandPoint; 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir // remove allready processed points 195*cdf0e10cSrcweir delete pRegionBandPoint->mpNextBandPoint; 196*cdf0e10cSrcweir delete pRegionBandPoint; 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir // continue with next element in the list 199*cdf0e10cSrcweir pRegionBandPoint = pNextBandPoint; 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir // remove last element if necessary 203*cdf0e10cSrcweir if ( pRegionBandPoint ) 204*cdf0e10cSrcweir delete pRegionBandPoint; 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir // list is now empty 207*cdf0e10cSrcweir mpFirstBandPoint = NULL; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir // ----------------------------------------------------------------------- 211*cdf0e10cSrcweir // 212*cdf0e10cSrcweir // generate separations from lines and process union with existing 213*cdf0e10cSrcweir // separations 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir sal_Bool ImplRegionBand::InsertPoint( long nX, long nLineId, 216*cdf0e10cSrcweir sal_Bool bEndPoint, LineType eLineType ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir if ( !mpFirstBandPoint ) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir mpFirstBandPoint = new ImplRegionBandPoint; 221*cdf0e10cSrcweir mpFirstBandPoint->mnX = nX; 222*cdf0e10cSrcweir mpFirstBandPoint->mnLineId = nLineId; 223*cdf0e10cSrcweir mpFirstBandPoint->mbEndPoint = bEndPoint; 224*cdf0e10cSrcweir mpFirstBandPoint->meLineType = eLineType; 225*cdf0e10cSrcweir mpFirstBandPoint->mpNextBandPoint = NULL; 226*cdf0e10cSrcweir return sal_True; 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir // look if line allready touched the band 230*cdf0e10cSrcweir ImplRegionBandPoint* pRegionBandPoint = mpFirstBandPoint; 231*cdf0e10cSrcweir ImplRegionBandPoint* pLastTestedRegionBandPoint = NULL; 232*cdf0e10cSrcweir while( pRegionBandPoint ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir if ( pRegionBandPoint->mnLineId == nLineId ) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir if ( bEndPoint ) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir if( !pRegionBandPoint->mbEndPoint ) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir // remove old band point 241*cdf0e10cSrcweir if( !mpFirstBandPoint->mpNextBandPoint ) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir // if we've only got one point => replace first point 244*cdf0e10cSrcweir pRegionBandPoint->mnX = nX; 245*cdf0e10cSrcweir pRegionBandPoint->mbEndPoint = sal_True; 246*cdf0e10cSrcweir return sal_True; 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir else 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir // remove current point 251*cdf0e10cSrcweir if( !pLastTestedRegionBandPoint ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir // remove and delete old first point 254*cdf0e10cSrcweir ImplRegionBandPoint* pSaveBandPoint = mpFirstBandPoint; 255*cdf0e10cSrcweir mpFirstBandPoint = mpFirstBandPoint->mpNextBandPoint; 256*cdf0e10cSrcweir delete pSaveBandPoint; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir else 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir // remove and delete current band point 261*cdf0e10cSrcweir pLastTestedRegionBandPoint->mpNextBandPoint = pRegionBandPoint->mpNextBandPoint; 262*cdf0e10cSrcweir delete pRegionBandPoint; 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir break; 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir else 270*cdf0e10cSrcweir return sal_False; 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir // use next element 274*cdf0e10cSrcweir pLastTestedRegionBandPoint = pRegionBandPoint; 275*cdf0e10cSrcweir pRegionBandPoint = pRegionBandPoint->mpNextBandPoint; 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir // search appropriate position and insert point into the list 279*cdf0e10cSrcweir ImplRegionBandPoint* pNewRegionBandPoint; 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir pRegionBandPoint = mpFirstBandPoint; 282*cdf0e10cSrcweir pLastTestedRegionBandPoint = NULL; 283*cdf0e10cSrcweir while ( pRegionBandPoint ) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir // new point completly left? -> insert as first point 286*cdf0e10cSrcweir if ( nX <= pRegionBandPoint->mnX ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir pNewRegionBandPoint = new ImplRegionBandPoint; 289*cdf0e10cSrcweir pNewRegionBandPoint->mnX = nX; 290*cdf0e10cSrcweir pNewRegionBandPoint->mnLineId = nLineId; 291*cdf0e10cSrcweir pNewRegionBandPoint->mbEndPoint = bEndPoint; 292*cdf0e10cSrcweir pNewRegionBandPoint->meLineType = eLineType; 293*cdf0e10cSrcweir pNewRegionBandPoint->mpNextBandPoint = pRegionBandPoint; 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir // connections to the new point 296*cdf0e10cSrcweir if ( !pLastTestedRegionBandPoint ) 297*cdf0e10cSrcweir mpFirstBandPoint = pNewRegionBandPoint; 298*cdf0e10cSrcweir else 299*cdf0e10cSrcweir pLastTestedRegionBandPoint->mpNextBandPoint = pNewRegionBandPoint; 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir return sal_True; 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir // use next element 305*cdf0e10cSrcweir pLastTestedRegionBandPoint = pRegionBandPoint; 306*cdf0e10cSrcweir pRegionBandPoint = pRegionBandPoint->mpNextBandPoint; 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir // not inserted -> add to the end of the list 310*cdf0e10cSrcweir pNewRegionBandPoint = new ImplRegionBandPoint; 311*cdf0e10cSrcweir pNewRegionBandPoint->mnX = nX; 312*cdf0e10cSrcweir pNewRegionBandPoint->mnLineId = nLineId; 313*cdf0e10cSrcweir pNewRegionBandPoint->mbEndPoint = bEndPoint; 314*cdf0e10cSrcweir pNewRegionBandPoint->meLineType = eLineType; 315*cdf0e10cSrcweir pNewRegionBandPoint->mpNextBandPoint = NULL; 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir // connections to the new point 318*cdf0e10cSrcweir pLastTestedRegionBandPoint->mpNextBandPoint = pNewRegionBandPoint; 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir return sal_True; 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir // ----------------------------------------------------------------------- 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir void ImplRegionBand::MoveX( long nHorzMove ) 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir // move all x-separations 328*cdf0e10cSrcweir ImplRegionBandSep* pSep = mpFirstSep; 329*cdf0e10cSrcweir while ( pSep ) 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir pSep->mnXLeft += nHorzMove; 332*cdf0e10cSrcweir pSep->mnXRight += nHorzMove; 333*cdf0e10cSrcweir pSep = pSep->mpNextSep; 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir // ----------------------------------------------------------------------- 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir void ImplRegionBand::ScaleX( double fHorzScale ) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir ImplRegionBandSep* pSep = mpFirstSep; 342*cdf0e10cSrcweir while ( pSep ) 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir pSep->mnXLeft = FRound( pSep->mnXLeft * fHorzScale ); 345*cdf0e10cSrcweir pSep->mnXRight = FRound( pSep->mnXRight * fHorzScale ); 346*cdf0e10cSrcweir pSep = pSep->mpNextSep; 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir // ----------------------------------------------------------------------- 351*cdf0e10cSrcweir // 352*cdf0e10cSrcweir // combine overlaping sparations 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir sal_Bool ImplRegionBand::OptimizeBand() 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir ImplRegionBandSep* pPrevSep = 0; 357*cdf0e10cSrcweir ImplRegionBandSep* pSep = mpFirstSep; 358*cdf0e10cSrcweir while ( pSep ) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir // remove? 361*cdf0e10cSrcweir if ( pSep->mbRemoved || (pSep->mnXRight < pSep->mnXLeft) ) 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir ImplRegionBandSep* pOldSep = pSep; 364*cdf0e10cSrcweir if ( pSep == mpFirstSep ) 365*cdf0e10cSrcweir mpFirstSep = pSep->mpNextSep; 366*cdf0e10cSrcweir else 367*cdf0e10cSrcweir pPrevSep->mpNextSep = pSep->mpNextSep; 368*cdf0e10cSrcweir pSep = pSep->mpNextSep; 369*cdf0e10cSrcweir delete pOldSep; 370*cdf0e10cSrcweir continue; 371*cdf0e10cSrcweir } 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir // overlaping separations? -> combine! 374*cdf0e10cSrcweir if ( pSep->mpNextSep ) 375*cdf0e10cSrcweir { 376*cdf0e10cSrcweir if ( (pSep->mnXRight+1) >= pSep->mpNextSep->mnXLeft ) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir if ( pSep->mpNextSep->mnXRight > pSep->mnXRight ) 379*cdf0e10cSrcweir pSep->mnXRight = pSep->mpNextSep->mnXRight; 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir ImplRegionBandSep* pOldSep = pSep->mpNextSep; 382*cdf0e10cSrcweir pSep->mpNextSep = pOldSep->mpNextSep; 383*cdf0e10cSrcweir delete pOldSep; 384*cdf0e10cSrcweir continue; 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir pPrevSep = pSep; 389*cdf0e10cSrcweir pSep = pSep->mpNextSep; 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir return sal_True; 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir // ----------------------------------------------------------------------- 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir void ImplRegionBand::Union( long nXLeft, long nXRight ) 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir DBG_ASSERT( nXLeft <= nXRight, "ImplRegionBand::Union(): nxLeft > nXRight" ); 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir // band empty? -> add element 402*cdf0e10cSrcweir if ( !mpFirstSep ) 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir mpFirstSep = new ImplRegionBandSep; 405*cdf0e10cSrcweir mpFirstSep->mnXLeft = nXLeft; 406*cdf0e10cSrcweir mpFirstSep->mnXRight = nXRight; 407*cdf0e10cSrcweir mpFirstSep->mbRemoved = sal_False; 408*cdf0e10cSrcweir mpFirstSep->mpNextSep = NULL; 409*cdf0e10cSrcweir return; 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir // process real union 413*cdf0e10cSrcweir ImplRegionBandSep* pNewSep; 414*cdf0e10cSrcweir ImplRegionBandSep* pPrevSep = 0; 415*cdf0e10cSrcweir ImplRegionBandSep* pSep = mpFirstSep; 416*cdf0e10cSrcweir while ( pSep ) 417*cdf0e10cSrcweir { 418*cdf0e10cSrcweir // new separation completely inside? nothing to do! 419*cdf0e10cSrcweir if ( (nXLeft >= pSep->mnXLeft) && (nXRight <= pSep->mnXRight) ) 420*cdf0e10cSrcweir return; 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir // new separation completly left? -> new separation! 423*cdf0e10cSrcweir if ( nXRight < pSep->mnXLeft ) 424*cdf0e10cSrcweir { 425*cdf0e10cSrcweir pNewSep = new ImplRegionBandSep; 426*cdf0e10cSrcweir pNewSep->mnXLeft = nXLeft; 427*cdf0e10cSrcweir pNewSep->mnXRight = nXRight; 428*cdf0e10cSrcweir pNewSep->mbRemoved = sal_False; 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir pNewSep->mpNextSep = pSep; 431*cdf0e10cSrcweir if ( pSep == mpFirstSep ) 432*cdf0e10cSrcweir mpFirstSep = pNewSep; 433*cdf0e10cSrcweir else 434*cdf0e10cSrcweir pPrevSep->mpNextSep = pNewSep; 435*cdf0e10cSrcweir break; 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir // new separation overlaping from left? -> extend boundary 439*cdf0e10cSrcweir if ( (nXRight >= pSep->mnXLeft) && (nXLeft <= pSep->mnXLeft) ) 440*cdf0e10cSrcweir pSep->mnXLeft = nXLeft; 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir // new separation overlaping from right? -> extend boundary 443*cdf0e10cSrcweir if ( (nXLeft <= pSep->mnXRight) && (nXRight > pSep->mnXRight) ) 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir pSep->mnXRight = nXRight; 446*cdf0e10cSrcweir break; 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir // not inserted, but last element? -> add to the end of the list 450*cdf0e10cSrcweir if ( !pSep->mpNextSep && (nXLeft > pSep->mnXRight) ) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir pNewSep = new ImplRegionBandSep; 453*cdf0e10cSrcweir pNewSep->mnXLeft = nXLeft; 454*cdf0e10cSrcweir pNewSep->mnXRight = nXRight; 455*cdf0e10cSrcweir pNewSep->mbRemoved = sal_False; 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir pSep->mpNextSep = pNewSep; 458*cdf0e10cSrcweir pNewSep->mpNextSep = NULL; 459*cdf0e10cSrcweir break; 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir pPrevSep = pSep; 463*cdf0e10cSrcweir pSep = pSep->mpNextSep; 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir OptimizeBand(); 467*cdf0e10cSrcweir } 468*cdf0e10cSrcweir 469*cdf0e10cSrcweir // ----------------------------------------------------------------------- 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir void ImplRegionBand::Intersect( long nXLeft, long nXRight ) 472*cdf0e10cSrcweir { 473*cdf0e10cSrcweir DBG_ASSERT( nXLeft <= nXRight, "ImplRegionBand::Intersect(): nxLeft > nXRight" ); 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir // band has been touched 476*cdf0e10cSrcweir mbTouched = sal_True; 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir // band empty? -> nothing to do 479*cdf0e10cSrcweir if ( !mpFirstSep ) 480*cdf0e10cSrcweir return; 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir // process real intersection 483*cdf0e10cSrcweir ImplRegionBandSep* pSep = mpFirstSep; 484*cdf0e10cSrcweir while ( pSep ) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir // new separation completly outside? -> remove separation 487*cdf0e10cSrcweir if ( (nXRight < pSep->mnXLeft) || (nXLeft > pSep->mnXRight) ) 488*cdf0e10cSrcweir // will be removed from the optimizer 489*cdf0e10cSrcweir pSep->mbRemoved = sal_True; 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir // new separation overlaping from left? -> reduce right boundary 492*cdf0e10cSrcweir if ( (nXLeft <= pSep->mnXLeft) && 493*cdf0e10cSrcweir (nXRight <= pSep->mnXRight) && 494*cdf0e10cSrcweir (nXRight >= pSep->mnXLeft) ) 495*cdf0e10cSrcweir pSep->mnXRight = nXRight; 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir // new separation overlaping from right? -> reduce right boundary 498*cdf0e10cSrcweir if ( (nXLeft >= pSep->mnXLeft) && 499*cdf0e10cSrcweir (nXLeft <= pSep->mnXRight) && 500*cdf0e10cSrcweir (nXRight >= pSep->mnXRight) ) 501*cdf0e10cSrcweir pSep->mnXLeft = nXLeft; 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir // new separation within the actual one? -> reduce both boundaries 504*cdf0e10cSrcweir if ( (nXLeft >= pSep->mnXLeft) && (nXRight <= pSep->mnXRight) ) 505*cdf0e10cSrcweir { 506*cdf0e10cSrcweir pSep->mnXRight = nXRight; 507*cdf0e10cSrcweir pSep->mnXLeft = nXLeft; 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir pSep = pSep->mpNextSep; 511*cdf0e10cSrcweir } 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir OptimizeBand(); 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir // ----------------------------------------------------------------------- 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir void ImplRegionBand::Exclude( long nXLeft, long nXRight ) 519*cdf0e10cSrcweir { 520*cdf0e10cSrcweir DBG_ASSERT( nXLeft <= nXRight, "ImplRegionBand::Exclude(): nxLeft > nXRight" ); 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir // band has been touched 523*cdf0e10cSrcweir mbTouched = sal_True; 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir // band empty? -> nothing to do 526*cdf0e10cSrcweir if ( !mpFirstSep ) 527*cdf0e10cSrcweir return; 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir // process real exclusion 530*cdf0e10cSrcweir ImplRegionBandSep* pNewSep; 531*cdf0e10cSrcweir ImplRegionBandSep* pPrevSep = 0; 532*cdf0e10cSrcweir ImplRegionBandSep* pSep = mpFirstSep; 533*cdf0e10cSrcweir while ( pSep ) 534*cdf0e10cSrcweir { 535*cdf0e10cSrcweir sal_Bool bSepProcessed = sal_False; 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir // new separation completely overlapping? -> remove separation 538*cdf0e10cSrcweir if ( (nXLeft <= pSep->mnXLeft) && (nXRight >= pSep->mnXRight) ) 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir // will be removed from the optimizer 541*cdf0e10cSrcweir pSep->mbRemoved = sal_True; 542*cdf0e10cSrcweir bSepProcessed = sal_True; 543*cdf0e10cSrcweir } 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir // new separation overlaping from left? -> reduce boundary 546*cdf0e10cSrcweir if ( !bSepProcessed ) 547*cdf0e10cSrcweir { 548*cdf0e10cSrcweir if ( (nXRight >= pSep->mnXLeft) && (nXLeft <= pSep->mnXLeft) ) 549*cdf0e10cSrcweir { 550*cdf0e10cSrcweir pSep->mnXLeft = nXRight+1; 551*cdf0e10cSrcweir bSepProcessed = sal_True; 552*cdf0e10cSrcweir } 553*cdf0e10cSrcweir } 554*cdf0e10cSrcweir 555*cdf0e10cSrcweir // new separation overlaping from right? -> reduce boundary 556*cdf0e10cSrcweir if ( !bSepProcessed ) 557*cdf0e10cSrcweir { 558*cdf0e10cSrcweir if ( (nXLeft <= pSep->mnXRight) && (nXRight > pSep->mnXRight) ) 559*cdf0e10cSrcweir { 560*cdf0e10cSrcweir pSep->mnXRight = nXLeft-1; 561*cdf0e10cSrcweir bSepProcessed = sal_True; 562*cdf0e10cSrcweir } 563*cdf0e10cSrcweir } 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir // new separation within the actual one? -> reduce boundary 566*cdf0e10cSrcweir // and add new entry for reminder 567*cdf0e10cSrcweir if ( !bSepProcessed ) 568*cdf0e10cSrcweir { 569*cdf0e10cSrcweir if ( (nXLeft >= pSep->mnXLeft) && (nXRight <= pSep->mnXRight) ) 570*cdf0e10cSrcweir { 571*cdf0e10cSrcweir pNewSep = new ImplRegionBandSep; 572*cdf0e10cSrcweir pNewSep->mnXLeft = pSep->mnXLeft; 573*cdf0e10cSrcweir pNewSep->mnXRight = nXLeft-1; 574*cdf0e10cSrcweir pNewSep->mbRemoved = sal_False; 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir pSep->mnXLeft = nXRight+1; 577*cdf0e10cSrcweir 578*cdf0e10cSrcweir // connections from the new separation 579*cdf0e10cSrcweir pNewSep->mpNextSep = pSep; 580*cdf0e10cSrcweir 581*cdf0e10cSrcweir // connections to the new separation 582*cdf0e10cSrcweir if ( pSep == mpFirstSep ) 583*cdf0e10cSrcweir mpFirstSep = pNewSep; 584*cdf0e10cSrcweir else 585*cdf0e10cSrcweir pPrevSep->mpNextSep = pNewSep; 586*cdf0e10cSrcweir } 587*cdf0e10cSrcweir } 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir pPrevSep = pSep; 590*cdf0e10cSrcweir pSep = pSep->mpNextSep; 591*cdf0e10cSrcweir } 592*cdf0e10cSrcweir 593*cdf0e10cSrcweir OptimizeBand(); 594*cdf0e10cSrcweir } 595*cdf0e10cSrcweir 596*cdf0e10cSrcweir // ----------------------------------------------------------------------- 597*cdf0e10cSrcweir 598*cdf0e10cSrcweir void ImplRegionBand::XOr( long nXLeft, long nXRight ) 599*cdf0e10cSrcweir { 600*cdf0e10cSrcweir DBG_ASSERT( nXLeft <= nXRight, "ImplRegionBand::XOr(): nxLeft > nXRight" ); 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir // #i46602# Reworked rectangle Xor 603*cdf0e10cSrcweir // 604*cdf0e10cSrcweir // In general, we can distinguish 11 cases of intersection 605*cdf0e10cSrcweir // (details below). The old implementation explicitely handled 7 606*cdf0e10cSrcweir // cases (numbered in the order of appearance, use CVS to get your 607*cdf0e10cSrcweir // hands on the old version), therefore, I've sticked to that 608*cdf0e10cSrcweir // order, and added four more cases. The code below references 609*cdf0e10cSrcweir // those numbers via #1, #2, etc. 610*cdf0e10cSrcweir // 611*cdf0e10cSrcweir // Num Mnem newX:oldX newY:oldY Description Result Can quit? 612*cdf0e10cSrcweir // 613*cdf0e10cSrcweir // #1 Empty band - - The band is empty, thus, simply add new bandSep just add Yes 614*cdf0e10cSrcweir // 615*cdf0e10cSrcweir // #2 apart - - The rectangles are disjunct, add new one as is just add Yes 616*cdf0e10cSrcweir // 617*cdf0e10cSrcweir // #3 atop == == The rectangles are _exactly_ the same, remove existing just remove Yes 618*cdf0e10cSrcweir // 619*cdf0e10cSrcweir // #4 around < > The new rectangle extends the old to both sides intersect No 620*cdf0e10cSrcweir // 621*cdf0e10cSrcweir // #5 left < < The new rectangle is left of the old (but intersects) intersect Yes 622*cdf0e10cSrcweir // 623*cdf0e10cSrcweir // #5b left-atop < == The new is left of the old, and coincides on the right intersect Yes 624*cdf0e10cSrcweir // 625*cdf0e10cSrcweir // #6 right > > The new is right of the old (but intersects) intersect No 626*cdf0e10cSrcweir // 627*cdf0e10cSrcweir // #6b right-atop == > The new is right of the old, and coincides on the left intersect No 628*cdf0e10cSrcweir // 629*cdf0e10cSrcweir // #7 inside > < The new is fully inside the old intersect Yes 630*cdf0e10cSrcweir // 631*cdf0e10cSrcweir // #8 inside-right > == The new is fully inside the old, coincides on the right intersect Yes 632*cdf0e10cSrcweir // 633*cdf0e10cSrcweir // #9 inside-left == < The new is fully inside the old, coincides on the left intersect Yes 634*cdf0e10cSrcweir // 635*cdf0e10cSrcweir // 636*cdf0e10cSrcweir // Then, to correctly perform XOr, the segment that's switched off 637*cdf0e10cSrcweir // (i.e. the overlapping part of the old and the new segment) must 638*cdf0e10cSrcweir // be extended by one pixel value at each border: 639*cdf0e10cSrcweir // 1 1 640*cdf0e10cSrcweir // 0 4 0 4 641*cdf0e10cSrcweir // 111100000001111 642*cdf0e10cSrcweir // 643*cdf0e10cSrcweir // Clearly, the leading band sep now goes from 0 to 3, and the 644*cdf0e10cSrcweir // trailing band sep from 11 to 14. This mimicks the xor look of a 645*cdf0e10cSrcweir // bitmap operation. 646*cdf0e10cSrcweir // 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir // band empty? -> add element 649*cdf0e10cSrcweir if ( !mpFirstSep ) 650*cdf0e10cSrcweir { 651*cdf0e10cSrcweir mpFirstSep = new ImplRegionBandSep; 652*cdf0e10cSrcweir mpFirstSep->mnXLeft = nXLeft; 653*cdf0e10cSrcweir mpFirstSep->mnXRight = nXRight; 654*cdf0e10cSrcweir mpFirstSep->mbRemoved = sal_False; 655*cdf0e10cSrcweir mpFirstSep->mpNextSep = NULL; 656*cdf0e10cSrcweir return; 657*cdf0e10cSrcweir } 658*cdf0e10cSrcweir 659*cdf0e10cSrcweir // process real xor 660*cdf0e10cSrcweir ImplRegionBandSep* pNewSep; 661*cdf0e10cSrcweir ImplRegionBandSep* pPrevSep = 0; 662*cdf0e10cSrcweir ImplRegionBandSep* pSep = mpFirstSep; 663*cdf0e10cSrcweir 664*cdf0e10cSrcweir while ( pSep ) 665*cdf0e10cSrcweir { 666*cdf0e10cSrcweir long nOldLeft( pSep->mnXLeft ); 667*cdf0e10cSrcweir long nOldRight( pSep->mnXRight ); 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir // did the current segment actually touch the new rect? If 670*cdf0e10cSrcweir // not, skip all comparisons, go on, loop and try to find 671*cdf0e10cSrcweir // intersecting bandSep 672*cdf0e10cSrcweir if( nXLeft <= nOldRight ) 673*cdf0e10cSrcweir { 674*cdf0e10cSrcweir if( nXRight < nOldLeft ) 675*cdf0e10cSrcweir { 676*cdf0e10cSrcweir // #2 677*cdf0e10cSrcweir 678*cdf0e10cSrcweir // add _before_ current bandSep 679*cdf0e10cSrcweir pNewSep = new ImplRegionBandSep; 680*cdf0e10cSrcweir pNewSep->mnXLeft = nXLeft; 681*cdf0e10cSrcweir pNewSep->mnXRight = nXRight; 682*cdf0e10cSrcweir pNewSep->mpNextSep = pSep; 683*cdf0e10cSrcweir pNewSep->mbRemoved = sal_False; 684*cdf0e10cSrcweir 685*cdf0e10cSrcweir // connections from the new separation 686*cdf0e10cSrcweir pNewSep->mpNextSep = pSep; 687*cdf0e10cSrcweir 688*cdf0e10cSrcweir // connections to the new separation 689*cdf0e10cSrcweir if ( pSep == mpFirstSep ) 690*cdf0e10cSrcweir mpFirstSep = pNewSep; 691*cdf0e10cSrcweir else 692*cdf0e10cSrcweir pPrevSep->mpNextSep = pNewSep; 693*cdf0e10cSrcweir pPrevSep = NULL; // do not run accidentally into the "right" case when breaking the loop 694*cdf0e10cSrcweir break; 695*cdf0e10cSrcweir } 696*cdf0e10cSrcweir else if( nXLeft == nOldLeft && nXRight == nOldRight ) 697*cdf0e10cSrcweir { 698*cdf0e10cSrcweir // #3 699*cdf0e10cSrcweir pSep->mbRemoved = sal_True; 700*cdf0e10cSrcweir pPrevSep = NULL; // do not run accidentally into the "right" case when breaking the loop 701*cdf0e10cSrcweir break; 702*cdf0e10cSrcweir } 703*cdf0e10cSrcweir else if( nXLeft != nOldLeft && nXRight == nOldRight ) 704*cdf0e10cSrcweir { 705*cdf0e10cSrcweir // # 5b, 8 706*cdf0e10cSrcweir if( nXLeft < nOldLeft ) 707*cdf0e10cSrcweir { 708*cdf0e10cSrcweir nXRight = nOldLeft; // 5b 709*cdf0e10cSrcweir } 710*cdf0e10cSrcweir else 711*cdf0e10cSrcweir { 712*cdf0e10cSrcweir nXRight = nXLeft; // 8 713*cdf0e10cSrcweir nXLeft = nOldLeft; 714*cdf0e10cSrcweir } 715*cdf0e10cSrcweir 716*cdf0e10cSrcweir pSep->mnXLeft = nXLeft; 717*cdf0e10cSrcweir pSep->mnXRight = nXRight-1; 718*cdf0e10cSrcweir 719*cdf0e10cSrcweir pPrevSep = NULL; // do not run accidentally into the "right" case when breaking the loop 720*cdf0e10cSrcweir break; 721*cdf0e10cSrcweir } 722*cdf0e10cSrcweir else if( nXLeft == nOldLeft && nXRight != nOldRight ) 723*cdf0e10cSrcweir { 724*cdf0e10cSrcweir // # 6b, 9 725*cdf0e10cSrcweir 726*cdf0e10cSrcweir if( nXRight > nOldRight ) 727*cdf0e10cSrcweir { 728*cdf0e10cSrcweir nXLeft = nOldRight+1; // 6b 729*cdf0e10cSrcweir 730*cdf0e10cSrcweir // cannot break here, simply mark segment as removed, 731*cdf0e10cSrcweir // and go on with adapted nXLeft/nXRight 732*cdf0e10cSrcweir pSep->mbRemoved = sal_True; 733*cdf0e10cSrcweir } 734*cdf0e10cSrcweir else 735*cdf0e10cSrcweir { 736*cdf0e10cSrcweir pSep->mnXLeft = nXRight+1; // 9 737*cdf0e10cSrcweir 738*cdf0e10cSrcweir pPrevSep = NULL; // do not run accidentally into the "right" case when breaking the loop 739*cdf0e10cSrcweir break; 740*cdf0e10cSrcweir } 741*cdf0e10cSrcweir } 742*cdf0e10cSrcweir else // if( nXLeft != nOldLeft && nXRight != nOldRight ) follows automatically 743*cdf0e10cSrcweir { 744*cdf0e10cSrcweir // #4,5,6,7 745*cdf0e10cSrcweir DBG_ASSERT( nXLeft != nOldLeft && nXRight != nOldRight, 746*cdf0e10cSrcweir "ImplRegionBand::XOr(): Case 4,5,6,7 expected all coordinates to be not equal!" ); 747*cdf0e10cSrcweir 748*cdf0e10cSrcweir // The plain-jane check would look like this: 749*cdf0e10cSrcweir // 750*cdf0e10cSrcweir // if( nXLeft < nOldLeft ) 751*cdf0e10cSrcweir // { 752*cdf0e10cSrcweir // // #4,5 753*cdf0e10cSrcweir // if( nXRight > nOldRight ) 754*cdf0e10cSrcweir // { 755*cdf0e10cSrcweir // // #4 756*cdf0e10cSrcweir // } 757*cdf0e10cSrcweir // else 758*cdf0e10cSrcweir // { 759*cdf0e10cSrcweir // // #5 done! 760*cdf0e10cSrcweir // } 761*cdf0e10cSrcweir // } 762*cdf0e10cSrcweir // else 763*cdf0e10cSrcweir // { 764*cdf0e10cSrcweir // // #6,7 765*cdf0e10cSrcweir // if( nXRight > nOldRight ) 766*cdf0e10cSrcweir // { 767*cdf0e10cSrcweir // // #6 768*cdf0e10cSrcweir // } 769*cdf0e10cSrcweir // else 770*cdf0e10cSrcweir // { 771*cdf0e10cSrcweir // // #7 done! 772*cdf0e10cSrcweir // } 773*cdf0e10cSrcweir // } 774*cdf0e10cSrcweir // 775*cdf0e10cSrcweir // but since we generally don't have to care whether 776*cdf0e10cSrcweir // it's 4 or 6 (only that we must not stop processing 777*cdf0e10cSrcweir // here), condensed that in such a way that only the 778*cdf0e10cSrcweir // coordinates get shuffled into correct ordering. 779*cdf0e10cSrcweir 780*cdf0e10cSrcweir if( nXLeft < nOldLeft ) 781*cdf0e10cSrcweir ::std::swap( nOldLeft, nXLeft ); 782*cdf0e10cSrcweir 783*cdf0e10cSrcweir bool bDone( false ); 784*cdf0e10cSrcweir 785*cdf0e10cSrcweir if( nXRight < nOldRight ) 786*cdf0e10cSrcweir { 787*cdf0e10cSrcweir ::std::swap( nOldRight, nXRight ); 788*cdf0e10cSrcweir bDone = true; 789*cdf0e10cSrcweir } 790*cdf0e10cSrcweir 791*cdf0e10cSrcweir // now, nOldLeft<nXLeft<=nOldRight<nXRight always 792*cdf0e10cSrcweir // holds. Note that we need the nXLeft<=nOldRight here, as 793*cdf0e10cSrcweir // the intersection part might be only one pixel (original 794*cdf0e10cSrcweir // nXLeft==nXRight) 795*cdf0e10cSrcweir DBG_ASSERT( nOldLeft<nXLeft && nXLeft<=nOldRight && nOldRight<nXRight, 796*cdf0e10cSrcweir "ImplRegionBand::XOr(): Case 4,5,6,7 expected coordinates to be ordered now!" ); 797*cdf0e10cSrcweir 798*cdf0e10cSrcweir pSep->mnXLeft = nOldLeft; 799*cdf0e10cSrcweir pSep->mnXRight = nXLeft-1; 800*cdf0e10cSrcweir 801*cdf0e10cSrcweir nXLeft = nOldRight+1; 802*cdf0e10cSrcweir // nxRight is already setup correctly 803*cdf0e10cSrcweir 804*cdf0e10cSrcweir if( bDone ) 805*cdf0e10cSrcweir { 806*cdf0e10cSrcweir // add behind current bandSep 807*cdf0e10cSrcweir pNewSep = new ImplRegionBandSep; 808*cdf0e10cSrcweir 809*cdf0e10cSrcweir pNewSep->mnXLeft = nXLeft; 810*cdf0e10cSrcweir pNewSep->mnXRight = nXRight; 811*cdf0e10cSrcweir pNewSep->mpNextSep = pSep->mpNextSep; 812*cdf0e10cSrcweir pNewSep->mbRemoved = sal_False; 813*cdf0e10cSrcweir 814*cdf0e10cSrcweir // connections from the new separation 815*cdf0e10cSrcweir pSep->mpNextSep = pNewSep; 816*cdf0e10cSrcweir 817*cdf0e10cSrcweir pPrevSep = NULL; // do not run accidentally into the "right" case when breaking the loop 818*cdf0e10cSrcweir break; 819*cdf0e10cSrcweir } 820*cdf0e10cSrcweir } 821*cdf0e10cSrcweir } 822*cdf0e10cSrcweir 823*cdf0e10cSrcweir pPrevSep = pSep; 824*cdf0e10cSrcweir pSep = pSep->mpNextSep; 825*cdf0e10cSrcweir } 826*cdf0e10cSrcweir 827*cdf0e10cSrcweir // new separation completely right of existing bandSeps ? 828*cdf0e10cSrcweir if( pPrevSep && nXLeft >= pPrevSep->mnXRight ) 829*cdf0e10cSrcweir { 830*cdf0e10cSrcweir pNewSep = new ImplRegionBandSep; 831*cdf0e10cSrcweir pNewSep->mnXLeft = nXLeft; 832*cdf0e10cSrcweir pNewSep->mnXRight = nXRight; 833*cdf0e10cSrcweir pNewSep->mpNextSep = NULL; 834*cdf0e10cSrcweir pNewSep->mbRemoved = sal_False; 835*cdf0e10cSrcweir 836*cdf0e10cSrcweir // connections from the new separation 837*cdf0e10cSrcweir pPrevSep->mpNextSep = pNewSep; 838*cdf0e10cSrcweir } 839*cdf0e10cSrcweir 840*cdf0e10cSrcweir OptimizeBand(); 841*cdf0e10cSrcweir } 842*cdf0e10cSrcweir 843*cdf0e10cSrcweir // ----------------------------------------------------------------------- 844*cdf0e10cSrcweir 845*cdf0e10cSrcweir sal_Bool ImplRegionBand::IsInside( long nX ) 846*cdf0e10cSrcweir { 847*cdf0e10cSrcweir ImplRegionBandSep* pSep = mpFirstSep; 848*cdf0e10cSrcweir while ( pSep ) 849*cdf0e10cSrcweir { 850*cdf0e10cSrcweir if ( (pSep->mnXLeft <= nX) && (pSep->mnXRight >= nX) ) 851*cdf0e10cSrcweir return sal_True; 852*cdf0e10cSrcweir 853*cdf0e10cSrcweir pSep = pSep->mpNextSep; 854*cdf0e10cSrcweir } 855*cdf0e10cSrcweir 856*cdf0e10cSrcweir return sal_False; 857*cdf0e10cSrcweir } 858*cdf0e10cSrcweir 859*cdf0e10cSrcweir // ----------------------------------------------------------------------- 860*cdf0e10cSrcweir 861*cdf0e10cSrcweir sal_Bool ImplRegionBand::IsOver( long nLeft, long nRight ) 862*cdf0e10cSrcweir { 863*cdf0e10cSrcweir ImplRegionBandSep* pSep = mpFirstSep; 864*cdf0e10cSrcweir while ( pSep ) 865*cdf0e10cSrcweir { 866*cdf0e10cSrcweir if ( (pSep->mnXLeft < nRight) && (pSep->mnXRight > nLeft) ) 867*cdf0e10cSrcweir return sal_True; 868*cdf0e10cSrcweir 869*cdf0e10cSrcweir pSep = pSep->mpNextSep; 870*cdf0e10cSrcweir } 871*cdf0e10cSrcweir 872*cdf0e10cSrcweir return sal_False; 873*cdf0e10cSrcweir } 874*cdf0e10cSrcweir 875*cdf0e10cSrcweir // ----------------------------------------------------------------------- 876*cdf0e10cSrcweir 877*cdf0e10cSrcweir sal_Bool ImplRegionBand::IsInside( long nLeft, long nRight ) 878*cdf0e10cSrcweir { 879*cdf0e10cSrcweir ImplRegionBandSep* pSep = mpFirstSep; 880*cdf0e10cSrcweir while ( pSep ) 881*cdf0e10cSrcweir { 882*cdf0e10cSrcweir if ( (pSep->mnXLeft >= nLeft) && (nRight <= pSep->mnXRight) ) 883*cdf0e10cSrcweir return sal_True; 884*cdf0e10cSrcweir 885*cdf0e10cSrcweir pSep = pSep->mpNextSep; 886*cdf0e10cSrcweir } 887*cdf0e10cSrcweir 888*cdf0e10cSrcweir return sal_False; 889*cdf0e10cSrcweir } 890*cdf0e10cSrcweir 891*cdf0e10cSrcweir // ----------------------------------------------------------------------- 892*cdf0e10cSrcweir 893*cdf0e10cSrcweir long ImplRegionBand::GetXLeftBoundary() const 894*cdf0e10cSrcweir { 895*cdf0e10cSrcweir DBG_ASSERT( mpFirstSep != NULL, "ImplRegionBand::XLeftBoundary -> no separation in band!" ); 896*cdf0e10cSrcweir 897*cdf0e10cSrcweir return mpFirstSep->mnXLeft; 898*cdf0e10cSrcweir } 899*cdf0e10cSrcweir 900*cdf0e10cSrcweir // ----------------------------------------------------------------------- 901*cdf0e10cSrcweir 902*cdf0e10cSrcweir long ImplRegionBand::GetXRightBoundary() const 903*cdf0e10cSrcweir { 904*cdf0e10cSrcweir DBG_ASSERT( mpFirstSep != NULL, "ImplRegionBand::XRightBoundary -> no separation in band!" ); 905*cdf0e10cSrcweir 906*cdf0e10cSrcweir // search last separation 907*cdf0e10cSrcweir ImplRegionBandSep* pSep = mpFirstSep; 908*cdf0e10cSrcweir while ( pSep->mpNextSep ) 909*cdf0e10cSrcweir pSep = pSep->mpNextSep; 910*cdf0e10cSrcweir return pSep->mnXRight; 911*cdf0e10cSrcweir } 912*cdf0e10cSrcweir 913*cdf0e10cSrcweir // ----------------------------------------------------------------------- 914*cdf0e10cSrcweir 915*cdf0e10cSrcweir sal_Bool ImplRegionBand::operator==( const ImplRegionBand& rRegionBand ) const 916*cdf0e10cSrcweir { 917*cdf0e10cSrcweir ImplRegionBandSep* pOwnRectBandSep = mpFirstSep; 918*cdf0e10cSrcweir ImplRegionBandSep* pSecondRectBandSep = rRegionBand.mpFirstSep; 919*cdf0e10cSrcweir while ( pOwnRectBandSep && pSecondRectBandSep ) 920*cdf0e10cSrcweir { 921*cdf0e10cSrcweir // get boundaries of current rectangle 922*cdf0e10cSrcweir long nOwnXLeft = pOwnRectBandSep->mnXLeft; 923*cdf0e10cSrcweir long nSecondXLeft = pSecondRectBandSep->mnXLeft; 924*cdf0e10cSrcweir if ( nOwnXLeft != nSecondXLeft ) 925*cdf0e10cSrcweir return sal_False; 926*cdf0e10cSrcweir 927*cdf0e10cSrcweir long nOwnXRight = pOwnRectBandSep->mnXRight; 928*cdf0e10cSrcweir long nSecondXRight = pSecondRectBandSep->mnXRight; 929*cdf0e10cSrcweir if ( nOwnXRight != nSecondXRight ) 930*cdf0e10cSrcweir return sal_False; 931*cdf0e10cSrcweir 932*cdf0e10cSrcweir // get next separation from current band 933*cdf0e10cSrcweir pOwnRectBandSep = pOwnRectBandSep->mpNextSep; 934*cdf0e10cSrcweir 935*cdf0e10cSrcweir // get next separation from current band 936*cdf0e10cSrcweir pSecondRectBandSep = pSecondRectBandSep->mpNextSep; 937*cdf0e10cSrcweir } 938*cdf0e10cSrcweir 939*cdf0e10cSrcweir // differnt number of separations? 940*cdf0e10cSrcweir if ( pOwnRectBandSep || pSecondRectBandSep ) 941*cdf0e10cSrcweir return sal_False; 942*cdf0e10cSrcweir 943*cdf0e10cSrcweir return sal_True; 944*cdf0e10cSrcweir } 945*cdf0e10cSrcweir 946*cdf0e10cSrcweir // ----------------------------------------------------------------------- 947*cdf0e10cSrcweir 948*cdf0e10cSrcweir ImplRegionBand* ImplRegionBand::SplitBand (const sal_Int32 nY) 949*cdf0e10cSrcweir { 950*cdf0e10cSrcweir OSL_ASSERT(nY>mnYTop); 951*cdf0e10cSrcweir OSL_ASSERT(nY<=mnYBottom); 952*cdf0e10cSrcweir 953*cdf0e10cSrcweir // Create a copy of the given band (we tell the constructor to copy the points together 954*cdf0e10cSrcweir // with the seps.) 955*cdf0e10cSrcweir ImplRegionBand* pLowerBand = new ImplRegionBand(*this, false); 956*cdf0e10cSrcweir 957*cdf0e10cSrcweir // Adapt vertical coordinates. 958*cdf0e10cSrcweir mnYBottom = nY-1; 959*cdf0e10cSrcweir pLowerBand->mnYTop = nY; 960*cdf0e10cSrcweir 961*cdf0e10cSrcweir // Insert new band into list of bands. 962*cdf0e10cSrcweir pLowerBand->mpNextBand = mpNextBand; 963*cdf0e10cSrcweir mpNextBand = pLowerBand; 964*cdf0e10cSrcweir pLowerBand->mpPrevBand = this; 965*cdf0e10cSrcweir if (pLowerBand->mpNextBand != NULL) 966*cdf0e10cSrcweir pLowerBand->mpNextBand->mpPrevBand = pLowerBand; 967*cdf0e10cSrcweir 968*cdf0e10cSrcweir return pLowerBand; 969*cdf0e10cSrcweir } 970