1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20 #pragma once
21
22 #include <editeng/eeitem.hxx>
23 #include <svl/poolitem.hxx>
24 #include <optional>
25 #include <tools/color.hxx>
26 #include <tools/debug.hxx>
27
28 class SvxFont;
29 class SvxFontItem;
30 class SvxWeightItem;
31 class SvxPostureItem;
32 class SvxShadowedItem;
33 class SvxEscapementItem;
34 class SvxContourItem;
35 class SvxCrossedOutItem;
36 class SvxUnderlineItem;
37 class SvxOverlineItem;
38 class SvxFontHeightItem;
39 class SvxCharScaleWidthItem;
40 class SvxColorItem;
41 class SvxAutoKernItem;
42 class SvxKerningItem;
43 class SvxWordLineModeItem;
44 class SvxFieldItem;
45 class SvxLanguageItem;
46 class SvxEmphasisMarkItem;
47 class SvxCharReliefItem;
48 class SfxVoidItem;
49 class OutputDevice;
50 class SvxCaseMapItem;
51 class SfxGrabBagItem;
52
53 #define CH_FEATURE_OLD (sal_uInt8) 0xFF
54 #define CH_FEATURE u'\x0001'
55
56 // DEF_METRIC: For my pool, the DefMetric should always appear when
57 // GetMetric (nWhich)!
58 // => To determine the DefMetric simply use GetMetric(0)
59 #define DEF_METRIC 0
60
61
62
63 // bFeature: Attribute must not expand/shrink, length is always 1
64 // bEdge: Attribute will not expand, if you want to expand just on the edge
65 class EditCharAttrib
66 {
67 const SfxPoolItem* pItem;
68
69 sal_Int32 nStart;
70 sal_Int32 nEnd;
71 bool bFeature :1;
72 bool bEdge :1;
73
74 public:
75 EditCharAttrib( const SfxPoolItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
76 virtual ~EditCharAttrib();
77
78 EditCharAttrib(const EditCharAttrib&) = delete;
79 EditCharAttrib& operator=(const EditCharAttrib&) = delete;
80
81 void dumpAsXml(xmlTextWriterPtr pWriter) const;
82
Which() const83 sal_uInt16 Which() const { return pItem->Which(); }
GetItem() const84 const SfxPoolItem* GetItem() const { return pItem; }
85
GetStart()86 sal_Int32& GetStart() { return nStart; }
GetEnd()87 sal_Int32& GetEnd() { return nEnd; }
88
GetStart() const89 sal_Int32 GetStart() const { return nStart; }
GetEnd() const90 sal_Int32 GetEnd() const { return nEnd; }
91
92 inline sal_Int32 GetLen() const;
93
94 inline void MoveForward( sal_Int32 nDiff );
95 inline void MoveBackward( sal_Int32 nDiff );
96
97 inline void Expand( sal_Int32 nDiff );
98 inline void Collaps( sal_Int32 nDiff );
99
100 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev );
101
IsIn(sal_Int32 nIndex) const102 bool IsIn( sal_Int32 nIndex ) const
103 { return ( ( nStart <= nIndex ) && ( nEnd >= nIndex ) ); }
IsInside(sal_Int32 nIndex) const104 bool IsInside( sal_Int32 nIndex ) const
105 { return ( ( nStart < nIndex ) && ( nEnd > nIndex ) ); }
IsEmpty() const106 bool IsEmpty() const
107 { return nStart == nEnd; }
108
IsFeature() const109 bool IsFeature() const { return bFeature; }
SetFeature(bool b)110 void SetFeature( bool b) { bFeature = b; }
111
IsEdge() const112 bool IsEdge() const { return bEdge; }
SetEdge(bool b)113 void SetEdge( bool b ) { bEdge = b; }
114 };
115
GetLen() const116 inline sal_Int32 EditCharAttrib::GetLen() const
117 {
118 DBG_ASSERT( nEnd >= nStart, "EditCharAttrib: nEnd < nStart!" );
119 return nEnd-nStart;
120 }
121
MoveForward(sal_Int32 nDiff)122 inline void EditCharAttrib::MoveForward( sal_Int32 nDiff )
123 {
124 DBG_ASSERT( SAL_MAX_INT32 - nDiff > nEnd, "EditCharAttrib: MoveForward?!" );
125 nStart = nStart + nDiff;
126 nEnd = nEnd + nDiff;
127 }
128
MoveBackward(sal_Int32 nDiff)129 inline void EditCharAttrib::MoveBackward( sal_Int32 nDiff )
130 {
131 DBG_ASSERT( (nStart - nDiff) >= 0, "EditCharAttrib: MoveBackward?!" );
132 nStart = nStart - nDiff;
133 nEnd = nEnd - nDiff;
134 }
135
Expand(sal_Int32 nDiff)136 inline void EditCharAttrib::Expand( sal_Int32 nDiff )
137 {
138 DBG_ASSERT( SAL_MAX_INT32 - nDiff > nEnd, "EditCharAttrib: Expand?!" );
139 DBG_ASSERT( !bFeature, "Please do not expand any features!" );
140 nEnd = nEnd + nDiff;
141 }
142
Collaps(sal_Int32 nDiff)143 inline void EditCharAttrib::Collaps( sal_Int32 nDiff )
144 {
145 DBG_ASSERT( nEnd - nDiff >= nStart, "EditCharAttrib: Collaps?!" );
146 DBG_ASSERT( !bFeature, "Please do not shrink any Features!" );
147 nEnd = nEnd - nDiff;
148 }
149
150
151
152 class EditCharAttribFont final : public EditCharAttrib
153 {
154 public:
155 EditCharAttribFont( const SvxFontItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
156
157 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
158 };
159
160
161
162 class EditCharAttribWeight final : public EditCharAttrib
163 {
164 public:
165 EditCharAttribWeight( const SvxWeightItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
166
167 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
168 };
169
170
171 class EditCharAttribItalic final : public EditCharAttrib
172 {
173 public:
174 EditCharAttribItalic( const SvxPostureItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
175
176 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
177 };
178
179
180
181 class EditCharAttribShadow final : public EditCharAttrib
182 {
183 public:
184 EditCharAttribShadow( const SvxShadowedItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
185
186 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
187 };
188
189
190
191 class EditCharAttribEscapement final : public EditCharAttrib
192 {
193 public:
194 EditCharAttribEscapement( const SvxEscapementItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
195
196 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
197 };
198
199
200
201 class EditCharAttribOutline final : public EditCharAttrib
202 {
203 public:
204 EditCharAttribOutline( const SvxContourItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
205
206 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
207 };
208
209
210
211 class EditCharAttribStrikeout final : public EditCharAttrib
212 {
213 public:
214 EditCharAttribStrikeout( const SvxCrossedOutItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
215
216 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
217 };
218
219
220
221 class EditCharAttribCaseMap final : public EditCharAttrib
222 {
223 public:
224 EditCharAttribCaseMap( const SvxCaseMapItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
225
226 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
227 };
228
229
230
231 class EditCharAttribUnderline final : public EditCharAttrib
232 {
233 public:
234 EditCharAttribUnderline( const SvxUnderlineItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
235
236 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
237 };
238
239
240
241 class EditCharAttribOverline final : public EditCharAttrib
242 {
243 public:
244 EditCharAttribOverline( const SvxOverlineItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
245
246 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
247 };
248
249
250
251 class EditCharAttribEmphasisMark final : public EditCharAttrib
252 {
253 public:
254 EditCharAttribEmphasisMark( const SvxEmphasisMarkItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
255
256 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
257 };
258
259
260
261 class EditCharAttribRelief final : public EditCharAttrib
262 {
263 public:
264 EditCharAttribRelief( const SvxCharReliefItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
265
266 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
267 };
268
269
270
271 class EditCharAttribFontHeight final : public EditCharAttrib
272 {
273 public:
274 EditCharAttribFontHeight( const SvxFontHeightItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
275
276 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
277 };
278
279
280
281 class EditCharAttribFontWidth final : public EditCharAttrib
282 {
283 public:
284 EditCharAttribFontWidth( const SvxCharScaleWidthItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
285
286 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
287 };
288
289
290
291 class EditCharAttribColor final : public EditCharAttrib
292 {
293 public:
294 EditCharAttribColor( const SvxColorItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
295
296 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
297 };
298
299
300 class EditCharAttribBackgroundColor final : public EditCharAttrib
301 {
302 public:
303 EditCharAttribBackgroundColor(const SvxColorItem& rAttr,
304 sal_Int32 nStart,
305 sal_Int32 nEnd );
306 virtual void SetFont(SvxFont& rFont, OutputDevice* pOutDev) override;
307 };
308
309
310
311 class EditCharAttribLanguage final : public EditCharAttrib
312 {
313 public:
314 EditCharAttribLanguage( const SvxLanguageItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
315
316 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
317 };
318
319
320
321 class EditCharAttribTab final : public EditCharAttrib
322 {
323 public:
324 EditCharAttribTab( const SfxVoidItem& rAttr, sal_Int32 nPos );
325
326 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
327 };
328
329
330
331 class EditCharAttribLineBreak final : public EditCharAttrib
332 {
333 public:
334 EditCharAttribLineBreak( const SfxVoidItem& rAttr, sal_Int32 nPos );
335
336 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
337 };
338
339
340
341 class EditCharAttribField final : public EditCharAttrib
342 {
343 OUString aFieldValue;
344 std::optional<Color> mxTxtColor;
345 std::optional<Color> mxFldColor;
346
347 EditCharAttribField& operator = ( const EditCharAttribField& rAttr ) = delete;
348
349 public:
350 EditCharAttribField( const SvxFieldItem& rAttr, sal_Int32 nPos );
351 EditCharAttribField( const EditCharAttribField& rAttr );
352 virtual ~EditCharAttribField() override;
353
354 bool operator == ( const EditCharAttribField& rAttr ) const;
operator !=(const EditCharAttribField & rAttr) const355 bool operator != ( const EditCharAttribField& rAttr ) const
356 { return !(operator == ( rAttr ) ); }
357
358 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
GetTextColor()359 std::optional<Color>& GetTextColor() { return mxTxtColor; }
GetFieldColor()360 std::optional<Color>& GetFieldColor() { return mxFldColor; }
361
GetFieldValue() const362 const OUString& GetFieldValue() const { return aFieldValue;}
363 void SetFieldValue(const OUString& rVal);
364
365 void Reset();
366 };
367
368
369
370 class EditCharAttribPairKerning final : public EditCharAttrib
371 {
372 public:
373 EditCharAttribPairKerning( const SvxAutoKernItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
374
375 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
376 };
377
378
379
380 class EditCharAttribKerning final : public EditCharAttrib
381 {
382 public:
383 EditCharAttribKerning( const SvxKerningItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
384
385 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
386 };
387
388
389
390 class EditCharAttribWordLineMode final : public EditCharAttrib
391 {
392 public:
393 EditCharAttribWordLineMode( const SvxWordLineModeItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
394
395 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
396 };
397
398
399 class EditCharAttribGrabBag final : public EditCharAttrib
400 {
401 public:
402 EditCharAttribGrabBag( const SfxGrabBagItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
403 };
404
405
406 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
407