[Libreoffice-commits] core.git: emfio/inc emfio/source

2021-11-09 Thread Mike Kaganski (via logerrit)
 emfio/inc/mtftools.hxx   |2 
 emfio/source/reader/mtftools.cxx |  100 +++
 2 files changed, 30 insertions(+), 72 deletions(-)

New commits:
commit 40e6ae66b893b86bdda7d414b4bd58bfc612566f
Author: Mike Kaganski 
AuthorDate: Wed Nov 10 00:25:38 2021 +0300
Commit: Mike Kaganski 
CommitDate: Wed Nov 10 07:30:35 2021 +0100

Simplify MtfTools::ImplMap

Use o3tl::convert instead of homemade constants; unify logic and
move common code out of the switch.

Change-Id: I31e53d04017aac7d6a2f435adb9233b9c0e3ba6e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124939
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/emfio/inc/mtftools.hxx b/emfio/inc/mtftools.hxx
index 3bae0285a9bc..8e3ccba65b84 100644
--- a/emfio/inc/mtftools.hxx
+++ b/emfio/inc/mtftools.hxx
@@ -259,8 +259,6 @@ namespace emfio
 //Scalar constants
 #define UNDOCUMENTED_WIN_RCL_RELATION 32
 #define MS_FIXPOINT_BITCOUNT_28_4 4
-#define HUNDREDTH_MILLIMETERS_PER_MILLIINCH 2.54
-#define MILLIINCH_PER_TWIPS   1.44
 
 class MetaFontAction;
 
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index b98fa7c11d19..204a598d4550 100644
--- a/emfio/source/reader/mtftools.cxx
+++ b/emfio/source/reader/mtftools.cxx
@@ -519,84 +519,38 @@ namespace emfio
 
 if ( mnGfxMode == GM_COMPATIBLE )
 {
+fX2 -= mnWinOrgX;
+fY2 -= mnWinOrgY;
+
 switch( mnMapMode )
 {
 case MM_LOENGLISH :
 {
-fX2 -= mnWinOrgX;
-fY2  = mnWinOrgY-fY2;
-fX2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH * 10;
-fY2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH * 10;
-double nDevOrgX = mnDevOrgX;
-if (mnPixX)
-nDevOrgX *= static_cast(mnMillX) * 100.0 / 
static_cast(mnPixX);
-fX2 += nDevOrgX;
-double nDevOrgY = mnDevOrgY;
-if (mnPixY)
-nDevOrgY *= static_cast(mnMillY) * 100.0 / 
static_cast(mnPixY);
-fY2 += nDevOrgY;
+fX2 = o3tl::convert(fX2, o3tl::Length::in100, 
o3tl::Length::mm100);
+fY2 = o3tl::convert(-fY2, o3tl::Length::in100, 
o3tl::Length::mm100);
 }
 break;
 case MM_HIENGLISH :
 {
-fX2 -= mnWinOrgX;
-fY2  = mnWinOrgY-fY2;
-fX2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH;
-fY2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH;
-double nDevOrgX = mnDevOrgX;
-if (mnPixX)
-nDevOrgX *= static_cast(mnMillX) * 100.0 / 
static_cast(mnPixX);
-fX2 += nDevOrgX;
-double nDevOrgY = mnDevOrgY;
-if (mnPixY)
-nDevOrgY *= static_cast(mnMillY) * 100.0 / 
static_cast(mnPixY);
-fY2 += nDevOrgY;
+fX2 = o3tl::convert(fX2, o3tl::Length::in1000, 
o3tl::Length::mm100);
+fY2 = o3tl::convert(-fY2, o3tl::Length::in1000, 
o3tl::Length::mm100);
 }
 break;
 case MM_TWIPS:
 {
-fX2 -= mnWinOrgX;
-fY2  = mnWinOrgY-fY2;
-fX2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH / 
MILLIINCH_PER_TWIPS;
-fY2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH / 
MILLIINCH_PER_TWIPS;
-double nDevOrgX = mnDevOrgX;
-if (mnPixX)
-nDevOrgX *= static_cast(mnMillX) * 100.0 / 
static_cast(mnPixX);
-fX2 += nDevOrgX;
-double nDevOrgY = mnDevOrgY;
-if (mnPixY)
-nDevOrgY *= static_cast(mnMillY) * 100.0 / 
static_cast(mnPixY);
-fY2 += nDevOrgY;
+fX2 = o3tl::convert(fX2, o3tl::Length::twip, 
o3tl::Length::mm100);
+fY2 = o3tl::convert(-fY2, o3tl::Length::twip, 
o3tl::Length::mm100);
 }
 break;
 case MM_LOMETRIC :
 {
-fX2 -= mnWinOrgX;
-fY2  = mnWinOrgY-fY2;
-fX2 *= 10;
-fY2 *= 10;
-double nDevOrgX = mnDevOrgX;
-if (mnPixX)
-nDevOrgX *= static_cast(mnMillX) * 100.0 / 
static_cast(mnPixX);
-fX2 += 

[Libreoffice-commits] core.git: emfio/inc emfio/source

2021-09-08 Thread Caolán McNamara (via logerrit)
 emfio/inc/wmfreader.hxx   |2 +-
 emfio/source/reader/wmfreader.cxx |   10 ++
 2 files changed, 7 insertions(+), 5 deletions(-)

New commits:
commit 5b6fcbf4a754a2699b3b865256848238f93113a2
Author: Caolán McNamara 
AuthorDate: Wed Sep 8 20:29:41 2021 +0100
Commit: Caolán McNamara 
CommitDate: Wed Sep 8 22:28:31 2021 +0200

ofz: MemorySanitizer: use-of-uninitialized-value

sidestep the resize behaviour of SvMemoryStream by using an honest
std::vector and make it use that buffer

Change-Id: Ic5e405010ac076fc04e1ca8dc6dbb495162101ce
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121832
Tested-by: Jenkins
Reviewed-by: Caolán McNamara 

diff --git a/emfio/inc/wmfreader.hxx b/emfio/inc/wmfreader.hxx
index a7dff2b94d85..f7788d53651c 100644
--- a/emfio/inc/wmfreader.hxx
+++ b/emfio/inc/wmfreader.hxx
@@ -35,7 +35,7 @@ namespace emfio
 sal_uInt32  mnRecSize;
 
 // embedded EMF data
-std::unique_ptr mpEMFStream;
+std::optional> mpEMFStream;
 
 // total number of comment records containing EMF data
 sal_uInt32  mnEMFRecCount;
diff --git a/emfio/source/reader/wmfreader.cxx 
b/emfio/source/reader/wmfreader.cxx
index a32c7f100e04..d71dbf485710 100644
--- a/emfio/source/reader/wmfreader.cxx
+++ b/emfio/source/reader/wmfreader.cxx
@@ -1315,7 +1315,7 @@ namespace emfio
 mpEMFStream.reset();
 }
 else
-mpEMFStream = 
std::make_unique(mnEMFSize, 0);
+mpEMFStream = std::vector();
 }
 else if( (mnEMFRecCount != nComRecCount ) || 
(mnEMFSize != nEMFTotalSize ) ) // add additional checks here
 {
@@ -1343,7 +1343,9 @@ namespace emfio
 std::vector aBuf(nCurRecSize);
 sal_uInt32 nCount = 
mpInputStream->ReadBytes(aBuf.data(), nCurRecSize);
 if( nCount == nCurRecSize )
-mpEMFStream->WriteBytes(aBuf.data(), 
nCount);
+{
+
mpEMFStream->insert(mpEMFStream->end(), aBuf.begin(), aBuf.end());
+}
 }
 }
 }
