/* -*- 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/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
constchar* const sText = " \n \nThis is a testtext\nNew paragraph,\nnew line\n" "Hyperlink, this is\n?\nThis is more text\noutline mode\n?\nNew paragraph\n";
OString aTmp;
m_aTextOut.makeStringAndClear().convertToString( &aTmp,
RTL_TEXTENCODING_ASCII_US,
OUSTRING_TO_OSTRING_CVTFLAGS );
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Imported text is \"This is a testtext New paragraph, newline" " Hyperlink, this is * This is more text outline mode * New paragraph\"",
aTmp, OString(sText) );
CPPUNIT_ASSERT_MESSAGE( "red circle seen in input", m_bRedCircleSeen );
CPPUNIT_ASSERT_MESSAGE( "green stroke seen in input", m_bGreenStrokeSeen );
CPPUNIT_ASSERT_MESSAGE( "dashed line seen in input", m_bDashedLineSeen );
CPPUNIT_ASSERT_MESSAGE( "image seen in input", m_bImageSeen );
}
if( rContext.DashArray.empty() )
{
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is green", 1.0, rContext.LineColor.Alpha, 0.00000001);
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is green", 0.0, rContext.LineColor.Blue, 0.00000001);
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is green", 1.0, rContext.LineColor.Green, 0.00000001);
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is green", 0.0, rContext.LineColor.Red, 0.00000001);
CPPUNIT_ASSERT_MESSAGE( "Line width is 0",
rtl::math::approxEqual(rContext.LineWidth, 28.3) );
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 1.0, rContext.LineColor.Alpha, 0.00000001);
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Blue, 0.00000001);
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Green, 0.00000001);
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Red, 0.00000001);
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line width is 0",
0, rContext.LineWidth, 0.0000001 );
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 1.0, rContext.LineColor.Alpha, 0.00000001);
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Blue, 0.00000001);
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Green, 0.00000001);
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Red, 0.00000001);
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Blend mode is normal",
rendering::BlendMode::NORMAL, rContext.BlendMode );
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Flatness is 10",
10, rContext.Flatness, 0.00000001 );
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font id is 0",
sal_Int32(0), rContext.FontId );
}
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 1.0, rContext.LineColor.Alpha, 0.00000001);
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Blue, 0.00000001);
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Green, 0.00000001);
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Red, 0.00000001);
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Blend mode is normal",
rendering::BlendMode::NORMAL, rContext.BlendMode );
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Flatness is 0",
1, rContext.Flatness, 0.00000001 );
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font id is 0",
sal_Int32(0), rContext.FontId );
if( aCurClip.count() ) // #i92985# adapted API from (..., false, false) to (..., true, false)
aNewClip = basegfx::utils::clipPolyPolygonOnPolyPolygon( aCurClip, aNewClip, true, false );
getCurrentContext().Clip = aNewClip;
}
virtualvoid intersectClipToStroke(const uno::Reference<rendering::XPolyPolygon2D>& /* rPath */) override
{ // Not copying the contents of this, unlike the other clip functions above // it's too complex to copy in, and I don't think the clip is actually used in the test
}
class PDFITest : public test::BootstrapFixture, public XmlTestTools
{ public: void testXPDFParser()
{ #if HAVE_FEATURE_POPPLER auto pSink = std::make_shared<TestSink>();
CPPUNIT_ASSERT(
pdfi::xpdf_ImportFromFile(
m_directories.getURLFromSrc(u"/sdext/source/pdfimport/test/testinput.pdf"),
pSink,
uno::Reference< task::XInteractionHandler >(),
OUString(),
getComponentContext(), u""_ustr ) );
pSink->check(); #endif
}
void testTdf55425_decrypt()
{ #if HAVE_FEATURE_POPPLER // This tries to load an encrypted file // It was created with LO set to PDF2.0 and with a password set auto pSink = std::make_shared<TestSink>();
CPPUNIT_ASSERT(
pdfi::xpdf_ImportFromFile(
m_directories.getURLFromSrc(u"/sdext/qa/unit/data/tdf55425_crypt-pdf20-passa.pdf"),
pSink,
uno::Reference< task::XInteractionHandler >(),
u"a"_ustr, // Critically secure test password
getComponentContext(), u""_ustr)); #endif
}
OString aOutput;
CPPUNIT_ASSERT_MESSAGE("Exporting to ODF",
xAdaptor->odfConvert(m_directories.getURLFromSrc(u"/sdext/source/pdfimport/test/testTdf105536.pdf"), new OutputWrapString(aOutput),
nullptr)); // This ensures that the imported image arrives properly flipped
CPPUNIT_ASSERT(aOutput.indexOf("draw:transform=\"matrix(-21488.4 0 0 -27978.1 21488.4 27978.1)\"") != -1); #endif
}
void testTdf141709_chinesechar()
{ // this test crashes on the windows jenkins boxes, but no-one can catch it locally #if HAVE_FEATURE_POPPLER
rtl::Reference<pdfi::PDFIRawAdaptor> xAdaptor(new pdfi::PDFIRawAdaptor(OUString(), getComponentContext()));
xAdaptor->setTreeVisitorFactory(createDrawTreeVisitorFactory());
OString aOutput;
CPPUNIT_ASSERT_MESSAGE("Exporting to ODF",
xAdaptor->odfConvert(m_directories.getURLFromSrc(u"/sdext/qa/unit/data/testTdf141709_chinesechar.pdf"), new OutputWrapString(aOutput),
nullptr));
xmlDocUniquePtr pXmlDoc(xmlParseDoc(reinterpret_cast<xmlChar const *>(aOutput.getStr()))); // This ensures that the imported text contains all of the characters
OString xpath = "//draw:frame[@draw:z-index='3'][1]/draw:text-box/text:p/text:span[1]"_ostr;
OUString sContent = getXPathContent(pXmlDoc, xpath).replaceAll("\n", "");
CPPUNIT_ASSERT_EQUAL_MESSAGE(aOutput.getStr(), u"敏捷的狐狸跨过慵懒的"_ustr, sContent);
xpath = "//draw:frame[@draw:z-index='4'][1]/draw:text-box/text:p/text:span[1]"_ostr;
sContent = getXPathContent(pXmlDoc, xpath).replaceAll("\n", "");
CPPUNIT_ASSERT_EQUAL_MESSAGE(aOutput.getStr(), u"狗。"_ustr, sContent); #endif
}
OString aOutput;
CPPUNIT_ASSERT_MESSAGE("Converting PDF to ODF XML",
xAdaptor->odfConvert( m_directories.getURLFromSrc(
u"/sdext/qa/unit/data/tdf78427-testFontFeatures.pdf"), new OutputWrapString(aOutput),
nullptr )); // Un-comment the following debug line to see the content of generated XML content in // workdir/CppunitTest/sdext_pdfimport.test.log after running "make CppunitTest_sdext_pdfimport". //std::cout << aOutput << std::endl;
xmlDocUniquePtr pXmlDoc(xmlParseDoc(reinterpret_cast<xmlChar const *>(aOutput.getStr()))); //CPPUNIT_ASSERT(pXmlDoc);
/* Test for the 1st paragraph */
OUString styleName = getXPath(pXmlDoc, "//draw:frame[1]//text:span[1]", "style-name");
OString xpath = "//office:automatic-styles/style:style[@style:name=\"" +
OUStringToOString(styleName, RTL_TEXTENCODING_UTF8) + "\"]/style:text-properties"; // the font-weight and font-style should be normal
assertXPath(pXmlDoc, xpath, "font-weight", u"normal");
assertXPathNoAttribute(pXmlDoc, xpath, "font-style");
/* Test for the 2nd paragraph */
styleName = getXPath(pXmlDoc, "//draw:frame[2]//text:span[1]", "style-name");
xpath = "//office:automatic-styles/style:style[@style:name=\"" +
OUStringToOString(styleName, RTL_TEXTENCODING_UTF8) + "\"]/style:text-properties"; // there should be a font-weight="bold", but no font-style italic
assertXPath(pXmlDoc, xpath, "font-weight", u"bold");
assertXPathNoAttribute(pXmlDoc, xpath, "font-style");
/* Test for the 3rd paragraph */
styleName = getXPath(pXmlDoc, "//draw:frame[3]//text:span[1]", "style-name");
xpath = "//office:automatic-styles/style:style[@style:name=\"" +
OUStringToOString(styleName, RTL_TEXTENCODING_UTF8) + "\"]/style:text-properties"; // there should be a font-style="italic", but no font-weight bold
assertXPath(pXmlDoc, xpath, "font-weight", u"normal");
assertXPath(pXmlDoc, xpath, "font-style", u"italic");
/* Test for the 4th paragraph */
styleName = getXPath(pXmlDoc, "//draw:frame[4]//text:span[1]", "style-name");
xpath = "//office:automatic-styles/style:style[@style:name=\"" +
OUStringToOString(styleName, RTL_TEXTENCODING_UTF8) + "\"]/style:text-properties"; // there should be both font-style="italic" and font-weight="bold"
assertXPath(pXmlDoc, xpath, "font-weight", u"bold");
assertXPath(pXmlDoc, xpath, "font-style", u"italic");
/* Test for the 5th paragraph */
styleName = getXPath(pXmlDoc, "//draw:frame[5]//text:span[1]", "style-name");
xpath = "//office:automatic-styles/style:style[@style:name=\"" +
OUStringToOString(styleName, RTL_TEXTENCODING_UTF8) + "\"]/style:text-properties"; // the font should be Arial and font-weight="bold", no font-style
assertXPath(pXmlDoc, xpath, "font-family", u"Arial");
assertXPath(pXmlDoc, xpath, "font-weight", u"bold");
assertXPathNoAttribute(pXmlDoc, xpath, "font-style");
/* Test for the 6th paragraph */
styleName = getXPath(pXmlDoc, "//draw:frame[6]//text:span[1]", "style-name");
xpath = "//office:automatic-styles/style:style[@style:name=\"" +
OUStringToOString(styleName, RTL_TEXTENCODING_UTF8) + "\"]/style:text-properties"; // the font should be Arial without font-weight and font-style
assertXPath(pXmlDoc, xpath, "font-family", u"Arial");
assertXPath(pXmlDoc, xpath, "font-weight", u"normal");
assertXPathNoAttribute(pXmlDoc, xpath, "font-style");
/* Test for the 7th paragraph */
styleName = getXPath(pXmlDoc, "//draw:frame[7]//text:span[1]", "style-name");
xpath = "//office:automatic-styles/style:style[@style:name=\"" +
OUStringToOString(styleName, RTL_TEXTENCODING_UTF8) + "\"]/style:text-properties"; // the font should be SimSun without font-weight and font-style
assertXPath(pXmlDoc, xpath, "font-family", u"SimSun"); // TODO: tdf#143095 use localized font name rather than PS name
assertXPath(pXmlDoc, xpath, "font-weight", u"normal");
assertXPathNoAttribute(pXmlDoc, xpath, "font-style");
/* Test for the 8th paragraph */
styleName = getXPath(pXmlDoc, "//draw:frame[8]//text:span[1]", "style-name");
xpath = "//office:automatic-styles/style:style[@style:name=\"" +
OUStringToOString(styleName, RTL_TEXTENCODING_UTF8) + "\"]/style:text-properties"; // the font should be SimSun and font-weight="bold", no font-style italic
assertXPath(pXmlDoc, xpath, "font-family", u"SimSun");
assertXPath(pXmlDoc, xpath, "font-weight", u"bold");
assertXPathNoAttribute(pXmlDoc, xpath, "font-style");
/* Test for the 9th paragraph */
styleName = getXPath(pXmlDoc, "//draw:frame[9]//text:span[1]", "style-name");
xpath = "//office:automatic-styles/style:style[@style:name=\"" +
OUStringToOString(styleName, RTL_TEXTENCODING_UTF8) + "\"]/style:text-properties"; // the font should be SimSun, font-weight should be "normal", font-style="italic"
assertXPath(pXmlDoc, xpath, "font-family", u"SimSun");
assertXPath(pXmlDoc, xpath, "font-weight", u"normal"); // FIXME and remove the below comment: // the chinese chars are shown in pdf as faux italic (fake italic). It is currencly imported wrongly as normal font style. // See tdf#78427 for how the faux bold problem was handled. Faux italic may be handled using the transformation pattern. // assertXPath(pXmlDoc, xpath, "font-style", "italic");
/* Test for the 10th paragraph */
styleName = getXPath(pXmlDoc, "//draw:frame[10]//text:span[1]", "style-name");
xpath = "//office:automatic-styles/style:style[@style:name=\"" +
OUStringToOString(styleName, RTL_TEXTENCODING_UTF8) + "\"]/style:text-properties"; // the font should be SimSun font-weight="bold" and font-style="italic"
assertXPath(pXmlDoc, xpath, "font-family", u"SimSun");
assertXPath(pXmlDoc, xpath, "font-weight", u"bold"); // FIXME: faux italic, see above // assertXPath(pXmlDoc, xpath, "font-style", "italic");
/* Test for the 11th paragraph */
styleName = getXPath(pXmlDoc, "//draw:frame[11]//text:span[1]", "style-name");
xpath = "//office:automatic-styles/style:style[@style:name=\"" +
OUStringToOString(styleName, RTL_TEXTENCODING_UTF8) + "\"]/style:text-properties"; // the font should be SimSun and there should be style:text-outline="true" // (i.e., the real "outline" font rather than faux bold / fake bold)
assertXPath(pXmlDoc, xpath, "font-family", u"SimSun");
assertXPath(pXmlDoc, xpath, "font-weight", u"normal");
assertXPathNoAttribute(pXmlDoc, xpath, "font-style");
assertXPath(pXmlDoc, xpath, "text-outline", u"true"); #endif
}
void testTdf78427_FontWeight_MyraidProSemibold() // Related to attachment 155937.
{ #if HAVE_FEATURE_POPPLER
rtl::Reference<pdfi::PDFIRawAdaptor> xAdaptor(new pdfi::PDFIRawAdaptor(OUString(), getComponentContext()));
xAdaptor->setTreeVisitorFactory(createDrawTreeVisitorFactory());
OString aOutput;
CPPUNIT_ASSERT_MESSAGE("Converting PDF to ODF XML",
xAdaptor->odfConvert( m_directories.getURLFromSrc(
u"/sdext/qa/unit/data/tdf78427-MyraidPro-Semibold-Light.pdf"), new OutputWrapString(aOutput),
nullptr )); //std::cout << aOutput << std::endl;
// The for the 1st frame */
OUString styleName = getXPath(pXmlDoc, "//draw:frame[1]//text:span[1]", "style-name");
OString xpath = "//office:automatic-styles/style:style[@style:name=\"" +
OUStringToOString(styleName, RTL_TEXTENCODING_UTF8) + "\"]/style:text-properties"; // the font-weight and font-style should be 600 (Semibold)
assertXPath(pXmlDoc, xpath, "font-weight", u"600");
// The for the 2nd frame */
styleName = getXPath(pXmlDoc, "//draw:frame[2]//text:span[1]", "style-name");
xpath = "//office:automatic-styles/style:style[@style:name=\"" +
OUStringToOString(styleName, RTL_TEXTENCODING_UTF8) + "\"]/style:text-properties"; // the font-weight and font-style should be 300 (Light)
assertXPath(pXmlDoc, xpath, "font-weight", u"300"); #endif
}
OString aOutput;
CPPUNIT_ASSERT_MESSAGE("Converting PDF to ODF XML",
xAdaptor->odfConvert( m_directories.getURLFromSrc(u"/sdext/qa/unit/data/testTdf143959.pdf"), new OutputWrapString(aOutput),
nullptr ));
OString aOutput;
CPPUNIT_ASSERT_MESSAGE("Converting PDF to ODF XML",
xAdaptor->odfConvert(m_directories.getURLFromSrc(u"/sdext/qa/unit/data/tdf104597_textrun.pdf"), new OutputWrapString(aOutput),
nullptr));
// Test for ٱلسََّل . It appears in the 3rd frame, i.e. after the امُ عَلَيَْك which is in the 2nd frame (from left to right) // thus these two frames together appear as ٱلسََّل امُ عَلَيْكَ in Draw. // FIXME: Should be ٱلسَّلَامُ عَلَيْكَ (i.e. the two text frames should be merged into one so that the ل and the ا will show as لَا rather than ل ا)
xpath = "string(//draw:frame[@draw:transform='matrix(917.222222222222 0 0 917.222222222222 17420.1666666667 2159.23861112778)']/draw:text-box/text:p/text:span)"_ostr;
sContent = getXPathContent(pXmlDoc, xpath);
CPPUNIT_ASSERT_EQUAL_MESSAGE(aOutput.getStr(), u"ٱلسََّل"_ustr, sContent.replaceAll("\n\n", " ").replaceAll("\n", ""));
/* Test for Chinese characters */ // Use last() instead of matrix below, because the matrix may be different on different OS due to fallback of Chinese fonts.
xpath = "string(//draw:frame[last()]/draw:text-box/text:p/text:span)"_ostr;
sContent = getXPathContent(pXmlDoc, xpath);
CPPUNIT_ASSERT_EQUAL_MESSAGE(aOutput.getStr(), u"中文测试,中文"_ustr, sContent.replaceAll("\n\n", " ").replaceAll("\n", ""));
// Test pdf text run in the Writer PDF import filter
xAdaptor->setTreeVisitorFactory(createWriterTreeVisitorFactory());
OString aOutput2;
xAdaptor->odfConvert(m_directories.getURLFromSrc(u"/sdext/qa/unit/data/tdf104597_textrun.pdf"), new OutputWrapString(aOutput2),
nullptr);
xmlDocUniquePtr pXmlDoc2(xmlParseDoc(reinterpret_cast<xmlChar const *>(aOutput2.getStr())));
xpath = "string(//draw:frame[@draw:z-index='3'][1]/draw:text-box/text:p/text:span)"_ostr;
sContent = getXPathContent(pXmlDoc2, xpath).replaceAll("\n\n", " ").replaceAll("\n", "");
CPPUNIT_ASSERT_EQUAL_MESSAGE(aOutput2.getStr(), u"ٱلسََّل"_ustr, sContent);
xpath = "string(//draw:frame[@draw:z-index='2'][1]/draw:text-box/text:p/text:span)"_ostr;
sContent = getXPathContent(pXmlDoc2, xpath).replaceAll("\n\n", " ").replaceAll("\n", "");
CPPUNIT_ASSERT_EQUAL(u"امُ عَلَيَْك"_ustr, sContent);
xpath = "string(//draw:frame[last()]/draw:text-box/text:p/text:span)"_ostr;
sContent = getXPathContent(pXmlDoc2, xpath).replaceAll("\n\n", " ").replaceAll("\n", "");
CPPUNIT_ASSERT_EQUAL_MESSAGE(aOutput2.getStr(), u"中文测试,中文"_ustr, sContent); #endif
}
OString aOutput;
xAdaptor->odfConvert(m_directories.getURLFromSrc(u"/sdext/qa/unit/data/testSpace.pdf"), new OutputWrapString(aOutput),
nullptr);
xmlDocUniquePtr pXmlDoc(xmlParseDoc(reinterpret_cast<xmlChar const *>(aOutput.getStr())));
// Space test: there are 10 spaces, each space is expressed as a <text:s text:c="1" ...>, // thus the 10th text:s should exist and the attribute "text:c" should be "1".
OString xpath = "//draw:frame[@draw:z-index='1'][1]/draw:text-box/text:p/text:span/text:s[10]"_ostr;
OUString sContent = getXPath(pXmlDoc, xpath, "c");
CPPUNIT_ASSERT_EQUAL_MESSAGE(aOutput.getStr(), u"1"_ustr, sContent);
// Tab test: there are 10 tabs. Text before and after the tabs are shown in different draw frames. // With the Liberation Serif font, the horizontal position of the first frame is 20.03mm and the // second frame is 94.12mm.
xpath = "//draw:frame[@draw:z-index='2'][1]"_ostr;
sContent = getXPath(pXmlDoc, xpath, "transform");
CPPUNIT_ASSERT_EQUAL_MESSAGE(aOutput.getStr(), u"translate( 20.03mm 25.05mm )"_ustr, sContent);
xpath = "//draw:frame[@draw:z-index='3'][1]"_ostr;
sContent = getXPath(pXmlDoc, xpath, "transform");
CPPUNIT_ASSERT_EQUAL_MESSAGE(aOutput.getStr(), u"translate( 94.12mm 25.05mm )"_ustr, sContent);
// Non-breaking space test: there are 10 NBSpaces, which are treated as the same as normal space in PDF, // thus each is expressed as a <text:s text:c="1" ...>. // The 10th text:s should exist and the attribute "text:c" should be "1".
xpath = "//draw:frame[@draw:z-index='4'][1]/draw:text-box/text:p/text:span/text:s[10]"_ostr;
sContent = getXPath(pXmlDoc, xpath, "c");
CPPUNIT_ASSERT_EQUAL_MESSAGE(aOutput.getStr(), u"1"_ustr, sContent); #endif
}
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.