[Libreoffice-commits] core.git: 2 commits - sc/source

Jan Holesovsky kendy at collabora.com
Fri Jul 24 01:53:22 PDT 2015


 sc/source/ui/view/gridwin4.cxx |    5 --
 sc/source/ui/view/output.cxx   |   87 +++++++++++++++++++++++++++++------------
 2 files changed, 62 insertions(+), 30 deletions(-)

New commits:
commit 7c927b64fa42ea1b0ddf97ce6b6aa400f2e30d5b
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Fri Jul 24 10:31:17 2015 +0200

    calc mapmode: Cleanup DrawBackground + fix one pixel size.
    
    Change-Id: I2ff1aa1d83a3228ee76eda7cd2e411cf084079f6

diff --git a/sc/source/ui/view/output.cxx b/sc/source/ui/view/output.cxx
index 6cc3d60..cef48f9 100644
--- a/sc/source/ui/view/output.cxx
+++ b/sc/source/ui/view/output.cxx
@@ -327,8 +327,21 @@ void ScOutputData::DrawGrid(vcl::RenderContext& rRenderContext, bool bGrid, bool
     // It is a big mess to distinguish when we are using pixels and when logic
     // units for drawing.  Ultimately we want to work only in the logic units,
     // but until that happens, we need to special-case:
-    // * metafile
-    // * drawing to the screen - everything is internally counted in pixels there
+    //
+    //   * metafile
+    //   * drawing to the screen - everything is internally counted in pixels there
+    //
+    // 'Internally' in the above means the pCellInfo[...].nWidth and
+    // pRowInfo[...]->nHeight:
+    //
+    //   * when bWorksInPixels is true: these are in pixels
+    //   * when bWorksInPixels is false: these are in the logic units
+    //
+    // This is where all the confusion comes from, ultimately we want them
+    // always in the logic units (100th of milimiters), but we need to get
+    // there gradually (get rid of setting MAP_PIXEL first), otherwise we'd
+    // break all the drawing by one change.
+    // So until that happens, we need to special case.
     bool bWorksInPixels = bMetaFile;
 
     if ( eType == OUTTYPE_WINDOW )
@@ -956,20 +969,21 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext)
 {
     FindRotated();              //! from the outside?
 
-    bool bWorksInPixels = bMetaFile;
+    Size aOnePixel = rRenderContext.PixelToLogic(Size(1,1));
+    long nOneXLogic = aOnePixel.Width();
+    long nOneYLogic = aOnePixel.Height();
 
-    if ( eType == OUTTYPE_WINDOW )
-    {
+    // See more about bWorksInPixels in ScOutputData::DrawGrid
+    bool bWorksInPixels = false;
+    if (eType == OUTTYPE_WINDOW)
         bWorksInPixels = true;
-    }
 
     long nOneX = 1;
     long nOneY = 1;
     if (!bWorksInPixels)
     {
-        Size aOnePixel = rRenderContext.PixelToLogic(Size(1,1));
-        nOneX = aOnePixel.Width();
-        nOneY = aOnePixel.Height();
+        nOneX = nOneXLogic;
+        nOneY = nOneYLogic;
     }
 
     Rectangle aRect;
@@ -1014,6 +1028,8 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext)
                     nPosX += nMirrorW - nOneX;
 
                 aRect = Rectangle(nPosX, nPosY - nOneY, nPosX, nPosY - nOneY + nRowHeight);
+                if (bWorksInPixels)
+                    aRect = rRenderContext.PixelToLogic(aRect); // internal data in pixels, but we'll be drawing in logic units
 
                 const SvxBrushItem* pOldBackground = NULL;
                 const SvxBrushItem* pBackground;
@@ -1067,18 +1083,11 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext)
                     const ScDataBarInfo* pDataBarInfo = pInfo->pDataBar.get();
                     const ScIconSetInfo* pIconSetInfo = pInfo->pIconSet.get();
 
-                    Rectangle aRectC = aRect;
-                    long nPosXC = nPosX;
+                    long nPosXLogic = nPosX;
+                    if (bWorksInPixels)
+                        nPosXLogic = rRenderContext.PixelToLogic(Point(nPosX, 0)).X();
 
-                    if(bWorksInPixels)
-                    {
-                        aRectC = rRenderContext.PixelToLogic(aRect);
-                        nPosXC = rRenderContext.PixelToLogic(Point(nPosX, 0)).X();
-                    }
-                    drawCells(rRenderContext, pColor, pBackground, pOldColor, pOldBackground, aRectC, nPosXC, nLayoutSign, nOneX, nOneY, pDataBarInfo, pOldDataBarInfo, pIconSetInfo, pOldIconSetInfo);
-
-                    if(bWorksInPixels)
-                        aRect = rRenderContext.LogicToPixel(aRectC);
+                    drawCells(rRenderContext, pColor, pBackground, pOldColor, pOldBackground, aRect, nPosXLogic, nLayoutSign, nOneXLogic, nOneYLogic, pDataBarInfo, pOldDataBarInfo, pIconSetInfo, pOldIconSetInfo);
 
                     // extend for all merged cells
                     nMergedCells = 1;
@@ -1095,19 +1104,11 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext)
                     }
                 }
 
-                Rectangle aRectC = aRect;
-                long nPosXC = nPosX;
-
-                if(bWorksInPixels)
-                {
-                    aRectC = rRenderContext.PixelToLogic(aRect);
-                    nPosXC = rRenderContext.PixelToLogic(Point(nPosX, 0)).X();
-                }
-
-                drawCells(rRenderContext, NULL, NULL, pOldColor, pOldBackground, aRectC, nPosXC, nLayoutSign, nOneX, nOneY, NULL, pOldDataBarInfo, NULL, pOldIconSetInfo);
+                long nPosXLogic = nPosX;
+                if (bWorksInPixels)
+                    nPosXLogic = rRenderContext.PixelToLogic(Point(nPosX, 0)).X();
 
-                if(bWorksInPixels)
-                    aRect = rRenderContext.LogicToPixel(aRectC);
+                drawCells(rRenderContext, NULL, NULL, pOldColor, pOldBackground, aRect, nPosXLogic, nLayoutSign, nOneXLogic, nOneYLogic, NULL, pOldDataBarInfo, NULL, pOldIconSetInfo);
 
                 nArrY += nSkip;
             }
commit e24d47fb840c95ca247dda5c9d3acc106b8d6abc
Author: Krisztian Pinter <pin.terminator at gmail.com>
Date:   Sun Jun 14 20:38:26 2015 +0200

    calc mapmode: Refactor DrawBackground to use logic units
    
    Change-Id: Id47eac2578e75750eac04b481fe58df6d4f5e70d

diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 7282b90..4839bb9 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -720,13 +720,8 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableI
     if ( bGridFirst && ( bGrid || bPage ) )
         aOutputData.DrawGrid(*pContentDev, bGrid, bPage);
 
-    MapMode aPrevMapMode = pContentDev->GetMapMode();
-    pContentDev->SetMapMode(MAP_PIXEL);
-
     aOutputData.DrawBackground(*pContentDev);
 
-    pContentDev->SetMapMode(aPrevMapMode);
-
     if ( !bGridFirst && ( bGrid || bPage ) )
         aOutputData.DrawGrid(*pContentDev, bGrid, bPage);
 
