/* -*- 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/.
*/
if (aEditEngine.GetRefDevice()->GetDPIY() != 96
|| aEditEngine.GetRefDevice()->GetDPIScaleFactor() != 1.0) return;
// Get EditDoc for current EditEngine's instance
EditDoc& rDoc = aEditEngine.GetEditDoc();
// Initially no text should be there
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen());
CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0)));
// Set initial text
OUString aText = u"This is multi-line paragraph"_ustr;
// Check the first line
ParagraphInfos aInfo = aEditEngine.GetParagraphInfos(0);
CPPUNIT_ASSERT_EQUAL(nExpMaxAscent, aInfo.nFirstLineMaxAscent);
CPPUNIT_ASSERT_EQUAL(nExpLineHeight, aEditEngine.GetLineHeight(0));
};
// Test first case - 60%
doTest(60, 122, 153);
// Force multiple lines
aEditEngine.SetPaperSize(Size(1000, 6000));
CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aEditEngine.GetLineCount(0));
// Test second case - 150%
doTest(150, 337, 382);
// Test lower Word limit - 6% (factor 0.06)
doTest(6, 12, 15);
// Test upper Word limit - 13200% (factor 132)
doTest(13200, 33615, 33660);
} #endif
bool includes(const uno::Sequence<OUString>& rSeq, std::u16string_view rVal)
{ for (OUString const& s : rSeq) if (s == rVal) returntrue;
returnfalse;
}
void Test::testUnoTextFields()
{
{ // DATE
rtl::Reference<SvxUnoTextField> xField(new SvxUnoTextField(text::textfield::Type::DATE));
uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.text.textfield.DateTime");
CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood);
}
{ // URL
rtl::Reference<SvxUnoTextField> xField(new SvxUnoTextField(text::textfield::Type::URL));
uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.text.textfield.URL");
CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood);
}
{ // PAGE
rtl::Reference<SvxUnoTextField> xField(new SvxUnoTextField(text::textfield::Type::PAGE));
uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.text.textfield.PageNumber");
CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood);
}
{ // PAGES
rtl::Reference<SvxUnoTextField> xField(new SvxUnoTextField(text::textfield::Type::PAGES));
uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.text.textfield.PageCount");
CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood);
}
{ // TIME
rtl::Reference<SvxUnoTextField> xField(new SvxUnoTextField(text::textfield::Type::TIME));
uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.text.textfield.DateTime");
CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood);
}
{ // FILE
rtl::Reference<SvxUnoTextField> xField( new SvxUnoTextField(text::textfield::Type::DOCINFO_TITLE));
uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.text.textfield.docinfo.Title");
CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood);
}
{ // TABLE
rtl::Reference<SvxUnoTextField> xField(new SvxUnoTextField(text::textfield::Type::TABLE));
uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.text.textfield.SheetName");
CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood);
}
{ // EXTENDED TIME
rtl::Reference<SvxUnoTextField> xField( new SvxUnoTextField(text::textfield::Type::EXTENDED_TIME));
uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.text.textfield.DateTime");
CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood);
}
{ // EXTENDED FILE
rtl::Reference<SvxUnoTextField> xField( new SvxUnoTextField(text::textfield::Type::EXTENDED_FILE));
uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.text.textfield.FileName");
CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood);
}
{ // AUTHOR
rtl::Reference<SvxUnoTextField> xField(new SvxUnoTextField(text::textfield::Type::AUTHOR));
uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.text.textfield.Author");
CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood);
}
{ // MEASURE
rtl::Reference<SvxUnoTextField> xField(new SvxUnoTextField(text::textfield::Type::MEASURE));
uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.text.textfield.Measure");
CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood);
}
{ // PRESENTATION HEADER
rtl::Reference<SvxUnoTextField> xField( new SvxUnoTextField(text::textfield::Type::PRESENTATION_HEADER));
uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.presentation.textfield.Header");
CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood);
}
{ // PRESENTATION FOOTER
rtl::Reference<SvxUnoTextField> xField( new SvxUnoTextField(text::textfield::Type::PRESENTATION_FOOTER));
uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.presentation.textfield.Footer");
CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood);
}
{ // PRESENTATION DATE TIME
rtl::Reference<SvxUnoTextField> xField( new SvxUnoTextField(text::textfield::Type::PRESENTATION_DATE_TIME));
uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.presentation.textfield.DateTime");
CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood);
}
}
IMPL_STATIC_LINK(Test, CalcFieldValueHdl, EditFieldInfo*, pInfo, void)
{ if (!pInfo) return;
// Get EditDoc for current EditEngine's instance
EditDoc& rDoc = aEditEngine.GetEditDoc();
// New instance must be empty - no initial text
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen());
CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0)));
// Copy text using legacy format
uno::Reference<datatransfer::XTransferable> xData
= aEditEngine.CreateTransferable(ESelection(0, 10, 0, 21));
// Paste text at the end
aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true);
// Assert Changes ACP, ACP: after Copy/Paste
// Check the fields count
CPPUNIT_ASSERT_EQUAL(size_t(3), aEditEngine.GetFieldInfo(0).size());
// Check the updated text length
CPPUNIT_ASSERT_EQUAL(aTextLen + 10 + aRepres1.getLength() * 2 + aRepres2.getLength(),
rDoc.GetTextLen());
// Check the updated text contents
CPPUNIT_ASSERT_EQUAL( u"sampletextforuser@example.comtestingexample@domain.comfeaturefieldsforuser@example.comtesting"_ustr, rDoc.GetParaAsString(sal_Int32(0)) );
// Get EditDoc for current EditEngine's instance
EditDoc& rDoc = aEditEngine.GetEditDoc();
// Initially no text should be there
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen());
CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0)));
// Set initial text
OUString aText = u"This is custom initial text"_ustr;
sal_Int32 aTextLen = aText.getLength();
aEditEngine.SetText(aText);
// Copy initial text using legacy format
uno::Reference<datatransfer::XTransferable> xData
= aEditEngine.CreateTransferable(ESelection(0, 0, 0, aTextLen));
// Paste text at the end
aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true);
/// XTransferable implementation that provides simple HTML content. class TestTransferable : public cppu::WeakImplHelper<datatransfer::XTransferable>
{
std::vector<OString> m_aContent;
std::vector<OUString> m_aMimeType;
uno::Reference<datatransfer::XTransferable> xData(new TestTransferable(aContent, aMime)); // When trying to paste HTML:
aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true);
// Then make sure the text gets pasted: // Without the accompanying fix in place, this test would have failed with: // - Expected: test // - Actual : // i.e. RTF and plain text paste worked, but not HTML.
CPPUNIT_ASSERT_EQUAL(u"test"_ustr, rDoc.GetParaAsString(static_cast<sal_Int32>(0)));
}
// When trying to paste an HTML fragment:
aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true);
// Then make sure the text gets pasted: // Without the accompanying fix in place, this test would have failed with: // - Expected: abc // - Actual : // i.e. a HTML fragment without a proper header was ignored on paste.
CPPUNIT_ASSERT_EQUAL(u"abc"_ustr, rDoc.GetParaAsString(static_cast<sal_Int32>(0)));
}
// When trying to paste HTML:
aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true);
// Then make sure the text gets pasted: // Without the accompanying fix in place, this test would have failed with: // - Expected: www.libreoffice.org // - Actual : // i.e. RTF and plain text paste worked, but not HTML.
CPPUNIT_ASSERT_EQUAL(u"www.libreoffice.org"_ustr,
rDoc.GetParaAsString(static_cast<sal_Int32>(0)));
}
// When trying to paste HTML:
aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true);
// Then make sure the text gets pasted: // expected "abc" // wrong: www.libreoffice.org // i.e. HTML is preferred over HTML.
CPPUNIT_ASSERT_EQUAL(u"abc"_ustr, rDoc.GetParaAsString(static_cast<sal_Int32>(0)));
} void Test::testMultiParaSelCopyPaste()
{ // Create EditEngine's instance
EditEngine aEditEngine(mpItemPool.get());
// Get EditDoc for current EditEngine's instance
EditDoc& rDoc = aEditEngine.GetEditDoc();
// Initially no text should be there
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen());
CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0)));
// Insert initial text
OUString aFirstPara = u"This is first paragraph"_ustr; // Selection Ref ........8..............
OUString aSecondPara = u"This is second paragraph"_ustr; // Selection Ref .............14.........
OUString aThirdPara = u"This is third paragraph"_ustr;
OUString aText = aFirstPara + "\n" + aSecondPara + "\n" + aThirdPara;
sal_Int32 aTextLen = aFirstPara.getLength() + aSecondPara.getLength() + aThirdPara.getLength();
aEditEngine.SetText( aText );
OUString aCopyText = u"first paragraphThis is second"_ustr;
sal_Int32 aCopyTextLen = aCopyText.getLength();
// Get EditDoc for current EditEngine's instance
EditDoc& rDoc = aEditEngine.GetEditDoc();
// New instance must be empty - no initial text
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen());
CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0)));
// Get corresponding Item for inserting tabs in the text
SfxVoidItem aTab(EE_FEATURE_TAB);
// Copy text using legacy format
uno::Reference<datatransfer::XTransferable> xData
= aEditEngine.CreateTransferable(ESelection(0, 6, 0, aTextLen + 2));
// Paste text at the end
aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true);
OUString aContent = pNode->GetExpandedText();
CPPUNIT_ASSERT_EQUAL_MESSAGE("get text", u"Please write email to jim@bob.com. if you find a fish(not a dog)."_ustr,
aContent);
CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong length", aContent.getLength(), rDoc.GetTextLen());
// Check expansion and positioning re-work
CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong length", aContent.getLength(), pNode->GetExpandedLen()); for (sal_Int32 n = 0; n < aContent.getLength(); n++)
{
sal_Int32 nStart = n, nEnd = n;
pNode->UnExpandPositions(nStart, nEnd);
CPPUNIT_ASSERT_MESSAGE("out of bound start", nStart < pNode->Len());
CPPUNIT_ASSERT_MESSAGE("out of bound end", nEnd <= pNode->Len());
}
staticconststruct
{
sal_Int32 mnStart, mnEnd;
sal_Int32 mnNewStart, mnNewEnd;
} aTrickyOnes[] = { { 0, 1, /* -> */ 0, 1 },
{ 21, 25, /* -> */ 21, 23 }, // the field is really just one char
{ 25, 27, /* -> */ 22, 23 },
{ 50, 56, /* -> */ 40, 46 } }; for (size_t n = 0; n < std::size(aTrickyOnes); n++)
{
sal_Int32 nStart = aTrickyOnes[n].mnStart;
sal_Int32 nEnd = aTrickyOnes[n].mnEnd;
pNode->UnExpandPositions(nStart, nEnd);
// Get EditDoc for current EditEngine's instance
EditDoc& rDoc = aEditEngine.GetEditDoc();
// New instance must be empty - no initial text
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen());
CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0)));
// Get corresponding ItemSet for inserting Bold/Italic text
std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(aEditEngine.GetEmptyItemSet()));
SvxWeightItem aBold(WEIGHT_BOLD, EE_CHAR_WEIGHT);
SvxPostureItem aItalic(ITALIC_NORMAL, EE_CHAR_ITALIC);
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[1].mnParagraph));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs2[1].mnStart));
CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(aAttrs2[1].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[1].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs2[1]));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[2].mnParagraph));
CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(aAttrs2[2].mnStart));
CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs2[2].mnEnd));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs2[2].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs2[2]));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs2[2]));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[3].mnParagraph));
CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs2[3].mnStart));
CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs2[3].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[3].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs2[3]));
// Copy text using legacy format
uno::Reference<datatransfer::XTransferable> xData
= aEditEngine.CreateTransferable(ESelection(0, 1, 0, aTextLen - 1));
// Paste text at the end
aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true);
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[1].mnParagraph));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[1].mnStart));
CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(aAttrs3[1].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[1].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs3[1]));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[2].mnParagraph));
CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(aAttrs3[2].mnStart));
CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs3[2].mnEnd));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[2].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs3[2]));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs3[2]));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[3].mnParagraph));
CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs3[3].mnStart));
CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs3[3].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[3].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs3[3]));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[5].mnParagraph));
CPPUNIT_ASSERT_EQUAL(21, static_cast<int>(aAttrs3[5].mnStart));
CPPUNIT_ASSERT_EQUAL(27, static_cast<int>(aAttrs3[5].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[5].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs3[5]));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[6].mnParagraph));
CPPUNIT_ASSERT_EQUAL(27, static_cast<int>(aAttrs3[6].mnStart));
CPPUNIT_ASSERT_EQUAL(33, static_cast<int>(aAttrs3[6].mnEnd));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[6].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs3[6]));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs3[6]));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[7].mnParagraph));
CPPUNIT_ASSERT_EQUAL(33, static_cast<int>(aAttrs3[7].mnStart));
CPPUNIT_ASSERT_EQUAL(37, static_cast<int>(aAttrs3[7].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[7].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs3[7]));
// Get EditDoc for current EditEngine's instance
EditDoc& rDoc = aEditEngine.GetEditDoc();
// New instance must be empty - no initial text
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen());
CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0)));
// Get corresponding ItemSet for inserting Underline text
std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(aEditEngine.GetEmptyItemSet()));
SvxUnderlineItem aULine(LINESTYLE_SINGLE, EE_CHAR_UNDERLINE);
// Copy text using legacy format
uno::Reference<datatransfer::XTransferable> xData
= aEditEngine.CreateTransferable(ESelection(0, 6, 0, aTextLen - 4));
// Paste text at the end
aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true);
// Check updated text for appropriate Underline
std::unique_ptr<EditTextObject> pEditText2(aEditEngine.CreateTextObject());
std::vector<editeng::Section> aAttrs2;
pEditText2->GetAllSections(aAttrs2);
// There should be 4 sections - woUnderline - wUnderline - woUnderline - wUnderline (w - with, wo - without)
CPPUNIT_ASSERT_EQUAL(size_t(4), aAttrs2.size());
// Get EditDoc for current EditEngine's instance
EditDoc& rDoc = aEditEngine.GetEditDoc();
// Initially no text should be there
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen());
CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0)));
// Insert initial text
OUString aFirstPara = u"This is first paragraph"_ustr;
OUString aSecondPara = u"This is second paragraph"_ustr;
OUString aThirdPara = u"This is third paragraph"_ustr;
OUString aText = aFirstPara + "\n" + aSecondPara + "\n" + aThirdPara;
sal_Int32 aTextLen = aFirstPara.getLength() + aSecondPara.getLength() + aThirdPara.getLength();
aEditEngine.SetText(aText);
sal_Int32 aCopyTextLen = aFirstPara.getLength() + aSecondPara.getLength();
// Copy initial text using legacy format
uno::Reference<datatransfer::XTransferable> xData
= aEditEngine.CreateTransferable(ESelection(0, 0, 1, aSecondPara.getLength()));
// Paste text at the end
aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true);
// Get EditDoc for current EditEngine's instance
EditDoc& rDoc = aEditEngine.GetEditDoc();
// Initially no text should be there
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen());
CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0)));
// Get corresponding ItemSet for inserting Bold/Italic text
std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(aEditEngine.GetEmptyItemSet()));
SvxWeightItem aBold(WEIGHT_BOLD, EE_CHAR_WEIGHT);
SvxPostureItem aItalic(ITALIC_NORMAL, EE_CHAR_ITALIC);
// Insert initial text
OUString aFirstPara = u"This is first paragraph"_ustr; // Positions Ref .....*5.*8....*14*17... // Bold Ref .....[ BOLD ]..... // Italic Ref ..............[ ITA // Copy Ref ........[ Copy Sel
OUString aSecondPara = u"This is second paragraph"_ustr; // Positions Ref .....*5.*8...*13..*18... // Bold Ref .....[ BOLD ]..... // Italic Ref LIC ]............... // Copy Ref ection ]..........
OUString aThirdPara = u"This is third paragraph"_ustr;
OUString aText = aFirstPara + "\n" + aSecondPara + "\n" + aThirdPara;
sal_Int32 aTextLen = aFirstPara.getLength() + aSecondPara.getLength() + aThirdPara.getLength();
aEditEngine.SetText( aText );
OUString aCopyText = u"first paragraphThis is second"_ustr;
sal_Int32 aCopyTextLen = aCopyText.getLength();
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[1].mnParagraph));
CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs2[1].mnStart));
CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs2[1].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[1].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs2[1]));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[2].mnParagraph));
CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs2[2].mnStart));
CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs2[2].mnEnd));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs2[2].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs2[2]));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs2[2]));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[3].mnParagraph));
CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs2[3].mnStart));
CPPUNIT_ASSERT_EQUAL(23, static_cast<int>(aAttrs2[3].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[3].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs2[3]));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[4].mnParagraph));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[4].mnStart));
CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs2[4].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[4].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs2[4]));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[5].mnParagraph));
CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs2[5].mnStart));
CPPUNIT_ASSERT_EQUAL(9, static_cast<int>(aAttrs2[5].mnEnd));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs2[5].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs2[5]));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs2[5]));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[6].mnParagraph));
CPPUNIT_ASSERT_EQUAL(9, static_cast<int>(aAttrs2[6].mnStart));
CPPUNIT_ASSERT_EQUAL(19, static_cast<int>(aAttrs2[6].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[6].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs2[6]));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[1].mnParagraph));
CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs3[1].mnStart));
CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs3[1].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[1].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs3[1]));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[2].mnParagraph));
CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs3[2].mnStart));
CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs3[2].mnEnd));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[2].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs3[2]));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs3[2]));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[3].mnParagraph));
CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs3[3].mnStart));
CPPUNIT_ASSERT_EQUAL(23, static_cast<int>(aAttrs3[3].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[3].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs3[3]));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[4].mnParagraph));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[4].mnStart));
CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs3[4].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[4].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs3[4]));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[5].mnParagraph));
CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs3[5].mnStart));
CPPUNIT_ASSERT_EQUAL(9, static_cast<int>(aAttrs3[5].mnEnd));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[5].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs3[5]));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs3[5]));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[6].mnParagraph));
CPPUNIT_ASSERT_EQUAL(9, static_cast<int>(aAttrs3[6].mnStart));
CPPUNIT_ASSERT_EQUAL(19, static_cast<int>(aAttrs3[6].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[6].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs3[6]));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[9].mnParagraph));
CPPUNIT_ASSERT_EQUAL(23, static_cast<int>(aAttrs3[9].mnStart));
CPPUNIT_ASSERT_EQUAL(29, static_cast<int>(aAttrs3[9].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[9].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs3[9]));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[10].mnParagraph));
CPPUNIT_ASSERT_EQUAL(29, static_cast<int>(aAttrs3[10].mnStart));
CPPUNIT_ASSERT_EQUAL(33, static_cast<int>(aAttrs3[10].mnEnd));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[10].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs3[10]));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs3[10]));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[11].mnParagraph));
CPPUNIT_ASSERT_EQUAL(33, static_cast<int>(aAttrs3[11].mnStart));
CPPUNIT_ASSERT_EQUAL(38, static_cast<int>(aAttrs3[11].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[11].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs3[11]));
CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(aAttrs3[12].mnParagraph));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[12].mnStart));
CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs3[12].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[12].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs3[12]));
CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(aAttrs3[13].mnParagraph));
CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs3[13].mnStart));
CPPUNIT_ASSERT_EQUAL(9, static_cast<int>(aAttrs3[13].mnEnd));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[13].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs3[13]));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs3[13]));
CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(aAttrs3[14].mnParagraph));
CPPUNIT_ASSERT_EQUAL(9, static_cast<int>(aAttrs3[14].mnStart));
CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs3[14].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[14].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs3[14]));
}
// Get EditDoc for current EditEngine's instance
EditDoc& rDoc = aEditEngine.GetEditDoc();
// Initially no text should be there
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen());
CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0)));
// Insert initial text
OUString aFirstPara = u"This is first paragraph"_ustr; // Selection Ref ........8..............
OUString aSecondPara = u"This is second paragraph"_ustr; // Selection Ref .............14.........
OUString aThirdPara = u"This is third paragraph"_ustr;
OUString aText = aFirstPara + "\n" + aSecondPara + "\n" + aThirdPara;
sal_Int32 aTextLen = aFirstPara.getLength() + aSecondPara.getLength() + aThirdPara.getLength();
aEditEngine.SetText( aText );
OUString aCopyText = u"first paragraphThis is second"_ustr;
sal_Int32 aCopyTextLen = aCopyText.getLength();
{
aEngine.SetText(u"aaabbbccc"_ustr);
pSet->Put(aBold);
CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be exactly one item.", static_cast<sal_uInt16>(1), pSet->Count());
aEngine.QuickSetAttribs(*pSet,
ESelection(0, 0, 0, 6)); // 'aaabbb' - end point is not inclusive.
pSet.reset(new SfxItemSet(aEngine.GetEmptyItemSet()));
pSet->Put(aItalic);
CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be exactly one item.", static_cast<sal_uInt16>(1), pSet->Count());
aEngine.QuickSetAttribs(*pSet, ESelection(0, 3, 0, 9)); // 'bbbccc'
std::unique_ptr<EditTextObject> pEditText(aEngine.CreateTextObject());
CPPUNIT_ASSERT_MESSAGE("Failed to create text object.", pEditText);
std::vector<editeng::Section> aAttrs;
pEditText->GetAllSections(aAttrs);
// Now, we should have a total of 3 sections.
CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be 3 sections.", static_cast<size_t>(3),
aAttrs.size());
// First section should be 0-3 of paragraph 0, and it should only have boldness applied.
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs[0].mnParagraph));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs[0].mnStart));
CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(aAttrs[0].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs[0].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs[0]));
// Second section should be 3-6, and it should be both bold and italic.
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs[1].mnParagraph));
CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(aAttrs[1].mnStart));
CPPUNIT_ASSERT_EQUAL(6, static_cast<int>(aAttrs[1].mnEnd));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs[1].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs[1]));
CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs[1]));
// Third section should be 6-9, and it should be only italic.
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs[2].mnParagraph));
CPPUNIT_ASSERT_EQUAL(6, static_cast<int>(aAttrs[2].mnStart));
CPPUNIT_ASSERT_EQUAL(9, static_cast<int>(aAttrs[2].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs[2].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs[2]));
}
{ // Set text consisting of 5 paragraphs with the 2nd and 4th paragraphs // being empty.
aEngine.Clear();
aEngine.SetText(u"one\n\ntwo\n\nthree"_ustr);
sal_Int32 nParaCount = aEngine.GetParagraphCount();
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), nParaCount);
// Apply boldness to paragraphs 1, 3, 5 only. Leave 2 and 4 unformatted.
pSet.reset(new SfxItemSet(aEngine.GetEmptyItemSet()));
pSet->Put(aBold);
CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be exactly one item.", static_cast<sal_uInt16>(1), pSet->Count());
aEngine.QuickSetAttribs(*pSet, ESelection(0, 0, 0, 3));
aEngine.QuickSetAttribs(*pSet, ESelection(2, 0, 2, 3));
aEngine.QuickSetAttribs(*pSet, ESelection(4, 0, 4, 5));
std::unique_ptr<EditTextObject> pEditText(aEngine.CreateTextObject());
CPPUNIT_ASSERT_MESSAGE("Failed to create text object.", pEditText);
std::vector<editeng::Section> aAttrs;
pEditText->GetAllSections(aAttrs);
CPPUNIT_ASSERT_EQUAL(size_t(5), aAttrs.size());
// 1st, 3rd and 5th sections should correspond with 1st, 3rd and 5th paragraphs.
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs[0].mnParagraph));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs[0].mnStart));
CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(aAttrs[0].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs[0].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs[0]));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs[2].mnParagraph));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs[2].mnStart));
CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(aAttrs[2].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs[2].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs[2]));
CPPUNIT_ASSERT_EQUAL(4, static_cast<int>(aAttrs[4].mnParagraph));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs[4].mnStart));
CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs[4].mnEnd));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs[4].maAttributes.size()));
CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs[4]));
// The 2nd and 4th paragraphs should be empty.
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs[1].mnParagraph));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs[1].mnStart));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs[1].mnEnd));
CPPUNIT_ASSERT_MESSAGE("Attribute array should be empty.", aAttrs[1].maAttributes.empty());
CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(aAttrs[3].mnParagraph));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs[3].mnStart));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs[3].mnEnd));
CPPUNIT_ASSERT_MESSAGE("Attribute array should be empty.", aAttrs[3].maAttributes.empty());
}
// now delete & join the paragraphs - this is fdo#85496 scenario
aEngine.QuickDelete(ESelection(0, 0, 1, 3));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aEngine.GetParagraphCount());
std::unique_ptr<EditTextObject> pEditText(aEngine.CreateTextObject());
CPPUNIT_ASSERT_MESSAGE("Failed to create text object.", pEditText);
std::vector<editeng::Section> aAttrs;
pEditText->GetAllSections(aAttrs);
// Get EditDoc for current EditEngine's instance
EditDoc& rDoc = aEditEngine.GetEditDoc();
// Initially no text should be there
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen());
CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0)));
// Insert initial text
OUString aFirstPara = u"This is first paragraph"_ustr;
OUString aSecondPara = u"This is second paragraph"_ustr;
OUString aThirdPara = u"This is third paragraph"_ustr;
OUString aFourthPara = u"This is fourth paragraph"_ustr;
OUString aFifthPara = u"This is fifth paragraph"_ustr;
OUString aSixthPara = u"This is sixth paragraph"_ustr; //Positions Ref: ........*8.............
OUString aSeventhPara = u"This is seventh paragraph"_ustr;
OUString aEighthPara = u"This is eighth paragraph"_ustr; //Positions Ref: .............*13
OUString aNinthPara = u"This is ninth paragraph"_ustr;
OUString aTenthPara = u"This is tenth paragraph"_ustr;
OUString aText = aFirstPara + "\n" + aSecondPara + "\n" + aThirdPara + "\n" +
aFourthPara + "\n" + aFifthPara + "\n" + aSixthPara + "\n" + aSeventhPara + "\n" +
aEighthPara + "\n" + aNinthPara + "\n" + aTenthPara;
sal_Int32 aTextLen = aFirstPara.getLength() + aSecondPara.getLength() + aThirdPara.getLength() +
aFourthPara.getLength() + aFifthPara.getLength() + aSixthPara.getLength() +
aSeventhPara.getLength() + aEighthPara.getLength() + aNinthPara.getLength() + aTenthPara.getLength();
aEditEngine.SetText( aText );
OUString aCopyText = u"sixth paragraphThis is seventh paragraphThis is eighth"_ustr;
sal_Int32 aCopyTextLen = aCopyText.getLength();
// Copy initial text using legacy format
uno::Reference<datatransfer::XTransferable> xData
= aEditEngine.CreateTransferable(ESelection(5, 8, 7, 14));
// Paste text at the end of 4th Para
ContentNode* pLastNode = rDoc.GetObject(3);
aEditEngine.InsertText(xData, OUString(), EditPaM(pLastNode, pLastNode->Len()), true);
using TF = TransliterationFlags; static constexpr OUString sText2 = u"Mary Jones met joe Smith. Time Passed."_ustr; int selStart = 12; int selEnd = 12;
ESelection esel(0, selStart, 0, selEnd);
ESelection eSentenSel(0, 0, 0, 25);
/* DocumentContentOperationsManager checks if the cursor is inside of a word before transliterating, * but Edit Engine has no such check. Therefore, behavior is different between these two when the
* cursor is on a word boundary. */
/* No selection tests. Cursor between the ' ' and 'm' before 'met' - except in SENTENCE_CASE where the complete sentence is selected.*/
CPPUNIT_ASSERT_EQUAL(u""_ustr, editEng.GetText(esel));
CPPUNIT_ASSERT_EQUAL(u"Mary jones met joe smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, eSentenSel, TF::SENTENCE_CASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones Met joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones MET joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones met joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
/* No selection tests. Cursor between the 't' and the ' ' after 'met'. */
selStart = 14;
selEnd = 14;
esel = ESelection(0, selStart, 0, selEnd);
CPPUNIT_ASSERT_EQUAL(u""_ustr, editEng.GetText(esel));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones Met joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones MET joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones met joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
/* No selection tests. Cursor between the 'h' and the '.' after 'Smith'. */
selStart = 24;
selEnd = 24;
esel = ESelection(0, selStart, 0, selEnd);
CPPUNIT_ASSERT_EQUAL(u""_ustr, editEng.GetText(esel));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones met joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones met joe SMITH. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones met joe smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
/* No selection tests. Cursor between the 'm' and 'e' in 'met'. */
selStart = 12;
selEnd = 12;
esel = ESelection(0, selStart, 0, selEnd);
CPPUNIT_ASSERT_EQUAL(u""_ustr, editEng.GetText(esel));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones Met joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones MET joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones met joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
/* Test behavior when there is a selection that does not cross a word boundary: "met" */
selStart = 11;
selEnd = 14;
esel = ESelection(0, selStart, 0, selEnd);
CPPUNIT_ASSERT_EQUAL(u"met"_ustr, editEng.GetText(esel));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones Met joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones MET joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones met joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
/* Test behavior when there is a selection that does not begin at a word boundary: "et" */
selStart = 12;
selEnd = 14;
esel = ESelection(0, selStart, 0, selEnd);
CPPUNIT_ASSERT_EQUAL(u"et"_ustr, editEng.GetText(esel));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones mEt joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones mET joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones met joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
/* Test behavior when there is a selection that ends in the middle of a word */
selStart = 11;
selEnd = 13;
esel = ESelection(0, selStart, 0, selEnd);
CPPUNIT_ASSERT_EQUAL(u"me"_ustr, editEng.GetText(esel));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones Met joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones MEt joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones met joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
/* Test behavior when there is a selection that crosses a word boundary: "nes met joe Sm" */
selStart = 7;
selEnd = 21;
esel = ESelection(0, selStart, 0, selEnd);
CPPUNIT_ASSERT_EQUAL(u"nes met joe Sm"_ustr, editEng.GetText(esel));
CPPUNIT_ASSERT_EQUAL(u"Mary JoNes met joe smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::SENTENCE_CASE));
CPPUNIT_ASSERT_EQUAL(u"Mary JoNes Met Joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
CPPUNIT_ASSERT_EQUAL(u"Mary JoNES MET JOE SMith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones met joe smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
/* Test behavior when there is a selection that crosses a sentence boundary: "joe Smith. Time Passed." */
selStart = 15;
selEnd = 38;
esel = ESelection(0, selStart, 0, selEnd);
editEng.SetText(sText2);
CPPUNIT_ASSERT_EQUAL(u"joe Smith. Time Passed."_ustr, editEng.GetText(esel));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones met Joe smith. Time passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::SENTENCE_CASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones met Joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones met JOE SMITH. TIME PASSED."_ustr, lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(u"Mary Jones met joe smith. time passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
/* Test behavior when sentence ends with a capital that is not selected: "CURRENT IS EQUAL TO 10 A" */
selStart = 0;
selEnd = 19;
esel = ESelection(0, selStart, 0, selEnd); static constexpr OUString sText3(u"CURRENT IS EQUAL TO 10 A"_ustr);
editEng.SetText(sText3);
CPPUNIT_ASSERT_EQUAL(u"CURRENT IS EQUAL TO"_ustr, editEng.GetText(esel));
CPPUNIT_ASSERT_EQUAL(u"Current is equal to 10 A"_ustr, lcl_translitTest(editEng, sText3, esel, TF::SENTENCE_CASE));
CPPUNIT_ASSERT_EQUAL(u"Current Is Equal To 10 A"_ustr, lcl_translitTest(editEng, sText3, esel, TF::TITLE_CASE));
CPPUNIT_ASSERT_EQUAL(u"CURRENT IS EQUAL TO 10 A"_ustr, lcl_translitTest(editEng, sText3, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(u"current is equal to 10 A"_ustr, lcl_translitTest(editEng, sText3, esel, TF::UPPERCASE_LOWERCASE));
}
void Test::testTdf147196()
{
EditEngine editEng( mpItemPool.get() );
editEng.SetText(u"2.2 Publication of information - CAA\nSection 4.2 of a CA\'s Certificate Policy and/or Certification Practice Statement SHALL state the CA\'s policy or practice on processing CAA Records for Fully Qualified Domain Names; that policy shall be consistent with these Requirements. \n\nIt shall clearly specify the set of Issuer Domain Names that the CA recognises in CAA \"issue\" or \"issuewild\" records as permitting it to issue. The CA SHALL log all actions taken, if any, consistent with its processing practice."_ustr);
editEng.TransliterateText(ESelection(0, 0, 3, 232), TransliterationFlags::TITLE_CASE);
CPPUNIT_ASSERT_EQUAL(u"2.2 Publication Of Information - Caa\nSection 4.2 Of A Ca\'s Certificate Policy And/Or Certification Practice Statement Shall State The Ca\'s Policy Or Practice On Processing Caa Records For Fully Qualified Domain Names; That Policy Shall Be Consistent With These Requirements. \n\nIt Shall Clearly Specify The Set Of Issuer Domain Names That The Ca Recognises In Caa \"Issue\" Or \"Issuewild\" Records As Permitting It To Issue. The Ca Shall Log All Actions Taken, If Any, Consistent With Its Processing Practice."_ustr, editEng.GetText());
}
void Test::testTdf148148()
{ using TF = TransliterationFlags;
EditEngine editEng(mpItemPool.get());
/* Test what happens when node contains text but selection does not contain any text */ int selStart = 0; int selEnd = 3;
ESelection esel(0, selStart, 0, selEnd); static constexpr OUString sText1(u" text"_ustr);
editEng.SetText(sText1);
CPPUNIT_ASSERT_EQUAL(u" "_ustr, editEng.GetText(esel));
/* Test what happens when node contains only non-word text but selection does not contain any text */
selStart = 0;
selEnd = 3;
esel = ESelection(0, selStart, 0, selEnd); static constexpr OUString sText3(u" -1"_ustr);
editEng.SetText(sText3);
CPPUNIT_ASSERT_EQUAL(u" "_ustr, editEng.GetText(esel));
// Get Field Item for inserting URLs in text
SvxURLField aURLField(u"http://not.a.real.link"_ustr,
u"Really long hyperlink text that won't fit in 1 line, no matter what."_ustr,
SvxURLFormat::Repr);
SvxFieldItem aField(aURLField, EE_FEATURE_FIELD);
ParaPortionList& rParagraphPortionList = aEditEngine.GetParaPortions();
EditLineList& rLines = rParagraphPortionList.getRef(0).GetLines();
{
EditLine const& rLine = rLines[0];
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rLine.GetStart()); // Line 1 contains the beginning of the link.
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), rLine.GetEnd());
}
{
EditLine const& rLine = rLines[1];
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), rLine.GetStart()); //Line 2 contains the end of the link and the text that follows it
CPPUNIT_ASSERT_EQUAL(sal_Int32(14), rLine.GetEnd());
}
{
EditLine const& rLine = rLines[2]; //line 3 contains the last word that does not fit in line 2
CPPUNIT_ASSERT_EQUAL(sal_Int32(14), rLine.GetStart());
CPPUNIT_ASSERT_EQUAL(sal_Int32(19), rLine.GetEnd());
}
}
// tdf#151748: Verify that editeng produces an empty kashida array if the line does not have room void Test::testTdf151748StaleKashidaArray()
{
ScopedVclPtrInstance<VirtualDevice> pVirtualDevice(DeviceFormat::WITHOUT_ALPHA);
// Initial state: Check that a kashida array has been created
{
ParaPortionList& rParagraphPortionList = aEditEngine.GetParaPortions();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), rParagraphPortionList.Count());
// Resize the paper so there is no longer room for kashida
aEditEngine.SetPaperSize(Size(1400, 500));
// Follow-up state: Check that the kashida array has been cleared
{
ParaPortionList& rParagraphPortionList = aEditEngine.GetParaPortions();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), rParagraphPortionList.Count());
// Since there is no room for kashida, the kashida array should be empty. // Without the bug fix, this will be 17:
CPPUNIT_ASSERT_EQUAL(size_t(0), rArray.size());
}
}
// tdf#162803: Verify that editeng clears stale kashida data during layout void Test::testTdf162803StaleKashidaArray()
{
ScopedVclPtrInstance<VirtualDevice> pVirtualDevice(DeviceFormat::WITHOUT_ALPHA);
// Initial state: Check that a kashida array has been created
{
ParaPortionList& rParagraphPortionList = aEditEngine.GetParaPortions();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), rParagraphPortionList.Count());
// Resize the paper so the entire text fits on a single line
aEditEngine.SetPaperSize(Size(4000, 500));
// Follow-up state: Check that the kashida array has been cleared
{
ParaPortionList& rParagraphPortionList = aEditEngine.GetParaPortions();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), rParagraphPortionList.Count());
// Since there is no room for kashida, the kashida array should be empty. // Without the bug fix, this will be 17:
CPPUNIT_ASSERT_EQUAL(size_t(0), rArray.size());
}
}
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.