@@ -1594,8 +1596,8 @@ namespace emfio
 if(mpEMFStream && mnEMFRecCount == mnEMFRec)
 {
 GDIMetaFile aMeta;
-mpEMFStream->Seek( 0 );
-std::unique_ptr 
pEMFReader(std::make_unique( *mpEMFStream, aMeta ));
+SvMemoryStream aStream(mpEMFStream->data(), 
mpEMFStream->size(), StreamMode::STD_READ);
+std::unique_ptr 
pEMFReader(std::make_unique(aStream, aMeta));
 pEMFReader->SetEnableEMFPlus(mbEnableEMFPlus);
 bEMFAvailable = pEMFReader->ReadEnhWMF();
 pEMFReader.reset(); // destroy first!!!


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

2021-06-11 Thread Luboš Luňák (via logerrit)
 emfio/inc/wmfreader.hxx|5 +
 emfio/source/emfuno/xemfparser.cxx |5 -
 emfio/source/reader/emfreader.cxx  |2 +-
 emfio/source/reader/wmfreader.cxx  |1 +
 vcl/source/filter/wmf/wmf.cxx  |   10 ++
 5 files changed, 17 insertions(+), 6 deletions(-)

New commits:
commit b342a445cd8b115e76d261860088b012b74c0b0e
Author: Luboš Luňák 
AuthorDate: Fri Jun 11 15:48:32 2021 +0200
Commit: Luboš Luňák 
CommitDate: Fri Jun 11 23:59:32 2021 +0200

drop EMF+ also when converting WMF, not just EMF

A WMF may have EMF with EMF+ actions embedded. When we read that,
we drop drawing non-EMF+ actions if we use EMF+. But EMF+ actions
are stored as MetaCommentAction in the metafile, and WMF writer
(unlike EMF) writer simply ignores comments. So when writing WMF,
make sure to read non-EMF actions so that something is written.

This is an extension of 295626a0bd39540544b774094a63df23e5376839.

Change-Id: I37355f694fe656b661abe54274ea203934e68151
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117062
Tested-by: Jenkins
Reviewed-by: Luboš Luňák 

diff --git a/emfio/inc/wmfreader.hxx b/emfio/inc/wmfreader.hxx
index 279f3e4caeee..a7dff2b94d85 100644
--- a/emfio/inc/wmfreader.hxx
+++ b/emfio/inc/wmfreader.hxx
@@ -51,6 +51,8 @@ namespace emfio
 // eventually handed over external header
 const WmfExternal* mpExternalHeader;
 
+bool mbEnableEMFPlus = true;
+
 // reads header of the WMF-Datei
 boolReadHeader();
 
@@ -68,6 +70,9 @@ namespace emfio
 
 // read WMF file from stream and fill the GDIMetaFile
 void ReadWMF();
+
+// Allows disabling EMF+ if EMF is embedded in this WMF.
+void SetEnableEMFPlus(bool bEnableEMFPlus) { mbEnableEMFPlus = 
bEnableEMFPlus; }
 };
 }
 
diff --git a/emfio/source/emfuno/xemfparser.cxx 
b/emfio/source/emfuno/xemfparser.cxx
index 7788802c4e1c..e5d27056332d 100644
--- a/emfio/source/emfuno/xemfparser.cxx
+++ b/emfio/source/emfuno/xemfparser.cxx
@@ -130,7 +130,10 @@ namespace emfio::emfreader
 }
 else
 {
-emfio::WmfReader(*pStream, aMtf, bExternalHeaderUsed ? 
 : nullptr).ReadWMF();
+emfio::WmfReader aReader(*pStream, aMtf, 
bExternalHeaderUsed ?  : nullptr);
+if (!bEnableEMFPlus)
+aReader.SetEnableEMFPlus(bEnableEMFPlus);
+aReader.ReadWMF();
 
 // Need to check for ErrCode at stream to not lose 
former work.
 // This may contain important information and will 
behave the
diff --git a/emfio/source/reader/emfreader.cxx 
b/emfio/source/reader/emfreader.cxx
index 04f591a7eb9a..4ad77dd3fb32 100644
--- a/emfio/source/reader/emfreader.cxx
+++ b/emfio/source/reader/emfreader.cxx
@@ -817,7 +817,7 @@ namespace emfio
 bEnableEMFPlus = mbEnableEMFPlus;
 }
 
-SAL_INFO("emfio", "EMF_PLUS_DISABLE is " << (bEnableEMFPlus ? 
"enabled" : "disabled"));
+SAL_INFO("emfio", "EMF+ reading is " << (bEnableEMFPlus ? "enabled" : 
"disabled"));
 
 while (bStatus && mnRecordCount-- && mpInputStream->good() && 
!mbReadOtherGraphicFormat)
 {
diff --git a/emfio/source/reader/wmfreader.cxx 
b/emfio/source/reader/wmfreader.cxx
index 93908503d9bf..9ddb674b7c05 100644
--- a/emfio/source/reader/wmfreader.cxx
+++ b/emfio/source/reader/wmfreader.cxx
@@ -1596,6 +1596,7 @@ namespace emfio
 GDIMetaFile aMeta;
 mpEMFStream->Seek( 0 );
 std::unique_ptr 
pEMFReader(std::make_unique( *mpEMFStream, aMeta ));
+pEMFReader->SetEnableEMFPlus(mbEnableEMFPlus);
 bEMFAvailable = pEMFReader->ReadEnhWMF();
 pEMFReader.reset(); // destroy first!!!
 
diff --git a/vcl/source/filter/wmf/wmf.cxx b/vcl/source/filter/wmf/wmf.cxx
index ccff80c20339..ee1ce77e4185 100644
--- a/vcl/source/filter/wmf/wmf.cxx
+++ b/vcl/source/filter/wmf/wmf.cxx
@@ -88,13 +88,15 @@ bool ConvertGraphicToWMF(const Graphic& rGraphic, SvStream& 
rTargetStream,
  FilterConfigItem const* pConfigItem, bool bPlaceable)
 {
 GfxLink aLink = rGraphic.GetGfxLink();
-if (aLink.IsEMF() && aLink.GetData() && aLink.GetDataSize())
+if (aLink.GetType() == GfxLinkType::NativeWmf && aLink.GetData() && 
aLink.GetDataSize())
 {
-// This may be an EMF+ file, converting that to WMF is better done by 
re-parsing EMF+ as EMF
-// and converting that to WMF.
+// This may be an EMF+ file or WMF file with EMF+ embedded. In 
EmfReader::ReadEnhWMF()
+// we normally drop non-EMF commands when reading EMF+, so converting 
that to WMF
+// is better done by re-parsing with EMF+ disabled.
 auto & 

[Libreoffice-commits] core.git: emfio/inc emfio/source

2021-05-22 Thread Bartosz Kosiorek (via logerrit)
 emfio/inc/emfreader.hxx   |2 +-
 emfio/source/reader/emfreader.cxx |   17 +
 2 files changed, 6 insertions(+), 13 deletions(-)

New commits:
commit 4f4c5b43f0c69385aa2738cbac7f7c898af1972f
Author: Bartosz Kosiorek 
AuthorDate: Sat May 22 19:19:12 2021 +0200
Commit: Bartosz Kosiorek 
CommitDate: Sat May 22 20:08:11 2021 +0200

tdf#55007 EMF Allow negatives values for Start Point and End Point

With previous inplementation, the ARC, ARCTO, CHORD and PIE
records were get Start Point and End Point only with
positive values. It was causing display issues.

This patch fix that according to [MS-EMF] specification

Change-Id: Ie1d90a904e840674380b81af0dfe21260374587d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115994
Tested-by: Jenkins
Reviewed-by: Bartosz Kosiorek 

diff --git a/emfio/inc/emfreader.hxx b/emfio/inc/emfreader.hxx
index e580835fc083..a09ad6fa2c20 100644
--- a/emfio/inc/emfreader.hxx
+++ b/emfio/inc/emfreader.hxx
@@ -27,7 +27,7 @@ namespace emfio
 class EmfReader : public MtfTools
 {
 private:
-sal_Int32   mnRecordCount;
+sal_uInt32   mnRecordCount;
 
 boolmbRecordPath : 1;
 boolmbEMFPlus : 1;
diff --git a/emfio/source/reader/emfreader.cxx 
b/emfio/source/reader/emfreader.cxx
index e9a3afec3f19..9a8784c7e631 100644
--- a/emfio/source/reader/emfreader.cxx
+++ b/emfio/source/reader/emfreader.cxx
@@ -1369,8 +1369,8 @@ namespace emfio
 case EMR_ARCTO :
 case EMR_CHORD :
 {
-sal_uInt32 nStartX, nStartY, nEndX, nEndY;
-mpInputStream->ReadInt32( nX32 ).ReadInt32( nY32 
).ReadInt32( nx32 ).ReadInt32( ny32 ).ReadUInt32( nStartX ).ReadUInt32( nStartY 
).ReadUInt32( nEndX ).ReadUInt32( nEndY );
+sal_Int32 nStartX, nStartY, nEndX, nEndY;
+mpInputStream->ReadInt32( nX32 ).ReadInt32( nY32 
).ReadInt32( nx32 ).ReadInt32( ny32 ).ReadInt32( nStartX ).ReadInt32( nStartY 
).ReadInt32( nEndX ).ReadInt32( nEndY );
 SAL_INFO( "emfio", "\t\t Bounds: " << nX32 << ":" << 
nY32 << ", " << nx32 << ":" << ny32 << ", Start: " << nStartX << ":" << nStartY 
<< ", End: " << nEndX << ":" << nEndY );
 tools::Polygon aPoly( ReadRectangle( nX32, nY32, nx32, 
ny32 ), Point( nStartX, nStartY ), Point( nEndX, nEndY ), PolyStyle::Arc );
 if ( nRecType == EMR_CHORD )
@@ -1382,8 +1382,8 @@ namespace emfio
 
 case EMR_PIE :
 {
-sal_uInt32 nStartX, nStartY, nEndX, nEndY;
-mpInputStream->ReadInt32( nX32 ).ReadInt32( nY32 
).ReadInt32( nx32 ).ReadInt32( ny32 ).ReadUInt32( nStartX ).ReadUInt32( nStartY 
).ReadUInt32( nEndX ).ReadUInt32( nEndY );
+sal_Int32 nStartX, nStartY, nEndX, nEndY;
+mpInputStream->ReadInt32( nX32 ).ReadInt32( nY32 
).ReadInt32( nx32 ).ReadInt32( ny32 ).ReadInt32( nStartX ).ReadInt32( nStartY 
).ReadInt32( nEndX ).ReadInt32( nEndY );
 tools::Polygon aPoly( ReadRectangle( nX32, nY32, nx32, 
ny32 ), Point( nStartX, nStartY ), Point( nEndX, nEndY ), PolyStyle::Pie );
 DrawPolygon( aPoly, mbRecordPath );
 }
@@ -2153,16 +2153,9 @@ namespace emfio
 mnEndPos = nActualFileSize;
 }
 
-mpInputStream->ReadInt32(mnRecordCount);
+mpInputStream->ReadUInt32(mnRecordCount);
 SAL_INFO("emfio", "\tRecords: " << mnRecordCount);
 
-if (mnRecordCount <= 0)
-{
-SAL_WARN("emfio", "EMF\t\tEMF Header object shows record counter 
as <= 0! This shouldn't "
-"be possible... indicator of possible file 
corruption?");
-return false;
-}
-
 // the number of "handles", or graphics objects used in the metafile
 
 sal_uInt16 nHandlesCount;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: emfio/inc emfio/source

2021-03-25 Thread Bartosz Kosiorek (via logerrit)
 emfio/inc/mtftools.hxx|6 +++---
 emfio/source/reader/mtftools.cxx  |   26 +++---
 emfio/source/reader/wmfreader.cxx |8 
 3 files changed, 26 insertions(+), 14 deletions(-)

New commits:
commit 6f2fe8bbc4909f457509391522cae4b8084e69e5
Author: Bartosz Kosiorek 
AuthorDate: Wed Mar 24 14:45:43 2021 +0100
Commit: Bartosz Kosiorek 
CommitDate: Thu Mar 25 14:25:13 2021 +0100

WMF/EMF Convert all index type of Objects to unsigned

Based on WMF and EMF documentation, all indexes should be unsigned.
With this commit it was applied, which simplifies code.

Change-Id: I3257da7e595ace45622c6d865fd4b034dc605cb8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113039
Tested-by: Jenkins
Reviewed-by: Bartosz Kosiorek 

diff --git a/emfio/inc/mtftools.hxx b/emfio/inc/mtftools.hxx
index 286442767d3a..2d31fe4ef4ad 100644
--- a/emfio/inc/mtftools.hxx
+++ b/emfio/inc/mtftools.hxx
@@ -605,11 +605,11 @@ namespace emfio
 voidSetTextAlign(sal_uInt32 nAlign);
 
 voidCreateObject(std::unique_ptr pObject);
-voidCreateObjectIndexed(sal_Int32 nIndex, 
std::unique_ptr pObject);
+voidCreateObjectIndexed(sal_uInt32 nIndex, 
std::unique_ptr pObject);
 voidCreateObject();
 
-voidDeleteObject(sal_Int32 nIndex);
-voidSelectObject(sal_Int32 nIndex);
+voidDeleteObject(sal_uInt32 nIndex);
+voidSelectObject(sal_uInt32 nIndex);
 rtl_TextEncodingGetCharSet() const { return maFont.GetCharSet(); };
 const vcl::Font&GetFont() const { return maFont; }
 voidSetTextLayoutMode(ComplexTextLayoutFlags 
nLayoutMode);
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index fdb8496f1563..5a2f5d1ca806 100644
--- a/emfio/source/reader/mtftools.cxx
+++ b/emfio/source/reader/mtftools.cxx
@@ -782,10 +782,11 @@ namespace emfio
 return rPolyPolygon;
 }
 
-void MtfTools::SelectObject( sal_Int32 nIndex )
+void MtfTools::SelectObject( sal_uInt32 nIndex )
 {
 if ( nIndex & ENHMETA_STOCK_OBJECT )
 {
+SAL_INFO ( "emfio", "\t\t ENHMETA_STOCK_OBJECT, StockObject 
Enumeration: 0x" << std::hex  << nIndex );
 sal_uInt16 nStockId = static_cast(nIndex);
 switch( nStockId )
 {
@@ -802,12 +803,17 @@ namespace emfio
 }
 break;
 case GRAY_BRUSH :
-case DKGRAY_BRUSH :
 {
 maFillStyle = WinMtfFillStyle( COL_GRAY );
 mbFillStyleSelected = true;
 }
 break;
+case DKGRAY_BRUSH :
+{
+maFillStyle = WinMtfFillStyle( COL_GRAY7 );
+mbFillStyleSelected = true;
+}
+break;
 case BLACK_BRUSH :
 {
 maFillStyle = WinMtfFillStyle( COL_BLACK );
@@ -845,13 +851,19 @@ namespace emfio
 
 GDIObj *pGDIObj = nullptr;
 
-if ( o3tl::make_unsigned(nIndex) < mvGDIObj.size() )
+if ( nIndex < mvGDIObj.size() )
 pGDIObj = mvGDIObj[ nIndex ].get();
 
 if ( pGDIObj )
 {
+
+SAL_INFO ( "emfio", "\t\t Index: " << nIndex );
 if (const auto pen = dynamic_cast(pGDIObj))
+{
 maLineStyle = *pen;
+SAL_INFO ( "emfio", "\t Line Style, Color: 0x" << std::hex 
<< maLineStyle.aLineColor
+<< ", Weight: " << 
maLineStyle.aLineInfo.GetWidth() );
+}
 else if (const auto brush = dynamic_cast(
  pGDIObj))
 {
@@ -958,7 +970,7 @@ namespace emfio
 mvGDIObj[ nIndex ] = std::move(pObject);
 }
 
-void MtfTools::CreateObjectIndexed( sal_Int32 nIndex, 
std::unique_ptr pObject )
+void MtfTools::CreateObjectIndexed( sal_uInt32 nIndex, 
std::unique_ptr pObject )
 {
 if ( ( nIndex & ENHMETA_STOCK_OBJECT ) != 0 )
 return;
@@ -989,7 +1001,7 @@ namespace emfio
 }
 }
 }
-if ( o3tl::make_unsigned(nIndex) >= mvGDIObj.size() )
+if ( nIndex >= mvGDIObj.size() )
 ImplResizeObjectArry( nIndex + 16 );
 
 mvGDIObj[ nIndex ] = std::move(pObject);
@@ -1000,11 +1012,11 @@ namespace emfio
 CreateObject(std::make_unique());
 }
 
-void MtfTools::DeleteObject( sal_Int32 nIndex )
+void MtfTools::DeleteObject( sal_uInt32 nIndex )
 {
 if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 )
 {
-if ( o3tl::make_unsigned(nIndex) < mvGDIObj.size() )
+if ( 

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

2021-02-23 Thread Armin Le Grand (Allotropia) (via logerrit)
 emfio/inc/mtftools.hxx|   24 
 emfio/source/reader/emfreader.cxx |4 
 emfio/source/reader/mtftools.cxx  |  211 +-
 emfio/source/reader/wmfreader.cxx |3 
 include/vcl/metaact.hxx   |8 +
 vcl/inc/impfont.hxx   |6 -
 vcl/source/filter/wmf/emfwr.cxx   |2 
 vcl/source/font/font.cxx  |   64 ++-
 8 files changed, 286 insertions(+), 36 deletions(-)

New commits:
commit 3d33e4ce3987ea17e73a72e84f7f0df7af8101a6
Author: Armin Le Grand (Allotropia) 
AuthorDate: Tue Feb 23 14:24:24 2021 +0100
Commit: Armin Le Grand 
CommitDate: Tue Feb 23 20:42:34 2021 +0100

tdf#127471 Detect EMF/WMF with wrong FontScale

Before correcting our EMF/WMF export to write the Windows-
specific data in the case of FontScaling, we wrote these
files with wrong FontScaling.
This change tries to detect and correct this at import, so
that newer versions of the office on all plattforms can
again load old, from us but not on Windows written EMF/WMF
files.
With this change we can read again all new and old EMF/WMF
files (see table in task, comment 80).

Change-Id: I1a0b0ab5f57c7cd40520401568af05cab4ecb4c8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111399
Tested-by: Jenkins
Reviewed-by: Armin Le Grand 

diff --git a/emfio/inc/mtftools.hxx b/emfio/inc/mtftools.hxx
index 70471b66ea21..286442767d3a 100644
--- a/emfio/inc/mtftools.hxx
+++ b/emfio/inc/mtftools.hxx
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "emfiodllapi.h"
 
@@ -259,6 +260,8 @@ namespace emfio
 #define HUNDREDTH_MILLIMETERS_PER_MILLIINCH 2.54
 #define MILLIINCH_PER_TWIPS   1.44
 
+class MetaFontAction;
+
 // WmfReader ==
 
 namespace emfio
@@ -458,6 +461,24 @@ namespace emfio
 {}
 };
 
+// tdf#127471 implement detection and correction of wrongly scaled
+// fonts in own-written, old (before this fix) EMF/WMF files
+class ScaledFontDetectCorrectHelper
+{
+private:
+rtl::Reference  
maCurrentMetaFontAction;
+std::vector 
maAlternativeFontScales;
+std::vector, double>>  
maPositiveIdentifiedCases;
+std::vector, double>>  
maNegativeIdentifiedCases;
+
+public:
+ScaledFontDetectCorrectHelper();
+void endCurrentMetaFontAction();
+void newCurrentMetaFontAction(rtl::Reference& 
rNewMetaFontAction);
+void evaluateAlternativeFontScale(OUString const & rText, tools::Long 
nImportedTextLength);
+void applyAlternativeFontScale();
+};
+
 class MtfTools
 {
 MtfTools(MtfTools const &) = delete;
@@ -521,6 +542,9 @@ namespace emfio
 sal_uInt32  mnEndPos;
 std::vector>maBmpSaveList;
 
+// tdf#127471 always try to detect - only used with ScaledText
+ScaledFontDetectCorrectHelper maScaledFontHelper;
+
 boolmbNopMode : 1;
 boolmbFillStyleSelected : 1;
 boolmbClipNeedsUpdate : 1;
diff --git a/emfio/source/reader/emfreader.cxx 
b/emfio/source/reader/emfreader.cxx
index c2240ed612e5..30730725a182 100644
--- a/emfio/source/reader/emfreader.cxx
+++ b/emfio/source/reader/emfreader.cxx
@@ -2043,6 +2043,10 @@ namespace emfio
 }
 mpInputStream->Seek( nNextPos );
 }
+
+// tdf#127471
+maScaledFontHelper.applyAlternativeFontScale();
+
 if( !maBmpSaveList.empty() )
 ResolveBitmapActions( maBmpSaveList );
 
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index 6064ca937a16..e64bb488a458 100644
--- a/emfio/source/reader/mtftools.cxx
+++ b/emfio/source/reader/mtftools.cxx
@@ -299,6 +299,184 @@ namespace emfio
 #endif
 };
 
+// tdf#127471
+ScaledFontDetectCorrectHelper::ScaledFontDetectCorrectHelper()
+:   maCurrentMetaFontAction(),
+maAlternativeFontScales(),
+maPositiveIdentifiedCases(),
+maNegativeIdentifiedCases()
+{
+}
+
+void ScaledFontDetectCorrectHelper::endCurrentMetaFontAction()
+{
+if(maCurrentMetaFontAction.is() && !maAlternativeFontScales.empty())
+{
+// create average corrected FontScale value and count
+// positive/negative hits
+sal_uInt32 nPositive(0);
+sal_uInt32 nNegative(0);
+double fAverage(0.0);
+
+for(double fPart : maAlternativeFontScales)
+{
+if(fPart < 0.0)
+{
+nNegative++;
+fAverage += -fPart;
+}
+else
+{
+nPositive++;
+fAverage += fPart;
+}
+}
+
+fAverage /= 

[Libreoffice-commits] core.git: emfio/inc emfio/source include/vcl vcl/qa vcl/source

2020-12-09 Thread Miklos Vajna (via logerrit)
 emfio/inc/emfreader.hxx  |2 ++
 emfio/source/emfuno/xemfparser.cxx   |   16 
 emfio/source/reader/emfreader.cxx|6 ++
 include/vcl/vectorgraphicdata.hxx|4 
 include/vcl/wmf.hxx  |2 ++
 vcl/qa/cppunit/GraphicTest.cxx   |   26 ++
 vcl/source/filter/graphicfilter.cxx  |2 +-
 vcl/source/filter/wmf/wmf.cxx|   29 -
 vcl/source/gdi/vectorgraphicdata.cxx |   11 +++
 9 files changed, 96 insertions(+), 2 deletions(-)

New commits:
commit ca67839234e78fe6bea21ec39906d1bd71d34d47
Author: Miklos Vajna 
AuthorDate: Wed Dec 9 09:38:48 2020 +0100
Commit: Miklos Vajna 
CommitDate: Wed Dec 9 10:46:31 2020 +0100

vcl: improve EMF+ -> WMF conversion

We throw away EMF fallback info when parsing EMF+ data. This means that
the resulting GDIMetaFile (containing EMF+ data but no EMF fallback) is
tricky to export to WMF, where EMF+ comments are not allowed.

Improve the conversion result by re-parsing such EMF+ data with EMF+
disabled, and then converting the GDIMetaFile (containing EMF fallback
data) to WMF.

Change-Id: Ib2c0388f1344aef7f601ce9be59e4a8924e8085b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107453
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins

diff --git a/emfio/inc/emfreader.hxx b/emfio/inc/emfreader.hxx
index 39d576b64aed..e580835fc083 100644
--- a/emfio/inc/emfreader.hxx
+++ b/emfio/inc/emfreader.hxx
@@ -35,6 +35,7 @@ namespace emfio
 /// Another format is read already, can ignore actual EMF data.
 bool mbReadOtherGraphicFormat = false;
 basegfx::B2DTuple maSizeHint;
+bool mbEnableEMFPlus = true;
 
 boolReadHeader();
 // reads and converts the rectangle
@@ -49,6 +50,7 @@ namespace emfio
 /// Parses EMR_COMMENT_MULTIFORMATS.
 void ReadMultiformatsComment();
 void SetSizeHint(const basegfx::B2DTuple& rSizeHint) { maSizeHint = 
rSizeHint; }
+void SetEnableEMFPlus(bool bEnableEMFPlus) { mbEnableEMFPlus = 
bEnableEMFPlus; }
 
 private:
 template  void ReadAndDrawPolyPolygon(sal_uInt32 nNextPos);
diff --git a/emfio/source/emfuno/xemfparser.cxx 
b/emfio/source/emfuno/xemfparser.cxx
index 8667ccf1faea..7788802c4e1c 100644
--- a/emfio/source/emfuno/xemfparser.cxx
+++ b/emfio/source/emfuno/xemfparser.cxx
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -87,6 +88,17 @@ namespace emfio::emfreader
 {
 WmfExternal aExternalHeader;
 const bool 
bExternalHeaderUsed(aExternalHeader.setSequence(rProperties));
+bool bEnableEMFPlus = true;
+comphelper::SequenceAsHashMap aMap(rProperties);
+auto it = aMap.find("EMFPlusEnable");
+if (it != aMap.end())
+{
+bool bValue;
+if (it->second >>= bValue)
+{
+bEnableEMFPlus = bValue;
+}
+}
 
 // rough check - import and conv to primitive
 GDIMetaFile aMtf;
@@ -110,6 +122,10 @@ namespace emfio::emfreader
 // read and get possible failure/error, ReadEnhWMF 
returns success
 emfio::EmfReader aReader(*pStream, aMtf);
 aReader.SetSizeHint(maSizeHint);
+if (!bEnableEMFPlus)
+{
+aReader.SetEnableEMFPlus(bEnableEMFPlus);
+}
 bReadError = !aReader.ReadEnhWMF();
 }
 else
diff --git a/emfio/source/reader/emfreader.cxx 
b/emfio/source/reader/emfreader.cxx
index 69916939fa26..ae00508380e1 100644
--- a/emfio/source/reader/emfreader.cxx
+++ b/emfio/source/reader/emfreader.cxx
@@ -803,6 +803,12 @@ namespace emfio
 OUString aEMFPlusDisable;
 rtl::Bootstrap::get("EMF_PLUS_DISABLE", aEMFPlusDisable);
 bool bEnableEMFPlus = aEMFPlusDisable.isEmpty();
+if (!mbEnableEMFPlus)
+{
+// EMF+ is enabled if neither the bootstrap variable, not the 
member variable disables
+// it.
+bEnableEMFPlus = mbEnableEMFPlus;
+}
 
 SAL_INFO("emfio", "EMF_PLUS_DISABLE is " << (bEnableEMFPlus ? 
"enabled" : "disabled"));
 
diff --git a/include/vcl/vectorgraphicdata.hxx 
b/include/vcl/vectorgraphicdata.hxx
index 0fdc9abbba42..1787d060e11b 100644
--- a/include/vcl/vectorgraphicdata.hxx
+++ b/include/vcl/vectorgraphicdata.hxx
@@ -77,6 +77,8 @@ private:
 /// Useful for PDF, which is vector-based, but still rendered to a bitmap.
 basegfx::B2DTuple maSizeHint;
 
+bool mbEnableEMFPlus = true;
+
 // on demand creators
 void ensurePdfReplacement();
 void 

[Libreoffice-commits] core.git: emfio/inc emfio/source extensions/source filter/source include/filter

2020-10-22 Thread Noel (via logerrit)
 emfio/inc/mtftools.hxx|4 -
 emfio/source/reader/mtftools.cxx  |8 +--
 emfio/source/reader/wmfreader.cxx |6 +-
 extensions/source/bibliography/bibbeam.cxx|2 
 extensions/source/bibliography/bibconfig.hxx  |   13 +++---
 extensions/source/bibliography/bibcont.cxx|8 +--
 extensions/source/bibliography/general.cxx|4 -
 extensions/source/scanner/grid.cxx|8 +--
 extensions/source/scanner/sanedlg.cxx |   14 +++---
 filter/source/graphicfilter/egif/egif.cxx |   22 +-
 filter/source/graphicfilter/eps/eps.cxx   |   52 -
 filter/source/graphicfilter/icgm/actimpr.cxx  |   30 +++---
 filter/source/graphicfilter/icgm/bitmap.cxx   |   10 ++--
 filter/source/graphicfilter/icgm/bitmap.hxx   |2 
 filter/source/graphicfilter/icgm/bundles.hxx  |   10 ++--
 filter/source/graphicfilter/icgm/cgm.cxx  |2 
 filter/source/graphicfilter/icgm/cgmtypes.hxx |6 +-
 filter/source/graphicfilter/icgm/class1.cxx   |2 
 filter/source/graphicfilter/icgm/class3.cxx   |4 -
 filter/source/graphicfilter/icgm/class4.cxx   |   26 ++--
 filter/source/graphicfilter/icgm/class5.cxx   |4 -
 filter/source/graphicfilter/icgm/classx.cxx   |2 
 filter/source/graphicfilter/icgm/elements.cxx |6 +-
 filter/source/graphicfilter/icgm/elements.hxx |   12 ++---
 filter/source/graphicfilter/icgm/outact.hxx   |4 -
 filter/source/graphicfilter/idxf/dxf2mtf.cxx  |   32 +++
 filter/source/graphicfilter/idxf/dxf2mtf.hxx  |6 +-
 filter/source/graphicfilter/idxf/dxfblkrd.hxx |2 
 filter/source/graphicfilter/idxf/dxfentrd.hxx |   53 +-
 filter/source/graphicfilter/idxf/dxfgrprd.cxx |2 
 filter/source/graphicfilter/idxf/dxfgrprd.hxx |9 ++--
 filter/source/graphicfilter/idxf/dxftblrd.cxx |2 
 filter/source/graphicfilter/idxf/dxftblrd.hxx |   34 
 filter/source/graphicfilter/idxf/dxfvec.cxx   |4 -
 filter/source/graphicfilter/ieps/ieps.cxx |   24 +--
 filter/source/graphicfilter/ipcd/ipcd.cxx |   24 +--
 filter/source/graphicfilter/ipict/ipict.cxx   |   16 +++
 filter/source/graphicfilter/ipict/shape.cxx   |   40 +--
 filter/source/graphicfilter/itga/itga.cxx |2 
 filter/source/graphicfilter/itiff/itiff.cxx   |   14 +++---
 filter/source/msfilter/msdffimp.cxx   |   36 -
 filter/source/msfilter/mstoolbar.cxx  |2 
 filter/source/msfilter/svdfppt.cxx|   14 +++---
 filter/source/msfilter/util.cxx   |2 
 filter/source/pdf/pdfexport.cxx   |   10 ++--
 filter/source/svg/svgfilter.cxx   |2 
 filter/source/svg/svgwriter.cxx   |   48 +++
 filter/source/svg/svgwriter.hxx   |   14 +++---
 include/filter/msfilter/msdffimp.hxx  |   20 -
 include/filter/msfilter/mstoolbar.hxx |2 
 include/filter/msfilter/util.hxx  |3 -
 51 files changed, 342 insertions(+), 336 deletions(-)

New commits:
commit 180dd91c189de0bf03d5062e33c20da94c5d35d9
Author: Noel 
AuthorDate: Wed Oct 21 15:26:38 2020 +0200
Commit: Noel Grandin 
CommitDate: Thu Oct 22 08:07:45 2020 +0200

long->tools::Long in emfio..filter

Change-Id: I961cee10d45d628ff70dea0694a7a63a4fe867ea
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104624
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/emfio/inc/mtftools.hxx b/emfio/inc/mtftools.hxx
index 9506b4f5f31c..5c0c60973350 100644
--- a/emfio/inc/mtftools.hxx
+++ b/emfio/inc/mtftools.hxx
@@ -625,8 +625,8 @@ namespace emfio
 );
 voidDrawText(Point& rPosition,
 OUString const & rString,
-long* pDXArry = nullptr,
-long* pDYArry = nullptr,
+tools::Long* pDXArry = nullptr,
+tools::Long* pDYArry = nullptr,
 bool bRecordPath = false,
 sal_Int32 nGraphicsMode = GM_COMPATIBLE);
 
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index 080521ed0523..e32b0f2be502 100644
--- a/emfio/source/reader/mtftools.cxx
+++ b/emfio/source/reader/mtftools.cxx
@@ -266,7 +266,7 @@ namespace emfio
 aFont.SetFontSize( aFontSize );
 pVDev->SetFont( aFont );
 FontMetric aMetric( pVDev->GetFontMetric() );
-long nHeight = aMetric.GetAscent() + aMetric.GetDescent();
+tools::Long nHeight = aMetric.GetAscent() + aMetric.GetDescent();
 if (nHeight)
 {
 double fHeight = (static_cast(aFontSize.Height()) * 
rFont.lfHeight ) / nHeight;
@@ -743,7 +743,7 @@ namespace emfio
 if ( pLineStyle->aLineInfo.GetStyle() == LineStyle::Dash )
 {
 aSize.AdjustWidth(1 );
-long 

[Libreoffice-commits] core.git: emfio/inc emfio/source

2020-09-17 Thread Miklos Vajna (via logerrit)
 emfio/inc/emfreader.hxx   |4 +
 emfio/source/reader/emfreader.cxx |   86 ++
 2 files changed, 82 insertions(+), 8 deletions(-)

New commits:
commit d75c5b38911557173c54a78f42ff220ab3918573
Author: Miklos Vajna 
AuthorDate: Thu Sep 17 13:21:52 2020 +0200
Commit: Miklos Vajna 
CommitDate: Thu Sep 17 17:21:44 2020 +0200

tdf#136836 emfio: speed up import of EMF import when the orig PDF is 
available

The PPTX bugdoc has a 17MB EMF file, which has enough instructions to
keep Impress busy for minutes during import.

Take advantage of the detail that this EMF has a
EMR_COMMENT_MULTIFORMATS record that contains the original PDF, which
can be rendered much faster:

- old cost: 122.153 seconds
- new cost: 1.952 seconds (1.6% of baseline)

Change-Id: I38efc1c24e21a7622377b9e1c1938ebee826bae9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102918
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins

diff --git a/emfio/inc/emfreader.hxx b/emfio/inc/emfreader.hxx
index 90d8969ae70c..75a77211ea61 100644
--- a/emfio/inc/emfreader.hxx
+++ b/emfio/inc/emfreader.hxx
@@ -32,6 +32,8 @@ namespace emfio
 boolmbRecordPath : 1;
 boolmbEMFPlus : 1;
 boolmbEMFPlusDualMode : 1;
+/// An other format is read already, can ignore actual EMF data.
+bool mbReadOtherGraphicFormat = false;
 
 boolReadHeader();
 // reads and converts the rectangle
@@ -43,6 +45,8 @@ namespace emfio
 
 bool ReadEnhWMF();
 void ReadGDIComment(sal_uInt32 nCommentId);
+/// Parses EMR_COMMENT_MULTIFORMATS.
+void ReadMultiformatsComment();
 
 private:
 template  void ReadAndDrawPolyPolygon(sal_uInt32 nNextPos);
diff --git a/emfio/source/reader/emfreader.cxx 
b/emfio/source/reader/emfreader.cxx
index 8c128d2965c6..7bb4d408203a 100644
--- a/emfio/source/reader/emfreader.cxx
+++ b/emfio/source/reader/emfreader.cxx
@@ -24,6 +24,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #ifdef DBG_UTIL
 #include 
@@ -163,6 +165,8 @@ using namespace std;
 #define EMR_SETLINKEDUFIS  119
 #define EMR_SETTEXTJUSTIFICATION   120
 
+#define PDF_SIGNATURE 0x50444620 // "PDF "
+
 namespace
 {
 
@@ -381,16 +385,13 @@ namespace emfio
 {
 }
 
-#if OSL_DEBUG_LEVEL > 0
 const sal_uInt32 EMR_COMMENT_BEGINGROUP = 0x0002;
 const sal_uInt32 EMR_COMMENT_ENDGROUP = 0x0003;
 const sal_uInt32 EMR_COMMENT_MULTIFORMATS = 0x4004;
 const sal_uInt32 EMR_COMMENT_WINDOWS_METAFILE = 0x8001;
-#endif
 
 void EmfReader::ReadGDIComment(sal_uInt32 nCommentId)
 {
-#if OSL_DEBUG_LEVEL > 0
 sal_uInt32 nPublicCommentIdentifier;
 mpInputStream->ReadUInt32(nPublicCommentIdentifier);
 
@@ -433,7 +434,7 @@ namespace emfio
 break;
 
 case EMR_COMMENT_MULTIFORMATS:
-SAL_WARN("emfio", "\t\tEMR_COMMENT_MULTIFORMATS not 
implemented");
+ReadMultiformatsComment();
 break;
 
 case EMR_COMMENT_WINDOWS_METAFILE:
@@ -444,9 +445,78 @@ namespace emfio
 SAL_WARN("emfio", "\t\tEMR_COMMENT_PUBLIC not implemented, id: 
0x" << std::hex << nCommentId << std::dec);
 break;
 }
-#else
-(void) nCommentId;
-#endif
+}
+
+void EmfReader::ReadMultiformatsComment()
+{
+tools::Rectangle aOutputRect = EmfReader::ReadRectangle();
+
+sal_uInt32 nCountFormats;
+mpInputStream->ReadUInt32(nCountFormats);
+if (nCountFormats < 1)
+{
+return;
+}
+
+// Read the first EmrFormat.
+sal_uInt32 nSignature;
+mpInputStream->ReadUInt32(nSignature);
+if (nSignature != PDF_SIGNATURE)
+{
+return;
+}
+
+sal_uInt32 nVersion;
+mpInputStream->ReadUInt32(nVersion);
+if (nVersion != 1)
+{
+return;
+}
+
+sal_uInt32 nSizeData;
+mpInputStream->ReadUInt32(nSizeData);
+if (!nSizeData || nSizeData > mpInputStream->remainingSize())
+{
+return;
+}
+
+sal_uInt32 nOffData;
+mpInputStream->ReadUInt32(nOffData);
+if (!nOffData)
+{
+return;
+}
+
+std::vector aPdfData(nSizeData);
+mpInputStream->ReadBytes(aPdfData.data(), aPdfData.size());
+if (!mpInputStream->good())
+{
+return;
+}
+
+SvMemoryStream aPdfStream;
+aPdfStream.WriteBytes(aPdfData.data(), aPdfData.size());
+aPdfStream.Seek(0);
+Graphic aGraphic;
+if (!vcl::ImportPDF(aPdfStream, aGraphic))
+{
+return;
+}
+
+maBmpSaveList.emplace_back(new BSaveStruct(aGraphic.GetBitmapEx(), 
aOutputRect, SRCCOPY));
+const std::shared_ptr pVectorGraphicData

[Libreoffice-commits] core.git: emfio/inc emfio/source

2019-11-23 Thread Chris Sherlock (via logerrit)
 emfio/inc/emfreader.hxx   |1 
 emfio/source/reader/emfreader.cxx |  268 +-
 emfio/source/reader/mtftools.cxx  |6 
 3 files changed, 211 insertions(+), 64 deletions(-)

New commits:
commit debb38c7be8015b4de4aace6f8ac78e4ee2fbfa6
Author: Chris Sherlock 
AuthorDate: Wed Nov 20 15:16:07 2019 +1100
Commit: Bartosz Kosiorek 
CommitDate: Sat Nov 23 23:55:40 2019 +0100

emfio: extra logging

For emfio I believe we need more logging, so I am gradually adding this.
I decided to log the EMR_COMMENT_PUBLIC record subtypes
EMR_COMMENT_BEGINGROUP and EMR_COMMENT_ENDGROUP.

I honestly don't know what these actually do, but they are specified in
[MS-EMF] 2.3.3.4.1 and 2.3.3.4.2. Later on, we will need to look into
handling EMR_COMMENT_MULTIFORMATS so we can display things with EPS
data. We should also probably look into handling
EMR_COMMENT_WINDOWS_METAFILE later on also.

Change-Id: I7c3ba3cfd7f51a6cff2c7a47a48dde12240d0382
Reviewed-on: https://gerrit.libreoffice.org/83407
Tested-by: Jenkins
Reviewed-by: Bartosz Kosiorek 

diff --git a/emfio/inc/emfreader.hxx b/emfio/inc/emfreader.hxx
index a54eee1a9c70..90d8969ae70c 100644
--- a/emfio/inc/emfreader.hxx
+++ b/emfio/inc/emfreader.hxx
@@ -42,6 +42,7 @@ namespace emfio
 ~EmfReader();
 
 bool ReadEnhWMF();
+void ReadGDIComment(sal_uInt32 nCommentId);
 
 private:
 template  void ReadAndDrawPolyPolygon(sal_uInt32 nNextPos);
diff --git a/emfio/source/reader/emfreader.cxx 
b/emfio/source/reader/emfreader.cxx
index b5fdf0238031..ed42f904c011 100644
--- a/emfio/source/reader/emfreader.cxx
+++ b/emfio/source/reader/emfreader.cxx
@@ -375,7 +375,7 @@ namespace emfio
 , mnRecordCount(0)
 , mbRecordPath(false)
 , mbEMFPlus(false)
-,mbEMFPlusDualMode(false)
+, mbEMFPlusDualMode(false)
 {
 }
 
@@ -383,6 +383,74 @@ namespace emfio
 {
 }
 
+#if OSL_DEBUG_LEVEL > 0
+const sal_uInt32 EMR_COMMENT_BEGINGROUP = 0x0002;
+const sal_uInt32 EMR_COMMENT_ENDGROUP = 0x0003;
+const sal_uInt32 EMR_COMMENT_MULTIFORMATS = 0x0004;
+const sal_uInt32 EMR_COMMENT_WINDOWS_METAFILE = 0x0005;
+
+void EmfReader::ReadGDIComment(sal_uInt32 nCommentId)
+{
+sal_uInt32 nPublicCommentIdentifier;
+mpInputStream->ReadUInt32(nPublicCommentIdentifier);
+
+SAL_INFO("emfio", "\t\tEMR_COMMENT_PUBLIC, id: 0x" << std::hex << 
nCommentId << std::dec);
+switch (nPublicCommentIdentifier)
+{
+case EMR_COMMENT_BEGINGROUP:
+{
+SAL_INFO("emfio", "\t\t\tEMR_COMMENT_BEGINGROUP");
+sal_uInt32 left, top, right, bottom;
+
mpInputStream->ReadUInt32(left).ReadUInt32(top).ReadUInt32(right).ReadUInt32(bottom);
+
+SAL_INFO("emfio", "\t\t\t\tBounding rect");
+SAL_INFO("emfio", "\t\t\t\t\tLeft: " << left);
+SAL_INFO("emfio", "\t\t\t\t\tTop: " << top);
+SAL_INFO("emfio", "\t\t\t\t\tRight: " << right);
+SAL_INFO("emfio", "\t\t\t\t\tBottom: " << bottom);
+
+sal_uInt32 nDescChars;
+mpInputStream->ReadUInt32(nDescChars);
+
+OUString aDesc;
+for (sal_uInt32 i=0; i < nDescChars; i++)
+{
+sal_uInt16 cChar(0);
+mpInputStream->ReadUInt16(cChar);
+if (cChar == '\0')
+break;
+
+sal_Unicode cUniChar = static_cast(cChar);
+aDesc = aDesc.concat(OUString(cUniChar));
+}
+
+SAL_INFO("emfio", "\t\tDescription: " << aDesc);
+}
+break;
+
+case EMR_COMMENT_ENDGROUP:
+SAL_INFO("emfio", "\t\t\tEMR_COMMENT_ENDGROUP");
+break;
+
+case EMR_COMMENT_MULTIFORMATS:
+SAL_WARN("emfio", "\t\tEMR_COMMENT_MULTIFORMATS not 
implemented");
+break;
+
+case EMR_COMMENT_WINDOWS_METAFILE:
+SAL_WARN("emfio", "\t\tEMR_COMMENT_WINDOWS_METAFILE not 
implemented");
+break;
+
+default:
+SAL_WARN("emfio", "\t\tEMR_COMMENT_PUBLIC not implemented, id: 
0x" << std::hex << nCommentId << std::dec);
+break;
+}
+}
+#else
+void EmfReader::ReadGDIComment(sal_uInt32)
+{
+}
+#endif
+
 void EmfReader::ReadEMFPlusComment(sal_uInt32 length, bool& bHaveDC)
 {
 if (!mbEMFPlus)
@@ -425,14 +493,14 @@ namespace emfio
 mpInputStream->ReadUInt16( type ).ReadUInt16( flags ).ReadUInt32( 
size ).ReadUInt32( dataSize );
 nRemainder -= nRequiredHeaderSize;
 
-SAL_INFO ("emfio", "\t\tEMF+ record type: " << std::hex << type << 
std::dec);
+SAL_INFO("emfio", 

[Libreoffice-commits] core.git: emfio/inc emfio/source

2019-06-04 Thread Stephan Bergmann (via logerrit)
 emfio/inc/mtftools.hxx   |1 +
 emfio/source/reader/mtftools.cxx |5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)

New commits:
commit ee6dd4d39e9169283e74a9210ace0b8f7f897da4
Author: Stephan Bergmann 
AuthorDate: Mon Jun 3 14:37:37 2019 +0200
Commit: Thorsten Behrens 
CommitDate: Tue Jun 4 14:55:46 2019 +0200

Avoid truncation of ±1E20 to long

With -fsanitize=float-cast-overflow, opening doc/abi5309-1.doc as obtained 
by
bin/get-bugzilla-attachments-by-mimetype (i.e., the attachment at
) fails with

> include/tools/helpers.hxx:76:79: runtime error: 1e+20 is outside the 
range of representable values of type 'long'
>  #0 in FRound(double) at include/tools/helpers.hxx:76:79 
(instdir/program/libtllo.so +0x3c13dd)
>  #1 in ImplPolygon::ImplPolygon(basegfx::B2DPolygon const&) at 
tools/source/generic/poly.cxx:474:30 (instdir/program/libtllo.so +0x40f35f)
>  #2 in tools::Polygon::Polygon(basegfx::B2DPolygon const&) at 
tools/source/generic/poly.cxx:1849:72 (instdir/program/libtllo.so +0x42c9ff)
>  #3 in ImplPolyPolygon::ImplPolyPolygon(basegfx::B2DPolyPolygon const&) 
at tools/source/generic/poly2.cxx:482:28 (instdir/program/libtllo.so +0x45561e)
>  #4 in tools::PolyPolygon::PolyPolygon(basegfx::B2DPolyPolygon const&) at 
tools/source/generic/poly2.cxx:463:25 (instdir/program/libtllo.so +0x45512d)
>  #5 in emfio::MtfTools::DrawPolygon(tools::Polygon, bool) at 
emfio/source/reader/mtftools.cxx:1287:17 
(instdir/program/../program/libemfiolo.so +0x1828d3)
>  #6 in emfio::WmfReader::ReadRecordParams(unsigned short) at 
emfio/source/reader/wmfreader.cxx:367:21 
(instdir/program/../program/libemfiolo.so +0x1cffde)
>  #7 in emfio::WmfReader::ReadWMF() at 
emfio/source/reader/wmfreader.cxx:1425:29 
(instdir/program/../program/libemfiolo.so +0x1f7567)
>  #8 in 
emfio::emfreader::XEmfParser::getDecomposition(com::sun::star::uno::Reference
 const&, rtl::OUString const&, 
com::sun::star::uno::Sequence const&) at 
emfio/source/emfuno/xemfparser.cxx:152:108 
(instdir/program/../program/libemfiolo.so +0x13795a)
>  #9 in non-virtual thunk to 
emfio::emfreader::XEmfParser::getDecomposition(com::sun::star::uno::Reference
 const&, rtl::OUString const&, 
com::sun::star::uno::Sequence const&) at 
emfio/source/emfuno/xemfparser.cxx (instdir/program/../program/libemfiolo.so 
+0x138735)
>  #10 in VectorGraphicData::ensureSequenceAndRange() at 
vcl/source/gdi/vectorgraphicdata.cxx:172:137 (instdir/program/libvcllo.so 
+0x86bdadf)
>  #11 in VectorGraphicData::ensureReplacement() at 
vcl/source/gdi/vectorgraphicdata.cxx:138:5 (instdir/program/libvcllo.so 
+0x86bcb94)
>  #12 in VectorGraphicData::getReplacement() const at 
vcl/source/gdi/vectorgraphicdata.cxx:286:45 (instdir/program/libvcllo.so 
+0x86c0a04)
>  #13 in ImpGraphic::ImplSetPrefSize(Size const&) at 
vcl/source/gdi/impgraph.cxx:956:45 (instdir/program/libvcllo.so +0x7d05433)
>  #14 in Graphic::SetPrefSize(Size const&) at 
vcl/source/gdi/graph.cxx:388:19 (instdir/program/libvcllo.so +0x7ca7e26)
>  #15 in SvxMSDffManager::GetBLIPDirect(SvStream&, Graphic&, 
tools::Rectangle*) at filter/source/msfilter/msdffimp.cxx:6616:26 
(instdir/program/../program/libmsfilterlo.so +0x9617bc)
>  #16 in SvxMSDffManager::GetBLIP(unsigned long, Graphic&, 
tools::Rectangle*) at filter/source/msfilter/msdffimp.cxx:6453:23 
(instdir/program/../program/libmsfilterlo.so +0x95f368)
>  #17 in SvxMSDffManager::ImportGraphic(SvStream&, SfxItemSet&, DffObjData 
const&) at filter/source/msfilter/msdffimp.cxx:3821:24 
(instdir/program/../program/libmsfilterlo.so +0x990678)
>  #18 in SvxMSDffManager::ImportShape(DffRecordHeader const&, SvStream&, 
SvxMSDffClientData&, tools::Rectangle&, tools::Rectangle const&, int, int*) at 
filter/source/msfilter/msdffimp.cxx:4368:28 
(instdir/program/../program/libmsfilterlo.so +0x9a221a)
>  #19 in SvxMSDffManager::ImportObj(SvStream&, SvxMSDffClientData&, 
tools::Rectangle&, tools::Rectangle const&, int, int*) at 
filter/source/msfilter/msdffimp.cxx:4073:16 
(instdir/program/../program/libmsfilterlo.so +0x9972d8)
>  #20 in SvxMSDffManager::GetShape(unsigned long, SdrObject*&, 
SvxMSDffImportData&) at filter/source/msfilter/msdffimp.cxx:6377:23 
(instdir/program/../program/libmsfilterlo.so +0x9dde0c)
>  #21 in SwWW8ImplReader::Read_GrafLayer(long) at 
sw/source/filter/ww8/ww8graf.cxx:2567:34 
(instdir/program/../program/libmswordlo.so +0x2c51a1f)
>  #22 in SwWW8ImplReader::ReadChar(long, long) at 
sw/source/filter/ww8/ww8par.cxx:3697:17 
(instdir/program/../program/libmswordlo.so +0x2db3a07)
>  #23 in SwWW8ImplReader::ReadChars(int&, int, long, long) at 
sw/source/filter/ww8/ww8par.cxx:3484:27 
(instdir/program/../program/libmswordlo.so +0x2dafba2)
>  #24 in SwWW8ImplReader::ReadText(int, int, ManTypes) at 
sw/source/filter/ww8/ww8par.cxx:4045:22 

[Libreoffice-commits] core.git: emfio/inc emfio/source

2017-11-14 Thread Caolán McNamara
 emfio/inc/emfreader.hxx   |8 ++--
 emfio/source/reader/emfreader.cxx |   63 ++
 2 files changed, 41 insertions(+), 30 deletions(-)

New commits:
commit 7d6f8b48ad4131b13f18ce9d92c10f6b998a68ec
Author: Caolán McNamara 
Date:   Tue Nov 14 09:47:57 2017 +

ofz: stop at min of end of record and end of stream

Change-Id: I61c7cf74ea75ec56b6ccb3661f6fdd54a1ff12e1
Reviewed-on: https://gerrit.libreoffice.org/44705
Tested-by: Jenkins 
Reviewed-by: Caolán McNamara 
Tested-by: Caolán McNamara 

diff --git a/emfio/inc/emfreader.hxx b/emfio/inc/emfreader.hxx
index 4b2855cf54f6..a54eee1a9c70 100644
--- a/emfio/inc/emfreader.hxx
+++ b/emfio/inc/emfreader.hxx
@@ -44,10 +44,10 @@ namespace emfio
 bool ReadEnhWMF();
 
 private:
-template  void ReadAndDrawPolyPolygon();
-template  void ReadAndDrawPolyLine();
-template  tools::Polygon ReadPolygon(sal_uInt32 nStartIndex, 
sal_uInt32 nPoints);
-template  tools::Polygon ReadPolygonWithSkip(const bool 
skipFirst);
+template  void ReadAndDrawPolyPolygon(sal_uInt32 nNextPos);
+template  void ReadAndDrawPolyLine(sal_uInt32 nNextPos);
+template  tools::Polygon ReadPolygon(sal_uInt32 nStartIndex, 
sal_uInt32 nPoints, sal_uInt32 nNextPos);
+template  tools::Polygon ReadPolygonWithSkip(const bool 
skipFirst, sal_uInt32 nNextPos);
 
 tools::Rectangle ReadRectangle();
 void ReadEMFPlusComment(sal_uInt32 length, bool& bHaveDC);
diff --git a/emfio/source/reader/emfreader.cxx 
b/emfio/source/reader/emfreader.cxx
index bcd8b7a83855..6ee222d427cb 100644
--- a/emfio/source/reader/emfreader.cxx
+++ b/emfio/source/reader/emfreader.cxx
@@ -468,7 +468,7 @@ namespace emfio
  * skipFirst: if the first point read is the 0th point or the 1st point in 
the array.
  * */
 template 
-tools::Polygon EmfReader::ReadPolygonWithSkip(const bool skipFirst)
+tools::Polygon EmfReader::ReadPolygonWithSkip(const bool skipFirst, 
sal_uInt32 nNextPos)
 {
 sal_uInt32 nPoints(0), nStartIndex(0);
 mpInputStream->SeekRel( 16 );
@@ -479,7 +479,7 @@ namespace emfio
 nStartIndex ++;
 }
 
-return ReadPolygon(nStartIndex, nPoints);
+return ReadPolygon(nStartIndex, nPoints, nNextPos);
 }
 
 /**
@@ -490,13 +490,22 @@ namespace emfio
  * mpInputStream: the stream containing the polygons
  * */
 template 
-tools::Polygon EmfReader::ReadPolygon(sal_uInt32 nStartIndex, sal_uInt32 
nPoints)
+tools::Polygon EmfReader::ReadPolygon(sal_uInt32 nStartIndex, sal_uInt32 
nPoints, sal_uInt32 nNextPos)
 {
 bool bRecordOk = nPoints <= SAL_MAX_UINT16;
 SAL_WARN_IF(!bRecordOk, "emfio", "polygon record has more polygons 
than we can handle");
 if (!bRecordOk)
 return tools::Polygon();
 
+auto nRemainingSize = std::min(nNextPos - mpInputStream->Tell(), 
mpInputStream->remainingSize());
+auto nMaxPossiblePoints = nRemainingSize / (sizeof(T) * 2);
+auto nPointCount = nPoints - nStartIndex;
+if (nPointCount > nMaxPossiblePoints)
+{
+SAL_WARN("emfio", "polygon claims more points than record can 
provide, truncating");
+nPoints = nMaxPossiblePoints + nStartIndex;
+}
+
 tools::Polygon aPolygon(nPoints);
 for (sal_uInt32 i = nStartIndex ; i < nPoints && 
mpInputStream->good(); i++ )
 {
@@ -519,20 +528,21 @@ namespace emfio
  * The \ parameter refers to the type of the points. (e.g. 
sal_uInt16 or sal_uInt32)
  * */
 template 
-void EmfReader::ReadAndDrawPolyLine()
+void EmfReader::ReadAndDrawPolyLine(sal_uInt32 nNextPos)
 {
 sal_uInt32  nPoints;
 sal_uInt32  i, nNumberOfPolylines( 0 ), nCount( 0 );
 mpInputStream->SeekRel( 0x10 ); // TODO Skipping Bounds. A 128-bit WMF 
RectL object (specifies the bounding rectangle in device units.)
 mpInputStream->ReadUInt32( nNumberOfPolylines );
 mpInputStream->ReadUInt32( nCount ); // total number of points in all 
polylines
-if (mpInputStream->Tell() >= mnEndPos)
+const auto nEndPos = std::min(nNextPos, mnEndPos);
+if (mpInputStream->Tell() >= nEndPos)
 return;
 
 // taking the amount of points of each polygon, retrieving the total 
number of points
 if ( mpInputStream->good() &&
  ( nNumberOfPolylines < SAL_MAX_UINT32 / sizeof( sal_uInt16 ) ) &&
- ( nNumberOfPolylines * sizeof( sal_uInt16 ) ) <= ( mnEndPos - 
mpInputStream->Tell() )
+ ( nNumberOfPolylines * sizeof( sal_uInt16 ) ) <= ( nEndPos - 
mpInputStream->Tell() )
)
 {
 std::unique_ptr< sal_uInt32[] > pnPolylinePointCount( new 
sal_uInt32[ nNumberOfPolylines ] );
@@ -544,8 +554,8 @@ 

[Libreoffice-commits] core.git: emfio/inc emfio/source

2017-10-26 Thread Patrick Jaap
 emfio/inc/emfreader.hxx   |1 +
 emfio/source/reader/emfreader.cxx |   18 ++
 2 files changed, 19 insertions(+)

New commits:
commit e06807f51d157844b357dab1bbf960cc55162330
Author: Patrick Jaap 
Date:   Mon Oct 2 16:21:04 2017 +0200

tdf#31814 EMF/EMF+ implement dual mode

There can be a dual mode flag set in the EMF+ data. If set,
we should process either EMF or EMF+ data, because the contained
information should be equal (says the documentation).
The more advanced EMF+ renderer is chosen here.

The flag is read in the EMFPlusReader and blocks the reading of other
EMF records than HEADER, EOF and COMMENT.

Thanks to Chris, for pointing out the dual mode!

Change-Id: I8522930cebbb9e9ecc732397cbb3deea9e8c9127
Reviewed-on: https://gerrit.libreoffice.org/43122
Reviewed-by: Patrick Jaap 
Reviewed-by: Bartosz Kosiorek 
Tested-by: Bartosz Kosiorek 

diff --git a/emfio/inc/emfreader.hxx b/emfio/inc/emfreader.hxx
index 8ee533c24068..4b2855cf54f6 100644
--- a/emfio/inc/emfreader.hxx
+++ b/emfio/inc/emfreader.hxx
@@ -31,6 +31,7 @@ namespace emfio
 
 boolmbRecordPath : 1;
 boolmbEMFPlus : 1;
+boolmbEMFPlusDualMode : 1;
 
 boolReadHeader();
 // reads and converts the rectangle
diff --git a/emfio/source/reader/emfreader.cxx 
b/emfio/source/reader/emfreader.cxx
index 859c3510b759..8ff413b79033 100644
--- a/emfio/source/reader/emfreader.cxx
+++ b/emfio/source/reader/emfreader.cxx
@@ -384,6 +384,7 @@ namespace emfio
 , mnRecordCount(0)
 , mbRecordPath(false)
 , mbEMFPlus(false)
+,mbEMFPlusDualMode(false)
 {
 }
 
@@ -443,6 +444,15 @@ namespace emfio
 SAL_INFO ("vcl.emf", "\t\tEMF+ lock DC (device context)");
 }
 
+// look for the "dual mode" in header
+// it indicates that either EMF or EMF+ records should be processed
+// 0x4001= EMF+ header
+// flags & 1 = dual mode active
+if ( type == 0x4001 && flags & 1 )
+{
+mbEMFPlusDualMode = true;
+}
+
 // Get the length of the remaining data of this record based
 // on the alleged size
 sal_uInt32 nRemainingRecordData = size >= nRequiredHeaderSize ?
@@ -697,6 +707,14 @@ namespace emfio
 }
 }
 }
+else if ( !bHaveDC && mbEMFPlusDualMode && nRecType != EMR_HEADER 
&& nRecType != EMR_EOF )
+{
+// skip content (EMF record) in dual mode
+// we process only EMR_COMMENT (see above) to access EMF+ data
+// with 2 exceptions, according to EMF+ specification:
+// EMR_HEADER and EMR_EOF
+// if a device context is given (bHaveDC) process the 
following EMF record, too.
+}
 else if( !mbEMFPlus || bHaveDC || nRecType == EMR_EOF )
 {
 switch( nRecType )
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits