core.git: vcl/qa vcl/source

2024-08-23 Thread Tibor Nagy (via logerrit)
 vcl/qa/cppunit/pdfexport/data/tdf159895.odt |binary
 vcl/qa/cppunit/pdfexport/pdfexport2.cxx |   61 
 vcl/source/gdi/pdfwriter_impl.cxx   |   15 +++---
 3 files changed, 68 insertions(+), 8 deletions(-)

New commits:
commit 54374c97b86730d97f5ad622dc88c0798af4be1c
Author: Tibor Nagy 
AuthorDate: Thu Aug 22 21:34:34 2024 +0200
Commit: Nagy Tibor 
CommitDate: Fri Aug 23 16:25:43 2024 +0200

tdf#159895 sw: fix "Stack empty" error in tagged PDF export

Change-Id: I8a2e0d51d1cfe6d4b517f193c73e512600638cf0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172302
Tested-by: Jenkins
Reviewed-by: Nagy Tibor 

diff --git a/vcl/qa/cppunit/pdfexport/data/tdf159895.odt 
b/vcl/qa/cppunit/pdfexport/data/tdf159895.odt
new file mode 100644
index ..77091cf51cad
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf159895.odt differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx
index 9b08b1fa047a..4895845f4b8c 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx
@@ -85,6 +85,67 @@ void PdfExportTest2::load(std::u16string_view rFile, 
vcl::filter::PDFDocument& r
 CPPUNIT_ASSERT(rDocument.Read(aStream));
 }
 
+CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf159895)
+{
+// Enable PDF/UA
+uno::Sequence 
aFilterData(comphelper::InitPropertySequence({
+{ "PDFUACompliance", uno::Any(true) },
+{ "ExportFormFields", uno::Any(true) },
+}));
+aMediaDescriptor[u"FilterData"_ustr] <<= aFilterData;
+
+vcl::filter::PDFDocument aDocument;
+load(u"tdf159895.odt", aDocument);
+
+// The document has one page.
+std::vector aPages = aDocument.GetPages();
+CPPUNIT_ASSERT_EQUAL(size_t(1), aPages.size());
+
+for (const auto& rDocElement : aDocument.GetElements())
+{
+auto pObj = 
dynamic_cast(rDocElement.get());
+if (!pObj)
+continue;
+
+auto pType = 
dynamic_cast(pObj->Lookup("Type"_ostr));
+if (pType && pType->GetValue() == "XObject")
+{
+auto pFilter = 
dynamic_cast(pObj->Lookup("Filter"_ostr));
+CPPUNIT_ASSERT(pFilter);
+
+vcl::filter::PDFStreamElement* pStream = pObj->GetStream();
+CPPUNIT_ASSERT(pStream);
+SvMemoryStream& rObjectStream = pStream->GetMemory();
+// Uncompress it.
+SvMemoryStream aUncompressed;
+ZCodec aZCodec;
+aZCodec.BeginCompression();
+rObjectStream.Seek(0);
+aZCodec.Decompress(rObjectStream, aUncompressed);
+CPPUNIT_ASSERT(aZCodec.EndCompression());
+
+auto pStart = static_cast(aUncompressed.GetData());
+const char* const pEnd = pStart + aUncompressed.GetSize();
+
+OString sText;
+while (true)
+{
+auto const pLine = ::std::find(pStart, pEnd, '
');
+if (pLine == pEnd)
+break;
+
+std::string_view const line(pStart, pLine - pStart);
+pStart = pLine + 1;
+if (!line.empty() && line[0] != '%')
+{
+sText += line + "
"_ostr;
+}
+}
+CPPUNIT_ASSERT_EQUAL("/Tx BMC
EMC
"_ostr, sText);
+}
+}
+}
+
 CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf124272)
 {
 // Import the bugdoc and export as PDF.
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 434156491703..d986c93c3de3 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -4364,20 +4364,12 @@ void PDFWriterImpl::createDefaultListBoxAppearance( 
PDFWidget& rBox, const PDFWr
 Font aFont = drawFieldBorder( rBox, rWidget, rSettings );
 sal_Int32 nBest = getSystemFont( aFont );
 
-beginRedirect( pListBoxStream, rBox.m_aRect );
-
 setLineColor( COL_TRANSPARENT );
 setFillColor( replaceColor( rWidget.BackgroundColor, 
rSettings.GetFieldColor() ) );
 drawRectangle( rBox.m_aRect );
 
-// empty appearance, see createDefaultEditAppearance for reference
-writeBuffer( "/Tx BMC
EMC
" );
-
-endRedirect();
 pop();
 
-rBox.m_aAppearances[ "N"_ostr ][ "Standard"_ostr ] = pListBoxStream;
-
 // prepare DA string
 OStringBuffer aDA( 256 );
 // prepare DA string
@@ -4394,6 +4386,13 @@ void PDFWriterImpl::createDefaultListBoxAppearance( 
PDFWidget& rBox, const PDFWr
 aDA.append( ' ' );
 m_aPages[ m_nCurrentPage ].appendMappedLength( sal_Int32( 
aFont.GetFontHeight() ), aDA );
 aDA.append( " Tf" );
+
+beginRedirect(pListBoxStream, rBox.m_aRect);
+// empty appearance, see createDefaultEditAppearance for reference
+writeBuffer("/Tx BMC
EMC
");
+endRedirect();
+
+rBox.m_aAppearances["N"_ostr]["Standard"_ostr] = pListBoxStream;
 rBox.m_aDAString = aDA.makeStringAn

core.git: vcl/qa vcl/source

2024-07-24 Thread Patrick Luby (via logerrit)
 vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx |4 ++--
 vcl/source/filter/webp/writer.cxx  |4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 4bbdb2f0718d71840a4e55cc7e9c82157422b0dd
Author: Patrick Luby 
AuthorDate: Wed Jul 24 10:25:30 2024 -0400
Commit: Patrick Luby 
CommitDate: Wed Jul 24 20:58:16 2024 +0200

tdf#162171 alpha mask pixels are now alpha instead of transparency

Starting with commit 81994cb2b8b32453a92bcb011830fcb884f22ff3,
alpha masks now store alpha instead of transparency values.

Change-Id: I74d7a536e0ae1aea3b462d660ae3e4b815cf89c2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170968
Tested-by: Jenkins
Reviewed-by: Noel Grandin 
Reviewed-by: Patrick Luby 

diff --git a/vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx 
b/vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx
index 7c2c88a983ca..0bdf908ad059 100644
--- a/vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx
+++ b/vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx
@@ -95,7 +95,7 @@ void WebpFilterTest::testRoundtrip(bool lossy)
 pAccess->SetFillColor(COL_BLUE);
 pAccess->FillRect(tools::Rectangle(Point(10, 10), Size(10, 10)));
 BitmapScopedWriteAccess pAccessAlpha(aAlpha);
-pAccessAlpha->SetFillColor(BitmapColor(0)); // opaque
+pAccessAlpha->SetFillColor(BitmapColor(COL_WHITE)); // opaque
 pAccessAlpha->FillRect(tools::Rectangle(Point(0, 0), Size(10, 10)));
 pAccessAlpha->FillRect(tools::Rectangle(Point(10, 0), Size(10, 10)));
 pAccessAlpha->FillRect(tools::Rectangle(Point(0, 10), Size(10, 10)));
@@ -144,7 +144,7 @@ void WebpFilterTest::testRoundtrip(bool lossy)
 CPPUNIT_ASSERT_EQUAL(sal_uInt8(255), pAccessAlpha->GetPixelIndex(0, 
0));
 CPPUNIT_ASSERT_EQUAL(sal_uInt8(255), pAccessAlpha->GetPixelIndex(0, 
19));
 CPPUNIT_ASSERT_EQUAL(sal_uInt8(255), pAccessAlpha->GetPixelIndex(19, 
0));
-CPPUNIT_ASSERT_EQUAL(sal_uInt8(191), pAccessAlpha->GetPixelIndex(19, 
19));
+CPPUNIT_ASSERT_EQUAL(sal_uInt8(64), pAccessAlpha->GetPixelIndex(19, 
19));
 }
 
 aStream.Seek(STREAM_SEEK_TO_BEGIN);
diff --git a/vcl/source/filter/webp/writer.cxx 
b/vcl/source/filter/webp/writer.cxx
index 021947682a1c..da20e2dcc18e 100644
--- a/vcl/source/filter/webp/writer.cxx
+++ b/vcl/source/filter/webp/writer.cxx
@@ -148,8 +148,8 @@ static bool writeWebp(SvStream& rStream, const BitmapEx& 
bitmapEx, bool lossless
 for (tools::Long x = 0; x < access->Width(); ++x)
 {
 BitmapColor color = access->GetPixelFromData(srcB, x);
-BitmapColor transparency = 
accessAlpha->GetPixelFromData(srcA, x);
-color.SetAlpha(255 - transparency.GetIndex());
+BitmapColor alpha = accessAlpha->GetPixelFromData(srcA, x);
+color.SetAlpha(alpha.GetIndex());
 dst[0] = color.GetRed();
 dst[1] = color.GetGreen();
 dst[2] = color.GetBlue();


core.git: vcl/qa vcl/source

2024-07-24 Thread Jonathan Clark (via logerrit)
 vcl/qa/cppunit/pdfexport/data/tdf157390-overlapping-kanji.fodt |  239 
++
 vcl/qa/cppunit/pdfexport/pdfexport2.cxx|   54 ++
 vcl/source/gdi/pdfwriter_impl.cxx  |   13 
 3 files changed, 304 insertions(+), 2 deletions(-)

New commits:
commit 15d92cd882e7d8280d6d9bdc44b6f29a951aef46
Author: Jonathan Clark 
AuthorDate: Wed Jul 24 01:45:01 2024 -0600
Commit: Jonathan Clark 
CommitDate: Wed Jul 24 15:05:59 2024 +0200

tdf#157390 Fix overlapping CJK characters in PDF export

This change fixes a vertical text glyph metrics regression that was
introduced while migrating PDF export to use metrics from HarfBuzz. The
root cause was incorrectly caching CJK glyph heights in place of widths
for vertical text.

Change-Id: I8426fc902658d1c045b42e760028f26b09eeef93
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170935
Tested-by: Jenkins
Reviewed-by: Jonathan Clark 

diff --git a/vcl/qa/cppunit/pdfexport/data/tdf157390-overlapping-kanji.fodt 
b/vcl/qa/cppunit/pdfexport/data/tdf157390-overlapping-kanji.fodt
new file mode 100644
index ..6385cf597986
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/tdf157390-overlapping-kanji.fodt
@@ -0,0 +1,239 @@
+
+http://www.w3.org/TR/css3-text/"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:dc="http://purl.org/dc/elements/1.1/"; xmlns:c
 alcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:
 meta:1.0" 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ 
2024-07-23T06:07:05.8023702802024-07-24T00:55:47.337561889PT45M9S14LibreOfficeDev/25.2.0.0.alpha0$Linux_X86_64
 
LibreOffice_project/e9bd8614e28421d4907b06ed2e84bda9ba08e12f2024-07-23T06:49:26.331205263PDF
 files
+ 
+  
+  
+  
+   
+
+ 
AAERAQAABAAQR1BPU1gER70AAAwkAAACmkdTVUIWpuctAAAOwcZPUy8yVT7L/QAA
+  CKBgU1RBVHiSbN0AABCILmNtYXAfLimoAAAJAMhnYXNwEAAADBwI
+  Z2x5ZuFez6oAAAEcAAAGqGhlYWQi08pEAAAICDZoaGVhDBEIgAAACHwkaG10eCu5
+  CEYAAAhAPGxvY2EMDgoDAAAH5CJtYXhwAGUCCQAAB8QgbmFtZS00RvoAAAnQ
+  AAACKnBvc3T/hgAyAAAL/CBwcmVwaAaMhQAACcgHdmhlYQyeFyAAABDcJHZt
+  dHgNEAQOAAAQuCIAAgBf//MA4wLtAAUAEQAAdwMnMwcDByImNTQ2MzIWFRQGgg0CXAIM
+  IBsnJxscJibdAahoaP5Y6iceICYmIB4nAAIAWgHjAX8DAwAFAAsAAFMnJzMHBzMnJzMHB24S
+  AmACEYwTAmECEwHjumZmurpmZroAAQDTASUBVwGyAAsAAEEiJjU0NjMyFhUUBgEUGyYmGxso
+  KAElKB4gJycgHigAAAEANP/IAVUA4AAJAABFLgInNx4CFwERIExNJEEkUE0fOChQSh05HUxQ
+  JQAAAgB+//cDmAK8ACEALgAAUw4CFQYWFhceAjMyPgI3Fw4CIyImJicuAjU0JicFHgQXBy4D
+  J98CAwMBAQMECCY3IxMkIRsJPx49PyIvWEAOBQUBAgUCahsxKSEVBVAGHiw6JAK6DCQkDR9P
+  VSpTfUYjO0klR1VjLEWbgSxmXB0RNhIeIltnbm0yIUSNhXYrAAEAcP/VA1gC8gBXAABTFhYz
+  Mj4DNzY2NxcGBgcOAwc2NjMyFhYVFAYGIyImJjU0NjYzMhYWFwcmJiMiBhUUFjMyNjY1NCYm
+  IyIOAgcnPgM3PgM3Ig4DBwYGB+4RJw8PRVdXRRAWGAguDR0OE0BNSh4jRyFTgUlUmmpEYjUm
+  Ri5DWDADSARHPCIuSjtVfUM6ZUE/ZFdVMDkfS0xBFhU/RD0TED5MSz0QECIQAuECAgIDAwQB
+  AgQCOgkUDA41QT4ZDAk9akRQeEEkQCoiPCQ3WTMMQFMmGiQqLlg+MU4tGzJLMDsZPz83EhE1
+  

core.git: vcl/qa vcl/source

2024-06-25 Thread Tomaž Vajngerl (via logerrit)
 vcl/source/filter/igif/gifread.cxx |  148 +++--
 1 file changed, 45 insertions(+), 103 deletions(-)

New commits:
commit d9fee55c634b500f1d7d0edaa25cecfc276b0869
Author: Tomaž Vajngerl 
AuthorDate: Tue Jun 25 00:08:50 2024 +0900
Commit: Tomaž Vajngerl 
CommitDate: Wed Jun 26 00:44:55 2024 +0200

vcl: remove partial GIF image loading

This removes the code that handles the IO_PENDING and the graphic
"context" handling from GIF image format.

Partial loading of images complicates the image filter life cycle
a lot (many exceptions) and is not really needed so much today as
this was needed in the past. In most cases we load the whole image
in one pass anyway. Even loading from the network should be fast
enough to not cause issues for the user.

Most image filters don't even implement this like PNG and nobody
noticed for many years that this is not supported.

To handle IO_PENDING case it is probably better to load the
bitstream into memory and then load the whole image after that
in one pass. This can also be implemented all inside (Imp)Graphic
in a very straight forward way.

In addition some broken GIF files for testCVEs now fail to load
completely and those need to be moved from pass/ to fail/.

Change-Id: I5fb7004a4aff957da872bb3f5c66b61bf95f18d7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165212
Reviewed-by: Tomaž Vajngerl 
Tested-by: Jenkins

diff --git 
a/vcl/qa/cppunit/graphicfilter/data/gif/pass/afl-sample-short-read-1.gif 
b/vcl/qa/cppunit/graphicfilter/data/gif/fail/afl-sample-short-read-1.gif
similarity index 100%
rename from 
vcl/qa/cppunit/graphicfilter/data/gif/pass/afl-sample-short-read-1.gif
rename to vcl/qa/cppunit/graphicfilter/data/gif/fail/afl-sample-short-read-1.gif
diff --git 
a/vcl/qa/cppunit/graphicfilter/data/gif/pass/afl-sample-short-read-2.gif 
b/vcl/qa/cppunit/graphicfilter/data/gif/fail/afl-sample-short-read-2.gif
similarity index 100%
rename from 
vcl/qa/cppunit/graphicfilter/data/gif/pass/afl-sample-short-read-2.gif
rename to vcl/qa/cppunit/graphicfilter/data/gif/fail/afl-sample-short-read-2.gif
diff --git a/vcl/qa/cppunit/graphicfilter/data/gif/pass/crash-1.gif 
b/vcl/qa/cppunit/graphicfilter/data/gif/fail/crash-1.gif
similarity index 100%
rename from vcl/qa/cppunit/graphicfilter/data/gif/pass/crash-1.gif
rename to vcl/qa/cppunit/graphicfilter/data/gif/fail/crash-1.gif
diff --git a/vcl/qa/cppunit/graphicfilter/data/gif/pass/crash-2.gif 
b/vcl/qa/cppunit/graphicfilter/data/gif/fail/crash-2.gif
similarity index 100%
rename from vcl/qa/cppunit/graphicfilter/data/gif/pass/crash-2.gif
rename to vcl/qa/cppunit/graphicfilter/data/gif/fail/crash-2.gif
diff --git a/vcl/source/filter/igif/gifread.cxx 
b/vcl/source/filter/igif/gifread.cxx
index 443eb05c045a..67af603218d4 100644
--- a/vcl/source/filter/igif/gifread.cxx
+++ b/vcl/source/filter/igif/gifread.cxx
@@ -42,8 +42,7 @@ enum GIFAction
 enum ReadState
 {
 GIFREAD_OK,
-GIFREAD_ERROR,
-GIFREAD_NEED_MORE
+GIFREAD_ERROR
 };
 
 }
@@ -115,7 +114,6 @@ public:
 ReadState   ReadGIF( Graphic& rGraphic );
 boolReadIsAnimated();
 void GetLogicSize(Size& rLogicSize);
-Graphic GetIntermediateGraphic();
 
 explicitGIFReader( SvStream& rStm );
 };
@@ -261,13 +259,13 @@ bool GIFReader::ReadGlobalHeader()
 boolbRet = false;
 
 auto nRead = rIStm.ReadBytes(pBuf, 6);
-if (nRead == 6 && (rIStm.GetError() != ERRCODE_IO_PENDING))
+if (nRead == 6 && rIStm.good())
 {
 pBuf[ 6 ] = 0;
 if( !strcmp( pBuf, "GIF87a" ) || !strcmp( pBuf, "GIF89a" ) )
 {
 nRead = rIStm.ReadBytes(pBuf, 7);
-if (nRead == 7 && (rIStm.GetError() != ERRCODE_IO_PENDING))
+if (nRead == 7 && rIStm.good())
 {
 sal_uInt8   nAspect;
 sal_uInt8   nRF;
@@ -287,7 +285,7 @@ bool GIFReader::ReadGlobalHeader()
 else
 nBackgroundColor = 0;
 
-if (rIStm.GetError() != ERRCODE_IO_PENDING)
+if (rIStm.good())
 bRet = true;
 }
 }
@@ -307,7 +305,7 @@ void GIFReader::ReadPaletteEntries( BitmapPalette* pPal, 
sal_uLong nCount )
 std::unique_ptr pBuf(new sal_uInt8[ nLen ]);
 std::size_t nRead = rIStm.ReadBytes(pBuf.get(), nLen);
 nCount = nRead/3UL;
-if (rIStm.GetError() == ERRCODE_IO_PENDING)
+if (!rIStm.good())
 return;
 
 sal_uInt8* pTmp = pBuf.get();
@@ -340,7 +338,7 @@ bool GIFReader::ReadExtension()
 // Extension-Label
 sal_uInt8 cFunction(0);
 rIStm.ReadUChar( cFunction );
-if (rIStm.GetError() != ERRCODE_IO_PENDING)
+if (rIStm.good())
 {
 boolbOverreadDataBlocks = false;
 sal_uInt8 cSize(0);
@@ -358,7 +356,7 @@ bool GIFReader::ReadExtension()
 sal

core.git: vcl/qa vcl/source

2024-04-24 Thread Patrick Luby (via logerrit)
 vcl/qa/cppunit/pdfexport/pdfexport2.cxx |6 +-
 vcl/source/gdi/pdfwriter_impl.cxx   |   14 ++
 2 files changed, 15 insertions(+), 5 deletions(-)

New commits:
commit 4b31f87e918c38a7eb30ceb85563a5c98b426da5
Author: Patrick Luby 
AuthorDate: Mon Apr 22 19:36:14 2024 -0400
Commit: Patrick Luby 
CommitDate: Wed Apr 24 20:17:56 2024 +0200

tdf#160714 use crop box for bounds of embedded PDF object

If there is no crop box, fallback to the media box just to be safe.

Change-Id: I29f99a43e550cf09a1534c0aa01ffd6a55536fb7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166544
Tested-by: Jenkins
Reviewed-by: Patrick Luby 

diff --git a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx
index 525f1d91a449..ccaab1d5c9bf 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx
@@ -45,6 +45,7 @@
 #include 
 
 #include 
+#include 
 #include 
 #include 
 
@@ -4627,7 +4628,10 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest2, 
testRexportMediaBoxOrigin)
 = { // Rotation by $   heta$ $cos( heta), sin( heta), -sin(
heta), cos( heta)$
 0, -1, 1, 0,
 // Translate x,y
--aOrigin[1] - aSize[1] / 2 + aSize[0] / 2, aOrigin[0] + aSize[0] / 
2 + aSize[1] / 2
+-aOrigin[1] - aSize[1] / vcl::PDF_INSERT_MAGIC_SCALE_FACTOR / 2
++ aSize[0] / vcl::PDF_INSERT_MAGIC_SCALE_FACTOR / 2,
+aOrigin[0] + aSize[0] / vcl::PDF_INSERT_MAGIC_SCALE_FACTOR / 2
++ aSize[1] / vcl::PDF_INSERT_MAGIC_SCALE_FACTOR / 2
   };
 
 for (sal_Int32 nIdx = 0; nIdx < 6; ++nIdx)
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index d780b0c4f88e..cf5a5fc39546 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -9124,9 +9124,15 @@ void PDFWriterImpl::writeReferenceXObject(const 
ReferenceXObjectEmit& rEmit)
 }
 
 double aOrigin[2] = { 0.0, 0.0 };
-if (auto* pArray = 
dynamic_cast(pPage->Lookup("MediaBox"_ostr)))
+
+// tdf#160714 use crop box for bounds of embedded PDF object
+// If there is no crop box, fallback to the media box just to be safe.
+auto* pBoundsArray = 
dynamic_cast(pPage->Lookup("CropBox"_ostr));
+if (!pBoundsArray)
+pBoundsArray = 
dynamic_cast(pPage->Lookup("MediaBox"_ostr));
+if (pBoundsArray)
 {
-const auto& rElements = pArray->GetElements();
+const auto& rElements = pBoundsArray->GetElements();
 if (rElements.size() >= 4)
 {
 // get x1, y1 of the rectangle.
@@ -9239,9 +9245,9 @@ void PDFWriterImpl::writeReferenceXObject(const 
ReferenceXObjectEmit& rEmit)
 // Now transform the object: rotate around the center and make 
sure that the rotation
 // doesn't affect the aspect ratio.
 basegfx::B2DHomMatrix aMat;
-aMat.translate(-0.5 * aBBox.getWidth() - aOrigin[0], -0.5 * 
aBBox.getHeight() - aOrigin[1]);
+aMat.translate((-0.5 * aBBox.getWidth() / fMagicScaleFactor) - 
aOrigin[0], (-0.5 * aBBox.getHeight() / fMagicScaleFactor) - aOrigin[1]);
 aMat.rotate(basegfx::deg2rad(nAngle));
-aMat.translate(0.5 * nWidth, 0.5 * nHeight);
+aMat.translate(0.5 * nWidth / fMagicScaleFactor, 0.5 * nHeight / 
fMagicScaleFactor);
 
 aLine.append(" /Matrix [ ");
 aLine.append(aMat.a());


core.git: vcl/qa vcl/source

2024-04-22 Thread Noel Grandin (via logerrit)
 vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx |   12 ++--
 vcl/source/filter/webp/reader.cxx  |4 ++--
 2 files changed, 8 insertions(+), 8 deletions(-)

New commits:
commit c503b6eef32055f75dc9cf761bd20eda4f161dd4
Author: Noel Grandin 
AuthorDate: Mon Apr 22 14:52:32 2024 +0200
Commit: Noel Grandin 
CommitDate: Mon Apr 22 21:24:17 2024 +0200

tdf#160431 Inverts webp file image when inserted

regression from
commit 81994cb2b8b32453a92bcb011830fcb884f22ff3
Author: Noel Grandin 
Date:   Fri Apr 16 20:33:10 2021 +0200
Convert internal vcl bitmap formats transparency->alpha (II)

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

diff --git a/vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx 
b/vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx
index d3c43f48191f..cbc23315ca30 100644
--- a/vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx
+++ b/vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx
@@ -141,10 +141,10 @@ void WebpFilterTest::testRoundtrip(bool lossy)
 }
 AlphaMask tmpAlpha = aResultBitmap.GetAlphaMask();
 BitmapScopedReadAccess pAccessAlpha(tmpAlpha);
-CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), pAccessAlpha->GetPixelIndex(0, 0));
-CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), pAccessAlpha->GetPixelIndex(0, 19));
-CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), pAccessAlpha->GetPixelIndex(19, 0));
-CPPUNIT_ASSERT_EQUAL(sal_uInt8(64), pAccessAlpha->GetPixelIndex(19, 
19));
+CPPUNIT_ASSERT_EQUAL(sal_uInt8(255), pAccessAlpha->GetPixelIndex(0, 
0));
+CPPUNIT_ASSERT_EQUAL(sal_uInt8(255), pAccessAlpha->GetPixelIndex(0, 
19));
+CPPUNIT_ASSERT_EQUAL(sal_uInt8(255), pAccessAlpha->GetPixelIndex(19, 
0));
+CPPUNIT_ASSERT_EQUAL(sal_uInt8(191), pAccessAlpha->GetPixelIndex(19, 
19));
 }
 
 aStream.Seek(STREAM_SEEK_TO_BEGIN);
@@ -192,8 +192,8 @@ void WebpFilterTest::testRead(std::u16string_view rName, 
bool lossy, bool alpha)
 {
 AlphaMask tmpAlpha = aResultBitmap.GetAlphaMask();
 BitmapScopedReadAccess pAccessAlpha(tmpAlpha);
-CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), pAccessAlpha->GetPixelIndex(0, 
0));
-CPPUNIT_ASSERT_EQUAL(sal_uInt8(255), 
pAccessAlpha->GetPixelIndex(0, 9));
+CPPUNIT_ASSERT_EQUAL(sal_uInt8(255), 
pAccessAlpha->GetPixelIndex(0, 0));
+CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), pAccessAlpha->GetPixelIndex(0, 
9));
 }
 }
 }
diff --git a/vcl/source/filter/webp/reader.cxx 
b/vcl/source/filter/webp/reader.cxx
index 61af0d3c0241..a5ff3aaca916 100644
--- a/vcl/source/filter/webp/reader.cxx
+++ b/vcl/source/filter/webp/reader.cxx
@@ -241,7 +241,7 @@ static bool readWebp(SvStream& stream, Graphic& graphic)
 for (tools::Long x = 0; x < access->Width(); ++x)
 {
 memcpy(dstB, src, 3);
-*dstA = 255 - *(src + 3);
+*dstA = *(src + 3);
 src += 4;
 dstB += 3;
 dstA += 1;
@@ -273,7 +273,7 @@ static bool readWebp(SvStream& stream, Graphic& graphic)
 for (tools::Long x = 0; x < accessAlpha->Width(); ++x)
 {
 sal_uInt8 a = src[3];
-accessAlpha->SetPixelIndex(y, x, 255 - a);
+accessAlpha->SetPixelIndex(y, x, a);
 src += 4;
 }
 }


core.git: vcl/qa vcl/source

2024-03-04 Thread Noel Grandin (via logerrit)
 vcl/qa/cppunit/pdfexport/data/tdf159817.fodt |  607 +++
 vcl/qa/cppunit/pdfexport/pdfexport2.cxx  |   56 ++
 vcl/source/control/button.cxx|6 
 vcl/source/control/combobox.cxx  |9 
 vcl/source/window/tabpage.cxx|5 
 5 files changed, 675 insertions(+), 8 deletions(-)

New commits:
commit b03f1dfb15a67641bc516a1c6b5632857451a18d
Author: Noel Grandin 
AuthorDate: Sun Mar 3 17:11:39 2024 +0200
Commit: Noel Grandin 
CommitDate: Mon Mar 4 09:27:07 2024 +0100

tdf#159817 tdf#159802 Form controls coordinates wrong when export to pdf

This reverts the following commits:
d408fe5cd45c9594feecec727ab2f73c66e361d0 "unnecessary LogicToPixel in 
CheckBox::Draw"
7441aaa4c5b2215e369c62e22af098184e8ce807 "unnecessary LogicToPixel in 
RadioButton::Draw"
a2dacae0c8acfad8a5e5a16c766ee740ec202c5e "unnecessary LogicToPixel in 
ComboBox::Draw"
f73e8c895e24fda10931ecf344a1a0dd8bcdf92c "unnecessary LogicToPixel in 
TabPage::Draw"

I am fairly sure this code that I am restoring is dodgy,
and I am just papering over some other bug somewhere, but
I can't seem to see where that is.

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

diff --git a/vcl/qa/cppunit/pdfexport/data/tdf159817.fodt 
b/vcl/qa/cppunit/pdfexport/data/tdf159817.fodt
new file mode 100644
index ..6aa986bdc6ad
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/tdf159817.fodt
@@ -0,0 +1,607 @@
+
+
+http://www.w3.org/TR/css3-text/"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:formx="u
 rn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:dc="http://purl.org/dc/elements/1.1/"; 
xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
 xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:ooo="http:/
 /openoffice.org/2004/office" 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ LibreOfficeDev/24.8.0.0.alpha0$MacOSX_AARCH64 
LibreOffice_project/d8978a8c4ffabd6b36a691fd3e2df685638082342003-10-02T15:57:292024-03-03T15:16:09.338790904880P124DT12H36M25S2024-02-21T10:01:49.80100Fichiers
 PDF
+ 
+  
+   0
+   0
+   20717
+   10631
+   false
+   false
+   
+
+ view2
+ 11534
+ 5101
+ 0
+ 0
+ 20715
+ 10629
+ 0
+ 1
+ false
+ 140
+ false
+ false
+ false
+ true
+ false
+ false
+
+   
+  
+  
+   0
+   true
+   false
+   false
+   false
+   true
+   false
+   true
+   false
+   
+   true
+   false
+   false
+   false
+   false
+   true
+   false
+   false
+   0
+   false
+   false
+   false
+   false
+   false
+   true
+   false
+   false
+   false
+   false
+   false
+   true
+   false
+   449756
+   true
+   true
+   true
+   false
+   false
+   false
+   false
+   false
+   false
+   false
+   true
+   true
+   false
+   false
+   true
+   false
+   20255833
+   false
+   false
+   false
+   false
+   false
+   false
+   true
+   false
+   false
+   false
+   false
+   true
+   false
+   
+   true
+   false
+   false
+   false
+   true
+   false
+   false
+  

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

2023-11-06 Thread Noel Grandin (via logerrit)
 vcl/qa/cppunit/outdev.cxx  |   38 ++
 vcl/source/outdev/gradient.cxx |   35 ++-
 2 files changed, 8 insertions(+), 65 deletions(-)

New commits:
commit ee38eea6dd2ef487a4a6014ed2a36f46946648c7
Author: Noel Grandin 
AuthorDate: Sun Nov 5 20:23:32 2023 +0200
Commit: Noel Grandin 
CommitDate: Tue Nov 7 06:10:47 2023 +0100

simplify OutputDevice::ClipAndDrawGradientMetafile

using a poly clip is better than using XOR, so make this the
default.

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

diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index 379346dd0b76..83325db08b60 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -1920,47 +1920,13 @@ static size_t ClipGradientTest(GDIMetaFile& rMtf, 
size_t nIndex)
 pAction = rMtf.GetAction(nIndex);
 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a push action", MetaActionType::PUSH, 
pAction->GetType());
 MetaPushAction* pPushAction = dynamic_cast(pAction);
-CPPUNIT_ASSERT_EQUAL_MESSAGE("Not using XOR push flags", 
vcl::PushFlags::RASTEROP,
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not using CLIPREGION push flags", 
vcl::PushFlags::CLIPREGION,
  pPushAction->GetFlags());
 
 nIndex++;
 pAction = rMtf.GetAction(nIndex);
-CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a rasterop action", 
MetaActionType::RASTEROP,
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a CLIPREGION action", 
MetaActionType::CLIPREGION,
  pAction->GetType());
-MetaRasterOpAction* pRasterOpAction = 
dynamic_cast(pAction);
-CPPUNIT_ASSERT_EQUAL_MESSAGE("Not an XOR rasterop", RasterOp::Xor,
- pRasterOpAction->GetRasterOp());
-
-nIndex++;
-pAction = rMtf.GetAction(nIndex);
-CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a gradient action", 
MetaActionType::GRADIENT,
- pAction->GetType());
-
-nIndex++;
-pAction = rMtf.GetAction(nIndex);
-CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", 
MetaActionType::FILLCOLOR,
- pAction->GetType());
-
-nIndex++;
-pAction = rMtf.GetAction(nIndex);
-CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a rasterop action", 
MetaActionType::RASTEROP,
- pAction->GetType());
-pRasterOpAction = dynamic_cast(pAction);
-CPPUNIT_ASSERT_EQUAL_MESSAGE("Not an N0 rasterop", RasterOp::N0,
- pRasterOpAction->GetRasterOp());
-
-nIndex++;
-pAction = rMtf.GetAction(nIndex);
-CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polypolygon action", 
MetaActionType::POLYPOLYGON,
- pAction->GetType());
-
-nIndex++;
-pAction = rMtf.GetAction(nIndex);
-CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a rasterop action", 
MetaActionType::RASTEROP,
- pAction->GetType());
-pRasterOpAction = dynamic_cast(pAction);
-CPPUNIT_ASSERT_EQUAL_MESSAGE("Not an XOR rasterop", RasterOp::Xor,
- pRasterOpAction->GetRasterOp());
 
 nIndex++;
 pAction = rMtf.GetAction(nIndex);
diff --git a/vcl/source/outdev/gradient.cxx b/vcl/source/outdev/gradient.cxx
index 52359a779061..d7fb11afd5d5 100644
--- a/vcl/source/outdev/gradient.cxx
+++ b/vcl/source/outdev/gradient.cxx
@@ -24,7 +24,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include 
 
@@ -156,36 +155,14 @@ void OutputDevice::DrawGradient( const 
tools::PolyPolygon& rPolyPoly,
 
 void OutputDevice::ClipAndDrawGradientMetafile ( const Gradient &rGradient, 
const tools::PolyPolygon &rPolyPoly )
 {
-const tools::Rectangle aBoundRect( rPolyPoly.GetBoundRect() );
 const bool  bOldOutput = IsOutputEnabled();
-
 EnableOutput( false );
-#if HAVE_FEATURE_SKIA
-// tdf#156539 Draw the gradient with polypolygonal clip when using Skia
-// For some unknown reason, the previous "draw gradient with XOR, draw
-// polygon with N0, and draw gradient again with XOR" does not work
-// with Skia/Raster (at least on macOS). Fortunately, Skia supports
-// polypolygonal clipping so just clip and draw the gradient.
-if ( SkiaHelper::isVCLSkiaEnabled() )
-{
-Push( vcl::PushFlags::CLIPREGION );
-SetClipRegion( vcl::Region( rPolyPoly ) );
-DrawGradient( aBoundRect, rGradient );
-Pop();
-}
-else
-#endif
-{
-Push( vcl::PushFlags::RASTEROP );
-SetRasterOp( RasterOp::Xor );
-DrawGradient( aBoundRect, rGradient );
-SetFillColor( COL_BLACK );
-SetRasterOp( RasterOp::N0 );
-DrawPolyPolygon( rPolyPoly );
-SetRasterOp( RasterOp::Xor );
-DrawGradient( aBoundRect, rGradient );
-Pop();
-}
+
+Push( vcl::PushFlags::CLIPREGION );
+

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

2023-10-24 Thread Michael Stahl (via logerrit)
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |   45 ++---
 vcl/source/gdi/pdfwriter_impl.cxx  |   35 ++---
 2 files changed, 28 insertions(+), 52 deletions(-)

New commits:
commit 049f458143cbd02ab915271418625cda1299f4b1
Author: Michael Stahl 
AuthorDate: Tue Oct 24 15:58:14 2023 +0200
Commit: Michael Stahl 
CommitDate: Tue Oct 24 18:46:50 2023 +0200

tdf#157028 vcl: PDF export: inline attribute dictionaries

There seems to be no reason why SE attribute dictionaries are separate
objects, they could just be inline, which saves a little space (1%)
and more importantly the PDF file is easier to read with less clutter.

Change-Id: Iaaea2432313c0b710edabecae32545205f4f495e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158392
Tested-by: Jenkins
Reviewed-by: Michael Stahl 

diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 8dd1a9a71fbf..70da866889aa 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -3475,11 +3475,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf149140)
 CPPUNIT_ASSERT(pAttrs != nullptr);
 for (const auto& rAttrRef : pAttrs->GetElements())
 {
-auto pARef = 
dynamic_cast(rAttrRef);
-CPPUNIT_ASSERT(pARef != nullptr);
-auto pAttr = pARef->LookupObject();
-CPPUNIT_ASSERT(pAttr != nullptr);
-auto pAttrDict = pAttr->GetDictionary();
+auto pAttrDict = 
dynamic_cast(rAttrRef);
 CPPUNIT_ASSERT(pAttrDict != nullptr);
 auto pOwner
 = 
dynamic_cast(pAttrDict->LookupElement("O"));
@@ -3841,11 +3837,8 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf135638)
 auto pS = 
dynamic_cast(pObject->Lookup("S"));
 if (pS && pS->GetValue() == "Figure")
 {
-auto pARef = 
dynamic_cast(pObject->Lookup("A"));
-CPPUNIT_ASSERT(pARef != nullptr);
-auto pAttr = pARef->LookupObject();
-CPPUNIT_ASSERT(pAttr != nullptr);
-auto pAttrDict = pAttr->GetDictionary();
+auto pAttrDict
+= 
dynamic_cast(pObject->Lookup("A"));
 CPPUNIT_ASSERT(pAttrDict != nullptr);
 auto pOwner
 = 
dynamic_cast(pAttrDict->LookupElement("O"));
@@ -4398,12 +4391,8 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testSpans)
 auto pS103101
 = 
dynamic_cast(pObject103101->Lookup("S"));
 CPPUNIT_ASSERT_EQUAL(OString("Span"), pS103101->GetValue());
-auto pA103101
-= 
dynamic_cast(pObject103101->Lookup("A"));
-CPPUNIT_ASSERT(pA103101);
-auto pObjectA103101 = pA103101->LookupObject();
-CPPUNIT_ASSERT(pObjectA103101);
-auto pDictA103101 = pObjectA103101->GetDictionary();
+auto pDictA103101
+= 
dynamic_cast(pObject103101->Lookup("A"));
 CPPUNIT_ASSERT(pDictA103101 != nullptr);
 CPPUNIT_ASSERT_EQUAL(OString("Layout"), 
dynamic_cast(
 
pDictA103101->LookupElement("O"))
@@ -4963,13 +4952,12 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf157397)
 CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType160->GetValue());
 auto pS160 = 
dynamic_cast(pObject160->Lookup("S"));
 CPPUNIT_ASSERT_EQUAL(OString("Form"), pS160->GetValue());
-auto pA160 = 
dynamic_cast(pObject160->Lookup("A"));
-CPPUNIT_ASSERT(pA160);
-auto pA160Obj = pA160->LookupObject();
-auto pA160O = 
dynamic_cast(pA160Obj->Lookup("O"));
+auto pA160Dict = 
dynamic_cast(pObject160->Lookup("A"));
+CPPUNIT_ASSERT(pA160Dict);
+auto pA160O = 
dynamic_cast(pA160Dict->LookupElement("O"));
 CPPUNIT_ASSERT(pA160O);
 CPPUNIT_ASSERT_EQUAL(OString("PrintField"), pA160O->GetValue());
-auto pA160Role = 
dynamic_cast(pA160Obj->Lookup("Role"));
+auto pA160Role = 
dynamic_cast(pA160Dict->LookupElement("Role"));
 CPPUNIT_ASSERT(pA160Role);
 CPPUNIT_ASSERT_EQUAL(OString("tv"), pA160Role->GetValue());
 
@@ -5088,13 +5076,9 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf135192)
 for (const auto& 
rAttrRef :
  
pAttrs->GetElements())
 {
-auto pARef = 
dynamic_cast<
-
vcl::filter::PDFReferenceElement*>(
+auto pAttrDict = 
dynamic_cast<
+ 

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

2023-10-12 Thread Michael Stahl (via logerrit)
 vcl/qa/cppunit/pdfexport/data/PDF_export_with_formcontrol.fodt |  174 ++
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |  257 
++
 vcl/source/gdi/pdfextoutdevdata.cxx|   20 
 3 files changed, 447 insertions(+), 4 deletions(-)

New commits:
commit 2e32aa1e9fc240c9cd9854655106d0decbd3694a
Author: Michael Stahl 
AuthorDate: Tue Oct 10 18:20:04 2023 +0200
Commit: Michael Stahl 
CommitDate: Thu Oct 12 11:06:10 2023 +0200

tdf#157397 vcl: PDF export: fix CreateControl replay

The problem is that the CreateLink and CreateControl actions are
replayed in a different order than they are recorded, because CreateLink
is a global action, and CreateControl a page action.

This means that the mCurId at the time when
PDFExtOutDevData::CreateControl() is called does not correspond to a
position in mParaIds when CreateControl is replayed; it will be inserted
too early and bump all the CreateLink ones to later indexes.

Avoid this by adding another global action CreateControlLink that is
added when CreateControl is being replayed, which appears to work.

(Another subtle problem is that, in case of PDF/A-1, the page actions
could be discarded completely; this should work in that case too.)

(regression from commit d4d471fc88fe4fd14f44dfccdfe360dec327d4f0)

Change-Id: I92d89ac08db6548e9f0d1480d984aeacb4d22262
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157767
Tested-by: Jenkins
Reviewed-by: Michael Stahl 

diff --git a/vcl/qa/cppunit/pdfexport/data/PDF_export_with_formcontrol.fodt 
b/vcl/qa/cppunit/pdfexport/data/PDF_export_with_formcontrol.fodt
new file mode 100644
index ..4aa4a92b6710
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/PDF_export_with_formcontrol.fodt
@@ -0,0 +1,174 @@
+
+http://www.w3.org/TR/css3-text/"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:dc="http://purl.org/dc/elements/1.1/"; xmlns:c
 alcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:
 meta:1.0" 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ A. 
Spielhoff2020-09-12T10:51:34.4381175712023-10-11T12:40:15.543658302PT7H23M50S98LibreOfficeDev/7.5.7.0.0$Linux_X86_64
 
LibreOffice_project/0325c0aa2d3e6df97ff554ca540d316273fd149a2023-09-23T14:07:35.317591779PDF-Dateien:
 A Spielhoff
+ 
+  
+  
+  
+  
+ 
+  
+   
+   
+
+   
+   
+  
+  
+   
+   
+  
+  
+   
+  
+  
+   
+  
+  
+  
+   
+  
+  
+  
+   
+  
+  
+   
+  
+  
+   
+  
+  
+   
+
+ 
+
+   
+   
+
+ 
+
+   
+   
+
+ 
+
+   
+   
+
+ 
+
+   
+   
+
+ 
+
+   
+   
+
+ 
+
+   
+   
+
+ 
+
+   
+   
+
+ 
+
+   
+   
+
+ 
+
+   
+   
+
+ 
+
+   
+  
+  
+  
+  
+ 
+ 
+  
+   
+  
+  
+   
+  
+  
+   
+  
+  
+   
+   
+  
+  
+   
+  
+  
+   
+  
+  
+   
+  
+  
+   
+  
+  
+   
+
+
+   
+   
+   
+  
+  
+   
+  
+ 
+ 
+  
+  
+ 
+  
+   
+
+ 
+  
+   

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

2023-09-19 Thread Patrick Luby (via logerrit)
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |3 ---
 vcl/source/gdi/pdfwriter_impl.cxx  |   10 ++
 2 files changed, 10 insertions(+), 3 deletions(-)

New commits:
commit c2d7c8e5c616980d5fa77ac48babbf27342b2f0a
Author: Patrick Luby 
AuthorDate: Tue Sep 19 16:43:46 2023 -0400
Commit: Miklos Vajna 
CommitDate: Wed Sep 20 08:14:19 2023 +0200

tdf#156842 increase scale for external PDF data

For some unknown reason, the scale is 8 times larger than for
non-external PDF XObjects.

This fix also allows the CppunitTest_vcl_pdfexport to run
successfully on macOS.

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

diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index b26176c1aa0d..a07ceeb53eae 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -5290,10 +5290,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, 
testPdfImageHyperlink)
 // - Expected: 0.0012626264
 // - Actual  : 0.00126
 // i.e. the rounded reciprocal was 794 points, not the original 792.
-// FIXME macOS actual value is 0.0001578282, for unknown reasons.
-#if !defined MACOSX
 CPPUNIT_ASSERT_EQUAL(0.0012626264, rtl::math::round(aScale.getY(), 10));
-#endif
 }
 
 CPPUNIT_TEST_FIXTURE(PdfExportTest, testURIs)
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 64dfc809fccc..8d4082b1c227 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -9125,6 +9125,16 @@ void PDFWriterImpl::writeReferenceXObject(const 
ReferenceXObjectEmit& rEmit)
 sal_Int32 nWrappedFormObject = 0;
 if (!m_aContext.UseReferenceXObject)
 {
+#ifdef MACOSX
+// tdf#156842 increase scale for external PDF data
+// For some unknown reason, the scale is 8 times larger than for
+// non-external PDF XObjects.
+// This fix also allows the CppunitTest_vcl_pdfexport to run
+// successfully on macOS.
+fScaleX = 8.0 / aSize.Width();
+fScaleY = 8.0 / aSize.Height();
+#endif
+
 // Parse the PDF data, we need that to write the PDF dictionary of our
 // object.
 if (rEmit.m_nExternalPDFDataIndex < 0)


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

2023-09-12 Thread Xisco Fauli (via logerrit)
 vcl/qa/cppunit/GraphicTest.cxx  |   12 ++
 vcl/qa/cppunit/data/tdf149545.svg   |   32 
 vcl/source/filter/GraphicFormatDetector.cxx |2 -
 3 files changed, 45 insertions(+), 1 deletion(-)

New commits:
commit fb07dcf993bd3ff7880b26414e4095560c296d8b
Author: Xisco Fauli 
AuthorDate: Tue Sep 12 14:29:21 2023 +0200
Commit: Tomaž Vajngerl 
CommitDate: Tue Sep 12 21:21:19 2023 +0200

tdf#149545: increase svg check size

otherwise it will fail to open documents like the one in
tdf#149545 with long comments before "https://gerrit.libreoffice.org/c/core/+/156844
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
index 606936c65f9e..ef9678e42197 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -1294,6 +1294,18 @@ CPPUNIT_TEST_FIXTURE(GraphicTest, testTdf156016)
 CPPUNIT_ASSERT_EQUAL(tools::Long(100 * scalingY), 
aGraphic.GetSizePixel().Height());
 }
 
+CPPUNIT_TEST_FIXTURE(GraphicTest, testTdf149545)
+{
+// Without the fix in place, this test would have failed with
+// - Expected: 0x0(Error Area:Io Class:NONE Code:0)
+// - Actual  : 0x8203(Error Area:Vcl Class:General Code:3)
+Graphic aGraphic = loadGraphic(u"tdf149545.svg");
+CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
+const auto[scalingX, scalingY] = getDPIScaling();
+CPPUNIT_ASSERT_EQUAL(tools::Long(100 * scalingX), 
aGraphic.GetSizePixel().Width());
+CPPUNIT_ASSERT_EQUAL(tools::Long(100 * scalingY), 
aGraphic.GetSizePixel().Height());
+}
+
 CPPUNIT_TEST_FIXTURE(GraphicTest, testAvailableThreaded)
 {
 Graphic jpgGraphic1 = importUnloadedGraphic(u"TypeDetectionExample.jpg");
diff --git a/vcl/qa/cppunit/data/tdf149545.svg 
b/vcl/qa/cppunit/data/tdf149545.svg
new file mode 100644
index ..39fd956142bd
--- /dev/null
+++ b/vcl/qa/cppunit/data/tdf149545.svg
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+http://www.w3.org/2000/svg"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; id="svg-root" width="100%" 
height="100%" viewBox="0 0 99 99">
+
+
+
+
diff --git a/vcl/source/filter/GraphicFormatDetector.cxx 
b/vcl/source/filter/GraphicFormatDetector.cxx
index 2cf9e953003e..38a6ec28585e 100644
--- a/vcl/source/filter/GraphicFormatDetector.cxx
+++ b/vcl/source/filter/GraphicFormatDetector.cxx
@@ -32,7 +32,7 @@
 #include 
 #include 
 
-constexpr sal_uInt32 SVG_CHECK_SIZE = 2048;
+constexpr sal_uInt32 SVG_CHECK_SIZE = 8192;
 constexpr sal_uInt32 WMF_EMF_CHECK_SIZE = 44;
 
 namespace


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

2023-08-22 Thread Khaled Hosny (via logerrit)
 vcl/qa/cppunit/svm/svmtest.cxx |4 ++--
 vcl/source/gdi/mtfxmldump.cxx  |   32 
 2 files changed, 26 insertions(+), 10 deletions(-)

New commits:
commit 77dab2ac3a4dfdc6f51fdfc31078fb828e8164fa
Author: Khaled Hosny 
AuthorDate: Thu Aug 17 17:19:09 2023 +0300
Commit: خالد حسني 
CommitDate: Tue Aug 22 10:52:58 2023 +0200

vcl: Fix dumping meta file layout flags to XML

These are bit flags, so we were always writing #, so now it does
bitwise check for the flags and while at it write the names of the flags
not the numeric values.

Change-Id: I13cae38c0e549b2da1f834a264e3a3255bfa5c5a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155793
Tested-by: Jenkins
Reviewed-by: خالد حسني 

diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx
index 5161f4cce960..d89f2f93118d 100644
--- a/vcl/qa/cppunit/svm/svmtest.cxx
+++ b/vcl/qa/cppunit/svm/svmtest.cxx
@@ -2298,11 +2298,11 @@ void SvmTest::checkLayoutMode(const GDIMetaFile& 
rMetaFile)
 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
 
 assertXPathAttrs(pDoc, "/metafile/layoutmode[1]", {
-{"textlayout", "#0004"}
+{"textlayout", "TextOriginLeft"}
 });
 
 assertXPathAttrs(pDoc, "/metafile/layoutmode[2]", {
-{"textlayout", "#0001"}
+{"textlayout", "BiDiRtl"}
 });
 }
 
diff --git a/vcl/source/gdi/mtfxmldump.cxx b/vcl/source/gdi/mtfxmldump.cxx
index 8726316324de..c26a44310774 100644
--- a/vcl/source/gdi/mtfxmldump.cxx
+++ b/vcl/source/gdi/mtfxmldump.cxx
@@ -439,17 +439,33 @@ OUString convertPixelFormatToString(vcl::PixelFormat 
ePixelFormat)
 return OUString();
 }
 
-OUString convertComplexTestLayoutFlags(vcl::text::ComplexTextLayoutFlags 
eComplexTestLayoutFlags)
+OUString convertComplexTestLayoutFlags(vcl::text::ComplexTextLayoutFlags 
nFlags)
 {
-switch(eComplexTestLayoutFlags)
+if (nFlags == vcl::text::ComplexTextLayoutFlags::Default)
+return "Default";
+
+std::vector aStrings;
+
+if (nFlags & vcl::text::ComplexTextLayoutFlags::BiDiRtl)
+aStrings.emplace_back("BiDiRtl");
+if (nFlags & vcl::text::ComplexTextLayoutFlags::BiDiStrong)
+aStrings.emplace_back("BiDiStrong");
+if (nFlags & vcl::text::ComplexTextLayoutFlags::TextOriginLeft)
+aStrings.emplace_back("TextOriginLeft");
+if (nFlags & vcl::text::ComplexTextLayoutFlags::TextOriginRight)
+aStrings.emplace_back("TextOriginRight");
+
+OUString aString;
+
+if (aStrings.empty())
+return aString;
+
+aString = aStrings[0];
+for (size_t i = 1; i < aStrings.size(); ++i)
 {
-default:
-case vcl::text::ComplexTextLayoutFlags::Default: return "#";
-case vcl::text::ComplexTextLayoutFlags::BiDiRtl: return "#0001";
-case vcl::text::ComplexTextLayoutFlags::BiDiStrong: return "#0002";
-case vcl::text::ComplexTextLayoutFlags::TextOriginLeft: return "#0004";
-case vcl::text::ComplexTextLayoutFlags::TextOriginRight: return 
"#0008";
+aString += ", " + aStrings[i];
 }
+return aString;
 }
 
 OUString convertGfxLinkTypeToString(GfxLinkType eGfxLinkType)


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

2023-07-30 Thread Mike Kaganski (via logerrit)
 vcl/qa/cppunit/pdfexport/data/wide_page1.fodt |   40 ++
 vcl/qa/cppunit/pdfexport/pdfexport.cxx|   56 ++
 vcl/source/gdi/pdfwriter_impl.cxx |8 ---
 3 files changed, 98 insertions(+), 6 deletions(-)

New commits:
commit e80e2a8dbed8a6cea71eca333564a9fa75b5cfbc
Author: Mike Kaganski 
AuthorDate: Fri Jul 28 17:55:17 2023 +0300
Commit: Mike Kaganski 
CommitDate: Sun Jul 30 20:08:04 2023 +0200

tdf#156528: Fix handling PDF page scaling factor after large pages

The map mode wasn't set when current page's user unit was 1, which meant
that it used the unchanged value from the previous page, where it could
be different.

Change-Id: Id1f1515dceac25cddc12081a86fabf8b32d633f0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155025
Tested-by: Mike Kaganski 
Reviewed-by: Mike Kaganski 

diff --git a/vcl/qa/cppunit/pdfexport/data/wide_page1.fodt 
b/vcl/qa/cppunit/pdfexport/data/wide_page1.fodt
new file mode 100644
index ..9e7390a8e22a
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/wide_page1.fodt
@@ -0,0 +1,40 @@
+
+
+http://openoffice.org/2004/office"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:dc="http://purl.org/dc/elements/1.1/"; 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:ooow="http://openoffice.org/200
 4/writer" xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
 xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; xmlns
 :css3t="http://www.w3.org/TR/css3-text/"; 
xmlns:officeooo="http://openoffice.org/2009/office"; office:version="1.3" 
office:mimetype="application/vnd.oasis.opendocument.text">
+ 
+ 
+ 
+  
+  
+   
+  
+  
+   
+  
+  
+   
+  
+  
+   
+  
+  
+   
+  
+ 
+ 
+  
+  
+ 
+ 
+  
+   
+ 
+ 
+
+   
+ 
+ 
+
+  
+ 
+
\ No newline at end of file
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index aaf3998eb99a..2ac143029c07 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -5423,6 +5423,62 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf48707_2)
 }
 }
 
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf156528)
+{
+aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+saveAsPDF(u"wide_page1.fodt");
+std::unique_ptr pPdfDocument = parsePDFExport();
+
+// The document has two pages
+CPPUNIT_ASSERT_EQUAL(2, pPdfDocument->getPageCount());
+
+// 1st page (5100 mm width x 210 mm high, UserUnit = 2)
+auto pPdfPage = pPdfDocument->openPage(0);
+CPPUNIT_ASSERT(pPdfPage);
+CPPUNIT_ASSERT_DOUBLES_EQUAL(o3tl::convert(5100.0 / 2, o3tl::Length::mm, 
o3tl::Length::pt),
+ pPdfPage->getWidth(), 1);
+CPPUNIT_ASSERT_DOUBLES_EQUAL(o3tl::convert(210.0 / 2, o3tl::Length::mm, 
o3tl::Length::pt),
+ pPdfPage->getHeight(), 1);
+
+// 1 object (rectangle 5060 mm width x 170 mm high, UserUnit = 2)
+CPPUNIT_ASSERT_EQUAL(1, pPdfPage->getObjectCount());
+auto pRect = pPdfPage->getObject(0);
+CPPUNIT_ASSERT(pRect);
+CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Path, pRect->getType());
+auto bounds = pRect->getBounds();
+CPPUNIT_ASSERT_DOUBLES_EQUAL(o3tl::convert(5060.0 / 2, o3tl::Length::mm, 
o3tl::Length::pt),
+ 

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

2023-07-11 Thread Michael Stahl (via logerrit)
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |2 +-
 vcl/source/gdi/pdfwriter_impl.cxx  |8 
 2 files changed, 5 insertions(+), 5 deletions(-)

New commits:
commit 1ae1f76caeef35a0db7705dd0c330936a77b6a8c
Author: Michael Stahl 
AuthorDate: Mon Jul 10 20:38:25 2023 +0200
Commit: Michael Stahl 
CommitDate: Tue Jul 11 12:17:07 2023 +0200

tdf#152234 vcl: Role values are lowercase

Old version 3 of PAC throws exceptions if these are capitalized;
presumably this is case sensitive, and all-lowercase unlike everything
else.

Change-Id: Ifc0cef38e333123e810376ab6a7630443d253841
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154282
Tested-by: Jenkins
Reviewed-by: Michael Stahl 

diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index f5de0480e4d4..5e26c693197d 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -4260,7 +4260,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testFormControlAnnot)
 CPPUNIT_ASSERT_EQUAL(OString("PrintField"), pO->GetValue());
 auto pRole = 
dynamic_cast(pAObj->Lookup("Role"));
 CPPUNIT_ASSERT(pRole);
-CPPUNIT_ASSERT_EQUAL(OString("Cb"), pRole->GetValue());
+CPPUNIT_ASSERT_EQUAL(OString("cb"), pRole->GetValue());
 auto pKids = 
dynamic_cast(pStructElem->Lookup("K"));
 auto nMCID(0);
 auto nRef(0);
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 75e74b4e1af9..9d957f0d113a 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -1911,10 +1911,10 @@ const char* PDFWriterImpl::getAttributeValueTag( 
PDFWriter::StructAttributeValue
 aValueStrings[ PDFWriter::Header ]  = "Header";
 aValueStrings[ PDFWriter::Footer ]  = "Footer";
 aValueStrings[ PDFWriter::Watermark ]   = "Watermark";
-aValueStrings[ PDFWriter::Rb ]  = "Rb";
-aValueStrings[ PDFWriter::Cb ]  = "Cb";
-aValueStrings[ PDFWriter::Pb ]  = "Pb";
-aValueStrings[ PDFWriter::Tv ]  = "Tv";
+aValueStrings[ PDFWriter::Rb ]  = "rb";
+aValueStrings[ PDFWriter::Cb ]  = "cb";
+aValueStrings[ PDFWriter::Pb ]  = "pb";
+aValueStrings[ PDFWriter::Tv ]  = "tv";
 aValueStrings[ PDFWriter::Disc ]= "Disc";
 aValueStrings[ PDFWriter::Circle ]  = "Circle";
 aValueStrings[ PDFWriter::Square ]  = "Square";


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

2023-07-04 Thread Xisco Fauli (via logerrit)
 vcl/qa/cppunit/GraphicTest.cxx  |  100 +---
 vcl/source/filter/graphicfilter.cxx |8 --
 2 files changed, 83 insertions(+), 25 deletions(-)

New commits:
commit cf40ee4a162da5f357793463e5707492030eb5df
Author: Xisco Fauli 
AuthorDate: Tue Jul 4 12:06:04 2023 +0200
Commit: Xisco Fauli 
CommitDate: Tue Jul 4 15:15:33 2023 +0200

CppunitTest_vcl_graphic_test: Demultiplex test code

and relax hack a bit, enabling webp based on testname is
dirty since they might change

Change-Id: Id933095701d01426d2802d6a194d6f74c07baaa9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153957
Tested-by: Jenkins
Reviewed-by: Xisco Fauli 

diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
index 2dff15f29d34..d9ba3b875486 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -50,7 +50,11 @@ public:
 
 private:
 void testUnloadedGraphic();
-void testUnloadedGraphicLoading();
+void testUnloadedGraphicLoadingPng();
+void testUnloadedGraphicLoadingGif();
+void testUnloadedGraphicLoadingJpg();
+void testUnloadedGraphicLoadingTif();
+void testUnloadedGraphicLoadingWebp();
 void testUnloadedGraphicWmf();
 void testUnloadedGraphicAlpha();
 void testUnloadedGraphicSizeUnit();
@@ -91,7 +95,11 @@ private:
 
 CPPUNIT_TEST_SUITE(GraphicTest);
 CPPUNIT_TEST(testUnloadedGraphic);
-CPPUNIT_TEST(testUnloadedGraphicLoading);
+CPPUNIT_TEST(testUnloadedGraphicLoadingPng);
+CPPUNIT_TEST(testUnloadedGraphicLoadingGif);
+CPPUNIT_TEST(testUnloadedGraphicLoadingJpg);
+CPPUNIT_TEST(testUnloadedGraphicLoadingTif);
+CPPUNIT_TEST(testUnloadedGraphicLoadingWebp);
 CPPUNIT_TEST(testUnloadedGraphicWmf);
 CPPUNIT_TEST(testUnloadedGraphicAlpha);
 CPPUNIT_TEST(testUnloadedGraphicSizeUnit);
@@ -294,25 +302,79 @@ void GraphicTest::testUnloadedGraphic()
 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
 }
 
-void GraphicTest::testUnloadedGraphicLoading()
+void GraphicTest::testUnloadedGraphicLoadingPng()
 {
-const OUString aFormats[] = { "png", "gif", "jpg", "tif", "webp" };
+Graphic aGraphic = makeUnloadedGraphic(u"png");
 
-for (OUString const& sFormat : aFormats)
-{
-Graphic aGraphic = makeUnloadedGraphic(sFormat);
-
-// check available
-CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
-CPPUNIT_ASSERT_EQUAL(tools::Long(120), 
aGraphic.GetSizePixel().Width());
-CPPUNIT_ASSERT_EQUAL(tools::Long(100), 
aGraphic.GetSizePixel().Height());
-CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
-CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0);
-CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
-
-if (sFormat != "jpg")
-CPPUNIT_ASSERT_EQUAL(true, checkBitmap(aGraphic));
-}
+// check available
+CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
+CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
+CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
+CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
+CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0);
+CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
+
+CPPUNIT_ASSERT_EQUAL(true, checkBitmap(aGraphic));
+}
+
+void GraphicTest::testUnloadedGraphicLoadingGif()
+{
+Graphic aGraphic = makeUnloadedGraphic(u"gif");
+
+// check available
+CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
+CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
+CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
+CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
+CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0);
+CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
+
+CPPUNIT_ASSERT_EQUAL(true, checkBitmap(aGraphic));
+}
+
+void GraphicTest::testUnloadedGraphicLoadingJpg()
+{
+Graphic aGraphic = makeUnloadedGraphic(u"jpg");
+
+// check available
+CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
+CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
+CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
+CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
+CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0);
+CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
+
+CPPUNIT_ASSERT_EQUAL(false, checkBitmap(aGraphic));
+}
+
+void GraphicTest::testUnloadedGraphicLoadingTif()
+{
+Graphic aGraphic = makeUnloadedGraphic(u"tif");
+
+// check available
+CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
+CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
+CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
+CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
+CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0);
+CPPUNIT_ASSER

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

2023-07-03 Thread Khaled Hosny (via logerrit)
 vcl/qa/cppunit/pdfexport/data/tdf48707-1.fodt |  290 ++
 vcl/qa/cppunit/pdfexport/data/tdf48707-2.fodt |  335 ++
 vcl/qa/cppunit/pdfexport/pdfexport.cxx|   65 +
 vcl/source/gdi/pdfwriter_impl.cxx |3 
 4 files changed, 693 insertions(+)

New commits:
commit 13c4456ca382a92b93395db367ef8edb27a349fa
Author: Khaled Hosny 
AuthorDate: Mon Jul 3 14:19:42 2023 +0300
Commit: خالد حسني 
CommitDate: Mon Jul 3 17:35:17 2023 +0200

tdf#48707: Explicitly set overline color in PDF export

Like we do with underline color, so that color does not leak from
elsewhere.

Change-Id: I3716a117a0d0a1260e47cbfed2242f401a09d7b6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153877
Tested-by: Jenkins
Reviewed-by: خالد حسني 

diff --git a/vcl/qa/cppunit/pdfexport/data/tdf48707-1.fodt 
b/vcl/qa/cppunit/pdfexport/data/tdf48707-1.fodt
new file mode 100644
index ..02286e5051c5
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/tdf48707-1.fodt
@@ -0,0 +1,290 @@
+
+
+http://www.w3.org/TR/css3-text/"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:formx="u
 rn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:dc="http://purl.org/dc/elements/1.1/"; 
xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
 xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:ooo="http:/
 /openoffice.org/2004/office" 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ Scott 
Wills2011-08-03T07:12:282023-07-03T14:56:12.773653822PT1M52S2LibreOffice/7.5.4.2$MacOSX_X86_64
 
LibreOffice_project/36ccfdc35048b057fd9854c757a8b67ec53977b6
+ 
+  
+   0
+   0
+   22666
+   10624
+   true
+   false
+   
+
+ view2
+ 10463
+ 2501
+ 0
+ 0
+ 22664
+ 10622
+ 3
+ 0
+ false
+ 167
+ false
+ false
+ true
+ true
+ false
+
+   
+  
+  
+   true
+   true
+   true
+   true
+   false
+   
+   false
+   false
+   true
+   false
+   false
+   false
+   true
+   false
+   false
+   false
+   false
+   false
+   0
+   0
+   false
+   false
+   false
+   false
+   true
+   false
+   false
+   false
+   true
+   false
+   false
+   
+   false
+   false
+   
+   true
+   false
+   false
+   false
+   false
+   false
+   true
+   true
+   false
+   false
+   false
+   false
+   false
+   false
+   false
+   false
+   false
+   
+   false
+   false
+   false
+   false
+   false
+   false
+   0
+   false
+   false
+   false
+   false
+   false
+   true
+   false
+   false
+   false
+   false
+   false
+   false
+   false
+   
+   false
+   false
+   true
+   true
+   false
+   true
+   true
+   false
+   821660
+   true
+   true
+   false
+   
+   false
+   true
+   false
+   high-resolution
+   1
+   0
+   true
+   false
+   false
+   true
+   true
+   true
+   true
+   true
+   false
+   true
+   
+   false
+   true
+   850755
+   false
+  
+ 
+ 
+  
+   http://openoffice.org/2004/office"; 
xmlns:xlink="http://www.w3.org/1999/xlink"/>
+  
+ 
+ 
+  
+  
+  
+  
+  
+ 
+ 
+  
+   
+   
+
+   
+   
+  
+  
+   
+   
+  
+  
+   
+  
+  
+   
+  
+  
+  
+   
+   
+  
+  
+   
+  
+  
+   
+  
+  
+   
+   
+  
+  
+   

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

2023-06-20 Thread Khaled Hosny (via logerrit)
 vcl/qa/cppunit/complextext.cxx   |   52 +++
 vcl/qa/cppunit/data/tdf107718.otf|binary
 vcl/qa/cppunit/data/tdf107718.otf.readme |   11 ++
 vcl/source/gdi/CommonSalLayout.cxx   |2 -
 4 files changed, 64 insertions(+), 1 deletion(-)

New commits:
commit 1afc13b0b84353109827d78807836c01f030ab66
Author: Khaled Hosny 
AuthorDate: Tue Jun 20 10:17:49 2023 +0300
Commit: خالد حسني 
CommitDate: Tue Jun 20 14:20:23 2023 +0200

tdf#107718: Fix script itemization of vertical text

Mixed script vertical text was not correctly splitting runs at script
changes, resulting in Hangul text being mixed with Han text in the same
run breaking the Hangul composition.

Change-Id: I09c3f799bede6aa8a19684779d500504a9813af7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153313
Tested-by: Jenkins
Reviewed-by: خالد حسني 

diff --git a/vcl/qa/cppunit/complextext.cxx b/vcl/qa/cppunit/complextext.cxx
index 631a24379a7f..bcf96cb4f99b 100644
--- a/vcl/qa/cppunit/complextext.cxx
+++ b/vcl/qa/cppunit/complextext.cxx
@@ -479,4 +479,56 @@ CPPUNIT_TEST_FIXTURE(VclComplexTextTest, testTdf153440)
 #endif
 }
 
+CPPUNIT_TEST_FIXTURE(VclComplexTextTest, testTdf107718)
+{
+#if !defined _WIN32 // TODO: Fails on jenkins but passes locally
+vcl::Font aFont(u"Source Han Sans", u"Regular", Size(0, 72));
+
+ScopedVclPtrInstance pOutDev;
+
+bool bAdded = addFont(pOutDev, u"tdf107718.otf", u"Source Han Sans");
+CPPUNIT_ASSERT_EQUAL(true, bAdded);
+
+OUString aText(u"\u4E16\u1109\u1168\u11BC\u302E");
+for (bool bVertical : { false, true })
+{
+aFont.SetVertical(bVertical);
+pOutDev->SetFont(aFont);
+
+auto pLayout = pOutDev->ImplLayout(aText, 0, -1, Point(0, 0), 0, {}, 
{});
+
+int nStart = 0;
+DevicePoint aPos;
+const GlyphItem* pGlyphItem;
+while (pLayout->GetNextGlyph(&pGlyphItem, aPos, nStart))
+{
+// Check that we found a font for all characters, a zero glyph ID
+// means no font was found so the rest of the test would be
+// meaningless.
+CPPUNIT_ASSERT(pGlyphItem->glyphId());
+
+// Assert that we are indeed doing vertical layout for vertical
+// font since the bug does not happen for horizontal text.
+CPPUNIT_ASSERT_EQUAL(bVertical, pGlyphItem->IsVertical());
+
+// For the second glyph, assert that it is a composition of 
characters 1 to 4
+// Without the fix this fails with:
+// - Expected: 4
+// - Actual  : 1
+if (nStart == 2)
+{
+CPPUNIT_ASSERT_EQUAL(1, pGlyphItem->charPos());
+CPPUNIT_ASSERT_EQUAL(4, pGlyphItem->charCount());
+}
+}
+
+// Assert there are only three glyphs
+// Without the fix this fails with:
+// - Expected: 3
+// - Actual  : 5
+CPPUNIT_ASSERT_EQUAL(3, nStart);
+}
+#endif
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qa/cppunit/data/tdf107718.otf 
b/vcl/qa/cppunit/data/tdf107718.otf
new file mode 100644
index ..b892a29a886a
Binary files /dev/null and b/vcl/qa/cppunit/data/tdf107718.otf differ
diff --git a/vcl/qa/cppunit/data/tdf107718.otf.readme 
b/vcl/qa/cppunit/data/tdf107718.otf.readme
new file mode 100644
index ..b3f740ef58ad
--- /dev/null
+++ b/vcl/qa/cppunit/data/tdf107718.otf.readme
@@ -0,0 +1,11 @@
+This is a subset copy of Source Han Sans font licensed under Open Font License 
and
+obtained from (the Static Super OTC):
+
+  https://github.com/adobe-fonts/source-han-sans/releases/tag/2.004R
+
+And subset using hb-subset to contain only the one glyph used in the test:
+
+  hb-subset SourceHanSans.ttc --face-index=25 
--unicodes="u4E16,u1109,u1168,u11BC,u302E,uC185,u0020" -o tdf107718.otf
+
+U+C185 is not directly used in the test but we need its glyphs. The space is
+added to the subset as it seems needed to get the font to work on Windows.
diff --git a/vcl/source/gdi/CommonSalLayout.cxx 
b/vcl/source/gdi/CommonSalLayout.cxx
index 907197c70c5e..7ea3ba687485 100644
--- a/vcl/source/gdi/CommonSalLayout.cxx
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -391,7 +391,7 @@ bool 
GenericSalLayout::LayoutText(vcl::text::ImplLayoutArgs& rArgs, const SalLay
 aDirection = bRightToLeft ? HB_DIRECTION_RTL : 
HB_DIRECTION_LTR;
 }
 
-if (aSubRuns.empty() || aSubRuns.back().maDirection != 
aDirection)
+if (aSubRuns.empty() || aSubRuns.back().maDirection != 
aDirection || aSubRuns.back().maScript != aScript)
 aSubRuns.push_back({ nPrevIdx, nIdx, aScript, 
aDirection });
 else
 aSubRuns.back().mnEnd = nIdx;


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

2023-05-25 Thread Khaled Hosny (via logerrit)
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |8 
 vcl/source/gdi/CommonSalLayout.cxx |2 +-
 vcl/source/gdi/sallayout.cxx   |   13 ++---
 3 files changed, 7 insertions(+), 16 deletions(-)

New commits:
commit 43a5400063b17ed4ba4cbb38bdf5da4a991f60e2
Author: Khaled Hosny 
AuthorDate: Thu May 25 10:59:18 2023 +0300
Commit: خالد حسني 
CommitDate: Thu May 25 14:18:07 2023 +0200

tdf#152048: Fix underline width for Kashida-justified text

Fix GenericSalLayout::GetTextWidth() again, this time doing away with
using linearPos as it is wrong, the glyph’s position is not directly
related to how much it contributes to the text width (for example,
combining marks have zero advance width yet their position is different
from the base glyph they apply too). This is a followup to:

commit ce7c1c608fa99c86c8f2380cd8b82d02123f514e
Author: Khaled Hosny 
Date:   Wed Aug 31 07:07:54 2022 +0200

vcl: Fix GenericSalLayout::GetTextWidth()

Additionally, inserted Kashida should have its origWidth and newWidth
both set to zero, since it does not add to the text width, all
additional width is already added to the glyph the Kashida is applied
to.

With both fixes, the text width of Kashida-justified lines is correctly
calculated and the underline no longer extends beyond the text line.

Fix test expectation now we are reporting the real text width.

Change-Id: I0de93f955929cf3030cf420cb4f4e94df974fb79
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152267
Tested-by: Jenkins
Reviewed-by: خالد حسني 

diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 4bdc920b3574..bf2ca137646f 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -777,15 +777,15 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf108963)
 pSegment = pPdfPageObject->getPathSegment(1);
 CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFSegmentType::Lineto, 
pSegment->getType());
 aPoint = pSegment->getPoint();
-CPPUNIT_ASSERT_DOUBLES_EQUAL(275.074, aPoint.getX(), 0.0005);
-CPPUNIT_ASSERT_DOUBLES_EQUAL(267.590, aPoint.getY(), 0.0005);
+CPPUNIT_ASSERT_DOUBLES_EQUAL(275.216, aPoint.getX(), 0.0005);
+CPPUNIT_ASSERT_DOUBLES_EQUAL(267.732, aPoint.getY(), 0.0005);
 CPPUNIT_ASSERT(!pSegment->isClosed());
 
 pSegment = pPdfPageObject->getPathSegment(2);
 CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFSegmentType::Lineto, 
pSegment->getType());
 aPoint = pSegment->getPoint();
-CPPUNIT_ASSERT_DOUBLES_EQUAL(287.490, aPoint.getX(), 0.0005);
-CPPUNIT_ASSERT_DOUBLES_EQUAL(251.801, aPoint.getY(), 0.0005);
+CPPUNIT_ASSERT_DOUBLES_EQUAL(287.660, aPoint.getX(), 0.0005);
+CPPUNIT_ASSERT_DOUBLES_EQUAL(251.914, aPoint.getY(), 0.0005);
 CPPUNIT_ASSERT(!pSegment->isClosed());
 
 pSegment = pPdfPageObject->getPathSegment(3);
diff --git a/vcl/source/gdi/CommonSalLayout.cxx 
b/vcl/source/gdi/CommonSalLayout.cxx
index 0c6043a91869..907197c70c5e 100644
--- a/vcl/source/gdi/CommonSalLayout.cxx
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -834,7 +834,7 @@ void GenericSalLayout::ApplyDXArray(const double* pDXArray, 
const sal_Bool* pKas
 aPos.adjustX(-nClusterWidth + pGlyphIter->origWidth());
 while (nCopies--)
 {
-GlyphItem aKashida(nCharPos, 0, nKashidaIndex, aPos, nFlags, 
nKashidaWidth, 0, 0);
+GlyphItem aKashida(nCharPos, 0, nKashidaIndex, aPos, nFlags, 0, 0, 
0);
 pGlyphIter = m_GlyphItems.insert(pGlyphIter, aKashida);
 aPos.adjustX(nKashidaWidth - nOverlap);
 ++pGlyphIter;
diff --git a/vcl/source/gdi/sallayout.cxx b/vcl/source/gdi/sallayout.cxx
index 85ad838615d9..1ed2a37ad71b 100644
--- a/vcl/source/gdi/sallayout.cxx
+++ b/vcl/source/gdi/sallayout.cxx
@@ -269,19 +269,10 @@ DeviceCoordinate GenericSalLayout::GetTextWidth() const
 if (!m_GlyphItems.IsValid())
 return 0;
 
-// initialize the extent
-DeviceCoordinate nMinPos = 0;
-DeviceCoordinate nMaxPos = 0;
-
+DeviceCoordinate nWidth = 0;
 for (auto const& aGlyphItem : m_GlyphItems)
-{
-// update the text extent with the glyph extent
-DeviceCoordinate nXPos = aGlyphItem.linearPos().getX() - 
aGlyphItem.xOffset();
-nMinPos = std::min(nMinPos, nXPos);
-nMaxPos = std::max(nMaxPos, nXPos + aGlyphItem.newWidth());
-}
+nWidth += aGlyphItem.newWidth();
 
-DeviceCoordinate nWidth = nMaxPos - nMinPos;
 return nWidth;
 }
 


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

2023-03-30 Thread Noel Grandin (via logerrit)
 vcl/qa/cppunit/BitmapTest.cxx  |   10 
 vcl/source/app/svmain.cxx  |   14 
 vcl/source/control/field.cxx   |9 
 vcl/source/control/fmtfield.cxx|   26 -
 vcl/source/control/throbber.cxx|   12 
 vcl/source/filter/ipdf/pdfdocument.cxx |   40 +-
 vcl/source/gdi/mtfxmldump.cxx  |5 
 vcl/source/gdi/pdfobjectcopier.cxx |8 
 vcl/source/gdi/pdfwriter_impl.cxx  |  530 +++--
 vcl/source/gdi/print3.cxx  |3 
 vcl/source/treelist/headbar.cxx|3 
 vcl/source/treelist/imap2.cxx  |3 
 vcl/source/treelist/transfer.cxx   |   10 
 vcl/source/window/printdlg.cxx |7 
 vcl/unx/generic/fontmanager/helper.cxx |7 
 vcl/unx/generic/print/glyphset.cxx |6 
 vcl/unx/generic/print/printerjob.cxx   |   38 +-
 vcl/unx/generic/printer/jobdata.cxx|   55 +--
 vcl/unx/generic/printer/ppdparser.cxx  |   18 -
 vcl/unx/gtk3/gtkinst.cxx   |6 
 20 files changed, 359 insertions(+), 451 deletions(-)

New commits:
commit a5084d15e1b72e303e1628fbff84432036b014a9
Author: Noel Grandin 
AuthorDate: Thu Mar 30 10:42:07 2023 +0200
Commit: Noel Grandin 
CommitDate: Thu Mar 30 13:36:59 2023 +

loplugin:stringadd in vcl

when applying my upcoming patch to also consider O[U]StringBuffer

Change-Id: I44ce7183e4b292269fac1e3d2217286bf5abe823
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149752
Tested-by: Noel Grandin 
Reviewed-by: Noel Grandin 

diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx
index 98fabd569f24..dfcf44a8f6a7 100644
--- a/vcl/qa/cppunit/BitmapTest.cxx
+++ b/vcl/qa/cppunit/BitmapTest.cxx
@@ -330,13 +330,9 @@ void checkAndInsert(CRCHash& rHash, sal_uInt64 nCRC, const 
char* pLocation)
 auto it = rHash.find(nCRC);
 if (it != rHash.end())
 {
-OStringBuffer aBuf("CRC collision between ");
-aBuf.append(pLocation);
-aBuf.append(" and ");
-aBuf.append(it->second);
-aBuf.append(" hash is 0x");
-aBuf.append(static_cast(nCRC), 16);
-CPPUNIT_FAIL(aBuf.toString().getStr());
+OString aBuf = OString::Concat("CRC collision between ") + pLocation + 
" and " + it->second
+   + " hash is 0x" + 
OString::number(static_cast(nCRC), 16);
+CPPUNIT_FAIL(aBuf.getStr());
 }
 rHash[nCRC] = pLocation;
 }
diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx
index 571be29579bc..ab461912724f 100644
--- a/vcl/source/app/svmain.cxx
+++ b/vcl/source/app/svmain.cxx
@@ -456,13 +456,13 @@ void DeInitVCL()
 nBadTopWindows--;
 else
 {
-aBuf.append( "text = \"" );
-aBuf.append( OUStringToOString( pWin->GetText(), 
osl_getThreadTextEncoding() ) );
-aBuf.append( "\" type = \"" );
-aBuf.append( typeid(*pWin).name() );
-aBuf.append( "\", ptr = 0x" );
-aBuf.append( reinterpret_cast( pWin ), 16 );
-aBuf.append( "\n" );
+aBuf.append( "text = \""
++ OUStringToOString( pWin->GetText(), 
osl_getThreadTextEncoding() )
++ "\" type = \""
++ typeid(*pWin).name()
++ "\", ptr = 0x"
++ OString::number(reinterpret_cast( pWin ), 16 )
++ "\n" );
 }
 }
 SAL_WARN_IF( nBadTopWindows!=0, "vcl", aBuf.getStr() );
diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx
index 0bd9ebab713e..3de0eaf50165 100644
--- a/vcl/source/control/field.cxx
+++ b/vcl/source/control/field.cxx
@@ -314,8 +314,7 @@ bool ImplNumericGetValue( const OUString& rStr, sal_Int64& 
rValue,
 sal_Int64 nDenom = o3tl::toInt64(aStrDenom);
 if (nDenom == 0) return false; // Division by zero
 double nFrac2Dec = nWholeNum + static_cast(nNum)/nDenom; // 
Convert to double for floating point precision
-OUStringBuffer aStrFrac;
-aStrFrac.append(nFrac2Dec);
+OUStringBuffer aStrFrac(OUString::number(nFrac2Dec));
 // Reconvert division result to string and parse
 nDecPos = aStrFrac.indexOf('.');
 if ( nDecPos >= 0)
@@ -383,14 +382,12 @@ void ImplUpdateSeparatorString( OUString& io_rText,
|| (nIndexTh != -1 && nIndexDec == -1)
)
 {
-aBuf.append( pBuffer + nIndex, nIndexTh - nIndex );
-aBuf.append( rNewThSep );
+aBuf.append( OUString::Concat(std::u16string_view(pBuffer + 
nIndex, nIndexTh - nIndex )) + rNewThSep );
 nIndex = nIndexTh + rOldThSep.size();
 }
 else if( nIndexDec != -1 )
 {
-aBuf.append( pBuffer + nIndex, nIndexDec - nIndex );
-aBuf.append( rNewDecSep );
+aBuf.append( OUString::Concat(std::u16string_view(pBuffer + 
nIndex, nIndexDec - nIndex )) + rNewDecSep );
 nIndex = nIndexDec + rOldDec

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

2023-03-22 Thread Michael Stahl (via logerrit)
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |   12 +++--
 vcl/source/gdi/pdfwriter_impl.cxx  |   42 +
 2 files changed, 42 insertions(+), 12 deletions(-)

New commits:
commit d41c3c820dad7c78bc57815e0f4a6999d125561d
Author: Michael Stahl 
AuthorDate: Mon Mar 20 20:40:13 2023 +0100
Commit: Michael Stahl 
CommitDate: Wed Mar 22 11:55:55 2023 +

vcl: PDF/UA export: produce UF and Desc for embedded files

  7.11 Embedded files
  The file specification dictionary for an embedded file shall contain
  the F and UF keys and should contain the Desc key (ISO 32000-1:2008,
  7.11.3, Table 44.).

Also write Alt text as hex/unicode string, not literal string.

Change-Id: Id83597cc5ea645bd57c110514bafede433aee572
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149259
Tested-by: Jenkins
Reviewed-by: Michael Stahl 

diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 4304846c9834..448ba4ba24ed 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -3610,13 +3610,19 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testMediaShapeAnnot)
 CPPUNIT_ASSERT(pR);
 auto pC = 
dynamic_cast(pR->LookupElement("C"));
 CPPUNIT_ASSERT(pC);
+auto pD = 
dynamic_cast(pC->LookupElement("D"));
+CPPUNIT_ASSERT(pD);
+auto pDesc = 
dynamic_cast(pD->LookupElement("Desc"));
+CPPUNIT_ASSERT(pDesc);
+CPPUNIT_ASSERT_EQUAL(OUString("alternativloser text\nand some 
description"),
+ 
::vcl::filter::PDFDocument::DecodeHexStringUTF16BE(*pDesc));
 auto pAlt = 
dynamic_cast(pC->LookupElement("Alt"));
 CPPUNIT_ASSERT(pAlt);
 auto pLang = 
dynamic_cast(pAlt->GetElement(0));
 CPPUNIT_ASSERT_EQUAL(OString(""), pLang->GetValue());
-auto pAltText = 
dynamic_cast(pAlt->GetElement(1));
-CPPUNIT_ASSERT_EQUAL(OString("alternativloser text\\nand some 
description"),
- pAltText->GetValue());
+auto pAltText = 
dynamic_cast(pAlt->GetElement(1));
+CPPUNIT_ASSERT_EQUAL(OUString("alternativloser text\nand some 
description"),
+ 
::vcl::filter::PDFDocument::DecodeHexStringUTF16BE(*pAltText));
 
 auto pStructParent
 = 
dynamic_cast(pAnnot->Lookup("StructParent"));
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index f6776c1d560b..3fe6430fc000 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -3607,17 +3607,33 @@ bool PDFWriterImpl::emitScreenAnnotations()
 aLine.append("/C<) /EF << /F 
");
+aLine.append("\n/D << /Type /Filespec /F () ");
+if (PDFWriter::PDFVersion::PDF_1_7 <= m_aContext.Version)
+{   // ISO 14289-1:2014, Clause: 7.11
+aLine.append("/UF () ");
+}
+aLine.append("/EF << /F ");
 aLine.append(rScreen.m_nTempFileObject);
-aLine.append(" 0 R >> >>");
+aLine.append(" 0 R >>");
 }
 else
 {
 // Linked.
-aLine.append("/D << /Type /Filespec /FS /URL /F ");
+aLine.append("\n/D << /Type /Filespec /FS /URL /F ");
 appendLiteralStringEncrypt(rScreen.m_aURL, rScreen.m_nObject, 
aLine, osl_getThreadTextEncoding());
-aLine.append(" >>");
+if (PDFWriter::PDFVersion::PDF_1_7 <= m_aContext.Version)
+{   // ISO 14289-1:2014, Clause: 7.11
+aLine.append("/UF ");
+appendUnicodeTextStringEncrypt(rScreen.m_aURL, 
rScreen.m_nObject, aLine);
+}
+}
+if (PDFWriter::PDFVersion::PDF_1_6 <= m_aContext.Version
+&& !rScreen.m_AltText.isEmpty())
+{   // ISO 14289-1:2014, Clause: 7.11
+aLine.append("/Desc ");
+appendUnicodeTextStringEncrypt(rScreen.m_AltText, 
rScreen.m_nObject, aLine);
 }
+aLine.append(" >>\n"); // end of /D
 // Allow playing the video via a tempfile.
 aLine.append("/P <>");
 // ISO 14289-1:2014, Clause: 7.18.6.2
@@ -3626,7 +3642,7 @@ bool PDFWriterImpl::emitScreenAnnotations()
 // ISO 14289-1:2014, Clause: 7.18.6.2
 // Alt text is a "Multi-language Text Array"
 aLine.append(" /Alt [ () ");
-appendLiteralStringEncrypt(rScreen.m_AltText, rScreen.m_nObject, 
aLine, osl_getThreadTextEncoding());
+appendUnicodeTextStringEncrypt(rScreen.m_AltText, rScreen.m_nObject, 
aLine);
 aLine.append(" ] ");
 aLine.append(">>");
 
@@ -5207,9 +5223,12 @@ bool PDFWriterImpl::emitCatalog()
 aLine.append("/F<");
 PDFWriter::AppendUnicodeTextString(rAttachedFile.maFilename, aLine);
 aLine.append("> ");
-aLine.append("/UF<");
-PDFWriter::AppendUnicodeTextString(rAttachedFile.maFilename, aLine);
-aLine.append("> ");
+if (PD

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

2023-03-07 Thread Jaume Pujantell (via logerrit)
 vcl/qa/cppunit/filter/ipdf/data/array-mixed-numbers-and-elements.pdf |   55 
++
 vcl/qa/cppunit/filter/ipdf/ipdf.cxx  |   25 

 vcl/source/filter/ipdf/pdfdocument.cxx   |   45 

 3 files changed, 125 insertions(+)

New commits:
commit 574e89ccda1b389faca9f3e44d909a71b5599473
Author: Jaume Pujantell 
AuthorDate: Fri Mar 3 19:25:11 2023 +0100
Commit: Andras Timar 
CommitDate: Tue Mar 7 08:36:01 2023 +

Fix a bug parsing pdf arrays

The parser ignored number elements in some situations, like before
a reference element. This manifested in creating an invalid pdf
file when exporting as pdf a document that contains a pdf.

Change-Id: I98625c8da8631056079814f7e824f36177cf41c7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148198
Tested-by: Jenkins
Reviewed-by: Andras Timar 

diff --git 
a/vcl/qa/cppunit/filter/ipdf/data/array-mixed-numbers-and-elements.pdf 
b/vcl/qa/cppunit/filter/ipdf/data/array-mixed-numbers-and-elements.pdf
new file mode 100644
index ..01030ecf88bc
--- /dev/null
+++ b/vcl/qa/cppunit/filter/ipdf/data/array-mixed-numbers-and-elements.pdf
@@ -0,0 +1,55 @@
+%PDF-1.7
+%���
+1 0 obj <<
+  /Type /Catalog
+  /Pages 2 0 R
+>>
+endobj
+2 0 obj <<
+  /Type /Pages
+  /MediaBox [0 0 200 300]
+  /Count 1
+  /Kids [3 0 R]
+>>
+endobj
+3 0 obj <<
+  /Type /Page
+  /Parent 2 0 R
+  /Contents 4 0 R
+  /Test [1 4 0 R 3 false 5 (Lieral) 7 <90>]
+>>
+endobj
+4 0 obj <<
+  /Length 188
+>>
+stream
+q
+0 0 0 rg
+0 290 10 10 re B*
+10 150 50 30 re B*
+0 0 1 rg
+190 290 10 10 re B*
+70 232 50 30 re B*
+0 1 0 rg
+190 0 10 10 re B*
+130 150 50 30 re B*
+1 0 0 rg
+0 0 10 10 re B*
+70 67 50 30 re B*
+Q
+endstream
+endobj
+xref
+0 5
+00 65535 f 
+15 0 n 
+68 0 n 
+000157 0 n 
+000270 0 n 
+trailer <<
+  /Root 1 0 R
+  /Size 5
+>>
+startxref
+510
+%%EOF
diff --git a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx 
b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
index 1c143a1b8319..c27555ca1d70 100644
--- a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
+++ b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
@@ -186,6 +186,31 @@ CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, testCommentEnd)
 CPPUNIT_ASSERT(aDocument.Read(aFile));
 }
 
+CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, testMixedArrayWithNumbers)
+{
+// Load a file that has markup like this:
+// 3 0 obj <<
+//  /Test [1 4 0 R 3 false 5 (Lieral) 7 <90>]
+// >>
+OUString aSourceURL = 
createFileURL(u"array-mixed-numbers-and-elements.pdf");
+SvFileStream aFile(aSourceURL, StreamMode::READ);
+vcl::filter::PDFDocument aDocument;
+CPPUNIT_ASSERT(aDocument.Read(aFile));
+std::vector aPages = aDocument.GetPages();
+CPPUNIT_ASSERT(!aPages.empty());
+vcl::filter::PDFObjectElement* pPage = aPages[0];
+auto pTest = 
dynamic_cast(pPage->Lookup("Test"));
+std::vector aElements = pTest->GetElements();
+
+// Without the accompanying fix in place, this test would have failed with
+// the array containing the wrong number of elements and in the incorrect 
order
+CPPUNIT_ASSERT_EQUAL(8, static_cast(aElements.size()));
+CPPUNIT_ASSERT(dynamic_cast(aElements[0]));
+CPPUNIT_ASSERT(dynamic_cast(aElements[2]));
+CPPUNIT_ASSERT(dynamic_cast(aElements[4]));
+CPPUNIT_ASSERT(dynamic_cast(aElements[6]));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/filter/ipdf/pdfdocument.cxx 
b/vcl/source/filter/ipdf/pdfdocument.cxx
index 19748e241ead..5ff50d3b55ac 100644
--- a/vcl/source/filter/ipdf/pdfdocument.cxx
+++ b/vcl/source/filter/ipdf/pdfdocument.cxx
@@ -3248,6 +3248,18 @@ size_t PDFObjectParser::parse(PDFElement* 
pParsingElement, size_t nStartIndex, i
 }
 else if (auto pReference = 
dynamic_cast(pCurrentElement))
 {
+// Handle previously stored number
+if (aNumbers.size() > 2)
+{
+aNumbers.resize(aNumbers.size() - 2);
+if (pParsingArray)
+{
+for (auto& pNumber : aNumbers)
+pParsingArray->PushBack(pNumber);
+}
+aNumbers.clear();
+}
+
 if (pParsingArray)
 {
 pParsingArray->PushBack(pReference);
@@ -3268,6 +3280,17 @@ size_t PDFObjectParser::parse(PDFElement* 
pParsingElement, size_t nStartIndex, i
 }
 else if (auto pLiteralString = 
dynamic_cast(pCurrentElement))
 {
+// Handle previously stored number
+if (!aNumbers.empty())
+{
+if (pParsingArray)
+{
+for (auto& pNumber : aNumbers)
+pParsingArray->PushBack(pNumber);
+}
+aNumbers.clear();
+}
+
 if (pParsingArray)
 {
 

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

2023-03-05 Thread Sarper Akdemir (via logerrit)
 vcl/qa/cppunit/png/PngFilterTest.cxx |   53 +++
 vcl/source/filter/png/PngImageWriter.cxx |   35 +++-
 2 files changed, 79 insertions(+), 9 deletions(-)

New commits:
commit c010b8cc712d1336ed79fb220764f1a850dc22e5
Author: Sarper Akdemir 
AuthorDate: Wed Jan 25 15:36:59 2023 +0300
Commit: Tomaž Vajngerl 
CommitDate: Sun Mar 5 10:55:44 2023 +

tdf#153180: PngImageWriter add support for gray alpha colortype

8 bit grayscale images can have alpha accompanying it, and
PNG supports 2 channel gray-alpha images.

libpng supports this with the use of colortype
PNG_COLOR_TYPE_GRAY_ALPHA.

This patch adds support for writing GRAY_ALPHA colorType PNG
images.

This is done by expanding what was in place for
ScanlineFormat::N24BitTcRgb with alpha PNG_COLOR_TYPE_RGBA.

Change-Id: I80d462d784f91529eb9371c6bdb029c78f32f81e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146138
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/png/PngFilterTest.cxx 
b/vcl/qa/cppunit/png/PngFilterTest.cxx
index dae007eb7898..fc3963c356e8 100644
--- a/vcl/qa/cppunit/png/PngFilterTest.cxx
+++ b/vcl/qa/cppunit/png/PngFilterTest.cxx
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -176,6 +177,7 @@ public:
 void testPngRoundtrip24_8();
 void testPngRoundtrip32();
 void testPngWrite8BitRGBPalette();
+void testTdf153180MonochromeFilterPngExport();
 void testDump();
 
 CPPUNIT_TEST_SUITE(PngFilterTest);
@@ -188,6 +190,7 @@ public:
 CPPUNIT_TEST(testPngRoundtrip32);
 CPPUNIT_TEST(testPngWrite8BitRGBPalette);
 CPPUNIT_TEST(testDump);
+CPPUNIT_TEST(testTdf153180MonochromeFilterPngExport);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -1958,6 +1961,56 @@ void PngFilterTest::testPngWrite8BitRGBPalette()
 }
 }
 
+void PngFilterTest::testTdf153180MonochromeFilterPngExport()
+{
+GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
+
+Graphic aGraphicOriginal;
+{
+// 3 * 16 bits rgb color alpha, no background chunk
+const OUString aURL(getFullUrl(u"bgan6a16.png"));
+SvFileStream aFileStream(aURL, StreamMode::READ);
+ErrCode aResult = rFilter.ImportGraphic(aGraphicOriginal, aURL, 
aFileStream);
+CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, aResult);
+CPPUNIT_ASSERT(aGraphicOriginal.IsAlpha());
+}
+
+// Apply the monochrome filter to the graphic but keep the alpha.
+BitmapEx aBitmapEx(aGraphicOriginal.GetBitmapEx());
+AlphaMask aAlphaMask(aBitmapEx.GetAlphaMask());
+
+BitmapEx aTmpBmpEx(aBitmapEx.GetBitmap());
+BitmapFilter::Filter(aTmpBmpEx, BitmapMonochromeFilter{ sal_uInt8{ 127 } 
});
+
+Graphic aGraphicAfterFilter{ BitmapEx(aTmpBmpEx.GetBitmap(), aAlphaMask) };
+CPPUNIT_ASSERT(aGraphicAfterFilter.IsAlpha());
+
+// export the resulting graphic
+utl::TempFileNamed aTempFile(u"testPngExportTdf153180", true, u".png");
+if (!bKeepTemp)
+aTempFile.EnableKillingFile();
+{
+SvStream& rStream = *aTempFile.GetStream(StreamMode::WRITE);
+vcl::PngImageWriter aPngWriter(rStream);
+bool bWriteSuccess = 
aPngWriter.write(aGraphicAfterFilter.GetBitmapEx());
+CPPUNIT_ASSERT_EQUAL(true, bWriteSuccess);
+aTempFile.CloseStream();
+}
+{
+SvStream& rStream = *aTempFile.GetStream(StreamMode::READ);
+rStream.Seek(0);
+// Import the png and check that it still has alpha
+Graphic aGraphic;
+ErrCode aResult = rFilter.ImportGraphic(aGraphic, aTempFile.GetURL(), 
rStream);
+CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, aResult);
+
+// Without the accompanying patch would fail with:
+// assertion failed
+// -Expression : aGraphic.IsAlpha()
+CPPUNIT_ASSERT(aGraphic.IsAlpha());
+}
+}
+
 void PngFilterTest::testDump()
 {
 utl::TempFileNamed aTempFile;
diff --git a/vcl/source/filter/png/PngImageWriter.cxx 
b/vcl/source/filter/png/PngImageWriter.cxx
index 35ccefaec2c7..914302223d6a 100644
--- a/vcl/source/filter/png/PngImageWriter.cxx
+++ b/vcl/source/filter/png/PngImageWriter.cxx
@@ -15,15 +15,25 @@
 
 namespace
 {
-void combineScanlineChannels(Scanline pRGBScanline, Scanline pAlphaScanline,
+void combineScanlineChannels(Scanline pColorScanline, Scanline pAlphaScanline,
  std::vector>& 
pResult,
- sal_uInt32 nBitmapWidth)
+ sal_uInt32 nBitmapWidth, int colorType)
 {
+if (colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
+{
+for (sal_uInt32 i = 0; i < nBitmapWidth; ++i)
+{
+pResult[i * 2] = *pColorScanline++; // Gray
+pResult[i * 2 + 1] = *pAlphaScanline++; // A
+}
+return;
+}
+
 for (sal_uInt32 i = 0; i < nBitmapWidth; ++i)
 {
-pResult[i * 4] = *pRGBSca

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

2023-01-15 Thread Tomaž Vajngerl (via logerrit)
 vcl/qa/cppunit/svm/svmtest.cxx |   36 ++---
 vcl/source/gdi/mtfxmldump.cxx  |   70 +
 2 files changed, 89 insertions(+), 17 deletions(-)

New commits:
commit 28edd79792a4b0ae7665a23bfbebb9499416daef
Author: Tomaž Vajngerl 
AuthorDate: Sat Jan 14 16:45:15 2023 +0900
Commit: Tomaž Vajngerl 
CommitDate: Sun Jan 15 08:07:41 2023 +

vcl: add more device independent checks for bitmaps in svmtest

Adds writing of "contentchecksum" to MetafileXmlDump, which sums
the content of all the colors in an device independent way, by
reading the each pixel color from the bitmap and summing each
component always in RGBA order.

In addition add some others bitmap attributes not checked before,
like bitmap width, height and pixel format.

Change-Id: I3bb5f7f6342766df235af71a4682a5d3ce17ab44
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145500
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx
index 02cec9bcfd45..e8925ffda064 100644
--- a/vcl/qa/cppunit/svm/svmtest.cxx
+++ b/vcl/qa/cppunit/svm/svmtest.cxx
@@ -1005,8 +1005,7 @@ void SvmTest::checkBitmapExs(const GDIMetaFile& 
rMetaFile, bool bIsSvmFile)
 if (SkiaHelper::isVCLSkiaEnabled())
 return; // TODO SKIA using CRCs is broken (the idea of it)
 
-std::vector aExpectedCRC;
-aExpectedCRC.insert(aExpectedCRC.end(),
+std::array aExpectedCRC
 {
 #if defined OSL_BIGENDIAN
 "08feb5d3",
@@ -1027,39 +1026,54 @@ void SvmTest::checkBitmapExs(const GDIMetaFile& 
rMetaFile, bool bIsSvmFile)
 "3c80d829",
 "71efc447",
 #endif
-});
+};
+
+std::array aExpectedContentChecksum
+{
+"26bdebd04e5b18d685cea04982179e273ee3b659",
+"f4f52df6ef965a2f0fbccbe6aca35ba3457cf9d5",
+"7c953a06d34bbd38897f950d595df2880dbb0f75",
+"ca3e5cdde1c395e1ee76d339a5bf6e46fbac3249",
+"8a1ebc46f890eb0879464c6e293bffd4ce7fadc0", // 1-bit
+"23611fc9f484c23e45bbd457730adb8ab5355509", // 4-bit color bitmap - 
same as 8-bit color bitmap
+"23611fc9f484c23e45bbd457730adb8ab5355509",
+"97e499b74104debf12f99a774a2c4edc914d8900",
+};
 
 assertXPathAttrs(pDoc, "/metafile/bmpex[1]", {
-{"x", "1"}, {"y", "1"}, {"crc", aExpectedCRC[0]}, {"transparenttype", 
"bitmap"}
+{"x", "1"}, {"y", "1"}, {"crc", aExpectedCRC[0]}, {"transparenttype", 
"bitmap"}, {"contentchecksum", aExpectedContentChecksum[0]}, {"pixelformat", 
"24BPP"}
 });
 assertXPathAttrs(pDoc, "/metafile/bmpexscale[1]", {
 {"x", "5"}, {"y", "0"}, {"width", "2"}, {"height", "3"},
-{"crc", aExpectedCRC[1]}, {"transparenttype", "bitmap"}
+{"crc", aExpectedCRC[1]}, {"transparenttype", "bitmap"}, 
{"contentchecksum", aExpectedContentChecksum[1]}, {"pixelformat", "24BPP"}
 });
 assertXPathAttrs(pDoc, "/metafile/bmpexscalepart[1]", {
 {"destx", "7"}, {"desty", "1"}, {"destwidth", "2"}, {"destheight", 
"2"},
 {"srcx", "0"},  {"srcy", "0"},  {"srcwidth", "3"},  {"srcheight", "4"},
-{"crc", aExpectedCRC[2]}, {"transparenttype", "bitmap"}
+{"crc", aExpectedCRC[2]}, {"transparenttype", "bitmap"}, 
{"contentchecksum", aExpectedContentChecksum[2]}, {"pixelformat", "24BPP"}
 });
 
 #ifndef MACOSX
 assertXPathAttrs(pDoc, "/metafile/bmpex[2]", {
-{"x", "6"}, {"y", "6"}, {"crc", aExpectedCRC[3]}, {"transparenttype", 
"bitmap"}
+{"x", "6"}, {"y", "6"}, {"crc", aExpectedCRC[3]}, {"transparenttype", 
"bitmap"}, {"contentchecksum", aExpectedContentChecksum[3]}
+});
+assertXPathAttrs(pDoc, "/metafile/bmpex[3]", {
+{"x", "0"}, {"y", "6"}, {"transparenttype", "bitmap"}, 
{"contentchecksum", aExpectedContentChecksum[4]}, {"pixelformat", "8BPP"}
 });
 if (!bIsSvmFile)
 {
 assertXPathAttrs(pDoc, "/metafile/bmpex[3]", {
-{"x", "0"}, {"y", "6"}, {"crc", aExpectedCRC[4]}, 
{"transparenttype", "bitmap"}
+{"crc", aExpectedCRC[4]}
 });
 }
 assertXPathAttrs(pDoc, "/metafile/bmpex[4]", {
-{"x", "2"}, {"y", "6"}, {"crc", aExpectedCRC[5]}, {"transparenttype", 
"bitmap"}
+{"x", "2"}, {"y", "6"}, {"crc", aExpectedCRC[5]}, {"transparenttype", 
"bitmap"}, {"contentchecksum", aExpectedContentChecksum[5]}, {"pixelformat", 
"8BPP"}
 });
 assertXPathAttrs(pDoc, "/metafile/bmpex[5]", {
-{"x", "0"}, {"y", "8"}, {"crc", aExpectedCRC[6]}, {"transparenttype", 
"bitmap"}
+{"x", "0"}, {"y", "8"}, {"crc", aExpectedCRC[6]}, {"transparenttype", 
"bitmap"}, {"contentchecksum", aExpectedContentChecksum[6]}, {"pixelformat", 
"8BPP"}
 });
 assertXPathAttrs(pDoc, "/metafile/bmpex[6]", {
-{"x", "2"}, {"y", "8"}, {"crc", aExpectedCRC[7]}, {"transparenttype", 
"bitmap"}
+{"x", "2"}, {"y", "8"}, {"crc", aExpectedCRC[7]}, {"transparenttype", 
"bitma

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

2023-01-02 Thread Dennis Francis (via logerrit)
 vcl/qa/cppunit/pdfexport/data/ref-to-kids.pdf |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx|   46 ++
 vcl/source/gdi/pdfobjectcopier.cxx|   22 
 3 files changed, 68 insertions(+)

New commits:
commit 68540314ecc801ddff06b843ac2e332b02bd7a3b
Author: Dennis Francis 
AuthorDate: Fri Dec 2 13:11:42 2022 +0530
Commit: Miklos Vajna 
CommitDate: Tue Jan 3 07:26:25 2023 +

vcl: Copy the resource kind object itself if...

some of the items in that resource are themselves dictionaries instead
of references.

Change-Id: I427386b14fe5507dfdfc9745dad27a8fceefd929
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143564
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 
(cherry picked from commit 4cb521b28e8582eda1a63bc4d92061fd111a2e3d)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144438
Tested-by: Jenkins

diff --git a/vcl/qa/cppunit/pdfexport/data/ref-to-kids.pdf 
b/vcl/qa/cppunit/pdfexport/data/ref-to-kids.pdf
index 0390ccad8410..fdda33f78231 100644
Binary files a/vcl/qa/cppunit/pdfexport/data/ref-to-kids.pdf and 
b/vcl/qa/cppunit/pdfexport/data/ref-to-kids.pdf differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index ce070a711911..4cf31e708220 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -4247,6 +4247,52 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, 
testRexportMediaBoxOrigin)
 }
 }
 
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testRexportResourceItemReference)
+{
+// We need to enable PDFium import (and make sure to disable after the 
test)
+bool bResetEnvVar = false;
+if (getenv("LO_IMPORT_USE_PDFIUM") == nullptr)
+{
+bResetEnvVar = true;
+osl_setEnvironment(OUString("LO_IMPORT_USE_PDFIUM").pData, 
OUString("1").pData);
+}
+comphelper::ScopeGuard aPDFiumEnvVarGuard([&]() {
+if (bResetEnvVar)
+osl_clearEnvironment(OUString("LO_IMPORT_USE_PDFIUM").pData);
+});
+
+// Load the PDF and save as PDF
+vcl::filter::PDFDocument aDocument;
+load(u"ref-to-kids.pdf", aDocument);
+
+std::vector aPages = aDocument.GetPages();
+CPPUNIT_ASSERT_EQUAL(size_t(5), aPages.size());
+
+// Directly go to the inner XObject Im10 that has reference to Font in 
page 2.
+auto pInnerIm = aDocument.LookupObject(10);
+CPPUNIT_ASSERT(pInnerIm);
+
+auto pResources
+= 
dynamic_cast(pInnerIm->Lookup("Resources"));
+CPPUNIT_ASSERT(pResources);
+auto pFontsReference
+= 
dynamic_cast(pResources->LookupElement("Font"));
+CPPUNIT_ASSERT(pFontsReference);
+
+auto pFontsObject = pFontsReference->LookupObject();
+CPPUNIT_ASSERT(pFontsObject);
+
+auto pFontDict
+= 
dynamic_cast(pFontsObject->Lookup("FF132"));
+CPPUNIT_ASSERT(pFontDict);
+
+auto pFontDescriptor = pFontDict->LookupObject("FontDescriptor");
+CPPUNIT_ASSERT(pFontDescriptor);
+
+auto pFontWidths = pFontDict->LookupObject("Widths");
+CPPUNIT_ASSERT(pFontWidths);
+}
+
 } // end anonymous namespace
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/gdi/pdfobjectcopier.cxx 
b/vcl/source/gdi/pdfobjectcopier.cxx
index 67f70d10f2a9..2f32cdc27ce1 100644
--- a/vcl/source/gdi/pdfobjectcopier.cxx
+++ b/vcl/source/gdi/pdfobjectcopier.cxx
@@ -184,6 +184,7 @@ OString 
PDFObjectCopier::copyExternalResources(filter::PDFObjectElement& rPage,
 
 // Get the rKind subset of the resource dictionary.
 std::map aItems;
+filter::PDFObjectElement* pKindObject = nullptr;
 if (auto pResources = 
dynamic_cast(rPage.Lookup("Resources")))
 {
 // Resources is a direct dictionary.
@@ -202,6 +203,7 @@ OString 
PDFObjectCopier::copyExternalResources(filter::PDFObjectElement& rPage,
 return {};
 }
 
+pKindObject = pReferenced;
 aItems = pReferenced->GetDictionaryItems();
 }
 }
@@ -210,23 +212,37 @@ OString 
PDFObjectCopier::copyExternalResources(filter::PDFObjectElement& rPage,
 // Resources is an indirect object.
 filter::PDFElement* pValue = pPageResources->Lookup(rKind);
 if (auto pDictionary = 
dynamic_cast(pValue))
+{
 // Kind is a direct dictionary.
 aItems = pDictionary->GetItems();
+}
 else if (filter::PDFObjectElement* pObject = 
pPageResources->LookupObject(rKind))
+{
 // Kind is an indirect object.
 aItems = pObject->GetDictionaryItems();
+pKindObject = pObject;
+}
 }
 if (aItems.empty())
 return {};
 
 SvMemoryStream& rDocBuffer = rPage.GetDocument().GetEditBuffer();
+bool bHasDictValue = false;
 
 for (const auto& rItem : aItems)
 {
 // For each item copy it over to our output then insert it into aRet.
 auto pReference = 
dynamic_cast(rItem.second);
 

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

2023-01-02 Thread Dennis Francis (via logerrit)
 vcl/qa/cppunit/pdfexport/data/ref-to-kids.pdf |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx|   61 ++
 vcl/source/gdi/pdfwriter_impl.cxx |   29 ++--
 3 files changed, 85 insertions(+), 5 deletions(-)

New commits:
commit e72f77b8164820569834f5459514c18d2bfd911b
Author: Dennis Francis 
AuthorDate: Thu Dec 1 11:47:12 2022 +0530
Commit: Miklos Vajna 
CommitDate: Tue Jan 3 07:25:42 2023 +

vcl: use /MediaBox origin in the ctm...

of the inner XObject, else the clip polypolygon may clip out partly or
whole contents. Adjusting the clip polypolygon is not straightforward.

Change-Id: If3b208ba850c3579c9e16c15e4fb2f947dad4406
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143561
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 
(cherry picked from commit a67dcc248a103098de883a4dd2fa9ff2e1cc1f90)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144436
Tested-by: Jenkins

diff --git a/vcl/qa/cppunit/pdfexport/data/ref-to-kids.pdf 
b/vcl/qa/cppunit/pdfexport/data/ref-to-kids.pdf
index 598358a636aa..0390ccad8410 100644
Binary files a/vcl/qa/cppunit/pdfexport/data/ref-to-kids.pdf and 
b/vcl/qa/cppunit/pdfexport/data/ref-to-kids.pdf differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 428f9d5a132a..ce070a711911 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -4186,6 +4186,67 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, 
testRexportFilterSingletonArray)
 CPPUNIT_ASSERT(it != pEnd);
 }
 
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testRexportMediaBoxOrigin)
+{
+// We need to enable PDFium import (and make sure to disable after the 
test)
+bool bResetEnvVar = false;
+if (getenv("LO_IMPORT_USE_PDFIUM") == nullptr)
+{
+bResetEnvVar = true;
+osl_setEnvironment(OUString("LO_IMPORT_USE_PDFIUM").pData, 
OUString("1").pData);
+}
+comphelper::ScopeGuard aPDFiumEnvVarGuard([&]() {
+if (bResetEnvVar)
+osl_clearEnvironment(OUString("LO_IMPORT_USE_PDFIUM").pData);
+});
+
+// Load the PDF and save as PDF
+vcl::filter::PDFDocument aDocument;
+load(u"ref-to-kids.pdf", aDocument);
+
+std::vector aPages = aDocument.GetPages();
+CPPUNIT_ASSERT_EQUAL(size_t(5), aPages.size());
+
+// Directly go to the inner XObject Im10 that contains the rectangle 
drawings in page 2.
+auto pInnerIm = aDocument.LookupObject(10);
+CPPUNIT_ASSERT(pInnerIm);
+
+constexpr sal_Int32 aOrigin[2] = { -800, -600 };
+sal_Int32 aSize[2] = { 0, 0 };
+
+auto pBBox = 
dynamic_cast(pInnerIm->Lookup("BBox"));
+CPPUNIT_ASSERT(pBBox);
+const auto& rElements2 = pBBox->GetElements();
+CPPUNIT_ASSERT_EQUAL(static_cast(4), rElements2.size());
+for (sal_Int32 nIdx = 0; nIdx < 4; ++nIdx)
+{
+const auto* pNumElement = 
dynamic_cast(rElements2[nIdx]);
+CPPUNIT_ASSERT(pNumElement);
+if (nIdx < 2)
+CPPUNIT_ASSERT_EQUAL(aOrigin[nIdx], 
static_cast(pNumElement->GetValue()));
+else
+aSize[nIdx - 2] = static_cast(pNumElement->GetValue()) 
- aOrigin[nIdx - 2];
+}
+
+auto pMatrix = 
dynamic_cast(pInnerIm->Lookup("Matrix"));
+CPPUNIT_ASSERT(pMatrix);
+const auto& rElements = pMatrix->GetElements();
+CPPUNIT_ASSERT_EQUAL(static_cast(6), rElements.size());
+sal_Int32 aMatTranslate[6]
+= { // Rotation by $\theta$ $cos(\theta), sin(\theta), -sin(\theta), 
cos(\theta)$
+0, -1, 1, 0,
+// Translate x,y
+-aOrigin[1] - aSize[1] / 2 + aSize[0] / 2, aOrigin[0] + aSize[0] / 
2 + aSize[1] / 2
+  };
+
+for (sal_Int32 nIdx = 0; nIdx < 6; ++nIdx)
+{
+const auto* pNumElement = 
dynamic_cast(rElements[nIdx]);
+CPPUNIT_ASSERT(pNumElement);
+CPPUNIT_ASSERT_EQUAL(aMatTranslate[nIdx], 
static_cast(pNumElement->GetValue()));
+}
+}
+
 } // end anonymous namespace
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index f4a3145c5085..d95a74aeb6af 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -8873,6 +8873,21 @@ void PDFWriterImpl::writeReferenceXObject(const 
ReferenceXObjectEmit& rEmit)
 return;
 }
 
+double aOrigin[2] = { 0.0, 0.0 };
+if (auto* pArray = 
dynamic_cast(pPage->Lookup("MediaBox")))
+{
+const auto& rElements = pArray->GetElements();
+if (rElements.size() >= 4)
+{
+// get x1, y1 of the rectangle.
+for (sal_Int32 nIdx = 0; nIdx < 2; ++nIdx)
+{
+if (const auto* pNumElement = 
dynamic_cast(rElements[nIdx]))
+aOrigin[nIdx] = pNumElement->GetValue();
+}
+}
+}
+
 std::vect

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

2022-12-20 Thread Dennis Francis (via logerrit)
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |   50 +
 vcl/source/gdi/pdfobjectcopier.cxx |8 +
 2 files changed, 58 insertions(+)

New commits:
commit db2757e110c1d99bc6128d80a0c6b9fd63982b89
Author: Dennis Francis 
AuthorDate: Thu Dec 1 11:28:49 2022 +0530
Commit: Miklos Vajna 
CommitDate: Wed Dec 21 07:59:04 2022 +

vcl: /Filter [/FlatDecode] not properly read

Change-Id: I156e153ae1a123cf9cf54eb23e6d3abe8962f677
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143560
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 
(cherry picked from commit f5ad4f9dfac27d5675fa5c397f66b8cc45cc31a1)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144435
Tested-by: Jenkins

diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index f18077505abd..428f9d5a132a 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -4136,6 +4136,56 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testRexportRefToKids)
 }
 }
 
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testRexportFilterSingletonArray)
+{
+// We need to enable PDFium import (and make sure to disable after the 
test)
+bool bResetEnvVar = false;
+if (getenv("LO_IMPORT_USE_PDFIUM") == nullptr)
+{
+bResetEnvVar = true;
+osl_setEnvironment(OUString("LO_IMPORT_USE_PDFIUM").pData, 
OUString("1").pData);
+}
+comphelper::ScopeGuard aPDFiumEnvVarGuard([&]() {
+if (bResetEnvVar)
+osl_clearEnvironment(OUString("LO_IMPORT_USE_PDFIUM").pData);
+});
+
+// Load the PDF and save as PDF
+vcl::filter::PDFDocument aDocument;
+load(u"ref-to-kids.pdf", aDocument);
+
+std::vector aPages = aDocument.GetPages();
+CPPUNIT_ASSERT_EQUAL(size_t(5), aPages.size());
+
+// Directly go to the inner XObject Im5 that contains the rectangle 
drawings.
+auto pInnerIm = aDocument.LookupObject(5);
+CPPUNIT_ASSERT(pInnerIm);
+
+auto pFilter = 
dynamic_cast(pInnerIm->Lookup("Filter"));
+CPPUNIT_ASSERT(pFilter);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Filter must be FlateDecode", 
OString("FlateDecode"),
+ pFilter->GetValue());
+
+vcl::filter::PDFStreamElement* pStream = pInnerIm->GetStream();
+CPPUNIT_ASSERT(pStream);
+SvMemoryStream& rObjectStream = pStream->GetMemory();
+// Uncompress it.
+SvMemoryStream aUncompressed;
+ZCodec aZCodec;
+aZCodec.BeginCompression();
+rObjectStream.Seek(0);
+aZCodec.Decompress(rObjectStream, aUncompressed);
+CPPUNIT_ASSERT(aZCodec.EndCompression());
+
+// Without the fix, the stream is doubly compressed,
+// hence one decompression will not yield the "re" expressions.
+auto pStart = static_cast(aUncompressed.GetData());
+const char* pEnd = pStart + aUncompressed.GetSize();
+OString aImage = "100 0 30 50 re B*\n70 67 50 30 re B*\n";
+auto it = std::search(pStart, pEnd, aImage.getStr(), aImage.getStr() + 
aImage.getLength());
+CPPUNIT_ASSERT(it != pEnd);
+}
+
 } // end anonymous namespace
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/gdi/pdfobjectcopier.cxx 
b/vcl/source/gdi/pdfobjectcopier.cxx
index 93b7b4989710..999be92bd752 100644
--- a/vcl/source/gdi/pdfobjectcopier.cxx
+++ b/vcl/source/gdi/pdfobjectcopier.cxx
@@ -283,6 +283,14 @@ sal_Int32 
PDFObjectCopier::copyPageStreams(std::vectorGetMemory();
 
 auto pFilter = 
dynamic_cast(pContent->Lookup("Filter"));
+auto pFilterArray = 
dynamic_cast(pContent->Lookup("Filter"));
+if (!pFilter && pFilterArray)
+{
+auto& aElements = pFilterArray->GetElements();
+if (!aElements.empty())
+pFilter = dynamic_cast(aElements[0]);
+}
+
 if (pFilter)
 {
 if (pFilter->GetValue() != "FlateDecode")


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

2022-12-20 Thread Dennis Francis (via logerrit)
 vcl/qa/cppunit/pdfexport/data/ref-to-kids.pdf |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx|   38 ++
 vcl/source/filter/ipdf/pdfdocument.cxx|   21 +-
 3 files changed, 58 insertions(+), 1 deletion(-)

New commits:
commit 9a45d2779ceaa1938feddf820d826922ed17854b
Author: Dennis Francis 
AuthorDate: Thu Dec 1 11:18:22 2022 +0530
Commit: Miklos Vajna 
CommitDate: Wed Dec 21 07:58:38 2022 +

vcl: read references to /Kids array...

if the argument of /Kids is not an array.

Conflicts:
vcl/qa/cppunit/pdfexport/pdfexport.cxx

Change-Id: Ib73962d3a27aa7e1ce5ddbe6845a1dd73bd7a343
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143559
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 
(cherry picked from commit 10185a6aec5d3b74a51e4b9474645e12bf794df8)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144434
Tested-by: Jenkins

diff --git a/vcl/qa/cppunit/pdfexport/data/ref-to-kids.pdf 
b/vcl/qa/cppunit/pdfexport/data/ref-to-kids.pdf
new file mode 100644
index ..598358a636aa
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/ref-to-kids.pdf 
differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index ea8f83e6ba8f..f18077505abd 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -15,6 +15,7 @@
 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -4098,6 +4099,43 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf139627)
  / aRect[jehtatweel].getWidth());
 #endif
 }
+
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testRexportRefToKids)
+{
+// We need to enable PDFium import (and make sure to disable after the 
test)
+bool bResetEnvVar = false;
+if (getenv("LO_IMPORT_USE_PDFIUM") == nullptr)
+{
+bResetEnvVar = true;
+osl_setEnvironment(OUString("LO_IMPORT_USE_PDFIUM").pData, 
OUString("1").pData);
+}
+comphelper::ScopeGuard aPDFiumEnvVarGuard([&]() {
+if (bResetEnvVar)
+osl_clearEnvironment(OUString("LO_IMPORT_USE_PDFIUM").pData);
+});
+
+// Load the PDF and save as PDF
+vcl::filter::PDFDocument aDocument;
+load(u"ref-to-kids.pdf", aDocument);
+
+std::vector aPages = aDocument.GetPages();
+CPPUNIT_ASSERT_EQUAL(size_t(5), aPages.size());
+
+vcl::filter::PDFObjectElement* pResources = 
aPages[0]->LookupObject("Resources");
+CPPUNIT_ASSERT(pResources);
+
+auto pXObjects
+= 
dynamic_cast(pResources->Lookup("XObject"));
+CPPUNIT_ASSERT(pXObjects);
+
+// Without the fix LookupObject for all /Im's will fail.
+for (auto const& rPair : pXObjects->GetItems())
+{
+if (rPair.first.startsWith("Im"))
+CPPUNIT_ASSERT(pXObjects->LookupObject(rPair.first));
+}
+}
+
 } // end anonymous namespace
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/filter/ipdf/pdfdocument.cxx 
b/vcl/source/filter/ipdf/pdfdocument.cxx
index 25e731f5352a..19748e241ead 100644
--- a/vcl/source/filter/ipdf/pdfdocument.cxx
+++ b/vcl/source/filter/ipdf/pdfdocument.cxx
@@ -1918,7 +1918,26 @@ const std::vector>& 
PDFDocument::GetElements() const
 /// Visits the page tree recursively, looking for page objects.
 static void visitPages(PDFObjectElement* pPages, 
std::vector& rRet)
 {
-auto pKids = dynamic_cast(pPages->Lookup("Kids"));
+auto pKidsRef = pPages->Lookup("Kids");
+auto pKids = dynamic_cast(pKidsRef);
+if (!pKids)
+{
+auto pRefKids = dynamic_cast(pKidsRef);
+if (!pRefKids)
+{
+SAL_WARN("vcl.filter", "visitPages: pages has no kids");
+return;
+}
+auto pObjWithKids = pRefKids->LookupObject();
+if (!pObjWithKids)
+{
+SAL_WARN("vcl.filter", "visitPages: pages has no kids");
+return;
+}
+
+pKids = pObjWithKids->GetArray();
+}
+
 if (!pKids)
 {
 SAL_WARN("vcl.filter", "visitPages: pages has no kids");


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

2022-10-05 Thread Khaled Hosny (via logerrit)
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |   54 +
 vcl/source/gdi/CommonSalLayout.cxx |6 ---
 2 files changed, 22 insertions(+), 38 deletions(-)

New commits:
commit 09c076c3f29c28497f162d3a5b7baab040725d56
Author: Khaled Hosny 
AuthorDate: Wed Oct 5 21:00:46 2022 +0200
Commit: خالد حسني 
CommitDate: Wed Oct 5 22:08:08 2022 +0200

tdf#151350: Fix extraneous gaps before marks

After latest changes we no longer need HarfBuzz buffer level
MONOTONE_CHARACTERS (which was needed to allow us to address individual
combining marks). With the default cluster level, combining marks get
the same cluster as their base and so we need not do any thing special.

I had to update testTdf139627 because this results in using ActualText
spans in the PDF, and PDFium support for them is lacking.

Change-Id: I0011072330fdbf409c30ff781fd3beaceae400f5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140994
Tested-by: Jenkins
Reviewed-by: خالد حسني 

diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 88139dd0ecd4..b8efd4c5dc6e 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -3621,10 +3621,10 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testBitmapScaledown)
 CPPUNIT_ASSERT_EQUAL(2616, nWidth);
 }
 }
-} // end anonymous namespace
 
 CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf139627)
 {
+#if HAVE_MORE_FONTS
 aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
 saveAsPDF(u"justified-arabic-kashida.odt");
 std::unique_ptr pPdfDocument = parseExport();
@@ -3635,20 +3635,19 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf139627)
 std::unique_ptr pPdfPage = 
pPdfDocument->openPage(/*nIndex=*/0);
 CPPUNIT_ASSERT(pPdfPage);
 
-// 7 or 8 objects, 4 text, others are path
+// 7 objects, 3 text, others are path
 int nPageObjectCount = pPdfPage->getObjectCount();
-CPPUNIT_ASSERT_GREATEREQUAL(7, nPageObjectCount);
+CPPUNIT_ASSERT_EQUAL(7, nPageObjectCount);
 
-// 4 text objects, "رم" (reh+mim), then "ِ" (kasreh), tatweel, and "ج" 
(jeh)
-OUString sText[4];
+// 3 text objects
+OUString sText[3];
 
 /* With "Noto Sans Arabic" font, these are the X ranges on Linux:
-0: ( 61.75 - 218.35)
-1: (479.70 - 520.02)
-2: (209.40 - 457.08)
-3: (447.80 - 546.62)
+0: ( 61.75 - 415.94)
+1: (479.70 - 422.40)
+2: (209.40 - 453.2)
 */
-basegfx::B2DRectangle aRect[4];
+basegfx::B2DRectangle aRect[3];
 
 std::unique_ptr pTextPage = 
pPdfPage->getTextPage();
 std::unique_ptr pPageObject;
@@ -3665,47 +3664,38 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf139627)
 ++nTextObjectCount;
 }
 }
-CPPUNIT_ASSERT_EQUAL(4, nTextObjectCount);
+CPPUNIT_ASSERT_EQUAL(3, nTextObjectCount);
 
 // Text: جِـرم (which means "mass" in Persian)
-// Rendered as (left to right): "reh + mim" - "tatweel" - "kasreh" - "jeh"
-int rehmim = 0, kasreh = 1, tatweel = 2, jeh = 3;
-
-// Bad rendering can cause tatweel enumerated before kasreh
-// This can be the end of journey, but let's accept this for now
-if (sText[2].equals(u"ِ"))
-{
-tatweel = 1;
-kasreh = 2;
-}
+// Rendered as (left to right): "reh + mim" - "kasreh" - "jeh + tatweel"
+int rehmim = 0, kasreh = 1, jehtatweel = 2;
 
 CPPUNIT_ASSERT_EQUAL(OUString(u"رم"), sText[rehmim].trim());
-CPPUNIT_ASSERT_EQUAL(OUString(u"ِ"), sText[kasreh].trim());
-CPPUNIT_ASSERT_EQUAL(OUString(u""), sText[tatweel].trim());
-CPPUNIT_ASSERT_EQUAL(OUString(u"ج"), sText[jeh].trim());
+CPPUNIT_ASSERT_EQUAL(OUString(u""), sText[kasreh].trim());
+CPPUNIT_ASSERT_EQUAL(OUString(u""), sText[jehtatweel].trim());
 
 // "Kasreh" should be within "jeh" character
-CPPUNIT_ASSERT_GREATER(aRect[jeh].getMinX(), aRect[kasreh].getMinX());
-CPPUNIT_ASSERT_LESS(aRect[jeh].getMaxX(), aRect[kasreh].getMaxX());
+CPPUNIT_ASSERT_GREATER(aRect[jehtatweel].getMinX(), 
aRect[kasreh].getMinX());
+CPPUNIT_ASSERT_LESS(aRect[jehtatweel].getMaxX(), aRect[kasreh].getMaxX());
 
 // "Tatweel" should cover "jeh" and "reh"+"mim" to avoid gap
 // Checking right gap
-CPPUNIT_ASSERT_GREATER(aRect[jeh].getMinX(), aRect[tatweel].getMaxX());
+//CPPUNIT_ASSERT_GREATER(aRect[jehtatweel].getMinX(), 
aRect[tatweel].getMaxX());
 // Checking left gap
 // Kashida fails to reach to rehmim before the series of patches starting
 // with 3901e029bd39575f700e69a73818565d62226a23. The visible symptom is
 // a gap in the left of Kashida.
-// CPPUNIT_ASSERT_LESS(aRect[rehmim].getMaxX(), aRect[tatweel].getMinX());
+CPPUNIT_ASSERT_LESS(aRect[rehmim].getMaxX(), aRect[jehtatweel].getMinX());
 
 // Overlappings of Kashida and surrounding characters is ~9% of the width
 // of the "jeh" characte

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

2022-08-30 Thread Khaled Hosny (via logerrit)
 vcl/qa/cppunit/complextext.cxx |5 ++---
 vcl/source/gdi/sallayout.cxx   |9 +++--
 2 files changed, 5 insertions(+), 9 deletions(-)

New commits:
commit ce7c1c608fa99c86c8f2380cd8b82d02123f514e
Author: Khaled Hosny 
AuthorDate: Wed Aug 31 07:07:54 2022 +0200
Commit: خالد حسني 
CommitDate: Wed Aug 31 08:47:16 2022 +0200

vcl: Fix GenericSalLayout::GetTextWidth()

There was a mismatch between text width calculated in
GenericSalLayout::GetTextWidth() and last glyph width calculated in
GenericSalLayout::GetCharWidths(), with the later using the sum of
GlyphItem::newWidth() and the later using the GlyphItem::linearPos(),
but linearPos() includes glyph offset and it should be subtracted from
it to get actual width and we were subtracting it in the wrong place.

I fixed where the xOffset() is subtracted but didn’t change it to simply
sum GlyphItem::newWidth() though that is simpler so that we continue to
test that linearPos() is correctly set.

Change-Id: I40d6be6d1c82ed0ca1ce04bf792adf72faa0d787
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139071
Tested-by: Jenkins
Reviewed-by: خالد حسني 

diff --git a/vcl/qa/cppunit/complextext.cxx b/vcl/qa/cppunit/complextext.cxx
index fb25459bb737..d052564d638b 100644
--- a/vcl/qa/cppunit/complextext.cxx
+++ b/vcl/qa/cppunit/complextext.cxx
@@ -287,9 +287,8 @@ void VclComplexTextTest::testCaret()
 CPPUNIT_ASSERT_EQUAL(aCharWidths[6], aCharWidths[7]);
 CPPUNIT_ASSERT_EQUAL(aCharWidths[8], aCharWidths[9]);
 CPPUNIT_ASSERT_EQUAL(aRefCharWidths, aCharWidths);
-// FIXME: this should be 353, and the next assert should be true as well.
-CPPUNIT_ASSERT_EQUAL(tools::Long(388), nTextWidth2);
-//CPPUNIT_ASSERT_EQUAL(nTextWidth, nTextWidth2);
+CPPUNIT_ASSERT_EQUAL(tools::Long(353), nTextWidth2);
+CPPUNIT_ASSERT_EQUAL(nTextWidth, nTextWidth2);
 CPPUNIT_ASSERT_EQUAL(sal_Int32(nTextWidth), aCharWidths.back());
 
 // B. LTR text
diff --git a/vcl/source/gdi/sallayout.cxx b/vcl/source/gdi/sallayout.cxx
index 6d22b302b6c5..de5385f93ac2 100644
--- a/vcl/source/gdi/sallayout.cxx
+++ b/vcl/source/gdi/sallayout.cxx
@@ -286,12 +286,9 @@ DeviceCoordinate GenericSalLayout::GetTextWidth() const
 for (auto const& aGlyphItem : m_GlyphItems)
 {
 // update the text extent with the glyph extent
-DeviceCoordinate nXPos = aGlyphItem.linearPos().getX();
-if( nMinPos > nXPos )
-nMinPos = nXPos;
-nXPos += aGlyphItem.newWidth() - aGlyphItem.xOffset();
-if( nMaxPos < nXPos )
-nMaxPos = nXPos;
+DeviceCoordinate nXPos = aGlyphItem.linearPos().getX() - 
aGlyphItem.xOffset();
+nMinPos = std::min(nMinPos, nXPos);
+nMaxPos = std::max(nMaxPos, nXPos + aGlyphItem.newWidth());
 }
 
 DeviceCoordinate nWidth = nMaxPos - nMinPos;


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

2022-08-30 Thread Khaled Hosny (via logerrit)
 vcl/qa/cppunit/complextext.cxx |   91 +
 vcl/source/gdi/CommonSalLayout.cxx |   54 ++---
 2 files changed, 137 insertions(+), 8 deletions(-)

New commits:
commit bdbbdc9b931d35f6d7d816512ac5be599295dc80
Author: Khaled Hosny 
AuthorDate: Sun Aug 28 06:59:06 2022 +0200
Commit: خالد حسني 
CommitDate: Wed Aug 31 08:46:25 2022 +0200

tdf#30731: Use ligature caret positions from the font

When ligature caret positions from the font are available, use them for
more accurate caret positions instead of evenly distributing the glyph
width over grapheme clusters.

Change-Id: I0ecfa35e1fff2b264b105182a4b29b2ebd033093
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138955
Tested-by: Jenkins
Reviewed-by: خالد حسني 

diff --git a/vcl/qa/cppunit/complextext.cxx b/vcl/qa/cppunit/complextext.cxx
index 0b76f5eb91d9..fb25459bb737 100644
--- a/vcl/qa/cppunit/complextext.cxx
+++ b/vcl/qa/cppunit/complextext.cxx
@@ -53,6 +53,7 @@ public:
 void testCaching();
 void testCachingSubstring();
 void testCaret();
+void testGdefCaret();
 
 CPPUNIT_TEST_SUITE(VclComplexTextTest);
 CPPUNIT_TEST(testArabic);
@@ -60,6 +61,7 @@ public:
 CPPUNIT_TEST(testCaching);
 CPPUNIT_TEST(testCachingSubstring);
 CPPUNIT_TEST(testCaret);
+CPPUNIT_TEST(testGdefCaret);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -236,6 +238,8 @@ void VclComplexTextTest::testCachingSubstring()
 void VclComplexTextTest::testCaret()
 {
 #if HAVE_MORE_FONTS
+// Test caret placement in fonts *without* ligature carets in GDEF table.
+
 ScopedVclPtrInstance pWin(static_cast(nullptr));
 CPPUNIT_ASSERT( pWin );
 
@@ -313,6 +317,93 @@ void VclComplexTextTest::testCaret()
 #endif
 }
 
+void VclComplexTextTest::testGdefCaret()
+{
+#if HAVE_MORE_FONTS
+// Test caret placement in fonts *with* ligature carets in GDEF table.
+
+ScopedVclPtrInstance pWin(static_cast(nullptr));
+CPPUNIT_ASSERT( pWin );
+
+OutputDevice *pOutDev = pWin->GetOutDev();
+
+vcl::Font aFont;
+OUString aText;
+std::vector aCharWidths, aRefCharWidths;
+tools::Long nTextWidth, nTextWidth2;
+
+// A. RTL text
+aFont = vcl::Font("Noto Naskh Arabic", "Regular", Size(0, 200));
+pOutDev->SetFont(aFont);
+
+aText = u"لا بلا";
+
+// 1) Regular DX array, the ligature width is given to the first components
+// and the next ones are all zero width.
+aRefCharWidths = { 104, 104, 148, 203, 325, 325 };
+aCharWidths.resize(aText.getLength());
+std::fill(aCharWidths.begin(), aCharWidths.end(), 0);
+nTextWidth = pOutDev->GetTextArray(aText, &aCharWidths, 0, -1, 
/*bCaret*/false);
+CPPUNIT_ASSERT_EQUAL(aRefCharWidths, aCharWidths);
+CPPUNIT_ASSERT_EQUAL(tools::Long(325), nTextWidth);
+CPPUNIT_ASSERT_EQUAL(sal_Int32(nTextWidth), aCharWidths.back());
+
+// 2) Caret placement DX array, ligature width is distributed over its
+// components.
+aRefCharWidths = { 53, 104, 148, 203, 265, 325 };
+aCharWidths.resize(aText.getLength());
+std::fill(aCharWidths.begin(), aCharWidths.end(), 0);
+nTextWidth = pOutDev->GetTextArray(aText, &aCharWidths, 0, -1, 
/*bCaret*/true);
+CPPUNIT_ASSERT_EQUAL(aRefCharWidths, aCharWidths);
+CPPUNIT_ASSERT_EQUAL(tools::Long(325), nTextWidth);
+CPPUNIT_ASSERT_EQUAL(sal_Int32(nTextWidth), aCharWidths.back());
+
+// 3) caret placement with combining marks, they should not add to ligature
+// component count.
+aText = u"لَاَ بلَاَ";
+aRefCharWidths = { 53, 53, 104, 104, 148, 203, 265, 265, 325, 325 };
+aCharWidths.resize(aText.getLength());
+std::fill(aCharWidths.begin(), aCharWidths.end(), 0);
+nTextWidth2 = pOutDev->GetTextArray(aText, &aCharWidths, 0, -1, 
/*bCaret*/true);
+CPPUNIT_ASSERT_EQUAL(aCharWidths[0], aCharWidths[1]);
+CPPUNIT_ASSERT_EQUAL(aCharWidths[2], aCharWidths[3]);
+CPPUNIT_ASSERT_EQUAL(aCharWidths[6], aCharWidths[7]);
+CPPUNIT_ASSERT_EQUAL(aCharWidths[8], aCharWidths[9]);
+CPPUNIT_ASSERT_EQUAL(aRefCharWidths, aCharWidths);
+CPPUNIT_ASSERT_EQUAL(tools::Long(325), nTextWidth2);
+CPPUNIT_ASSERT_EQUAL(nTextWidth, nTextWidth2);
+CPPUNIT_ASSERT_EQUAL(sal_Int32(nTextWidth), aCharWidths.back());
+
+// B. LTR text
+aFont = vcl::Font("Amiri", "Regular", Size(0, 200));
+pOutDev->SetFont(aFont);
+
+aText = u"fi ffi fl ffl fb ffb";
+
+// 1) Regular DX array, the ligature width is given to the first components
+// and the next ones are all zero width.
+aRefCharWidths = { 104, 104, 162, 321, 321, 321, 379, 487, 487, 545, 708,
+   708, 708, 766, 926, 926, 984, 1198, 1198, 1198 };
+aCharWidths.resize(aText.getLength());
+std::fill(aCharWidths.begin(), aCharWidths.end(), 0);
+nTextWidth = pOutDev->GetTextArray(aText, &aCharWidths, 0, -1, 
/*bCaret*/false);
+CPPUNIT_ASSERT_EQUAL(aRefCharWidths, aCharWidths);
+CPPUNIT_AS

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

2022-08-03 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/pdfexport/data/bitmap-scaledown.odt |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |   46 ++---
 vcl/source/outdev/bitmapex.cxx |   10 
 3 files changed, 40 insertions(+), 16 deletions(-)

New commits:
commit 7c94d7267bc8b5f43185204ab4953c4b188214bf
Author: Miklos Vajna 
AuthorDate: Wed Aug 3 09:44:03 2022 +0200
Commit: Miklos Vajna 
CommitDate: Wed Aug 3 11:11:15 2022 +0200

tdf#149943 vcl: fix pixelated PDF export and print for a rotated image

The bugdoc has a barcode which looks good in Writer, but it's quite
blurry in the PDF export result.

This is a problem since commit dd4a67084853a030bf4b9f1f85d728620e0604a5
(vcl: avoid downscale && upscale in DrawTransformedBitmapEx(),
2019-10-08), where the motivation was to not downscale a bitmap in case
it has a larger amount of pixels but a smaller logic size. This went
wrong here and resulted in a blurry bitmap for a not so small image.

Fix the problem by mostly reverting the above commit, because it's no
longer necessary: 68549e00d5e23aa22bc974a8151d93cd948444b3 (vcl,
BitmapEx transformed draw: special-case simple rotations, 2019-10-10)
already made sure that the rotation case doesn't use scaling from the
transform.

testTdf128630 has been adapted to pass again (after manually verifying
that the bugdoc export result is still OK), now the bad case there
simply produces a smaller bitmap.

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

diff --git a/vcl/qa/cppunit/pdfexport/data/bitmap-scaledown.odt 
b/vcl/qa/cppunit/pdfexport/data/bitmap-scaledown.odt
new file mode 100644
index ..da9b167fd9d7
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/bitmap-scaledown.odt 
differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 03aed3112d64..fb821ae4 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -1638,7 +1638,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf128630)
 // The document has one page.
 CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
 
-// Assert the aspect ratio of the only bitmap on the page.
+// Assert the size of the only bitmap on the page.
 std::unique_ptr pPdfPage = 
pPdfDocument->openPage(/*nIndex=*/0);
 CPPUNIT_ASSERT(pPdfPage);
 int nPageObjectCount = pPdfPage->getObjectCount();
@@ -1651,12 +1651,13 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf128630)
 std::unique_ptr pBitmap = 
pPageObject->getImageBitmap();
 CPPUNIT_ASSERT(pBitmap);
 int nWidth = pBitmap->getWidth();
-int nHeight = pBitmap->getHeight();
 // Without the accompanying fix in place, this test would have failed 
with:
-// assertion failed
-// - Expression: nWidth != nHeight
-// i.e. the bitmap lost its custom aspect ratio during export.
-CPPUNIT_ASSERT(nWidth != nHeight);
+// - Expected: 466
+// - Actual  : 289
+// i.e. the rotated + scaled arrow was more thin than it should be.
+CPPUNIT_ASSERT_EQUAL(466, nWidth);
+int nHeight = pBitmap->getHeight();
+CPPUNIT_ASSERT_EQUAL(466, nHeight);
 }
 }
 
@@ -3451,6 +3452,39 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, 
testPdfImageEncryption)
 // missing encryption.
 CPPUNIT_ASSERT_EQUAL(2, pPageObject->getFormObjectCount());
 }
+
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testBitmapScaledown)
+{
+// Given a document with an upscaled and rotated barcode bitmap in it:
+aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+
+// When saving as PDF:
+saveAsPDF(u"bitmap-scaledown.odt");
+
+// Then verify that the bitmap is not downscaled:
+std::unique_ptr pPdfDocument = parseExport();
+CPPUNIT_ASSERT(pPdfDocument);
+CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
+std::unique_ptr pPdfPage = 
pPdfDocument->openPage(/*nIndex=*/0);
+CPPUNIT_ASSERT(pPdfPage);
+int nPageObjectCount = pPdfPage->getObjectCount();
+for (int i = 0; i < nPageObjectCount; ++i)
+{
+std::unique_ptr pPageObject = 
pPdfPage->getObject(i);
+if (pPageObject->getType() != vcl::pdf::PDFPageObjectType::Image)
+continue;
+
+std::unique_ptr pBitmap = 
pPageObject->getImageBitmap();
+CPPUNIT_ASSERT(pBitmap);
+// In-file sizes: good is 2631x380, bad is 1565x14.
+int nWidth = pBitmap->getWidth();
+// Without the accompanying fix in place, this test would have failed 
with:
+// - Expected: 2616
+// - Actual  : 1565
+// i.e. the bitmap in the pdf result was small enough to be blurry.
+CPPUNIT_ASSERT_EQUAL(2616, nWidth);
+}
+}
 } // end anonymous namespace
 

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

2022-07-19 Thread Chris Sherlock (via logerrit)
 vcl/qa/cppunit/complextext.cxx |   14 +++---
 vcl/source/outdev/text.cxx |8 
 2 files changed, 11 insertions(+), 11 deletions(-)

New commits:
commit 4d9e9ff5f4cb199844eb1d2b4000bb837089347f
Author: Chris Sherlock 
AuthorDate: Thu Jun 30 21:07:26 2022 +1000
Commit: Tomaž Vajngerl 
CommitDate: Tue Jul 19 12:59:54 2022 +0200

vcl: allow OutputDevice::GetTextRect() cater for rotated fonts

Change-Id: I52bdfe75ef1dd7973d14cad72e31a1e559bb7876
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136667
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/complextext.cxx b/vcl/qa/cppunit/complextext.cxx
index a7cf83d4edfd..d6c624fa7406 100644
--- a/vcl/qa/cppunit/complextext.cxx
+++ b/vcl/qa/cppunit/complextext.cxx
@@ -98,27 +98,19 @@ void VclComplexTextTest::testArabic()
 CPPUNIT_ASSERT_DOUBLES_EQUAL(71, aBoundRect.GetWidth(), 2); // This 
sometimes equals to 70
 CPPUNIT_ASSERT_DOUBLES_EQUAL(15, aBoundRect.getOpenHeight(), 1);
 
-#if 0
-// FIXME: This seems to be wishful thinking, GetTextRect() does not take
-// rotation into account.
-
 // normal orientation
 tools::Rectangle aInput;
 tools::Rectangle aRect = pOutDev->GetTextRect( aInput, aOneTwoThree );
 
 // now rotate 270 degrees
 vcl::Font aRotated( aFont );
-aRotated.SetOrientation( 2700 );
+aRotated.SetOrientation( 2700_deg10 );
 pOutDev->SetFont( aRotated );
 tools::Rectangle aRectRot = pOutDev->GetTextRect( aInput, aOneTwoThree );
 
 // Check that we did do the rotation...
-fprintf( stderr, "%" SAL_PRIdINT64 " %" SAL_PRIdINT64 " %" SAL_PRIdINT64 " 
%" SAL_PRIdINT64 "\n",
- sal_Int64(aRect.GetWidth()), sal_Int64(aRect.GetHeight()),
- sal-Int64(aRectRot.GetWidth()), sal_Int64(aRectRot.GetHeight()) );
-CPPUNIT_ASSERT( aRectRot.GetWidth() == aRect.GetHeight() );
-CPPUNIT_ASSERT( aRectRot.GetHeight() == aRect.GetWidth() );
-#endif
+CPPUNIT_ASSERT_EQUAL( aRectRot.GetWidth(), aRect.GetHeight() );
+CPPUNIT_ASSERT_EQUAL( aRectRot.GetHeight(), aRect.GetWidth() );
 #endif
 }
 
diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx
index e82d89930b6d..2f7199fa3fa3 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -2042,6 +2042,14 @@ tools::Rectangle OutputDevice::GetTextRect( const 
tools::Rectangle& rRect,
 aRect.AdjustLeft( -1 );
 else
 aRect.AdjustRight( 1 );
+
+if (maFont.GetOrientation() != 0_deg10)
+{
+tools::Polygon aRotatedPolygon(aRect);
+aRotatedPolygon.Rotate(Point(aRect.GetWidth() / 2, aRect.GetHeight() / 
2), maFont.GetOrientation());
+return aRotatedPolygon.GetBoundRect();
+}
+
 return aRect;
 }
 


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

2022-07-19 Thread Chris Sherlock (via logerrit)
 vcl/qa/cppunit/complextext.cxx |2 +-
 vcl/source/app/svapp.cxx   |2 +-
 vcl/source/control/scrbar.cxx  |4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 9e7aee7c85b5ef341705d2969461bc96743fcbcc
Author: Chris Sherlock 
AuthorDate: Mon Jul 18 19:46:22 2022 +1000
Commit: Tomaž Vajngerl 
CommitDate: Tue Jul 19 12:05:10 2022 +0200

vcl: migrate from getOpenHeight/Width() to GetWidth/Height()

Change-Id: Ia51d6a6f2e9dcb6ba6193f7617848e7bd560dabb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137170
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/complextext.cxx b/vcl/qa/cppunit/complextext.cxx
index a79fe420884d..a7cf83d4edfd 100644
--- a/vcl/qa/cppunit/complextext.cxx
+++ b/vcl/qa/cppunit/complextext.cxx
@@ -95,7 +95,7 @@ void VclComplexTextTest::testArabic()
 pOutDev->GetTextBoundRect(aBoundRect, aOneTwoThree);
 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, aBoundRect.Left(), 1); // This sometimes 
equals to 1
 CPPUNIT_ASSERT_DOUBLES_EQUAL(1, aBoundRect.Top(), 1);
-CPPUNIT_ASSERT_DOUBLES_EQUAL(71, aBoundRect.getOpenWidth(), 1); // This 
sometimes equals to 70
+CPPUNIT_ASSERT_DOUBLES_EQUAL(71, aBoundRect.GetWidth(), 2); // This 
sometimes equals to 70
 CPPUNIT_ASSERT_DOUBLES_EQUAL(15, aBoundRect.getOpenHeight(), 1);
 
 #if 0
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index c315c35f0fd1..36beccb6bcb5 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -1375,7 +1375,7 @@ tools::Rectangle Application::GetScreenPosSizePixel( 
unsigned int nScreen )
 return tools::Rectangle();
 }
 tools::Rectangle aRect = pSys->GetDisplayScreenPosSizePixel(nScreen);
-if (aRect.getOpenHeight() == 0)
+if (aRect.GetHeight() == 0)
 SAL_WARN("vcl", "Requesting screen size/pos for screen #" << nScreen 
<< " returned 0 height.");
 return aRect;
 }
diff --git a/vcl/source/control/scrbar.cxx b/vcl/source/control/scrbar.cxx
index 7ef7174ee714..79fb1d4c11df 100644
--- a/vcl/source/control/scrbar.cxx
+++ b/vcl/source/control/scrbar.cxx
@@ -1118,12 +1118,12 @@ IMPL_LINK_NOARG(ScrollBar, ImplAutoTimerHdl, Timer *, 
void)
 void ScrollBar::ImplInvert()
 {
 tools::Rectangle aRect( maThumbRect );
-if( aRect.getOpenWidth() > 4 )
+if( aRect.GetWidth() > 5 )
 {
 aRect.AdjustLeft(2 );
 aRect.AdjustRight( -2 );
 }
-if( aRect.getOpenHeight() > 4 )
+if( aRect.GetHeight() > 5 )
 {
 aRect.AdjustTop(2 );
 aRect.AdjustBottom( -2 );


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

2022-07-19 Thread offtkp (via logerrit)
 vcl/qa/cppunit/png/PngFilterTest.cxx |   49 +++
 vcl/source/filter/png/PngImageWriter.cxx |5 +--
 2 files changed, 52 insertions(+), 2 deletions(-)

New commits:
commit 3d1032cf6b67f3f6fa539d1d42d681080517d38c
Author: offtkp 
AuthorDate: Tue Jul 5 00:49:14 2022 +0300
Commit: Tomaž Vajngerl 
CommitDate: Tue Jul 19 09:59:27 2022 +0200

Add PngImageWriter 8 bit palette export support

Also add test that fills a 256 color palette, exports a 16x16 image and
reimports it and checks each pixel color

Change-Id: Id53f3116e42d669cd528edfd791a1a981551ae0f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136817
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/png/PngFilterTest.cxx 
b/vcl/qa/cppunit/png/PngFilterTest.cxx
index 2eae9544ecbb..64a99756aa89 100644
--- a/vcl/qa/cppunit/png/PngFilterTest.cxx
+++ b/vcl/qa/cppunit/png/PngFilterTest.cxx
@@ -176,6 +176,7 @@ public:
 void testPngRoundtrip24_8();
 void testPngRoundtrip32();
 void testPngWrite1BitRGBPalette();
+void testPngWrite8BitRGBPalette();
 
 CPPUNIT_TEST_SUITE(PngFilterTest);
 CPPUNIT_TEST(testPng);
@@ -186,6 +187,7 @@ public:
 CPPUNIT_TEST(testPngRoundtrip24_8);
 CPPUNIT_TEST(testPngRoundtrip32);
 CPPUNIT_TEST(testPngWrite1BitRGBPalette);
+CPPUNIT_TEST(testPngWrite8BitRGBPalette);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -1929,6 +1931,53 @@ void PngFilterTest::testPngWrite1BitRGBPalette()
 }
 }
 
+void PngFilterTest::testPngWrite8BitRGBPalette()
+{
+SvMemoryStream aExportStream;
+BitmapPalette aRedPalette;
+aRedPalette.SetEntryCount(256);
+for (sal_uInt16 i = 0; i < 256; i++)
+{
+aRedPalette[i].SetRed(i);
+aRedPalette[i].SetGreen(0);
+aRedPalette[i].SetBlue(0);
+}
+{
+Bitmap aBitmap(Size(16, 16), vcl::PixelFormat::N8_BPP, &aRedPalette);
+{
+BitmapScopedWriteAccess pWriteAccessBitmap(aBitmap);
+for (int i = 0; i < 16; i++)
+{
+for (int j = 0; j < 16; j++)
+{
+pWriteAccessBitmap->SetPixelIndex(i, j, i * 16 + j);
+}
+}
+}
+BitmapEx aBitmapEx(aBitmap);
+vcl::PngImageWriter aPngWriter(aExportStream);
+CPPUNIT_ASSERT_EQUAL(true, aPngWriter.write(aBitmapEx));
+}
+aExportStream.Seek(0);
+{
+vcl::PngImageReader aPngReader(aExportStream);
+BitmapEx aBitmapEx;
+CPPUNIT_ASSERT_EQUAL(true, aPngReader.read(aBitmapEx));
+
+CPPUNIT_ASSERT_EQUAL(16L, aBitmapEx.GetSizePixel().Width());
+CPPUNIT_ASSERT_EQUAL(16L, aBitmapEx.GetSizePixel().Height());
+
+for (int i = 0; i < 16; i++)
+{
+for (int j = 0; j < 16; j++)
+{
+CPPUNIT_ASSERT_EQUAL(aRedPalette[i * 16 + j].GetRGBColor(),
+ aBitmapEx.GetPixelColor(j, i));
+}
+}
+}
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(PngFilterTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/filter/png/PngImageWriter.cxx 
b/vcl/source/filter/png/PngImageWriter.cxx
index 48399ba05018..6a123e4eb547 100644
--- a/vcl/source/filter/png/PngImageWriter.cxx
+++ b/vcl/source/filter/png/PngImageWriter.cxx
@@ -110,8 +110,9 @@ static bool pngWrite(SvStream& rStream, BitmapEx& 
rBitmapEx, int nCompressionLev
 case ScanlineFormat::N8BitPal:
 {
 if (!aBitmap.HasGreyPalette8Bit())
-return false;
-colorType = PNG_COLOR_TYPE_GRAY;
+colorType = PNG_COLOR_TYPE_PALETTE;
+else
+colorType = PNG_COLOR_TYPE_GRAY;
 bitDepth = 8;
 break;
 }


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

2022-07-19 Thread offtkp (via logerrit)
 vcl/qa/cppunit/png/PngFilterTest.cxx |   66 +++
 vcl/source/filter/png/PngImageWriter.cxx |   24 +++
 2 files changed, 90 insertions(+)

New commits:
commit 80395bf5f2bc7d48c690893abf8604540c24806f
Author: offtkp 
AuthorDate: Mon Jul 4 22:07:28 2022 +0300
Commit: Tomaž Vajngerl 
CommitDate: Tue Jul 19 09:59:03 2022 +0200

Add PngImageWriter 1 bit palette export support

Added support for exporting 1 bit palette png for non grayscale images
and unit test

Change-Id: I0b4c63c922fad4e42c7db61e81c553c69dd6bff6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136813
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/png/PngFilterTest.cxx 
b/vcl/qa/cppunit/png/PngFilterTest.cxx
index 81531f21b0e6..2eae9544ecbb 100644
--- a/vcl/qa/cppunit/png/PngFilterTest.cxx
+++ b/vcl/qa/cppunit/png/PngFilterTest.cxx
@@ -175,6 +175,7 @@ public:
 void testPngRoundtrip24();
 void testPngRoundtrip24_8();
 void testPngRoundtrip32();
+void testPngWrite1BitRGBPalette();
 
 CPPUNIT_TEST_SUITE(PngFilterTest);
 CPPUNIT_TEST(testPng);
@@ -184,6 +185,7 @@ public:
 CPPUNIT_TEST(testPngRoundtrip24);
 CPPUNIT_TEST(testPngRoundtrip24_8);
 CPPUNIT_TEST(testPngRoundtrip32);
+CPPUNIT_TEST(testPngWrite1BitRGBPalette);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -1863,6 +1865,70 @@ void PngFilterTest::testPngRoundtrip24_8()
 
 void PngFilterTest::testPngRoundtrip32() {}
 
+void PngFilterTest::testPngWrite1BitRGBPalette()
+{
+SvMemoryStream aExportStream;
+{
+BitmapPalette aPal;
+aPal.SetEntryCount(2);
+aPal[0] = COL_RED;
+aPal[1] = COL_GREEN;
+Bitmap aBitmap(Size(16, 16), vcl::PixelFormat::N1_BPP, &aPal);
+{
+BitmapScopedWriteAccess pWriteAccessBitmap(aBitmap);
+// Top left
+for (int i = 0; i < 8; i++)
+{
+for (int j = 0; j < 8; j++)
+{
+pWriteAccessBitmap->SetPixelIndex(i, j, 0);
+}
+}
+// Top right
+for (int i = 0; i < 8; i++)
+{
+for (int j = 8; j < 16; j++)
+{
+pWriteAccessBitmap->SetPixelIndex(i, j, 1);
+}
+}
+// Bottom left
+for (int i = 8; i < 16; i++)
+{
+for (int j = 0; j < 8; j++)
+{
+pWriteAccessBitmap->SetPixelIndex(i, j, 1);
+}
+}
+// Bottom right
+for (int i = 8; i < 16; i++)
+{
+for (int j = 8; j < 16; j++)
+{
+pWriteAccessBitmap->SetPixelIndex(i, j, 0);
+}
+}
+}
+BitmapEx aBitmapEx(aBitmap);
+vcl::PngImageWriter aPngWriter(aExportStream);
+CPPUNIT_ASSERT_EQUAL(true, aPngWriter.write(aBitmapEx));
+}
+aExportStream.Seek(0);
+{
+vcl::PngImageReader aPngReader(aExportStream);
+BitmapEx aBitmapEx;
+CPPUNIT_ASSERT_EQUAL(true, aPngReader.read(aBitmapEx));
+
+CPPUNIT_ASSERT_EQUAL(16L, aBitmapEx.GetSizePixel().Width());
+CPPUNIT_ASSERT_EQUAL(16L, aBitmapEx.GetSizePixel().Height());
+
+CPPUNIT_ASSERT_EQUAL(COL_RED, aBitmapEx.GetPixelColor(0, 0));
+CPPUNIT_ASSERT_EQUAL(COL_RED, aBitmapEx.GetPixelColor(15, 15));
+CPPUNIT_ASSERT_EQUAL(COL_GREEN, aBitmapEx.GetPixelColor(15, 0));
+CPPUNIT_ASSERT_EQUAL(COL_GREEN, aBitmapEx.GetPixelColor(0, 15));
+}
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(PngFilterTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/filter/png/PngImageWriter.cxx 
b/vcl/source/filter/png/PngImageWriter.cxx
index b83683b181da..48399ba05018 100644
--- a/vcl/source/filter/png/PngImageWriter.cxx
+++ b/vcl/source/filter/png/PngImageWriter.cxx
@@ -100,6 +100,13 @@ static bool pngWrite(SvStream& rStream, BitmapEx& 
rBitmapEx, int nCompressionLev
 auto eScanlineFormat = pAccess->GetScanlineFormat();
 switch (eScanlineFormat)
 {
+case ScanlineFormat::N1BitMsbPal:
+case ScanlineFormat::N1BitLsbPal:
+{
+colorType = PNG_COLOR_TYPE_PALETTE;
+bitDepth = 1;
+break;
+}
 case ScanlineFormat::N8BitPal:
 {
 if (!aBitmap.HasGreyPalette8Bit())
@@ -133,6 +140,23 @@ static bool pngWrite(SvStream& rStream, BitmapEx& 
rBitmapEx, int nCompressionLev
 int compressionType = PNG_COMPRESSION_TYPE_DEFAULT;
 int filterMethod = PNG_FILTER_TYPE_DEFAULT;
 
+// Convert BitmapPalette to png_color*
+if (colorType == PNG_COLOR_TYPE_PALETTE)
+{
+// Reserve enough space for 3 channels for each palette entry
+auto aBitmapPalette = pAccess->GetPalette();
+ 

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

2022-06-02 Thread Caolán McNamara (via logerrit)
 vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx |5 ++---
 vcl/source/filter/itiff/itiff.cxx  |7 +++
 2 files changed, 9 insertions(+), 3 deletions(-)

New commits:
commit 1577c0dc30ed3c9db361fb989e41a3e9d6c45dfa
Author: Caolán McNamara 
AuthorDate: Wed Jun 1 20:24:22 2022 +0100
Commit: Caolán McNamara 
CommitDate: Thu Jun 2 10:01:14 2022 +0200

tdf#149418 the expectation is on success the tiff stream pos is at EOF

which is what the old one did, so do that here as well, libtiff will
leave the stream some other pos by default, presumably the directory.

which explains the testTdf138818 mystery

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

diff --git a/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx 
b/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx
index d4fdeea43524..72f12ca565f5 100644
--- a/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx
+++ b/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx
@@ -113,7 +113,6 @@ void TiffFilterTest::testTdf115863()
 CPPUNIT_ASSERT_EQUAL(tools::Long(618), aSize.Height());
 }
 
-//TODO-check if this is still correct, looks ok, but what was it testing 
exactly
 void TiffFilterTest::testTdf138818()
 {
 OUString aURL = getUrl() + "tdf138818.tif";
@@ -126,9 +125,9 @@ void TiffFilterTest::testTdf138818()
 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult);
 
 // Without the fix in place, this test would have failed with
-// - Expected: 45953
+// - Expected: 46428
 // - Actual  : 45951
-CPPUNIT_ASSERT_EQUAL(sal_uInt32(45953), 
aGraphic.GetGfxLink().GetDataSize());
+CPPUNIT_ASSERT_EQUAL(sal_uInt32(46428), 
aGraphic.GetGfxLink().GetDataSize());
 }
 
 void TiffFilterTest::testTdf74331()
diff --git a/vcl/source/filter/itiff/itiff.cxx 
b/vcl/source/filter/itiff/itiff.cxx
index 672ef92d902a..1a7e48d1a3e9 100644
--- a/vcl/source/filter/itiff/itiff.cxx
+++ b/vcl/source/filter/itiff/itiff.cxx
@@ -113,6 +113,8 @@ bool ImportTiffGraphicImport(SvStream& rTIFF, Graphic& 
rGraphic)
 if (!tif)
 return false;
 
+const auto nOrigPos = rTIFF.Tell();
+
 Animation aAnimation;
 
 do
@@ -246,9 +248,14 @@ bool ImportTiffGraphicImport(SvStream& rTIFF, Graphic& 
rGraphic)
 rGraphic = aAnimation.GetBitmapEx();
 else
 rGraphic = aAnimation;
+
+// seek to end of TIFF if succeeded
+rTIFF.Seek(STREAM_SEEK_TO_END);
+
 return true;
 }
 
+rTIFF.Seek(nOrigPos);
 return false;
 }
 


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

2022-05-24 Thread Caolán McNamara (via logerrit)
 vcl/qa/cppunit/graphicfilter/data/tiff/fail/ofz47589.tiff |binary
 vcl/source/filter/itiff/itiff.cxx |  207 +++---
 2 files changed, 50 insertions(+), 157 deletions(-)

New commits:
commit e4977792c501305502100c0d45b5ca605981008f
Author: Caolán McNamara 
AuthorDate: Tue May 24 12:09:51 2022 +0100
Commit: Caolán McNamara 
CommitDate: Tue May 24 16:37:13 2022 +0200

ofz#47589 can't avoid passing in an output in the general case after all

there's a flip case which assumes the dest buffer is available, so
the 'ALTERNATE RASTER FORMATS' case of man TIFFRGBAImageGet isn't
as useful as it looked initially.

This reverts commit e912a446210fdae61be3fc04d20d90488cedcdf6, etc

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

diff --git a/vcl/qa/cppunit/graphicfilter/data/tiff/fail/ofz47589.tiff 
b/vcl/qa/cppunit/graphicfilter/data/tiff/fail/ofz47589.tiff
new file mode 100644
index ..936afbd992e4
Binary files /dev/null and 
b/vcl/qa/cppunit/graphicfilter/data/tiff/fail/ofz47589.tiff differ
diff --git a/vcl/source/filter/itiff/itiff.cxx 
b/vcl/source/filter/itiff/itiff.cxx
index 4514ce916959..b682d759f115 100644
--- a/vcl/source/filter/itiff/itiff.cxx
+++ b/vcl/source/filter/itiff/itiff.cxx
@@ -36,83 +36,10 @@ namespace
 {
 SvStream& rStream;
 tsize_t nSize;
-/*
-ORIENTATION_TOPLEFT = 1
-ORIENTATION_TOPRIGHT = 2
-ORIENTATION_BOTRIGHT = 3
-ORIENTATION_BOTLEFT = 4
-ORIENTATION_LEFTTOP = 5
-ORIENTATION_RIGHTTOP = 6
-ORIENTATION_RIGHTBOT = 7
-ORIENTATION_LEFTBOT = 8
- */
-uint16_t nOrientation;
-
-tileContigRoutine pOrigContig;
-tileSeparateRoutine pOrigSeparate;
-BitmapWriteAccess* pWriteAccess;
-BitmapWriteAccess* pAlphaAccess;
-std::vector aBuffer;
-
 Context(SvStream& rInStream, tsize_t nInSize)
 : rStream(rInStream)
 , nSize(nInSize)
-, nOrientation(0)
-, pOrigContig(nullptr)
-, pOrigSeparate(nullptr)
-, pWriteAccess(nullptr)
-, pAlphaAccess(nullptr)
-{
-}
-
-uint32_t* GetBuffer(uint32_t w, uint32_t h, int32_t toskew)
 {
-uint32_t nExtraPerRow;
-if (toskew >= 0)
-nExtraPerRow = toskew;
-else
-{
-int32_t nExtraNeg = w + toskew + w;
-nExtraPerRow = std::abs(nExtraNeg);
-}
-uint32_t nScanLine = w + nExtraPerRow;
-aBuffer.resize(nScanLine * h);
-uint32_t* pBuffer = aBuffer.data();
-if (toskew < 0)
-pBuffer += h * nScanLine - nScanLine;
-
-return pBuffer;
-}
-
-void SetPixels(uint32_t x, uint32_t y, uint32_t w, uint32_t h, const 
uint32_t* pSrc, int32_t skew)
-{
-uint32_t nDestRow = y;
-for (uint32_t nRow = 0; nRow < h; ++nRow)
-{
-for (uint32_t nCol = 0; nCol < w; ++nCol)
-{
-uint32_t nDestCol;
-switch (nOrientation)
-{
-case ORIENTATION_LEFTBOT:
-nDestCol = x + w - 1 - nCol;
-break;
-default:
-nDestCol = x + nCol;
-break;
-}
-
-pWriteAccess->SetPixel(nDestRow, nDestCol,
-Color(TIFFGetR(*pSrc), TIFFGetG(*pSrc), 
TIFFGetB(*pSrc)));
-pAlphaAccess->SetPixelIndex(nDestRow, nDestCol, 255 - 
TIFFGetA(*pSrc));
-++pSrc;
-}
-pSrc += skew;
-if (skew >= 0)
-++nDestRow;
-else
---nDestRow;
-}
 }
 };
 }
@@ -163,36 +90,6 @@ static toff_t tiff_size(thandle_t handle)
 return pContext->nSize;
 }
 
-static void putContigPixel(TIFFRGBAImage* img, uint32_t* /*raster*/,
-   uint32_t x, uint32_t y, uint32_t w, uint32_t h,
-   int32_t fromskew, int32_t toskew,
-   unsigned char* cp)
-{
-Context* pContext = static_cast(TIFFClientdata(img->tif));
-
-uint32_t* pBuffer = pContext->GetBuffer(w, h, toskew);
-
-(pContext->pOrigContig)(img, pBuffer, 0, 0, w, h,
-fromskew, toskew, cp);
-
-pContext->SetPixels(x, y, w, h, pBuffer, toskew);
-}
-
-static void putSeparatePixel(TIFFRGBAImage* img, uint32_t* /*raster*/,
- uint32_t x, uint32_t y, uint32_t w, uint32_t h,
-  

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

2022-05-02 Thread Stephan Bergmann (via logerrit)
 vcl/qa/api/XGraphicTest.cxx  |   18 +-
 vcl/qa/cppunit/filter/ipdf/ipdf.cxx  |2 +-
 vcl/qa/cppunit/pdfexport/pdfexport.cxx   |   14 +++---
 vcl/source/components/fontident.cxx  |2 +-
 vcl/source/control/managedmenubutton.cxx |6 +++---
 vcl/source/gdi/pdfwriter_impl2.cxx   |2 +-
 vcl/source/gdi/print3.cxx|   14 +++---
 vcl/source/gdi/vectorgraphicdata.cxx |4 ++--
 vcl/source/outdev/outdev.cxx |2 +-
 vcl/source/window/printdlg.cxx   |   10 +-
 vcl/source/window/winproc.cxx|4 ++--
 vcl/win/dtrans/DOTransferable.cxx|2 +-
 12 files changed, 40 insertions(+), 40 deletions(-)

New commits:
commit c8053f5a5629c04defd813b061f0d59d6bf15f88
Author: Stephan Bergmann 
AuthorDate: Mon May 2 22:23:07 2022 +0200
Commit: Stephan Bergmann 
CommitDate: Tue May 3 07:15:11 2022 +0200

Just use Any ctor instead of makeAny in vcl

Change-Id: Ib9b588cd10154049a5493c1be16de72955ea6077
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133736
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/vcl/qa/api/XGraphicTest.cxx b/vcl/qa/api/XGraphicTest.cxx
index afe50155a927..df05c05f9f4c 100644
--- a/vcl/qa/api/XGraphicTest.cxx
+++ b/vcl/qa/api/XGraphicTest.cxx
@@ -125,9 +125,9 @@ void XGraphicTest::testGraphicProvider()
 xGraphicProvider.set(graphic::GraphicProvider::create(xContext), 
uno::UNO_SET_THROW);
 
 auto aMediaProperties(comphelper::InitPropertySequence({
-{ "URL", uno::makeAny(aGraphicURL) },
-{ "LazyRead", uno::makeAny(true) },
-{ "LoadAsLink", uno::makeAny(false) },
+{ "URL", uno::Any(aGraphicURL) },
+{ "LazyRead", uno::Any(true) },
+{ "LoadAsLink", uno::Any(false) },
 }));
 
 uno::Reference xGraphic(
@@ -164,9 +164,9 @@ void XGraphicTest::testGraphicProvider()
 xGraphicProvider.set(graphic::GraphicProvider::create(xContext), 
uno::UNO_SET_THROW);
 
 auto aMediaProperties(comphelper::InitPropertySequence({
-{ "URL", uno::makeAny(aGraphicURL) },
-{ "LazyRead", uno::makeAny(false) },
-{ "LoadAsLink", uno::makeAny(true) },
+{ "URL", uno::Any(aGraphicURL) },
+{ "LazyRead", uno::Any(false) },
+{ "LoadAsLink", uno::Any(true) },
 }));
 
 uno::Reference xGraphic(
@@ -201,9 +201,9 @@ void XGraphicTest::testGraphicProvider()
 xGraphicProvider.set(graphic::GraphicProvider::create(xContext), 
uno::UNO_SET_THROW);
 
 auto aMediaProperties(comphelper::InitPropertySequence({
-{ "URL", uno::makeAny(aGraphicURL) },
-{ "LazyRead", uno::makeAny(true) },
-{ "LoadAsLink", uno::makeAny(true) },
+{ "URL", uno::Any(aGraphicURL) },
+{ "LazyRead", uno::Any(true) },
+{ "LoadAsLink", uno::Any(true) },
 }));
 
 uno::Reference xGraphic(
diff --git a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx 
b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
index a2732b58d862..ca5460e63b48 100644
--- a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
+++ b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
@@ -114,7 +114,7 @@ CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, 
testPDFAddVisibleSignatureLastPage)
 // Select it and assign a certificate.
 uno::Reference 
xSelectionSupplier(pBaseModel->getCurrentController(),
 
uno::UNO_QUERY);
-xSelectionSupplier->select(uno::makeAny(xShape));
+xSelectionSupplier->select(uno::Any(xShape));
 auto xCert = GetValidCertificate(
 
getSecurityContext()->getSecurityEnvironment()->getPersonalCertificates());
 if (!xCert)
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 0bfebea97464..54f9334a1607 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -1513,7 +1513,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf113143)
 // want to test.
 { "ReduceImageResolution", uno::Any(false) },
 // Set a custom PDF version.
-{ "SelectPdfVersion", uno::makeAny(static_cast(16)) },
+{ "SelectPdfVersion", uno::Any(static_cast(16)) },
 }));
 aMediaDescriptor["FilterData"] <<= aFilterData;
 saveAsPDF(u"tdf113143.odp");
@@ -2113,7 +2113,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, 
testPdfImageResourceInlineXObjectRef)
 xFactory->createInstance("com.sun.star.text.TextGraphicObject"), 
uno::UNO_QUERY);
 OUString aURL
 = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"pdf-image-resource-inline-xobject-ref.pdf";
-xGraphicObject->setPropertyValue("GraphicURL", uno::makeAny(aURL));
+xGraphicObject->setPropertyValue("GraphicURL", uno::Any(aURL));
 uno::Reference xShape(xGraphicObject, uno::UNO_QUERY);
 xShape->setSize(awt::Size(1000, 1

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

2022-05-01 Thread Caolán McNamara (via logerrit)
 vcl/qa/cppunit/graphicfilter/data/tiff/tdf74331.tif |binary
 vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx  |   51 
 vcl/source/filter/itiff/itiff.cxx   |  239 ++--
 3 files changed, 177 insertions(+), 113 deletions(-)

New commits:
commit 520d8c9ec7718cf6678614ecf18656dafcad9445
Author: Caolán McNamara 
AuthorDate: Fri Apr 29 13:18:47 2022 +0100
Commit: Caolán McNamara 
CommitDate: Sun May 1 11:03:13 2022 +0200

tdf#74331: 16bit "min-is-black" tiff not loaded correctly

try an alternative fix

git show -w is your friend here

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

diff --git a/vcl/qa/cppunit/graphicfilter/data/tiff/tdf74331.tif 
b/vcl/qa/cppunit/graphicfilter/data/tiff/tdf74331.tif
new file mode 100644
index ..702b8218ca5f
Binary files /dev/null and 
b/vcl/qa/cppunit/graphicfilter/data/tiff/tdf74331.tif differ
diff --git a/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx 
b/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx
index 5842acf9ae8d..72f12ca565f5 100644
--- a/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx
+++ b/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx
@@ -45,6 +45,7 @@ public:
 void testTdf126460();
 void testTdf115863();
 void testTdf138818();
+void testTdf74331();
 void testRoundtrip();
 void testRGB8bits();
 void testRGB16bits();
@@ -54,6 +55,7 @@ public:
 CPPUNIT_TEST(testTdf126460);
 CPPUNIT_TEST(testTdf115863);
 CPPUNIT_TEST(testTdf138818);
+CPPUNIT_TEST(testTdf74331);
 CPPUNIT_TEST(testRoundtrip);
 CPPUNIT_TEST(testRGB8bits);
 CPPUNIT_TEST(testRGB16bits);
@@ -128,6 +130,55 @@ void TiffFilterTest::testTdf138818()
 CPPUNIT_ASSERT_EQUAL(sal_uInt32(46428), 
aGraphic.GetGfxLink().GetDataSize());
 }
 
+void TiffFilterTest::testTdf74331()
+{
+OUString aURL = getUrl() + "tdf74331.tif";
+SvFileStream aFileStream(aURL, StreamMode::READ);
+Graphic aGraphic;
+GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
+
+ErrCode bResult = rFilter.ImportGraphic(aGraphic, aURL, aFileStream);
+
+CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult);
+
+Bitmap aBitmap = aGraphic.GetBitmapEx().GetBitmap();
+Size aSize = aBitmap.GetSizePixel();
+CPPUNIT_ASSERT_EQUAL(tools::Long(200), aSize.Width());
+CPPUNIT_ASSERT_EQUAL(tools::Long(200), aSize.Height());
+
+Bitmap::ScopedReadAccess pReadAccess(aBitmap);
+
+// Check the image contains different kinds of grays
+int nGrayCount = 0;
+int nGray3Count = 0;
+int nGray7Count = 0;
+int nLightGrayCount = 0;
+
+for (tools::Long nX = 1; nX < aSize.Width() - 1; ++nX)
+{
+for (tools::Long nY = 1; nY < aSize.Height() - 1; ++nY)
+{
+const Color aColor = pReadAccess->GetColor(nY, nX);
+if (aColor == COL_GRAY)
+++nGrayCount;
+else if (aColor == COL_GRAY3)
+++nGray3Count;
+else if (aColor == COL_GRAY7)
+++nGray7Count;
+else if (aColor == COL_LIGHTGRAY)
+++nLightGrayCount;
+}
+}
+
+// Without the fix in place, this test would have failed with
+// - Expected: 313
+// - Actual  : 0
+CPPUNIT_ASSERT_EQUAL(313, nGrayCount);
+CPPUNIT_ASSERT_EQUAL(71, nGray3Count);
+CPPUNIT_ASSERT_EQUAL(227, nGray7Count);
+CPPUNIT_ASSERT_EQUAL(165, nLightGrayCount);
+}
+
 void TiffFilterTest::testRoundtrip()
 {
 Bitmap aBitmap(Size(2, 2), vcl::PixelFormat::N24_BPP);
diff --git a/vcl/source/filter/itiff/itiff.cxx 
b/vcl/source/filter/itiff/itiff.cxx
index 7fa66b746c5d..f94864f429e0 100644
--- a/vcl/source/filter/itiff/itiff.cxx
+++ b/vcl/source/filter/itiff/itiff.cxx
@@ -978,156 +978,169 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY)
 {
 if ( nMaxSampleValue > nMinSampleValue )
 {
-sal_uInt32 nMinMax = ( ( 1 << nDstBitsPerPixel ) - 1 ) / ( 
nMaxSampleValue - nMinSampleValue );
 sal_uInt8* pt = getMapData(0);
 sal_uInt8* ptend = pt + nBytesPerRow;
-sal_uInt8 nShift;
 
-switch ( nDstBitsPerPixel )
+if (nBitsPerSample > 8)
 {
-case 8 :
+sal_uInt32 nMinMax = nMinSampleValue * 255 / ( nMaxSampleValue 
- nMinSampleValue );
+for (sal_Int32 nx = 0; nx < nImageWidth; ++nx)
 {
-if (pt + nImageWidth > ptend)
-return false;
+nVal = GetBits(pt, nx * nSamplesPerPixel * nBitsPerSample, 
nBitsPerSample);
+SetPixel(nY, nx, static_cast(nVal - nMinMax));
+}
+}
+else
+{
+sal_uInt32 nMinMax = ( ( 1 << nDstBitsPerPixel ) - 1 ) / ( 
nMaxSampleValue - nMinSampleValue )

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

2022-04-30 Thread Caolán McNamara (via logerrit)
 dev/null   |binary
 vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx |   51 -
 vcl/source/filter/itiff/itiff.cxx  |7 +-
 3 files changed, 3 insertions(+), 55 deletions(-)

New commits:
commit 1f81dd9b05c4eaa3e4caae8fe38ef2ee7eb1db49
Author: Caolán McNamara 
AuthorDate: Fri Apr 29 13:16:22 2022 +0100
Commit: Caolán McNamara 
CommitDate: Sat Apr 30 11:49:06 2022 +0200

ofz#47104 Revert "tdf#74331: 16bit "min-is-black" tiff not loaded correctly"

This reverts commit bd1d0967920655ef85a2352259332f99fef6876e.

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

diff --git a/vcl/qa/cppunit/graphicfilter/data/tiff/tdf74331.tif 
b/vcl/qa/cppunit/graphicfilter/data/tiff/tdf74331.tif
deleted file mode 100644
index 702b8218ca5f..
Binary files a/vcl/qa/cppunit/graphicfilter/data/tiff/tdf74331.tif and 
/dev/null differ
diff --git a/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx 
b/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx
index 72f12ca565f5..5842acf9ae8d 100644
--- a/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx
+++ b/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx
@@ -45,7 +45,6 @@ public:
 void testTdf126460();
 void testTdf115863();
 void testTdf138818();
-void testTdf74331();
 void testRoundtrip();
 void testRGB8bits();
 void testRGB16bits();
@@ -55,7 +54,6 @@ public:
 CPPUNIT_TEST(testTdf126460);
 CPPUNIT_TEST(testTdf115863);
 CPPUNIT_TEST(testTdf138818);
-CPPUNIT_TEST(testTdf74331);
 CPPUNIT_TEST(testRoundtrip);
 CPPUNIT_TEST(testRGB8bits);
 CPPUNIT_TEST(testRGB16bits);
@@ -130,55 +128,6 @@ void TiffFilterTest::testTdf138818()
 CPPUNIT_ASSERT_EQUAL(sal_uInt32(46428), 
aGraphic.GetGfxLink().GetDataSize());
 }
 
-void TiffFilterTest::testTdf74331()
-{
-OUString aURL = getUrl() + "tdf74331.tif";
-SvFileStream aFileStream(aURL, StreamMode::READ);
-Graphic aGraphic;
-GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
-
-ErrCode bResult = rFilter.ImportGraphic(aGraphic, aURL, aFileStream);
-
-CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult);
-
-Bitmap aBitmap = aGraphic.GetBitmapEx().GetBitmap();
-Size aSize = aBitmap.GetSizePixel();
-CPPUNIT_ASSERT_EQUAL(tools::Long(200), aSize.Width());
-CPPUNIT_ASSERT_EQUAL(tools::Long(200), aSize.Height());
-
-Bitmap::ScopedReadAccess pReadAccess(aBitmap);
-
-// Check the image contains different kinds of grays
-int nGrayCount = 0;
-int nGray3Count = 0;
-int nGray7Count = 0;
-int nLightGrayCount = 0;
-
-for (tools::Long nX = 1; nX < aSize.Width() - 1; ++nX)
-{
-for (tools::Long nY = 1; nY < aSize.Height() - 1; ++nY)
-{
-const Color aColor = pReadAccess->GetColor(nY, nX);
-if (aColor == COL_GRAY)
-++nGrayCount;
-else if (aColor == COL_GRAY3)
-++nGray3Count;
-else if (aColor == COL_GRAY7)
-++nGray7Count;
-else if (aColor == COL_LIGHTGRAY)
-++nLightGrayCount;
-}
-}
-
-// Without the fix in place, this test would have failed with
-// - Expected: 313
-// - Actual  : 0
-CPPUNIT_ASSERT_EQUAL(313, nGrayCount);
-CPPUNIT_ASSERT_EQUAL(71, nGray3Count);
-CPPUNIT_ASSERT_EQUAL(227, nGray7Count);
-CPPUNIT_ASSERT_EQUAL(165, nLightGrayCount);
-}
-
 void TiffFilterTest::testRoundtrip()
 {
 Bitmap aBitmap(Size(2, 2), vcl::PixelFormat::N24_BPP);
diff --git a/vcl/source/filter/itiff/itiff.cxx 
b/vcl/source/filter/itiff/itiff.cxx
index c9f73a742875..7fa66b746c5d 100644
--- a/vcl/source/filter/itiff/itiff.cxx
+++ b/vcl/source/filter/itiff/itiff.cxx
@@ -859,7 +859,7 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY)
 sal_uInt32  nRed, nGreen, nBlue, ns, nVal;
 sal_uInt8   nByteVal;
 
-if ( nDstBitsPerPixel == 24 || (nDstBitsPerPixel == 8 && 
nPhotometricInterpretation <= 1 && nSamplesPerPixel == 1) )
+if ( nDstBitsPerPixel == 24 )
 {
 if ( nBitsPerSample == 8 && nSamplesPerPixel >= 3 &&
  nPlanes == 1 && nPhotometricInterpretation == 2 )
@@ -904,8 +904,7 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY)
 }
 else if (
( nPhotometricInterpretation == 2 && nSamplesPerPixel >= 3 ) ||
-   ( nPhotometricInterpretation == 5 && nSamplesPerPixel == 3 ) ||
-   ( nPhotometricInterpretation <= 1 && nSamplesPerPixel == 1 )
+   ( nPhotometricInterpretation == 5 && nSamplesPerPixel == 3 )
 )
 {
 if ( nMaxSampleValue > nMinSampleValue )
@@ -925,7 +924,7 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY)
 nGreen = GetBits( getMapData(1), nx * nBitsPerSample, 
nBitsPerSample );
  

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

2022-03-12 Thread Caolán McNamara (via logerrit)
 vcl/qa/cppunit/graphicfilter/data/svm/pass/ofz45269-1.svm |binary
 vcl/source/filter/svm/SvmReader.cxx   |   35 +-
 2 files changed, 24 insertions(+), 11 deletions(-)

New commits:
commit 916aca240195b3e224ea374df4d447201bf852be
Author: Caolán McNamara 
AuthorDate: Fri Mar 11 15:33:44 2022 +
Commit: Caolán McNamara 
CommitDate: Sat Mar 12 13:23:28 2022 +0100

ofz#45269 Integer-overflow

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

diff --git a/vcl/qa/cppunit/graphicfilter/data/svm/pass/ofz45269-1.svm 
b/vcl/qa/cppunit/graphicfilter/data/svm/pass/ofz45269-1.svm
new file mode 100644
index ..4dceee3a9db4
Binary files /dev/null and 
b/vcl/qa/cppunit/graphicfilter/data/svm/pass/ofz45269-1.svm differ
diff --git a/vcl/source/filter/svm/SvmReader.cxx 
b/vcl/source/filter/svm/SvmReader.cxx
index 550e9e59bcfd..fe05c3439719 100644
--- a/vcl/source/filter/svm/SvmReader.cxx
+++ b/vcl/source/filter/svm/SvmReader.cxx
@@ -826,6 +826,24 @@ rtl::Reference SvmReader::BmpHandler()
 return pAction;
 }
 
+namespace
+{
+void sanitizeNegativeSizeDimensions(Size& rSize)
+{
+if (rSize.Width() < 0)
+{
+SAL_WARN("vcl.gdi", "sanitizeNegativeSizeDimensions: negative width");
+rSize.setWidth(0);
+}
+
+if (rSize.Height() < 0)
+{
+SAL_WARN("vcl.gdi", "sanitizeNegativeSizeDimensions: negative height");
+rSize.setHeight(0);
+}
+}
+}
+
 rtl::Reference SvmReader::BmpScaleHandler()
 {
 rtl::Reference pAction(new MetaBmpScaleAction);
@@ -836,8 +854,10 @@ rtl::Reference SvmReader::BmpScaleHandler()
 TypeSerializer aSerializer(mrStream);
 Point aPoint;
 aSerializer.readPoint(aPoint);
+
 Size aSz;
 aSerializer.readSize(aSz);
+sanitizeNegativeSizeDimensions(aSz);
 
 pAction->SetBitmap(aBmp);
 pAction->SetPoint(aPoint);
@@ -902,17 +922,7 @@ rtl::Reference SvmReader::BmpExScaleHandler()
 
 Size aSize;
 aSerializer.readSize(aSize);
-if (aSize.Width() < 0)
-{
-SAL_WARN("vcl.gdi", "MetaBmpExScaleAction: negative width");
-aSize.setWidth(0);
-}
-
-if (aSize.Height() < 0)
-{
-SAL_WARN("vcl.gdi", "MetaBmpExScaleAction: negative height");
-aSize.setHeight(0);
-}
+sanitizeNegativeSizeDimensions(aSize);
 
 pAction->SetBitmapEx(aBmpEx);
 pAction->SetPoint(aPoint);
@@ -1300,8 +1310,11 @@ rtl::Reference 
SvmReader::FloatTransparentHandler(ImplMetaReadData*
 TypeSerializer aSerializer(mrStream);
 Point aPoint;
 aSerializer.readPoint(aPoint);
+
 Size aSize;
 aSerializer.readSize(aSize);
+sanitizeNegativeSizeDimensions(aSize);
+
 Gradient aGradient;
 aSerializer.readGradient(aGradient);
 


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

2022-03-09 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/pdfexport/data/pdf-image-annots.odg |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |   20 
 vcl/source/gdi/pdfwriter_impl.cxx  |   16 ++--
 3 files changed, 34 insertions(+), 2 deletions(-)

New commits:
commit 63dba12b779dd4d007c8cb8cf4b967bd78077cac
Author: Miklos Vajna 
AuthorDate: Wed Mar 9 13:36:27 2022 +0100
Commit: Miklos Vajna 
CommitDate: Wed Mar 9 17:11:49 2022 +0100

PDF export of PDF images: don't preserve annotations in general

Regression from 33c9bc0225a92f26770f9ef20b252af47853e7b9 (PDF export of
PDF images: preserve hyperlinks, 2022-01-07), the problem was that we
want to preserve hyperlinks, but annotations are added by the PDF export
explicitly, so it isn't a good idea to "preserve" them as well.

Fix the problem by going back to the old behavior, except when the
annotation sub-type is /Link.

This keeps hyperlinks working but doesn't lead to duplicated comments
when re-exporting an image + adding comments explicitly.

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

diff --git a/vcl/qa/cppunit/pdfexport/data/pdf-image-annots.odg 
b/vcl/qa/cppunit/pdfexport/data/pdf-image-annots.odg
new file mode 100644
index ..6dee0145c536
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/pdf-image-annots.odg 
differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index e7f2354b9118..0ebf70becdb3 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -3148,6 +3148,26 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testURIs)
 CPPUNIT_ASSERT_EQUAL(URIs[i].out, pURIElem->GetValue());
 }
 }
+
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfImageAnnots)
+{
+// Given a document with a PDF image that has 2 comments (popup, text) and 
a hyperlink:
+aMediaDescriptor["FilterName"] <<= OUString("draw_pdf_Export");
+
+// When saving to PDF:
+saveAsPDF(u"pdf-image-annots.odg");
+
+// Then make sure only the hyperlink is kept, since Draw itself has its 
own comments:
+std::unique_ptr pPdfDocument = parseExport();
+CPPUNIT_ASSERT(pPdfDocument);
+std::unique_ptr pPdfPage = 
pPdfDocument->openPage(/*nIndex=*/0);
+CPPUNIT_ASSERT(pPdfPage);
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 1
+// - Actual  : 3
+// i.e. not only the hyperlink but also the 2 comments were exported, 
leading to duplication.
+CPPUNIT_ASSERT_EQUAL(1, pPdfPage->getAnnotationCount());
+}
 } // end anonymous namespace
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 51291604fe51..6477163c1b78 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -8440,7 +8440,7 @@ void PDFWriterImpl::writeReferenceXObject(const 
ReferenceXObjectEmit& rEmit)
 return;
 }
 
-// Merge page annotations (links, etc) from pPage to our page.
+// Merge link annotations from pPage to our page.
 std::vector aAnnots;
 if (auto pArray = 
dynamic_cast(pPage->Lookup("Annots")))
 {
@@ -8458,7 +8458,19 @@ void PDFWriterImpl::writeReferenceXObject(const 
ReferenceXObjectEmit& rEmit)
 continue;
 }
 
-// Annotation refers to an object, remember it.
+auto pType = 
dynamic_cast(pObject->Lookup("Type"));
+if (!pType || pType->GetValue() != "Annot")
+{
+continue;
+}
+
+auto pSubtype = 
dynamic_cast(pObject->Lookup("Subtype"));
+if (!pSubtype || pSubtype->GetValue() != "Link")
+{
+continue;
+}
+
+// Reference to a link annotation object, remember it.
 aAnnots.push_back(pObject);
 }
 }


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

2022-03-09 Thread Dr. David Alan Gilbert (via logerrit)
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |6 ++
 vcl/source/gdi/pdfwriter_impl.cxx  |   16 ++--
 2 files changed, 16 insertions(+), 6 deletions(-)

New commits:
commit 9579737b36e5055d5eb72abc0ace2b9b65600c76
Author: Dr. David Alan Gilbert 
AuthorDate: Sat Nov 13 01:33:06 2021 +
Commit: Stephan Bergmann 
CommitDate: Wed Mar 9 14:05:27 2022 +0100

tdf#143216: pdfwriter: Don't treat semi-valid URIs as local paths

Currently the PDF writer treats URIs that are rejected by INetURIObject,
as local files, and prepends a path to them.  For URIs that are valid
according to the basic URI syntax, but unhandled by INetURIObject
(such as http://user:password@domain) this produces a confusing result
with a ./uri in the PDF.

Avoid the prefixing where the URI follows the basic URI syntax, even
if INetURIObject didn't like it.

Change-Id: I87c599885a40fd7101c678ae79f83f594d0f23ee
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125202
Reviewed-by: Stephan Bergmann 
Tested-by: Jenkins

diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 35ca1c9bc051..e7f2354b9118 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -3049,6 +3049,12 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testURIs)
 "file://localfile.odt/",
 true,
 },
+{
+// tdf 143216
+"http://username:passw...@example.com";,
+"http://username:passw...@example.com";,
+true,
+},
 {
 "git://git.example.org/project/example",
 "git://git.example.org/project/example",
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 21f085fe2660..51291604fe51 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -47,6 +47,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -3280,6 +3281,7 @@ we check in the following sequence:
 boolbTargetHasPDFExtension = false;
 INetProtocol eTargetProtocol = aTargetURL.GetProtocol();
 boolbIsUNCPath = false;
+boolbUnparsedURI = false;
 
 // check if the protocol is a known one, or if there is no 
protocol at all (on target only)
 // if there is no protocol, make the target relative to the 
current document directory
@@ -3292,14 +3294,14 @@ we check in the following sequence:
 }
 else
 {
-INetURLObject aNewBase( aDocumentURL );//duplicate 
document URL
-aNewBase.removeSegment(); //remove last segment from it, 
obtaining the base URL of the
-  //target document
-aNewBase.insertName( url );
-aTargetURL = aNewBase;//reassign the new target URL
+INetURLObject 
aNewURL(rtl::Uri::convertRelToAbs(m_aContext.BaseURL, url));
+aTargetURL = aNewURL; //reassign the new target URL
+
 //recompute the target protocol, with the new URL
 //normal URL processing resumes
 eTargetProtocol = aTargetURL.GetProtocol();
+
+bUnparsedURI = eTargetProtocol == INetProtocol::NotValid;
 }
 }
 
@@ -3415,7 +3417,9 @@ we check in the following sequence:
 //substitute the fragment
 aTargetURL.SetMark( 
OStringToOUString(aLineLoc.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US) );
 }
-OUString aURL = aTargetURL.GetMainURL( bFileSpec ? 
INetURLObject::DecodeMechanism::WithCharset : 
INetURLObject::DecodeMechanism::NONE );
+OUString aURL = bUnparsedURI ? url :
+   aTargetURL.GetMainURL( 
bFileSpec ? INetURLObject::DecodeMechanism::WithCharset :
+   
   INetURLObject::DecodeMechanism::NONE );
 appendLiteralStringEncrypt(bSetRelative ? 
INetURLObject::GetRelURL( m_aContext.BaseURL, aURL,

 INetURLObject::EncodeMechanism::WasEncoded,

 bFileSpec ? INetURLObject::DecodeMechanism::WithCharset : 
INetURLObject::DecodeMechanism::NONE


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

2022-02-04 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |   42 +
 vcl/source/gdi/pdfwriter_impl.cxx  |4 +--
 2 files changed, 44 insertions(+), 2 deletions(-)

New commits:
commit 50682cea4196819980c8e2d4018f80384097ce6f
Author: Miklos Vajna 
AuthorDate: Fri Feb 4 10:55:28 2022 +0100
Commit: Miklos Vajna 
CommitDate: Fri Feb 4 16:42:55 2022 +0100

PDF export: improve precision of pdf image sizes

This helps exporting full-page PDF images from Draw more accurately. In
case the page size was A4, then the page height is 841.8897637795276
i.e. 842 points. Full-page PDF images are scaled to this size, so the
referred PDF form XObject has the reciprocal of that scaling.  We used
to just write 0.00118, doubling the precision leads to
0.0011878840.

In practice the old precision resulted in e.g. hyperlink rectangles to
get out of sync with link text after 2 roundtrips, while the new
precision doesn't result in any noticeable modification to the link text
position after a roundtrip.

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

diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 2906be647d22..9bc315fcb2bd 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -41,6 +41,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -2934,6 +2935,47 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, 
testPdfImageHyperlink)
 // Without the accompanying fix in place, this test would have failed, the 
hyperlink of the PDF
 // image was lost.
 CPPUNIT_ASSERT(pPdfPage->hasLinks());
+
+// Also test the precision of the form XObject.
+// Given a full-page form XObject, page height is 27.94 cm (792 points):
+// When writing the reciprocal of the object height to PDF:
+std::unique_ptr pFormObject;
+for (int i = 0; i < pPdfPage->getObjectCount(); ++i)
+{
+std::unique_ptr pObject = 
pPdfPage->getObject(i);
+if (pObject->getType() == vcl::pdf::PDFPageObjectType::Form)
+{
+pFormObject = std::move(pObject);
+break;
+}
+}
+CPPUNIT_ASSERT(pFormObject);
+std::unique_ptr pInnerFormObject;
+for (int i = 0; i < pFormObject->getFormObjectCount(); ++i)
+{
+std::unique_ptr pObject = 
pFormObject->getFormObject(i);
+if (pObject->getType() == vcl::pdf::PDFPageObjectType::Form)
+{
+pInnerFormObject = std::move(pObject);
+break;
+}
+}
+CPPUNIT_ASSERT(pInnerFormObject);
+// Then make sure that enough digits are used, so the point size is 
unchanged:
+basegfx::B2DHomMatrix aMatrix = pInnerFormObject->getMatrix();
+basegfx::B2DTuple aScale;
+basegfx::B2DTuple aTranslate;
+double fRotate{};
+double fShearX{};
+aMatrix.decompose(aScale, aTranslate, fRotate, fShearX);
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 0.0012626264
+// - Actual  : 0.00126
+// i.e. the rounded reciprocal was 794 points, not the original 792.
+// FIXME macOS actual value is 0.0001578282, for unknown reasons.
+#if !defined MACOSX
+CPPUNIT_ASSERT_EQUAL(0.0012626264, rtl::math::round(aScale.getY(), 10));
+#endif
 }
 
 } // end anonymous namespace
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 0af6cc78f221..71e1292baaf1 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -8568,9 +8568,9 @@ void PDFWriterImpl::writeReferenceXObject(const 
ReferenceXObjectEmit& rEmit)
 
 aLine.append(">> >>");
 aLine.append(" /Matrix [ ");
-appendDouble(fScaleX, aLine);
+appendDouble(fScaleX, aLine, /*nPrecision=*/10);
 aLine.append(" 0 0 ");
-appendDouble(fScaleY, aLine);
+appendDouble(fScaleY, aLine, /*nPrecision=*/10);
 aLine.append(" 0 0 ]");
 aLine.append(" /BBox [ 0 0 ");
 aLine.append(aSize.Width());


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

2022-01-07 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/pdfexport/data/pdf-image-hyperlink.odg |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx|   18 +
 vcl/source/gdi/pdfwriter_impl.cxx |   35 ++
 3 files changed, 53 insertions(+)

New commits:
commit 1984a5c140cc3c7c291047dacf3bddd7061d2047
Author: Miklos Vajna 
AuthorDate: Fri Jan 7 12:23:34 2022 +0100
Commit: Miklos Vajna 
CommitDate: Fri Jan 7 14:59:22 2022 +0100

PDF export of PDF images: preserve hyperlinks

The input file has a single page, with a full-page PDF image, which
contains a hyperlink. Similar to pdfcrop, we used to wrap this into a
form XObject, so page-level annotations like hyperlinks were lost.

Explicitly merge page-level annotations from the source page to the page
that contains the PDF image to preserve those annotations.

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

diff --git a/vcl/qa/cppunit/pdfexport/data/pdf-image-hyperlink.odg 
b/vcl/qa/cppunit/pdfexport/data/pdf-image-hyperlink.odg
new file mode 100644
index ..aa0f89300b2c
Binary files /dev/null and 
b/vcl/qa/cppunit/pdfexport/data/pdf-image-hyperlink.odg differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index af5f396db14d..7c6e273bf173 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -2872,6 +2872,24 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf145873)
 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.49, pObject->getBounds().getHeight(), 0.1);
 }
 
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfImageHyperlink)
+{
+// Given a Draw file, containing a PDF image, which has a hyperlink in it:
+aMediaDescriptor["FilterName"] <<= OUString("draw_pdf_Export");
+
+// When saving to PDF:
+saveAsPDF(u"pdf-image-hyperlink.odg");
+
+// Then make sure that link is preserved:
+std::unique_ptr pPdfDocument = parseExport();
+CPPUNIT_ASSERT(pPdfDocument);
+std::unique_ptr pPdfPage = 
pPdfDocument->openPage(/*nIndex=*/0);
+CPPUNIT_ASSERT(pPdfPage);
+// Without the accompanying fix in place, this test would have failed, the 
hyperlink of the PDF
+// image was lost.
+CPPUNIT_ASSERT(pPdfPage->hasLinks());
+}
+
 } // end anonymous namespace
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 53552f4ec4c8..d102108a8513 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -8434,6 +8434,41 @@ void PDFWriterImpl::writeReferenceXObject(const 
ReferenceXObjectEmit& rEmit)
 return;
 }
 
+// Merge page annotations (links, etc) from pPage to our page.
+std::vector aAnnots;
+if (auto pArray = 
dynamic_cast(pPage->Lookup("Annots")))
+{
+for (const auto pElement : pArray->GetElements())
+{
+auto pReference = 
dynamic_cast(pElement);
+if (!pReference)
+{
+continue;
+}
+
+filter::PDFObjectElement* pObject = pReference->LookupObject();
+if (!pObject)
+{
+continue;
+}
+
+// Annotation refers to an object, remember it.
+aAnnots.push_back(pObject);
+}
+}
+if (!aAnnots.empty())
+{
+PDFObjectCopier aCopier(*this);
+SvMemoryStream& rDocBuffer = pPage->GetDocument().GetEditBuffer();
+std::map aMap;
+for (const auto& pAnnot : aAnnots)
+{
+// Copy over the annotation and refer to its new id.
+sal_Int32 nNewId = aCopier.copyExternalResource(rDocBuffer, 
*pAnnot, aMap);
+m_aPages.back().m_aAnnotations.push_back(nNewId);
+}
+}
+
 nWrappedFormObject = createObject();
 // Write the form XObject wrapped below. This is a separate object from
 // the wrapper, this way there is no need to alter the stream contents.


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

2022-01-06 Thread Andras Timar (via logerrit)
 vcl/qa/cppunit/BmpFilterTest.cxx |   13 +
 vcl/qa/cppunit/data/tdf73523.bmp |binary
 vcl/source/bitmap/dibtools.cxx   |   34 --
 3 files changed, 37 insertions(+), 10 deletions(-)

New commits:
commit 3a0d539b3a8a76efc2cdac04c658645fe750bec4
Author: Andras Timar 
AuthorDate: Mon Jan 3 22:12:01 2022 +0100
Commit: Andras Timar 
CommitDate: Thu Jan 6 23:12:13 2022 +0100

tdf#73523 support WinBMPv3-NT version of BMP files (found in Visio files)

It is a special case when there are additional 12 bytes of color bitfields
after the info header. See also the useful comments at

https://searchfox.org/mozilla-central/source/image/decoders/nsBMPDecoder.cpp#47

It turned out we generate this type of BMP files internally from EMF files,
but in that case the bfOffBits of BITMAPFILEHEADER struct points to the
pixel data. In case of Visio, bfOffBits points to the color mask. There was
no better solution than preventing jumping back in the stream.

Change-Id: I97f0fd4f184ea77beeab8b22fc98fdb78472d9bb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127920
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127927
Tested-by: Jenkins
Reviewed-by: Andras Timar 

diff --git a/vcl/qa/cppunit/BmpFilterTest.cxx b/vcl/qa/cppunit/BmpFilterTest.cxx
index 20be739d0e98..1ab7bc2a0a4a 100644
--- a/vcl/qa/cppunit/BmpFilterTest.cxx
+++ b/vcl/qa/cppunit/BmpFilterTest.cxx
@@ -204,4 +204,17 @@ CPPUNIT_TEST_FIXTURE(BmpFilterTest, testBMP_V2)
 CPPUNIT_ASSERT_EQUAL(COL_LIGHTGREEN, aBitmap.GetPixelColor(2, 2));
 }
 
+CPPUNIT_TEST_FIXTURE(BmpFilterTest, testTdf73523)
+{
+SvFileStream aFileStream(getFullUrl(u"tdf73523.bmp"), StreamMode::READ);
+Graphic aGraphic;
+CPPUNIT_ASSERT(BmpReader(aFileStream, aGraphic));
+auto aBitmap = aGraphic.GetBitmapEx();
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: c[8000]
+// - Actual  : c[]
+// i.e. the pixel is red not black
+CPPUNIT_ASSERT_EQUAL(COL_RED, aBitmap.GetPixelColor(0, 0));
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qa/cppunit/data/tdf73523.bmp b/vcl/qa/cppunit/data/tdf73523.bmp
new file mode 100644
index ..f4364ea3e841
Binary files /dev/null and b/vcl/qa/cppunit/data/tdf73523.bmp differ
diff --git a/vcl/qa/cppunit/graphicfilter/data/bmp/fail/crash-1.bmp 
b/vcl/qa/cppunit/graphicfilter/data/bmp/pass/crash-1.bmp
similarity index 100%
rename from vcl/qa/cppunit/graphicfilter/data/bmp/fail/crash-1.bmp
rename to vcl/qa/cppunit/graphicfilter/data/bmp/pass/crash-1.bmp
diff --git a/vcl/source/bitmap/dibtools.cxx b/vcl/source/bitmap/dibtools.cxx
index 65117319afe5..96b82b9a7b86 100644
--- a/vcl/source/bitmap/dibtools.cxx
+++ b/vcl/source/bitmap/dibtools.cxx
@@ -246,8 +246,18 @@ bool ImplReadDIBInfoHeader(SvStream& rIStm, DIBV5Header& 
rHeader, bool& bTopDown
 readUInt32( rHeader.nV5ProfileSize );
 readUInt32( rHeader.nV5Reserved );
 
+// Read color mask. An additional 12 bytes of color bitfields follow 
the info header (WinBMPv3-NT)
+sal_uInt32 nColorMask = 0;
+if (BITFIELDS == rHeader.nCompression && DIBINFOHEADERSIZE == 
rHeader.nSize)
+{
+rIStm.ReadUInt32( rHeader.nV5RedMask );
+rIStm.ReadUInt32( rHeader.nV5GreenMask );
+rIStm.ReadUInt32( rHeader.nV5BlueMask );
+nColorMask = 12;
+}
+
 // seek to EndPos
-if (!checkSeek(rIStm, aStartPos + rHeader.nSize))
+if (!checkSeek(rIStm, aStartPos + rHeader.nSize + nColorMask))
 return false;
 }
 
@@ -530,14 +540,12 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& 
rHeader, BitmapWriteAccess& r
 }
 else
 {
-// Read color mask
-if(bTCMask && BITFIELDS == rHeader.nCompression)
-{
-rIStm.SeekRel( -12 );
-rIStm.ReadUInt32( nRMask );
-rIStm.ReadUInt32( nGMask );
-rIStm.ReadUInt32( nBMask );
-}
+if (rHeader.nV5RedMask > 0)
+nRMask = rHeader.nV5RedMask;
+if (rHeader.nV5GreenMask > 0)
+nGMask = rHeader.nV5GreenMask;
+if (rHeader.nV5BlueMask > 0)
+nBMask = rHeader.nV5BlueMask;
 
 const tools::Long nWidth(rHeader.nWidth);
 const tools::Long nHeight(rHeader.nHeight);
@@ -908,7 +916,13 @@ bool ImplReadDIBBody(SvStream& rIStm, Bitmap& rBmp, 
AlphaMask* pBmpAlpha, sal_uI
 
 if (nOffset)
 {
-pIStm->SeekRel(nOffset - (pIStm->Tell() - nStmPos));
+// It is problematic to seek backwards. We are at the
+// end of BITMAPINFOHEADER or 12 bytes further in case
+// of WinBMPv3-NT format. It is possible to seek forward
+// though because a gap may be there.
+sal_Int32 nSeekRel = nOffset - (pIStm->Te

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

2021-12-26 Thread Chris Sherlock (via logerrit)
 vcl/qa/cppunit/outdev.cxx  |  112 -
 vcl/source/outdev/gradient.cxx |   46 +---
 2 files changed, 106 insertions(+), 52 deletions(-)

New commits:
commit 1de7e1f4640bad725626b574b33eb2db9244f378
Author: Chris Sherlock 
AuthorDate: Tue Dec 14 19:09:39 2021 +1100
Commit: Tomaž Vajngerl 
CommitDate: Mon Dec 27 03:47:28 2021 +0100

vcl: remove unnecessary actions from DrawGradientToMetafile()

It turns out, we never actually needed to decompose the gradient into
seperate actions in DrawGradientToMetafile(). We still need this for
AddGradientActions() however.

Update tests and add new ones for AddGradientActions().

Change-Id: I2115da8e7d1efa5bcd2a8f4f00d9678216549e4f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126846
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index 469a24521643..dc2ea8ad2ed2 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -10,6 +10,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -93,9 +94,12 @@ public:
 void testDrawGradient_drawmode();
 void testDrawGradient_rect_linear();
 void testDrawGradient_rect_axial();
+void testAddGradientActions_rect_linear();
+void testAddGradientActions_rect_axial();
 void testDrawGradient_polygon_linear();
 void testDrawGradient_polygon_axial();
 void testDrawGradient_rect_complex();
+void testAddGradientActions_rect_complex();
 
 CPPUNIT_TEST_SUITE(VclOutdevTest);
 CPPUNIT_TEST(testVirtualDevice);
@@ -152,9 +156,12 @@ public:
 CPPUNIT_TEST(testDrawGradient_drawmode);
 CPPUNIT_TEST(testDrawGradient_rect_linear);
 CPPUNIT_TEST(testDrawGradient_rect_axial);
+CPPUNIT_TEST(testAddGradientActions_rect_linear);
+CPPUNIT_TEST(testAddGradientActions_rect_axial);
 CPPUNIT_TEST(testDrawGradient_polygon_linear);
 CPPUNIT_TEST(testDrawGradient_polygon_axial);
 CPPUNIT_TEST(testDrawGradient_rect_complex);
+CPPUNIT_TEST(testAddGradientActions_rect_complex);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -2135,12 +2142,12 @@ static size_t TestLinearStripes(GDIMetaFile& rMtf, 
size_t nTimes, size_t nIndex)
 {
 nIndex++;
 MetaAction* pAction = rMtf.GetAction(nIndex);
-CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", 
MetaActionType::FILLCOLOR,
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action (start)", 
MetaActionType::FILLCOLOR,
  pAction->GetType());
 
 nIndex++;
 pAction = rMtf.GetAction(nIndex);
-CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action", 
MetaActionType::POLYGON,
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action (start)", 
MetaActionType::POLYGON,
  pAction->GetType());
 
 for (size_t i = 0; i < nTimes - 1; i++)
@@ -2158,12 +2165,12 @@ static size_t TestLinearStripes(GDIMetaFile& rMtf, 
size_t nTimes, size_t nIndex)
 
 nIndex++;
 pAction = rMtf.GetAction(nIndex);
-CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", 
MetaActionType::FILLCOLOR,
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action (end)", 
MetaActionType::FILLCOLOR,
  pAction->GetType());
 
 nIndex++;
 pAction = rMtf.GetAction(nIndex);
-CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action", 
MetaActionType::POLYGON,
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action (end)", 
MetaActionType::POLYGON,
  pAction->GetType());
 
 return nIndex;
@@ -2236,6 +2243,35 @@ void VclOutdevTest::testDrawGradient_rect_linear()
 MetaAction* pAction = aMtf.GetAction(nIndex);
 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a gradient action (rectangle area)", 
MetaActionType::GRADIENT,
  pAction->GetType());
+}
+
+void VclOutdevTest::testAddGradientActions_rect_linear()
+{
+ScopedVclPtrInstance pVDev;
+GDIMetaFile aMtf;
+
+tools::Rectangle aRect(Point(10, 10), Size(40, 40));
+pVDev->SetOutputSizePixel(Size(100, 100));
+
+Gradient aGradient(GradientStyle::Linear, COL_RED, COL_WHITE);
+aGradient.SetBorder(100);
+
+pVDev->AddGradientActions(aRect, aGradient, aMtf);
+
+size_t nIndex = 0;
+
+MetaAction* pAction = aMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a push action", MetaActionType::PUSH, 
pAction->GetType());
+
+nIndex++;
+pAction = aMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a rectangular intersect clip action",
+ MetaActionType::ISECTRECTCLIPREGION, 
pAction->GetType());
+
+nIndex++;
+pAction = aMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a line color action", 
MetaActionType::LINECOLOR,
+ pAction->GetType());
 
 TestLinearStripes(aMtf, 3, nIndex);
 }
@@ -2259,6 +2295,35 @@ void VclOutd

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

2021-12-14 Thread Hossein (via logerrit)
 vcl/qa/cppunit/physicalfontcollection.cxx  |   14 ++
 vcl/source/font/PhysicalFontCollection.cxx |   24 +---
 2 files changed, 31 insertions(+), 7 deletions(-)

New commits:
commit ddd675c5a79b26d23da8d4affeeb888ac3664635
Author: Hossein 
AuthorDate: Wed Dec 15 02:15:52 2021 +0100
Commit: Hossein 
CommitDate: Wed Dec 15 03:17:56 2021 +0100

tdf#144961 vcl: fix CJK matching in FindFontFamilyByAttributes

Whilst testing CJK matching, I uncovered an issue. The matching
algorithm detects that the font is a CJK font if there are any CJK
characters in the font name. However, if you searched for a CJK font
against a font that was not a CJK font (i.e. the family name had no
CJK characters) then it would still match against this font family.

We now check if the font being matched against was a CJK font family
or not, if not then I reduced the testMatch value by CJK_MATCH_VALUE.

The fix can be tested with:

make CPPUNIT_TEST_NAME=testShouldNotFindCJKFamily -sr \
CppunitTest_vcl_font

Without the fix in place, the test fails with:

Test name: VclPhysicalFontCollectionTest::testShouldNotFindCJKFamily
assertion failed
- Expression: !aFontCollection.FindFontFamilyByAttributes( 
ImplFontAttrs::CJK, WEIGHT_NORMAL, WIDTH_NORMAL, ITALIC_NONE, "")
- family found

Change-Id: I18b246f151b2174dc4ae0f5507630a4e8e4bb442
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123309
Tested-by: Jenkins
Reviewed-by: Hossein 

diff --git a/vcl/qa/cppunit/physicalfontcollection.cxx 
b/vcl/qa/cppunit/physicalfontcollection.cxx
index a147fb1dea4f..7df20ce76b66 100644
--- a/vcl/qa/cppunit/physicalfontcollection.cxx
+++ b/vcl/qa/cppunit/physicalfontcollection.cxx
@@ -35,6 +35,7 @@ public:
 void testShouldFindFontFamilyByTokenNames();
 void testShouldFindNoFamilyWithWorthlessAttributes();
 void testShouldFindCJKFamily();
+void testShouldNotFindCJKFamily();
 void testShouldFindStarsymbolFamily();
 void testShouldFindOpensymbolFamilyWithMultipleSymbolFamilies();
 void testShouldFindSymboltypeFamily();
@@ -65,6 +66,7 @@ public:
 CPPUNIT_TEST(testShouldFindFontFamilyByTokenNames);
 CPPUNIT_TEST(testShouldFindNoFamilyWithWorthlessAttributes);
 CPPUNIT_TEST(testShouldFindCJKFamily);
+CPPUNIT_TEST(testShouldNotFindCJKFamily);
 CPPUNIT_TEST(testShouldFindStarsymbolFamily);
 CPPUNIT_TEST(testShouldFindOpensymbolFamilyWithMultipleSymbolFamilies);
 CPPUNIT_TEST(testShouldFindSymboltypeFamily);
@@ -186,6 +188,18 @@ void 
VclPhysicalFontCollectionTest::testShouldFindCJKFamily()
  pCJKFamily->GetSearchName());
 }
 
+void VclPhysicalFontCollectionTest::testShouldNotFindCJKFamily()
+{
+vcl::font::PhysicalFontCollection aFontCollection;
+vcl::font::PhysicalFontFamily* pFontFamily
+= aFontCollection.FindOrCreateFontFamily(GetEnglishSearchFontName(u"No 
CJK characters"));
+AddNormalFontFace(pFontFamily, "No CJK characters");
+
+CPPUNIT_ASSERT_MESSAGE("family found",
+   !aFontCollection.FindFontFamilyByAttributes(
+   ImplFontAttrs::CJK, WEIGHT_NORMAL, 
WIDTH_NORMAL, ITALIC_NONE, ""));
+}
+
 void VclPhysicalFontCollectionTest::testShouldFindStarsymbolFamily()
 {
 vcl::font::PhysicalFontCollection aFontCollection;
diff --git a/vcl/source/font/PhysicalFontCollection.cxx 
b/vcl/source/font/PhysicalFontCollection.cxx
index 0cb503a7df54..211e4e65bd57 100644
--- a/vcl/source/font/PhysicalFontCollection.cxx
+++ b/vcl/source/font/PhysicalFontCollection.cxx
@@ -445,13 +445,23 @@ PhysicalFontFamily* 
PhysicalFontCollection::FindFontFamilyByAttributes(ImplFontA
 // test CJK script attributes
 if ( nSearchType & ImplFontAttrs::CJK )
 {
-// Matching language
-if( ImplFontAttrs::None == ((nSearchType ^ nMatchType) & 
ImplFontAttrs::CJK_AllLang) )
-nTestMatch += 1000*3;
-if( nMatchType & ImplFontAttrs::CJK )
-nTestMatch += 1000*2;
-if( nMatchType & ImplFontAttrs::Full )
-nTestMatch += 1000;
+// if the matching font doesn't support any CJK languages, then
+// it is not appropriate
+if ( !(nMatchType & ImplFontAttrs::CJK_AllLang) )
+{
+nTestMatch -= 1000;
+}
+else
+{
+// Matching language
+if ( (nSearchType & ImplFontAttrs::CJK_AllLang)
+&& (nMatchType & ImplFontAttrs::CJK_AllLang) )
+nTestMatch += 1000*3;
+if ( nMatchType & ImplFontAttrs::CJK )
+nTestMatch += 1000*2;
+if ( nMatchType & ImplFontAttrs::Full )
+nTestMatch += 1000;
+}
 }
 else 

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

2021-10-22 Thread Chris Sherlock (via logerrit)
 vcl/qa/cppunit/outdev.cxx  |   59 +
 vcl/source/outdev/gradient.cxx |   58 ++--
 2 files changed, 92 insertions(+), 25 deletions(-)

New commits:
commit 82275140a56750302265a5be21236ae7a15f16e6
Author: Chris Sherlock 
AuthorDate: Sat Oct 2 23:04:02 2021 +1000
Commit: Tomaž Vajngerl 
CommitDate: Fri Oct 22 14:39:36 2021 +0200

vcl: move variable declar's closer to 1st use in 
DrawComplexGradientToMetaFile

Change-Id: Id626799d1b077e649f67a8abf335a63efd15d433
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123000
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index 3779d9b96536..5e05a5acd48b 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -95,6 +95,7 @@ public:
 void testDrawGradient_rect_axial();
 void testDrawGradient_polygon_linear();
 void testDrawGradient_polygon_axial();
+void testDrawGradient_rect_complex();
 
 CPPUNIT_TEST_SUITE(VclOutdevTest);
 CPPUNIT_TEST(testVirtualDevice);
@@ -153,6 +154,7 @@ public:
 CPPUNIT_TEST(testDrawGradient_rect_axial);
 CPPUNIT_TEST(testDrawGradient_polygon_linear);
 CPPUNIT_TEST(testDrawGradient_polygon_axial);
+CPPUNIT_TEST(testDrawGradient_rect_complex);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -2277,6 +2279,7 @@ void VclOutdevTest::testDrawGradient_polygon_linear()
 
 Gradient aGradient(GradientStyle::Linear, COL_RED, COL_WHITE);
 aGradient.SetBorder(100);
+
 pVDev->DrawGradient(aPolyPolygon, aGradient);
 
 size_t nIndex = ClipGradientTest(aMtf, INITIAL_SETUP_ACTION_COUNT);
@@ -2296,6 +2299,7 @@ void VclOutdevTest::testDrawGradient_polygon_axial()
 
 Gradient aGradient(GradientStyle::Axial, COL_RED, COL_WHITE);
 aGradient.SetBorder(100);
+
 pVDev->DrawGradient(aPolyPolygon, aGradient);
 
 size_t nIndex = ClipGradientTest(aMtf, INITIAL_SETUP_ACTION_COUNT);
@@ -2303,6 +2307,61 @@ void VclOutdevTest::testDrawGradient_polygon_axial()
 TestAxialStripes(aMtf, 3, nIndex);
 }
 
+static size_t TestComplexStripes(GDIMetaFile& rMtf, size_t nTimes, size_t 
nIndex)
+{
+nIndex++;
+MetaAction* pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", 
MetaActionType::FILLCOLOR,
+ pAction->GetType());
+
+for (size_t i = 1; i < nTimes; i++)
+{
+nIndex++;
+pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polypolygon action", 
MetaActionType::POLYPOLYGON,
+ pAction->GetType());
+
+nIndex++;
+pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", 
MetaActionType::FILLCOLOR,
+ pAction->GetType());
+}
+
+nIndex++;
+pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", 
MetaActionType::FILLCOLOR,
+ pAction->GetType());
+
+nIndex++;
+pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polypolygon action", 
MetaActionType::POLYGON,
+ pAction->GetType());
+
+return nIndex;
+}
+
+void VclOutdevTest::testDrawGradient_rect_complex()
+{
+ScopedVclPtrInstance pVDev;
+GDIMetaFile aMtf;
+aMtf.Record(pVDev.get());
+
+tools::Rectangle aRect(Point(10, 10), Size(40, 40));
+pVDev->SetOutputSizePixel(Size(1000, 1000));
+
+Gradient aGradient(GradientStyle::Square, COL_RED, COL_WHITE);
+aGradient.SetBorder(10);
+pVDev->DrawGradient(aRect, aGradient);
+
+size_t nIndex = INITIAL_SETUP_ACTION_COUNT;
+
+MetaAction* pAction = aMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a gradient action (rectangle area)", 
MetaActionType::GRADIENT,
+ pAction->GetType());
+
+nIndex = TestComplexStripes(aMtf, 40, nIndex);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(VclOutdevTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/outdev/gradient.cxx b/vcl/source/outdev/gradient.cxx
index ea4a60669a64..6bb6e8de64fc 100644
--- a/vcl/source/outdev/gradient.cxx
+++ b/vcl/source/outdev/gradient.cxx
@@ -808,40 +808,48 @@ void OutputDevice::DrawComplexGradientToMetafile( const 
tools::Rectangle& rRect,
 // Also for printers always use PolyPolygon, as not all printers
 // can print polygons on top of each other.
 
-std::optional xPolyPoly;
-tools::Rectangle   aRect;
-Point   aCenter;
-Color   aStartCol( rGradient.GetStartColor() );
-Color   aEndCol( rGradient.GetEndColor() );
-tools::LongnStartRed = ( 
static_cast(aStartCol.GetRed()) * rGradient.GetStartIntensity() ) 
/ 100;
-tools::LongnStartGreen = ( 
static_cast(aStartCol.GetGreen()) * rGradient.GetStartIntensity() 
)

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

2021-10-21 Thread Mark Hung (via logerrit)
 vcl/qa/cppunit/pdfexport/data/tdf144222.ods |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx  |   42 
 vcl/source/gdi/pdfwriter_impl.cxx   |2 -
 3 files changed, 42 insertions(+), 2 deletions(-)

New commits:
commit a4244c0f05b95ded277a3a7ed217bf0451daa996
Author: Mark Hung 
AuthorDate: Sat Oct 16 13:55:56 2021 +0800
Commit: Mark Hung 
CommitDate: Thu Oct 21 14:13:30 2021 +0200

tdf#144222 fix pdf export with vertical layout

Remove the offset adjustment that is no longer necessary.
That was done in every backend before, and has been
removed now.  We can trust what layout text provides us.

Regression from:

commit dd0d0b44fd1c6c0292d7b2eb3f5cf2baa21e4481
Author: Mark Hung 
Date:   Sun May 2 15:12:46 2021 +0800

vcl: adjust LayoutText() for vertical writing.

Change-Id: I077f5a5f0711444086e56e4469dbcb3010ffe661
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123682
Tested-by: Jenkins
Reviewed-by: Mark Hung 

diff --git a/vcl/qa/cppunit/pdfexport/data/tdf144222.ods 
b/vcl/qa/cppunit/pdfexport/data/tdf144222.ods
new file mode 100644
index ..7b572d301abc
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf144222.ods differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 0da9bedd33ef..ad19395c5669 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -2945,6 +2945,48 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, 
testPdfImageRotate180)
 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, aScale.getX(), 0.01);
 }
 
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf144222)
+{
+// Assume Windows has the font for U+4E2D
+#ifdef _WIN32
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"tdf144222.ods";
+utl::MediaDescriptor aMediaDescriptor;
+aMediaDescriptor["FilterName"] <<= OUString("calc_pdf_Export");
+auto pPdfDocument = exportAndParse(aURL, aMediaDescriptor);
+
+// The document has one page.
+CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
+std::unique_ptr pPdfPage = 
pPdfDocument->openPage(/*nIndex=*/0);
+CPPUNIT_ASSERT(pPdfPage);
+std::unique_ptr pTextPage = 
pPdfPage->getTextPage();
+CPPUNIT_ASSERT(pTextPage);
+
+int nPageObjectCount = pPdfPage->getObjectCount();
+const OUString sChar = u"\u4E2D";
+basegfx::B2DRectangle aRect1, aRect2;
+int nCount = 0;
+
+for (int i = 0; i < nPageObjectCount; ++i)
+{
+std::unique_ptr pPdfPageObject = 
pPdfPage->getObject(i);
+if (pPdfPageObject->getType() == vcl::pdf::PDFPageObjectType::Text)
+{
+++nCount;
+OUString sText = pPdfPageObject->getText(pTextPage);
+if (sText == sChar)
+aRect1 = pPdfPageObject->getBounds();
+else
+aRect2 = pPdfPageObject->getBounds();
+}
+}
+
+CPPUNIT_ASSERT_EQUAL(2, nCount);
+CPPUNIT_ASSERT(!aRect1.isEmpty());
+CPPUNIT_ASSERT(!aRect2.isEmpty());
+CPPUNIT_ASSERT(!aRect1.overlaps(aRect2));
+#endif
+}
+
 } // end anonymous namespace
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 7718cbd39f9c..b987c948bd6d 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -5841,8 +5841,6 @@ void PDFWriterImpl::drawVerticalGlyphs(
 if (rGlyphs[i].m_pGlyph->IsVertical())
 {
 fDeltaAngle = M_PI/2.0;
-aDeltaPos.setX( GetFontMetric().GetAscent() );
-aDeltaPos.setY( 
static_cast(static_cast(GetFontMetric().GetDescent()) * fXScale) );
 fYScale = fXScale;
 fTempXScale = 1.0;
 fSkewA = -fSkewB;


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

2021-10-20 Thread Chris Sherlock (via logerrit)
 vcl/qa/cppunit/outdev.cxx  |  290 +
 vcl/source/outdev/gradient.cxx |1 
 2 files changed, 291 insertions(+)

New commits:
commit 85d53dafd8332fc9c7bf71d6cc9da19ab9d8e252
Author: Chris Sherlock 
AuthorDate: Sat Oct 2 18:49:20 2021 +1000
Commit: Tomaž Vajngerl 
CommitDate: Wed Oct 20 16:04:38 2021 +0200

vcl: test OutputDevice::DrawGradient()

Change-Id: Ica59cdc5f9164892e390143e86946a0bebde525c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122997
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index df5d8b2c9bf4..3779d9b96536 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -16,8 +16,10 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -88,6 +90,11 @@ public:
 void testDrawPolyLine();
 void testDrawPolygon();
 void testDrawPolyPolygon();
+void testDrawGradient_drawmode();
+void testDrawGradient_rect_linear();
+void testDrawGradient_rect_axial();
+void testDrawGradient_polygon_linear();
+void testDrawGradient_polygon_axial();
 
 CPPUNIT_TEST_SUITE(VclOutdevTest);
 CPPUNIT_TEST(testVirtualDevice);
@@ -141,6 +148,11 @@ public:
 CPPUNIT_TEST(testDrawPolyLine);
 CPPUNIT_TEST(testDrawPolygon);
 CPPUNIT_TEST(testDrawPolyPolygon);
+CPPUNIT_TEST(testDrawGradient_drawmode);
+CPPUNIT_TEST(testDrawGradient_rect_linear);
+CPPUNIT_TEST(testDrawGradient_rect_axial);
+CPPUNIT_TEST(testDrawGradient_polygon_linear);
+CPPUNIT_TEST(testDrawGradient_polygon_axial);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -2013,6 +2025,284 @@ void VclOutdevTest::testDrawPolyPolygon()
 }
 }
 
+static size_t ClipGradientTest(GDIMetaFile& rMtf, size_t nIndex)
+{
+MetaAction* pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a comment action", 
MetaActionType::COMMENT,
+ pAction->GetType());
+
+nIndex++;
+pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a gradientex action", 
MetaActionType::GRADIENTEX,
+ pAction->GetType());
+
+// clip gradient
+nIndex++;
+pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a push action", MetaActionType::PUSH, 
pAction->GetType());
+MetaPushAction* pPushAction = dynamic_cast(pAction);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not using XOR push flags", 
vcl::PushFlags::RASTEROP,
+ pPushAction->GetFlags());
+
+nIndex++;
+pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a rasterop action", 
MetaActionType::RASTEROP,
+ pAction->GetType());
+MetaRasterOpAction* pRasterOpAction = 
dynamic_cast(pAction);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not an XOR rasterop", RasterOp::Xor,
+ pRasterOpAction->GetRasterOp());
+
+nIndex++;
+pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a gradient action", 
MetaActionType::GRADIENT,
+ pAction->GetType());
+
+nIndex++;
+pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", 
MetaActionType::FILLCOLOR,
+ pAction->GetType());
+
+nIndex++;
+pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a rasterop action", 
MetaActionType::RASTEROP,
+ pAction->GetType());
+pRasterOpAction = dynamic_cast(pAction);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not an N0 rasterop", RasterOp::N0,
+ pRasterOpAction->GetRasterOp());
+
+nIndex++;
+pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polypolygon action", 
MetaActionType::POLYPOLYGON,
+ pAction->GetType());
+
+nIndex++;
+pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a rasterop action", 
MetaActionType::RASTEROP,
+ pAction->GetType());
+pRasterOpAction = dynamic_cast(pAction);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not an XOR rasterop", RasterOp::Xor,
+ pRasterOpAction->GetRasterOp());
+
+nIndex++;
+pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a gradient action", 
MetaActionType::GRADIENT,
+ pAction->GetType());
+
+nIndex++;
+pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a pop action", MetaActionType::POP, 
pAction->GetType());
+
+nIndex++;
+pAction = rMtf.GetAction(nIndex);
+CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a comment action", 
MetaActionType::COMMENT,
+ pAction->GetType());
+
+return nIndex;
+}
+
+void VclOutdevTest::testDr

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

2021-10-13 Thread Chris Sherlock (via logerrit)
 vcl/qa/cppunit/outdev.cxx  |2 --
 vcl/source/outdev/polyline.cxx |3 +++
 2 files changed, 3 insertions(+), 2 deletions(-)

New commits:
commit be052cbc459266db86c7ddd8daba1d30b7e66d57
Author: Chris Sherlock 
AuthorDate: Sat Oct 2 11:11:32 2021 +1000
Commit: Tomaž Vajngerl 
CommitDate: Wed Oct 13 19:40:47 2021 +0200

vcl: DrawPolyLine() did not set metaaction line join or cap

basegfx::B2DPolygon version of DrawPolyLine() doesn't set the metafile
line cap or join, this fixes this issue.

Change-Id: Id5d73537b0fc5e580789a98b7c5214d586da3cc9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122974
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index b15bbe1785cb..6429e7c01220 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -1896,12 +1896,10 @@ void VclOutdevTest::testDrawPolyLine()
  
pPolyLineAction->GetLineInfo().GetDotLen());
 CPPUNIT_ASSERT_EQUAL_MESSAGE("Distance wrong", static_cast(0),
  
pPolyLineAction->GetLineInfo().GetDistance());
-/* these aren't set!
 CPPUNIT_ASSERT_EQUAL_MESSAGE("Line join", basegfx::B2DLineJoin::Bevel,
  
pPolyLineAction->GetLineInfo().GetLineJoin());
 CPPUNIT_ASSERT_EQUAL_MESSAGE("Line cap", css::drawing::LineCap_BUTT,
  
pPolyLineAction->GetLineInfo().GetLineCap());
-*/
 }
 }
 
diff --git a/vcl/source/outdev/polyline.cxx b/vcl/source/outdev/polyline.cxx
index aeeb90845bd1..ef4f0a4a5f2d 100644
--- a/vcl/source/outdev/polyline.cxx
+++ b/vcl/source/outdev/polyline.cxx
@@ -149,6 +149,9 @@ void OutputDevice::DrawPolyLine( const basegfx::B2DPolygon& 
rB2DPolygon,
 if( fLineWidth != 0.0 )
 aLineInfo.SetWidth( fLineWidth );
 
+aLineInfo.SetLineJoin(eLineJoin);
+aLineInfo.SetLineCap(eLineCap);
+
 const tools::Polygon aToolsPolygon( rB2DPolygon );
 mpMetaFile->AddAction( new MetaPolyLineAction( aToolsPolygon, 
aLineInfo ) );
 }


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

2021-09-10 Thread Chris Sherlock (via logerrit)
 vcl/qa/cppunit/outdev.cxx |   21 +
 vcl/source/outdev/outdevstate.cxx |   11 ---
 vcl/source/outdev/text.cxx|   11 +++
 3 files changed, 32 insertions(+), 11 deletions(-)

New commits:
commit ecb7289fc3091fbbb8a65f43fc649e57a9870ac9
Author: Chris Sherlock 
AuthorDate: Wed Aug 25 18:45:50 2021 +1000
Commit: Noel Grandin 
CommitDate: Fri Sep 10 10:07:33 2021 +0200

vcl: move OutputDevice::SetDigitLanguage() to text.cxx

Ultimately I hope to reduce outdevstate.cxx to only have push(), pop()
and clearstack(), then rename outdevstate.cxx to stack.cxx. Eventually,
the plan is to separate metafile processing from rendering.

Add unit test for SetDigitLanguage() and GetDigitLanguage().

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

diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index 40559ef09172..ddf3344244bf 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -61,6 +61,7 @@ public:
 void testAntialias();
 void testDrawMode();
 void testLayoutMode();
+void testDigitLanguage();
 void testSystemTextColor();
 void testShouldDrawWavePixelAsRect();
 void testGetWaveLineSize();
@@ -98,6 +99,7 @@ public:
 CPPUNIT_TEST(testAntialias);
 CPPUNIT_TEST(testDrawMode);
 CPPUNIT_TEST(testLayoutMode);
+CPPUNIT_TEST(testDigitLanguage);
 CPPUNIT_TEST(testSystemTextColor);
 CPPUNIT_TEST(testShouldDrawWavePixelAsRect);
 CPPUNIT_TEST(testGetWaveLineSize);
@@ -848,6 +850,25 @@ void VclOutdevTest::testLayoutMode()
 CPPUNIT_ASSERT_EQUAL(ComplexTextLayoutFlags::BiDiRtl, 
pLayoutModeAction->GetLayoutMode());
 }
 
+void VclOutdevTest::testDigitLanguage()
+{
+ScopedVclPtrInstance pVDev;
+
+GDIMetaFile aMtf;
+aMtf.Record(pVDev.get());
+
+CPPUNIT_ASSERT_EQUAL(LANGUAGE_SYSTEM, pVDev->GetDigitLanguage());
+
+pVDev->SetDigitLanguage(LANGUAGE_GERMAN);
+
+CPPUNIT_ASSERT_EQUAL(LANGUAGE_GERMAN, pVDev->GetDigitLanguage());
+
+MetaAction* pAction = aMtf.GetAction(0);
+CPPUNIT_ASSERT_EQUAL(MetaActionType::TEXTLANGUAGE, pAction->GetType());
+auto pTextLanguageAction = static_cast(pAction);
+CPPUNIT_ASSERT_EQUAL(LANGUAGE_GERMAN, 
pTextLanguageAction->GetTextLanguage());
+}
+
 void VclOutdevTest::testSystemTextColor()
 {
 {
diff --git a/vcl/source/outdev/outdevstate.cxx 
b/vcl/source/outdev/outdevstate.cxx
index 13062ca91685..ee8eddf07fb1 100644
--- a/vcl/source/outdev/outdevstate.cxx
+++ b/vcl/source/outdev/outdevstate.cxx
@@ -198,15 +198,4 @@ void OutputDevice::ClearStack()
 Pop();
 }
 
-void OutputDevice::SetDigitLanguage( LanguageType eTextLanguage )
-{
-if( mpMetaFile )
-mpMetaFile->AddAction( new MetaTextLanguageAction( eTextLanguage ) );
-
-meTextLanguage = eTextLanguage;
-
-if( mpAlphaVDev )
-mpAlphaVDev->SetDigitLanguage( eTextLanguage );
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx
index 1d8164da09be..f1aa776629eb 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -63,6 +63,17 @@ void OutputDevice::SetLayoutMode( ComplexTextLayoutFlags 
nTextLayoutMode )
 mpAlphaVDev->SetLayoutMode( nTextLayoutMode );
 }
 
+void OutputDevice::SetDigitLanguage( LanguageType eTextLanguage )
+{
+if( mpMetaFile )
+mpMetaFile->AddAction( new MetaTextLanguageAction( eTextLanguage ) );
+
+meTextLanguage = eTextLanguage;
+
+if( mpAlphaVDev )
+mpAlphaVDev->SetDigitLanguage( eTextLanguage );
+}
+
 ImplMultiTextLineInfo::ImplMultiTextLineInfo()
 {
 }


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

2021-09-08 Thread Chris Sherlock (via logerrit)
 vcl/qa/cppunit/outdev.cxx |   15 +++
 vcl/source/outdev/outdev.cxx  |8 
 vcl/source/outdev/outdevstate.cxx |8 
 3 files changed, 23 insertions(+), 8 deletions(-)

New commits:
commit d70622afd96b5d1f530082c8d5dd332188937f17
Author: Chris Sherlock 
AuthorDate: Wed Aug 25 17:45:44 2021 +1000
Commit: Mike Kaganski 
CommitDate: Wed Sep 8 10:12:06 2021 +0200

vcl: move OutputDevice output flag functions to outdev.cxx

Add unit test for EnableOutput(), IsOutputEnabled() and is
IsDeviceOutputNecessary().

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

diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index 5f78c5127807..c69120155d65 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -57,6 +57,7 @@ public:
 void testDefaultRefPoint();
 void testRefPoint();
 void testRasterOp();
+void testOutputFlag();
 void testSystemTextColor();
 void testShouldDrawWavePixelAsRect();
 void testGetWaveLineSize();
@@ -90,6 +91,7 @@ public:
 CPPUNIT_TEST(testDefaultRefPoint);
 CPPUNIT_TEST(testRefPoint);
 CPPUNIT_TEST(testRasterOp);
+CPPUNIT_TEST(testOutputFlag);
 CPPUNIT_TEST(testSystemTextColor);
 CPPUNIT_TEST(testShouldDrawWavePixelAsRect);
 CPPUNIT_TEST(testGetWaveLineSize);
@@ -786,6 +788,19 @@ void VclOutdevTest::testRasterOp()
 CPPUNIT_ASSERT_EQUAL(RasterOp::Invert, pRasterOpAction->GetRasterOp());
 }
 
+void VclOutdevTest::testOutputFlag()
+{
+ScopedVclPtrInstance pVDev;
+
+CPPUNIT_ASSERT(pVDev->IsOutputEnabled());
+CPPUNIT_ASSERT(pVDev->IsDeviceOutputNecessary());
+
+pVDev->EnableOutput(false);
+
+CPPUNIT_ASSERT(!pVDev->IsOutputEnabled());
+CPPUNIT_ASSERT(!pVDev->IsDeviceOutputNecessary());
+}
+
 void VclOutdevTest::testSystemTextColor()
 {
 {
diff --git a/vcl/source/outdev/outdev.cxx b/vcl/source/outdev/outdev.cxx
index 1bbfc24cdb4d..1b006ff7f4dd 100644
--- a/vcl/source/outdev/outdev.cxx
+++ b/vcl/source/outdev/outdev.cxx
@@ -331,6 +331,14 @@ void OutputDevice::SetRasterOp( RasterOp eRasterOp )
 mpAlphaVDev->SetRasterOp( eRasterOp );
 }
 
+void OutputDevice::EnableOutput( bool bEnable )
+{
+mbOutput = bEnable;
+
+if( mpAlphaVDev )
+mpAlphaVDev->EnableOutput( bEnable );
+}
+
 sal_uInt16 OutputDevice::GetBitCount() const
 {
 // we need a graphics instance
diff --git a/vcl/source/outdev/outdevstate.cxx 
b/vcl/source/outdev/outdevstate.cxx
index 90fe67eccb1a..5de6b1c5ec92 100644
--- a/vcl/source/outdev/outdevstate.cxx
+++ b/vcl/source/outdev/outdevstate.cxx
@@ -198,14 +198,6 @@ void OutputDevice::ClearStack()
 Pop();
 }
 
-void OutputDevice::EnableOutput( bool bEnable )
-{
-mbOutput = bEnable;
-
-if( mpAlphaVDev )
-mpAlphaVDev->EnableOutput( bEnable );
-}
-
 void OutputDevice::SetAntialiasing( AntialiasingFlags nMode )
 {
 if ( mnAntialiasing != nMode )


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

2021-09-05 Thread Caolán McNamara (via logerrit)
 vcl/source/filter/imet/ios2met.cxx |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

New commits:
commit eca3b403293a2feb874acd7e38a79f2b60d0d266
Author: Caolán McNamara 
AuthorDate: Sat Sep 4 21:06:46 2021 +0100
Commit: Caolán McNamara 
CommitDate: Sun Sep 5 11:49:41 2021 +0200

ofz: Timeout, break earlier on stream failure

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

diff --git a/vcl/qa/cppunit/graphicfilter/data/met/pass/hang-3.met 
b/vcl/qa/cppunit/graphicfilter/data/met/fail/hang-3.met
similarity index 100%
rename from vcl/qa/cppunit/graphicfilter/data/met/pass/hang-3.met
rename to vcl/qa/cppunit/graphicfilter/data/met/fail/hang-3.met
diff --git a/vcl/source/filter/imet/ios2met.cxx 
b/vcl/source/filter/imet/ios2met.cxx
index 09ef10a95aa5..cf1694ca04a5 100644
--- a/vcl/source/filter/imet/ios2met.cxx
+++ b/vcl/source/filter/imet/ios2met.cxx
@@ -1236,7 +1236,7 @@ void OS2METReader::ReadPolygons()
 sal_uInt32 nNumPolys(0);
 pOS2MET->ReadUChar(nFlags).ReadUInt32(nNumPolys);
 
-if (nNumPolys > SAL_MAX_UINT16)
+if (!pOS2MET->good() || nNumPolys > SAL_MAX_UINT16)
 {
 pOS2MET->SetError(SVSTREAM_FILEFORMAT_ERROR);
 ErrorCode=11;
@@ -1249,7 +1249,7 @@ void OS2METReader::ReadPolygons()
 pOS2MET->ReadUInt32(nNumPoints);
 sal_uInt32 nLimit = SAL_MAX_UINT16;
 if (i==0) --nLimit;
-if (nNumPoints > nLimit)
+if (!pOS2MET->good() || nNumPoints > nLimit)
 {
 pOS2MET->SetError(SVSTREAM_FILEFORMAT_ERROR);
 ErrorCode=11;


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

2021-09-03 Thread Chris Sherlock (via logerrit)
 vcl/qa/cppunit/outdev.cxx|   40 
 vcl/source/outdev/outdev.cxx |3 ---
 2 files changed, 40 insertions(+), 3 deletions(-)

New commits:
commit 5f50890d06a411323e5e60098901be4911ef1356
Author: Chris Sherlock 
AuthorDate: Wed Aug 25 16:38:17 2021 +1000
Commit: Tomaž Vajngerl 
CommitDate: Sat Sep 4 05:54:27 2021 +0200

vcl: Add unit test for SetRefPoint(), IsRefPoint() and GetRefPoint()

Change-Id: I4fbc85015326b03fba15daf73176826669a16210
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121017
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index adbf72751b4c..1857b4555c8a 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -54,6 +54,8 @@ public:
 void testLineColor();
 void testFont();
 void testTransparentFont();
+void testDefaultRefPoint();
+void testRefPoint();
 void testSystemTextColor();
 void testShouldDrawWavePixelAsRect();
 void testGetWaveLineSize();
@@ -84,6 +86,8 @@ public:
 CPPUNIT_TEST(testLineColor);
 CPPUNIT_TEST(testFont);
 CPPUNIT_TEST(testTransparentFont);
+CPPUNIT_TEST(testDefaultRefPoint);
+CPPUNIT_TEST(testRefPoint);
 CPPUNIT_TEST(testSystemTextColor);
 CPPUNIT_TEST(testShouldDrawWavePixelAsRect);
 CPPUNIT_TEST(testGetWaveLineSize);
@@ -725,6 +729,42 @@ void VclOutdevTest::testTransparentFont()
 CPPUNIT_ASSERT_EQUAL(nActionsExpected, aMtf.GetActionSize());
 }
 
+void VclOutdevTest::testDefaultRefPoint()
+{
+ScopedVclPtrInstance pVDev;
+
+GDIMetaFile aMtf;
+aMtf.Record(pVDev.get());
+
+pVDev->SetRefPoint();
+
+CPPUNIT_ASSERT(!pVDev->IsRefPoint());
+CPPUNIT_ASSERT_EQUAL(Point(), pVDev->GetRefPoint());
+
+MetaAction* pAction = aMtf.GetAction(0);
+CPPUNIT_ASSERT_EQUAL(MetaActionType::REFPOINT, pAction->GetType());
+auto pRefPointAction = static_cast(pAction);
+CPPUNIT_ASSERT_EQUAL(Point(), pRefPointAction->GetRefPoint());
+}
+
+void VclOutdevTest::testRefPoint()
+{
+ScopedVclPtrInstance pVDev;
+
+GDIMetaFile aMtf;
+aMtf.Record(pVDev.get());
+
+pVDev->SetRefPoint(Point(10, 20));
+
+CPPUNIT_ASSERT(pVDev->IsRefPoint());
+CPPUNIT_ASSERT_EQUAL(Point(10, 20), pVDev->GetRefPoint());
+
+MetaAction* pAction = aMtf.GetAction(0);
+CPPUNIT_ASSERT_EQUAL(MetaActionType::REFPOINT, pAction->GetType());
+auto pRefPointAction = static_cast(pAction);
+CPPUNIT_ASSERT_EQUAL(Point(10, 20), pRefPointAction->GetRefPoint());
+}
+
 void VclOutdevTest::testSystemTextColor()
 {
 {
diff --git a/vcl/source/outdev/outdev.cxx b/vcl/source/outdev/outdev.cxx
index 71ec101f4dd1..eaef70931062 100644
--- a/vcl/source/outdev/outdev.cxx
+++ b/vcl/source/outdev/outdev.cxx
@@ -287,7 +287,6 @@ css::uno::Any OutputDevice::GetSystemGfxDataAny() const
 
 void OutputDevice::SetRefPoint()
 {
-
 if ( mpMetaFile )
 mpMetaFile->AddAction( new MetaRefPointAction( Point(), false ) );
 
@@ -298,10 +297,8 @@ void OutputDevice::SetRefPoint()
 if( mpAlphaVDev )
 mpAlphaVDev->SetRefPoint();
 }
-
 void OutputDevice::SetRefPoint( const Point& rRefPoint )
 {
-
 if ( mpMetaFile )
 mpMetaFile->AddAction( new MetaRefPointAction( rRefPoint, true ) );
 


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

2021-09-02 Thread Chris Sherlock (via logerrit)
 vcl/qa/cppunit/outdev.cxx |   73 ++
 vcl/source/outdev/font.cxx|   73 +++---
 vcl/source/outdev/outdevstate.cxx |   46 ---
 3 files changed, 133 insertions(+), 59 deletions(-)

New commits:
commit a01c60927c3cedf775d3ba66d3602988c274fb09
Author: Chris Sherlock 
AuthorDate: Wed Aug 25 16:13:57 2021 +1000
Commit: Mike Kaganski 
CommitDate: Fri Sep 3 07:20:41 2021 +0200

vcl: Migrate OutputDevice font functions to font.cxx

Add unit tests for SetFont() and GetFont()

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

diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index 0f2039d27943..adbf72751b4c 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -52,6 +52,8 @@ public:
 void testDefaultLineColor();
 void testTransparentLineColor();
 void testLineColor();
+void testFont();
+void testTransparentFont();
 void testSystemTextColor();
 void testShouldDrawWavePixelAsRect();
 void testGetWaveLineSize();
@@ -80,6 +82,8 @@ public:
 CPPUNIT_TEST(testDefaultLineColor);
 CPPUNIT_TEST(testTransparentLineColor);
 CPPUNIT_TEST(testLineColor);
+CPPUNIT_TEST(testFont);
+CPPUNIT_TEST(testTransparentFont);
 CPPUNIT_TEST(testSystemTextColor);
 CPPUNIT_TEST(testShouldDrawWavePixelAsRect);
 CPPUNIT_TEST(testGetWaveLineSize);
@@ -652,6 +656,75 @@ void VclOutdevTest::testLineColor()
 CPPUNIT_ASSERT_EQUAL(COL_RED, rColor);
 }
 
+void VclOutdevTest::testFont()
+{
+ScopedVclPtrInstance pVDev;
+
+// Use Dejavu fonts, they are shipped with LO, so they should be ~always 
available.
+// Use Sans variant for simpler glyph shapes (no serifs).
+vcl::Font font("DejaVu Sans", "Book", Size(0, 36));
+font.SetColor(COL_BLACK);
+font.SetFillColor(COL_RED);
+
+GDIMetaFile aMtf;
+aMtf.Record(pVDev.get());
+
+pVDev->SetFont(font);
+bool bSameFont(font == pVDev->GetFont());
+CPPUNIT_ASSERT_MESSAGE("Font is not the same", bSameFont);
+
+// four actions:
+// 1. Font action
+// 2. Text alignment action
+// 3. Text fill color action
+// 4. As not COL_TRANSPARENT (means use system font color), font color 
action
+size_t nActionsExpected = 4;
+CPPUNIT_ASSERT_EQUAL(nActionsExpected, aMtf.GetActionSize());
+
+MetaAction* pAction = aMtf.GetAction(0);
+CPPUNIT_ASSERT_EQUAL(MetaActionType::FONT, pAction->GetType());
+auto pFontAction = static_cast(pAction);
+bool bSameMetaFont = (font == pFontAction->GetFont());
+CPPUNIT_ASSERT_MESSAGE("Metafile font is not the same", bSameMetaFont);
+
+pAction = aMtf.GetAction(1);
+CPPUNIT_ASSERT_EQUAL(MetaActionType::TEXTALIGN, pAction->GetType());
+auto pTextAlignAction = static_cast(pAction);
+CPPUNIT_ASSERT_EQUAL(font.GetAlignment(), 
pTextAlignAction->GetTextAlign());
+
+pAction = aMtf.GetAction(2);
+CPPUNIT_ASSERT_EQUAL(MetaActionType::TEXTFILLCOLOR, pAction->GetType());
+auto pTextFillColorAction = static_cast(pAction);
+CPPUNIT_ASSERT_EQUAL(COL_RED, pTextFillColorAction->GetColor());
+
+pAction = aMtf.GetAction(3);
+CPPUNIT_ASSERT_EQUAL(MetaActionType::TEXTCOLOR, pAction->GetType());
+auto pTextColorAction = static_cast(pAction);
+CPPUNIT_ASSERT_EQUAL(COL_BLACK, pTextColorAction->GetColor());
+}
+
+void VclOutdevTest::testTransparentFont()
+{
+ScopedVclPtrInstance pVDev;
+
+// Use Dejavu fonts, they are shipped with LO, so they should be ~always 
available.
+// Use Sans variant for simpler glyph shapes (no serifs).
+vcl::Font font("DejaVu Sans", "Book", Size(0, 36));
+font.SetColor(COL_TRANSPARENT);
+
+GDIMetaFile aMtf;
+aMtf.Record(pVDev.get());
+
+pVDev->SetFont(font);
+
+// three actions as it sets the colour to the default system color (and 
doesn't add a text color action):
+// 1. Font action
+// 2. Text alignment action
+// 3. Text fill color action
+size_t nActionsExpected = 3;
+CPPUNIT_ASSERT_EQUAL(nActionsExpected, aMtf.GetActionSize());
+}
+
 void VclOutdevTest::testSystemTextColor()
 {
 {
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx
index bfaa0226b1ce..3f84afb2c3bf 100644
--- a/vcl/source/outdev/font.cxx
+++ b/vcl/source/outdev/font.cxx
@@ -17,33 +17,80 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include 
+#include 
+#include 
 #include 
 #include 
-
 #include 
+
+#include 
+#include 
+#include 
 #include 
-#include 
 #include 
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-#include 
+#include 
 
 #include 
 #include 
 
 #include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
 #include 
 
+void OutputDevice::SetFo

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

2021-09-02 Thread Caolán McNamara (via logerrit)
 vcl/qa/cppunit/graphicfilter/data/met/fail/afl-msan-1.met |binary
 vcl/source/filter/imet/ios2met.cxx|   42 +++---
 2 files changed, 35 insertions(+), 7 deletions(-)

New commits:
commit 5a864ebb0e18565e33e677df7987a8f94a7742ea
Author: Caolán McNamara 
AuthorDate: Wed Sep 1 16:12:32 2021 +0100
Commit: Caolán McNamara 
CommitDate: Thu Sep 2 09:28:47 2021 +0200

ofz: MemorySanitizer: use-of-uninitialized-value

bodge dodgy SetStreamSize for now

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

diff --git a/vcl/qa/cppunit/graphicfilter/data/met/fail/afl-msan-1.met 
b/vcl/qa/cppunit/graphicfilter/data/met/fail/afl-msan-1.met
new file mode 100644
index ..18877582a4e2
Binary files /dev/null and 
b/vcl/qa/cppunit/graphicfilter/data/met/fail/afl-msan-1.met differ
diff --git a/vcl/source/filter/imet/ios2met.cxx 
b/vcl/source/filter/imet/ios2met.cxx
index 98b4c2bb82cc..774ed1517b9d 100644
--- a/vcl/source/filter/imet/ios2met.cxx
+++ b/vcl/source/filter/imet/ios2met.cxx
@@ -364,7 +364,7 @@ private:
 OSAttr   aAttr;
 OSAttr   * pAttrStack;
 
-std::unique_ptr xOrdFile;
+std::unique_ptr xOrdFile;
 
 void AddPointsToPath(const tools::Polygon & rPoly);
 void AddPointsToArea(const tools::Polygon & rPoly);
@@ -2560,22 +2560,48 @@ void OS2METReader::ReadField(sal_uInt16 nFieldType, 
sal_uInt16 nFieldSize)
 case BegGrfObjMagic:
 break;
 case EndGrfObjMagic: {
-SvStream * pSave;
-sal_uInt16 nOrderID, nOrderLen;
-
 if (!xOrdFile)
 break;
 
+auto nMaxPos = xOrdFile->Tell();
+if (!nMaxPos)
+break;
+
 // In xOrdFile all "DatGrfObj" fields were collected so that the
 // therein contained "Orders" are continuous and not segmented by 
fields.
 // To read them from the memory stream without having any trouble,
 // we use a  little trick:
 
-pSave=pOS2MET;
+SvStream *pSave = pOS2MET;
 pOS2MET=xOrdFile.get(); //(!)
-auto nMaxPos = pOS2MET->Tell();
 pOS2MET->Seek(0);
 
+// in a sane world this block is just: 
pOS2MET->SetStreamSize(nMaxPos);
+if (nMaxPos)
+{
+#ifndef NDEBUG
+const sal_uInt8 nLastByte = static_cast(xOrdFile->GetData())[nMaxPos-1];
+#endif
+pOS2MET->SetStreamSize(nMaxPos); // shrink stream to written 
portion
+assert(pOS2MET->remainingSize() == nMaxPos || 
pOS2MET->remainingSize() == nMaxPos - 1);
+SAL_WARN_IF(pOS2MET->remainingSize() == nMaxPos, 
"filter.os2met", "this SetStreamSize workaround is no longer needed");
+// The shrink case of SvMemoryStream::ReAllocateMemory, i.e. 
nEndOfData = nNewSize - 1, looks buggy to me, workaround
+// it by using Seek to move the nEndOfData to the sane position
+if (pOS2MET->remainingSize() < nMaxPos)
+{
+pOS2MET->Seek(nMaxPos);
+pOS2MET->Seek(0);
+}
+
+assert(nLastByte == static_cast(xOrdFile->GetData())[nMaxPos-1]);
+}
+
+assert(pOS2MET->remainingSize() == nMaxPos);
+
+// disable stream growing past its current size
+xOrdFile->SetResizeOffset(0);
+
+
 // "Segment header":
 sal_uInt8 nbyte(0);
 pOS2MET->ReadUChar( nbyte );
@@ -2586,11 +2612,13 @@ void OS2METReader::ReadField(sal_uInt16 nFieldType, 
sal_uInt16 nFieldSize)
 
 // loop through Order:
 while (pOS2MET->Tell()GetError()==ERRCODE_NONE) {
-pOS2MET->ReadUChar( nbyte ); 
nOrderID=static_cast(nbyte) & 0x00ff;
+pOS2MET->ReadUChar( nbyte );
+sal_uInt16 nOrderID = static_cast(nbyte) & 0x00ff;
 if (nOrderID==0x00fe) {
 pOS2MET->ReadUChar( nbyte );
 nOrderID=(nOrderID << 8) | (static_cast(nbyte) 
& 0x00ff);
 }
+sal_uInt16 nOrderLen;
 if (nOrderID>0x00ff || nOrderID==GOrdPolygn) {
 // ooo: As written in OS2 documentation, the order length 
should now
 // be written as big endian word. (Quote: "Highorder byte 
precedes loworder byte").


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

2021-09-01 Thread Chris Sherlock (via logerrit)
 vcl/qa/cppunit/outdev.cxx |   69 ++
 vcl/source/outdev/line.cxx|   87 ++
 vcl/source/outdev/outdevstate.cxx |   70 --
 3 files changed, 148 insertions(+), 78 deletions(-)

New commits:
commit 7ded01efaec8171a204a255395767432bab881b5
Author: Chris Sherlock 
AuthorDate: Wed Aug 25 15:24:13 2021 +1000
Commit: Mike Kaganski 
CommitDate: Thu Sep 2 08:18:51 2021 +0200

vcl: move OutputDevice line functions to line.cxx

Add unit tests for SetLineColor(), IsLineColor() and GetLineColor()

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

diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index d9aa34a0250c..f5d814fe91fb 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -48,6 +48,9 @@ public:
 void testDefaultFillColor();
 void testTransparentFillColor();
 void testFillColor();
+void testDefaultLineColor();
+void testTransparentLineColor();
+void testLineColor();
 void testSystemTextColor();
 void testShouldDrawWavePixelAsRect();
 void testGetWaveLineSize();
@@ -72,6 +75,9 @@ public:
 CPPUNIT_TEST(testDefaultFillColor);
 CPPUNIT_TEST(testTransparentFillColor);
 CPPUNIT_TEST(testFillColor);
+CPPUNIT_TEST(testDefaultLineColor);
+CPPUNIT_TEST(testTransparentLineColor);
+CPPUNIT_TEST(testLineColor);
 CPPUNIT_TEST(testSystemTextColor);
 CPPUNIT_TEST(testShouldDrawWavePixelAsRect);
 CPPUNIT_TEST(testGetWaveLineSize);
@@ -535,6 +541,69 @@ void VclOutdevTest::testFillColor()
 CPPUNIT_ASSERT_EQUAL(COL_RED, rColor);
 }
 
+void VclOutdevTest::testDefaultLineColor()
+{
+// Create a virtual device, and connect a metafile to it.
+ScopedVclPtrInstance pVDev;
+
+GDIMetaFile aMtf;
+aMtf.Record(pVDev.get());
+
+CPPUNIT_ASSERT(pVDev->IsLineColor());
+CPPUNIT_ASSERT_EQUAL(COL_BLACK, pVDev->GetLineColor());
+
+pVDev->SetLineColor();
+CPPUNIT_ASSERT(!pVDev->IsLineColor());
+CPPUNIT_ASSERT_EQUAL(COL_TRANSPARENT, pVDev->GetLineColor());
+MetaAction* pAction = aMtf.GetAction(0);
+CPPUNIT_ASSERT_EQUAL(MetaActionType::LINECOLOR, pAction->GetType());
+auto pLineAction = static_cast(pAction);
+const Color& rColor = pLineAction->GetColor();
+CPPUNIT_ASSERT_EQUAL(Color(), rColor);
+}
+
+void VclOutdevTest::testTransparentLineColor()
+{
+// Create a virtual device, and connect a metafile to it.
+ScopedVclPtrInstance pVDev;
+
+GDIMetaFile aMtf;
+aMtf.Record(pVDev.get());
+
+CPPUNIT_ASSERT(pVDev->IsLineColor());
+CPPUNIT_ASSERT_EQUAL(COL_BLACK, pVDev->GetLineColor());
+
+pVDev->SetLineColor(COL_TRANSPARENT);
+CPPUNIT_ASSERT(!pVDev->IsLineColor());
+CPPUNIT_ASSERT_EQUAL(COL_TRANSPARENT, pVDev->GetLineColor());
+MetaAction* pAction = aMtf.GetAction(0);
+CPPUNIT_ASSERT_EQUAL(MetaActionType::LINECOLOR, pAction->GetType());
+auto pLineAction = static_cast(pAction);
+const Color& rColor = pLineAction->GetColor();
+CPPUNIT_ASSERT_EQUAL(COL_TRANSPARENT, rColor);
+}
+
+void VclOutdevTest::testLineColor()
+{
+// Create a virtual device, and connect a metafile to it.
+ScopedVclPtrInstance pVDev;
+
+GDIMetaFile aMtf;
+aMtf.Record(pVDev.get());
+
+CPPUNIT_ASSERT(pVDev->IsLineColor());
+CPPUNIT_ASSERT_EQUAL(COL_BLACK, pVDev->GetLineColor());
+
+pVDev->SetLineColor(COL_RED);
+CPPUNIT_ASSERT(pVDev->IsLineColor());
+CPPUNIT_ASSERT_EQUAL(COL_RED, pVDev->GetLineColor());
+MetaAction* pAction = aMtf.GetAction(0);
+CPPUNIT_ASSERT_EQUAL(MetaActionType::LINECOLOR, pAction->GetType());
+auto pLineAction = static_cast(pAction);
+const Color& rColor = pLineAction->GetColor();
+CPPUNIT_ASSERT_EQUAL(COL_RED, rColor);
+}
+
 void VclOutdevTest::testSystemTextColor()
 {
 {
diff --git a/vcl/source/outdev/line.cxx b/vcl/source/outdev/line.cxx
index 479705082265..9c1b5749f336 100644
--- a/vcl/source/outdev/line.cxx
+++ b/vcl/source/outdev/line.cxx
@@ -17,21 +17,92 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include 
-#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
-#include 
 #include 
 #include 
-#include 
 #include 
 
+#include 
 #include 
 
-#include 
-#include 
-#include 
-#include 
+#include 
+#include 
+
+void OutputDevice::SetLineColor()
+{
+
+if ( mpMetaFile )
+mpMetaFile->AddAction( new MetaLineColorAction( Color(), false ) );
+
+if ( mbLineColor )
+{
+mbInitLineColor = true;
+mbLineColor = false;
+maLineColor = COL_TRANSPARENT;
+}
+
+if( mpAlphaVDev )
+mpAlphaVDev->SetLineColor();
+}
+
+void OutputDevice::SetLineColor( const Color& rColor )
+{
+
+Color aColor = vcl::drawmode::GetLineColor(rColor, GetDrawMode(), 
GetSett

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

2021-08-23 Thread Caolán McNamara (via logerrit)
 vcl/qa/cppunit/graphicfilter/data/svm/pass/ofz-timeout-1.svm |binary
 vcl/source/bitmap/BitmapEx.cxx   |4 ++--
 2 files changed, 2 insertions(+), 2 deletions(-)

New commits:
commit 2652675c417353bd0f072bc7c2579b6d24bf3eba
Author: Caolán McNamara 
AuthorDate: Sun Aug 22 20:31:07 2021 +0100
Commit: Caolán McNamara 
CommitDate: Mon Aug 23 10:00:40 2021 +0200

ofz: use BmpScaleFlag::Fast when recovering from bad svm mask size

this isn't supposed to happen and is an error recovery added by:

commit baebeb7de4c5f9511e45c2846ec2a72861a948c0
Date:   Fri Jul 27 14:04:19 2012 +

Resolves: #i120165# Adapt Mask/Alpha at BitmapEx construction...

when size differs from base bitmap

so use the time-cheapest scaling available

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

diff --git a/vcl/qa/cppunit/graphicfilter/data/svm/pass/ofz-timeout-1.svm 
b/vcl/qa/cppunit/graphicfilter/data/svm/pass/ofz-timeout-1.svm
new file mode 100644
index ..5b61891be667
Binary files /dev/null and 
b/vcl/qa/cppunit/graphicfilter/data/svm/pass/ofz-timeout-1.svm differ
diff --git a/vcl/source/bitmap/BitmapEx.cxx b/vcl/source/bitmap/BitmapEx.cxx
index 91ee55c58ed3..187b9290738e 100644
--- a/vcl/source/bitmap/BitmapEx.cxx
+++ b/vcl/source/bitmap/BitmapEx.cxx
@@ -133,7 +133,7 @@ BitmapEx::BitmapEx( const Bitmap& rBmp, const Bitmap& rMask 
) :
 if (!maBitmap.IsEmpty() && maBitmap.GetSizePixel() != 
maAlphaMask.GetSizePixel())
 {
 OSL_ENSURE(false, "Mask size differs from Bitmap size, corrected Mask 
(!)");
-maAlphaMask.Scale(maBitmap.GetSizePixel());
+maAlphaMask.Scale(maBitmap.GetSizePixel(), BmpScaleFlag::Fast);
 }
 }
 
@@ -145,7 +145,7 @@ BitmapEx::BitmapEx( const Bitmap& rBmp, const AlphaMask& 
rAlphaMask ) :
 if (!maBitmap.IsEmpty() && !maAlphaMask.IsEmpty() && 
maBitmap.GetSizePixel() != maAlphaMask.GetSizePixel())
 {
 OSL_ENSURE(false, "Alpha size differs from Bitmap size, corrected Mask 
(!)");
-maAlphaMask.Scale(rBmp.GetSizePixel());
+maAlphaMask.Scale(rBmp.GetSizePixel(), BmpScaleFlag::Fast);
 }
 }
 


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

2021-06-28 Thread panoskorovesis (via logerrit)
 vcl/qa/cppunit/svm/data/eps.svm |binary
 vcl/qa/cppunit/svm/svmtest.cxx  |   77 ++--
 vcl/source/gdi/mtfxmldump.cxx   |   59 ++
 3 files changed, 133 insertions(+), 3 deletions(-)

New commits:
commit d1eb1e6e487fad489b7c80b68613290da6edfe8a
Author: panoskorovesis 
AuthorDate: Wed Jun 23 13:52:32 2021 +0300
Commit: Tomaž Vajngerl 
CommitDate: Mon Jun 28 13:55:01 2021 +0200

Add EPS cppunit test to vcl.

The test creates an EPS along with a second metafile and
tests their attributes. mtfxmldump.cxx was edited to support
EPS.

Change-Id: I43495304aaf191e1a8ad034b96ff59de085a0630
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117702
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/svm/data/eps.svm b/vcl/qa/cppunit/svm/data/eps.svm
new file mode 100644
index ..33b923a14adc
Binary files /dev/null and b/vcl/qa/cppunit/svm/data/eps.svm differ
diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx
index c260a974282d..abe76a85e606 100644
--- a/vcl/qa/cppunit/svm/svmtest.cxx
+++ b/vcl/qa/cppunit/svm/svmtest.cxx
@@ -183,7 +183,7 @@ class SvmTest : public test::BootstrapFixture, public 
XmlTestTools
 //void checkFloatTransparent(const GDIMetaFile& rMetaFile);
 void testFloatTransparent();
 
-//void checkEPS(const GDIMetaFile& rMetaFile);
+void checkEPS(const GDIMetaFile& rMetaFile);
 void testEPS();
 
 void checkRefPoint(const GDIMetaFile& rMetaFile);
@@ -2035,8 +2035,81 @@ void SvmTest::testTransparent()
 void SvmTest::testFloatTransparent()
 {}
 
+void SvmTest::checkEPS(const GDIMetaFile& rMetaFile)
+{
+xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
+
+assertXPathAttrs(pDoc, "/metafile/eps[1]", {
+{"x", "1"},
+{"y", "8"},
+{"width", "2"},
+{"height", "7"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/eps[1]/gfxlink[1]", {
+{"width", "3"},
+{"height", "6"},
+{"type", "EpsBuffer"},
+{"userid", "12345"},
+{"datasize", "3"},
+{"data", "616263"},
+{"native", "false"},
+{"emf", "false"},
+{"validmapmode", "true"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/eps[1]/gfxlink[1]/prefmapmode[1]", {
+{"mapunit", "Map100thInch"},
+{"x", "0"},
+{"y", "1"},
+{"scalex", "(1/2)"},
+{"scaley", "(2/3)"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/eps[1]/metafile[1]/point[1]", {
+{"x", "1"},
+{"y", "8"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/eps[1]/metafile[1]/point[2]", {
+{"x", "2"},
+{"y", "7"}
+});
+}
+
 void SvmTest::testEPS()
-{}
+{
+GDIMetaFile aGDIMetaFile;
+ScopedVclPtrInstance pVirtualDev;
+setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
+
+sal_uInt32 nDataSize = 3;
+std::unique_ptr pBuffer (new sal_uInt8[nDataSize]);
+pBuffer[0] = 'a';
+pBuffer[1] = 'b';
+pBuffer[2] = 'c';
+
+MapMode aMapMode1(MapUnit::Map100thInch);
+aMapMode1.SetOrigin(Point(0, 1));
+aMapMode1.SetScaleX(Fraction(1, 2));
+aMapMode1.SetScaleY(Fraction(2, 3));
+
+GDIMetaFile aGDIMetaFile1;
+ScopedVclPtrInstance pVirtualDev1;
+setupBaseVirtualDevice(*pVirtualDev1, aGDIMetaFile1);
+
+pVirtualDev1->DrawPixel(Point(1, 8));
+pVirtualDev1->DrawPixel(Point(2, 7));
+
+GfxLink aGfxLink(std::move(pBuffer), nDataSize, GfxLinkType::EpsBuffer);
+aGfxLink.SetPrefMapMode(aMapMode1);
+aGfxLink.SetUserId(12345);
+aGfxLink.SetPrefSize(Size(3, 6));
+pVirtualDev->DrawEPS(Point(1, 8), Size(2, 7), aGfxLink, &aGDIMetaFile1);
+
+checkEPS(writeAndReadStream(aGDIMetaFile));
+checkEPS(readFile(u"eps.svm"));
+}
 
 void SvmTest::checkRefPoint(const GDIMetaFile& rMetaFile)
 {
diff --git a/vcl/source/gdi/mtfxmldump.cxx b/vcl/source/gdi/mtfxmldump.cxx
index 0b9ba2c2ef20..64df808a 100644
--- a/vcl/source/gdi/mtfxmldump.cxx
+++ b/vcl/source/gdi/mtfxmldump.cxx
@@ -452,6 +452,27 @@ OUString 
convertComplexTestLayoutFlags(ComplexTextLayoutFlags eComplexTestLayout
 }
 }
 
+OUString convertGfxLinkTypeToString(GfxLinkType eGfxLinkType)
+{
+switch(eGfxLinkType)
+{
+case GfxLinkType::EpsBuffer: return "EpsBuffer";
+case GfxLinkType::NativeBmp: return "NativeBmp";
+case GfxLinkType::NativeGif: return "NativeGif";
+case GfxLinkType::NativeJpg: return "NativeJpg";
+case GfxLinkType::NativeMet: return "NativeMet";
+case GfxLinkType::NativeMov: return "NativeMov";
+case GfxLinkType::NativePct: return "NativePct";
+case GfxLinkType::NativePdf: return "NativePdf";
+case GfxLinkType::NativePng: return "NativePng";
+case GfxLinkType::NativeSvg: return "NativeSvg";
+case GfxLinkType::NativeTif: return "NativeTif";
+case GfxLinkType::NativeWmf: return "NativeWmf";
+case GfxLinkType::NONE

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

2021-06-22 Thread panoskorovesis (via logerrit)
 vcl/qa/cppunit/svm/data/layoutmode.svm |binary
 vcl/qa/cppunit/svm/svmtest.cxx |   27 +--
 vcl/source/gdi/mtfxmldump.cxx  |   26 +-
 3 files changed, 50 insertions(+), 3 deletions(-)

New commits:
commit bc4cea4943c9189b92f51aacf097549023398b2e
Author: panoskorovesis 
AuthorDate: Mon Jun 21 14:40:08 2021 +0300
Commit: Tomaž Vajngerl 
CommitDate: Wed Jun 23 08:57:09 2021 +0200

Add LayoutMode cppunit test to vcl.

The test sets two LayoutModes (using ComplexTextLayoutFlags)
and checks their attributes.

Change-Id: Id765c150485c6f06c1326498a7f1b40b8f9c12fa
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117575
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/svm/data/layoutmode.svm 
b/vcl/qa/cppunit/svm/data/layoutmode.svm
new file mode 100644
index ..d12f09d663aa
Binary files /dev/null and b/vcl/qa/cppunit/svm/data/layoutmode.svm differ
diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx
index a8244ff2f25b..a95c249c96bf 100644
--- a/vcl/qa/cppunit/svm/svmtest.cxx
+++ b/vcl/qa/cppunit/svm/svmtest.cxx
@@ -190,7 +190,7 @@ class SvmTest : public test::BootstrapFixture, public 
XmlTestTools
 void checkComment(const GDIMetaFile& rMetaFile);
 void testComment();
 
-//void checkLayoutMode(const GDIMetaFile& rMetaFile);
+void checkLayoutMode(const GDIMetaFile& rMetaFile);
 void testLayoutMode();
 
 void checkTextLanguage(const GDIMetaFile& rMetaFile);
@@ -2108,8 +2108,31 @@ void SvmTest::testComment()
 checkComment(readFile(u"comment.svm"));
 }
 
+void SvmTest::checkLayoutMode(const GDIMetaFile& rMetaFile)
+{
+xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
+
+assertXPathAttrs(pDoc, "/metafile/layoutmode[1]", {
+{"textlayout", "#0004"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/layoutmode[2]", {
+{"textlayout", "#0001"}
+});
+}
+
 void SvmTest::testLayoutMode()
-{}
+{
+GDIMetaFile aGDIMetaFile;
+ScopedVclPtrInstance pVirtualDev;
+setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
+
+pVirtualDev->SetLayoutMode(ComplexTextLayoutFlags::TextOriginLeft);
+pVirtualDev->SetLayoutMode(ComplexTextLayoutFlags::BiDiRtl);
+
+checkLayoutMode(writeAndReadStream(aGDIMetaFile));
+checkLayoutMode(readFile(u"layoutmode.svm"));
+}
 
 void SvmTest::checkTextLanguage(const GDIMetaFile& rMetaFile)
 {
diff --git a/vcl/source/gdi/mtfxmldump.cxx b/vcl/source/gdi/mtfxmldump.cxx
index 901edde87437..0b9ba2c2ef20 100644
--- a/vcl/source/gdi/mtfxmldump.cxx
+++ b/vcl/source/gdi/mtfxmldump.cxx
@@ -439,6 +439,19 @@ OUString convertPixelFormatToString(vcl::PixelFormat 
ePixelFormat)
 return OUString();
 }
 
+OUString convertComplexTestLayoutFlags(ComplexTextLayoutFlags 
eComplexTestLayoutFlags)
+{
+switch(eComplexTestLayoutFlags)
+{
+default:
+case ComplexTextLayoutFlags::Default: return "#";
+case ComplexTextLayoutFlags::BiDiRtl: return "#0001";
+case ComplexTextLayoutFlags::BiDiStrong: return "#0002";
+case ComplexTextLayoutFlags::TextOriginLeft: return "#0004";
+case ComplexTextLayoutFlags::TextOriginRight: return "#0008";
+}
+}
+
 OUString hex32(sal_uInt32 nNumber)
 {
 std::stringstream ss;
@@ -1351,7 +1364,18 @@ void MetafileXmlDump::writeXml(const GDIMetaFile& 
rMetaFile, tools::XmlWriter& r
 }
 break;
 
-//case MetaActionType::LAYOUTMODE:
+case MetaActionType::LAYOUTMODE:
+{
+const MetaLayoutModeAction* pMetaLayoutModeAction = 
static_cast(pAction);
+
+rWriter.startElement(sCurrentElementTag);
+
+rWriter.attribute("textlayout", 
convertComplexTestLayoutFlags(pMetaLayoutModeAction->GetLayoutMode()));
+
+rWriter.endElement();
+}
+break;
+
 case MetaActionType::TEXTLANGUAGE:
 {
 const MetaTextLanguageAction* pMetaTextLanguageAction = 
static_cast(pAction);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2021-06-22 Thread panoskorovesis (via logerrit)
 vcl/qa/cppunit/svm/data/textlanguage.svm |binary
 vcl/qa/cppunit/svm/svmtest.cxx   |   27 +--
 vcl/source/gdi/mtfxmldump.cxx|   19 ++-
 3 files changed, 43 insertions(+), 3 deletions(-)

New commits:
commit 659c6af5338e1a6d6ff7715f20fa992b62c48ce5
Author: panoskorovesis 
AuthorDate: Fri Jun 18 09:40:58 2021 +0300
Commit: Tomaž Vajngerl 
CommitDate: Wed Jun 23 08:56:09 2021 +0200

Add TextLanguage cppunit test to vcl.

The test sets two languages for the metafile and checks their attributes.

Change-Id: Ibb23c03af48af5c40ea65593917a40a928fd1280
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117368
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/svm/data/textlanguage.svm 
b/vcl/qa/cppunit/svm/data/textlanguage.svm
new file mode 100644
index ..2e930d27e55e
Binary files /dev/null and b/vcl/qa/cppunit/svm/data/textlanguage.svm differ
diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx
index 605a8f5c8afd..a8244ff2f25b 100644
--- a/vcl/qa/cppunit/svm/svmtest.cxx
+++ b/vcl/qa/cppunit/svm/svmtest.cxx
@@ -193,7 +193,7 @@ class SvmTest : public test::BootstrapFixture, public 
XmlTestTools
 //void checkLayoutMode(const GDIMetaFile& rMetaFile);
 void testLayoutMode();
 
-//void checkTextLanguage(const GDIMetaFile& rMetaFile);
+void checkTextLanguage(const GDIMetaFile& rMetaFile);
 void testTextLanguage();
 
 public:
@@ -2111,8 +2111,31 @@ void SvmTest::testComment()
 void SvmTest::testLayoutMode()
 {}
 
+void SvmTest::checkTextLanguage(const GDIMetaFile& rMetaFile)
+{
+xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
+
+assertXPathAttrs(pDoc, "/metafile/textlanguage[1]", {
+{"language", "#0408"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/textlanguage[2]", {
+{"language", "#00ff"}
+});
+}
+
 void SvmTest::testTextLanguage()
-{}
+{
+GDIMetaFile aGDIMetaFile;
+ScopedVclPtrInstance pVirtualDev;
+setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
+
+pVirtualDev->SetDigitLanguage(LANGUAGE_GREEK);
+pVirtualDev->SetDigitLanguage(LANGUAGE_NONE);
+
+checkTextLanguage(writeAndReadStream(aGDIMetaFile));
+checkTextLanguage(readFile(u"textlanguage.svm"));
+}
 
 CPPUNIT_TEST_SUITE_REGISTRATION(SvmTest);
 
diff --git a/vcl/source/gdi/mtfxmldump.cxx b/vcl/source/gdi/mtfxmldump.cxx
index 84c280c2eaae..901edde87437 100644
--- a/vcl/source/gdi/mtfxmldump.cxx
+++ b/vcl/source/gdi/mtfxmldump.cxx
@@ -398,6 +398,13 @@ OUString convertHatchStyle(HatchStyle eStyle)
 return OUString();
 }
 
+OUString convertLanguageTypeToString(LanguageType rLanguageType)
+{
+std::stringstream ss;
+ss << std::hex << std::setfill ('0') << std::setw(4) << 
rLanguageType.get();
+return "#" + OUString::createFromAscii(ss.str().c_str());
+}
+
 OUString convertWallpaperStyleToString(WallpaperStyle eWallpaperStyle)
 {
 switch (eWallpaperStyle)
@@ -1345,7 +1352,17 @@ void MetafileXmlDump::writeXml(const GDIMetaFile& 
rMetaFile, tools::XmlWriter& r
 break;
 
 //case MetaActionType::LAYOUTMODE:
-//case MetaActionType::TEXTLANGUAGE:
+case MetaActionType::TEXTLANGUAGE:
+{
+const MetaTextLanguageAction* pMetaTextLanguageAction = 
static_cast(pAction);
+
+rWriter.startElement(sCurrentElementTag);
+
+rWriter.attribute("language", 
convertLanguageTypeToString(pMetaTextLanguageAction->GetTextLanguage()));
+
+rWriter.endElement();
+}
+break;
 
 case MetaActionType::OVERLINECOLOR:
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2021-06-15 Thread panoskorovesis (via logerrit)
 vcl/qa/cppunit/svm/data/moveclipregion.svm |binary
 vcl/qa/cppunit/svm/svmtest.cxx |   35 +++--
 vcl/source/gdi/mtfxmldump.cxx  |   11 -
 3 files changed, 43 insertions(+), 3 deletions(-)

New commits:
commit 240c6557898de6ab2b2055d1c133a803b396
Author: panoskorovesis 
AuthorDate: Mon Jun 14 14:04:37 2021 +0300
Commit: Tomaž Vajngerl 
CommitDate: Wed Jun 16 08:22:48 2021 +0200

Add MoveClipRegion cppunit test to vcl

The test creates two MoveClipRegions and checks their attributes.
mtfxmldump.cxx was modified to support MoveClipRegion case.

Change-Id: Ibfabf9d4048cf94e43c259e411a6c59b73baff34
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117153
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/svm/data/moveclipregion.svm 
b/vcl/qa/cppunit/svm/data/moveclipregion.svm
new file mode 100644
index ..6b53403741be
Binary files /dev/null and b/vcl/qa/cppunit/svm/data/moveclipregion.svm differ
diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx
index 3fb91f84f006..02fbcdb5c04f 100644
--- a/vcl/qa/cppunit/svm/svmtest.cxx
+++ b/vcl/qa/cppunit/svm/svmtest.cxx
@@ -136,7 +136,7 @@ class SvmTest : public test::BootstrapFixture, public 
XmlTestTools
 void checkIntersectRegionClipRegion(const GDIMetaFile& rMetaFile);
 void testIntersectRegionClipRegion();
 
-//void checkMoveClipRegion(const GDIMetaFile& rMetaFile);
+void checkMoveClipRegion(const GDIMetaFile& rMetaFile);
 void testMoveClipRegion();
 
 void checkLineColor(const GDIMetaFile& rMetaFile);
@@ -1647,8 +1647,39 @@ void SvmTest::testIntersectRegionClipRegion()
 checkIntersectRegionClipRegion(readFile(u"intersectregionclipregion.svm"));
 }
 
+void SvmTest::checkMoveClipRegion(const GDIMetaFile& rMetaFile)
+{
+xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
+
+assertXPathAttrs(pDoc, "/metafile/moveclipregion[1]", {
+{"horzmove", "1"},
+{"vertmove", "2"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/moveclipregion[2]", {
+{"horzmove", "-3"},
+{"vertmove", "-4"}
+});
+}
+
 void SvmTest::testMoveClipRegion()
-{}
+{
+GDIMetaFile aGDIMetaFile;
+ScopedVclPtrInstance pVirtualDev;
+setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
+
+tools::Rectangle aRectangle(Point(1, 2), Size(4, 8));
+
+vcl::Region aRegion(aRectangle);
+aRegion.Move(2, 2);
+pVirtualDev->SetClipRegion(aRegion);
+
+pVirtualDev->MoveClipRegion(1, 2);
+pVirtualDev->MoveClipRegion(-3, -4);
+
+checkMoveClipRegion(writeAndReadStream(aGDIMetaFile));
+checkMoveClipRegion(readFile(u"moveclipregion.svm"));
+}
 
 void SvmTest::checkLineColor(const GDIMetaFile& rMetaFile)
 {
diff --git a/vcl/source/gdi/mtfxmldump.cxx b/vcl/source/gdi/mtfxmldump.cxx
index 7799a3014f15..e5651906ed57 100644
--- a/vcl/source/gdi/mtfxmldump.cxx
+++ b/vcl/source/gdi/mtfxmldump.cxx
@@ -1094,7 +1094,16 @@ void MetafileXmlDump::writeXml(const GDIMetaFile& 
rMetaFile, tools::XmlWriter& r
 }
 break;
 
-// case MetaActionType::MOVECLIPREGION:
+case MetaActionType::MOVECLIPREGION:
+{
+const auto* pMetaMoveClipRegionAction = 
static_cast(pAction);
+rWriter.startElement(sCurrentElementTag);
+
+rWriter.attribute("horzmove", 
pMetaMoveClipRegionAction->GetHorzMove());
+rWriter.attribute("vertmove", 
pMetaMoveClipRegionAction->GetVertMove());
+rWriter.endElement();
+}
+break;
 
 case MetaActionType::LINECOLOR:
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2021-06-14 Thread panoskorovesis (via logerrit)
 vcl/qa/cppunit/svm/data/clipregion.svm |binary
 vcl/qa/cppunit/svm/svmtest.cxx |   96 +++--
 vcl/source/gdi/mtfxmldump.cxx  |   24 
 3 files changed, 116 insertions(+), 4 deletions(-)

New commits:
commit fff9163cd8ad27d251c06d0e903a71e185009d80
Author: panoskorovesis 
AuthorDate: Thu Jun 10 09:41:18 2021 +0300
Commit: Tomaž Vajngerl 
CommitDate: Mon Jun 14 14:46:06 2021 +0200

Add ClipRegion cppunit test to vcl

The test creates multiple ClipRegions with
different shapes and tests their attributes.
Makefile was edited to support basegfx::B2DPolyPolygon

Change-Id: Iabdf744e1749627b2bc4cbc0c8e933b38552e785
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116959
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/svm/data/clipregion.svm 
b/vcl/qa/cppunit/svm/data/clipregion.svm
index aa0d277fee1f..bf8170222c61 100644
Binary files a/vcl/qa/cppunit/svm/data/clipregion.svm and 
b/vcl/qa/cppunit/svm/data/clipregion.svm differ
diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx
index ec9c80614e22..3fb91f84f006 100644
--- a/vcl/qa/cppunit/svm/svmtest.cxx
+++ b/vcl/qa/cppunit/svm/svmtest.cxx
@@ -23,6 +23,8 @@
 
 #include 
 
+#include 
+
 #include 
 #include 
 
@@ -1447,6 +1449,66 @@ void SvmTest::checkClipRegion(const GDIMetaFile& 
rMetaFile)
 {"right", "5"},
 {"bottom", "5"},
 });
+
+assertXPathAttrs(pDoc, "/metafile/clipregion[2]/polygon[1]/point[1]", {
+{"x", "1"},
+{"y", "8"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/clipregion[2]/polygon[1]/point[2]", {
+{"x", "2"},
+{"y", "7"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/clipregion[2]/polygon[1]/point[3]", {
+{"x", "3"},
+{"y", "6"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/clipregion[3]/polygon[1]/point[1]", {
+{"x", "1"},
+{"y", "8"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/clipregion[3]/polygon[1]/point[2]", {
+{"x", "2"},
+{"y", "7"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/clipregion[3]/polygon[1]/point[3]", {
+{"x", "3"},
+{"y", "6"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/clipregion[3]/polygon[2]/point[1]", {
+{"x", "4"},
+{"y", "9"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/clipregion[3]/polygon[2]/point[2]", {
+{"x", "5"},
+{"y", "10"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/clipregion[3]/polygon[2]/point[3]", {
+{"x", "6"},
+{"y", "11"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/clipregion[4]/polygon[1]/point[1]", {
+{"x", "0"},
+{"y", "1"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/clipregion[4]/polygon[1]/point[2]", {
+{"x", "2"},
+{"y", "3"}
+});
+
+assertXPathAttrs(pDoc, "/metafile/clipregion[4]/polygon[1]/point[3]", {
+{"x", "4"},
+{"y", "4"}
+});
 }
 
 void SvmTest::testClipRegion()
@@ -1457,12 +1519,38 @@ void SvmTest::testClipRegion()
 
 vcl::Region aRegion(tools::Rectangle(Point(2, 2), Size(4, 4)));
 
-// TODO
-// explicit Region(const tools::Polygon& rPolygon);
-// explicit Region(const tools::PolyPolygon& rPolyPoly);
-// explicit Region(const basegfx::B2DPolyPolygon&);
 pVirtualDev->SetClipRegion(aRegion);
 
+tools::Polygon aPolygon(3);
+aPolygon.SetPoint(Point(1, 8), 0);
+aPolygon.SetPoint(Point(2, 7), 1);
+aPolygon.SetPoint(Point(3, 6), 2);
+
+vcl::Region aRegion2(aPolygon);
+pVirtualDev->SetClipRegion(aRegion2);
+
+tools::Polygon aPolygon1(3);
+aPolygon1.SetPoint(Point(4, 9), 0);
+aPolygon1.SetPoint(Point(5, 10), 1);
+aPolygon1.SetPoint(Point(6, 11), 2);
+
+tools::PolyPolygon aPolyPolygon(2);
+aPolyPolygon.Insert(aPolygon);
+aPolyPolygon.Insert(aPolygon1);
+
+vcl::Region aRegion3(aPolyPolygon);
+pVirtualDev->SetClipRegion(aRegion3);
+
+basegfx::B2DPolygon aB2DPolygon;
+aB2DPolygon.append(basegfx::B2DPoint(0.0, 1.1));
+aB2DPolygon.append(basegfx::B2DPoint(2.2, 3.3));
+aB2DPolygon.append(basegfx::B2DPoint(3.7, 3.8));
+
+basegfx::B2DPolyPolygon aB2DPolyPolygon(aB2DPolygon);
+
+vcl::Region aRegion4(aB2DPolyPolygon);
+pVirtualDev->SetClipRegion(aRegion4);
+
 checkClipRegion(writeAndReadStream(aGDIMetaFile));
 checkClipRegion(readFile(u"clipregion.svm"));
 }
diff --git a/vcl/source/gdi/mtfxmldump.cxx b/vcl/source/gdi/mtfxmldump.cxx
index 8bd21b9d7460..7799a3014f15 100644
--- a/vcl/source/gdi/mtfxmldump.cxx
+++ b/vcl/source/gdi/mtfxmldump.cxx
@@ -1041,6 +1041,30 @@ void MetafileXmlDump::writeXml(const GDIMetaFile& 
rMetaFile, tools::XmlWriter& r
 // dumping the real polypolygon in the future
 tools::Rectangle aRectangle = 
pMetaClipRegionAction->GetRegion().GetBoundRect();
 writeRectangle(rWriter, aRectangle);
+
+

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

2021-06-11 Thread Luboš Luňák (via logerrit)
 vcl/qa/cppunit/GraphicTest.cxx   |   79 +++
 vcl/qa/cppunit/data/wmf-embedded-emfplus.wmf |binary
 vcl/source/filter/wmf/wmf.cxx|   11 ++-
 3 files changed, 85 insertions(+), 5 deletions(-)

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

when converting WMF to WMF, simply do a direct copy

Actually, if we have the graphics data, just copy the graphics data,
that'll keep both the EMF+ and non-EMF+ content.

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

diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
index 608c5f4de85d..e9af574aa5a4 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -53,6 +54,7 @@ private:
 void testUnloadedGraphicSizeUnit();
 
 void testWMFRoundtrip();
+void testWMFWithEmfPlusRoundtrip();
 void testEmfToWmfConversion();
 
 void testSwappingGraphic_PNG_WithGfxLink();
@@ -89,6 +91,7 @@ private:
 CPPUNIT_TEST(testUnloadedGraphicAlpha);
 CPPUNIT_TEST(testUnloadedGraphicSizeUnit);
 CPPUNIT_TEST(testWMFRoundtrip);
+CPPUNIT_TEST(testWMFWithEmfPlusRoundtrip);
 CPPUNIT_TEST(testEmfToWmfConversion);
 
 CPPUNIT_TEST(testSwappingGraphic_PNG_WithGfxLink);
@@ -411,6 +414,82 @@ void GraphicTest::testWMFRoundtrip()
 CPPUNIT_ASSERT_EQUAL(nExpectedSize, nActualSize);
 }
 
+int getEmfPlusActionsCount(const Graphic& graphic)
+{
+const GDIMetaFile& metafile = graphic.GetGDIMetaFile();
+int emfPlusCount = 0;
+for (size_t i = 0; i < metafile.GetActionSize(); ++i)
+{
+MetaAction* action = metafile.GetAction(i);
+if (action->GetType() == MetaActionType::COMMENT)
+{
+const MetaCommentAction* commentAction = static_cast(action);
+if (commentAction->GetComment() == "EMF_PLUS")
+++emfPlusCount;
+}
+}
+return emfPlusCount;
+}
+
+int getPolygonActionsCount(const Graphic& graphic)
+{
+const GDIMetaFile& metafile = graphic.GetGDIMetaFile();
+int polygonCount = 0;
+for (size_t i = 0; i < metafile.GetActionSize(); ++i)
+{
+MetaAction* action = metafile.GetAction(i);
+if (action->GetType() == MetaActionType::POLYGON)
+++polygonCount;
+}
+return polygonCount;
+}
+
+void GraphicTest::testWMFWithEmfPlusRoundtrip()
+{
+// Load a WMF file.
+test::Directories aDirectories;
+OUString aURL = 
aDirectories.getURLFromSrc(u"vcl/qa/cppunit/data/wmf-embedded-emfplus.wmf");
+SvFileStream aStream(aURL, StreamMode::READ);
+sal_uInt64 nExpectedSize = aStream.TellEnd();
+GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
+Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
+
+CPPUNIT_ASSERT_GREATER(0, getEmfPlusActionsCount(aGraphic));
+CPPUNIT_ASSERT_EQUAL(0, getPolygonActionsCount(aGraphic));
+
+for (bool useConvertMetafile : { false, true })
+{
+// Save as WMF.
+utl::TempFile aTempFile;
+aTempFile.EnableKillingFile();
+SvStream& rOutStream = *aTempFile.GetStream(StreamMode::READWRITE);
+if (useConvertMetafile)
+ConvertGraphicToWMF(aGraphic, rOutStream, nullptr);
+else
+{
+sal_uInt16 nFormat = 
rGraphicFilter.GetExportFormatNumberForShortName(u"WMF");
+rGraphicFilter.ExportGraphic(aGraphic, OUString(), rOutStream, 
nFormat);
+}
+CPPUNIT_ASSERT_EQUAL(nExpectedSize, rOutStream.TellEnd());
+
+rOutStream.Seek(0);
+Graphic aNewGraphic = rGraphicFilter.ImportUnloadedGraphic(rOutStream);
+// Check that reading the WMF back preserves the EMF+ actions in it.
+CPPUNIT_ASSERT_GREATER(0, getEmfPlusActionsCount(aNewGraphic));
+// EmfReader::ReadEnhWMF() drops non-EMF+ drawing actions if EMF+ is 
found.
+CPPUNIT_ASSERT_EQUAL(0, getPolygonActionsCount(aNewGraphic));
+
+// With EMF+ disabled there should be no EMF+ actions.
+auto& rDataContainer = aNewGraphic.GetGfxLink().getDataContainer();
+auto aVectorGraphicData
+= std::make_shared(rDataContainer, 
VectorGraphicDataType::Wmf);
+aVectorGraphicData->setEnableEMFPlus(false);
+Graphic aNoEmfPlusGraphic(aVectorGraphicData);
+CPPUNIT_ASSERT_EQUAL(0, getEmfPlusActionsCount(aNoEmfPlusGraphic));
+CPPUNIT_ASSERT_GREATER(0, getPolygonActionsCount(aNoEmfPlusGraphic));
+}
+}
+
 void GraphicTest::testEmfToWmfConversion()
 {
 // Load EMF data.
diff --git a/vcl/qa/cppunit/data/wmf-embedded-emfplus.wmf 
b/vcl/qa/cppunit/data/wmf-embedde

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

2021-06-11 Thread Julien Nabet (via logerrit)
 vcl/qa/cppunit/canvasbitmaptest.cxx |   28 ++--
 vcl/source/gdi/print.cxx|4 +---
 vcl/source/helper/canvastools.cxx   |   25 +
 3 files changed, 32 insertions(+), 25 deletions(-)

New commits:
commit 771c8282aadb45373fc6348cc70f4cd75a43a396
Author: Julien Nabet 
AuthorDate: Fri Jun 11 14:20:45 2021 +0200
Commit: Julien Nabet 
CommitDate: Fri Jun 11 15:32:10 2021 +0200

Simplify Sequences initializations (vcl)

Change-Id: Id93bde17dbc4c71ad93bc094b94408fc9e39ec98
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117055
Tested-by: Jenkins
Reviewed-by: Julien Nabet 

diff --git a/vcl/qa/cppunit/canvasbitmaptest.cxx 
b/vcl/qa/cppunit/canvasbitmaptest.cxx
index d77599e7b8a4..9b50282ee8b0 100644
--- a/vcl/qa/cppunit/canvasbitmaptest.cxx
+++ b/vcl/qa/cppunit/canvasbitmaptest.cxx
@@ -216,19 +216,27 @@ void checkCanvasBitmap( const 
rtl::Reference& xBmp,
 if( nOriginalDepth <= 8 )
 return;
 
-uno::Sequence aARGBColor(1);
-uno::Sequence  aRGBColor(1);
 uno::Sequence aPixel3, aPixel4;
 
 const Color aCol(COL_GREEN);
-aARGBColor[0].Red   = vcl::unotools::toDoubleColor(aCol.GetRed());
-aARGBColor[0].Green = vcl::unotools::toDoubleColor(aCol.GetGreen());
-aARGBColor[0].Blue  = vcl::unotools::toDoubleColor(aCol.GetBlue());
-aARGBColor[0].Alpha = 1.0;
-
-aRGBColor[0].Red   = vcl::unotools::toDoubleColor(aCol.GetRed());
-aRGBColor[0].Green = vcl::unotools::toDoubleColor(aCol.GetGreen());
-aRGBColor[0].Blue  = vcl::unotools::toDoubleColor(aCol.GetBlue());
+uno::Sequence aARGBColor
+{
+{
+1.0,
+vcl::unotools::toDoubleColor(aCol.GetRed()),
+vcl::unotools::toDoubleColor(aCol.GetGreen()),
+vcl::unotools::toDoubleColor(aCol.GetBlue())
+}
+};
+
+uno::Sequence  aRGBColor
+{
+{
+vcl::unotools::toDoubleColor(aCol.GetRed()),
+vcl::unotools::toDoubleColor(aCol.GetGreen()),
+vcl::unotools::toDoubleColor(aCol.GetBlue())
+}
+};
 
 aPixel3 = xBmp->convertIntegerFromARGB( aARGBColor );
 aPixel4 = xBmp->getPixel( aLayout, geometry::IntegerPoint2D(5,0) );
diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx
index d7928956e9bd..652bc00c58be 100644
--- a/vcl/source/gdi/print.cxx
+++ b/vcl/source/gdi/print.cxx
@@ -123,17 +123,15 @@ void PrinterOptions::ReadFromConfig( bool i_bFile )
 {
 xConfigProvider = css::configuration::theDefaultProvider::get( 
xContext );
 
-css::uno::Sequence< css::uno::Any > aArgs(1);
 css::beans::PropertyValue aVal;
 aVal.Name = "nodepath";
 if( i_bFile )
 aVal.Value <<= OUString( 
"/org.openoffice.Office.Common/Print/Option/File" );
 else
 aVal.Value <<= OUString( 
"/org.openoffice.Office.Common/Print/Option/Printer" );
-aArgs.getArray()[0] <<= aVal;
 xConfigAccess.set(
 xConfigProvider->createInstanceWithArguments(
-"com.sun.star.configuration.ConfigurationAccess", 
aArgs ),
+"com.sun.star.configuration.ConfigurationAccess", { 
css::uno::Any(aVal) } ),
 css::uno::UNO_QUERY );
 if( xConfigAccess.is() )
 {
diff --git a/vcl/source/helper/canvastools.cxx 
b/vcl/source/helper/canvastools.cxx
index fef5500a8227..c547dace4a14 100644
--- a/vcl/source/helper/canvastools.cxx
+++ b/vcl/source/helper/canvastools.cxx
@@ -565,15 +565,13 @@ namespace vcl::unotools
 
 uno::Sequence< double > colorToStdColorSpaceSequence( const Color& 
rColor )
 {
-uno::Sequence< double > aRet(4);
-double* pRet = aRet.getArray();
-
-pRet[0] = toDoubleColor(rColor.GetRed());
-pRet[1] = toDoubleColor(rColor.GetGreen());
-pRet[2] = toDoubleColor(rColor.GetBlue());
-pRet[3] = toDoubleColor(rColor.GetAlpha());
-
-return aRet;
+return
+{
+toDoubleColor(rColor.GetRed()),
+toDoubleColor(rColor.GetGreen()),
+toDoubleColor(rColor.GetBlue()),
+toDoubleColor(rColor.GetAlpha())
+};
 }
 
 Color stdColorSpaceSequenceToColor( const uno::Sequence< double >& 
rColor)
@@ -595,12 +593,15 @@ namespace vcl::unotools
 const Color&rColor,
 const uno::Reference< rendering::XColorSpace >& xColorSpace )
 {
-uno::Sequence aSeq(1);
-aSeq[0] = rendering::ARGBColor(
+uno::Sequence aSeq
+{
+{
 toDoubleColor(rColor.GetAlpha()),
 toDoubleColor(rColor.GetRed()),
 toDoubleColor(rColor.GetGreen()),
-to

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

2021-06-09 Thread panoskorovesis (via logerrit)
 vcl/qa/cppunit/svm/data/gradientex.svm |binary
 vcl/qa/cppunit/svm/svmtest.cxx |  105 -
 vcl/source/gdi/mtfxmldump.cxx  |   30 -
 3 files changed, 131 insertions(+), 4 deletions(-)

New commits:
commit dbd86edb55de543d9b0b88bca1d43676da88215a
Author: panoskorovesis 
AuthorDate: Wed Jun 9 10:32:25 2021 +0300
Commit: Tomaž Vajngerl 
CommitDate: Wed Jun 9 15:49:06 2021 +0200

Add GradientEx cppunit test to vcl

The test creates two GradientEx and checks
their attributes. In mtfxmldump.cxx the
case regarding GradientEx was completed

Change-Id: I52f2303fa3123b97fb8a4b0783610c0bae300fc8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116819
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/svm/data/gradientex.svm 
b/vcl/qa/cppunit/svm/data/gradientex.svm
new file mode 100644
index ..6a83d078cd2c
Binary files /dev/null and b/vcl/qa/cppunit/svm/data/gradientex.svm differ
diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx
index 0331502d1041..844a12bd1214 100644
--- a/vcl/qa/cppunit/svm/svmtest.cxx
+++ b/vcl/qa/cppunit/svm/svmtest.cxx
@@ -116,7 +116,7 @@ class SvmTest : public test::BootstrapFixture, public 
XmlTestTools
 void checkGradient(const GDIMetaFile& rMetaFile);
 void testGradient();
 
-//void checkGradientEx(const GDIMetaFile& rMetaFile);
+void checkGradientEx(const GDIMetaFile& rMetaFile);
 void testGradientEx();
 
 void checkHatch(const GDIMetaFile& rMetaFile);
@@ -1254,8 +1254,109 @@ void SvmTest::testGradient()
 checkGradient(readFile(u"gradient.svm"));
 }
 
+void SvmTest::checkGradientEx(const GDIMetaFile& rMetaFile)
+{
+xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
+
+assertXPathAttrs(pDoc, "/metafile/gradientex[1]", {
+{"style", "Linear"},
+{"startcolor", "#ff"},
+{"endcolor", "#00"},
+{"angle", "0"},
+{"border", "0"},
+{"offsetx", "50"},
+{"offsety", "50"},
+{"startintensity", "100"},
+{"endintensity", "100"},
+{"steps", "0"}
+});
+assertXPathAttrs(pDoc, "/metafile/gradientex[1]/polygon/point[1]", {
+{"x", "1"},
+{"y", "8"}
+});
+assertXPathAttrs(pDoc, "/metafile/gradientex[1]/polygon/point[2]", {
+{"x", "2"},
+{"y", "7"}
+});
+assertXPathAttrs(pDoc, "/metafile/gradientex[1]/polygon/point[3]", {
+{"x", "3"},
+{"y", "6"}
+});
+assertXPathAttrs(pDoc, "/metafile/gradientex[2]", {
+{"style", "Axial"},
+{"startcolor", "#ff00ff"},
+{"endcolor", "#008080"},
+{"angle", "55"},
+{"border", "10"},
+{"offsetx", "22"},
+{"offsety", "24"},
+{"startintensity", "4"},
+{"endintensity", "14"},
+{"steps", "64"}
+});
+assertXPathAttrs(pDoc, "/metafile/gradientex[2]/polygon[1]/point[1]", {
+{"x", "1"},
+{"y", "2"}
+});
+assertXPathAttrs(pDoc, "/metafile/gradientex[2]/polygon[1]/point[2]", {
+{"x", "3"},
+{"y", "4"}
+});
+assertXPathAttrs(pDoc, "/metafile/gradientex[2]/polygon[2]/point[1]", {
+{"x", "8"},
+{"y", "9"}
+});
+assertXPathAttrs(pDoc, "/metafile/gradientex[2]/polygon[2]/point[2]", {
+{"x", "6"},
+{"y", "7"}
+});
+}
+
 void SvmTest::testGradientEx()
-{}
+{
+GDIMetaFile aGDIMetaFile;
+ScopedVclPtrInstance pVirtualDev;
+setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
+
+tools::Polygon aPolygon(3);
+aPolygon.SetPoint(Point(1, 8), 0);
+aPolygon.SetPoint(Point(2, 7), 1);
+aPolygon.SetPoint(Point(3, 6), 2);
+
+tools::PolyPolygon aPolyPolygon(1);
+aPolyPolygon.Insert(aPolygon);
+
+Gradient aGradient(GradientStyle::Linear, COL_WHITE, COL_BLACK);
+pVirtualDev->DrawGradient(aPolyPolygon, aGradient);
+
+tools::Polygon aPolygon2(2);
+aPolygon2.SetPoint(Point(1, 2), 0);
+aPolygon2.SetPoint(Point(3, 4), 1);
+
+tools::Polygon aPolygon3(2);
+aPolygon3.SetPoint(Point(8, 9), 0);
+aPolygon3.SetPoint(Point(6, 7), 1);
+
+tools::PolyPolygon aPolyPolygon2(1);
+aPolyPolygon2.Insert(aPolygon2);
+aPolyPolygon2.Insert(aPolygon3);
+
+Gradient aGradient2;
+aGradient2.SetStyle(GradientStyle::Axial);
+aGradient2.SetStartColor(COL_LIGHTMAGENTA);
+aGradient2.SetEndColor(COL_CYAN);
+aGradient2.SetAngle(Degree10(55));
+aGradient2.SetBorder(10);
+aGradient2.SetOfsX(22);
+aGradient2.SetOfsY(24);
+aGradient2.SetStartIntensity(4);
+aGradient2.SetEndIntensity(14);
+aGradient2.SetSteps(64);
+pVirtualDev->DrawGradient(aPolyPolygon2, aGradient2);
+
+checkGradientEx(writeAndReadStream(aGDIMetaFile));
+checkGradientEx(readFile(u"gradientex.svm"));
+}
 
 void SvmTest::checkHatch(const GDIMetaFile& rMetaFile)
 {
diff --git a/vcl/source/gdi/mtfxmldump.cxx b/vcl/source/gdi/

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

2021-05-17 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/pdfexport/data/pdf-image-rotate-180.pdf |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |   67 +
 vcl/source/gdi/pdfwriter_impl.cxx  |   53 -
 3 files changed, 99 insertions(+), 21 deletions(-)

New commits:
commit d7d43cf460d66354a40ffa3b34c0f9efcd42d0be
Author: Miklos Vajna 
AuthorDate: Mon May 17 13:51:31 2021 +0200
Commit: Miklos Vajna 
CommitDate: Mon May 17 15:24:57 2021 +0200

vcl PDF export: fix re-exporting PDF images with arbitrary page-level 
rotation

Building on top of commit bd520b177637d4b7d9d93733103cff17a3c91b0a (vcl
PDF export: fix re-exporting PDF images with page-level rotation,
2019-11-06), this was already working for 90 degrees, now generalize
this to work with 180 degrees as well.

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

diff --git a/vcl/qa/cppunit/pdfexport/data/pdf-image-rotate-180.pdf 
b/vcl/qa/cppunit/pdfexport/data/pdf-image-rotate-180.pdf
new file mode 100644
index ..981ca32061cd
Binary files /dev/null and 
b/vcl/qa/cppunit/pdfexport/data/pdf-image-rotate-180.pdf differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 8e089ded9d95..a3575e415d4f 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -2794,6 +2794,73 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfUaMetadata)
 CPPUNIT_ASSERT_EQUAL(OString("1"), aPdfUaPart);
 }
 
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfImageRotate180)
+{
+// Create an empty document.
+mxComponent = loadFromDesktop("private:factory/swriter");
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xText = xTextDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+
+// Insert the PDF image.
+uno::Reference xFactory(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xGraphicObject(
+xFactory->createInstance("com.sun.star.text.TextGraphicObject"), 
uno::UNO_QUERY);
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"pdf-image-rotate-180.pdf";
+xGraphicObject->setPropertyValue("GraphicURL", uno::makeAny(aURL));
+uno::Reference xShape(xGraphicObject, uno::UNO_QUERY);
+xShape->setSize(awt::Size(1000, 1000));
+uno::Reference xTextContent(xGraphicObject, 
uno::UNO_QUERY);
+xText->insertTextContent(xCursor->getStart(), xTextContent, 
/*bAbsorb=*/false);
+
+// Save as PDF.
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+utl::MediaDescriptor aMediaDescriptor;
+aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+xStorable->storeToURL(maTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
+
+// Parse the export result.
+SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
+maMemory.WriteStream(aFile);
+std::shared_ptr pPDFium = vcl::pdf::PDFiumLibrary::get();
+std::unique_ptr pPdfDocument
+= pPDFium->openDocument(maMemory.GetData(), maMemory.GetSize());
+CPPUNIT_ASSERT(pPdfDocument);
+CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
+
+// Make sure that the page -> form -> form has a child image.
+std::unique_ptr pPdfPage = 
pPdfDocument->openPage(/*nIndex=*/0);
+CPPUNIT_ASSERT(pPdfPage);
+CPPUNIT_ASSERT_EQUAL(1, pPdfPage->getObjectCount());
+std::unique_ptr pPageObject = 
pPdfPage->getObject(0);
+CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Form, 
pPageObject->getType());
+// 2: white background and the actual object.
+CPPUNIT_ASSERT_EQUAL(2, pPageObject->getFormObjectCount());
+std::unique_ptr pFormObject = 
pPageObject->getFormObject(1);
+CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Form, 
pFormObject->getType());
+CPPUNIT_ASSERT_EQUAL(1, pFormObject->getFormObjectCount());
+
+// Check if the inner form object (original page object in the pdf image) 
has the correct
+// rotation.
+std::unique_ptr pInnerFormObject = 
pFormObject->getFormObject(0);
+CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Form, 
pInnerFormObject->getType());
+CPPUNIT_ASSERT_EQUAL(1, pInnerFormObject->getFormObjectCount());
+std::unique_ptr pImage = 
pInnerFormObject->getFormObject(0);
+CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Image, 
pImage->getType());
+basegfx::B2DHomMatrix aMat = pInnerFormObject->getMatrix();
+basegfx::B2DTuple aScale;
+basegfx::B2DTuple aTranslate;
+double fRotate = 0;
+double fShearX = 0;
+aMat.decompose(aScale, aTranslate, fRotate, fShearX);
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: -1
+// - Actual  : 1
+// i.e. the 180 degrees rotation didn't happen (via a combination of 
horizontal + vertical
+// 

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

2021-05-12 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/filter/ipdf/data/comment-end.pdf |   69 
 vcl/qa/cppunit/filter/ipdf/ipdf.cxx |   19 ++
 vcl/source/filter/ipdf/pdfdocument.cxx  |7 ++
 3 files changed, 94 insertions(+), 1 deletion(-)

New commits:
commit 6b1d5bafdc722d07d3dc4980764275a6caa707ba
Author: Miklos Vajna 
AuthorDate: Wed May 12 10:51:09 2021 +0200
Commit: Miklos Vajna 
CommitDate: Wed May 12 14:58:51 2021 +0200

vcl PDF tokenizer: fix EOF position when \r is not followed by \n

Otherwise this would break partial tokenize when we only read a trailer
in the middle of the file: m_aEOFs.back() is one byte larger than
rStream.Tell(), so we reader past the end of the trailer, resulting in a
tokenize failure.

What's special about the bugdoc:

- it has 2 xrefs, the first is incomplete, and refers to a second which
is later in the file
- the object length is as indirect object, triggering an xref lookup
- the first EOF is followed by a \r, but then not with a \n

This results in reading past the end of the first trailer and then
triggering a lookup failure.

FWIW, pdfium does the same in

,
we're on in sync with it.

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

diff --git a/vcl/qa/cppunit/filter/ipdf/data/comment-end.pdf 
b/vcl/qa/cppunit/filter/ipdf/data/comment-end.pdf
new file mode 100644
index ..6f1ad86f5c99
--- /dev/null
+++ b/vcl/qa/cppunit/filter/ipdf/data/comment-end.pdf
@@ -0,0 +1,69 @@
+%PDF-1.7
+%���
+1 0 obj <<
+  /Type /Catalog
+  /Pages 2 0 R
+>>
+endobj
+2 0 obj <<
+  /Type /Pages
+  /MediaBox [0 0 200 300]
+  /Count 1
+  /Kids [3 0 R]
+>>
+endobj
+3 0 obj <<
+  /Type /Page
+  /Parent 2 0 R
+  /Contents 4 0 R
+>>
+endobj
+4 0 obj <<
+  /Length 4
+>>
+stream
+q
+Q
+endstream
+endobj
+xref
+0 5
+00 65535 f 
+15 0 n 
+68 0 n 
+000157 0 n 
+000226 0 n 
+trailer <<
+  /Root 1 0 R
+  /Size 5
+  /Prev 541
+>>
+startxref
+280
+%%EOF
%%TEST
+4 0 obj <<
+  /Length 5 0 R
+>>
+stream
+q
+Q
+endstream
+endobj
+5 0 obj
+4
+endobj
+xref
+0 6
+00 65535 f 
+15 0 n 
+68 0 n 
+000157 0 n 
+000466 0 n 
+000524 0 n 
+trailer <<
+  /Root 1 0 R
+  /Size 6
+>>
+startxref
+280
+%%EOF
diff --git a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx 
b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
index df93de1b3b68..8ed49813e88b 100644
--- a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
+++ b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
@@ -182,6 +182,25 @@ CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, testRealNumbers)
 CPPUNIT_ASSERT(!aPages.empty());
 }
 
+CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, testCommentEnd)
+{
+// Load the test document:
+// - it has two xrefs
+// - second xref has an updated page content object with an indirect length
+// - last startxref refers to the first xref
+// - first xref has a /Prev to the second xref
+// - first xref is terminated by a \r, which is not followed by a newline
+// this means that if reading doesn't stop at the end of the first xref, 
then we'll try to look
+// up the offset of the length object, which we don't yet have
+OUString aSourceURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"comment-end.pdf";
+SvFileStream aFile(aSourceURL, StreamMode::READ);
+vcl::filter::PDFDocument aDocument;
+
+// Without the accompanying fix in place, this test would have failed, 
because Tokenize() didn't
+// stop at the end of the first xref.
+CPPUNIT_ASSERT(aDocument.Read(aFile));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/filter/ipdf/pdfdocument.cxx 
b/vcl/source/filter/ipdf/pdfdocument.cxx
index 5ebe05e6115a..c3f46c339467 100644
--- a/vcl/source/filter/ipdf/pdfdocument.cxx
+++ b/vcl/source/filter/ipdf/pdfdocument.cxx
@@ -2076,9 +2076,14 @@ bool PDFCommentElement::Read(SvStream& rStream)
 sal_uInt64 nPos = rStream.Tell();
 if (ch == '\r')
 {
+rStream.ReadChar(ch);
+rStream.SeekRel(-1);
 // If the comment ends with a \r\n, count the \n as well 
to match Adobe Acrobat
 // behavior.
-nPos += 1;
+if (ch == '\n')
+{
+nPos += 1;
+}
 }
 m_rDoc.PushBackEOF(nPos);
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2021-04-19 Thread Luboš Luňák (via logerrit)
 vcl/qa/cppunit/GraphicTest.cxx   |9 +
 vcl/source/filter/png/PngImageReader.cxx |3 ++-
 2 files changed, 11 insertions(+), 1 deletion(-)

New commits:
commit cbf98d15ebfdeb61d5b797b21442761c76cb5f02
Author: Luboš Luňák 
AuthorDate: Mon Apr 19 12:09:02 2021 +0200
Commit: Luboš Luňák 
CommitDate: Mon Apr 19 16:50:51 2021 +0200

do not overwrite bitmap if using existing one for png loading

A mistake from b94a2dc95dce8c67ddb9f01f7bd91da2a5759d9c.

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

diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
index d323a6cf5869..0f670a4fee36 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -1239,12 +1239,21 @@ void GraphicTest::testAvailableThreaded()
 Graphic pngGraphic1 = importUnloadedGraphic(u"TypeDetectionExample.png");
 Graphic pngGraphic2 = importUnloadedGraphic(u"testBasicMorphology.png");
 std::vector graphics = { &jpgGraphic1, &jpgGraphic2, 
&pngGraphic1, &pngGraphic2 };
+std::vector sizes;
 for (auto& graphic : graphics)
+{
 CPPUNIT_ASSERT(!graphic->isAvailable());
+sizes.push_back(graphic->GetSizePixel());
+}
 GraphicFilter& graphicFilter = GraphicFilter::GetGraphicFilter();
 graphicFilter.MakeGraphicsAvailableThreaded(graphics);
+int i = 0;
 for (auto& graphic : graphics)
+{
 CPPUNIT_ASSERT(graphic->isAvailable());
+CPPUNIT_ASSERT_EQUAL(sizes[i], graphic->GetSizePixel());
+++i;
+}
 }
 
 } // namespace
diff --git a/vcl/source/filter/png/PngImageReader.cxx 
b/vcl/source/filter/png/PngImageReader.cxx
index ff2d8b0a47a0..6631c238629e 100644
--- a/vcl/source/filter/png/PngImageReader.cxx
+++ b/vcl/source/filter/png/PngImageReader.cxx
@@ -477,7 +477,8 @@ bool ImportPNG(SvStream& rInputStream, Graphic& rGraphic, 
GraphicFilterImportFla
 BitmapEx bitmap;
 if (reader(rInputStream, bitmap, nImportFlags, pAccess, pAlphaAccess))
 {
-rGraphic = bitmap;
+if (!(nImportFlags & GraphicFilterImportFlags::UseExistingBitmap))
+rGraphic = bitmap;
 return true;
 }
 return false;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2021-04-15 Thread Luboš Luňák (via logerrit)
 vcl/qa/cppunit/GraphicTest.cxx   |   28 +
 vcl/source/filter/graphicfilter.cxx  |   73 +++--
 vcl/source/filter/png/PngImageReader.cxx |  164 ---
 vcl/source/filter/png/png.hxx|   33 ++
 4 files changed, 230 insertions(+), 68 deletions(-)

New commits:
commit b94a2dc95dce8c67ddb9f01f7bd91da2a5759d9c
Author: Luboš Luňák 
AuthorDate: Thu Apr 15 17:39:48 2021 +0200
Commit: Luboš Luňák 
CommitDate: Thu Apr 15 21:14:49 2021 +0200

threaded loading also for png loader

Similarly how the jpg loader can load in a thread. This somewhat
complicates the loader, since bitmaps cannot be created in threads
that do not hold the SolarMutex, and SolarMutex is held by
GraphicFilter::MakeGraphicsAvailableThreaded(), which cannot
release it (otherwise something else might grab it and change
things in the background).

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

diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
index a64ea67cdb78..d323a6cf5869 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -80,6 +80,8 @@ private:
 void testLoadPCX();
 void testLoadEPS();
 
+void testAvailableThreaded();
+
 CPPUNIT_TEST_SUITE(GraphicTest);
 CPPUNIT_TEST(testUnloadedGraphic);
 CPPUNIT_TEST(testUnloadedGraphicLoading);
@@ -114,6 +116,8 @@ private:
 CPPUNIT_TEST(testLoadPCX);
 CPPUNIT_TEST(testLoadEPS);
 
+CPPUNIT_TEST(testAvailableThreaded);
+
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -247,6 +251,15 @@ Graphic loadGraphic(std::u16string_view const& rFilename)
 return aGraphic;
 }
 
+Graphic importUnloadedGraphic(std::u16string_view const& rFilename)
+{
+test::Directories aDirectories;
+OUString aFilename = aDirectories.getURLFromSrc(DATA_DIRECTORY) + 
rFilename;
+SvFileStream aFileStream(aFilename, StreamMode::READ);
+GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
+return rGraphicFilter.ImportUnloadedGraphic(aFileStream);
+}
+
 void GraphicTest::testUnloadedGraphic()
 {
 // make unloaded test graphic
@@ -1219,6 +1232,21 @@ void GraphicTest::testLoadEPS()
 CPPUNIT_ASSERT_EQUAL(GraphicType::GdiMetafile, aGraphic.GetType());
 }
 
+void GraphicTest::testAvailableThreaded()
+{
+Graphic jpgGraphic1 = importUnloadedGraphic(u"TypeDetectionExample.jpg");
+Graphic jpgGraphic2 = importUnloadedGraphic(u"Exif1.jpg");
+Graphic pngGraphic1 = importUnloadedGraphic(u"TypeDetectionExample.png");
+Graphic pngGraphic2 = importUnloadedGraphic(u"testBasicMorphology.png");
+std::vector graphics = { &jpgGraphic1, &jpgGraphic2, 
&pngGraphic1, &pngGraphic2 };
+for (auto& graphic : graphics)
+CPPUNIT_ASSERT(!graphic->isAvailable());
+GraphicFilter& graphicFilter = GraphicFilter::GetGraphicFilter();
+graphicFilter.MakeGraphicsAvailableThreaded(graphics);
+for (auto& graphic : graphics)
+CPPUNIT_ASSERT(graphic->isAvailable());
+}
+
 } // namespace
 
 CPPUNIT_TEST_SUITE_REGISTRATION(GraphicTest);
diff --git a/vcl/source/filter/graphicfilter.cxx 
b/vcl/source/filter/graphicfilter.cxx
index cd29c5088a0e..9de2f801c790 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -44,6 +44,7 @@
 #include "igif/gifread.hxx"
 #include 
 #include "jpeg/jpeg.hxx"
+#include "png/png.hxx"
 #include "ixbm/xbmread.hxx"
 #include 
 #include 
@@ -545,6 +546,9 @@ struct GraphicImportContext
 std::shared_ptr m_pGraphic;
 /// Write pixel data using this access.
 std::unique_ptr m_pAccess;
+std::unique_ptr m_pAlphaAccess;
+// Need to have an AlphaMask instance to keep its lifetime.
+AlphaMask mAlphaMask;
 /// Signals if import finished correctly.
 ErrCode m_nStatus = ERRCODE_GRFILTER_FILTERERROR;
 /// Original graphic format.
@@ -581,10 +585,20 @@ void GraphicImportTask::doWork()
 
 void GraphicImportTask::doImport(GraphicImportContext& rContext)
 {
-if (!ImportJPEG(*rContext.m_pStream, *rContext.m_pGraphic, 
rContext.m_nImportFlags | GraphicFilterImportFlags::UseExistingBitmap, 
rContext.m_pAccess.get()))
-rContext.m_nStatus = ERRCODE_GRFILTER_FILTERERROR;
-else
-rContext.m_eLinkType = GfxLinkType::NativeJpg;
+if(rContext.m_eLinkType == GfxLinkType::NativeJpg)
+{
+if (!ImportJPEG(*rContext.m_pStream, *rContext.m_pGraphic, 
rContext.m_nImportFlags | GraphicFilterImportFlags::UseExistingBitmap, 
rContext.m_pAccess.get()))
+rContext.m_nStatus = ERRCODE_GRFILTER_FILTERERROR;
+}
+else if(rContext.m_eLinkType == GfxLinkType::NativePng)
+{
+if (!vcl::ImportPNG(*rContext.m_pStream, *rContext.m_pGraphic,
+rContext.m_nImportFlags | 
GraphicFilterImportFlags::UseExistingBitmap,
+rContext.m_pAccess.get(), 

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

2021-03-26 Thread Tomaž Vajngerl (via logerrit)
 vcl/qa/cppunit/BmpFilterTest.cxx |2 -
 vcl/qa/cppunit/svm/svmtest.cxx   |2 -
 vcl/source/bitmap/dibtools.cxx   |   40 +++
 3 files changed, 6 insertions(+), 38 deletions(-)

New commits:
commit 54c0e87c6ad4df012dbf338458ef156a8c846226
Author: Tomaž Vajngerl 
AuthorDate: Thu Mar 25 22:30:44 2021 +0900
Commit: Tomaž Vajngerl 
CommitDate: Fri Mar 26 08:29:10 2021 +0100

vcl: remove writing and reading 4-bit bitmaps for BMP format

This removes writing 4-bit palette bitmaps when writing to the
BMP format and reading from a 4-bit BMP uses 8-bit palette
instead.
This also changes the tests with the new expectations, but at
the same time it makes sure old BMP files and SVM files are still
compatible.

Change-Id: Ia5611a1f36ffa0a27ef5973296674f743fe80f65
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113137
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/BmpFilterTest.cxx b/vcl/qa/cppunit/BmpFilterTest.cxx
index 5cc2abac3d54..20be739d0e98 100644
--- a/vcl/qa/cppunit/BmpFilterTest.cxx
+++ b/vcl/qa/cppunit/BmpFilterTest.cxx
@@ -116,7 +116,7 @@ CPPUNIT_TEST_FIXTURE(BmpFilterTest, testBMP_Index_4BPP)
 auto aBitmap = aGraphic.GetBitmapEx();
 CPPUNIT_ASSERT_EQUAL(tools::Long(4), aBitmap.GetSizePixel().Width());
 CPPUNIT_ASSERT_EQUAL(tools::Long(4), aBitmap.GetSizePixel().Height());
-CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N4_BPP, aBitmap.getPixelFormat());
+CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, aBitmap.getPixelFormat());
 
 CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, aBitmap.GetPixelColor(0, 0));
 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aBitmap.GetPixelColor(2, 0));
diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx
index beb70c614791..29254fe9c323 100644
--- a/vcl/qa/cppunit/svm/svmtest.cxx
+++ b/vcl/qa/cppunit/svm/svmtest.cxx
@@ -985,7 +985,7 @@ void SvmTest::checkBitmapExs(const GDIMetaFile& rMetaFile)
 "5e01ddcc",
 "4df0e464",
 "4322ee3a",
-"794c92a9",
+"3c80d829", // 4-bit color bitmap - same as 8-bit color bitmap
 "3c80d829",
 "71efc447",
 });
diff --git a/vcl/source/bitmap/dibtools.cxx b/vcl/source/bitmap/dibtools.cxx
index c8d15815bd59..31277fd6a031 100644
--- a/vcl/source/bitmap/dibtools.cxx
+++ b/vcl/source/bitmap/dibtools.cxx
@@ -139,7 +139,6 @@ struct DIBV5Header : public DIBInfoHeader
 vcl::PixelFormat convertToBPP(sal_uInt16 nCount)
 {
 return (nCount <= 1) ? vcl::PixelFormat::N1_BPP :
-   (nCount <= 4) ? vcl::PixelFormat::N4_BPP :
(nCount <= 8) ? vcl::PixelFormat::N8_BPP :
vcl::PixelFormat::N24_BPP;
 }
@@ -1283,7 +1282,7 @@ bool ImplWriteDIBBits(SvStream& rOStm, BitmapReadAccess 
const & rAcc, BitmapRead
 // formats != *_TC_*). Note that this very problem might cause
 // trouble at other places - the introduction of 32 bit RGBA
 // bitmaps is relatively recent.
-// #i59239# discretize bitcount for aligned width to 1,4,8,24
+// #i59239# discretize bitcount for aligned width to 1,8,24
 // (other cases are not written below)
 const auto ePixelFormat(pAccAlpha ? vcl::PixelFormat::N32_BPP : 
convertToBPP(rAcc.GetBitCount()));
 const sal_uLong nAlignedWidth(AlignedWidth4Bytes(rAcc.Width() * 
sal_Int32(ePixelFormat)));
@@ -1353,35 +1352,6 @@ bool ImplWriteDIBBits(SvStream& rOStm, BitmapReadAccess 
const & rAcc, BitmapRead
 }
 break;
 
-case vcl::PixelFormat::N4_BPP:
-{
-//valgrind, zero out the trailing unused alignment bytes
-size_t nUnusedBytes = nAlignedWidth - ((nWidth+1) / 2);
-memset(aBuf.data() + nAlignedWidth - nUnusedBytes, 0, 
nUnusedBytes);
-
-for( tools::Long nY = nHeight - 1; nY >= 0; nY-- )
-{
-sal_uInt8* pTmp = aBuf.data();
-sal_uInt8 cTmp = 0;
-Scanline pScanline = rAcc.GetScanline( nY );
-
-for( tools::Long nX = 0, nShift = 2; nX < nWidth; nX++ 
)
-{
-if( !nShift )
-{
-nShift = 2;
-*pTmp++ = cTmp;
-cTmp = 0;
-}
-
-cTmp |= rAcc.GetIndexFromData( pScanline, nX ) << 
( --nShift << 2 );
-}
-*pTmp = cTmp;
-rOStm.WriteBytes(aBuf.data(), nAlignedWidth);
-}
-}
-break;
-
 case vcl::PixelFormat::N8_BPP:
 {
 for( tools::Long nY = nHeight - 1; nY >= 0; nY-- )
@@ -1473,17 +1443,15 @@ bool ImplWr

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

2021-03-21 Thread Luboš Luňák (via logerrit)
 vcl/qa/cppunit/complextext.cxx |   55 +
 vcl/source/gdi/CommonSalLayout.cxx |3 ++
 2 files changed, 58 insertions(+)

New commits:
commit 160ff36d2593a24b6a92ab5d66683528403c
Author: Luboš Luňák 
AuthorDate: Fri Mar 19 19:14:31 2021 +0100
Commit: Luboš Luňák 
CommitDate: Sun Mar 21 16:21:35 2021 +0100

fix SalLayoutGlyphs caching with MultiSalLayout

Writer's testTdf90069 was failing if there was the documents font
actually installed. If glyphs for layout are cached, it is still
necessary to do the fallback, and that needs setting the fallback
as needed.

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

diff --git a/vcl/qa/cppunit/complextext.cxx b/vcl/qa/cppunit/complextext.cxx
index f953c3060eb4..dae468baadc7 100644
--- a/vcl/qa/cppunit/complextext.cxx
+++ b/vcl/qa/cppunit/complextext.cxx
@@ -46,11 +46,13 @@ public:
 void testArabic();
 void testKashida();
 void testTdf95650(); // Windows-only issue
+void testCaching();
 
 CPPUNIT_TEST_SUITE(VclComplexTextTest);
 CPPUNIT_TEST(testArabic);
 CPPUNIT_TEST(testKashida);
 CPPUNIT_TEST(testTdf95650);
+CPPUNIT_TEST(testCaching);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -153,6 +155,59 @@ void VclComplexTextTest::testTdf95650()
 pOutDev->ImplLayout(aTxt, 9, 1, Point(), 0, nullptr, 
SalLayoutFlags::BiDiRtl);
 }
 
+static void testCachedGlyphs( const OUString& aText, const OUString& aFontName 
= OUString())
+{
+const std::string message = OUString("Font: " + aFontName + ", text: '" + 
aText + "'").toUtf8().getStr();
+ScopedVclPtrInstance pOutputDevice;
+if(!aFontName.isEmpty())
+{
+vcl::Font aFont( aFontName, Size(0, 12));
+pOutputDevice->SetFont( aFont );
+}
+// Get the glyphs for the text.
+std::unique_ptr pLayout1 = pOutputDevice->ImplLayout(
+aText, 0, aText.getLength(), Point(0, 0), 0, nullptr, 
SalLayoutFlags::GlyphItemsOnly);
+SalLayoutGlyphs aGlyphs1 = pLayout1->GetGlyphs();
+CPPUNIT_ASSERT_MESSAGE(message, aGlyphs1.IsValid());
+CPPUNIT_ASSERT_MESSAGE(message, aGlyphs1.Impl(0) != nullptr);
+// Reuse the cached glyphs to get glyphs again.
+std::unique_ptr pLayout2 = pOutputDevice->ImplLayout(
+aText, 0, aText.getLength(), Point(0, 0), 0, nullptr, 
SalLayoutFlags::GlyphItemsOnly, nullptr, &aGlyphs1);
+SalLayoutGlyphs aGlyphs2 = pLayout2->GetGlyphs();
+CPPUNIT_ASSERT_MESSAGE(message, aGlyphs2.IsValid());
+// And check it's the same.
+for( int level = 0; level < MAX_FALLBACK; ++level )
+{
+const std::string messageLevel = OString(message.c_str()
++ OStringLiteral(", level: ") + OString::number(level)).getStr();
+if( aGlyphs1.Impl(level) == nullptr)
+{
+CPPUNIT_ASSERT_MESSAGE(messageLevel, aGlyphs2.Impl(level) == 
nullptr);
+continue;
+}
+const SalLayoutGlyphsImpl* g1 = aGlyphs1.Impl(level);
+const SalLayoutGlyphsImpl* g2 = aGlyphs2.Impl(level);
+CPPUNIT_ASSERT_EQUAL_MESSAGE(messageLevel, g1->GetFont().get(), 
g2->GetFont().get());
+CPPUNIT_ASSERT_EQUAL_MESSAGE(messageLevel, g1->size(), g2->size());
+for( size_t i = 0; i < g1->size(); ++i )
+{
+CPPUNIT_ASSERT_EQUAL_MESSAGE(messageLevel, (*g1)[i].glyphId(), 
(*g2)[i].glyphId());
+CPPUNIT_ASSERT_EQUAL_MESSAGE(messageLevel, (*g1)[i].IsRTLGlyph(), 
(*g2)[i].IsRTLGlyph());
+CPPUNIT_ASSERT_EQUAL_MESSAGE(messageLevel, (*g1)[i].IsVertical(), 
(*g2)[i].IsVertical());
+}
+}
+}
+
+// Check that caching using SalLayoutGlyphs gives same results as without 
caching.
+// This should preferably use fonts that come with LO.
+void VclComplexTextTest::testCaching()
+{
+// Just something basic, no font fallback.
+testCachedGlyphs( "test", "Dejavu Sans" );
+// This font does not have latin characters, will need fallback.
+testCachedGlyphs( "test", "KacstBook" );
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(VclComplexTextTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/gdi/CommonSalLayout.cxx 
b/vcl/source/gdi/CommonSalLayout.cxx
index 2ef3c98d2f9d..5565b3eb4d69 100644
--- a/vcl/source/gdi/CommonSalLayout.cxx
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -296,6 +296,9 @@ bool GenericSalLayout::LayoutText(ImplLayoutArgs& rArgs, 
const SalLayoutGlyphsIm
 {
 // Work with pre-computed glyph items.
 m_GlyphItems = *pGlyphs;
+for(const GlyphItem& item : m_GlyphItems)
+if(!item.glyphId())
+SetNeedFallback(rArgs, item.charPos(), item.IsRTLGlyph());
 // Some flags are set as a side effect of text layout, restore them 
here.
 rArgs.mnFlags |= pGlyphs->mnFlags;
 return true;
___
Libreoffice-commits 

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

2021-03-14 Thread Caolán McNamara (via logerrit)
 vcl/qa/cppunit/graphicfilter/data/png/fail/ofz32026.png |binary
 vcl/source/filter/png/PngImageReader.cxx|   21 +++-
 2 files changed, 20 insertions(+), 1 deletion(-)

New commits:
commit 76546f678e86b5c551f3dfe28f35864cebdd2019
Author: Caolán McNamara 
AuthorDate: Sat Mar 13 19:51:14 2021 +
Commit: Caolán McNamara 
CommitDate: Sun Mar 14 22:01:54 2021 +0100

ofz#32026 null-deref

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

diff --git a/vcl/qa/cppunit/graphicfilter/data/png/fail/ofz32026.png 
b/vcl/qa/cppunit/graphicfilter/data/png/fail/ofz32026.png
new file mode 100644
index ..290671ecb43d
Binary files /dev/null and 
b/vcl/qa/cppunit/graphicfilter/data/png/fail/ofz32026.png differ
diff --git a/vcl/source/filter/png/PngImageReader.cxx 
b/vcl/source/filter/png/PngImageReader.cxx
index b1e8e10cdc1d..32231de9e03f 100644
--- a/vcl/source/filter/png/PngImageReader.cxx
+++ b/vcl/source/filter/png/PngImageReader.cxx
@@ -190,6 +190,11 @@ bool reader(SvStream& rStream, BitmapEx& rBitmapEx, bool 
bUseBitmap32)
 aBitmap = Bitmap(Size(width, height), vcl::PixelFormat::N24_BPP);
 {
 pWriteAccess = BitmapScopedWriteAccess(aBitmap);
+if (!pWriteAccess)
+{
+png_destroy_read_struct(&pPng, &pInfo, nullptr);
+return false;
+}
 ScanlineFormat eFormat = pWriteAccess->GetScanlineFormat();
 if (eFormat == ScanlineFormat::N24BitTcBgr)
 png_set_bgr(pPng);
@@ -227,6 +232,11 @@ bool reader(SvStream& rStream, BitmapEx& rBitmapEx, bool 
bUseBitmap32)
 aBitmap = Bitmap(Size(width, height), 
vcl::PixelFormat::N32_BPP);
 {
 pWriteAccess = BitmapScopedWriteAccess(aBitmap);
+if (!pWriteAccess)
+{
+png_destroy_read_struct(&pPng, &pInfo, nullptr);
+return false;
+}
 ScanlineFormat eFormat = pWriteAccess->GetScanlineFormat();
 if (eFormat == ScanlineFormat::N32BitTcAbgr
 || eFormat == ScanlineFormat::N32BitTcBgra)
@@ -275,6 +285,11 @@ bool reader(SvStream& rStream, BitmapEx& rBitmapEx, bool 
bUseBitmap32)
 aBitmapAlpha = AlphaMask(Size(width, height), nullptr);
 {
 pWriteAccess = BitmapScopedWriteAccess(aBitmap);
+if (!pWriteAccess)
+{
+png_destroy_read_struct(&pPng, &pInfo, nullptr);
+return false;
+}
 ScanlineFormat eFormat = pWriteAccess->GetScanlineFormat();
 if (eFormat == ScanlineFormat::N24BitTcBgr)
 png_set_bgr(pPng);
@@ -319,7 +334,11 @@ bool reader(SvStream& rStream, BitmapEx& rBitmapEx, bool 
bUseBitmap32)
 aBitmap.Erase(COL_WHITE);
 {
 pWriteAccess = BitmapScopedWriteAccess(aBitmap);
-
+if (!pWriteAccess)
+{
+png_destroy_read_struct(&pPng, &pInfo, nullptr);
+return false;
+}
 aRows = std::vector>(height);
 for (auto& rRow : aRows)
 rRow.resize(aRowSizeBytes, 0);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2021-02-22 Thread Luboš Luňák (via logerrit)
 vcl/qa/cppunit/BitmapTest.cxx |   65 +
 vcl/source/bitmap/bitmappaint.cxx |  140 +-
 2 files changed, 173 insertions(+), 32 deletions(-)

New commits:
commit e74c9a340ffa34d8d0a7c5bd728148462254a243
Author: Luboš Luňák 
AuthorDate: Fri Feb 19 13:21:52 2021 +0100
Commit: Luboš Luňák 
CommitDate: Mon Feb 22 13:00:03 2021 +0100

optimize Bitmap::Mirror()

For the usual bitmap pixel formats it's much faster to just move
around pixel data rather than call the pixel-set/get functions.

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

diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx
index 0c96977a880a..e6c95d27b954 100644
--- a/vcl/qa/cppunit/BitmapTest.cxx
+++ b/vcl/qa/cppunit/BitmapTest.cxx
@@ -45,6 +45,7 @@ class BitmapTest : public CppUnit::TestFixture
 void testOctree();
 void testEmptyAccess();
 void testDitherSize();
+void testMirror();
 
 CPPUNIT_TEST_SUITE(BitmapTest);
 CPPUNIT_TEST(testCreation);
@@ -61,6 +62,7 @@ class BitmapTest : public CppUnit::TestFixture
 CPPUNIT_TEST(testOctree);
 CPPUNIT_TEST(testEmptyAccess);
 CPPUNIT_TEST(testDitherSize);
+CPPUNIT_TEST(testMirror);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -682,6 +684,69 @@ void BitmapTest::testDitherSize()
 }
 }
 
+void BitmapTest::testMirror()
+{
+for (int bpp : { 4, 8, 24, 32 })
+{
+Bitmap bitmap(Size(11, 11), bpp);
+{
+bitmap.Erase(COL_MAGENTA);
+BitmapWriteAccess write(bitmap);
+if (write.HasPalette())
+{
+// Note that SetPixel() and GetColor() take arguments as Y,X.
+write.SetPixel(0, 0, 
BitmapColor(write.GetBestPaletteIndex(COL_BLACK)));
+write.SetPixel(10, 0, 
BitmapColor(write.GetBestPaletteIndex(COL_WHITE)));
+write.SetPixel(0, 10, 
BitmapColor(write.GetBestPaletteIndex(COL_RED)));
+write.SetPixel(10, 10, 
BitmapColor(write.GetBestPaletteIndex(COL_BLUE)));
+write.SetPixel(5, 0, 
BitmapColor(write.GetBestPaletteIndex(COL_GREEN)));
+write.SetPixel(0, 5, 
BitmapColor(write.GetBestPaletteIndex(COL_YELLOW)));
+}
+else
+{
+write.SetPixel(0, 0, COL_BLACK);
+write.SetPixel(10, 0, COL_WHITE);
+write.SetPixel(0, 10, COL_RED);
+write.SetPixel(10, 10, COL_BLUE);
+write.SetPixel(5, 0, COL_GREEN);
+write.SetPixel(0, 5, COL_YELLOW);
+}
+}
+bitmap.Mirror(BmpMirrorFlags::Horizontal);
+{
+BitmapReadAccess read(bitmap);
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLACK), read.GetColor(0, 10));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_WHITE), read.GetColor(10, 
10));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_RED), read.GetColor(0, 0));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLUE), read.GetColor(10, 0));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_GREEN), read.GetColor(5, 10));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_YELLOW), read.GetColor(0, 5));
+}
+bitmap.Mirror(BmpMirrorFlags::Vertical);
+{
+BitmapReadAccess read(bitmap);
+// Now is effectively mirrored in both directions.
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLACK), read.GetColor(10, 
10));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_WHITE), read.GetColor(0, 10));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_RED), read.GetColor(10, 0));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLUE), read.GetColor(0, 0));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_GREEN), read.GetColor(5, 10));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_YELLOW), read.GetColor(10, 
5));
+}
+bitmap.Mirror(BmpMirrorFlags::Vertical | BmpMirrorFlags::Horizontal);
+{
+BitmapReadAccess read(bitmap);
+// Now is back the original.
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLACK), read.GetColor(0, 0));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_WHITE), read.GetColor(10, 0));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_RED), read.GetColor(0, 10));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLUE), read.GetColor(10, 10));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_GREEN), read.GetColor(5, 0));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_YELLOW), read.GetColor(0, 5));
+}
+}
+}
+
 } // namespace
 
 CPPUNIT_TEST_SUITE_REGISTRATION(BitmapTest);
diff --git a/vcl/source/bitmap/bitmappaint.cxx 
b/vcl/source/bitmap/bitmappaint.cxx
index b69972788746..ad20832022d5 100644
--- a/vcl/source/bitmap/bitmappaint.cxx
+++ b/vcl/source/bitmap/bitmappaint.cxx
@@ -105,6 +105,28 @@ bool Bitmap

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

2021-01-06 Thread Tomaž Vajngerl (via logerrit)
 vcl/qa/cppunit/graphicfilter/filters-test.cxx |2 ++
 vcl/qa/cppunit/jpeg/JpegWriterTest.cxx|   16 
 vcl/source/filter/graphicfilter.cxx   |1 -
 3 files changed, 14 insertions(+), 5 deletions(-)

New commits:
commit 252ddaa9075462000bb8e63288b9c15daeecca8a
Author: Tomaž Vajngerl 
AuthorDate: Tue Dec 29 23:11:04 2020 +0900
Commit: Tomaž Vajngerl 
CommitDate: Thu Jan 7 01:05:07 2021 +0100

improve JpegWriterTest - detect type is correct during roundtrip

Change-Id: I4560be2dd1627caf8126142930c3479668689273
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108823
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/graphicfilter/filters-test.cxx 
b/vcl/qa/cppunit/graphicfilter/filters-test.cxx
index 5a4443f1075a..aee1dda1407e 100644
--- a/vcl/qa/cppunit/graphicfilter/filters-test.cxx
+++ b/vcl/qa/cppunit/graphicfilter/filters-test.cxx
@@ -144,6 +144,8 @@ void VclFiltersTest::testExportImport()
 checkExportImport(u"png");
 fprintf(stderr, "Check ExportImport BMP\n");
 checkExportImport(u"bmp");
+fprintf(stderr, "Check ExportImport TIF\n");
+checkExportImport(u"tif");
 }
 
 void VclFiltersTest::testCVEs()
diff --git a/vcl/qa/cppunit/jpeg/JpegWriterTest.cxx 
b/vcl/qa/cppunit/jpeg/JpegWriterTest.cxx
index b2144fe3b47e..f999c018df7c 100644
--- a/vcl/qa/cppunit/jpeg/JpegWriterTest.cxx
+++ b/vcl/qa/cppunit/jpeg/JpegWriterTest.cxx
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 
 constexpr OUStringLiteral gaDataUrl(u"/vcl/qa/cppunit/jpeg/data/");
 
@@ -54,16 +55,23 @@ BitmapEx JpegWriterTest::roundtripJPG(const OUString& aURL) 
{ return roundtripJP
 
 BitmapEx JpegWriterTest::roundtripJPG(const BitmapEx& bitmap)
 {
-SvMemoryStream stream;
+// EXPORT JPEG
+SvMemoryStream aStream;
 GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
 sal_uInt16 exportFormatJPG = 
rFilter.GetExportFormatNumberForShortName(JPG_SHORTNAME);
 Graphic aExportGraphic(bitmap);
-ErrCode bResult = rFilter.ExportGraphic(aExportGraphic, "memory", stream, 
exportFormatJPG);
+ErrCode bResult = rFilter.ExportGraphic(aExportGraphic, "memory", aStream, 
exportFormatJPG);
 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult);
-stream.Seek(0);
+//Detect the magic bytes - we need to be sure the file is actually a JPEG
+aStream.Seek(0);
+vcl::GraphicFormatDetector aDetector(aStream, "");
+CPPUNIT_ASSERT(aDetector.detect());
+CPPUNIT_ASSERT(aDetector.checkJPG());
+// IMPORT JPEG
+aStream.Seek(0);
 Graphic aImportGraphic;
 sal_uInt16 importFormatJPG = 
rFilter.GetImportFormatNumberForShortName(JPG_SHORTNAME);
-bResult = rFilter.ImportGraphic(aImportGraphic, "memory", stream, 
importFormatJPG);
+bResult = rFilter.ImportGraphic(aImportGraphic, "memory", aStream, 
importFormatJPG);
 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult);
 return aImportGraphic.GetBitmapEx();
 }
diff --git a/vcl/source/filter/graphicfilter.cxx 
b/vcl/source/filter/graphicfilter.cxx
index 2c2aa67bcbe2..684bb9c02731 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -649,7 +649,6 @@ extern "C" bool iptGraphicImport( SvStream& rStream, 
Graphic& rGraphic, FilterCo
 extern "C" bool ipxGraphicImport( SvStream& rStream, Graphic& rGraphic, 
FilterConfigItem* pConfigItem );
 extern "C" bool iraGraphicImport( SvStream& rStream, Graphic& rGraphic, 
FilterConfigItem* pConfigItem );
 extern "C" bool itgGraphicImport( SvStream& rStream, Graphic& rGraphic, 
FilterConfigItem* pConfigItem );
-extern "C" bool itiGraphicImport( SvStream& rStream, Graphic& rGraphic, 
FilterConfigItem* pConfigItem );
 
 #endif
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2020-12-07 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/GraphicTest.cxx  |   36 
 vcl/qa/cppunit/data/to-wmf.emf  |binary
 vcl/source/filter/graphicfilter.cxx |8 +++-
 3 files changed, 43 insertions(+), 1 deletion(-)

New commits:
commit c06abb40f7155e92c56026ce3ea0526ceb3a0f27
Author: Miklos Vajna 
AuthorDate: Mon Dec 7 17:10:56 2020 +0100
Commit: Miklos Vajna 
CommitDate: Mon Dec 7 18:22:24 2020 +0100

vcl graphic export: convert EMF to WMF when WMF is requested

Regression from commit 5868745db74ae930edb0058490076d82aaeafbe9
(emfplus: make VectorFormats Emf/Wmf/Svg work, 2017-06-12), we used to
export graphic data as-is when the requested format is WMF and the
source format is EMF or WMF.

Restrict the as-is copying to the WMF source format only.

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

diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
index df9711b54a35..479a3c91f836 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -25,8 +25,10 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
+#include 
 
 #if USE_TLS_NSS
 #include 
@@ -51,6 +53,7 @@ private:
 void testSwappingVectorGraphic();
 void testSwappingPageNumber();
 void testWMFRoundtrip();
+void testEmfToWmfConversion();
 
 CPPUNIT_TEST_SUITE(GraphicTest);
 CPPUNIT_TEST(testUnloadedGraphic);
@@ -62,6 +65,7 @@ private:
 CPPUNIT_TEST(testSwappingVectorGraphic);
 CPPUNIT_TEST(testSwappingPageNumber);
 CPPUNIT_TEST(testWMFRoundtrip);
+CPPUNIT_TEST(testEmfToWmfConversion);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -301,6 +305,38 @@ void GraphicTest::testUnloadedGraphicSizeUnit()
 CPPUNIT_ASSERT_EQUAL(Size(400, 363), aGraphic.GetPrefSize());
 }
 
+void GraphicTest::testEmfToWmfConversion()
+{
+// Load EMF data.
+GraphicFilter aGraphicFilter;
+test::Directories aDirectories;
+OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "to-wmf.emf";
+SvFileStream aStream(aURL, StreamMode::READ);
+Graphic aGraphic;
+// This similar to an application/x-openoffice-wmf mime type in 
manifest.xml in the ODF case.
+sal_uInt16 nFormat = 
aGraphicFilter.GetImportFormatNumberForShortName(u"WMF");
+CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE,
+ aGraphicFilter.ImportGraphic(aGraphic, OUString(), 
aStream, nFormat));
+CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Wmf,
+ 
aGraphic.getVectorGraphicData()->getVectorGraphicDataType());
+
+// Save as WMF.
+sal_uInt16 nFilterType = 
aGraphicFilter.GetExportFormatNumberForShortName(u"WMF");
+SvMemoryStream aGraphicStream;
+CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, aGraphicFilter.ExportGraphic(aGraphic, 
OUString(),
+
aGraphicStream, nFilterType));
+aGraphicStream.Seek(0);
+vcl::GraphicFormatDetector aDetector(aGraphicStream, OUString());
+CPPUNIT_ASSERT(aDetector.detect());
+CPPUNIT_ASSERT(aDetector.checkWMForEMF());
+
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: WMF
+// - Actual  : EMF
+// i.e. EMF data was requested to be converted to WMF, but the output was 
still EMF.
+CPPUNIT_ASSERT_EQUAL(OUString("WMF"), aDetector.msDetectedFormat);
+}
+
 void GraphicTest::testSwapping()
 {
 // Prepare Graphic from a PNG image first
diff --git a/vcl/qa/cppunit/data/to-wmf.emf b/vcl/qa/cppunit/data/to-wmf.emf
new file mode 100644
index ..e1a7b9f9e517
Binary files /dev/null and b/vcl/qa/cppunit/data/to-wmf.emf differ
diff --git a/vcl/source/filter/graphicfilter.cxx 
b/vcl/source/filter/graphicfilter.cxx
index ad3dabd4494e..4b4fa6c4582d 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -1960,9 +1960,15 @@ ErrCode GraphicFilter::ExportGraphic( const Graphic& 
rGraphic, const OUString& r
 // do we have a native Vector Graphic Data RenderGraphic, 
whose data can be written directly?
 auto const & 
rVectorGraphicDataPtr(rGraphic.getVectorGraphicData());
 
+bool bIsEMF = rGraphic.GetGfxLink().IsEMF();
+
+// VectorGraphicDataType::Wmf means WMF or EMF, allow direct 
write in the WMF case
+// only.
 if (rVectorGraphicDataPtr
 && rVectorGraphicDataPtr->getVectorGraphicDataArrayLength()
-&& VectorGraphicDataType::Wmf == 
rVectorGraphicDataPtr->getVectorGraphicDataType())
+&& VectorGraphicDataType::Wmf
+   == rVectorGraphicDataPtr->getVectorGraphicDataType()
+&& !bIsEMF)
 {
 
rOStm.WriteBytes(rVectorGraphicDataPtr->getVectorGraphicDa

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

2020-10-16 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/filter/ipdf/data/dict-array-dict.pdf |   55 
 vcl/qa/cppunit/filter/ipdf/ipdf.cxx |   21 +++
 vcl/source/filter/ipdf/pdfdocument.cxx  |   13 
 3 files changed, 87 insertions(+), 2 deletions(-)

New commits:
commit 056c1284d6a68525002c54bef10834cc135385db
Author: Miklos Vajna 
AuthorDate: Fri Oct 16 18:15:21 2020 +0200
Commit: Miklos Vajna 
CommitDate: Fri Oct 16 20:57:34 2020 +0200

vcl pdf tokenizer: fix handling of dict -> array -> dict tokens

Needed to be able to parse the /Reference key of signatures.

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

diff --git a/vcl/qa/cppunit/filter/ipdf/data/dict-array-dict.pdf 
b/vcl/qa/cppunit/filter/ipdf/data/dict-array-dict.pdf
new file mode 100644
index ..73de3117b9a6
--- /dev/null
+++ b/vcl/qa/cppunit/filter/ipdf/data/dict-array-dict.pdf
@@ -0,0 +1,55 @@
+%PDF-1.7
+%���
+1 0 obj <<
+  /Type /Catalog
+  /Pages 2 0 R
+>>
+endobj
+2 0 obj <<
+  /Type /Pages
+  /MediaBox [0 0 200 300]
+  /Count 1
+  /Kids [3 0 R]
+>>
+endobj
+3 0 obj <<
+  /Type /Page
+  /Parent 2 0 R
+  /Contents 4 0 R
+  /Key[<>]
+>>
+endobj
+4 0 obj <<
+  /Length 188
+>>
+stream
+q
+0 0 0 rg
+0 290 10 10 re B*
+10 150 50 30 re B*
+0 0 1 rg
+190 290 10 10 re B*
+70 232 50 30 re B*
+0 1 0 rg
+190 0 10 10 re B*
+130 150 50 30 re B*
+1 0 0 rg
+0 0 10 10 re B*
+70 67 50 30 re B*
+Q
+endstream
+endobj
+xref
+0 5
+00 65535 f 
+15 0 n 
+68 0 n 
+000157 0 n 
+000251 0 n 
+trailer <<
+  /Root 1 0 R
+  /Size 5
+>>
+startxref
+491
+%%EOF
diff --git a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx 
b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
index 96fd331ceb76..683a87f33995 100644
--- a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
+++ b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 using namespace ::com::sun::star;
 
@@ -140,6 +141,26 @@ CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, 
testPDFAddVisibleSignatureLastPage)
 CPPUNIT_ASSERT_EQUAL(4, pAnnot->getObjectCount());
 }
 
+CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, testDictArrayDict)
+{
+// Load a file that has markup like this:
+// 3 0 obj <<
+//   /Key[<>]
+// >>
+OUString aSourceURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"dict-array-dict.pdf";
+SvFileStream aFile(aSourceURL, StreamMode::READ);
+vcl::filter::PDFDocument aDocument;
+CPPUNIT_ASSERT(aDocument.Read(aFile));
+std::vector aPages = aDocument.GetPages();
+CPPUNIT_ASSERT(!aPages.empty());
+vcl::filter::PDFObjectElement* pPage = aPages[0];
+auto pKey = 
dynamic_cast(pPage->Lookup("Key"));
+
+// Without the accompanying fix in place, this test would have failed, 
because the value of Key
+// was a dictionary element, not an array element.
+CPPUNIT_ASSERT(pKey);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/filter/ipdf/pdfdocument.cxx 
b/vcl/source/filter/ipdf/pdfdocument.cxx
index ec763d54a2a1..2b6c9d49de34 100644
--- a/vcl/source/filter/ipdf/pdfdocument.cxx
+++ b/vcl/source/filter/ipdf/pdfdocument.cxx
@@ -2406,8 +2406,17 @@ size_t PDFDictionaryElement::Parse(const 
std::vector
 if (nexti >= i) // ensure we go forwards and not endlessly loop
 {
 i = nexti;
-rDictionary[aName] = pDictionary;
-aName.clear();
+if (pArray)
+{
+// Dictionary value inside an array.
+pArray->PushBack(pDictionary);
+}
+else
+{
+// Dictionary toplevel value.
+rDictionary[aName] = pDictionary;
+aName.clear();
+}
 }
 }
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2020-09-30 Thread Luboš Luňák (via logerrit)
 vcl/qa/cppunit/BackendTest.cxx   |   59 +++
 vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx |   38 +++---
 vcl/source/outdev/bitmap.cxx |   47 --
 3 files changed, 112 insertions(+), 32 deletions(-)

New commits:
commit 6b709ad5d46dc33f29ec28183cea40cf9e77e2af
Author: Luboš Luňák 
AuthorDate: Tue Sep 29 09:42:14 2020 +0200
Commit: Luboš Luňák 
CommitDate: Wed Sep 30 11:38:37 2020 +0200

fix DrawDeviceAlphaBitmap() with mirroring (tdf#136223)

It turns out even the slow path was broken, so make it work (a hack,
but it's already slow anyway, and apparently not used often).
Also make the fast paths work directly, even with manual mirroring
it should be still faster.

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

diff --git a/vcl/qa/cppunit/BackendTest.cxx b/vcl/qa/cppunit/BackendTest.cxx
index cb2dca9cfe91..1342c3a5ade9 100644
--- a/vcl/qa/cppunit/BackendTest.cxx
+++ b/vcl/qa/cppunit/BackendTest.cxx
@@ -711,6 +711,64 @@ public:
 CPPUNIT_ASSERT_EQUAL(COL_WHITE, device->GetPixel(Point(6, 6)));
 }
 
+void testDrawAlphaBitmapMirrored()
+{
+// Normal virtual device.
+ScopedVclPtr device = 
VclPtr::Create(DeviceFormat::DEFAULT);
+// Virtual device with alpha.
+ScopedVclPtr alphaDevice
+= VclPtr::Create(DeviceFormat::DEFAULT, 
DeviceFormat::DEFAULT);
+device->SetOutputSizePixel(Size(20, 20));
+device->SetBackground(Wallpaper(COL_BLACK));
+device->Erase();
+alphaDevice->SetOutputSizePixel(Size(20, 20));
+alphaDevice->SetBackground(Wallpaper(COL_BLACK));
+alphaDevice->Erase();
+Bitmap bitmap(Size(4, 4), 24);
+AlphaMask alpha(Size(4, 4));
+bitmap.Erase(COL_LIGHTBLUE);
+{
+BitmapScopedWriteAccess writeAccess(bitmap);
+writeAccess->SetPixel(3, 3, COL_LIGHTRED);
+}
+// alpha 127 will make COL_LIGHTRED -> COL_RED and the same for blue
+alpha.Erase(127);
+// Normal device.
+device->DrawBitmapEx(Point(5, 5), Size(-4, -4), BitmapEx(bitmap));
+device->DrawBitmapEx(Point(15, 15), Size(4, 4), BitmapEx(bitmap));
+exportDevice("/tmp/draw_alpha_bitmap_mirrored_01.png", device);
+CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, device->GetPixel(Point(18, 18)));
+CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, device->GetPixel(Point(17, 18)));
+CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, device->GetPixel(Point(2, 2)));
+CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, device->GetPixel(Point(3, 2)));
+device->Erase();
+device->DrawBitmapEx(Point(5, 5), Size(-4, -4), BitmapEx(bitmap, 
alpha));
+device->DrawBitmapEx(Point(15, 15), Size(4, 4), BitmapEx(bitmap, 
alpha));
+exportDevice("/tmp/draw_alpha_bitmap_mirrored_02.png", device);
+CPPUNIT_ASSERT_EQUAL(COL_RED, device->GetPixel(Point(18, 18)));
+CPPUNIT_ASSERT_EQUAL(COL_BLUE, device->GetPixel(Point(17, 18)));
+CPPUNIT_ASSERT_EQUAL(COL_RED, device->GetPixel(Point(2, 2)));
+CPPUNIT_ASSERT_EQUAL(COL_BLUE, device->GetPixel(Point(3, 2)));
+device->Erase();
+// Now with alpha device.
+alphaDevice->DrawBitmapEx(Point(5, 5), Size(-4, -4), BitmapEx(bitmap));
+alphaDevice->DrawBitmapEx(Point(15, 15), Size(4, 4), BitmapEx(bitmap));
+exportDevice("/tmp/draw_alpha_bitmap_mirrored_03.png", alphaDevice);
+CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, alphaDevice->GetPixel(Point(18, 
18)));
+CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, alphaDevice->GetPixel(Point(17, 
18)));
+CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, alphaDevice->GetPixel(Point(2, 2)));
+CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, alphaDevice->GetPixel(Point(3, 
2)));
+alphaDevice->Erase();
+alphaDevice->DrawBitmapEx(Point(5, 5), Size(-4, -4), BitmapEx(bitmap, 
alpha));
+alphaDevice->DrawBitmapEx(Point(15, 15), Size(4, 4), BitmapEx(bitmap, 
alpha));
+exportDevice("/tmp/draw_alpha_bitmap_mirrored_04.png", alphaDevice);
+CPPUNIT_ASSERT_EQUAL(COL_RED, alphaDevice->GetPixel(Point(18, 18)));
+CPPUNIT_ASSERT_EQUAL(COL_BLUE, alphaDevice->GetPixel(Point(17, 18)));
+CPPUNIT_ASSERT_EQUAL(COL_RED, alphaDevice->GetPixel(Point(2, 2)));
+CPPUNIT_ASSERT_EQUAL(COL_BLUE, alphaDevice->GetPixel(Point(3, 2)));
+alphaDevice->Erase();
+}
+
 void testTdf124848()
 {
 ScopedVclPtr device = 
VclPtr::Create(DeviceFormat::DEFAULT);
@@ -832,6 +890,7 @@ public:
 CPPUNIT_TEST(testRadialGradientOfs);
 
 CPPUNIT_TEST(testDrawBlendExtended);
+CPPUNIT_TEST(testDrawAlphaBitmapMirrored);
 
 CPPUNIT_TEST(testTdf124848);
 CPPUNIT_TEST(testTdf136171);
diff --git a/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx 
b/v

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

2020-09-04 Thread Luboš Luňák (via logerrit)
 vcl/qa/cppunit/BackendTest.cxx|   69 +-
 vcl/source/outdev/outdevstate.cxx |   39 -
 2 files changed, 106 insertions(+), 2 deletions(-)

New commits:
commit c5b6f8d6469850e14362f2c8f08cdf8c956cbf07
Author: Luboš Luňák 
AuthorDate: Wed Sep 2 11:45:10 2020 +0200
Commit: Luboš Luňák 
CommitDate: Fri Sep 4 17:29:13 2020 +0200

fix erasing virtual device with alpha

The background cannot be simply set as background also for the internal
alpha virtual device, since this hackish alpha uses black = opaque
and white = transparent. So e.g. setting to background to COL_WHITE
actually resulted in the content being transparent.
Try to map to what the alpha virtual device actually needs.

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

diff --git a/vcl/qa/cppunit/BackendTest.cxx b/vcl/qa/cppunit/BackendTest.cxx
index 45793434dd1b..0e3d9c54dd08 100644
--- a/vcl/qa/cppunit/BackendTest.cxx
+++ b/vcl/qa/cppunit/BackendTest.cxx
@@ -49,7 +49,7 @@ class BackendTest : public test::BootstrapFixture
 {
 if (mbExportBitmap)
 {
-BitmapEx aBitmapEx(device->GetBitmap(Point(0, 0), 
device->GetOutputSizePixel()));
+BitmapEx aBitmapEx(device->GetBitmapEx(Point(0, 0), 
device->GetOutputSizePixel()));
 SvFileStream aStream(filename, StreamMode::WRITE | 
StreamMode::TRUNC);
 GraphicFilter::GetGraphicFilter().compressAsPNG(aBitmapEx, 
aStream);
 }
@@ -517,6 +517,71 @@ public:
 
 // vcl::test::OutputDeviceTestGradient does not verify anything, cannot 
test here
 
+void testErase()
+{
+{
+// Create normal virtual device (no alpha).
+ScopedVclPtr device
+= VclPtr::Create(DeviceFormat::DEFAULT);
+device->SetOutputSizePixel(Size(10, 10));
+// Erase with white, check it's white.
+device->SetBackground(Wallpaper(COL_WHITE));
+device->Erase();
+exportDevice("/tmp/12-01_erase.png", device);
+CPPUNIT_ASSERT_EQUAL(COL_WHITE, device->GetPixel(Point(0, 0)));
+CPPUNIT_ASSERT_EQUAL(COL_WHITE, device->GetPixel(Point(9, 9)));
+CPPUNIT_ASSERT_EQUAL(COL_WHITE, device->GetPixel(Point(5, 5)));
+// Erase with black, check it's black.
+device->SetBackground(Wallpaper(COL_BLACK));
+device->Erase();
+exportDevice("/tmp/12-02_erase.png", device);
+CPPUNIT_ASSERT_EQUAL(COL_BLACK, device->GetPixel(Point(0, 0)));
+CPPUNIT_ASSERT_EQUAL(COL_BLACK, device->GetPixel(Point(9, 9)));
+CPPUNIT_ASSERT_EQUAL(COL_BLACK, device->GetPixel(Point(5, 5)));
+// Erase with cyan, check it's cyan.
+device->SetBackground(Wallpaper(COL_CYAN));
+device->Erase();
+exportDevice("/tmp/12-03_erase.png", device);
+CPPUNIT_ASSERT_EQUAL(COL_CYAN, device->GetPixel(Point(0, 0)));
+CPPUNIT_ASSERT_EQUAL(COL_CYAN, device->GetPixel(Point(9, 9)));
+CPPUNIT_ASSERT_EQUAL(COL_CYAN, device->GetPixel(Point(5, 5)));
+}
+{
+// Create virtual device with alpha.
+ScopedVclPtr device
+= VclPtr::Create(DeviceFormat::DEFAULT, 
DeviceFormat::DEFAULT);
+device->SetOutputSizePixel(Size(10, 10));
+// Erase with white, check it's white.
+device->SetBackground(Wallpaper(COL_WHITE));
+device->Erase();
+exportDevice("/tmp/12-04_erase.png", device);
+CPPUNIT_ASSERT_EQUAL(COL_WHITE, device->GetPixel(Point(0, 0)));
+CPPUNIT_ASSERT_EQUAL(COL_WHITE, device->GetPixel(Point(9, 9)));
+CPPUNIT_ASSERT_EQUAL(COL_WHITE, device->GetPixel(Point(5, 5)));
+// Erase with black, check it's black.
+device->SetBackground(Wallpaper(COL_BLACK));
+device->Erase();
+exportDevice("/tmp/12-05_erase.png", device);
+CPPUNIT_ASSERT_EQUAL(COL_BLACK, device->GetPixel(Point(0, 0)));
+CPPUNIT_ASSERT_EQUAL(COL_BLACK, device->GetPixel(Point(9, 9)));
+CPPUNIT_ASSERT_EQUAL(COL_BLACK, device->GetPixel(Point(5, 5)));
+// Erase with cyan, check it's cyan.
+device->SetBackground(Wallpaper(COL_CYAN));
+device->Erase();
+exportDevice("/tmp/12-06_erase.png", device);
+CPPUNIT_ASSERT_EQUAL(COL_CYAN, device->GetPixel(Point(0, 0)));
+CPPUNIT_ASSERT_EQUAL(COL_CYAN, device->GetPixel(Point(9, 9)));
+CPPUNIT_ASSERT_EQUAL(COL_CYAN, device->GetPixel(Point(5, 5)));
+// Erase with transparent, check it's transparent.
+device->SetBackground(Wallpaper(COL_TRANSPARENT));
+device->Erase();
+exportDevice("/

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

2020-08-28 Thread Andrea Gelmini (via logerrit)
 vcl/qa/cppunit/timer.cxx  |   10 +-
 vcl/source/gdi/mtfxmldump.cxx |4 ++--
 2 files changed, 7 insertions(+), 7 deletions(-)

New commits:
commit c2de8cb841aa330b96f488c19a56fc20457c37b3
Author: Andrea Gelmini 
AuthorDate: Thu Aug 27 23:32:18 2020 +0200
Commit: Julien Nabet 
CommitDate: Fri Aug 28 11:05:27 2020 +0200

Fix typos in code

It passed "make check" on Linux

Change-Id: I37715efd1fdeee53f2ebb747d668553ae4a75290
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101511
Tested-by: Jenkins
Reviewed-by: Julien Nabet 

diff --git a/vcl/qa/cppunit/timer.cxx b/vcl/qa/cppunit/timer.cxx
index 4071cd0fdc3b..112e3f611b96 100644
--- a/vcl/qa/cppunit/timer.cxx
+++ b/vcl/qa/cppunit/timer.cxx
@@ -470,21 +470,21 @@ namespace {
 class IdleSerializer : public Idle
 {
 sal_uInt32 mnPosition;
-sal_uInt32 &mrProcesed;
+sal_uInt32 &mrProcessed;
 public:
 IdleSerializer(const char *pDebugName, TaskPriority ePrio,
-   sal_uInt32 nPosition, sal_uInt32 &rProcesed)
+   sal_uInt32 nPosition, sal_uInt32 &rProcessed)
 : Idle( pDebugName )
 , mnPosition( nPosition )
-, mrProcesed( rProcesed )
+, mrProcessed( rProcessed )
 {
 SetPriority(ePrio);
 Start();
 }
 virtual void Invoke() override
 {
-++mrProcesed;
-CPPUNIT_ASSERT_EQUAL_MESSAGE( "Ignored prio", mnPosition, mrProcesed );
+++mrProcessed;
+CPPUNIT_ASSERT_EQUAL_MESSAGE( "Ignored prio", mnPosition, mrProcessed 
);
 }
 };
 
diff --git a/vcl/source/gdi/mtfxmldump.cxx b/vcl/source/gdi/mtfxmldump.cxx
index 4af6c43c9acd..229cecda695a 100644
--- a/vcl/source/gdi/mtfxmldump.cxx
+++ b/vcl/source/gdi/mtfxmldump.cxx
@@ -205,7 +205,7 @@ OUString convertPolygonFlags(PolyFlags eFlags)
 }
 }
 
-OUString convertFontWeigthToString(FontWeight eFontWeight)
+OUString convertFontWeightToString(FontWeight eFontWeight)
 {
 switch (eFontWeight)
 {
@@ -1145,7 +1145,7 @@ void MetafileXmlDump::writeXml(const GDIMetaFile& 
rMetaFile, tools::XmlWriter& r
 rWriter.attribute("width", aFont.GetFontSize().Width());
 rWriter.attribute("height", aFont.GetFontSize().Height());
 rWriter.attribute("orientation", aFont.GetOrientation());
-rWriter.attribute("weight", 
convertFontWeigthToString(aFont.GetWeight()));
+rWriter.attribute("weight", 
convertFontWeightToString(aFont.GetWeight()));
 rWriter.attribute("vertical", aFont.IsVertical() ? "true" : 
"false");
 
 rWriter.endElement();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2020-07-20 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/pdfexport/data/form-font-name.odt |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx   |   46 +++
 vcl/source/gdi/pdfwriter_impl.cxx|   13 +-
 3 files changed, 56 insertions(+), 3 deletions(-)

New commits:
commit 6294ecd7b4da38de98b24ddfb9f201cef98c1f41
Author: Miklos Vajna 
AuthorDate: Mon Jul 20 11:36:13 2020 +0200
Commit: Miklos Vajna 
CommitDate: Mon Jul 20 12:54:39 2020 +0200

tdf#50879 PDF export: ensure only built-in fonts are used for forms

Alternative would be to embed the whole font, which is unusual: PDF
typically just embeds the used subset.

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

diff --git a/vcl/qa/cppunit/pdfexport/data/form-font-name.odt 
b/vcl/qa/cppunit/pdfexport/data/form-font-name.odt
new file mode 100644
index ..a7430c9a8a6e
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/form-font-name.odt 
differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index dc6c01fcf719..607d89f8b630 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -130,6 +130,7 @@ public:
 void testVersion15();
 void testDefaultVersion();
 void testMultiPagePDF();
+void testFormFontName();
 
 
 CPPUNIT_TEST_SUITE(PdfExportTest);
@@ -175,6 +176,7 @@ public:
 CPPUNIT_TEST(testVersion15);
 CPPUNIT_TEST(testDefaultVersion);
 CPPUNIT_TEST(testMultiPagePDF);
+CPPUNIT_TEST(testFormFontName);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -2264,6 +2266,50 @@ void PdfExportTest::testMultiPagePDF()
 #endif
 }
 
+void PdfExportTest::testFormFontName()
+{
+// Import the bugdoc and export as PDF.
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"form-font-name.odt";
+mxComponent = loadFromDesktop(aURL);
+
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+utl::MediaDescriptor aMediaDescriptor;
+aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+xStorable->storeToURL(maTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
+
+// Parse the export result with pdfium.
+SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
+SvMemoryStream aMemory;
+aMemory.WriteStream(aFile);
+ScopedFPDFDocument pPdfDocument(
+FPDF_LoadMemDocument(aMemory.GetData(), aMemory.GetSize(), 
/*password=*/nullptr));
+CPPUNIT_ASSERT(pPdfDocument);
+
+// The document has one page.
+CPPUNIT_ASSERT_EQUAL(1, FPDF_GetPageCount(pPdfDocument.get()));
+ScopedFPDFPage pPdfPage(FPDF_LoadPage(pPdfDocument.get(), 
/*page_index=*/0));
+CPPUNIT_ASSERT(pPdfPage);
+
+// The page has one annotation.
+CPPUNIT_ASSERT_EQUAL(1, FPDFPage_GetAnnotCount(pPdfPage.get()));
+ScopedFPDFAnnotation pAnnot(FPDFPage_GetAnnot(pPdfPage.get(), 0));
+
+// Examine the default appearance.
+CPPUNIT_ASSERT(FPDFAnnot_HasKey(pAnnot.get(), "DA"));
+CPPUNIT_ASSERT_EQUAL(FPDF_OBJECT_STRING, 
FPDFAnnot_GetValueType(pAnnot.get(), "DA"));
+size_t nDALength = FPDFAnnot_GetStringValue(pAnnot.get(), "DA", nullptr, 
0);
+std::vector aDABuf(nDALength);
+FPDFAnnot_GetStringValue(pAnnot.get(), "DA", aDABuf.data(), nDALength);
+OUString aDA(reinterpret_cast(aDABuf.data()));
+
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 0 0 0 rg /TiRo 12 Tf
+// - Actual  : 0 0 0 rg /F2 12 Tf
+// i.e. Liberation Serif was exposed as a form font as-is, without picking 
the closest built-in
+// font.
+CPPUNIT_ASSERT_EQUAL(OUString("0 0 0 rg /TiRo 12 Tf"), aDA);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest);
 
 }
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 686635b5b5dc..e40cc7c00872 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -3602,6 +3602,13 @@ Font PDFWriterImpl::replaceFont( const vcl::Font& 
rControlFont, const vcl::Font&
 sal_Int32 PDFWriterImpl::getBestBuildinFont( const vcl::Font& rFont )
 {
 sal_Int32 nBest = 4; // default to Helvetica
+
+if (rFont.GetFamilyType() == FAMILY_ROMAN)
+{
+// Serif: default to Times-Roman.
+nBest = 8;
+}
+
 OUString aFontName( rFont.GetFamilyName() );
 aFontName = aFontName.toAsciiLowerCase();
 
@@ -3748,14 +3755,14 @@ void PDFWriterImpl::createDefaultEditAppearance( 
PDFWidget& rEdit, const PDFWrit
 
 // prepare font to use, draw field border
 Font aFont = drawFieldBorder( rEdit, rWidget, rSettings );
-sal_Int32 nBest = getSystemFont( aFont );
+// Get the built-in font which is closest to aFont.
+sal_Int32 nBest = getBestBuildinFont(aFont);
 
 // prepare DA string
 OStringBuffer aDA( 32 );
 appendNonStrokingColor( replaceColor( 

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

2020-07-02 Thread Luboš Luňák (via logerrit)
 vcl/qa/cppunit/svm/svmtest.cxx |6 ++--
 vcl/source/bitmap/salbmp.cxx   |   51 +
 2 files changed, 50 insertions(+), 7 deletions(-)

New commits:
commit 645d5113965942ee9cba2670fc897b9f8f56a1fb
Author: Luboš Luňák 
AuthorDate: Thu Jul 2 14:40:15 2020 +0200
Commit: Stephan Bergmann 
CommitDate: Fri Jul 3 08:52:58 2020 +0200

compute bitmap checksum for proper amount of bytes and bits

Change-Id: Ifee6fae39dd13a36c72674550cd48dc35fdd71ac
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97761
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx
index 9deed5e13c10..f318aa718c4d 100644
--- a/vcl/qa/cppunit/svm/svmtest.cxx
+++ b/vcl/qa/cppunit/svm/svmtest.cxx
@@ -997,7 +997,7 @@ void SvmTest::checkBitmapExs(const GDIMetaFile& rMetaFile)
 "281fc589",
 "b8dee5da",
 "4df0e464",
-"7d3a8da3",
+"4322ee3a",
 "1426653b",
 "4fd547df",
 "71efc447",
@@ -1012,8 +1012,8 @@ void SvmTest::checkBitmapExs(const GDIMetaFile& rMetaFile)
 "281fc589",
 "5e01ddcc",
 "4df0e464",
-"6c1263f9",
-"747e8dfb",
+"4322ee3a",
+"794c92a9",
 "3c80d829",
 "71efc447",
 });
diff --git a/vcl/source/bitmap/salbmp.cxx b/vcl/source/bitmap/salbmp.cxx
index 6d955b6aa4d3..eae8aadc5d0e 100644
--- a/vcl/source/bitmap/salbmp.cxx
+++ b/vcl/source/bitmap/salbmp.cxx
@@ -19,6 +19,18 @@
 
 #include 
 
+static BitmapChecksum scanlineChecksum(BitmapChecksum nCrc, const sal_uInt8* 
bits, int lineBitsCount, sal_uInt8 extraBitsMask)
+{
+if( lineBitsCount / 8 > 0 )
+nCrc = vcl_get_checksum( nCrc, bits, lineBitsCount / 8 );
+if( extraBitsMask != 0 )
+{
+sal_uInt8 extraByte = bits[ lineBitsCount / 8 ] & extraBitsMask;
+nCrc = vcl_get_checksum( nCrc, &extraByte, 1 );
+}
+return nCrc;
+}
+
 void SalBitmap::updateChecksum() const
 {
 if (mbChecksumValid)
@@ -30,19 +42,50 @@ void SalBitmap::updateChecksum() const
 if (pBuf)
 {
 nCrc = pBuf->maPalette.GetChecksum();
-const int bytesPerPixel = ( pBuf->mnBitCount + 7 ) / 8;
+const int lineBitsCount = pBuf->mnWidth * pBuf->mnBitCount;
+// With 1bpp/4bpp format we need to check only used bits in the last 
byte.
+sal_uInt8 extraBitsMask = 0;
+if( lineBitsCount % 8 != 0 )
+{
+const int extraBitsCount = lineBitsCount % 8;
+switch( RemoveScanline( pBuf->mnFormat ))
+{
+case ScanlineFormat::N1BitMsbPal:
+{
+static const sal_uInt8 mask1Bit[] = { 0x80, 0xc0, 0xe0, 
0xf0, 0xf8, 0xfc, 0xfe, 0xff };
+extraBitsMask = mask1Bit[ extraBitsCount ];
+break;
+}
+case ScanlineFormat::N1BitLsbPal:
+{
+static const sal_uInt8 mask1Bit[] = { 0x01, 0x03, 0x07, 
0x0f, 0x1f, 0x3f, 0x7f, 0xff };
+extraBitsMask = mask1Bit[ extraBitsCount ];
+break;
+}
+case ScanlineFormat::N4BitMsnPal:
+assert(extraBitsCount == 4);
+extraBitsMask = 0xf0;
+break;
+case ScanlineFormat::N4BitLsnPal:
+assert(extraBitsCount == 4);
+extraBitsMask = 0x0f;
+break;
+default:
+break;
+}
+}
 if( pBuf->mnFormat & ScanlineFormat::TopDown )
 {
-if( pBuf->mnScanlineSize == pBuf->mnWidth * bytesPerPixel )
+if( pBuf->mnScanlineSize == lineBitsCount / 8 )
 nCrc = vcl_get_checksum(nCrc, pBuf->mpBits, 
pBuf->mnScanlineSize * pBuf->mnHeight);
 else // Do not include padding with undefined content in the 
checksum.
 for( long y = 0; y < pBuf->mnHeight; ++y )
-nCrc = vcl_get_checksum(nCrc, pBuf->mpBits + y * 
pBuf->mnScanlineSize, pBuf->mnWidth * bytesPerPixel);
+nCrc = scanlineChecksum(nCrc, pBuf->mpBits + y * 
pBuf->mnScanlineSize, lineBitsCount, extraBitsMask);
 }
 else // Compute checksum in the order of scanlines, to make it 
consistent between different bitmap implementations.
 {
 for( long y = pBuf->mnHeight - 1; y >= 0; --y )
-nCrc = vcl_get_checksum(nCrc, pBuf->mpBits + y * 
pBuf->mnScanlineSize, pBuf->mnWidth * bytesPerPixel);
+nCrc = scanlineChecksum(nCrc, pBuf->mpBits + y * 
pBuf->mnScanlineSize, lineBitsCount, extraBitsMask);
 }
 pThis->ReleaseBuffer(pBuf, BitmapAccessMode::Read);
 pThis->mnChecksum = nCrc;
___

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

2020-06-30 Thread Luboš Luňák (via logerrit)
 vcl/qa/cppunit/svm/svmtest.cxx |8 
 vcl/source/bitmap/salbmp.cxx   |   15 ++-
 2 files changed, 18 insertions(+), 5 deletions(-)

New commits:
commit b1c119679700630d16bcf76d96a99e3a39908914
Author: Luboš Luňák 
AuthorDate: Tue Jun 30 09:38:43 2020 +0200
Commit: Luboš Luňák 
CommitDate: Wed Jul 1 07:35:25 2020 +0200

do not use scanline padding for computing vcl bitmap checksum

This idea of checksums is still kind of broken (different RGB order
or different scaling algorithm make the checksum different between
different VCL backends). But at least don't include undefined
garbage.

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

diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx
index 413c3b7f69f4..9deed5e13c10 100644
--- a/vcl/qa/cppunit/svm/svmtest.cxx
+++ b/vcl/qa/cppunit/svm/svmtest.cxx
@@ -1012,10 +1012,10 @@ void SvmTest::checkBitmapExs(const GDIMetaFile& 
rMetaFile)
 "281fc589",
 "5e01ddcc",
 "4df0e464",
-"34434a50",
-"d1736327",
-"b37875c2",
-"a85d44b8",
+"6c1263f9",
+"747e8dfb",
+"3c80d829",
+"71efc447",
 });
 }
 
diff --git a/vcl/source/bitmap/salbmp.cxx b/vcl/source/bitmap/salbmp.cxx
index 3932c12b8ce7..6d955b6aa4d3 100644
--- a/vcl/source/bitmap/salbmp.cxx
+++ b/vcl/source/bitmap/salbmp.cxx
@@ -30,7 +30,20 @@ void SalBitmap::updateChecksum() const
 if (pBuf)
 {
 nCrc = pBuf->maPalette.GetChecksum();
-nCrc = vcl_get_checksum(nCrc, pBuf->mpBits, pBuf->mnScanlineSize * 
pBuf->mnHeight);
+const int bytesPerPixel = ( pBuf->mnBitCount + 7 ) / 8;
+if( pBuf->mnFormat & ScanlineFormat::TopDown )
+{
+if( pBuf->mnScanlineSize == pBuf->mnWidth * bytesPerPixel )
+nCrc = vcl_get_checksum(nCrc, pBuf->mpBits, 
pBuf->mnScanlineSize * pBuf->mnHeight);
+else // Do not include padding with undefined content in the 
checksum.
+for( long y = 0; y < pBuf->mnHeight; ++y )
+nCrc = vcl_get_checksum(nCrc, pBuf->mpBits + y * 
pBuf->mnScanlineSize, pBuf->mnWidth * bytesPerPixel);
+}
+else // Compute checksum in the order of scanlines, to make it 
consistent between different bitmap implementations.
+{
+for( long y = pBuf->mnHeight - 1; y >= 0; --y )
+nCrc = vcl_get_checksum(nCrc, pBuf->mpBits + y * 
pBuf->mnScanlineSize, pBuf->mnWidth * bytesPerPixel);
+}
 pThis->ReleaseBuffer(pBuf, BitmapAccessMode::Read);
 pThis->mnChecksum = nCrc;
 pThis->mbChecksumValid = true;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2020-06-05 Thread Stephan Bergmann (via logerrit)
 vcl/qa/cppunit/FontFeatureTest.cxx |   17 -
 vcl/qa/cppunit/app/test_IconThemeInfo.cxx  |   15 +--
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |3 +--
 vcl/source/control/calendar.cxx|8 ++--
 vcl/source/control/imivctl1.cxx|3 +--
 vcl/source/font/PhysicalFontCollection.cxx |3 +--
 vcl/source/gdi/pdfwriter_impl.cxx  |3 +--
 vcl/source/graphic/GraphicObject.cxx   |3 +--
 vcl/source/treelist/svtabbx.cxx|7 ++-
 vcl/workben/svptest.cxx|4 +---
 vcl/workben/vcldemo.cxx|4 +---
 11 files changed, 24 insertions(+), 46 deletions(-)

New commits:
commit 27c48894cf45fc34f24ae5e1e8bd7a33ab544359
Author: Stephan Bergmann 
AuthorDate: Fri Jun 5 15:27:38 2020 +0200
Commit: Stephan Bergmann 
CommitDate: Fri Jun 5 17:01:58 2020 +0200

Upcoming loplugin:elidestringvar: vcl

Change-Id: Id746bbb3caeb7555e2a89b13fa6dcb089778002a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95597
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/vcl/qa/cppunit/FontFeatureTest.cxx 
b/vcl/qa/cppunit/FontFeatureTest.cxx
index e4040f35bf39..bd8595902449 100644
--- a/vcl/qa/cppunit/FontFeatureTest.cxx
+++ b/vcl/qa/cppunit/FontFeatureTest.cxx
@@ -68,15 +68,14 @@ void FontFeatureTest::testGetFontFeatures()
 
 CPPUNIT_ASSERT_EQUAL(size_t(53), rDefaultFontFeatures.size());
 
-OUString aExpectedFeaturesString = "c2sc case dlig fina frac hlig liga 
lnum "
-   "locl onum pnum sa01 sa02 sa03 sa04 
sa05 "
-   "sa06 sa07 sa08 salt sinf smcp ss01 
ss02 "
-   "ss03 sups tnum zero ingl cpsp lith 
litt "
-   "itlc para algn arti circ dash dbls 
foot "
-   "frsp grkn hang lng minu nfsp name quot 
"
-   "texm thou vari caps ligc ";
-
-CPPUNIT_ASSERT_EQUAL(aExpectedFeaturesString, aFeaturesString);
+CPPUNIT_ASSERT_EQUAL(OUString("c2sc case dlig fina frac hlig liga lnum "
+  "locl onum pnum sa01 sa02 sa03 sa04 sa05 "
+  "sa06 sa07 sa08 salt sinf smcp ss01 ss02 "
+  "ss03 sups tnum zero ingl cpsp lith litt "
+  "itlc para algn arti circ dash dbls foot "
+  "frsp grkn hang lng minu nfsp name quot "
+  "texm thou vari caps ligc "),
+ aFeaturesString);
 
 // Check C2SC feature
 {
diff --git a/vcl/qa/cppunit/app/test_IconThemeInfo.cxx 
b/vcl/qa/cppunit/app/test_IconThemeInfo.cxx
index d2e466d89f94..a68df2f78b9e 100644
--- a/vcl/qa/cppunit/app/test_IconThemeInfo.cxx
+++ b/vcl/qa/cppunit/app/test_IconThemeInfo.cxx
@@ -54,8 +54,7 @@ class IconThemeInfoTest : public CppUnit::TestFixture
 void
 IconThemeInfoTest::UpperCaseDisplayNameIsReturnedForNonDefaultId()
 {
-OUString const id("katze");
-OUString displayName = vcl::IconThemeInfo::ThemeIdToDisplayName(id);
+OUString displayName = vcl::IconThemeInfo::ThemeIdToDisplayName("katze");
 CPPUNIT_ASSERT_EQUAL_MESSAGE("theme id is properly uppercased", 
OUString("Katze"), displayName);
 }
 
@@ -69,16 +68,14 @@ IconThemeInfoTest::ImagesZipIsNotValid()
 void
 IconThemeInfoTest::ImagesColibreZipIsValid()
 {
-OUString const id("file://images_colibre.zip");
-bool valid = vcl::IconThemeInfo::UrlCanBeParsed(id);
+bool valid = 
vcl::IconThemeInfo::UrlCanBeParsed("file://images_colibre.zip");
 CPPUNIT_ASSERT_EQUAL_MESSAGE("images_colibre.zip is a valid theme name", 
true, valid);
 }
 
 void
 IconThemeInfoTest::ThemeIdIsDetectedFromFileNameWithUnderscore()
 {
-OUString const fname("images_colibre.zip");
-OUString sname = vcl::IconThemeInfo::FileNameToThemeId(fname);
+OUString sname = 
vcl::IconThemeInfo::FileNameToThemeId("images_colibre.zip");
 CPPUNIT_ASSERT_EQUAL_MESSAGE("'colibre' theme id is returned for 
'images_colibre.zip'", OUString("colibre"), sname);
 }
 
@@ -86,9 +83,8 @@ void
 IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined1()
 {
 bool thrown = false;
-OUString const fname("images_colibre");
 try {
-vcl::IconThemeInfo::FileNameToThemeId(fname);
+vcl::IconThemeInfo::FileNameToThemeId("images_colibre");
 }
 catch (std::runtime_error&) {
 thrown = true;
@@ -100,9 +96,8 @@ void
 IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined2()
 {
 bool thrown = false;
-OUString const fname("image_colibre.zip");
 try {
-vcl::IconThemeInfo::FileNameToThemeId(fname);
+vcl::IconThemeInfo::FileNameToThemeId("image_colibre.zip");
 }
 catch (std::runtime_error&) {
 thrown = true;
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 

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

2020-06-03 Thread Mark Hung (via logerrit)
 vcl/qa/cppunit/BitmapScaleTest.cxx  |   47 +++-
 vcl/source/bitmap/BitmapFastScaleFilter.cxx |3 -
 2 files changed, 40 insertions(+), 10 deletions(-)

New commits:
commit 4ce833e4ffa440d2f6970e94346c2745dffc3ebf
Author: Mark Hung 
AuthorDate: Tue Apr 14 00:05:37 2020 +0800
Commit: Mark Hung 
CommitDate: Wed Jun 3 16:18:28 2020 +0200

vcl: allow BitmapFastScaleFilter for 1xN or Nx1 cases.

Limiting both side to be at least 2px is not necessary,
so check for 1px and add test cases.

Change-Id: I3c6f6ed5c8842bf24e7983bd8ed27fb8bb9568c8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92117
Tested-by: Jenkins
Reviewed-by: Mark Hung 

diff --git a/vcl/qa/cppunit/BitmapScaleTest.cxx 
b/vcl/qa/cppunit/BitmapScaleTest.cxx
index b804cd1bf6d3..f73d54f6174d 100644
--- a/vcl/qa/cppunit/BitmapScaleTest.cxx
+++ b/vcl/qa/cppunit/BitmapScaleTest.cxx
@@ -110,7 +110,11 @@ void BitmapScaleTest::testScale()
 { Size(14, 18), Size(16, 30) },
 // ratio larger than 16 (triggers different paths in some 
OpenGL algorithms)
 { Size(18 * 20, 18 * 20), Size(14, 14) },
-{ Size(14, 14), Size(18 * 20, 18 * 20) }
+{ Size(14, 14), Size(18 * 20, 18 * 20) },
+// Boundary cases.
+{ Size(1, 1), Size(1, 1) },
+{ Size(16, 1), Size(12, 1) },
+{ Size(1, 16), Size(1, 12) }
   };
 for (const ScaleSize& scaleSize : scaleSizes)
 {
@@ -125,16 +129,18 @@ void BitmapScaleTest::testScale()
 BitmapScopedWriteAccess writeAccess(bitmap);
 const int halfW = scaleSize.srcSize.getWidth() / 2;
 const int halfH = scaleSize.srcSize.getHeight() / 2;
+const Size aSize(std::max(halfW, 1), std::max(halfH, 1));
+
 writeAccess->SetFillColor(COL_GREEN);
-writeAccess->FillRect(Rectangle(Point(0, 0), Size(halfW, 
halfH)));
+writeAccess->FillRect(Rectangle(Point(0, 0), aSize));
 writeAccess->SetFillColor(COL_RED);
-writeAccess->FillRect(Rectangle(Point(0, halfH), Size(halfW, 
halfH)));
+writeAccess->FillRect(Rectangle(Point(0, halfH), aSize));
 writeAccess->SetFillColor(COL_YELLOW);
-writeAccess->FillRect(Rectangle(Point(halfW, 0), Size(halfW, 
halfH)));
+writeAccess->FillRect(Rectangle(Point(halfW, 0), aSize));
 writeAccess->SetFillColor(COL_BLACK);
-writeAccess->FillRect(Rectangle(Point(halfW, halfH), 
Size(halfW, halfH)));
+writeAccess->FillRect(Rectangle(Point(halfW, halfH), aSize));
 writeAccess->SetFillColor(COL_BLUE);
-writeAccess->FillRect(Rectangle(Point(halfW / 2, halfH / 2), 
Size(halfW, halfH)));
+writeAccess->FillRect(Rectangle(Point(halfW / 2, halfH / 2), 
aSize));
 }
 if (bExportBitmap)
 {
@@ -150,13 +156,24 @@ void BitmapScaleTest::testScale()
 rFilter.compressAsPNG(bitmap, aStream);
 }
 CPPUNIT_ASSERT_EQUAL(scaleSize.destSize, bitmap.GetSizePixel());
+const int lastW = scaleSize.destSize.getWidth() - 1;
+const int lastH = scaleSize.destSize.getHeight() - 1;
+if (scaleSize.srcSize.getWidth() == 1 && 
scaleSize.srcSize.getHeight() == 1)
+{
+BitmapReadAccess readAccess(bitmap);
+assertColorsAreSimilar(2, __LINE__, COL_BLUE, 
readAccess.GetColor(0, 0));
+assertColorsAreSimilar(2, __LINE__, COL_BLUE, 
readAccess.GetColor(lastH, 0));
+assertColorsAreSimilar(2, __LINE__, COL_BLUE, 
readAccess.GetColor(0, lastW));
+assertColorsAreSimilar(2, __LINE__, COL_BLUE, 
readAccess.GetColor(lastH, lastW));
+assertColorsAreSimilar(2, __LINE__, COL_BLUE,
+   readAccess.GetColor(lastH / 2, lastW / 
2));
+}
+else if (lastW && lastH)
 {
 // Scaling should keep each quarter of the resulting bitmap 
have the same color,
 // so check that color in each corner of the result bitmap is 
the same color,
 // or reasonably close (some algorithms may alter the color 
very slightly).
 BitmapReadAccess readAccess(bitmap);
-const int lastW = scaleSize.destSize.getWidth() - 1;
-const int lastH = scaleSize.destSize.getHeight() - 1;
 assertColorsAreSimilar(2, __LINE__, COL_GREEN, 
readAccess.GetColor(0, 0));
 assertColorsAreSimilar(2, __LINE__, COL_RED, 
readAccess.GetColor(lastH, 0));
 assertColorsAreSimilar(2, __LINE__, COL_YELLOW, 
readAccess.GetColor(0, lastW));
@@ -164,6 +181,20 @@ void BitmapScaleTest::testScale

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

2020-04-16 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/pdfexport/data/6m-wide.odg |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx|   23 +
 vcl/source/gdi/pdfwriter_impl.cxx |   51 ++
 vcl/source/gdi/pdfwriter_impl.hxx |7 +++-
 4 files changed, 74 insertions(+), 7 deletions(-)

New commits:
commit 4830592b780833cf5eee2aef30bc9c5d444dfb24
Author: Miklos Vajna 
AuthorDate: Thu Apr 16 18:13:01 2020 +0200
Commit: Miklos Vajna 
CommitDate: Thu Apr 16 21:59:00 2020 +0200

PDF export: fix handling of page sizes larger than 508 cm

The value of these coordinates are not allowed to be larger than 14 400,
and Adobe Reader complains about them.

Use UserUnit to declare in case we won't work with points anymore, but
with a larger unit. This will mean UserUnit=2 in practice, since e.g.
Draw has is page size limited to 600x600cm, so larger values won't
happen, at least not for now.

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

diff --git a/vcl/qa/cppunit/pdfexport/data/6m-wide.odg 
b/vcl/qa/cppunit/pdfexport/data/6m-wide.odg
new file mode 100644
index ..49fb9bfff92e
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/6m-wide.odg differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index a3ea246ed612..a2910b44fb81 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -143,6 +143,7 @@ public:
 void testReduceSmallImage();
 void testReduceImage();
 void testLinkWrongPage();
+void testLargePage();
 
 CPPUNIT_TEST_SUITE(PdfExportTest);
 CPPUNIT_TEST(testTdf106059);
@@ -183,6 +184,7 @@ public:
 CPPUNIT_TEST(testReduceSmallImage);
 CPPUNIT_TEST(testReduceImage);
 CPPUNIT_TEST(testLinkWrongPage);
+CPPUNIT_TEST(testLargePage);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -1996,6 +1998,27 @@ void PdfExportTest::testLinkWrongPage()
 CPPUNIT_ASSERT(!HasLinksOnPage(pPdfPage2));
 }
 
+void PdfExportTest::testLargePage()
+{
+// Import the bugdoc and export as PDF.
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"6m-wide.odg";
+utl::MediaDescriptor aMediaDescriptor;
+aMediaDescriptor["FilterName"] <<= OUString("draw_pdf_Export");
+DocumentHolder pPdfDocument = exportAndParse(aURL, aMediaDescriptor);
+
+// The document has 1 page.
+CPPUNIT_ASSERT_EQUAL(1, FPDF_GetPageCount(pPdfDocument.get()));
+
+// Check the value (not the unit) of the page size.
+FS_SIZEF aSize;
+FPDF_GetPageSizeByIndexF(pPdfDocument.get(), 0, &aSize);
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 8503.94
+// - Actual  : 17007.875
+// i.e. the value for 600 cm was larger than the 14 400 limit set in the 
spec.
+CPPUNIT_ASSERT_DOUBLES_EQUAL(8503.94, static_cast(aSize.width), 
0.01);
+}
+
 void PdfExportTest::testPdfImageResourceInlineXObjectRef()
 {
 // Create an empty document.
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index e98e822c62e1..05fca4cf21f4 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -557,6 +557,7 @@ PDFPage::PDFPage( PDFWriterImpl* pWriter, double 
nPageWidth, double nPageHeight,
 {
 // object ref must be only ever updated in emit()
 m_nPageObject = m_pWriter->createObject();
+m_nUserUnit = std::ceil(std::max(nPageWidth, nPageHeight) / 14400.0);
 }
 
 void PDFPage::beginStream()
@@ -635,10 +636,15 @@ bool PDFPage::emit(sal_Int32 nParentObject )
 if( m_nPageWidth && m_nPageHeight )
 {
 aLine.append( "/MediaBox[0 0 " );
-aLine.append( m_nPageWidth );
+aLine.append(m_nPageWidth / m_nUserUnit);
 aLine.append( ' ' );
-aLine.append( m_nPageHeight );
+aLine.append(m_nPageHeight / m_nUserUnit);
 aLine.append( "]" );
+if (m_nUserUnit > 1)
+{
+aLine.append("\n/UserUnit ");
+aLine.append(m_nUserUnit);
+}
 }
 switch( m_eOrientation )
 {
@@ -1116,6 +1122,18 @@ void PDFPage::appendMatrix3(Matrix3 const & rMatrix, 
OStringBuffer& rBuffer)
 appendPoint(Point(long(rMatrix.get(4)), long(rMatrix.get(5))), rBuffer);
 }
 
+double PDFPage::getHeight() const
+{
+double fRet = m_nPageHeight ? m_nPageHeight : 
vcl::pdf::g_nInheritedPageHeight;
+
+if (m_nUserUnit > 1)
+{
+fRet /= m_nUserUnit;
+}
+
+return fRet;
+}
+
 PDFWriterImpl::PDFWriterImpl( const PDFWriter::PDFWriterContext& rContext,
const css::uno::Reference< 
css::beans::XMaterialHolder >& xEnc,
PDFWriter& i_rOuterFace)
@@ -1612,6 +1630,14 @@ void PDFWriterImpl::newPage( double nPageWidth, double 
nPageHeight, PDFWriter::O
 endPage(

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

2020-04-04 Thread Tomaž Vajngerl (via logerrit)
 vcl/qa/cppunit/BitmapFilterTest.cxx |5 
 vcl/source/bitmap/BitmapFilterStackBlur.cxx |  278 
 2 files changed, 208 insertions(+), 75 deletions(-)

New commits:
commit 3c1e746e479b89dd5c566c0a950dba23e0a2074e
Author: Tomaž Vajngerl 
AuthorDate: Sat Apr 4 13:52:24 2020 +0200
Commit: Tomaž Vajngerl 
CommitDate: Sat Apr 4 16:27:10 2020 +0200

vcl: Parallelize BitmapFilterStackBlur

Performance increase from ~3100ms to ~1400ms on 4c/8t CPU.

Change-Id: Ic057c3fafc3cf6f0f90430ca431db569be08a133
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91684
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/BitmapFilterTest.cxx 
b/vcl/qa/cppunit/BitmapFilterTest.cxx
index 732c0c2dfb0b..a28057a4bf57 100644
--- a/vcl/qa/cppunit/BitmapFilterTest.cxx
+++ b/vcl/qa/cppunit/BitmapFilterTest.cxx
@@ -129,10 +129,11 @@ void BitmapFilterTest::testPerformance()
 
 int nIterations = 10;
 auto start = std::chrono::high_resolution_clock::now();
+Bitmap aResult;
 for (int i = 0; i < nIterations; i++)
 {
 BitmapFilterStackBlur aBlurFilter(250, false); // don't extend the 
image
-aBlurFilter.filter(aBigBitmap);
+aResult = aBlurFilter.filter(aBigBitmap);
 }
 auto end = std::chrono::high_resolution_clock::now();
 auto elapsed = (end - start) / nIterations;
@@ -142,7 +143,7 @@ void BitmapFilterTest::testPerformance()
 std::unique_ptr pStream(
 new SvFileStream("~/BlurBigPerformance.png", StreamMode::WRITE | 
StreamMode::TRUNC));
 GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
-rFilter.compressAsPNG(aBigBitmap, *pStream);
+rFilter.compressAsPNG(aResult, *pStream);
 
 pStream.reset(new SvFileStream("~/BlurBigPerformance.txt", 
StreamMode::WRITE));
 pStream->WriteOString("Blur average time: ");
diff --git a/vcl/source/bitmap/BitmapFilterStackBlur.cxx 
b/vcl/source/bitmap/BitmapFilterStackBlur.cxx
index 9629cc079c00..adac14248753 100644
--- a/vcl/source/bitmap/BitmapFilterStackBlur.cxx
+++ b/vcl/source/bitmap/BitmapFilterStackBlur.cxx
@@ -11,6 +11,9 @@
 #include 
 #include 
 #include 
+#include 
+
+#include 
 
 namespace
 {
@@ -48,9 +51,30 @@ static const sal_Int16 constShiftTable[255]
 class BlurSharedData
 {
 public:
+BitmapReadAccess* mpReadAccess;
+BitmapWriteAccess* mpWriteAccess;
 long mnRadius;
 long mnComponentWidth;
 long mnDiv;
+long mnColorChannels;
+
+BlurSharedData(BitmapReadAccess* pReadAccess, BitmapWriteAccess* 
pWriteAccess, long aRadius,
+   long nComponentWidth, long nColorChannels)
+: mpReadAccess(pReadAccess)
+, mpWriteAccess(pWriteAccess)
+, mnRadius(aRadius)
+, mnComponentWidth(nComponentWidth)
+, mnDiv(aRadius + aRadius + 1)
+, mnColorChannels(nColorChannels)
+{
+}
+};
+
+class BlurArrays
+{
+public:
+BlurSharedData maShared;
+
 std::vector maStackBuffer;
 std::vector maPositionTable;
 std::vector maWeightTable;
@@ -59,31 +83,54 @@ public:
 std::vector mnInSumVector;
 std::vector mnOutSumVector;
 
-BlurSharedData(long aRadius, long nComponentWidth, long nColorChannels)
-: mnRadius(aRadius)
-, mnComponentWidth(nComponentWidth)
-, mnDiv(aRadius + aRadius + 1)
-, maStackBuffer(mnDiv * mnComponentWidth)
-, maPositionTable(mnDiv)
-, maWeightTable(mnDiv)
-, mnSumVector(nColorChannels)
-, mnInSumVector(nColorChannels)
-, mnOutSumVector(nColorChannels)
+BlurArrays(BlurSharedData const& rShared)
+: maShared(rShared)
+, maStackBuffer(maShared.mnDiv * maShared.mnComponentWidth)
+, maPositionTable(maShared.mnDiv)
+, maWeightTable(maShared.mnDiv)
+, mnSumVector(maShared.mnColorChannels)
+, mnInSumVector(maShared.mnColorChannels)
+, mnOutSumVector(maShared.mnColorChannels)
 {
 }
 
-void calculateWeightAndPositions(long nLastIndex)
+void initializeWeightAndPositions(long nLastIndex)
 {
-for (long i = 0; i < mnDiv; i++)
+for (long i = 0; i < maShared.mnDiv; i++)
 {
-maPositionTable[i] = std::min(nLastIndex, std::max(0L, i - 
mnRadius));
-maWeightTable[i] = mnRadius + 1 - std::abs(i - mnRadius);
+maPositionTable[i] = std::min(nLastIndex, std::max(0L, i - 
maShared.mnRadius));
+maWeightTable[i] = maShared.mnRadius + 1 - std::abs(i - 
maShared.mnRadius);
 }
 }
 
-long getMultiplyValue() { return 
static_cast(constMultiplyTable[mnRadius]); }
+long getMultiplyValue() { return 
static_cast(constMultiplyTable[maShared.mnRadius]); }
+
+long getShiftValue() { return 
static_cast(constShiftTable[maShared.mnRadius]); }
+};
+
+typedef void (*BlurRangeFn)(BlurSharedData const& rShared, long nStartY, long 
nEndY);
+
+constexpr long constBlurThread

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

2020-02-04 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |5 +++--
 vcl/source/gdi/pdfwriter_impl.cxx  |   10 ++
 2 files changed, 13 insertions(+), 2 deletions(-)

New commits:
commit 7088140dbf1d5e0391c2662f0213018a45620ff9
Author: Miklos Vajna 
AuthorDate: Mon Feb 3 20:23:23 2020 +0100
Commit: Miklos Vajna 
CommitDate: Tue Feb 4 09:14:49 2020 +0100

tdf#129976 PDF export of PDF images: adapt transparency to rendering

The bugdoc has a transparent PDF image, and we currently put a white
background behind that in Impress, given that vcl::RenderPDFBitmaps()
works with Bitmap instances, not BitmapEx ones.

This means that in case we preserve transparency during PDF export, the
content that was rendered OK now becomes unreadable.

Adapt the PDF export to do the same as rendering by putting a white
background behind the PDF image.

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

diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index c13b2ab80c09..c760fc7e1cf4 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -2009,8 +2009,9 @@ void PdfExportTest::testPdfImageResourceInlineXObjectRef()
 CPPUNIT_ASSERT_EQUAL(1, FPDFPage_CountObjects(pPdfPage.get()));
 FPDF_PAGEOBJECT pPageObject = FPDFPage_GetObject(pPdfPage.get(), 0);
 CPPUNIT_ASSERT_EQUAL(FPDF_PAGEOBJ_FORM, FPDFPageObj_GetType(pPageObject));
-CPPUNIT_ASSERT_EQUAL(1, FPDFFormObj_CountObjects(pPageObject));
-FPDF_PAGEOBJECT pFormObject = FPDFFormObj_GetObject(pPageObject, 0);
+// 2: white background and the actual object.
+CPPUNIT_ASSERT_EQUAL(2, FPDFFormObj_CountObjects(pPageObject));
+FPDF_PAGEOBJECT pFormObject = FPDFFormObj_GetObject(pPageObject, 1);
 CPPUNIT_ASSERT_EQUAL(FPDF_PAGEOBJ_FORM, FPDFPageObj_GetType(pFormObject));
 // Without the accompanying fix in place, this test would have failed with:
 // - Expected: 1
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index ec148b2159d8..6726b02b7173 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -8757,6 +8757,16 @@ void 
PDFWriterImpl::writeReferenceXObject(ReferenceXObjectEmit& rEmit)
 // Reset line width to the default.
 aStream.append(" 1 w\n");
 
+// vcl::RenderPDFBitmaps() effectively renders a white background for 
transparent input, be
+// consistent with that.
+aStream.append("1 1 1 rg\n");
+aStream.append("0 0 ");
+aStream.append(aSize.Width());
+aStream.append(" ");
+aStream.append(aSize.Height());
+aStream.append(" re\n");
+aStream.append("f*\n");
+
 // No reference XObject, draw the form XObject containing the original
 // page streams.
 aStream.append("/Im");
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2020-01-20 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/pdfexport/data/reduce-small-image.fodt |   21 +
 vcl/qa/cppunit/pdfexport/pdfexport.cxx|   41 ++
 vcl/source/gdi/pdfwriter_impl2.cxx|6 +-
 3 files changed, 66 insertions(+), 2 deletions(-)

New commits:
commit b894ec7fadb8ca6bf0b33fa9eee4b9303e8161d4
Author: Miklos Vajna 
AuthorDate: Mon Jan 20 17:53:25 2020 +0100
Commit: Miklos Vajna 
CommitDate: Mon Jan 20 22:43:49 2020 +0100

PDF export: skip pointless downsampling for very small images

Regression from commit b6588bd7c831ce88a29131ca7ea8d3f3e082564e (Reduce
image resolution by default in PDF Export, 2014-03-02) the problem is
that in case you have small enough bitmaps, then these used to look
OK at reasonable zoom levels, but now we intentionally scale down
bitmaps by default.

That makes little sense for tiny images, do this only for large ones.

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

diff --git a/vcl/qa/cppunit/pdfexport/data/reduce-small-image.fodt 
b/vcl/qa/cppunit/pdfexport/data/reduce-small-image.fodt
new file mode 100644
index ..99ff22746e48
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/reduce-small-image.fodt
@@ -0,0 +1,21 @@
+
+http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:css3t="http://www.w3.org/TR/css3-text/"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.
 0" 
xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
 xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:dc="http://purl.org/dc/elements/1.1/"; 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:rpt="http://op
 enoffice.org/2005/report" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+  
+
+
+
+
+  
+  
+
+  
+
+  
+  
+
+  iVBORw0KGgoNSUhEUgAAABAQCAYf8/9hMklEQVR42mP4//8/AyWYYXAZ
+   wHSK+z8pbOoaAJIgBWM1gFh/jxqAxwCKYmHgE9KAZSYAhK3Dgc2FxfUASUVORK5CYII=
+  
+
+  
+
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 80d88a84adf1..d3cdcce90ea4 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -137,6 +137,7 @@ public:
 void testTdf121615();
 void testTocLink();
 void testPdfImageResourceInlineXObjectRef();
+void testReduceSmallImage();
 
 CPPUNIT_TEST_SUITE(PdfExportTest);
 CPPUNIT_TEST(testTdf106059);
@@ -174,6 +175,7 @@ public:
 CPPUNIT_TEST(testTdf121615);
 CPPUNIT_TEST(testTocLink);
 CPPUNIT_TEST(testPdfImageResourceInlineXObjectRef);
+CPPUNIT_TEST(testReduceSmallImage);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -1858,6 +1860,45 @@ void PdfExportTest::testTocLink()
 CPPUNIT_ASSERT(FPDFLink_Enumerate(pPdfPage.get(), &nStartPos, 
&pLinkAnnot));
 }
 
+void PdfExportTest::testReduceSmallImage()
+{
+// Load the Writer document.
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"reduce-small-image.fodt";
+mxComponent = loadFromDesktop(aURL);
+
+// Save as PDF.
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+utl::MediaDescriptor aM

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

2019-11-26 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/outdev.cxx|   53 +++
 vcl/source/outdev/bitmap.cxx |3 +-
 2 files changed, 55 insertions(+), 1 deletion(-)

New commits:
commit 8dde8f9768f0dab97cdd30e3116f7e4d737c482f
Author: Miklos Vajna 
AuthorDate: Mon Nov 25 20:07:02 2019 +0100
Commit: Miklos Vajna 
CommitDate: Tue Nov 26 09:03:44 2019 +0100

tdf#128629 vcl DrawTransformedBitmapEx: do scaling for flipped bitmaps

Regression from commit dd4a67084853a030bf4b9f1f85d728620e0604a5 (vcl:
avoid downscale && upscale in DrawTransformedBitmapEx(), 2019-10-08),
the original problem to be solved was that in case you downscale a
bitmap and upscale it later, then you get blurry result, so we try to
avoid touching the pixels and just scale during rendering of the bitmap.

However, here the problem is that scaling is also (mis)used for flip
purposes, so go back to the original behavior for negative scaling.

This keeps the original problem fixed and solves the loss of flip as
well.

Change-Id: Ic9a6eb49d55f2fb8ccf18d982e574398f010cabd
Reviewed-on: https://gerrit.libreoffice.org/83711
Tested-by: Jenkins
Reviewed-by: Miklos Vajna 

diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index f4a27b0b0558..8b2dd7c3a841 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -31,6 +31,7 @@ public:
 void testGetReadableFontColorPrinter();
 void testGetReadableFontColorWindow();
 void testDrawTransformedBitmapEx();
+void testDrawTransformedBitmapExFlip();
 
 CPPUNIT_TEST_SUITE(VclOutdevTest);
 CPPUNIT_TEST(testVirtualDevice);
@@ -40,6 +41,7 @@ public:
 CPPUNIT_TEST(testGetReadableFontColorPrinter);
 CPPUNIT_TEST(testGetReadableFontColorWindow);
 CPPUNIT_TEST(testDrawTransformedBitmapEx);
+CPPUNIT_TEST(testDrawTransformedBitmapExFlip);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -201,6 +203,57 @@ void VclOutdevTest::testDrawTransformedBitmapEx()
 }
 }
 
+void VclOutdevTest::testDrawTransformedBitmapExFlip()
+{
+// Create a virtual device, and connect a metafile to it.
+// Also create a 16x16 bitmap.
+ScopedVclPtrInstance pVDev;
+Bitmap aBitmap(Size(16, 16), 24);
+{
+// Fill the top left quarter with black.
+BitmapScopedWriteAccess pWriteAccess(aBitmap);
+pWriteAccess->Erase(COL_WHITE);
+for (int i = 0; i < 8; ++i)
+{
+for (int j = 0; j < 8; ++j)
+{
+pWriteAccess->SetPixel(j, i, COL_BLACK);
+}
+}
+}
+BitmapEx aBitmapEx(aBitmap);
+basegfx::B2DHomMatrix aMatrix;
+// Negative y scale: bitmap should be upside down, so the black part goes 
to the bottom left.
+aMatrix.scale(8, -8);
+// Rotate 90 degrees clockwise, so the black part goes back to the top 
left.
+aMatrix.rotate(M_PI / 2);
+GDIMetaFile aMtf;
+aMtf.Record(pVDev.get());
+
+// Draw the scaled and rotated bitmap on the vdev.
+pVDev->DrawTransformedBitmapEx(aMatrix, aBitmapEx);
+CPPUNIT_ASSERT_EQUAL(static_cast(1), aMtf.GetActionSize());
+MetaAction* pAction = aMtf.GetAction(0);
+CPPUNIT_ASSERT_EQUAL(MetaActionType::BMPEXSCALE, pAction->GetType());
+auto pBitmapAction = static_cast(pAction);
+const BitmapEx& rBitmapEx = pBitmapAction->GetBitmapEx();
+
+aBitmap = rBitmapEx.GetBitmap();
+Bitmap::ScopedReadAccess pAccess(aBitmap);
+int nX = 8 * 0.25;
+int nY = 8 * 0.25;
+BitmapColor aColor = pAccess->GetPixel(nY, nX);
+std::stringstream ss;
+ss << "Color is expected to be black, is " << aColor.AsRGBHexString();
+ss << " (row " << nY << ", col " << nX << ")";
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: c[]
+// - Actual  : c[ff00]
+// - Color is expected to be black, is ff (row 2, col 2)
+// i.e. the top left quarter of the image was not black, due to a missing 
flip.
+CPPUNIT_ASSERT_EQUAL_MESSAGE(ss.str(), COL_BLACK, Color(aColor));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(VclOutdevTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx
index f0a20db1a41e..5db64d06dc40 100644
--- a/vcl/source/outdev/bitmap.cxx
+++ b/vcl/source/outdev/bitmap.cxx
@@ -1277,7 +1277,8 @@ void OutputDevice::DrawTransformedBitmapEx(
 basegfx::B2DVector aFullScale, aFullTranslate;
 double fFullRotate, fFullShearX;
 aFullTransform.decompose(aFullScale, aFullTranslate, fFullRotate, 
fFullShearX);
-if (aFullScale.getX() != 0 && aFullScale.getY() != 0)
+// Require positive scaling, negative scaling would loose 
horizontal or vertical flip.
+if (aFullScale.getX() > 0 && aFullScale.getY() > 0)
 {
 basegfx::B2DHomMatrix aTransform = 
basegfx::utils::createScaleB2DHomMatrix(
 rOr

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

2019-11-19 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/GraphicTest.cxx|   22 ++
 vcl/qa/cppunit/data/inch-size.emf |binary
 vcl/source/gdi/impgraph.cxx   |4 +++-
 3 files changed, 25 insertions(+), 1 deletion(-)

New commits:
commit 0098563895f6a4024b400582d1bf93cb4435ceed
Author: Miklos Vajna 
AuthorDate: Mon Nov 18 21:18:24 2019 +0100
Commit: Miklos Vajna 
CommitDate: Tue Nov 19 09:04:03 2019 +0100

tdf#128632 vcl image lazy-load: take unit into account when setting size

It makes no sense to set the size of an image based on the swap info
when the swap info unit and the actually loaded image's unit doesn't
match.

Converting the size would be also an option, but let's wait for the
first case when a custom size is actually needed for mismatching units.

Change-Id: I96b5c237f0be5587bb2f938faf3c69fa0e1d4a5c
Reviewed-on: https://gerrit.libreoffice.org/83122
Tested-by: Jenkins
Reviewed-by: Miklos Vajna 

diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
index 56e05c8bf3de..e67ba6ff7ee7 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 using namespace css;
 
@@ -29,12 +30,14 @@ class GraphicTest : public CppUnit::TestFixture
 void testUnloadedGraphicLoading();
 void testUnloadedGraphicWmf();
 void testUnloadedGraphicAlpha();
+void testUnloadedGraphicSizeUnit();
 
 CPPUNIT_TEST_SUITE(GraphicTest);
 CPPUNIT_TEST(testUnloadedGraphic);
 CPPUNIT_TEST(testUnloadedGraphicLoading);
 CPPUNIT_TEST(testUnloadedGraphicWmf);
 CPPUNIT_TEST(testUnloadedGraphicAlpha);
+CPPUNIT_TEST(testUnloadedGraphicSizeUnit);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -79,6 +82,8 @@ Graphic makeUnloadedGraphic(OUString const& sType, bool alpha 
= false)
 return rGraphicFilter.ImportUnloadedGraphic(aStream);
 }
 
+char const DATA_DIRECTORY[] = "/vcl/qa/cppunit/data/";
+
 void GraphicTest::testUnloadedGraphic()
 {
 // make unloaded test graphic
@@ -194,6 +199,23 @@ void GraphicTest::testUnloadedGraphicAlpha()
 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
 }
 
+void GraphicTest::testUnloadedGraphicSizeUnit()
+{
+GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
+test::Directories aDirectories;
+OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + 
"inch-size.emf";
+Size aMtfSize100(42, 42);
+SvFileStream aStream(aURL, StreamMode::READ);
+Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream, 0, 
&aMtfSize100);
+aGraphic.makeAvailable();
+
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 400x363
+// - Actual  : 42x42
+// i.e. a mm100 size was used as a hint and the inch size was set for a 
non-matching unit.
+CPPUNIT_ASSERT_EQUAL(Size(400, 363), aGraphic.GetPrefSize());
+}
+
 } // namespace
 
 CPPUNIT_TEST_SUITE_REGISTRATION(GraphicTest);
diff --git a/vcl/qa/cppunit/data/inch-size.emf 
b/vcl/qa/cppunit/data/inch-size.emf
new file mode 100644
index ..ac5a1b805cf2
Binary files /dev/null and b/vcl/qa/cppunit/data/inch-size.emf differ
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 824caae1698f..280ad3c2f1cd 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -1570,10 +1570,12 @@ bool ImpGraphic::loadPrepared()
 GraphicExternalLink aLink = maGraphicExternalLink;
 
 Size aPrefSize = maSwapInfo.maPrefSize;
+MapMode aPrefMapMode = maSwapInfo.maPrefMapMode;
 *this = *aGraphic.ImplGetImpGraphic();
-if (aPrefSize.getWidth() && aPrefSize.getHeight())
+if (aPrefSize.getWidth() && aPrefSize.getHeight() && aPrefMapMode == 
ImplGetPrefMapMode())
 {
 // Use custom preferred size if it was set when the graphic was 
still unloaded.
+// Only set the size in case the unloaded and loaded unit matches.
 ImplSetPrefSize(aPrefSize);
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

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

2019-11-11 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/pdfexport/data/tdf128630.odp |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx  |   36 
 vcl/source/outdev/bitmap.cxx|   14 ++
 3 files changed, 49 insertions(+), 1 deletion(-)

New commits:
commit c465d920f4fe15c6e614beffb80b53d24a3dc5c7
Author: Miklos Vajna 
AuthorDate: Mon Nov 11 21:09:14 2019 +0100
Commit: Miklos Vajna 
CommitDate: Tue Nov 12 08:47:16 2019 +0100

tdf#128630 vcl PDF export: fix aspect ratio when scaling rotated image

Regression from commit 68549e00d5e23aa22bc974a8151d93cd948444b3 (vcl,
BitmapEx transformed draw: special-case simple rotations, 2019-10-10),
the intention there was to fix an error on the last col/row of a bitmap,
but that was only tested with input where the aspect ratio doesn't
change on scaling.

Fix the problem by going back to the original way in the "aspect ratio
changes" case.

Change-Id: I52bed503ddaadbbbdf64ac6fec2fe268153866f1
Reviewed-on: https://gerrit.libreoffice.org/82467
Tested-by: Jenkins
Reviewed-by: Miklos Vajna 

diff --git a/vcl/qa/cppunit/pdfexport/data/tdf128630.odp 
b/vcl/qa/cppunit/pdfexport/data/tdf128630.odp
new file mode 100644
index ..d216504b7329
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf128630.odp differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 22585a9827eb..02e597c76dd5 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -128,6 +128,7 @@ public:
 void testTdf66597_3();
 void testTdf109143();
 void testTdf105954();
+void testTdf128630();
 void testTdf106702();
 void testTdf113143();
 void testTdf115262();
@@ -164,6 +165,7 @@ public:
 CPPUNIT_TEST(testTdf66597_3);
 CPPUNIT_TEST(testTdf109143);
 CPPUNIT_TEST(testTdf105954);
+CPPUNIT_TEST(testTdf128630);
 CPPUNIT_TEST(testTdf106702);
 CPPUNIT_TEST(testTdf113143);
 CPPUNIT_TEST(testTdf115262);
@@ -1510,6 +1512,40 @@ void PdfExportTest::testTdf105954()
 CPPUNIT_ASSERT_LESS(static_cast(250), aMeta.width);
 }
 
+void PdfExportTest::testTdf128630()
+{
+// Import the bugdoc and export as PDF.
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"tdf128630.odp";
+utl::MediaDescriptor aMediaDescriptor;
+aMediaDescriptor["FilterName"] <<= OUString("impress_pdf_Export");
+DocumentHolder pPdfDocument = exportAndParse(aURL, aMediaDescriptor);
+
+// The document has one page.
+CPPUNIT_ASSERT_EQUAL(1, FPDF_GetPageCount(pPdfDocument.get()));
+
+// Assert the aspect ratio of the only bitmap on the page.
+PageHolder pPdfPage(FPDF_LoadPage(pPdfDocument.get(), /*page_index=*/0));
+CPPUNIT_ASSERT(pPdfPage.get());
+int nPageObjectCount = FPDFPage_CountObjects(pPdfPage.get());
+for (int i = 0; i < nPageObjectCount; ++i)
+{
+FPDF_PAGEOBJECT pPageObject = FPDFPage_GetObject(pPdfPage.get(), i);
+if (FPDFPageObj_GetType(pPageObject) != FPDF_PAGEOBJ_IMAGE)
+continue;
+
+FPDF_BITMAP pBitmap = FPDFImageObj_GetBitmap(pPageObject);
+CPPUNIT_ASSERT(pBitmap);
+int nWidth = FPDFBitmap_GetWidth(pBitmap);
+int nHeight = FPDFBitmap_GetHeight(pBitmap);
+FPDFBitmap_Destroy(pBitmap);
+// Without the accompanying fix in place, this test would have failed 
with:
+// assertion failed
+// - Expression: nWidth != nHeight
+// i.e. the bitmap lost its custom aspect ratio during export.
+CPPUNIT_ASSERT(nWidth != nHeight);
+}
+}
+
 void PdfExportTest::testTdf106702()
 {
 // Import the bugdoc and export as PDF.
diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx
index 93c1f76aef1f..f0a20db1a41e 100644
--- a/vcl/source/outdev/bitmap.cxx
+++ b/vcl/source/outdev/bitmap.cxx
@@ -1285,8 +1285,20 @@ void OutputDevice::DrawTransformedBitmapEx(
 aFullTransform *= aTransform;
 }
 
-if (bSheared)
+double fSourceRatio = 1.0;
+if (rOriginalSizePixel.getHeight() != 0)
 {
+fSourceRatio = rOriginalSizePixel.getWidth() / 
rOriginalSizePixel.getHeight();
+}
+double fTargetRatio = 1.0;
+if (aFullScale.getY() != 0)
+{
+fTargetRatio = aFullScale.getX() / aFullScale.getY();
+}
+bool bAspectRatioKept = rtl::math::approxEqual(fSourceRatio, 
fTargetRatio);
+if (bSheared || !bAspectRatioKept)
+{
+// Not only rotation, or scaling does not keep aspect ratio.
 aTransformed = aTransformed.getTransformed(
 aFullTransform,
 aVisibleRange,
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freede

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

2019-11-05 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/pdfexport/data/pdf-image-resource-inline-xobject-ref.pdf |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx  |   64 
++
 vcl/source/gdi/pdfwriter_impl.cxx   |   17 
++
 3 files changed, 80 insertions(+), 1 deletion(-)

New commits:
commit adcdd56471f1cc10ff4135975ecadb3a703db6ad
Author: Miklos Vajna 
AuthorDate: Tue Nov 5 16:12:43 2019 +0100
Commit: Miklos Vajna 
CommitDate: Tue Nov 5 17:03:32 2019 +0100

vcl PDF export: fix re-exporting PDF images for dict obj resource sub-keys

Re-exporting PDF images works by tokenizing the PDF image, identifying
which PDF object is the page object and then copying that over to the
PDF output, together with the dependencies of that object.

This involves copying the resources of the page object. Previously we
assumed that the sub-keys of the resources are always inline
dictionaries, but the bugdoc shows that they can be references as well,
which point to dictionary objects, so add support for this scenario.

Change-Id: I78ee1c726e6ecd958232e9fab64773595e5b9c86
Reviewed-on: https://gerrit.libreoffice.org/82076
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins

diff --git 
a/vcl/qa/cppunit/pdfexport/data/pdf-image-resource-inline-xobject-ref.pdf 
b/vcl/qa/cppunit/pdfexport/data/pdf-image-resource-inline-xobject-ref.pdf
new file mode 100644
index ..b62068eae9dd
Binary files /dev/null and 
b/vcl/qa/cppunit/pdfexport/data/pdf-image-resource-inline-xobject-ref.pdf differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index eb779207de56..ba62f301bec4 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -19,6 +19,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -131,6 +134,7 @@ public:
 void testTdf115967();
 void testTdf121615();
 void testTocLink();
+void testPdfImageResourceInlineXObjectRef();
 
 CPPUNIT_TEST_SUITE(PdfExportTest);
 CPPUNIT_TEST(testTdf106059);
@@ -166,6 +170,7 @@ public:
 CPPUNIT_TEST(testTdf115967);
 CPPUNIT_TEST(testTdf121615);
 CPPUNIT_TEST(testTocLink);
+CPPUNIT_TEST(testPdfImageResourceInlineXObjectRef);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -1815,6 +1820,65 @@ void PdfExportTest::testTocLink()
 CPPUNIT_ASSERT(FPDFLink_Enumerate(pPdfPage.get(), &nStartPos, 
&pLinkAnnot));
 }
 
+void PdfExportTest::testPdfImageResourceInlineXObjectRef()
+{
+// Create an empty document.
+mxComponent = loadFromDesktop("private:factory/swriter");
+CPPUNIT_ASSERT(mxComponent.is());
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xText = xTextDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+
+// Insert the PDF image.
+uno::Reference xFactory(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xGraphicObject(
+xFactory->createInstance("com.sun.star.text.TextGraphicObject"), 
uno::UNO_QUERY);
+OUString aURL
+= m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"pdf-image-resource-inline-xobject-ref.pdf";
+xGraphicObject->setPropertyValue("GraphicURL", uno::makeAny(aURL));
+uno::Reference xShape(xGraphicObject, uno::UNO_QUERY);
+xShape->setSize(awt::Size(1000, 1000));
+uno::Reference xTextContent(xGraphicObject, 
uno::UNO_QUERY);
+xText->insertTextContent(xCursor->getStart(), xTextContent, 
/*bAbsorb=*/false);
+
+// Save as PDF.
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+utl::MediaDescriptor aMediaDescriptor;
+aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+xStorable->storeToURL(maTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
+
+// Init pdfium, vcl::ImportPDF() calls FPDF_DestroyLibrary after our 
setUp().
+FPDF_LIBRARY_CONFIG config;
+config.version = 2;
+config.m_pUserFontPaths = nullptr;
+config.m_pIsolate = nullptr;
+config.m_v8EmbedderSlot = 0;
+FPDF_InitLibraryWithConfig(&config);
+
+// Parse the export result.
+SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
+maMemory.WriteStream(aFile);
+DocumentHolder pPdfDocument(
+FPDF_LoadMemDocument(maMemory.GetData(), maMemory.GetSize(), 
/*password=*/nullptr));
+CPPUNIT_ASSERT(pPdfDocument.get());
+CPPUNIT_ASSERT_EQUAL(1, FPDF_GetPageCount(pPdfDocument.get()));
+
+// Make sure that the page -> form -> form has a child image.
+PageHolder pPdfPage(FPDF_LoadPage(pPdfDocument.get(), /*page_index=*/0));
+CPPUNIT_ASSERT(pPdfPage.get());
+CPPUNIT_ASSERT_EQUAL(1, FPDFPage_CountObjects(pPdfPage.get()));
+FPDF_PAGEOBJECT pPageObject = FPDFPage_GetObject(pPdfPage.get(), 0);
+CPPUNIT_ASSERT_EQUAL(FPDF_PAGEOBJ_FORM, FPDFPageObj_GetType(pPageObject));
+CPPUNIT_ASSERT_EQUAL(1, FPDFFormObj_CountObjects(pPage

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

2019-10-10 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/outdev.cxx|   37 +
 vcl/source/outdev/bitmap.cxx |   22 ++
 2 files changed, 55 insertions(+), 4 deletions(-)

New commits:
commit 68549e00d5e23aa22bc974a8151d93cd948444b3
Author: Miklos Vajna 
AuthorDate: Thu Oct 10 19:03:53 2019 +0200
Commit: Miklos Vajna 
CommitDate: Thu Oct 10 20:24:26 2019 +0200

vcl, BitmapEx transformed draw: special-case simple rotations

In case OutputDevice::DrawTransformedBitmapEx() has to do both shearing
and rotation, then recording to a metafile is unchanged.  But if we need
to do rotation, then it's not necessary to go via transformations.

This has the additional benefit that 90/180/270 degree rotations don't
introduce an off-by-one error, where the first row and col of the
transformed bitmap is transparent.

(At the moment it's not clear what introduces the unwanted translation,
but at least the direct Rotate() way resolves the visible end-user
problem, see the test.)

Change-Id: Ie1adbdb2221b086c19cc66f69308b6b7256fe29a
Reviewed-on: https://gerrit.libreoffice.org/80626
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins

diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index 53f2424f5dbe..e6a6b8f1c5f6 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -142,9 +143,22 @@ void VclOutdevTest::testDrawTransformedBitmapEx()
 // Also create a 16x16 bitmap.
 ScopedVclPtrInstance pVDev;
 Bitmap aBitmap(Size(16, 16), 24);
+{
+// Fill the top left quarter with black.
+BitmapScopedWriteAccess pWriteAccess(aBitmap);
+pWriteAccess->Erase(COL_WHITE);
+for (int i = 0; i < 8; ++i)
+{
+for (int j = 0; j < 8; ++j)
+{
+pWriteAccess->SetPixel(j, i, COL_BLACK);
+}
+}
+}
 BitmapEx aBitmapEx(aBitmap);
 basegfx::B2DHomMatrix aMatrix;
 aMatrix.scale(8, 8);
+// Rotate 90 degrees clockwise, so the black part goes to the top right.
 aMatrix.rotate(M_PI / 2);
 GDIMetaFile aMtf;
 aMtf.Record(pVDev.get());
@@ -162,6 +176,29 @@ void VclOutdevTest::testDrawTransformedBitmapEx()
 // - Actual  : 8x8
 // I.e. the bitmap before scaling was already scaled down, just because it 
was rotated.
 CPPUNIT_ASSERT_EQUAL(Size(16, 16), aTransformedSize);
+
+aBitmap = rBitmapEx.GetBitmap();
+Bitmap::ScopedReadAccess pAccess(aBitmap);
+for (int i = 0; i < 16; ++i)
+{
+for (int j = 0; j < 16; ++j)
+{
+BitmapColor aColor = pAccess->GetPixel(j, i);
+Color aExpected = i >= 8 && j < 8 ? COL_BLACK : COL_WHITE;
+std::stringstream ss;
+ss << "Color is expected to be ";
+ss << ((aExpected == COL_WHITE) ? "white" : "black");
+ss << ", is " << aColor.AsRGBHexString();
+ss << " (row " << j << ", col " << i << ")";
+// Without the accompanying fix in place, this test would have 
failed with:
+// - Expected: c[]
+// - Actual  : c[ff00]
+// - Color is expected to be black, is ff (row 0, col 8)
+// i.e. the top right quarter of the image was not fully black, 
there was a white first
+// row.
+CPPUNIT_ASSERT_EQUAL_MESSAGE(ss.str(), aExpected, Color(aColor));
+}
+}
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(VclOutdevTest);
diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx
index 2cbdb2fdb2b3..93c1f76aef1f 100644
--- a/vcl/source/outdev/bitmap.cxx
+++ b/vcl/source/outdev/bitmap.cxx
@@ -1285,10 +1285,24 @@ void OutputDevice::DrawTransformedBitmapEx(
 aFullTransform *= aTransform;
 }
 
-aTransformed = aTransformed.getTransformed(
-aFullTransform,
-aVisibleRange,
-fMaximumArea);
+if (bSheared)
+{
+aTransformed = aTransformed.getTransformed(
+aFullTransform,
+aVisibleRange,
+fMaximumArea);
+}
+else
+{
+// Just rotation, can do that directly.
+fFullRotate = fmod(fFullRotate * -1, F_2PI);
+if (fFullRotate < 0)
+{
+fFullRotate += F_2PI;
+}
+long nAngle10 = basegfx::fround(basegfx::rad2deg(fFullRotate) 
* 10);
+aTransformed.Rotate(nAngle10, COL_TRANSPARENT);
+}
 basegfx::B2DRange aTargetRange(0.0, 0.0, 1.0, 1.0);
 
 // get logic object target range
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailm

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

2019-10-08 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/outdev.cxx|   32 
 vcl/source/outdev/bitmap.cxx |   15 ++-
 2 files changed, 46 insertions(+), 1 deletion(-)

New commits:
commit dd4a67084853a030bf4b9f1f85d728620e0604a5
Author: Miklos Vajna 
AuthorDate: Tue Oct 8 09:16:27 2019 +0200
Commit: Miklos Vajna 
CommitDate: Tue Oct 8 14:31:32 2019 +0200

vcl: avoid downscale && upscale in DrawTransformedBitmapEx()

If we rotate a bitmap and put it to a metafile, we'll create a
MetaBmpExScaleAction. But just because we need to store a transformed
bitmap for rotation purposes, it doesn't mean we also need to scale it.

This helps in case later the metafile is upscaled and the downscaled
bitmap would look blurry.

Change-Id: I7d64a88af460e80dffde8052186888eddbb440fe
Reviewed-on: https://gerrit.libreoffice.org/80426
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins

diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index 0484e4a4143d..53f2424f5dbe 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -13,6 +13,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 
@@ -27,6 +29,7 @@ public:
 void testWindowBackgroundColor();
 void testGetReadableFontColorPrinter();
 void testGetReadableFontColorWindow();
+void testDrawTransformedBitmapEx();
 
 CPPUNIT_TEST_SUITE(VclOutdevTest);
 CPPUNIT_TEST(testVirtualDevice);
@@ -35,6 +38,7 @@ public:
 CPPUNIT_TEST(testWindowBackgroundColor);
 CPPUNIT_TEST(testGetReadableFontColorPrinter);
 CPPUNIT_TEST(testGetReadableFontColorWindow);
+CPPUNIT_TEST(testDrawTransformedBitmapEx);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -132,6 +136,34 @@ void VclOutdevTest::testUseAfterDispose()
 pVDev->GetViewTransformation();
 }
 
+void VclOutdevTest::testDrawTransformedBitmapEx()
+{
+// Create a virtual device, and connect a metafile to it.
+// Also create a 16x16 bitmap.
+ScopedVclPtrInstance pVDev;
+Bitmap aBitmap(Size(16, 16), 24);
+BitmapEx aBitmapEx(aBitmap);
+basegfx::B2DHomMatrix aMatrix;
+aMatrix.scale(8, 8);
+aMatrix.rotate(M_PI / 2);
+GDIMetaFile aMtf;
+aMtf.Record(pVDev.get());
+
+// Draw the rotated bitmap on the vdev.
+pVDev->DrawTransformedBitmapEx(aMatrix, aBitmapEx);
+CPPUNIT_ASSERT_EQUAL(static_cast(1), aMtf.GetActionSize());
+MetaAction* pAction = aMtf.GetAction(0);
+CPPUNIT_ASSERT_EQUAL(MetaActionType::BMPEXSCALE, pAction->GetType());
+auto pBitmapAction = static_cast(pAction);
+const BitmapEx& rBitmapEx = pBitmapAction->GetBitmapEx();
+Size aTransformedSize = rBitmapEx.GetSizePixel();
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 16x16
+// - Actual  : 8x8
+// I.e. the bitmap before scaling was already scaled down, just because it 
was rotated.
+CPPUNIT_ASSERT_EQUAL(Size(16, 16), aTransformedSize);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(VclOutdevTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx
index 7959b13f8f68..2cbdb2fdb2b3 100644
--- a/vcl/source/outdev/bitmap.cxx
+++ b/vcl/source/outdev/bitmap.cxx
@@ -1208,7 +1208,7 @@ void OutputDevice::DrawTransformedBitmapEx(
 const bool bInvert(RasterOp::Invert == meRasterOp);
 const bool bBitmapChangedColor(mnDrawMode & (DrawModeFlags::BlackBitmap | 
DrawModeFlags::WhiteBitmap | DrawModeFlags::GrayBitmap ));
 bool bDone(false);
-const basegfx::B2DHomMatrix aFullTransform(GetViewTransformation() * 
rTransformation);
+basegfx::B2DHomMatrix aFullTransform(GetViewTransformation() * 
rTransformation);
 const bool bTryDirectPaint(!bInvert && !bBitmapChangedColor && !bMetafile 
);
 
 if(bTryDirectPaint)
@@ -1272,6 +1272,19 @@ void OutputDevice::DrawTransformedBitmapEx(
 aTransformed = BitmapEx(aContent, aMaskBmp);
 }
 
+// Remove scaling from aFulltransform: we transform due to 
shearing or rotation, scaling
+// will happen according to aDestSize.
+basegfx::B2DVector aFullScale, aFullTranslate;
+double fFullRotate, fFullShearX;
+aFullTransform.decompose(aFullScale, aFullTranslate, fFullRotate, 
fFullShearX);
+if (aFullScale.getX() != 0 && aFullScale.getY() != 0)
+{
+basegfx::B2DHomMatrix aTransform = 
basegfx::utils::createScaleB2DHomMatrix(
+rOriginalSizePixel.getWidth() / aFullScale.getX(),
+rOriginalSizePixel.getHeight() / aFullScale.getY());
+aFullTransform *= aTransform;
+}
+
 aTransformed = aTransformed.getTransformed(
 aFullTransform,
 aVisibleRange,
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/li

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

2019-06-18 Thread Arkadiy Illarionov (via logerrit)
 vcl/qa/cppunit/canvasbitmaptest.cxx |   46 -
 vcl/source/components/fontident.cxx |6 --
 vcl/source/control/edit.cxx |   18 ++--
 vcl/source/filter/FilterConfigCache.cxx |4 -
 vcl/source/filter/FilterConfigItem.cxx  |   39 ++
 vcl/source/filter/graphicfilter.cxx |   32 +++---
 vcl/source/filter/jpeg/JpegWriter.cxx   |9 +---
 vcl/source/filter/png/pngwrite.cxx  |   15 +++
 vcl/source/filter/wmf/wmfexternal.cxx   |   10 ++--
 vcl/source/font/fontmetric.cxx  |   10 +---
 vcl/source/gdi/configsettings.cxx   |   14 ++
 vcl/source/gdi/print3.cxx   |   49 --
 vcl/source/graphic/UnoGraphic.cxx   |3 -
 vcl/source/graphic/UnoGraphicProvider.cxx   |   60 +++-
 vcl/source/helper/canvasbitmap.cxx  |   56 +-
 vcl/source/helper/canvastools.cxx   |   34 ++-
 vcl/source/helper/commandinfoprovider.cxx   |   47 +
 vcl/source/uitest/logger.cxx|7 ---
 vcl/source/uitest/uitest.cxx|6 --
 vcl/source/uitest/uno/uiobject_uno.cxx  |6 +-
 vcl/source/window/printdlg.cxx  |   15 +++
 vcl/unx/generic/dtrans/X11_selection.cxx|   21 +++--
 vcl/unx/generic/dtrans/X11_transferable.cxx |   11 ++---
 vcl/unx/gtk/a11y/atkaction.cxx  |   18 
 vcl/unx/gtk/a11y/atktable.cxx   |4 -
 vcl/unx/gtk/a11y/atktextattributes.cxx  |   14 ++
 vcl/unx/gtk/a11y/atkwrapper.cxx |   11 ++---
 vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx|   40 ++
 vcl/unx/gtk/salprn-gtk.cxx  |   15 +++
 vcl/unx/gtk3/gtk3gtkinst.cxx|4 -
 vcl/workben/vcldemo.cxx |8 +--
 31 files changed, 270 insertions(+), 362 deletions(-)

New commits:
commit 452a8e4abe0c416d664078baddff67c1561025ec
Author: Arkadiy Illarionov 
AuthorDate: Sat Jun 15 17:13:48 2019 +0300
Commit: Noel Grandin 
CommitDate: Tue Jun 18 09:43:08 2019 +0200

Simplify Sequence iterations in vcl

Use range-based loops or replace with comphelper or STL functions

Change-Id: If046738084c2d13cc1eaea6a03aaf60b63f62767
Reviewed-on: https://gerrit.libreoffice.org/74104
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/vcl/qa/cppunit/canvasbitmaptest.cxx 
b/vcl/qa/cppunit/canvasbitmaptest.cxx
index 070b8b6217a4..cf7a82c653ad 100644
--- a/vcl/qa/cppunit/canvasbitmaptest.cxx
+++ b/vcl/qa/cppunit/canvasbitmaptest.cxx
@@ -482,15 +482,13 @@ private:
 virtual uno::Sequence< rendering::RGBColor > SAL_CALL convertIntegerToRGB( 
const uno::Sequence< ::sal_Int8 >& deviceColor ) override
 {
 const uno::Sequence< rendering::ARGBColor > aTemp( 
convertIntegerToARGB(deviceColor) );
-const std::size_t nLen(aTemp.getLength());
-uno::Sequence< rendering::RGBColor > aRes( nLen );
-rendering::RGBColor* pOut = aRes.getArray();
-for( std::size_t i=0; i aRes( aTemp.getLength() );
+std::transform(aTemp.begin(), aTemp.end(), aRes.begin(),
+[](const rendering::ARGBColor& rColor) {
+return rendering::RGBColor(rColor.Red,
+   rColor.Green,
+   rColor.Blue);
+});
 
 return aRes;
 }
@@ -503,21 +501,18 @@ private:
0, static_cast(nLen%nBytesPerPixel));
 
 uno::Sequence< rendering::ARGBColor > aRes( nLen / nBytesPerPixel );
-rendering::ARGBColor* pOut( aRes.getArray() );
 
 if( getPalette().is() )
 {
-for( std::size_t i=0; i(nLen%nBytesPerPixel));
 
 uno::Sequence< rendering::ARGBColor > aRes( nLen / nBytesPerPixel );
-rendering::ARGBColor* pOut( aRes.getArray() );
 
 if( getPalette().is() )
 {
-for( std::size_t i=0; i& i_rArgs )
 if( !ImplGetSVData() )
 return; // VCL not initialized
 
-sal_uInt32 nArgs = i_rArgs.getLength();
-const Any* pArgs = i_rArgs.getConstArray();
 Sequence< sal_Int8 > aFontBuf;
-for( sal_uInt32 i = 0; i < nArgs; i++ )
+for( const auto& rArg : i_rArgs )
 {
-if( pArgs[i] >>= aFontBuf )
+if( rArg >>= aFontBuf )
 {
 m_aFont = Font::identifyFont( aFontBuf.getConstArray(), 
aFontBuf.getLength() );
 break;
diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx
index a1b1af252dc5..57d037546c5f 100644
--- a/vcl/source/control/edit.cxx
+++ b/vcl/source/control/edit.cxx
@@ -2924,18 +2924,12 @@ void Edit::dragEnter( const 
css::datatransfer::dnd::DropTargetDragEnterEvent& rD
 }
 // search for string data type
 const Sequence< css::datatransfer::DataFlavor >& rFlavors( 
rDTDE.SupportedDataFlavors )

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

2019-04-16 Thread Tomaž Vajngerl (via logerrit)
 vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx |   69 +++
 vcl/source/outdev/pixel.cxx  |   29 ++---
 2 files changed, 88 insertions(+), 10 deletions(-)

New commits:
commit ba9e513ee8305c668c94b6ba59e26da278581652
Author: Tomaž Vajngerl 
AuthorDate: Tue Apr 16 13:25:05 2019 +0900
Commit: Tomaž Vajngerl 
CommitDate: Tue Apr 16 11:14:18 2019 +0200

Test an alpha VirtualDevice and fix GetPixel and DrawPixel

This adds an test for a VirtualDevice with an alpha channel,
which checks that getting a BitmapEx from the alpha VirtualDevice
is has a alpha channel properly set.

Test that using GetPixel and DrawPixel properly handle an alpha
based Color, which they didn't, so this also includes the fix for
thouse 2 methods.

Change-Id: I419b8e0f66ab5f8266c6129e501ed75ef517fd44
Reviewed-on: https://gerrit.libreoffice.org/70805
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx 
b/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx
index 5fc6c5b7b53c..efb3dcfbcb2e 100644
--- a/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx
+++ b/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx
@@ -42,12 +42,14 @@ public:
 void testTdf104141();
 void testTdf113918();
 void testDrawAlphaBitmapEx();
+void testAlphaVirtualDevice();
 void testTdf116888();
 
 CPPUNIT_TEST_SUITE(BitmapRenderTest);
 CPPUNIT_TEST(testTdf104141);
 CPPUNIT_TEST(testTdf113918);
 CPPUNIT_TEST(testDrawAlphaBitmapEx);
+CPPUNIT_TEST(testAlphaVirtualDevice);
 CPPUNIT_TEST(testTdf116888);
 
 CPPUNIT_TEST_SUITE_END();
@@ -150,6 +152,73 @@ void BitmapRenderTest::testDrawAlphaBitmapEx()
 #endif
 }
 
+void BitmapRenderTest::testAlphaVirtualDevice()
+{
+// Create an alpha virtual device
+ScopedVclPtr 
pAlphaVirtualDevice(VclPtr::Create(
+*Application::GetDefaultDevice(), DeviceFormat::DEFAULT, 
DeviceFormat::DEFAULT));
+
+// Set it up
+pAlphaVirtualDevice->SetOutputSizePixel(Size(4, 4));
+pAlphaVirtualDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
+pAlphaVirtualDevice->Erase();
+
+// Get a BitmapEx from the VirDev -> Colors should have alpha
+BitmapEx aBitmap = pAlphaVirtualDevice->GetBitmapEx(Point(), Size(4, 4));
+CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Width());
+CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Height());
+Color aColor = aBitmap.GetPixelColor(1, 1);
+CPPUNIT_ASSERT_EQUAL(Color(0xff, 0xff, 0xff, 0xff), aColor);
+
+// Draw an opaque pixel to the VirDev
+pAlphaVirtualDevice->DrawPixel(Point(1, 1), Color(0x00, 0x22, 0xff, 0x55));
+
+// Read back the opaque pixel
+#ifdef MACOSX
+// Oh no.. what we input is not the same as what we get out!
+CPPUNIT_ASSERT_EQUAL(Color(0x00, 0x2C, 0xff, 0x44), 
pAlphaVirtualDevice->GetPixel(Point(1, 1)));
+#else
+CPPUNIT_ASSERT_EQUAL(Color(0x00, 0x22, 0xff, 0x55), 
pAlphaVirtualDevice->GetPixel(Point(1, 1)));
+#endif
+
+// Read back the BitmapEx and check the opaque pixel
+aBitmap = pAlphaVirtualDevice->GetBitmapEx(Point(), Size(4, 4));
+CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Width());
+CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Height());
+
+aColor = aBitmap.GetPixelColor(1, 1);
+#ifdef MACOSX
+// Oh no.. what we input is not the same as what we get out!
+CPPUNIT_ASSERT_EQUAL(Color(0x00, 0x2C, 0xff, 0x44), aColor);
+#else
+CPPUNIT_ASSERT_EQUAL(Color(0x00, 0x22, 0xff, 0x55), aColor);
+#endif
+
+// Draw an semi-transparent pixel
+pAlphaVirtualDevice->DrawPixel(Point(0, 0), Color(0x44, 0x22, 0xff, 0x55));
+
+// Read back the semi-transparent pixel
+#ifdef MACOSX
+// Oh no.. what we input is not the same as what we get out!
+CPPUNIT_ASSERT_EQUAL(Color(0x34, 0x2C, 0xFF, 0x44), 
pAlphaVirtualDevice->GetPixel(Point(0, 0)));
+#else
+CPPUNIT_ASSERT_EQUAL(Color(0x44, 0x22, 0xFF, 0x55), 
pAlphaVirtualDevice->GetPixel(Point(0, 0)));
+#endif
+
+// Read back the BitmapEx and check the semi-transparent pixel
+aBitmap = pAlphaVirtualDevice->GetBitmapEx(Point(), Size(4, 4));
+CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Width());
+CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Height());
+
+aColor = aBitmap.GetPixelColor(0, 0);
+#ifdef MACOSX
+// Oh no.. what we input is not the same as what we get out!
+CPPUNIT_ASSERT_EQUAL(Color(0x34, 0x2C, 0xFF, 0x44), aColor);
+#else
+CPPUNIT_ASSERT_EQUAL(Color(0x44, 0x22, 0xFF, 0x55), aColor);
+#endif
+}
+
 void BitmapRenderTest::testTdf116888()
 {
 // The image is a 8bit image with a non-grayscale palette. In OpenGL mode
diff --git a/vcl/source/outdev/pixel.cxx b/vcl/source/outdev/pixel.cxx
index b00835fe96db..ecde4564f4ac 100644
--- a/vcl/source/outdev/pixel.cxx
+++ b/vcl/source/outdev/pixel.cxx
@@ -32,20 +32,26 @@
 #include 
 #include 
 
-Color OutputDevice::GetPi

  1   2   >