diff --git a/sc/source/ui/view/output.cxx b/sc/source/ui/view/output.cxx
index ce60133..6cc3d60 100644
--- a/sc/source/ui/view/output.cxx
+++ b/sc/source/ui/view/output.cxx
@@ -789,14 +789,14 @@ namespace {
 
 static const double lclCornerRectTransparency = 40.0;
 
-void drawDataBars(vcl::RenderContext& rRenderContext, const ScDataBarInfo* pOldDataBarInfo, const Rectangle& rRect)
+void drawDataBars(vcl::RenderContext& rRenderContext, const ScDataBarInfo* pOldDataBarInfo, const Rectangle& rRect, long nOneX, long nOneY)
 {
     long nPosZero = 0;
     Rectangle aPaintRect = rRect;
-    aPaintRect.Top() += 2;
-    aPaintRect.Bottom() -= 2;
-    aPaintRect.Left() += 2;
-    aPaintRect.Right() -= 2;
+    aPaintRect.Top() += 2 * nOneY;
+    aPaintRect.Bottom() -= 2 * nOneY;
+    aPaintRect.Left() += 2 * nOneX;
+    aPaintRect.Right() -= 2 * nOneX;
     if(pOldDataBarInfo->mnZero)
     {
         // need to calculate null point in cell
@@ -865,21 +865,21 @@ BitmapEx& getIcon( ScIconSetType eType, sal_Int32 nIndex )
     return ScIconSetFormat::getBitmap( eType, nIndex );
 }
 
-void drawIconSets(vcl::RenderContext& rRenderContext, const ScIconSetInfo* pOldIconSetInfo, const Rectangle& rRect)
+void drawIconSets(vcl::RenderContext& rRenderContext, const ScIconSetInfo* pOldIconSetInfo, const Rectangle& rRect, long nOneX, long nOneY)
 {
     //long nSize = 16;
     ScIconSetType eType = pOldIconSetInfo->eIconSetType;
     sal_Int32 nIndex = pOldIconSetInfo->nIconIndex;
     BitmapEx& rIcon = getIcon( eType, nIndex );
-    long aOrigSize = std::max<long>(0,std::min(rRect.GetSize().getWidth() - 4, rRect.GetSize().getHeight() -4));
-    rRenderContext.DrawBitmapEx( Point( rRect.Left() +2, rRect.Top() + 2 ), Size(aOrigSize, aOrigSize), rIcon );
+    long aOrigSize = std::max<long>(0,std::min(rRect.GetSize().getWidth() - 4 * nOneX, rRect.GetSize().getHeight() -4 * nOneY));
+    rRenderContext.DrawBitmapEx( Point( rRect.Left() + 2 * nOneX, rRect.Top() + 2 * nOneY), Size(aOrigSize, aOrigSize), rIcon );
 }
 
 void drawCells(vcl::RenderContext& rRenderContext, const Color* pColor, const SvxBrushItem* pBackground, const Color*& pOldColor, const SvxBrushItem*& pOldBackground,
-        Rectangle& rRect, long nPosX, long nSignedOneX, const ScDataBarInfo* pDataBarInfo, const ScDataBarInfo*& pOldDataBarInfo,
+        Rectangle& rRect, long nPosX, long nLayoutSign, long nOneX, long nOneY, const ScDataBarInfo* pDataBarInfo, const ScDataBarInfo*& pOldDataBarInfo,
         const ScIconSetInfo* pIconSetInfo, const ScIconSetInfo*& pOldIconSetInfo)
 {
-
+    long nSignedOneX = nOneX * nLayoutSign;
     // need to paint if old color scale has been used and now
     // we have a different color or a style based background
     // we can here fall back to pointer comparison
@@ -892,9 +892,9 @@ void drawCells(vcl::RenderContext& rRenderContext, const Color* pColor, const Sv
             rRenderContext.DrawRect( rRect );
         }
         if( pOldDataBarInfo )
-            drawDataBars(rRenderContext, pOldDataBarInfo, rRect );
+            drawDataBars(rRenderContext, pOldDataBarInfo, rRect, nOneX, nOneY);
         if( pOldIconSetInfo )
-            drawIconSets(rRenderContext, pOldIconSetInfo, rRect );
+            drawIconSets(rRenderContext, pOldIconSetInfo, rRect, nOneX, nOneY);
 
         rRect.Left() = nPosX - nSignedOneX;
     }
@@ -912,9 +912,9 @@ void drawCells(vcl::RenderContext& rRenderContext, const Color* pColor, const Sv
             }
         }
         if( pOldDataBarInfo )
-            drawDataBars(rRenderContext, pOldDataBarInfo, rRect );
+            drawDataBars(rRenderContext, pOldDataBarInfo, rRect, nOneX, nOneY);
         if( pOldIconSetInfo )
-            drawIconSets(rRenderContext, pOldIconSetInfo, rRect );
+            drawIconSets(rRenderContext, pOldIconSetInfo, rRect, nOneX, nOneY);
 
         rRect.Left() = nPosX - nSignedOneX;
     }
