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(u
"/sd/qa/unit/data/"_ustr
)
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(1.0, pTextObject
->GetFontScale(), 1E-4);
48 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, pTextObject
->GetSpacingScale(), 1E-4);
51 OutlinerParaObject
* pOutlinerParagraphObject
= pTextObject
->GetOutlinerParaObject();
52 const EditTextObject
& aEdit
= pOutlinerParagraphObject
->GetTextObject();
53 CPPUNIT_ASSERT_EQUAL(u
"D1"_ustr
, aEdit
.GetText(0));
54 CPPUNIT_ASSERT_EQUAL(u
"D2"_ustr
, aEdit
.GetText(1));
55 CPPUNIT_ASSERT_EQUAL(u
"D3"_ustr
, 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& rEditEngine
= rEditView
.getEditEngine();
68 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), rEditEngine
.GetParagraphCount());
71 rEditView
.SetSelection(ESelection(3, 0));
72 rEditView
.InsertText(u
"\nD4"_ustr
);
73 Scheduler::ProcessEventsToIdle();
74 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), rEditEngine
.GetParagraphCount());
76 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.925, rEditEngine
.getScalingParameters().fFontY
, 1E-4);
77 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8, rEditEngine
.getScalingParameters().fSpacingY
, 1E-4);
80 rEditView
.SetSelection(ESelection(4, 0));
81 rEditView
.InsertText(u
"\nD5"_ustr
);
82 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), rEditEngine
.GetParagraphCount());
84 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.7, rEditEngine
.getScalingParameters().fFontY
, 1E-4);
85 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8, rEditEngine
.getScalingParameters().fSpacingY
, 1E-4);
88 rEditView
.SetSelection(ESelection(5, 0));
89 rEditView
.InsertText(u
"\nD6"_ustr
);
90 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), rEditEngine
.GetParagraphCount());
93 rEditView
.SetSelection(ESelection(4, EE_TEXTPOS_MAX
, 5, EE_TEXTPOS_MAX
));
94 rEditView
.DeleteSelected();
95 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), rEditEngine
.GetParagraphCount());
98 rEditView
.SetSelection(ESelection(3, EE_TEXTPOS_MAX
, 4, EE_TEXTPOS_MAX
));
99 rEditView
.DeleteSelected();
100 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), rEditEngine
.GetParagraphCount());
102 // Delete paragraph 4
103 rEditView
.SetSelection(ESelection(2, EE_TEXTPOS_MAX
, 3, EE_TEXTPOS_MAX
));
104 rEditView
.DeleteSelected();
105 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), rEditEngine
.GetParagraphCount());
107 // not ideal - scaling should be 100%, but close enough
108 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, rEditEngine
.getScalingParameters().fFontY
, 1E-4);
109 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, rEditEngine
.getScalingParameters().fSpacingY
, 1E-4);
111 // are we still in text edit mode?
112 CPPUNIT_ASSERT_EQUAL(true, pView1
->IsTextEdit());
113 pView1
->SdrEndTextEdit();
114 CPPUNIT_ASSERT_EQUAL(false, pView1
->IsTextEdit());
116 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, pTextObject
->GetFontScale(), 1E-4);
117 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, pTextObject
->GetSpacingScale(), 1E-4);
120 CPPUNIT_PLUGIN_IMPLEMENT();
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */