bump product version to 7.6.3.2-android
[LibreOffice.git] / starmath / source / smediteng.cxx
blob5560d501ef5a33998d2d3eae9cbaf96eb9a890e1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
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/.
8 */
9 #include <smediteng.hxx>
10 #include <smmod.hxx>
11 #include <cfgitem.hxx>
13 #include <vcl/settings.hxx>
14 #include <editeng/editview.hxx>
15 #include <editeng/eeitem.hxx>
16 #include <editeng/fhgtitem.hxx>
17 #include <editeng/fontitem.hxx>
18 #include <svl/itempool.hxx>
19 #include <svl/itemset.hxx>
20 #include <vcl/outdev.hxx>
21 #include <vcl/svapp.hxx>
23 SmEditEngine::SmEditEngine(SfxItemPool* pItemPool)
24 : EditEngine(pItemPool)
25 , m_nOldZoom(100)
26 , m_nNewZoom(100)
27 , m_nDefaultFontSize(0)
28 , m_aAllSelection(0, 0, 0, 0)
30 SetText(u"");
32 // Add external text leading
33 SetAddExtLeading(true);
35 // Allow to undo changes ( Ctrl + z )
36 EnableUndo(true);
38 // Length in pixel of a tabulation
39 SetDefTab(sal_uInt16(Application::GetDefaultDevice()->GetTextWidth("XXXX")));
41 // Set default background color by theme
42 SetBackgroundColor(
43 Application::GetDefaultDevice()->GetSettings().GetStyleSettings().GetFieldColor());
45 // Control words
46 SetControlWord((GetControlWord() | EEControlBits::AUTOINDENTING)
47 & EEControlBits(~EEControlBits::UNDOATTRIBS)
48 & EEControlBits(~EEControlBits::PASTESPECIAL));
50 // Word delimiters for auto word selection by double click
51 SetWordDelimiters(" .=+-*/(){}[];\"");
53 // Default mapping mode
54 SetRefMapMode(MapMode(MapUnit::MapPixel));
56 // Default size of the box
57 SetPaperSize(Size(1000, 0));
60 bool SmEditEngine::checkZoom()
62 return m_nOldZoom != (m_nNewZoom = SM_MOD()->GetConfig()->GetSmEditWindowZoomFactor());
65 void SmEditEngine::executeZoom(EditView* pEditView)
67 if (checkZoom())
69 updateZoom();
70 if (pEditView)
72 FormatAndLayout(pEditView);
73 pEditView->SetSelection(pEditView->GetSelection());
78 void SmEditEngine::updateZoom()
80 // In first run get font size as base to scale
81 if (m_nDefaultFontSize == 0)
83 SfxItemSet sfxatts = GetAttribs(0, 0, 0, GetAttribsFlags::CHARATTRIBS);
84 const SvxFontHeightItem* sfxattsh = sfxatts.GetItem(EE_CHAR_FONTHEIGHT);
85 m_nDefaultFontSize = sfxattsh->GetHeight();
88 // Now we calculate the new font size
89 sal_Int32 nNewFontSize = m_nDefaultFontSize * m_nNewZoom / 100;
91 // We apply the new font size to all the text
92 updateAllESelection(); // Update length of the text
93 SfxItemSet aSet = GetEmptyItemSet();
94 aSet.Put(SvxFontHeightItem(nNewFontSize, 100, EE_CHAR_FONTHEIGHT));
95 QuickSetAttribs(aSet, m_aAllSelection);
97 // We don't forget to equalize the zoomvalues
98 m_nOldZoom = m_nNewZoom;
101 void SmEditEngine::updateAllESelection()
103 sal_Int32 paracount = GetParagraphCount();
104 m_aAllSelection.nEndPara = paracount > 0 ? paracount - 1 : 0;
105 sal_Int32 textlength = GetTextLen(m_aAllSelection.nEndPara);
106 m_aAllSelection.nEndPos = textlength > 0 ? textlength : 0;
109 void SmEditEngine::setSmItemPool(SfxItemPool* mpItemPool, const SvtLinguOptions& maLangOptions)
111 // Set fonts to be used
112 struct FontData
114 LanguageType nFallbackLang;
115 LanguageType nLang;
116 DefaultFontType nFontType;
117 sal_uInt16 nFontInfoId;
120 FontData aFontDataTable[3]
121 = { // info to get western font to be used
122 { LANGUAGE_ENGLISH_US, maLangOptions.nDefaultLanguage, DefaultFontType::FIXED,
123 EE_CHAR_FONTINFO },
124 // info to get CJK font to be used
125 { LANGUAGE_JAPANESE, maLangOptions.nDefaultLanguage_CJK, DefaultFontType::CJK_TEXT,
126 EE_CHAR_FONTINFO_CJK },
127 // info to get CTL font to be used
128 { LANGUAGE_ARABIC_SAUDI_ARABIA, maLangOptions.nDefaultLanguage_CTL,
129 DefaultFontType::CTL_TEXT, EE_CHAR_FONTINFO_CTL }
132 // Text color
133 auto aDefaultDevice = Application::GetDefaultDevice();
134 Color aTextColor = aDefaultDevice->GetSettings().GetStyleSettings().GetFieldTextColor();
135 for (const FontData& aFontData : aFontDataTable)
137 LanguageType nLang
138 = (LANGUAGE_NONE == aFontData.nLang) ? aFontData.nFallbackLang : aFontData.nLang;
139 vcl::Font aFont = OutputDevice::GetDefaultFont(aFontData.nFontType, nLang,
140 GetDefaultFontFlags::OnlyOne);
141 aFont.SetColor(aTextColor);
142 mpItemPool->SetPoolDefaultItem(SvxFontItem(aFont.GetFamilyType(), aFont.GetFamilyName(),
143 aFont.GetStyleName(), aFont.GetPitch(),
144 aFont.GetCharSet(), aFontData.nFontInfoId));
147 // Set font heights
148 SvxFontHeightItem aFontHeight(
149 aDefaultDevice->LogicToPixel(Size(0, 11), MapMode(MapUnit::MapPoint)).Height(), 100,
150 EE_CHAR_FONTHEIGHT);
151 mpItemPool->SetPoolDefaultItem(aFontHeight);
152 aFontHeight.SetWhich(EE_CHAR_FONTHEIGHT_CJK);
153 mpItemPool->SetPoolDefaultItem(aFontHeight);
154 aFontHeight.SetWhich(EE_CHAR_FONTHEIGHT_CTL);
155 mpItemPool->SetPoolDefaultItem(aFontHeight);
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */