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 "sdmodeltestbase.hxx"
12 #include <com/sun/star/frame/Desktop.hpp>
14 #include <vcl/scheduler.hxx>
15 #include <svx/svdview.hxx>
16 #include <svx/svdpagv.hxx>
17 #include <editeng/editeng.hxx>
18 #include <editeng/editobj.hxx>
20 #include <DrawDocShell.hxx>
21 #include <unomodel.hxx>
23 #include <ViewShell.hxx>
27 class TextFittingTest
: public SdModelTestBase
31 : SdModelTestBase("/sd/qa/unit/data/")
36 CPPUNIT_TEST_FIXTURE(TextFittingTest
, testTest
)
38 createSdImpressDoc("TextFitting.odp");
40 SdXImpressDocument
* pXImpressDocument
= dynamic_cast<SdXImpressDocument
*>(mxComponent
.get());
41 CPPUNIT_ASSERT(pXImpressDocument
);
42 sd::ViewShell
* pViewShell
= pXImpressDocument
->GetDocShell()->GetViewShell();
43 SdPage
* pPage
= pViewShell
->GetActualPage();
44 auto pTextObject
= DynCastSdrTextObj(pPage
->GetObj(0));
45 CPPUNIT_ASSERT(pTextObject
);
47 CPPUNIT_ASSERT_DOUBLES_EQUAL(100.0, pTextObject
->GetFontScale(), 1E-2);
48 CPPUNIT_ASSERT_DOUBLES_EQUAL(100.0, pTextObject
->GetSpacingScale(), 1E-2);
51 OutlinerParaObject
* pOutlinerParagraphObject
= pTextObject
->GetOutlinerParaObject();
52 const EditTextObject
& aEdit
= pOutlinerParagraphObject
->GetTextObject();
53 CPPUNIT_ASSERT_EQUAL(OUString(u
"D1"), aEdit
.GetText(0));
54 CPPUNIT_ASSERT_EQUAL(OUString(u
"D2"), aEdit
.GetText(1));
55 CPPUNIT_ASSERT_EQUAL(OUString(u
"D3"), aEdit
.GetText(2));
58 sd::ViewShell
* pViewShell1
= pXImpressDocument
->GetDocShell()->GetViewShell();
59 SdrView
* pView1
= pViewShell1
->GetView();
60 Scheduler::ProcessEventsToIdle();
61 pView1
->SdrBeginTextEdit(pTextObject
);
62 CPPUNIT_ASSERT_EQUAL(true, pView1
->IsTextEdit());
64 auto* pOLV
= pView1
->GetTextEditOutlinerView();
66 auto& rEditView
= pOLV
->GetEditView();
67 auto* pEditEngine
= rEditView
.GetEditEngine();
68 CPPUNIT_ASSERT(pEditEngine
);
69 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), pEditEngine
->GetParagraphCount());
72 rEditView
.SetSelection(ESelection(3, 0, 3, 0));
73 rEditView
.InsertText(u
"\nD4");
74 Scheduler::ProcessEventsToIdle();
75 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), pEditEngine
->GetParagraphCount());
77 CPPUNIT_ASSERT_DOUBLES_EQUAL(87.49, pEditEngine
->getGlobalFontScale().getY(), 1E-2);
78 CPPUNIT_ASSERT_DOUBLES_EQUAL(90.0, pEditEngine
->getGlobalSpacingScale().getY(), 1E-2);
81 rEditView
.SetSelection(ESelection(4, 0, 4, 0));
82 rEditView
.InsertText(u
"\nD5");
83 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), pEditEngine
->GetParagraphCount());
85 CPPUNIT_ASSERT_DOUBLES_EQUAL(54.68, pEditEngine
->getGlobalFontScale().getY(), 1E-2);
86 CPPUNIT_ASSERT_DOUBLES_EQUAL(100.0, pEditEngine
->getGlobalSpacingScale().getY(), 1E-2);
89 rEditView
.SetSelection(ESelection(5, 0, 5, 0));
90 rEditView
.InsertText(u
"\nD6");
91 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), pEditEngine
->GetParagraphCount());
94 rEditView
.SetSelection(ESelection(4, EE_TEXTPOS_MAX_COUNT
, 5, EE_TEXTPOS_MAX_COUNT
));
95 rEditView
.DeleteSelected();
96 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), pEditEngine
->GetParagraphCount());
99 rEditView
.SetSelection(ESelection(3, EE_TEXTPOS_MAX_COUNT
, 4, EE_TEXTPOS_MAX_COUNT
));
100 rEditView
.DeleteSelected();
101 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), pEditEngine
->GetParagraphCount());
103 // Delete paragraph 4
104 rEditView
.SetSelection(ESelection(2, EE_TEXTPOS_MAX_COUNT
, 3, EE_TEXTPOS_MAX_COUNT
));
105 rEditView
.DeleteSelected();
106 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), pEditEngine
->GetParagraphCount());
108 // not ideal - scaling should be 100%, but close enough
109 CPPUNIT_ASSERT_DOUBLES_EQUAL(99.05, pEditEngine
->getGlobalFontScale().getY(), 1E-2);
110 CPPUNIT_ASSERT_DOUBLES_EQUAL(100.0, pEditEngine
->getGlobalSpacingScale().getY(), 1E-2);
112 // are we still in text edit mode?
113 CPPUNIT_ASSERT_EQUAL(true, pView1
->IsTextEdit());
114 pView1
->SdrEndTextEdit();
115 CPPUNIT_ASSERT_EQUAL(false, pView1
->IsTextEdit());
117 CPPUNIT_ASSERT_DOUBLES_EQUAL(100.0, pTextObject
->GetFontScale(), 1E-2);
118 CPPUNIT_ASSERT_DOUBLES_EQUAL(100.0, pTextObject
->GetSpacingScale(), 1E-2);
121 CPPUNIT_PLUGIN_IMPLEMENT();
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */