main/sw/source/core/layout/paintfrm.cxx
/** local help method for SwRootFrm::Paint(..) - Adjust given rectangle to pixel size

    By OD at 27.09.2002 for #103636#
    In order to avoid paint errors caused by multiple alignments - e.g. method
    ::SwAlignRect(..) - and other changes to the rectangle to be painted,
    this method is called for the rectangle to be painted in order to
    adjust it to the pixel it is overlapping.

    @author OD
*/
local help method for SwRootFrm::Paint(..) - Adjust given rectangle to pixel size
By OD at 27.09.2002 for #103636
In order to avoid paint errors caused by multiple alignments - e.g. method
::SwAlignRect(..) - and other changes to the rectangle to be painted,
this method is called for the rectangle to be painted in order to
adjust it to the pixel it is overlapping.
local help method for SwRootFrm :: Paint ( .. ) - Adjust given rectangle to pixel size By OD at 27 . 09 . 2002 for #103636 In order to avoid paint errors caused by multiple alignments - e . g . method :: SwAlignRect ( .. ) - and other changes to the rectangle to be painted this method is called for the rectangle to be painted in order to adjust it to the pixel it is overlapping .
void lcl_AdjustRectToPixelSize( SwRect& io_aSwRect, const OutputDevice &aOut )
{
    const Size aTwipToPxSize( aOut.PixelToLogic( Size( 1,1 )) );
    const Rectangle aPxCenterRect = aOut.PixelToLogic(
            aOut.LogicToPixel( io_aSwRect.SVRect() ) );
    const Rectangle aOrgPxRect = aOut.LogicToPixel( io_aSwRect.SVRect() );
    Rectangle aSizedRect = aPxCenterRect;
    aSizedRect.Left() -= (aTwipToPxSize.Width()/2 + 1);
    aSizedRect.Right() += (aTwipToPxSize.Width()/2 + 1);
    aSizedRect.Top() -= (aTwipToPxSize.Height()/2 + 1);
    aSizedRect.Bottom() += (aTwipToPxSize.Height()/2 + 1);
    while ( (aOut.LogicToPixel(aSizedRect)).Left() < aOrgPxRect.Left() )
    {
        ++aSizedRect.Left();
    }
    while ( (aOut.LogicToPixel(aSizedRect)).Right() > aOrgPxRect.Right() )
    {
        --aSizedRect.Right();
    }
    while ( (aOut.LogicToPixel(aSizedRect)).Top() < aOrgPxRect.Top() )
    {
        ++aSizedRect.Top();
    }
    while ( (aOut.LogicToPixel(aSizedRect)).Bottom() > aOrgPxRect.Bottom() )
    {
        --aSizedRect.Bottom();
    }
    io_aSwRect = SwRect( aSizedRect );
#ifdef DBG_UTIL
    Rectangle aTestOrgPxRect = aOut.LogicToPixel( io_aSwRect.SVRect() );
    Rectangle aTestNewPxRect = aOut.LogicToPixel( aSizedRect );
    ASSERT( aTestOrgPxRect == aTestNewPxRect,
            "Error in lcl_AlignRectToPixelSize(..): Adjusted rectangle has incorrect position or size");
#if OSL_DEBUG_LEVEL > 1
    Rectangle aTestNewRect( aSizedRect );
    --aSizedRect.Left();
    aTestNewPxRect = aOut.LogicToPixel( aSizedRect );
    ASSERT( aTestOrgPxRect.Left() >= (aTestNewPxRect.Left()+1),
            "Error in lcl_AlignRectToPixelSize(..): Left() not correct adjusted");
    ++aSizedRect.Left();
    ++aSizedRect.Right();
    aTestNewPxRect = aOut.LogicToPixel( aSizedRect );
    ASSERT( aTestOrgPxRect.Right() <= (aTestNewPxRect.Right()-1),
            "Error in lcl_AlignRectToPixelSize(..): Right() not correct adjusted");
    --aSizedRect.Right();
    --aSizedRect.Top();
    aTestNewPxRect = aOut.LogicToPixel( aSizedRect );
    ASSERT( aTestOrgPxRect.Top() >= (aTestNewPxRect.Top()+1),
            "Error in lcl_AlignRectToPixelSize(..): Top() not correct adjusted");
    ++aSizedRect.Top();
    ++aSizedRect.Bottom();
    aTestNewPxRect = aOut.LogicToPixel( aSizedRect );
    ASSERT( aTestOrgPxRect.Bottom() <= (aTestNewPxRect.Bottom()-1),
            "Error in lcl_AlignRectToPixelSize(..): Bottom() not correct adjusted");
    --aSizedRect.Bottom();
#endif
#endif
}
void lcl_AdjustRectToPixelSize ( SwRect & io_aSwRect , const OutputDevice & aOut ) { const Size aTwipToPxSize ( aOut . PixelToLogic ( Size ( 1 , 1 ) ) ) ; const Rectangle aPxCenterRect = aOut . PixelToLogic ( aOut . LogicToPixel ( io_aSwRect . SVRect ( ) ) ) ; const Rectangle aOrgPxRect = aOut . LogicToPixel ( io_aSwRect . SVRect ( ) ) ; Rectangle aSizedRect = aPxCenterRect ; aSizedRect . Left ( ) -= ( aTwipToPxSize . Width ( ) / 2 + 1 ) ; aSizedRect . Right ( ) += ( aTwipToPxSize . Width ( ) / 2 + 1 ) ; aSizedRect . Top ( ) -= ( aTwipToPxSize . Height ( ) / 2 + 1 ) ; aSizedRect . Bottom ( ) += ( aTwipToPxSize . Height ( ) / 2 + 1 ) ; while ( ( aOut . LogicToPixel ( aSizedRect ) ) . Left ( ) < aOrgPxRect . Left ( ) ) { ++ aSizedRect . Left ( ) ; } while ( ( aOut . LogicToPixel ( aSizedRect ) ) . Right ( ) > aOrgPxRect . Right ( ) ) { -- aSizedRect . Right ( ) ; } while ( ( aOut . LogicToPixel ( aSizedRect ) ) . Top ( ) < aOrgPxRect . Top ( ) ) { ++ aSizedRect . Top ( ) ; } while ( ( aOut . LogicToPixel ( aSizedRect ) ) . Bottom ( ) > aOrgPxRect . Bottom ( ) ) { -- aSizedRect . Bottom ( ) ; } io_aSwRect = SwRect ( aSizedRect ) ; #ifdef DBG_UTIL Rectangle aTestOrgPxRect = aOut . LogicToPixel ( io_aSwRect . SVRect ( ) ) ; Rectangle aTestNewPxRect = aOut . LogicToPixel ( aSizedRect ) ; ASSERT ( aTestOrgPxRect == aTestNewPxRect , " " ) ; #if OSL_DEBUG_LEVEL > 1 Rectangle aTestNewRect ( aSizedRect ) ; -- aSizedRect . Left ( ) ; aTestNewPxRect = aOut . LogicToPixel ( aSizedRect ) ; ASSERT ( aTestOrgPxRect . Left ( ) >= ( aTestNewPxRect . Left ( ) + 1 ) , " " ) ; ++ aSizedRect . Left ( ) ; ++ aSizedRect . Right ( ) ; aTestNewPxRect = aOut . LogicToPixel ( aSizedRect ) ; ASSERT ( aTestOrgPxRect . Right ( ) <= ( aTestNewPxRect . Right ( ) - 1 ) , " " ) ; -- aSizedRect . Right ( ) ; -- aSizedRect . Top ( ) ; aTestNewPxRect = aOut . LogicToPixel ( aSizedRect ) ; ASSERT ( aTestOrgPxRect . Top ( ) >= ( aTestNewPxRect . Top ( ) + 1 ) , " " ) ; ++ aSizedRect . Top ( ) ; ++ aSizedRect . Bottom ( ) ; aTestNewPxRect = aOut . LogicToPixel ( aSizedRect ) ; ASSERT ( aTestOrgPxRect . Bottom ( ) <= ( aTestNewPxRect . Bottom ( ) - 1 ) , " " ) ; -- aSizedRect . Bottom ( ) ; #endif #endif }
local help method for SwRootFrm::Paint(..) - Adjust given rectangle to pixel size
By OD at 27.09.2002 for #103636
In order to avoid paint errors caused by multiple alignments - e.g.
local help method for SwRootFrm :: Paint ( .. ) - Adjust given rectangle to pixel size By OD at 27 . 09 . 2002 for #103636 In order to avoid paint errors caused by multiple alignments - e . g .
/// local constant object of class <Size> to determine number of Twips /// representing a pixel. /// local object of class <Rectangle> in Twip coordinates /// calculated from given rectangle aligned to pixel centers. /// local constant object of class <Rectangle> representing given rectangle /// in pixel. /// calculate adjusted rectangle from pixel centered rectangle. /// Due to rounding differences <aPxCenterRect> doesn't exactly represents /// the Twip-centers. Thus, adjust borders by half of pixel width/height plus 1. /// Afterwards, adjust calculated Twip-positions of the all borders. /// adjust left() /// adjust right() /// adjust top() /// adjust bottom() /// check Left() /// check Right() /// check Top() /// check Bottom()