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 #ifndef INCLUDED_EDITENG_INC_EDITATTR_HXX
21 #define INCLUDED_EDITENG_INC_EDITATTR_HXX
22
23 #include <editeng/eeitem.hxx>
24 #include <svl/poolitem.hxx>
25 #include <boost/optional.hpp>
26 #include <tools/color.hxx>
27 #include <tools/debug.hxx>
28
29 class SvxFont;
30 class SvxFontItem;
31 class SvxWeightItem;
32 class SvxPostureItem;
33 class SvxShadowedItem;
34 class SvxEscapementItem;
35 class SvxContourItem;
36 class SvxCrossedOutItem;
37 class SvxUnderlineItem;
38 class SvxOverlineItem;
39 class SvxFontHeightItem;
40 class SvxCharScaleWidthItem;
41 class SvxColorItem;
42 class SvxBackgroundColorItem;
43 class SvxAutoKernItem;
44 class SvxKerningItem;
45 class SvxWordLineModeItem;
46 class SvxFieldItem;
47 class SvxLanguageItem;
48 class SvxEmphasisMarkItem;
49 class SvxCharReliefItem;
50 class SfxVoidItem;
51 class OutputDevice;
52 class SvxCaseMapItem;
53 class SfxGrabBagItem;
54
55 #define CH_FEATURE_OLD (sal_uInt8) 0xFF
56 #define CH_FEATURE u'\x0001'
57
58 // DEF_METRIC: For my pool, the DefMetric should always appear when
59 // GetMetric (nWhich)!
60 // => To determine the DefMetric simply use GetMetric(0)
61 #define DEF_METRIC 0
62
63
64 // class EditCharAttrib
65
66 // bFeature: Attribute must not expand/shrink, length is always 1
67 // bEdge: Attribute will not expand, if you want to expand just on the edge
68 class EditCharAttrib
69 {
70 const SfxPoolItem* pItem;
71
72 sal_Int32 nStart;
73 sal_Int32 nEnd;
74 bool bFeature :1;
75 bool bEdge :1;
76
77 public:
78 EditCharAttrib( const SfxPoolItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
79 virtual ~EditCharAttrib();
80
81 EditCharAttrib(const EditCharAttrib&) = delete;
82 EditCharAttrib& operator=(const EditCharAttrib&) = delete;
83
84 void dumpAsXml(xmlTextWriterPtr pWriter) const;
85
Which() const86 sal_uInt16 Which() const { return pItem->Which(); }
GetItem() const87 const SfxPoolItem* GetItem() const { return pItem; }
88
GetStart()89 sal_Int32& GetStart() { return nStart; }
GetEnd()90 sal_Int32& GetEnd() { return nEnd; }
91
GetStart() const92 sal_Int32 GetStart() const { return nStart; }
GetEnd() const93 sal_Int32 GetEnd() const { return nEnd; }
94
95 inline sal_Int32 GetLen() const;
96
97 inline void MoveForward( sal_Int32 nDiff );
98 inline void MoveBackward( sal_Int32 nDiff );
99
100 inline void Expand( sal_Int32 nDiff );
101 inline void Collaps( sal_Int32 nDiff );
102
103 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev );
104
IsIn(sal_Int32 nIndex) const105 bool IsIn( sal_Int32 nIndex ) const
106 { return ( ( nStart <= nIndex ) && ( nEnd >= nIndex ) ); }
IsInside(sal_Int32 nIndex) const107 bool IsInside( sal_Int32 nIndex ) const
108 { return ( ( nStart < nIndex ) && ( nEnd > nIndex ) ); }
IsEmpty() const109 bool IsEmpty() const
110 { return nStart == nEnd; }
111
IsFeature() const112 bool IsFeature() const { return bFeature; }
SetFeature(bool b)113 void SetFeature( bool b) { bFeature = b; }
114
IsEdge() const115 bool IsEdge() const { return bEdge; }
SetEdge(bool b)116 void SetEdge( bool b ) { bEdge = b; }
117 };
118
GetLen() const119 inline sal_Int32 EditCharAttrib::GetLen() const
120 {
121 DBG_ASSERT( nEnd >= nStart, "EditCharAttrib: nEnd < nStart!" );
122 return nEnd-nStart;
123 }
124
MoveForward(sal_Int32 nDiff)125 inline void EditCharAttrib::MoveForward( sal_Int32 nDiff )
126 {
127 DBG_ASSERT( SAL_MAX_INT32 - nDiff > nEnd, "EditCharAttrib: MoveForward?!" );
128 nStart = nStart + nDiff;
129 nEnd = nEnd + nDiff;
130 }
131
MoveBackward(sal_Int32 nDiff)132 inline void EditCharAttrib::MoveBackward( sal_Int32 nDiff )
133 {
134 DBG_ASSERT( (nStart - nDiff) >= 0, "EditCharAttrib: MoveBackward?!" );
135 nStart = nStart - nDiff;
136 nEnd = nEnd - nDiff;
137 }
138
Expand(sal_Int32 nDiff)139 inline void EditCharAttrib::Expand( sal_Int32 nDiff )
140 {
141 DBG_ASSERT( SAL_MAX_INT32 - nDiff > nEnd, "EditCharAttrib: Expand?!" );
142 DBG_ASSERT( !bFeature, "Please do not expand any features!" );
143 nEnd = nEnd + nDiff;
144 }
145
Collaps(sal_Int32 nDiff)146 inline void EditCharAttrib::Collaps( sal_Int32 nDiff )
147 {
148 DBG_ASSERT( nEnd - nDiff >= nStart, "EditCharAttrib: Collaps?!" );
149 DBG_ASSERT( !bFeature, "Please do not shrink any Features!" );
150 nEnd = nEnd - nDiff;
151 }
152
153
154 // class EditCharAttribFont
155
156 class EditCharAttribFont: public EditCharAttrib
157 {
158 public:
159 EditCharAttribFont( const SvxFontItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
160
161 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
162 };
163
164
165 // class EditCharAttribWeight
166
167 class EditCharAttribWeight : public EditCharAttrib
168 {
169 public:
170 EditCharAttribWeight( const SvxWeightItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
171
172 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
173 };
174
175 // class EditCharAttribItalic
176
177 class EditCharAttribItalic : public EditCharAttrib
178 {
179 public:
180 EditCharAttribItalic( const SvxPostureItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
181
182 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
183 };
184
185
186 // class EditCharAttribShadow
187
188 class EditCharAttribShadow : public EditCharAttrib
189 {
190 public:
191 EditCharAttribShadow( const SvxShadowedItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
192
193 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
194 };
195
196
197 // class EditCharAttribEscapement
198
199 class EditCharAttribEscapement : public EditCharAttrib
200 {
201 public:
202 EditCharAttribEscapement( const SvxEscapementItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
203
204 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
205 };
206
207
208 // class EditCharAttribOutline
209
210 class EditCharAttribOutline : public EditCharAttrib
211 {
212 public:
213 EditCharAttribOutline( const SvxContourItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
214
215 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
216 };
217
218
219 // class EditCharAttribStrikeout
220
221 class EditCharAttribStrikeout : public EditCharAttrib
222 {
223 public:
224 EditCharAttribStrikeout( const SvxCrossedOutItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
225
226 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
227 };
228
229
230 // class EditCharAttribCaseMap
231
232 class EditCharAttribCaseMap : public EditCharAttrib
233 {
234 public:
235 EditCharAttribCaseMap( const SvxCaseMapItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
236
237 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
238 };
239
240
241 // class EditCharAttribUnderline
242
243 class EditCharAttribUnderline : public EditCharAttrib
244 {
245 public:
246 EditCharAttribUnderline( const SvxUnderlineItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
247
248 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
249 };
250
251
252 // class EditCharAttribOverline
253
254 class EditCharAttribOverline : public EditCharAttrib
255 {
256 public:
257 EditCharAttribOverline( const SvxOverlineItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
258
259 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
260 };
261
262
263 // class EditCharAttribEmphasisMark
264
265 class EditCharAttribEmphasisMark : public EditCharAttrib
266 {
267 public:
268 EditCharAttribEmphasisMark( const SvxEmphasisMarkItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
269
270 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
271 };
272
273
274 // class EditCharAttribRelief
275
276 class EditCharAttribRelief : public EditCharAttrib
277 {
278 public:
279 EditCharAttribRelief( const SvxCharReliefItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
280
281 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
282 };
283
284
285 // class EditCharAttribFontHeight
286
287 class EditCharAttribFontHeight : public EditCharAttrib
288 {
289 public:
290 EditCharAttribFontHeight( const SvxFontHeightItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
291
292 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
293 };
294
295
296 // class EditCharAttribFontWidth
297
298 class EditCharAttribFontWidth : public EditCharAttrib
299 {
300 public:
301 EditCharAttribFontWidth( const SvxCharScaleWidthItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
302
303 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
304 };
305
306
307 // class EditCharAttribColor
308
309 class EditCharAttribColor : public EditCharAttrib
310 {
311 public:
312 EditCharAttribColor( const SvxColorItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
313
314 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
315 };
316
317 // class EditCharAttribBackgroundColor
318
319 class EditCharAttribBackgroundColor : public EditCharAttrib
320 {
321 public:
322 EditCharAttribBackgroundColor(const SvxBackgroundColorItem& rAttr,
323 sal_Int32 nStart,
324 sal_Int32 nEnd );
325 virtual void SetFont(SvxFont& rFont, OutputDevice* pOutDev) override;
326 };
327
328
329 // class EditCharAttribLanguage
330
331 class EditCharAttribLanguage : public EditCharAttrib
332 {
333 public:
334 EditCharAttribLanguage( const SvxLanguageItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
335
336 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
337 };
338
339
340 // class EditCharAttribTab
341
342 class EditCharAttribTab : public EditCharAttrib
343 {
344 public:
345 EditCharAttribTab( const SfxVoidItem& rAttr, sal_Int32 nPos );
346
347 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
348 };
349
350
351 // class EditCharAttribLineBreak
352
353 class EditCharAttribLineBreak : public EditCharAttrib
354 {
355 public:
356 EditCharAttribLineBreak( const SfxVoidItem& rAttr, sal_Int32 nPos );
357
358 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
359 };
360
361
362 // class EditCharAttribField
363
364 class EditCharAttribField: public EditCharAttrib
365 {
366 OUString aFieldValue;
367 boost::optional<Color> mxTxtColor;
368 boost::optional<Color> mxFldColor;
369
370 EditCharAttribField& operator = ( const EditCharAttribField& rAttr ) = delete;
371
372 public:
373 EditCharAttribField( const SvxFieldItem& rAttr, sal_Int32 nPos );
374 EditCharAttribField( const EditCharAttribField& rAttr );
375 virtual ~EditCharAttribField() override;
376
377 bool operator == ( const EditCharAttribField& rAttr ) const;
operator !=(const EditCharAttribField & rAttr) const378 bool operator != ( const EditCharAttribField& rAttr ) const
379 { return !(operator == ( rAttr ) ); }
380
381 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
GetTextColor()382 boost::optional<Color>& GetTextColor() { return mxTxtColor; }
GetFieldColor()383 boost::optional<Color>& GetFieldColor() { return mxFldColor; }
384
GetFieldValue() const385 const OUString& GetFieldValue() const { return aFieldValue;}
386 void SetFieldValue(const OUString& rVal);
387
388 void Reset();
389 };
390
391
392 // class EditCharAttribPairKerning
393
394 class EditCharAttribPairKerning : public EditCharAttrib
395 {
396 public:
397 EditCharAttribPairKerning( const SvxAutoKernItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
398
399 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
400 };
401
402
403 // class EditCharAttribKerning
404
405 class EditCharAttribKerning : public EditCharAttrib
406 {
407 public:
408 EditCharAttribKerning( const SvxKerningItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
409
410 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
411 };
412
413
414 // class EditCharAttribWordLineMode
415
416 class EditCharAttribWordLineMode: public EditCharAttrib
417 {
418 public:
419 EditCharAttribWordLineMode( const SvxWordLineModeItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
420
421 virtual void SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
422 };
423
424 // class EditCharAttribGrabBag
425
426 class EditCharAttribGrabBag: public EditCharAttrib
427 {
428 public:
429 EditCharAttribGrabBag( const SfxGrabBagItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
430 };
431
432
433 #endif
434
435 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
436