drawinglayer/source/tools/emfphelperdata.cxx |   95 ++++++++++++++-------------
 1 file changed, 52 insertions(+), 43 deletions(-)

New commits:
commit 52a2a0101f71b21876f17d5419132ffa27f6e35d
Author: Patrick Jaap <[email protected]>
Date:   Fri Oct 13 11:31:28 2017 +0200

    tdf#31814 Fix for EMF+ DrawString and DrawImage
    
    DrawString:
    The value 'fontAttribute' is optional and may be null,
    results in missing characters.
    
    DrawImage:
    The case of 'metafile' was missing and leads to
    low resolution rendering.
    
    Change-Id: I81566d884975fda832f4a5af6663c837f355c383
    Reviewed-on: https://gerrit.libreoffice.org/43367
    Tested-by: Jenkins <[email protected]>
    Reviewed-by: Bartosz Kosiorek <[email protected]>

diff --git a/drawinglayer/source/tools/emfphelperdata.cxx 
b/drawinglayer/source/tools/emfphelperdata.cxx
index 1dc3d611a046..c39083336046 100644
--- a/drawinglayer/source/tools/emfphelperdata.cxx
+++ b/drawinglayer/source/tools/emfphelperdata.cxx
@@ -32,6 +32,7 @@
 #include <drawinglayer/primitive2d/svggradientprimitive2d.hxx>
 #include <drawinglayer/primitive2d/textprimitive2d.hxx>
 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
+#include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
 #include <drawinglayer/attribute/fontattribute.hxx>
 #include <basegfx/matrix/b2dhommatrixtools.hxx>
 #include <basegfx/polygon/b2dpolygontools.hxx>
