sw/qa/extras/tiledrendering/data/tdf43244_SpacesOnMargin.odt |binary
 sw/qa/extras/tiledrendering/tiledrendering.cxx               |   46 +++++++++++
 sw/source/core/text/portxt.cxx                               |   15 +++
 3 files changed, 59 insertions(+), 2 deletions(-)

New commits:
commit 8741fd0e0ae9e346de2e09887f0668b831c9b48b
Author:     Attila Szűcs <szucs.atti...@nisz.hu>
AuthorDate: Fri May 27 13:12:27 2022 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Tue Jun 7 19:28:48 2022 +0200

    tdf#43244 sw: show stripped line-end spaces on margin
    
    in View->Formatting Marks mode instead of hiding them
    This way it's possible to avoid interoperability issues
    better, when these (now visible) spaces are stripped only
    in Writer, but not in MSO, resulting different layout,
    i.e. bad paragraph alignment, because the users can
    notice the extra spaces and remove them in Writer.
    
    Extend SwHolePortion::Paint() to paint its text,
    what is probably just a bunch of spaces.
    
    It's an initial fix for tdf#43100, tdf#120715 and tdf#104683
    (cursor movement on the hidden spaces, end of paragraph sign
    before the hidden spaces, unable to select spaces after the margin).
    
    Follow-up to commit 93d7bdcb855362b88cdcfcb18ea401d89da973fb
    "fdo#33167, i#20878: Show spaces at the end of line".
    
    Co-authored-by: Tibor Nagy (NISZ)
    
    Change-Id: I48df3b41af37c77fd594bb6776ca30e845c51490
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135104
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/tiledrendering/data/tdf43244_SpacesOnMargin.odt 
b/sw/qa/extras/tiledrendering/data/tdf43244_SpacesOnMargin.odt
new file mode 100644
index 000000000000..76c293dc0bd5
Binary files /dev/null and 
b/sw/qa/extras/tiledrendering/data/tdf43244_SpacesOnMargin.odt differ
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 42f7f9e21889..7354782563c4 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -2809,6 +2809,52 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, 
testPilcrowRedlining)
     comphelper::dispatchCommand(".uno:ControlCodes", {});
 }
 
+CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testTdf43244_SpacesOnMargin)
+{
+    // Load a document where the top left tile contains
+    // paragraph and line break symbols with redlining.
+    SwXTextDocument* pXTextDocument = createDoc("tdf43244_SpacesOnMargin.odt");
+
+    // show non printing characters, including pilcrow and
+    // line break symbols with redlining
+    comphelper::dispatchCommand(".uno:ControlCodes", {});
+
+    // Render a larger area, and then get the colors from the right side of 
the page.
+    size_t nCanvasWidth = 1024;
+    size_t nCanvasHeight = 512;
+    size_t nTileSize = 64;
+    std::vector<unsigned char> aPixmap(nCanvasWidth * nCanvasHeight * 4, 0);
+    ScopedVclPtrInstance<VirtualDevice> pDevice(DeviceFormat::DEFAULT);
+    pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
+    pDevice->SetOutputSizePixelScaleOffsetAndBuffer(Size(nCanvasWidth, 
nCanvasHeight),
+            Fraction(1.0), Point(), aPixmap.data());
+    pXTextDocument->paintTile(*pDevice, nCanvasWidth, nCanvasHeight, 
/*nTilePosX=*/0,
+        /*nTilePosY=*/0, /*nTileWidth=*/15360, /*nTileHeight=*/7680);
+    pDevice->EnableMapMode(false);
+    Bitmap aBitmap = pDevice->GetBitmap(Point(730, 120), Size(nTileSize, 
nTileSize));
+    Bitmap::ScopedReadAccess pAccess(aBitmap);
+
+    //Test if we see any spaces on the right margin in a 47x48 rectangle
+    bool bSpaceFound = false;
+    for (int i = 1; i < 48 && !bSpaceFound; i++)
+    {
+        for (int j = 0; j < i; j++)
+        {
+            Color aColor2(pAccess->GetPixel(j, i));
+            Color aColor1(pAccess->GetPixel(i, j + 1));
+
+            if (aColor1.GetRed() < 255 || aColor2.GetRed() < 255)
+            {
+                bSpaceFound = true;
+                break;
+            }
+        }
+    }
+    CPPUNIT_ASSERT(bSpaceFound);
+
+    comphelper::dispatchCommand(".uno:ControlCodes", {});
+}
+
 CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testClipText)
 {
     // Load a document where the top left tile contains table text with
diff --git a/sw/source/core/text/portxt.cxx b/sw/source/core/text/portxt.cxx
index 140e29c168cc..a5ae0ea7e287 100644
--- a/sw/source/core/text/portxt.cxx
+++ b/sw/source/core/text/portxt.cxx
@@ -760,8 +760,10 @@ void SwHolePortion::Paint( const SwTextPaintInfo &rInf ) 
const
     if( !rInf.GetOut() )
         return;
 
+    bool bPDFExport = rInf.GetVsh()->GetViewOptions()->IsPDFExport();
+
     // #i16816# export stuff only needed for tagged pdf support
-    if (!SwTaggedPDFHelper::IsExportTaggedPDF( *rInf.GetOut()) )
+    if (bPDFExport && !SwTaggedPDFHelper::IsExportTaggedPDF( *rInf.GetOut()) )
         return;
 
     // #i68503# the hole must have no decoration for a consistent visual 
appearance
@@ -779,7 +781,16 @@ void SwHolePortion::Paint( const SwTextPaintInfo &rInf ) 
const
         pFontSave.reset(new SwFontSave( rInf, pHoleFont.get() ));
     }
 
-    rInf.DrawText(" ", *this, TextFrameIndex(0), TextFrameIndex(1));
+    if (bPDFExport)
+    {
+        rInf.DrawText(" ", *this, TextFrameIndex(0), TextFrameIndex(1));
+    }
+    else
+    {
+        // tdf#43244: Paint spaces even at end of line,
+        // but only if this paint is not called for pdf export, to keep that 
pdf export intact
+        rInf.DrawText(*this, rInf.GetLen());
+    }
 
     pFontSave.reset();
     pHoleFont.reset();

Reply via email to