1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <swmodeltestbase.hxx>
12 #include <com/sun/star/awt/FontWeight.hpp>
13 #include <com/sun/star/graphic/GraphicType.hpp>
14 #include <com/sun/star/style/ParagraphAdjust.hpp>
15 #include <com/sun/star/style/TabStop.hpp>
16 #include <com/sun/star/text/TableColumnSeparator.hpp>
17 #include <com/sun/star/text/XFootnotesSupplier.hpp>
18 #include <com/sun/star/text/XPageCursor.hpp>
19 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
20 #include <com/sun/star/text/XTextTablesSupplier.hpp>
21 #include <com/sun/star/text/XTextFramesSupplier.hpp>
22 #include <com/sun/star/text/XTextTable.hpp>
23 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
24 #include <com/sun/star/text/WritingMode2.hpp>
25 #include <com/sun/star/text/XTextContentAppend.hpp>
26 #include <com/sun/star/text/XTextDocument.hpp>
27 #include <com/sun/star/awt/FontSlant.hpp>
28 #include <com/sun/star/awt/FontUnderline.hpp>
30 #include <tools/UnitConversion.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/settings.hxx>
33 #include <comphelper/sequenceashashmap.hxx>
34 #include <i18nlangtag/languagetag.hxx>
35 #include <comphelper/scopeguard.hxx>
39 class Test
: public SwModelTestBase
43 : SwModelTestBase("/sw/qa/extras/rtfexport/data/", "Rich Text Format")
48 DECLARE_RTFEXPORT_TEST(testFdo85889pc
, "fdo85889-pc.rtf")
50 uno::Reference
<text::XTextRange
> xTextRange
= getRun(getParagraph(1), 1);
52 CPPUNIT_ASSERT_EQUAL(OUString(u
"\u00B1\u2265\u2264"), xTextRange
->getString());
55 DECLARE_RTFEXPORT_TEST(testFdo85889pca
, "fdo85889-pca.rtf")
57 uno::Reference
<text::XTextRange
> xTextRange
= getRun(getParagraph(1), 1);
59 CPPUNIT_ASSERT_EQUAL(OUString(u
"\u00B1\u2017\u00BE"), xTextRange
->getString());
62 DECLARE_RTFEXPORT_TEST(testFdo85889mac
, "fdo85889-mac.rtf")
64 uno::Reference
<text::XTextRange
> xTextRange
= getRun(getParagraph(1), 1);
66 CPPUNIT_ASSERT_EQUAL(OUString(u
"\u00D2\u00DA\u00DB"), xTextRange
->getString());
69 CPPUNIT_TEST_FIXTURE(Test
, testFdo72031
)
71 auto verify
= [this]() {
72 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uF0C5"), getRun(getParagraph(1), 1)->getString());
75 AllSettings aSavedSettings
= Application::GetSettings();
76 AllSettings
aSettings(aSavedSettings
);
77 aSettings
.SetLanguageTag(LanguageTag("ru"));
78 Application::SetSettings(aSettings
);
79 comphelper::ScopeGuard
g([&aSavedSettings
] { Application::SetSettings(aSavedSettings
); });
81 createSwDoc("fdo72031.rtf");
83 saveAndReload("Rich Text Format");
87 DECLARE_RTFEXPORT_TEST(testFdo86750
, "fdo86750.rtf")
89 // This was 'HYPERLINK#anchor', the URL of the hyperlink had the field type as a prefix, leading to broken links.
90 CPPUNIT_ASSERT_EQUAL(OUString("#anchor"),
91 getProperty
<OUString
>(getRun(getParagraph(1), 1), "HyperLinkURL"));
94 DECLARE_RTFEXPORT_TEST(testTdf88811
, "tdf88811.rtf")
96 // The problem was that shapes anchored to the paragraph that is moved into a textframe were lost, so this was 2.
97 CPPUNIT_ASSERT_EQUAL(4, getShapes());
100 DECLARE_RTFEXPORT_TEST(testFdo49893_2
, "fdo49893-2.rtf")
102 // Ensure that header text exists on each page (especially on second page)
103 CPPUNIT_ASSERT_EQUAL(OUString("HEADER"), parseDump("/root/page[1]/header/txt/text()"));
104 CPPUNIT_ASSERT_EQUAL(OUString("HEADER"), parseDump("/root/page[2]/header/txt/text()"));
105 CPPUNIT_ASSERT_EQUAL(OUString("HEADER"), parseDump("/root/page[3]/header/txt/text()"));
108 DECLARE_RTFEXPORT_TEST(testFdo89496
, "fdo89496.rtf")
110 // Just ensure that document is loaded and shape exists
111 uno::Reference
<drawing::XShape
> xShape
= getShape(1);
112 CPPUNIT_ASSERT(xShape
.is());
115 DECLARE_RTFEXPORT_TEST(testFdo75614
, "tdf75614.rtf")
117 // Text after the footnote was missing, so this resulted in a css::container::NoSuchElementException.
118 CPPUNIT_ASSERT_EQUAL(OUString("after."), getRun(getParagraph(1), 3)->getString());
121 DECLARE_RTFEXPORT_TEST(mathtype
, "mathtype.rtf")
123 OUString aFormula
= getFormula(getRun(getParagraph(1), 1));
124 CPPUNIT_ASSERT(!aFormula
.isEmpty());
127 DECLARE_RTFEXPORT_TEST(testTdf86182
, "tdf86182.rtf")
129 // Writing mode was the default, i.e. text::WritingMode2::CONTEXT.
130 CPPUNIT_ASSERT_EQUAL(text::WritingMode2::RL_TB
,
131 getProperty
<sal_Int16
>(getParagraph(1), "WritingMode"));
134 DECLARE_RTFEXPORT_TEST(testTdf91074
, "tdf91074.rtf")
136 // The file failed to load, as the border color was imported using the LineColor UNO property.
137 uno::Reference
<drawing::XShape
> xShape
= getShape(1);
138 CPPUNIT_ASSERT_EQUAL(
140 Color(ColorTransparency
, getProperty
<table::BorderLine2
>(xShape
, "TopBorder").Color
));
143 CPPUNIT_TEST_FIXTURE(Test
, testTdf90260Nopar
)
145 createSwDoc("hello.rtf");
146 uno::Reference
<text::XTextDocument
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
147 uno::Reference
<text::XTextRange
> xText
= xTextDocument
->getText();
148 uno::Reference
<text::XTextRange
> xEnd
= xText
->getEnd();
149 paste(u
"rtfexport/data/tdf90260-nopar.rtf", "com.sun.star.comp.Writer.RtfFilter", xEnd
);
150 CPPUNIT_ASSERT_EQUAL(1, getParagraphs());
153 DECLARE_RTFEXPORT_TEST(testTdf86814
, "tdf86814.rtf")
155 // This was awt::FontWeight::NORMAL, i.e. the first run wasn't bold, when it should be bold (applied paragraph style with direct formatting).
156 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD
,
157 getProperty
<float>(getRun(getParagraph(1), 1), "CharWeight"));
160 /** Make sure that the document variable "Unused", which is not referenced in the document,
161 is imported and exported. */
162 DECLARE_RTFEXPORT_TEST(testTdf150267
, "tdf150267.rtf")
164 uno::Reference
<frame::XModel
> xModel(mxComponent
, uno::UNO_QUERY
);
165 uno::Reference
<text::XTextFieldsSupplier
> xSupplier(xModel
, uno::UNO_QUERY
);
166 uno::Reference
<container::XNameAccess
> xTextFieldMasters
= xSupplier
->getTextFieldMasters();
167 CPPUNIT_ASSERT_EQUAL(sal_True
,
168 xTextFieldMasters
->hasByName("com.sun.star.text.fieldmaster.User.Unused"));
170 auto xFieldMaster
= xTextFieldMasters
->getByName("com.sun.star.text.fieldmaster.User.Unused");
171 CPPUNIT_ASSERT_EQUAL(OUString("Hello World"), getProperty
<OUString
>(xFieldMaster
, "Content"));
174 DECLARE_RTFEXPORT_TEST(testTdf151370
, "tdf151370.rtf")
176 uno::Reference
<frame::XModel
> xModel(mxComponent
, uno::UNO_QUERY
);
177 uno::Reference
<text::XTextFieldsSupplier
> xSupplier(xModel
, uno::UNO_QUERY
);
178 uno::Reference
<container::XNameAccess
> xTextFieldMasters
= xSupplier
->getTextFieldMasters();
179 // Here we try to read/write docvar having non-ascii name and value. So it is encoded in Unicode
180 OUString
sFieldName(u
"com.sun.star.text.fieldmaster.User."
181 "LocalChars\u00c1\u0072\u0076\u00ed\u007a\u0074\u0075\u0072\u006f\u0054"
182 "\u00fc\u006b\u00f6\u0072\u0066\u00fa\u0072\u00f3\u0067\u00e9\u0070");
183 CPPUNIT_ASSERT_EQUAL(sal_True
, xTextFieldMasters
->hasByName(sFieldName
));
185 auto xFieldMaster
= xTextFieldMasters
->getByName(sFieldName
);
186 CPPUNIT_ASSERT_EQUAL(
187 OUString(u
"\u00e1\u0072\u0076\u00ed\u007a\u0074\u0075\u0072\u006f\u0074\u00fc"
188 "\u006b\u00f6\u0072\u0066\u00fa\u0072\u00f3\u0067\u00e9\u0070"),
189 getProperty
<OUString
>(xFieldMaster
, "Content"));
192 DECLARE_RTFEXPORT_TEST(testTdf108416
, "tdf108416.rtf")
194 uno::Reference
<container::XNameAccess
> xCharacterStyles(getStyles("CharacterStyles"));
195 uno::Reference
<beans::XPropertySet
> xListLabel(xCharacterStyles
->getByName("ListLabel 1"),
197 // This was awt::FontWeight::BOLD, list numbering got an unexpected bold formatting.
198 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL
, getProperty
<float>(xListLabel
, "CharWeight"));
201 DECLARE_RTFEXPORT_TEST(testBinSkipping
, "bin-skipping.rtf")
203 // before, it was importing '/nMUST NOT IMPORT'
204 CPPUNIT_ASSERT_EQUAL(OUString("text"), getRun(getParagraph(1), 1)->getString());
207 DECLARE_RTFEXPORT_TEST(testTdf92061
, "tdf92061.rtf")
209 // This was "C", i.e. part of the footnote ended up in the body text.
210 CPPUNIT_ASSERT_EQUAL(OUString("body-after"), getRun(getParagraph(1), 3)->getString());
213 DECLARE_RTFEXPORT_TEST(testTdf92481
, "tdf92481.rtf")
215 // This was 0, RTF_WIDOWCTRL was not imported.
216 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int8
>(2),
217 getProperty
<sal_Int8
>(getParagraph(1), "ParaWidows"));
220 DECLARE_RTFEXPORT_TEST(testTdf94456
, "tdf94456.rtf")
222 // Paragraph left margin and first line indent wasn't imported correctly.
225 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(762),
226 getProperty
<sal_Int32
>(getParagraph(1), "ParaLeftMargin"));
228 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(-762),
229 getProperty
<sal_Int32
>(getParagraph(1), "ParaFirstLineIndent"));
232 DECLARE_RTFEXPORT_TEST(testTdf94435
, "tdf94435.rtf")
234 // This was style::ParagraphAdjust_LEFT, \ltrpar undone the effect of \qc.
235 CPPUNIT_ASSERT_EQUAL(
236 style::ParagraphAdjust_CENTER
,
237 static_cast<style::ParagraphAdjust
>(getProperty
<sal_Int16
>(getParagraph(1), "ParaAdjust")));
240 DECLARE_RTFEXPORT_TEST(testTdf54584
, "tdf54584.rtf")
242 uno::Reference
<text::XTextFieldsSupplier
> xTextFieldsSupplier(mxComponent
, uno::UNO_QUERY
);
243 uno::Reference
<container::XEnumerationAccess
> xFieldsAccess(
244 xTextFieldsSupplier
->getTextFields());
245 uno::Reference
<container::XEnumeration
> xFields(xFieldsAccess
->createEnumeration());
246 // \PAGE was ignored, so no fields were in document -> exception was thrown
247 CPPUNIT_ASSERT_NO_THROW_MESSAGE(
248 "No fields in document found: field \"\\PAGE\" was not properly read",
249 xFields
->nextElement());
252 DECLARE_RTFEXPORT_TEST(testTdf96308Deftab
, "tdf96308-deftab.rtf")
254 uno::Reference
<lang::XMultiServiceFactory
> xTextFactory(mxComponent
, uno::UNO_QUERY
);
255 uno::Reference
<beans::XPropertySet
> xDefaults(
256 xTextFactory
->createInstance("com.sun.star.text.Defaults"), uno::UNO_QUERY
);
257 // This was 1270 as \deftab was ignored on import.
258 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(convertTwipToMm100(284)),
259 getProperty
<sal_Int32
>(xDefaults
, "TabStopDistance"));
262 DECLARE_RTFEXPORT_TEST(testLandscape
, "landscape.rtf")
264 // Check landscape flag.
265 CPPUNIT_ASSERT_EQUAL(3, getPages());
267 // All pages should have flag orientation
268 uno::Reference
<container::XNameAccess
> pageStyles
= getStyles("PageStyles");
271 uno::Reference
<frame::XModel
> xModel(mxComponent
, uno::UNO_QUERY
);
272 uno::Reference
<text::XTextViewCursorSupplier
> xTextViewCursorSupplier(
273 xModel
->getCurrentController(), uno::UNO_QUERY
);
274 uno::Reference
<text::XPageCursor
> xCursor(xTextViewCursorSupplier
->getViewCursor(),
277 // check that the first page has landscape flag
278 xCursor
->jumpToFirstPage();
279 OUString pageStyleName
= getProperty
<OUString
>(xCursor
, "PageStyleName");
280 uno::Reference
<style::XStyle
> xStylePage(pageStyles
->getByName(pageStyleName
), uno::UNO_QUERY
);
281 CPPUNIT_ASSERT_EQUAL(true, getProperty
<bool>(xStylePage
, "IsLandscape"));
283 // check that the second page has landscape flag
284 xCursor
->jumpToPage(2);
285 pageStyleName
= getProperty
<OUString
>(xCursor
, "PageStyleName");
286 xStylePage
.set(pageStyles
->getByName(pageStyleName
), uno::UNO_QUERY
);
287 CPPUNIT_ASSERT_EQUAL(true, getProperty
<bool>(xStylePage
, "IsLandscape"));
289 // check that the last page has landscape flag
290 xCursor
->jumpToLastPage();
291 pageStyleName
= getProperty
<OUString
>(xCursor
, "PageStyleName");
292 xStylePage
.set(pageStyles
->getByName(pageStyleName
), uno::UNO_QUERY
);
293 CPPUNIT_ASSERT_EQUAL(true, getProperty
<bool>(xStylePage
, "IsLandscape"));
296 DECLARE_RTFEXPORT_TEST(testTdf97035
, "tdf97035.rtf")
298 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
299 uno::Reference
<container::XIndexAccess
> xTables(xTextTablesSupplier
->getTextTables(),
301 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
303 // First cell width of the second row should be 2300
304 uno::Reference
<table::XTableRows
> xTableRows
= xTable
->getRows();
305 CPPUNIT_ASSERT_EQUAL(sal_Int16(2300), getProperty
<uno::Sequence
<text::TableColumnSeparator
>>(
306 xTableRows
->getByIndex(1), "TableColumnSeparators")[0]
310 DECLARE_RTFEXPORT_TEST(testTdf87034
, "tdf87034.rtf")
312 // This was A1BC34D, i.e. the first "super" text portion was mis-imported,
313 // and was inserted instead right before the second "super" text portion.
314 CPPUNIT_ASSERT_EQUAL(OUString("A1B3C4D"), getParagraph(1)->getString());
317 CPPUNIT_TEST_FIXTURE(Test
, testClassificatonPasteLevels
)
319 createSwDoc("classification-confidential.rtf");
320 uno::Reference
<text::XTextDocument
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
321 uno::Reference
<text::XTextRange
> xText
= xTextDocument
->getText();
322 uno::Reference
<text::XTextRange
> xEnd
= xText
->getEnd();
324 // Classified source and classified destination, but internal only has a
325 // higher level than confidential: nothing should happen.
326 OUString aOld
= xText
->getString();
327 paste(u
"rtfexport/data/classification-yes.rtf", "com.sun.star.comp.Writer.RtfFilter", xEnd
);
328 CPPUNIT_ASSERT_EQUAL(aOld
, xText
->getString());
331 DECLARE_RTFEXPORT_TEST(testTdf95707
, "tdf95707.rtf")
333 // Graphic was replaced with a "Read-Error" placeholder.
334 uno::Reference
<graphic::XGraphic
> xGraphic
335 = getProperty
<uno::Reference
<graphic::XGraphic
>>(getShape(1), "Graphic");
336 CPPUNIT_ASSERT(xGraphic
.is());
337 CPPUNIT_ASSERT(xGraphic
->getType() != graphic::GraphicType::EMPTY
);
340 DECLARE_RTFEXPORT_TEST(testTdf96275
, "tdf96275.rtf")
342 uno::Reference
<text::XTextTable
> xTable(getParagraphOrTable(1), uno::UNO_QUERY
);
343 uno::Reference
<text::XTextRange
> xCell(xTable
->getCellByName("A1"), uno::UNO_QUERY
);
344 uno::Reference
<text::XTextRange
> xParagraph
= getParagraphOfText(3, xCell
->getText());
345 // This was text: the shape's frame was part of the 1st paragraph instead of the 3rd one.
346 CPPUNIT_ASSERT_EQUAL(OUString("Frame"),
347 getProperty
<OUString
>(getRun(xParagraph
, 1), "TextPortionType"));
350 DECLARE_RTFEXPORT_TEST(testTdf82073
, "tdf82073.rtf")
352 uno::Reference
<text::XTextTable
> xTable(getParagraphOrTable(2), uno::UNO_QUERY
);
353 uno::Reference
<text::XTextRange
> xCell(xTable
->getCellByName("A1"), uno::UNO_QUERY
);
354 // This was -1: the background color was automatic, not black.
355 CPPUNIT_ASSERT_EQUAL(COL_BLACK
, getProperty
<Color
>(xCell
, "BackColor"));
358 DECLARE_RTFEXPORT_TEST(testTdf74795
, "tdf74795.rtf")
360 uno::Reference
<text::XTextTable
> xTable(getParagraphOrTable(1), uno::UNO_QUERY
);
361 uno::Reference
<text::XTextRange
> xCell(xTable
->getCellByName("A1"), uno::UNO_QUERY
);
362 // This was 0, \trpaddl was ignored on import.
363 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(635),
364 getProperty
<sal_Int32
>(xCell
, "LeftBorderDistance"));
366 xCell
.set(xTable
->getCellByName("A2"), uno::UNO_QUERY
);
367 // Make sure that the scope of the default is only one row.
368 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0),
369 getProperty
<sal_Int32
>(xCell
, "LeftBorderDistance"));
372 DECLARE_RTFEXPORT_TEST(testTdf137085
, "tdf137085.rtf")
374 uno::Reference
<text::XTextTable
> xTable(getParagraphOrTable(1), uno::UNO_QUERY
);
375 // \trpaddl0 overrides \trgaph600 (-1058 mm100) and built-in default of 190
376 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0), getProperty
<sal_Int32
>(xTable
, "LeftMargin"));
378 // the \trpaddl0 is applied to all cells
379 uno::Reference
<text::XTextRange
> xCell(xTable
->getCellByName("A1"), uno::UNO_QUERY
);
380 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0),
381 getProperty
<sal_Int32
>(xCell
, "LeftBorderDistance"));
383 xCell
.set(xTable
->getCellByName("B1"), uno::UNO_QUERY
);
384 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0),
385 getProperty
<sal_Int32
>(xCell
, "LeftBorderDistance"));
388 DECLARE_RTFEXPORT_TEST(testTdf77349
, "tdf77349.rtf")
390 uno::Reference
<container::XNamed
> xImage(getShape(1), uno::UNO_QUERY
);
391 // This was empty: imported image wasn't named automatically.
392 CPPUNIT_ASSERT_EQUAL(OUString("Image1"), xImage
->getName());
395 DECLARE_RTFEXPORT_TEST(testTdf50821
, "tdf50821.rtf")
397 uno::Reference
<text::XTextTable
> xTable(getParagraphOrTable(2), uno::UNO_QUERY
);
398 uno::Reference
<text::XTextRange
> xCell(xTable
->getCellByName("A1"), uno::UNO_QUERY
);
399 // This was 0, \trpaddfl was mishandled on import.
400 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(191),
401 getProperty
<sal_Int32
>(xCell
, "LeftBorderDistance"));
404 DECLARE_RTFEXPORT_TEST(testTdf100507
, "tdf100507.rtf")
406 // This was 0: left margin of the first paragraph was lost on import.
407 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(6618),
408 getProperty
<sal_Int32
>(getParagraph(1), "ParaLeftMargin"));
411 DECLARE_RTFEXPORT_TEST(testTdf44986
, "tdf44986.rtf")
413 // Check that the table at the second paragraph.
414 uno::Reference
<text::XTextTable
> xTable(getParagraphOrTable(2), uno::UNO_QUERY
);
415 uno::Reference
<table::XTableRows
> xTableRows
= xTable
->getRows();
416 // Check the first row of the table, it should have two cells (one separator).
417 // This was 0: the first row had no separators, so it had only one cell, which was too wide.
418 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty
<uno::Sequence
<text::TableColumnSeparator
>>(
419 xTableRows
->getByIndex(0), "TableColumnSeparators")
423 DECLARE_RTFEXPORT_TEST(testTdf90697
, "tdf90697.rtf")
425 // We want section breaks to be seen as section breaks, not as page breaks,
426 // so this document should have only one page, not three.
427 CPPUNIT_ASSERT_EQUAL(1, getPages());
430 DECLARE_RTFEXPORT_TEST(testTdf104317
, "tdf104317.rtf")
432 // This failed to load, we tried to set CustomShapeGeometry on a line shape.
433 CPPUNIT_ASSERT_EQUAL(1, getShapes());
436 DECLARE_RTFEXPORT_TEST(testTdf104744
, "tdf104744.rtf")
438 auto xRules
= getProperty
<uno::Reference
<container::XIndexAccess
>>(
439 getStyles("NumberingStyles")->getByName("WWNum1"), "NumberingRules");
440 comphelper::SequenceAsHashMap
aRule(xRules
->getByIndex(0));
442 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(1270), aRule
["IndentAt"].get
<sal_Int32
>());
445 CPPUNIT_TEST_FIXTURE(SwModelTestBase
, testChicagoNumberingFootnote
)
447 // Create a document, set footnote numbering type to SYMBOL_CHICAGO.
449 uno::Reference
<text::XFootnotesSupplier
> xFootnotesSupplier(mxComponent
, uno::UNO_QUERY
);
450 uno::Reference
<beans::XPropertySet
> xFootnoteSettings
451 = xFootnotesSupplier
->getFootnoteSettings();
452 sal_uInt16 nNumberingType
= style::NumberingType::SYMBOL_CHICAGO
;
453 xFootnoteSettings
->setPropertyValue("NumberingType", uno::Any(nNumberingType
));
455 // Insert a footnote.
456 uno::Reference
<lang::XMultiServiceFactory
> xFactory(mxComponent
, uno::UNO_QUERY
);
457 uno::Reference
<text::XTextContent
> xFootnote(
458 xFactory
->createInstance("com.sun.star.text.Footnote"), uno::UNO_QUERY
);
459 uno::Reference
<text::XTextDocument
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
460 uno::Reference
<text::XTextContentAppend
> xTextContentAppend(xTextDocument
->getText(),
462 xTextContentAppend
->appendTextContent(xFootnote
, {});
464 saveAndReload("Rich Text Format");
465 xFootnotesSupplier
.set(mxComponent
, uno::UNO_QUERY
);
466 sal_uInt16 nExpected
= style::NumberingType::SYMBOL_CHICAGO
;
468 = getProperty
<sal_uInt16
>(xFootnotesSupplier
->getFootnoteSettings(), "NumberingType");
469 // Without the accompanying fix in place, this test would have failed with:
472 // i.e. the numbering type was ARABIC, not SYMBOL_CHICAGO.
473 CPPUNIT_ASSERT_EQUAL(nExpected
, nActual
);
476 DECLARE_RTFEXPORT_TEST(testTdf105852
, "tdf105852.rtf")
478 uno::Reference
<text::XTextTablesSupplier
> xTablesSupplier(mxComponent
, uno::UNO_QUERY
);
479 uno::Reference
<container::XIndexAccess
> xTables(xTablesSupplier
->getTextTables(),
481 uno::Reference
<text::XTextTable
> xTextTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
482 uno::Reference
<table::XTableRows
> xTableRows
= xTextTable
->getRows();
483 // All rows but last were merged -> there were only 2 rows
484 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTableRows
->getCount());
485 // The first row must have 4 cells.
486 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getProperty
<uno::Sequence
<text::TableColumnSeparator
>>(
487 xTableRows
->getByIndex(0), "TableColumnSeparators")
489 // The third row must have 1 merged cell.
490 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty
<uno::Sequence
<text::TableColumnSeparator
>>(
491 xTableRows
->getByIndex(2), "TableColumnSeparators")
495 DECLARE_RTFEXPORT_TEST(testTdf104287
, "tdf104287.rtf")
497 uno::Reference
<text::XTextContent
> xShape(getShape(1), uno::UNO_QUERY
);
498 CPPUNIT_ASSERT(xShape
.is());
499 // This failed, the bitmap had no valid anchor.
500 CPPUNIT_ASSERT(xShape
->getAnchor().is());
503 DECLARE_RTFEXPORT_TEST(testTdf105729
, "tdf105729.rtf")
505 // This was style::ParagraphAdjust_LEFT, \ltrpar undone the effect of \qc from style.
506 CPPUNIT_ASSERT_EQUAL(
507 style::ParagraphAdjust_CENTER
,
508 static_cast<style::ParagraphAdjust
>(getProperty
<sal_Int16
>(getParagraph(1), "ParaAdjust")));
511 DECLARE_RTFEXPORT_TEST(testTdf106694
, "tdf106694.rtf")
513 auto aTabs
= getProperty
<uno::Sequence
<style::TabStop
>>(getParagraph(1), "ParaTabStops");
514 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(1), aTabs
.getLength());
515 // This was 0, tab position was incorrect, looked like it was missing.
516 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(14605), aTabs
[0].Position
);
519 DECLARE_RTFEXPORT_TEST(testTdf107116
, "tdf107116.rtf")
521 // This was 0, upper border around text (and its distance) was missing.
522 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(convertTwipToMm100(120)),
523 getProperty
<sal_Int32
>(getParagraph(2), "TopBorderDistance"));
526 DECLARE_RTFEXPORT_TEST(testTdf106950
, "tdf106950.rtf")
528 uno::Reference
<text::XTextRange
> xPara(getParagraph(1));
529 // This was ParagraphAdjust_LEFT, trying to set CharShadingValue on a
530 // paragraph style thrown an exception, and remaining properties were not
532 CPPUNIT_ASSERT_EQUAL(
533 style::ParagraphAdjust_CENTER
,
534 static_cast<style::ParagraphAdjust
>(getProperty
<sal_Int16
>(xPara
, "ParaAdjust")));
537 CPPUNIT_TEST_FIXTURE(Test
, testTdf116371
)
539 loadAndReload("tdf116371.odt");
540 CPPUNIT_ASSERT_EQUAL(1, getShapes());
541 CPPUNIT_ASSERT_EQUAL(1, getPages());
542 auto xShape(getShape(1));
543 // Without the accompanying fix in place, this test would have failed with
544 // 'Unknown property: RotateAngle', i.e. export lost the rotation, and then
545 // import created a Writer picture (instead of a Draw one).
546 CPPUNIT_ASSERT_DOUBLES_EQUAL(4700.0, getProperty
<double>(xShape
, "RotateAngle"), 10);
549 DECLARE_RTFEXPORT_TEST(testTdf133437
, "tdf133437.rtf")
551 CPPUNIT_ASSERT_EQUAL(3, getPages());
552 CPPUNIT_ASSERT_EQUAL(560, getShapes()); // 285 \shp + 275 \poswX
554 xmlDocUniquePtr pDump
= parseLayoutDump();
555 // Count shapes on first page
556 assertXPath(pDump
, "/root/page[1]/body/txt[1]/anchored/SwAnchoredDrawObject", 79);
559 assertXPath(pDump
, "/root/page[2]/body/txt[2]/anchored/SwAnchoredDrawObject", 118);
562 assertXPath(pDump
, "/root/page[3]/body/txt[2]/anchored/SwAnchoredDrawObject", 84);
565 CPPUNIT_TEST_FIXTURE(Test
, testTdf128320
)
567 loadAndReload("tdf128320.odt");
568 CPPUNIT_ASSERT_EQUAL(1, getShapes());
569 CPPUNIT_ASSERT_EQUAL(1, getPages());
570 // Shape does exist in RTF output
571 auto xShape(getShape(1));
572 CPPUNIT_ASSERT(xShape
.is());
574 // Let's see what is inside output RTF file
575 SvStream
* pStream
= maTempFile
.GetStream(StreamMode::READ
);
576 CPPUNIT_ASSERT(pStream
);
577 OString
aRtfContent(read_uInt8s_ToOString(*pStream
, pStream
->TellEnd()));
579 // There are some RTF tokens for shape props
580 // They are much more inside, but let's use \shpwr2 as an indicator
581 sal_Int32 nPos
= aRtfContent
.indexOf("\\shpwr2", 0);
582 CPPUNIT_ASSERT(nPos
> 0);
584 // It goes AFTER shape instruction (sadly here we do not check if it is contained inside)
585 sal_Int32 nPosShp
= aRtfContent
.indexOf("\\shpinst", 0);
586 CPPUNIT_ASSERT(nPosShp
> 0);
588 // But there are no more shape properties!
589 nPos
= aRtfContent
.indexOf("\\shpwr2", nPos
+ 1);
590 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), nPos
);
593 DECLARE_RTFEXPORT_TEST(testTdf129513
, "tdf129513.rtf")
595 // \pagebb after \intbl must not reset the "in table" flag
596 CPPUNIT_ASSERT_EQUAL(2, getParagraphs());
597 // Make sure the first paragraph is imported in table
598 uno::Reference
<text::XTextTable
> xTable(getParagraphOrTable(1), uno::UNO_QUERY_THROW
);
599 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable
->getCellNames().getLength());
600 uno::Reference
<text::XText
> xCell(xTable
->getCellByName("A1"), uno::UNO_QUERY_THROW
);
601 CPPUNIT_ASSERT_EQUAL(OUString("In table"), xCell
->getString());
604 DECLARE_RTFEXPORT_TEST(testTdf138210
, "tdf138210.rtf")
606 uno::Reference
<text::XTextFramesSupplier
> xTextFramesSupplier(mxComponent
, uno::UNO_QUERY
);
607 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextFramesSupplier
->getTextFrames(),
609 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
612 CPPUNIT_TEST_FIXTURE(Test
, testTdf137894
)
614 loadAndReload("tdf137894.odt");
615 CPPUNIT_ASSERT_EQUAL(1, getPages());
616 lang::Locale
locale1(getProperty
<lang::Locale
>(getRun(getParagraph(1), 1), "CharLocaleAsian"));
617 CPPUNIT_ASSERT_EQUAL(OUString("ja"), locale1
.Language
);
618 CPPUNIT_ASSERT_EQUAL(OUString("MS UI Gothic"),
619 getProperty
<OUString
>(getRun(getParagraph(1), 1), "CharFontNameAsian"));
620 CPPUNIT_ASSERT_EQUAL(20.f
, getProperty
<float>(getRun(getParagraph(1), 1), "CharHeightAsian"));
621 CPPUNIT_ASSERT_EQUAL(OUString("Mangal"),
622 getProperty
<OUString
>(getRun(getParagraph(1), 1), "CharFontNameComplex"));
623 CPPUNIT_ASSERT_EQUAL(20.f
, getProperty
<float>(getRun(getParagraph(1), 1), "CharHeightComplex"));
624 lang::Locale
locale2(
625 getProperty
<lang::Locale
>(getRun(getParagraph(2), 1), "CharLocaleComplex"));
626 CPPUNIT_ASSERT_EQUAL(OUString("he"), locale2
.Language
);
627 CPPUNIT_ASSERT_EQUAL(32.f
, getProperty
<float>(getRun(getParagraph(2), 1), "CharHeightComplex"));
630 CPPUNIT_TEST_FIXTURE(Test
, testTdf138779
)
632 loadAndReload("tdf138779.docx");
633 // The text "2. Kozuka Mincho Pro, 8 pt Ruby ..." has font size 11pt ( was 20pt ).
634 CPPUNIT_ASSERT_EQUAL(11.f
, getProperty
<float>(getRun(getParagraph(2), 14), "CharHeight"));
637 CPPUNIT_TEST_FIXTURE(Test
, testTdf144437
)
639 loadAndReload("tdf144437.odt");
640 SvStream
* pStream
= maTempFile
.GetStream(StreamMode::READ
);
641 CPPUNIT_ASSERT(pStream
);
642 OString
aRtfContent(read_uInt8s_ToOString(*pStream
, pStream
->TellEnd()));
644 sal_Int32 nTextEndPos
= aRtfContent
.indexOf("Bookmark here->", 0) + 14;
645 CPPUNIT_ASSERT_MESSAGE("Para content wasn't found in file", nTextEndPos
> 0);
647 sal_Int32 nBmkStartPos
= aRtfContent
.indexOf("{\\*\\bkmkstart bookmark}", 0);
648 CPPUNIT_ASSERT_MESSAGE("Bookmark start wasn't found in file", nBmkStartPos
> 0);
650 sal_Int32 nBmkEndPos
= aRtfContent
.indexOf("{\\*\\bkmkend bookmark}", 0);
651 CPPUNIT_ASSERT_MESSAGE("Bookmark end wasn't found in file", nBmkEndPos
> 0);
653 CPPUNIT_ASSERT_MESSAGE("Bookmark started in wrong position", nBmkStartPos
> nTextEndPos
);
654 CPPUNIT_ASSERT_MESSAGE("Bookmark ended in wrong position", nBmkEndPos
> nTextEndPos
);
655 CPPUNIT_ASSERT_MESSAGE("Bookmark start & end are wrong", nBmkEndPos
> nBmkStartPos
);
658 DECLARE_RTFEXPORT_TEST(testTdf131234
, "tdf131234.rtf")
660 uno::Reference
<text::XTextRange
> xRun
= getRun(getParagraph(1), 1, OUString(u
"Hello"));
662 // Ensure that text has default font attrs in spite of style referenced
663 // E.g. 12pt, Times New Roman, black, no bold, no italic, no underline
664 CPPUNIT_ASSERT_EQUAL(12.f
, getProperty
<float>(xRun
, "CharHeight"));
665 CPPUNIT_ASSERT_EQUAL(COL_BLACK
, getProperty
<Color
>(xRun
, "CharColor"));
666 CPPUNIT_ASSERT_EQUAL(OUString("Times New Roman"), getProperty
<OUString
>(xRun
, "CharFontName"));
667 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL
, getProperty
<float>(xRun
, "CharWeight"));
668 CPPUNIT_ASSERT_EQUAL(awt::FontUnderline::NONE
, getProperty
<sal_Int16
>(xRun
, "CharUnderline"));
669 CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE
, getProperty
<awt::FontSlant
>(xRun
, "CharPosture"));
672 DECLARE_RTFEXPORT_TEST(testTdf118047
, "tdf118047.rtf")
674 uno::Reference
<text::XTextRange
> xPara
= getParagraph(1);
676 // Ensure that default "Normal" style properties are not applied to text:
677 // text remains with fontsize 12pt and no huge margin below
678 CPPUNIT_ASSERT_EQUAL(12.f
, getProperty
<float>(getRun(xPara
, 1), "CharHeight"));
679 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty
<sal_Int32
>(getParagraph(1), "ParaBottomMargin"));
681 // Same for header, it should not derive props from "Normal" style
682 CPPUNIT_ASSERT_EQUAL(OUString("Header"), parseDump("/root/page[1]/header/txt/text()"));
683 sal_Int32 nHeight
= parseDump("/root/page[1]/header/infos/bounds", "height").toInt32();
684 CPPUNIT_ASSERT_MESSAGE("Header is too large", 1000 > nHeight
);
687 DECLARE_RTFEXPORT_TEST(testTdf104390
, "tdf104390.rtf")
689 uno::Reference
<text::XTextRange
> xPara
= getParagraph(1);
690 uno::Reference
<container::XEnumerationAccess
> xRunEnumAccess(xPara
, uno::UNO_QUERY
);
691 uno::Reference
<container::XEnumeration
> xRunEnum
= xRunEnumAccess
->createEnumeration();
693 // Check font in first run
694 uno::Reference
<text::XTextRange
> xRun(xRunEnum
->nextElement(), uno::UNO_QUERY
);
695 CPPUNIT_ASSERT_EQUAL(36.f
, getProperty
<float>(xRun
, "CharHeight"));
696 CPPUNIT_ASSERT_EQUAL(OUString("Courier New"), getProperty
<OUString
>(xRun
, "CharFontName"));
698 // Ensure this run covers whole paragraph text (ignore possible empty "paragraph marker" run)
699 CPPUNIT_ASSERT_EQUAL(xPara
->getString().getLength(), xRun
->getString().getLength());
702 DECLARE_RTFEXPORT_TEST(testTdf153681
, "tdf153681.odt")
704 uno::Reference
<text::XTextTablesSupplier
> xTablesSupplier(mxComponent
, uno::UNO_QUERY_THROW
);
705 uno::Reference
<container::XIndexAccess
> xTables(xTablesSupplier
->getTextTables(),
706 uno::UNO_QUERY_THROW
);
708 // This is outside table
709 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(1), uno::UNO_QUERY_THROW
);
710 // Without the accompanying fix in place, this test would have failed with:
713 // Generates extra cell
714 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getRows()->getCount());
715 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable
->getColumns()->getCount());
718 CPPUNIT_PLUGIN_IMPLEMENT();
720 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */