/src/libreoffice/starmath/source/smediteng.cxx
Line | Count | Source |
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. |
4 | | * |
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> |
12 | | |
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 <unotools/fontdefs.hxx> |
21 | | #include <vcl/outdev.hxx> |
22 | | #include <vcl/rendercontext/GetDefaultFontFlags.hxx> |
23 | | #include <vcl/svapp.hxx> |
24 | | |
25 | | SmEditEngine::SmEditEngine(SfxItemPool* pItemPool) |
26 | 0 | : EditEngine(pItemPool) |
27 | 0 | , m_nOldZoom(100) |
28 | 0 | , m_nNewZoom(100) |
29 | 0 | , m_nDefaultFontSize(0) |
30 | 0 | , m_aAllSelection(0, 0, 0, 0) |
31 | 0 | { |
32 | 0 | SetText(u""_ustr); |
33 | | |
34 | | // Add external text leading |
35 | 0 | SetAddExtLeading(true); |
36 | | |
37 | | // Allow to undo changes ( Ctrl + z ) |
38 | 0 | EnableUndo(true); |
39 | | |
40 | | // Length in pixel of a tabulation |
41 | 0 | SetDefTab(sal_uInt16(Application::GetDefaultDevice()->GetTextWidth(u"XXXX"_ustr))); |
42 | | |
43 | | // Set default background color by theme |
44 | 0 | SetBackgroundColor( |
45 | 0 | Application::GetDefaultDevice()->GetSettings().GetStyleSettings().GetFieldColor()); |
46 | | |
47 | | // Control words |
48 | 0 | SetControlWord((GetControlWord() | EEControlBits::AUTOINDENTING) |
49 | 0 | & EEControlBits(~EEControlBits::UNDOATTRIBS) |
50 | 0 | & EEControlBits(~EEControlBits::PASTESPECIAL)); |
51 | | |
52 | | // Word delimiters for auto word selection by double click |
53 | 0 | SetWordDelimiters(u" .=+-*/(){}[];\""_ustr); |
54 | | |
55 | | // Default mapping mode |
56 | 0 | SetRefMapMode(MapMode(MapUnit::MapPixel)); |
57 | | |
58 | | // Default size of the box |
59 | 0 | SetPaperSize(Size(1000, 0)); |
60 | 0 | } |
61 | | |
62 | | bool SmEditEngine::checkZoom() |
63 | 0 | { |
64 | 0 | return m_nOldZoom != (m_nNewZoom = SmModule::get()->GetConfig()->GetSmEditWindowZoomFactor()); |
65 | 0 | } |
66 | | |
67 | | void SmEditEngine::executeZoom(EditView* pEditView) |
68 | 0 | { |
69 | 0 | if (checkZoom()) |
70 | 0 | { |
71 | 0 | updateZoom(); |
72 | 0 | if (pEditView) |
73 | 0 | { |
74 | 0 | FormatAndLayout(pEditView); |
75 | 0 | pEditView->SetSelection(pEditView->GetSelection()); |
76 | 0 | } |
77 | 0 | } |
78 | 0 | } |
79 | | |
80 | | void SmEditEngine::updateZoom() |
81 | 0 | { |
82 | | // In first run get font size as base to scale |
83 | 0 | if (m_nDefaultFontSize == 0) |
84 | 0 | { |
85 | 0 | SfxItemSet sfxatts = GetAttribs(0, 0, 0, GetAttribsFlags::CHARATTRIBS); |
86 | 0 | const SvxFontHeightItem* sfxattsh = sfxatts.GetItem(EE_CHAR_FONTHEIGHT); |
87 | 0 | m_nDefaultFontSize = sfxattsh->GetHeight(); |
88 | 0 | } |
89 | | |
90 | | // Now we calculate the new font size |
91 | 0 | sal_Int32 nNewFontSize = m_nDefaultFontSize * m_nNewZoom / 100; |
92 | | |
93 | | // We apply the new font size to all the text |
94 | 0 | updateAllESelection(); // Update length of the text |
95 | 0 | SfxItemSet aSet = GetEmptyItemSet(); |
96 | 0 | aSet.Put(SvxFontHeightItem(nNewFontSize, 100, EE_CHAR_FONTHEIGHT)); |
97 | 0 | QuickSetAttribs(aSet, m_aAllSelection); |
98 | | |
99 | | // We don't forget to equalize the zoomvalues |
100 | 0 | m_nOldZoom = m_nNewZoom; |
101 | 0 | } |
102 | | |
103 | | void SmEditEngine::updateAllESelection() |
104 | 0 | { |
105 | 0 | sal_Int32 paracount = GetParagraphCount(); |
106 | 0 | m_aAllSelection.end.nPara = paracount > 0 ? paracount - 1 : 0; |
107 | 0 | sal_Int32 textlength = GetTextLen(m_aAllSelection.end.nPara); |
108 | 0 | m_aAllSelection.end.nIndex = textlength > 0 ? textlength : 0; |
109 | 0 | } |
110 | | |
111 | | void SmEditEngine::setSmItemPool(SfxItemPool* mpItemPool, const SvtLinguOptions& maLangOptions) |
112 | 0 | { |
113 | | // Set fonts to be used |
114 | 0 | struct FontData |
115 | 0 | { |
116 | 0 | LanguageType nFallbackLang; |
117 | 0 | LanguageType nLang; |
118 | 0 | DefaultFontType nFontType; |
119 | 0 | sal_uInt16 nFontInfoId; |
120 | 0 | }; |
121 | |
|
122 | 0 | FontData aFontDataTable[3] |
123 | 0 | = { // info to get western font to be used |
124 | 0 | { LANGUAGE_ENGLISH_US, maLangOptions.nDefaultLanguage, DefaultFontType::FIXED, |
125 | 0 | EE_CHAR_FONTINFO }, |
126 | | // info to get CJK font to be used |
127 | 0 | { LANGUAGE_JAPANESE, maLangOptions.nDefaultLanguage_CJK, DefaultFontType::CJK_TEXT, |
128 | 0 | EE_CHAR_FONTINFO_CJK }, |
129 | | // info to get CTL font to be used |
130 | 0 | { LANGUAGE_ARABIC_SAUDI_ARABIA, maLangOptions.nDefaultLanguage_CTL, |
131 | 0 | DefaultFontType::CTL_TEXT, EE_CHAR_FONTINFO_CTL } |
132 | 0 | }; |
133 | | |
134 | | // Text color |
135 | 0 | auto aDefaultDevice = Application::GetDefaultDevice(); |
136 | 0 | Color aTextColor = aDefaultDevice->GetSettings().GetStyleSettings().GetFieldTextColor(); |
137 | 0 | for (const FontData& aFontData : aFontDataTable) |
138 | 0 | { |
139 | 0 | LanguageType nLang |
140 | 0 | = (LANGUAGE_NONE == aFontData.nLang) ? aFontData.nFallbackLang : aFontData.nLang; |
141 | 0 | vcl::Font aFont = OutputDevice::GetDefaultFont(aFontData.nFontType, nLang, |
142 | 0 | GetDefaultFontFlags::OnlyOne); |
143 | 0 | aFont.SetColor(aTextColor); |
144 | 0 | mpItemPool->SetUserDefaultItem(SvxFontItem( |
145 | 0 | aFont.GetFamilyTypeMaybeAskConfig(), aFont.GetFamilyName(), aFont.GetStyleName(), |
146 | 0 | aFont.GetPitchMaybeAskConfig(), aFont.GetCharSet(), aFontData.nFontInfoId)); |
147 | 0 | } |
148 | | |
149 | | // Set font heights |
150 | 0 | SvxFontHeightItem aFontHeight( |
151 | 0 | aDefaultDevice->LogicToPixel(Size(0, 11), MapMode(MapUnit::MapPoint)).Height(), 100, |
152 | 0 | EE_CHAR_FONTHEIGHT); |
153 | 0 | mpItemPool->SetUserDefaultItem(aFontHeight); |
154 | 0 | aFontHeight.SetWhich(EE_CHAR_FONTHEIGHT_CJK); |
155 | 0 | mpItemPool->SetUserDefaultItem(aFontHeight); |
156 | 0 | aFontHeight.SetWhich(EE_CHAR_FONTHEIGHT_CTL); |
157 | 0 | mpItemPool->SetUserDefaultItem(aFontHeight); |
158 | 0 | } |
159 | | |
160 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |