/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// Parse the export result with pdfium.
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
// Get the first page
std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(0);
CPPUNIT_ASSERT(pPdfPage);
// Selection was not taken into account during export into PDF void ScPDFExportTest::testExportRange_Tdf120161()
{ // create test document
loadFromURL(u"private:factory/scalc"_ustr);
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
uno::Reference<sheet::XSpreadsheetDocument> xDoc(xModel, uno::UNO_QUERY_THROW);
uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW);
uno::Reference<container::XIndexAccess> xIndex(xSheets, uno::UNO_QUERY_THROW);
xSheets->insertNewByName(u"First Sheet"_ustr, 0);
uno::Reference<sheet::XSpreadsheet> rSheet(xIndex->getByIndex(0), UNO_QUERY_THROW);
// 2. Setup data
{
SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent);
CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
ScDocShellRef xDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
CPPUNIT_ASSERT(xDocSh);
// put some content into the first row with default font
ScDocument& rDoc = xDocSh->GetDocument(); for (unsignedint r = 0; r < 1; ++r) for (unsignedint c = 0; c < 14; ++c)
rDoc.SetValue(ScAddress(c, r, 0), (r + 1) * (c + 1));
// set "Text" to H1 cell with "DejaVuSans" font
ScFieldEditEngine& rEE = rDoc.GetEditEngine();
rEE.Clear();
rEE.SetTextCurrentDefaults(u"Text"_ustr);
setFont(rEE, 0, 4, u"DejaVuSans"_ustr); // set font for first 4 chars
rDoc.SetEditText(ScAddress(7, 0, 0), rEE.CreateTextObject());
}
// 2. Setup data
{
SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent);
CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
ScDocShellRef xDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
CPPUNIT_ASSERT(xDocSh);
// put some content into the table
ScDocument& rDoc = xDocSh->GetDocument(); for (unsignedint r = 0; r < 80; ++r) for (unsignedint c = 0; c < 12; ++c)
rDoc.SetValue(ScAddress(c, r, 0), (r + 1) * (c + 1));
}
// The document has one page.
std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aPages.size());
auto nArtifact(0); auto nLine(0); while (true)
{
++nLine; autoconst pLine = ::std::find(pStart, pEnd, '\n'); if (pLine == pEnd)
{ break;
}
std::string_view const line(pStart, pLine - pStart);
pStart = pLine + 1; if (!line.empty() && line[0] != '%')
{
::std::cerr << nLine << ": " << line << "\n "; if (o3tl::starts_with(line, "/Artifact BMC"))
nArtifact++;
}
}
// Without the fix in place, this test would have failed with // - Expected: 5 (Artifact: Header, Footer, Rectangle, DetectiveArrow, ValidationCircle) // - Actual : 2 (Artifact: Header, Footer)
CPPUNIT_ASSERT_EQUAL(static_cast<decltype(nArtifact)>(5), nArtifact);
}
// The document has one page.
std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aPages.size());
auto nArtifact(0); auto nLine(0); while (true)
{
++nLine; autoconst pLine = ::std::find(pStart, pEnd, '\n'); if (pLine == pEnd)
{ break;
}
std::string_view const line(pStart, pLine - pStart);
pStart = pLine + 1; if (!line.empty() && line[0] != '%')
{
::std::cerr << nLine << ": " << line << "\n "; if (o3tl::starts_with(line, "/Artifact BMC"))
nArtifact++;
}
}
// Without the fix in place, this test would have failed with // - Expected: 3 (Artifact: Header, Footer, TextBox) // - Actual : 2 (Artifact: Header, Footer)
CPPUNIT_ASSERT_EQUAL(static_cast<decltype(nArtifact)>(3), nArtifact);
}
// The document has one page.
std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aPages.size());
// The document has one page.
std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aPages.size());
// A1:A2
ScRange range1(0, 0, 0, 0, 1, 0);
exportToPDF(xModel, range1); // Parse the export result with pdfium.
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
// Get the first page
std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(/*nIndex=*/0);
CPPUNIT_ASSERT(pPdfPage);
std::unique_ptr<vcl::pdf::PDFiumTextPage> pTextPage = pPdfPage->getTextPage();
int nPageObjectCount = pPdfPage->getObjectCount();
CPPUNIT_ASSERT_EQUAL(2, nPageObjectCount);
// Without the fix in place, this test would have failed with // - Expected: Dies ist viel zu viel Text // - Actual : Dies ist vie
std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject1 = pPdfPage->getObject(0);
OUString sText1 = pPageObject1->getText(pTextPage);
CPPUNIT_ASSERT_EQUAL(u"Dies ist viel zu viel Text"_ustr, sText1);
// and it would also have failed with // - Expected: 2021-11-17 // - Actual : ###
std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject2 = pPdfPage->getObject(1);
OUString sText2 = pPageObject2->getText(pTextPage);
CPPUNIT_ASSERT_EQUAL(u"2021-11-17"_ustr, sText2);
}
// Parse the export result with pdfium.
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
// Get the first page
std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(/*nIndex=*/0);
CPPUNIT_ASSERT(pPdfPage);
std::unique_ptr<vcl::pdf::PDFiumTextPage> pTextPage = pPdfPage->getTextPage();
int nPageObjectCount = pPdfPage->getObjectCount();
CPPUNIT_ASSERT_EQUAL(5, nPageObjectCount);
// A1
ScRange range1(0, 0, 0, 0, 0, 0);
exportToPDF(xModel, range1); // Parse the export result with pdfium.
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
// Get the first page
std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(/*nIndex=*/0);
CPPUNIT_ASSERT(pPdfPage);
std::unique_ptr<vcl::pdf::PDFiumTextPage> pTextPage = pPdfPage->getTextPage();
int nChars = pTextPage->countChars();
std::vector<sal_uInt32> aChars(nChars); for (int i = 0; i < nChars; i++)
aChars[i] = pTextPage->getUnicode(i);
OUString aActualText(aChars.data(), aChars.size());
// Without the fix in place, this test would have failed with // - Expected: Blah blah (blah, blah) // - Actual : Blah blah
CPPUNIT_ASSERT_EQUAL(u"Blah blah (blah, blah)"_ustr, aActualText);
}
// C3:D3
ScRange range1(2, 2, 0, 3, 2, 0);
exportToPDF(xModel, range1); // Parse the export result with pdfium.
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
// Get the first page
std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(/*nIndex=*/0);
CPPUNIT_ASSERT(pPdfPage);
std::unique_ptr<vcl::pdf::PDFiumTextPage> pTextPage = pPdfPage->getTextPage();
int nChars = pTextPage->countChars();
std::vector<sal_uInt32> aChars(nChars); for (int i = 0; i < nChars; i++)
aChars[i] = pTextPage->getUnicode(i);
OUString aActualText(aChars.data(), aChars.size());
// Without the fix in place, this test would have failed with // - Expected: 11.00 11.00 // - Actual : 11.00 ###
CPPUNIT_ASSERT_EQUAL(u" 11.00 11.00 "_ustr, aActualText);
}
// just needs to not crash on export to pdf void ScPDFExportTest::testForcepoint97()
{
loadFromFile(u"forcepoint97.xlsx");
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.