Kaydet (Commit) e58dc868 authored tarafından Bartosz Kosiorek's avatar Bartosz Kosiorek

tdf#113624 EMF+ Add support for different units conversion

With previous implementation only Pixel unit was supported.
Other units (eg. inch, milimeters, points, world) was treated
as Pixel.
With this patch the correct unit conversion was implemented to following records:
 - FontObject
 - PenObject
 - SetWorldTransform

As a result records are properly scaled.
Tested with DrawString record from:
https://bugs.documentfoundation.org/attachment.cgi?id=140287

Change-Id: I77435ad8f1bbac08f298a03d91d0c7f1f1734e5c
Reviewed-on: https://gerrit.libreoffice.org/52825Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarBartosz Kosiorek <gang65@poczta.onet.pl>
üst a0c00817
......@@ -49,6 +49,9 @@ namespace emfplushelper
SAL_INFO("drawinglayer", "EMF+\tfont\nEMF+\theader: 0x" << std::hex << (header >> 12) << " version: 0x" << (header & 0x1fff) << " size: " << std::dec << emSize << " unit: 0x" << std::hex << sizeUnit << std::dec);
SAL_INFO("drawinglayer", "EMF+\tflags: 0x" << std::hex << fontFlags << " reserved: 0x" << reserved << " length: 0x" << std::hex << length << std::dec);
//tdf#113624 Convert unit to Pixels
emSize = emSize * EmfPlusHelperData::getUnitToPixelMultiplier(static_cast<UnitType>(sizeUnit));
if (length > 0 && length < 0x4000)
{
rtl_uString *pStr = rtl_uString_alloc(length);
......
......@@ -114,6 +114,44 @@ namespace emfplushelper
StringAlignmentFar = 0x00000002
} StringAlignment;
float EmfPlusHelperData::getUnitToPixelMultiplier(const UnitType aUnitType)
{
switch (aUnitType)
{
case UnitTypePixel:
{
return 1.0f;
}
case UnitTypePoint:
{
SAL_INFO("drawinglayer", "EMF+\t Converting Points to Pixels.");
return 1.333333f;
}
case UnitTypeInch:
{
SAL_INFO("drawinglayer", "EMF+\t TODO Test Converting Inches to Pixels, if it is working correctly.");
return 96.0f;
}
case UnitTypeMillimeter:
{
SAL_INFO("drawinglayer", "EMF+\t TODO Test Converting Milimeters to Pixels, if it is working correctly.");
return 3.779528f;
}
case UnitTypeDocument:
{
SAL_INFO("drawinglayer", "EMF+\t TODO Test Converting Documents to Pixels, if it is working correctly.");
return 0.32f;
}
case UnitTypeWorld:
case UnitTypeDisplay:
default:
{
SAL_WARN("drawinglayer", "EMF+\tTODO Unimplemented support of Unit Type: 0x" << std::hex << aUnitType);
}
}
return 1.0f;
}
void EmfPlusHelperData::processObjectRecord(SvMemoryStream& rObjectStream, sal_uInt16 flags, sal_uInt32 dataSize, bool bUseWholeStream)
{
sal_uInt32 index;
......@@ -1245,7 +1283,7 @@ namespace emfplushelper
}
else
{
SAL_WARN("drawinglayer", "EMF+ DrawImage(Points) Wrong EMF+ file. Only Unit Type Pixel is support by EMF+ standard in DrawImage(Points)");
SAL_WARN("drawinglayer", "EMF+ DrawImage(Points) Wrong EMF+ file. Only Unit Type Pixel is support by EMF+ specification for DrawImage(Points)");
}
break;
}
......@@ -1380,14 +1418,15 @@ namespace emfplushelper
SAL_INFO("drawinglayer", "EMF+ SetPageTransform");
SAL_INFO("drawinglayer", "EMF+\tscale: " << mfPageScale << " unit: " << flags);
if (flags != UnitTypePixel)
if ((flags == UnitTypeDisplay) || (flags == UnitTypeWorld))
{
SAL_WARN("drawinglayer", "EMF+\t TODO Only UnitTypePixel is supported. ");
SAL_WARN("drawinglayer", "EMF+ file error. UnitTypeDisplay and UnitTypeWorld are not supported by SetPageTransform in EMF+ specification.");
}
else
{
mnMmX *= mfPageScale;
mnMmY *= mfPageScale;
const float aPageScaleMul = mfPageScale * getUnitToPixelMultiplier(static_cast<UnitType>(flags));
mnMmX *= aPageScaleMul;
mnMmY *= aPageScaleMul;
mappingChanged();
}
break;
......
......@@ -262,6 +262,8 @@ namespace emfplushelper
static void ReadRectangle(SvStream& s, float& x, float& y, float &width, float& height, bool bCompressed = false);
static bool readXForm(SvStream& rIn, basegfx::B2DHomMatrix& rTarget);
::basegfx::B2DPolyPolygon const combineClip(::basegfx::B2DPolyPolygon const & leftPolygon, int combineMode, ::basegfx::B2DPolyPolygon const & rightPolygon);
static float getUnitToPixelMultiplier(const UnitType aUnitType);
};
}
......
......@@ -171,6 +171,8 @@ namespace emfplushelper
SAL_INFO("drawinglayer", "EMF+\t graphics version: 0x" << std::hex << graphicsVersion << " type (must be set to zero): " << penType <<
" pen data flags: 0x" << penDataFlags << " unit: " << penUnit << " width: " << std::dec << penWidth);
penWidth = penWidth * EmfPlusHelperData::getUnitToPixelMultiplier(static_cast<UnitType>(penUnit));
if (penDataFlags & PenDataTransform)
{
EmfPlusHelperData::readXForm(s, pen_transformation);
......
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