/* -*- 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]));
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.