@@ -1107,25 +1108,35 @@ namespace emfplushelper
 
                             if (bValid)
                             {
-                                BitmapEx aBmp(image.graphic.GetBitmapEx());
-                                aBmp.Crop(aSource);
-                                Size aSize(aBmp.GetSizePixel());
-                                SAL_INFO("cppcanvas.emf", "EMF+ bitmap size: " 
<< aSize.Width() << "x" << aSize.Height());
-                                if (aSize.Width() > 0 && aSize.Height() > 0)
+                                // create correct transform matrix
+                                basegfx::B2DHomMatrix aTransformMatrix = 
basegfx::utils::createScaleTranslateB2DHomMatrix(
+                                    aDstSize.getX(),
+                                    aDstSize.getY(),
+                                    aDstPoint.getX(),
+                                    aDstPoint.getY());
+
+                                if (image.type == 1) // Bitmap
                                 {
-                                    // create correct transform matrix
-                                    basegfx::B2DHomMatrix aTransformMatrix = 
basegfx::utils::createScaleTranslateB2DHomMatrix(
-                                        aDstSize.getX(),
-                                        aDstSize.getY(),
-                                        aDstPoint.getX(),
-                                        aDstPoint.getY());
-
-                                    mrTargetHolders.Current().append(
-                                        new 
drawinglayer::primitive2d::BitmapPrimitive2D(aBmp,aTransformMatrix));
+                                    BitmapEx aBmp(image.graphic.GetBitmapEx());
+                                    aBmp.Crop(aSource);
+                                    Size aSize(aBmp.GetSizePixel());
+                                    SAL_INFO("cppcanvas.emf", "EMF+ bitmap 
size: " << aSize.Width() << "x" << aSize.Height());
+                                    if (aSize.Width() > 0 && aSize.Height() > 
0)
+                                    {
+                                        mrTargetHolders.Current().append(
+                                            new 
drawinglayer::primitive2d::BitmapPrimitive2D(aBmp,aTransformMatrix));
+                                    }
+                                    else
+                                    {
+                                        SAL_INFO("cppcanvas.emf", "EMF+ 
warning: empty bitmap");
+                                    }
                                 }
-                                else
+                                else if (image.type == 2) // Metafile
                                 {
-                                    SAL_INFO("cppcanvas.emf", "EMF+ warning: 
empty bitmap");
+                                    GDIMetaFile 
aGDI(image.graphic.GetGDIMetaFile());
+                                    aGDI.Clip(aSource);
+                                    mrTargetHolders.Current().append(
+                                            new 
drawinglayer::primitive2d::MetafilePrimitive2D(aTransformMatrix,aGDI));
                                 }
                             }
                             else
@@ -1158,11 +1169,11 @@ namespace emfplushelper
                             // parse the string
                             OUString text = read_uInt16s_ToOUString(rMS, 
stringLength);
                             SAL_INFO("cppcanvas.emf", "EMF+ DrawString string: 
" << text);
-                            // get the stringFormat from the Object table
+                            // get the stringFormat from the Object table ( 
this is OPTIONAL and may be nullptr )
                             EMFPStringFormat *stringFormat = static_cast< 
EMFPStringFormat* >(maEMFPObjects[formatId & 0xff].get());
                             // get the font from the flags
                             EMFPFont *font = static_cast< EMFPFont* >( 
maEMFPObjects[flags & 0xff].get() );
-                            if (!stringFormat || !font)
+                            if (!font)
                             {
                                 break;
                             }
@@ -1175,35 +1186,33 @@ namespace emfplushelper
 
                             const OUString emptyString;
                             drawinglayer::attribute::FontAttribute 
fontAttribute(
-                                font->family,                                  
  // font family
-                                emptyString,                                   
  // (no) font style
-                                font->Bold() ? 8u : 1u,                        
  // weight: 8 = bold
-                                font->family == "SYMBOL",                      
  // symbol
-                                stringFormat->DirectionVertical(),             
  // vertical
-                                font->Italic(),                                
  // italic
-                                false,                                         
  // monospaced
-                                false,                                         
  // outline = false, no such thing in MS-EMFPLUS
-                                stringFormat->DirectionRightToLeft(),          
  // right-to-left
-                                false);                                        
  // BiDiStrong
-
-                            LanguageTag aLanguageTag(static_cast< LanguageType 
>(stringFormat->language));
-                            css::lang::Locale locale = 
aLanguageTag.getLocale();
-
-                            basegfx::B2DHomMatrix transformMatrix = 
basegfx::utils::createScaleTranslateB2DHomMatrix(MapSize(font->emSize,font->emSize),Map(lx,ly+font->emSize));
-
-                            basegfx::BColor color;
-                            if (flags & 0x8000) // we use a color
+                                font->family,                                  
        // font family
+                                emptyString,                                   
        // (no) font style
+                                font->Bold() ? 8u : 1u,                        
        // weight: 8 = bold
+                                font->family == "SYMBOL",                      
        // symbol
+                                stringFormat && 
stringFormat->DirectionVertical(),     // vertical
+                                font->Italic(),                                
        // italic
+                                false,                                         
        // monospaced
+                                false,                                         
        // outline = false, no such thing in MS-EMFPLUS
+                                stringFormat && 
stringFormat->DirectionRightToLeft(),  // right-to-left
+                                false);                                        
        // BiDiStrong
+
+                            css::lang::Locale locale;
+                            if (stringFormat)
                             {
-                                color = Color(0xff - (brushId >> 24), (brushId 
>> 16) & 0xff, (brushId >> 8) & 0xff, brushId & 0xff).getBColor();
+                                LanguageTag aLanguageTag(static_cast< 
LanguageType >(stringFormat->language));
+                                locale = aLanguageTag.getLocale();
                             }
-                            else // we use a pen
+                            else
                             {
-                                const EMFPPen* pen = 
static_cast<EMFPPen*>(maEMFPObjects[brushId & 0xff].get());
-                                if (pen)
-                                {
-                                    color = pen->GetColor().getBColor();
-                                }
+                                // use system default
+                                locale =  
Application::GetSettings().GetLanguageTag().getLocale();
                             }
+
+                            basegfx::B2DHomMatrix transformMatrix = 
basegfx::utils::createScaleTranslateB2DHomMatrix(MapSize(font->emSize,font->emSize),Map(lx,ly+font->emSize));
+
+                            basegfx::BColor color = 
EMFPGetBrushColorOrARGBColor(flags,brushId);
+
                             mrPropertyHolders.Current().setTextColor(color);
                             
mrPropertyHolders.Current().setTextColorActive(true);
 
_______________________________________________
Libreoffice-commits mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to