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

Jan Holesovsky kendy at collabora.com
Tue Jun 9 07:04:41 PDT 2015


 sc/source/ui/inc/gridmerg.hxx  |    4 +--
 sc/source/ui/inc/output.hxx    |    2 -
 sc/source/ui/view/gridmerg.cxx |   20 +++++++++++++++--
 sc/source/ui/view/gridwin4.cxx |   13 +++++++----
 sc/source/ui/view/hdrcont.cxx  |    4 +--
 sc/source/ui/view/output.cxx   |   48 +++++++++++++++++++++++------------------
 sc/source/ui/view/printfun.cxx |    4 +--
 7 files changed, 62 insertions(+), 33 deletions(-)

New commits:
commit f76b2b3b1184383695a35fa104470fa3027e477b
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue Jun 9 15:46:31 2015 +0200

    calc mapmode: Convert ScOutputData::DrawGrid to draw in logic units.
    
    Change-Id: Ie641c31e9023accf9d6bc510f8ca0b25ced3031b

diff --git a/sc/source/ui/inc/gridmerg.hxx b/sc/source/ui/inc/gridmerg.hxx
index 94e8994..89be9ff 100644
--- a/sc/source/ui/inc/gridmerg.hxx
+++ b/sc/source/ui/inc/gridmerg.hxx
@@ -42,8 +42,8 @@ public:
                 ScGridMerger( OutputDevice* pOutDev, long nOnePixelX, long nOnePixelY );
                 ~ScGridMerger();
 
-    void        AddHorLine( long nX1, long nX2, long nY );
-    void        AddVerLine( long nX, long nY1, long nY2 );
+    void        AddHorLine(bool bWorksInPixels, long nX1, long nX2, long nY);
+    void        AddVerLine(bool bWorksInPixels, long nX, long nY1, long nY2);
     void        Flush();
 };
 
diff --git a/sc/source/ui/inc/output.hxx b/sc/source/ui/inc/output.hxx
index 8873af7..a7b96f7 100644
--- a/sc/source/ui/inc/output.hxx
+++ b/sc/source/ui/inc/output.hxx
@@ -297,7 +297,7 @@ public:
 
     void    SetSnapPixel( bool bSet = true );
 
-    void    DrawGrid( bool bGrid, bool bPage );
+    void    DrawGrid(vcl::RenderContext& rRenderContext, bool bGrid, bool bPage);
     void    DrawStrings( bool bPixelToLogic = false );
 
     /// Draw all strings, or provide Rectangle where the text (defined by rAddress) would be drawn.
diff --git a/sc/source/ui/view/gridmerg.cxx b/sc/source/ui/view/gridmerg.cxx
index d2d434f..6ccc1817 100644
--- a/sc/source/ui/view/gridmerg.cxx
+++ b/sc/source/ui/view/gridmerg.cxx
@@ -86,8 +86,16 @@ void ScGridMerger::AddLine( long nStart, long nEnd, long nPos )
     }
 }
 