@@ -956,16 +956,25 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext)
 {
     FindRotated();              //! from the outside?
 
-    Rectangle aRect;
-    Size aOnePixel = rRenderContext.PixelToLogic(Size(1,1));
-    long nOneX = aOnePixel.Width();
-    long nOneY = aOnePixel.Height();
+    bool bWorksInPixels = bMetaFile;
 
-    if (bMetaFile)
-        nOneX = nOneY = 0;
+    if ( eType == OUTTYPE_WINDOW )
+    {
+        bWorksInPixels = true;
+    }
+
+    long nOneX = 1;
+    long nOneY = 1;
+    if (!bWorksInPixels)
+    {
+        Size aOnePixel = rRenderContext.PixelToLogic(Size(1,1));
+        nOneX = aOnePixel.Width();
+        nOneY = aOnePixel.Height();
+    }
+
+    Rectangle aRect;
 
     long nLayoutSign = bLayoutRTL ? -1 : 1;
-    long nSignedOneX = nOneX * nLayoutSign;
 
     rRenderContext.SetLineColor();
 
@@ -1000,9 +1009,11 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext)
                 }
 
                 long nPosX = nScrX;
+
                 if ( bLayoutRTL )
                     nPosX += nMirrorW - nOneX;
-                aRect = Rectangle( nPosX, nPosY-nOneY, nPosX, nPosY+nRowHeight-nOneY );
+
+                aRect = Rectangle(nPosX, nPosY - nOneY, nPosX, nPosY - nOneY + nRowHeight);
 
                 const SvxBrushItem* pOldBackground = NULL;
                 const SvxBrushItem* pBackground;
@@ -1055,7 +1066,19 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext)
                     const Color* pColor = pInfo->pColorScale.get();
                     const ScDataBarInfo* pDataBarInfo = pInfo->pDataBar.get();
                     const ScIconSetInfo* pIconSetInfo = pInfo->pIconSet.get();
-                    drawCells(rRenderContext, pColor, pBackground, pOldColor, pOldBackground, aRect, nPosX, nSignedOneX, pDataBarInfo, pOldDataBarInfo, pIconSetInfo, pOldIconSetInfo);
+
+                    Rectangle aRectC = aRect;
+                    long nPosXC = nPosX;
+
+                    if(bWorksInPixels)
+                    {
+                        aRectC = rRenderContext.PixelToLogic(aRect);
+                        nPosXC = rRenderContext.PixelToLogic(Point(nPosX, 0)).X();
+                    }
+                    drawCells(rRenderContext, pColor, pBackground, pOldColor, pOldBackground, aRectC, nPosXC, nLayoutSign, nOneX, nOneY, pDataBarInfo, pOldDataBarInfo, pIconSetInfo, pOldIconSetInfo);
+
+                    if(bWorksInPixels)
+                        aRect = rRenderContext.LogicToPixel(aRectC);
 
                     // extend for all merged cells
                     nMergedCells = 1;
@@ -1071,7 +1094,20 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext)
                         nPosX += pRowInfo[0].pCellInfo[nX+nOldMerged+nMerged].nWidth * nLayoutSign;
                     }
                 }
-                drawCells(rRenderContext, NULL, NULL, pOldColor, pOldBackground, aRect, nPosX, nSignedOneX, NULL, pOldDataBarInfo, NULL, pOldIconSetInfo);
+
+                Rectangle aRectC = aRect;
+                long nPosXC = nPosX;
+
+                if(bWorksInPixels)
+                {
+                    aRectC = rRenderContext.PixelToLogic(aRect);
+                    nPosXC = rRenderContext.PixelToLogic(Point(nPosX, 0)).X();
+                }
+
+                drawCells(rRenderContext, NULL, NULL, pOldColor, pOldBackground, aRectC, nPosXC, nLayoutSign, nOneX, nOneY, NULL, pOldDataBarInfo, NULL, pOldIconSetInfo);
+
+                if(bWorksInPixels)
+                    aRect = rRenderContext.LogicToPixel(aRectC);
 
                 nArrY += nSkip;
             }


More information about the Libreoffice-commits mailing list