LibreOffice Module starmath (master) 1
smediteng.cxx
Go to the documentation of this file.
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 <vcl/outdev.hxx>
21#include <vcl/svapp.hxx>
22
24 : EditEngine(pItemPool)
25 , m_nOldZoom(100)
26 , m_nNewZoom(100)
27 , m_nDefaultFontSize(0)
28 , m_aAllSelection(0, 0, 0, 0)
29{
30 SetText(u"");
31
32 // Add external text leading
33 SetAddExtLeading(true);
34
35 // Allow to undo changes ( Ctrl + z )
36 EnableUndo(true);
37
38 // Length in pixel of a tabulation
39 SetDefTab(sal_uInt16(Application::GetDefaultDevice()->GetTextWidth("XXXX")));
40
41 // Set default background color by theme
43 Application::GetDefaultDevice()->GetSettings().GetStyleSettings().GetFieldColor());
44
45 // Control words
46 SetControlWord((GetControlWord() | EEControlBits::AUTOINDENTING)
47 & EEControlBits(~EEControlBits::UNDOATTRIBS)
48 & EEControlBits(~EEControlBits::PASTESPECIAL));
49
50 // Word delimiters for auto word selection by double click
51 SetWordDelimiters(" .=+-*/(){}[];\"");
52
53 // Default mapping mode
54 SetRefMapMode(MapMode(MapUnit::MapPixel));
55
56 // Default size of the box
57 SetPaperSize(Size(1000, 0));
58}
59
61{
62 return m_nOldZoom != (m_nNewZoom = SM_MOD()->GetConfig()->GetSmEditWindowZoomFactor());
63}
64
66{
67 if (checkZoom())
68 {
69 updateZoom();
70 if (pEditView)
71 {
72 FormatAndLayout(pEditView);
73 pEditView->SetSelection(pEditView->GetSelection());
74 }
75 }
76}
77
79{
80 // In first run get font size as base to scale
81 if (m_nDefaultFontSize == 0)
82 {
83 SfxItemSet sfxatts = GetAttribs(0, 0, 0, GetAttribsFlags::CHARATTRIBS);
84 const SvxFontHeightItem* sfxattsh = sfxatts.GetItem(EE_CHAR_FONTHEIGHT);
85 m_nDefaultFontSize = sfxattsh->GetHeight();
86 }
87
88 // Now we calculate the new font size
89 sal_Int32 nNewFontSize = m_nDefaultFontSize * m_nNewZoom / 100;
90
91 // We apply the new font size to all the text
92 updateAllESelection(); // Update length of the text
94 aSet.Put(SvxFontHeightItem(nNewFontSize, 100, EE_CHAR_FONTHEIGHT));
96
97 // We don't forget to equalize the zoomvalues
99}
100
102{
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;
107}
108
109void SmEditEngine::setSmItemPool(SfxItemPool* mpItemPool, const SvtLinguOptions& maLangOptions)
110{
111 // Set fonts to be used
112 struct FontData
113 {
114 LanguageType nFallbackLang;
115 LanguageType nLang;
116 DefaultFontType nFontType;
117 sal_uInt16 nFontInfoId;
118 };
119
120 FontData aFontDataTable[3]
121 = { // info to get western font to be used
122 { LANGUAGE_ENGLISH_US, maLangOptions.nDefaultLanguage, DefaultFontType::FIXED,
124 // info to get CJK font to be used
125 { LANGUAGE_JAPANESE, maLangOptions.nDefaultLanguage_CJK, DefaultFontType::CJK_TEXT,
127 // info to get CTL font to be used
129 DefaultFontType::CTL_TEXT, EE_CHAR_FONTINFO_CTL }
130 };
131
132 // Text color
133 auto aDefaultDevice = Application::GetDefaultDevice();
134 Color aTextColor = aDefaultDevice->GetSettings().GetStyleSettings().GetFieldTextColor();
135 for (const FontData& aFontData : aFontDataTable)
136 {
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));
145 }
146
147 // Set font heights
148 SvxFontHeightItem aFontHeight(
149 aDefaultDevice->LogicToPixel(Size(0, 11), MapMode(MapUnit::MapPoint)).Height(), 100,
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);
156}
157
158/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
static OutputDevice * GetDefaultDevice()
void SetWordDelimiters(const OUString &rDelimiters)
void SetText(const OUString &rStr)
void SetAddExtLeading(bool b)
EEControlBits GetControlWord() const
sal_Int32 GetParagraphCount() const
void EnableUndo(bool bEnable)
SfxItemSet GetAttribs(sal_Int32 nPara, sal_Int32 nStart, sal_Int32 nEnd, GetAttribsFlags nFlags=GetAttribsFlags::ALL) const
sal_Int32 GetTextLen() const
void SetRefMapMode(const MapMode &rMapMode)
const SfxItemSet & GetEmptyItemSet() const
void SetControlWord(EEControlBits nWord)
void SetPaperSize(const Size &rSize)
void QuickSetAttribs(const SfxItemSet &rSet, const ESelection &rSel)
void FormatAndLayout(EditView *pCurView, bool bCalledFromUndo=false)
void SetBackgroundColor(const Color &rColor)
void SetDefTab(sal_uInt16 nDefTab)
ESelection GetSelection() const
void SetSelection(const ESelection &rNewSel)
static vcl::Font GetDefaultFont(DefaultFontType nType, LanguageType eLang, GetDefaultFontFlags nFlags, const OutputDevice *pOutDev=nullptr)
void SetPoolDefaultItem(const SfxPoolItem &)
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void executeZoom(EditView *pEditView=nullptr)
Runs checkZoom and if true runs updateZoom.
Definition: smediteng.cxx:65
sal_Int32 m_nOldZoom
Definition: smediteng.hxx:32
sal_Int32 m_nNewZoom
Definition: smediteng.hxx:33
ESelection m_aAllSelection
Definition: smediteng.hxx:52
static void setSmItemPool(SfxItemPool *mpItemPool, const SvtLinguOptions &maLangOptions)
Sets up default font parameters for the item pool.
Definition: smediteng.cxx:109
void updateAllESelection()
Finds the ESelection which contains all the text.
Definition: smediteng.cxx:101
bool checkZoom()
Checks if the zoom of smeditwindow has changed.
Definition: smediteng.cxx:60
sal_Int32 m_nDefaultFontSize
Definition: smediteng.hxx:34
void updateZoom()
Updates the zoom of smeditwindow.
Definition: smediteng.cxx:78
SmEditEngine(SfxItemPool *pItemPool)
Definition: smediteng.cxx:23
sal_uInt32 GetHeight() const
void SetColor(const Color &)
float u
EEControlBits
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO_CJK(EE_CHAR_START+17)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT(EE_CHAR_START+2)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CTL(EE_CHAR_START+20)
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO_CTL(EE_CHAR_START+18)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CJK(EE_CHAR_START+19)
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO(EE_CHAR_START+1)
DefaultFontType
#define LANGUAGE_NONE
#define LANGUAGE_JAPANESE
#define LANGUAGE_ARABIC_SAUDI_ARABIA
#define LANGUAGE_ENGLISH_US
#define SM_MOD()
Definition: smmod.hxx:98
sal_Int32 nEndPos
sal_Int32 nEndPara
LanguageType nDefaultLanguage
LanguageType nDefaultLanguage_CTL
LanguageType nDefaultLanguage_CJK