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

Miklos Vajna vmiklos at collabora.co.uk
Wed Feb 1 12:05:13 UTC 2017


 vcl/source/gdi/pdfwriter_impl.cxx |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

New commits:
commit ee32c7d8083ae1449d6b379034be92995c142da9
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Feb 1 10:52:19 2017 +0100

    tdf#105461 PDF export: handle text fill color
    
    Text portion level background in Writer text was working already, as
    Writer paints its background explicitly, and then uses no text fill
    color in the metafile (that is turned into a PDF later).
    
    However, text fill color is used for Writer shape text and also in
    Impress. The rectangle is not just the text itself, but also the ascent
    / descent region, this matches the desktop rendering result.
    
    Change-Id: I644007ade43a8b9e663890643b826ae12c427ea5
    Reviewed-on: https://gerrit.libreoffice.org/33781
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 11c0de1..267ee9e 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -8748,6 +8748,29 @@ void PDFWriterImpl::drawLayout( SalLayout& rLayout, const OUString& rText, bool
         }
     }
 
+    if (m_aCurrentPDFState.m_aFont.GetFillColor() != Color(COL_TRANSPARENT))
+    {
+        // PDF doesn't have a text fill color, so draw a rectangle before
+        // drawing the actual text.
+        push(PushFlags::FILLCOLOR | PushFlags::LINECOLOR);
+        setFillColor(m_aCurrentPDFState.m_aFont.GetFillColor());
+        // Avoid border around the rectangle for Writer shape text.
+        setLineColor(Color(COL_TRANSPARENT));
+
+        // The rectangle is the bounding box of the text, but also includes
+        // ascent / descent to match the on-screen rendering.
+        Rectangle aRectangle;
+        // This is the top left of the text without ascent / descent.
+        aRectangle.SetPos(m_pReferenceDevice->PixelToLogic(rLayout.GetDrawPosition()));
+        aRectangle.setY(aRectangle.getY() - aRefDevFontMetric.GetAscent());
+        aRectangle.SetSize(m_pReferenceDevice->PixelToLogic(Size(rLayout.GetTextWidth(), 0)));
+        // This includes ascent / descent.
+        aRectangle.setHeight(aRefDevFontMetric.GetLineHeight());
+        drawRectangle(aRectangle);
+
+        pop();
+    }
+
     Point aAlignOffset;
     if ( eAlign == ALIGN_BOTTOM )
         aAlignOffset.Y() -= aRefDevFontMetric.GetDescent();


More information about the Libreoffice-commits mailing list