-void ScGridMerger::AddHorLine( long nX1, long nX2, long nY )
+void ScGridMerger::AddHorLine(bool bWorksInPixels, long nX1, long nX2, long nY)
 {
+    if (bWorksInPixels)
+    {
+        Point aPoint(pDev->PixelToLogic(Point(nX1, nY)));
+        nX1 = aPoint.X();
+        nY = aPoint.Y();
+        nX2 = pDev->PixelToLogic(Point(nX2, 0)).X();
+    }
+
     if ( bOptimize )
     {
         if ( bVertical )
@@ -101,8 +109,16 @@ void ScGridMerger::AddHorLine( long nX1, long nX2, long nY )
         pDev->DrawLine( Point( nX1, nY ), Point( nX2, nY ) );
 }
 
-void ScGridMerger::AddVerLine( long nX, long nY1, long nY2 )
+void ScGridMerger::AddVerLine(bool bWorksInPixels, long nX, long nY1, long nY2)
 {
+    if (bWorksInPixels)
+    {
+        Point aPoint(pDev->PixelToLogic(Point(nX, nY1)));
+        nX = aPoint.X();
+        nY1 = aPoint.Y();
+        nY2 = pDev->PixelToLogic(Point(0, nY2)).Y();
+    }
+
     if ( bOptimize )
     {
         if ( !bVertical )
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index de54116..b9894c8 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -720,15 +720,20 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableI
 
     aOutputData.DrawDocumentBackground();
 
-    pContentDev->SetMapMode(MAP_PIXEL);
-
     if ( bGridFirst && ( bGrid || bPage ) )
-        aOutputData.DrawGrid( bGrid, bPage );
+        aOutputData.DrawGrid(*pContentDev, bGrid, bPage);
+
+    MapMode aPrevMapMode = pContentDev->GetMapMode();
+    pContentDev->SetMapMode(MAP_PIXEL);
 
     aOutputData.DrawBackground();
 
+    pContentDev->SetMapMode(aPrevMapMode);
+
     if ( !bGridFirst && ( bGrid || bPage ) )
-        aOutputData.DrawGrid( bGrid, bPage );
+        aOutputData.DrawGrid(*pContentDev, bGrid, bPage);
+
+    pContentDev->SetMapMode(MAP_PIXEL);
 
     if ( bPageMode )
     {
diff --git a/sc/source/ui/view/hdrcont.cxx b/sc/source/ui/view/hdrcont.cxx
index 1b094cb..18f3ce1 100644
--- a/sc/source/ui/view/hdrcont.cxx
+++ b/sc/source/ui/view/hdrcont.cxx
@@ -498,9 +498,9 @@ void ScHeaderControl::Paint( vcl::RenderContext& /*rRenderContext*/, const Recta
                             if ( nPass == ( bNextToMark ? SC_HDRPAINT_SEL_BOTTOM : SC_HDRPAINT_BOTTOM ) )
                             {
                                 if (bVertical)
-                                    aGrid.AddHorLine( aScrPos.X(), aEndPos.X(), aEndPos.Y() );
+                                    aGrid.AddHorLine(/* here we work in pixels */ true, aScrPos.X(), aEndPos.X(), aEndPos.Y());
                                 else
-                                    aGrid.AddVerLine( aEndPos.X(), aScrPos.Y(), aEndPos.Y() );
+                                    aGrid.AddVerLine(/* here we work in pixels */ true, aEndPos.X(), aScrPos.Y(), aEndPos.Y());
 
                                 //  thick bottom for hidden rows
                                 //  (drawn directly, without aGrid)
diff --git a/sc/source/ui/view/output.cxx b/sc/source/ui/view/output.cxx
index 4b33d2e..a2cc326 100644
--- a/sc/source/ui/view/output.cxx
+++ b/sc/source/ui/view/output.cxx
@@ -307,7 +307,7 @@ void ScOutputData::SetSyntaxMode( bool bNewMode )
         }
 }
 
-void ScOutputData::DrawGrid( bool bGrid, bool bPage )
+void ScOutputData::DrawGrid(vcl::RenderContext& rRenderContext, bool bGrid, bool bPage)
 {
     SCCOL nX;
     SCROW nY;
@@ -324,20 +324,16 @@ void ScOutputData::DrawGrid( bool bGrid, bool bPage )
     if (bPagebreakMode)
         bPage = false;          // no "normal" breaks over the whole width/height
 
-    //! um den einen Pixel sieht das Metafile (oder die Druck-Ausgabe) anders aus
-    //! als die Bildschirmdarstellung, aber wenigstens passen Druck und Metafile zusammen
-
-    Size aOnePixel = mpDev->PixelToLogic(Size(1,1));
-    long nOneX = aOnePixel.Width();
-    long nOneY = aOnePixel.Height();
-    if (bMetaFile)
-        nOneX = nOneY = 1;
-
-    long nLayoutSign = bLayoutRTL ? -1 : 1;
-    long nSignedOneX = nOneX * nLayoutSign;
+    // 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
+    bool bWorksInPixels = bMetaFile;
 
     if ( eType == OUTTYPE_WINDOW )
     {
+        bWorksInPixels = true;
         const svtools::ColorConfig& rColorCfg = SC_MOD()->GetColorConfig();
         aPageColor.SetColor( rColorCfg.GetColorValue(svtools::CALCPAGEBREAKAUTOMATIC).nColor );
         aManualColor.SetColor( rColorCfg.GetColorValue(svtools::CALCPAGEBREAKMANUAL).nColor );
@@ -348,8 +344,20 @@ void ScOutputData::DrawGrid( bool bGrid, bool bPage )
         aManualColor = aGridColor;
     }
 
-    mpDev->SetLineColor( aGridColor );
-    ScGridMerger aGrid( mpDev, nOneX, nOneY );
+    long nOneX = 1;
+    long nOneY = 1;
+    if (!bWorksInPixels)
+    {
+        Size aOnePixel = rRenderContext.PixelToLogic(Size(1,1));
+        nOneX = aOnePixel.Width();
+        nOneY = aOnePixel.Height();
+    }
+
+    long nLayoutSign = bLayoutRTL ? -1 : 1;
+    long nSignedOneX = nOneX * nLayoutSign;
+
+    rRenderContext.SetLineColor(aGridColor);
+    ScGridMerger aGrid(&rRenderContext, nOneX, nOneY);
 
     // vertical lines
 
@@ -383,7 +391,7 @@ void ScOutputData::DrawGrid( bool bGrid, bool bPage )
                 if (nBreak != nBreakOld)
                 {
                     aGrid.Flush();
-                    mpDev->SetLineColor( (nBreak & BREAK_MANUAL) ? aManualColor :
+                    rRenderContext.SetLineColor( (nBreak & BREAK_MANUAL) ? aManualColor :
                                         nBreak ? aPageColor : aGridColor );
                     nBreakOld = nBreak;
                 }
@@ -441,14 +449,14 @@ void ScOutputData::DrawGrid( bool bGrid, bool bPage )
 
                         if (pThisRowInfo->bChanged && !bHOver)
                         {
-                            aGrid.AddVerLine( nPosX-nSignedOneX, nPosY, nNextY-nOneY );
+                            aGrid.AddVerLine(bWorksInPixels, nPosX-nSignedOneX, nPosY, nNextY-nOneY);
                         }
                         nPosY = nNextY;
                     }
                 }
                 else
                 {
-                    aGrid.AddVerLine( nPosX-nSignedOneX, nScrY, nScrY+nScrH-nOneY );
+                    aGrid.AddVerLine(bWorksInPixels, nPosX-nSignedOneX, nScrY, nScrY+nScrH-nOneY);
                 }
             }
         }
@@ -489,7 +497,7 @@ void ScOutputData::DrawGrid( bool bGrid, bool bPage )
                 if (nBreakOld != nBreak)
                 {
                     aGrid.Flush();
-                    mpDev->SetLineColor( (nBreak & BREAK_MANUAL) ? aManualColor :
+                    rRenderContext.SetLineColor( (nBreak & BREAK_MANUAL) ? aManualColor :
                                         (nBreak) ? aPageColor : aGridColor );
                     nBreakOld = nBreak;
                 }
@@ -535,7 +543,7 @@ void ScOutputData::DrawGrid( bool bGrid, bool bPage )
                             }
                             if (!bVOver)
                             {
-                                aGrid.AddHorLine( nPosX, nNextX-nSignedOneX, nPosY-nOneY );
+                                aGrid.AddHorLine(bWorksInPixels, nPosX, nNextX-nSignedOneX, nPosY-nOneY);
                             }
                         }
                         nPosX = nNextX;
@@ -543,7 +551,7 @@ void ScOutputData::DrawGrid( bool bGrid, bool bPage )
                 }
                 else
                 {
-                    aGrid.AddHorLine( nScrX, nScrX+nScrW-nOneX, nPosY-nOneY );
+                    aGrid.AddHorLine(bWorksInPixels, nScrX, nScrX+nScrW-nOneX, nPosY-nOneY);
                 }
             }
         }
diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx
index 1e9f4d0..716cf99 100644
--- a/sc/source/ui/view/printfun.cxx
+++ b/sc/source/ui/view/printfun.cxx
@@ -563,7 +563,7 @@ void ScPrintFunc::DrawToDev( ScDocument* pDoc, OutputDevice* pDev, double /* nPr
         if (!bMetaFile && pViewData)
             pDev->SetMapMode(aMode);
 
-        aOutputData.DrawGrid( true, false );    // no page breaks
+        aOutputData.DrawGrid(*pDev, true, false);    // no page breaks
 
         pDev->SetLineColor( COL_BLACK );
 
@@ -1619,7 +1619,7 @@ void ScPrintFunc::PrintArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
     }
 
     if (aTableParam.bGrid)
-        aOutputData.DrawGrid( true, false );    // no page breaks
+        aOutputData.DrawGrid(*pDev, true, false);    // no page breaks
 
     aOutputData.AddPDFNotes();      // has no effect if not rendering PDF with notes enabled
 


More information about the Libreoffice-commits mailing list