Kaydet (Commit) 52a2a010 authored tarafından Patrick Jaap's avatar Patrick Jaap Kaydeden (comit) Bartosz Kosiorek

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/43367Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarBartosz Kosiorek <gang65@poczta.onet.pl>
üst c4525644
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <drawinglayer/primitive2d/svggradientprimitive2d.hxx> #include <drawinglayer/primitive2d/svggradientprimitive2d.hxx>
#include <drawinglayer/primitive2d/textprimitive2d.hxx> #include <drawinglayer/primitive2d/textprimitive2d.hxx>
#include <drawinglayer/primitive2d/bitmapprimitive2d.hxx> #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
#include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
#include <drawinglayer/attribute/fontattribute.hxx> #include <drawinglayer/attribute/fontattribute.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx> #include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx> #include <basegfx/polygon/b2dpolygontools.hxx>
...@@ -1107,25 +1108,35 @@ namespace emfplushelper ...@@ -1107,25 +1108,35 @@ namespace emfplushelper
if (bValid) if (bValid)
{ {
BitmapEx aBmp(image.graphic.GetBitmapEx()); // create correct transform matrix
aBmp.Crop(aSource); basegfx::B2DHomMatrix aTransformMatrix = basegfx::utils::createScaleTranslateB2DHomMatrix(
Size aSize(aBmp.GetSizePixel()); aDstSize.getX(),
SAL_INFO("cppcanvas.emf", "EMF+ bitmap size: " << aSize.Width() << "x" << aSize.Height()); aDstSize.getY(),
if (aSize.Width() > 0 && aSize.Height() > 0) aDstPoint.getX(),
aDstPoint.getY());
if (image.type == 1) // Bitmap
{ {
// create correct transform matrix BitmapEx aBmp(image.graphic.GetBitmapEx());
basegfx::B2DHomMatrix aTransformMatrix = basegfx::utils::createScaleTranslateB2DHomMatrix( aBmp.Crop(aSource);
aDstSize.getX(), Size aSize(aBmp.GetSizePixel());
aDstSize.getY(), SAL_INFO("cppcanvas.emf", "EMF+ bitmap size: " << aSize.Width() << "x" << aSize.Height());
aDstPoint.getX(), if (aSize.Width() > 0 && aSize.Height() > 0)
aDstPoint.getY()); {
mrTargetHolders.Current().append(
mrTargetHolders.Current().append( new drawinglayer::primitive2d::BitmapPrimitive2D(aBmp,aTransformMatrix));
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 else
...@@ -1158,11 +1169,11 @@ namespace emfplushelper ...@@ -1158,11 +1169,11 @@ namespace emfplushelper
// parse the string // parse the string
OUString text = read_uInt16s_ToOUString(rMS, stringLength); OUString text = read_uInt16s_ToOUString(rMS, stringLength);
SAL_INFO("cppcanvas.emf", "EMF+ DrawString string: " << text); 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()); EMFPStringFormat *stringFormat = static_cast< EMFPStringFormat* >(maEMFPObjects[formatId & 0xff].get());
// get the font from the flags // get the font from the flags
EMFPFont *font = static_cast< EMFPFont* >( maEMFPObjects[flags & 0xff].get() ); EMFPFont *font = static_cast< EMFPFont* >( maEMFPObjects[flags & 0xff].get() );
if (!stringFormat || !font) if (!font)
{ {
break; break;
} }
...@@ -1175,35 +1186,33 @@ namespace emfplushelper ...@@ -1175,35 +1186,33 @@ namespace emfplushelper
const OUString emptyString; const OUString emptyString;
drawinglayer::attribute::FontAttribute fontAttribute( drawinglayer::attribute::FontAttribute fontAttribute(
font->family, // font family font->family, // font family
emptyString, // (no) font style emptyString, // (no) font style
font->Bold() ? 8u : 1u, // weight: 8 = bold font->Bold() ? 8u : 1u, // weight: 8 = bold
font->family == "SYMBOL", // symbol font->family == "SYMBOL", // symbol
stringFormat->DirectionVertical(), // vertical stringFormat && stringFormat->DirectionVertical(), // vertical
font->Italic(), // italic font->Italic(), // italic
false, // monospaced false, // monospaced
false, // outline = false, no such thing in MS-EMFPLUS false, // outline = false, no such thing in MS-EMFPLUS
stringFormat->DirectionRightToLeft(), // right-to-left stringFormat && stringFormat->DirectionRightToLeft(), // right-to-left
false); // BiDiStrong false); // BiDiStrong
LanguageTag aLanguageTag(static_cast< LanguageType >(stringFormat->language)); css::lang::Locale locale;
css::lang::Locale locale = aLanguageTag.getLocale(); if (stringFormat)
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
{ {
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()); // use system default
if (pen) locale = Application::GetSettings().GetLanguageTag().getLocale();
{
color = pen->GetColor().getBColor();
}
} }
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().setTextColor(color);
mrPropertyHolders.Current().setTextColorActive(true); mrPropertyHolders.Current().setTextColorActive(true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment