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 #include <vcl/outdev.hxx>
21
22 #include <svl/grabbagitem.hxx>
23 #include <libxml/xmlwriter.h>
24 #include <editeng/svxfont.hxx>
25 #include <editeng/flditem.hxx>
26 #include <editeng/fontitem.hxx>
27 #include <editeng/postitem.hxx>
28 #include <editeng/wghtitem.hxx>
29 #include <editeng/udlnitem.hxx>
30 #include <editeng/contouritem.hxx>
31 #include <editeng/shdditem.hxx>
32 #include <editeng/escapementitem.hxx>
33 #include <editeng/colritem.hxx>
34 #include <editeng/wrlmitem.hxx>
35 #include <editeng/fhgtitem.hxx>
36 #include <editeng/crossedoutitem.hxx>
37 #include <editeng/kernitem.hxx>
38 #include <editeng/autokernitem.hxx>
39 #include <editeng/langitem.hxx>
40 #include <editeng/emphasismarkitem.hxx>
41 #include <editeng/charscaleitem.hxx>
42 #include <editeng/charreliefitem.hxx>
43 #include <editeng/cmapitem.hxx>
44
45 #include <editattr.hxx>
46
47
48
EditCharAttrib(const SfxPoolItem & rAttr,sal_Int32 nS,sal_Int32 nE)49 EditCharAttrib::EditCharAttrib( const SfxPoolItem& rAttr, sal_Int32 nS, sal_Int32 nE ) :
50 nStart(nS), nEnd(nE), bFeature(false), bEdge(false)
51 {
52 pItem = &rAttr;
53
54 assert((rAttr.Which() >= EE_ITEMS_START) && (rAttr.Which() <= EE_ITEMS_END));
55 assert((rAttr.Which() < EE_FEATURE_START) || (rAttr.Which() > EE_FEATURE_END) || (nE == (nS+1)));
56 }
57
~EditCharAttrib()58 EditCharAttrib::~EditCharAttrib()
59 {
60 }
61
SetFont(SvxFont &,OutputDevice *)62 void EditCharAttrib::SetFont( SvxFont&, OutputDevice* )
63 {
64 }
65
dumpAsXml(xmlTextWriterPtr pWriter) const66 void EditCharAttrib::dumpAsXml(xmlTextWriterPtr pWriter) const
67 {
68 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("EditCharAttrib"));
69 (void)xmlTextWriterWriteFormatAttribute(
70 pWriter, BAD_CAST("nStart"), "%" SAL_PRIdINT32, nStart);
71 (void)xmlTextWriterWriteFormatAttribute(
72 pWriter, BAD_CAST("nEnd"), "%" SAL_PRIdINT32, nEnd);
73 pItem->dumpAsXml(pWriter);
74 (void)xmlTextWriterEndElement(pWriter);
75 }
76
77
78
EditCharAttribFont(const SvxFontItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)79 EditCharAttribFont::EditCharAttribFont( const SvxFontItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
80 : EditCharAttrib( rAttr, _nStart, _nEnd )
81 {
82 assert(rAttr.Which() == EE_CHAR_FONTINFO || rAttr.Which() == EE_CHAR_FONTINFO_CJK || rAttr.Which() == EE_CHAR_FONTINFO_CTL);
83 }
84
SetFont(SvxFont & rFont,OutputDevice *)85 void EditCharAttribFont::SetFont( SvxFont& rFont, OutputDevice* )
86 {
87 const SvxFontItem& rAttr = static_cast<const SvxFontItem&>(*GetItem());
88
89 rFont.SetFamilyName( rAttr.GetFamilyName() );
90 rFont.SetFamily( rAttr.GetFamily() );
91 rFont.SetPitch( rAttr.GetPitch() );
92 rFont.SetCharSet( rAttr.GetCharSet() );
93 }
94
95
96
EditCharAttribItalic(const SvxPostureItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)97 EditCharAttribItalic::EditCharAttribItalic( const SvxPostureItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
98 : EditCharAttrib( rAttr, _nStart, _nEnd )
99 {
100 assert(rAttr.Which() == EE_CHAR_ITALIC || rAttr.Which() == EE_CHAR_ITALIC_CJK || rAttr.Which() == EE_CHAR_ITALIC_CTL);
101 }
102
SetFont(SvxFont & rFont,OutputDevice *)103 void EditCharAttribItalic::SetFont( SvxFont& rFont, OutputDevice* )
104 {
105 rFont.SetItalic( static_cast<const SvxPostureItem*>(GetItem())->GetPosture() );
106 }
107
108
109
EditCharAttribWeight(const SvxWeightItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)110 EditCharAttribWeight::EditCharAttribWeight( const SvxWeightItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
111 : EditCharAttrib( rAttr, _nStart, _nEnd )
112 {
113 assert(rAttr.Which() == EE_CHAR_WEIGHT || rAttr.Which() == EE_CHAR_WEIGHT_CJK || rAttr.Which() == EE_CHAR_WEIGHT_CTL);
114 }
115
SetFont(SvxFont & rFont,OutputDevice *)116 void EditCharAttribWeight::SetFont( SvxFont& rFont, OutputDevice* )
117 {
118 rFont.SetWeight( static_cast<const SvxWeightItem*>(GetItem())->GetValue() );
119 }
120
121
122
EditCharAttribUnderline(const SvxUnderlineItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)123 EditCharAttribUnderline::EditCharAttribUnderline( const SvxUnderlineItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
124 : EditCharAttrib( rAttr, _nStart, _nEnd )
125 {
126 assert(rAttr.Which() == EE_CHAR_UNDERLINE);
127 }
128
SetFont(SvxFont & rFont,OutputDevice * pOutDev)129 void EditCharAttribUnderline::SetFont( SvxFont& rFont, OutputDevice* pOutDev )
130 {
131 rFont.SetUnderline( static_cast<const SvxUnderlineItem*>(GetItem())->GetValue() );
132
133 if ( pOutDev )
134 pOutDev->SetTextLineColor( static_cast<const SvxUnderlineItem*>(GetItem())->GetColor() );
135
136 }
137
138
139
EditCharAttribOverline(const SvxOverlineItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)140 EditCharAttribOverline::EditCharAttribOverline( const SvxOverlineItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
141 : EditCharAttrib( rAttr, _nStart, _nEnd )
142 {
143 assert(rAttr.Which() == EE_CHAR_OVERLINE);
144 }
145
SetFont(SvxFont & rFont,OutputDevice * pOutDev)146 void EditCharAttribOverline::SetFont( SvxFont& rFont, OutputDevice* pOutDev )
147 {
148 rFont.SetOverline( static_cast<const SvxOverlineItem*>(GetItem())->GetValue() );
149 if ( pOutDev )
150 pOutDev->SetOverlineColor( static_cast<const SvxOverlineItem*>(GetItem())->GetColor() );
151 }
152
153
154
EditCharAttribFontHeight(const SvxFontHeightItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)155 EditCharAttribFontHeight::EditCharAttribFontHeight( const SvxFontHeightItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
156 : EditCharAttrib( rAttr, _nStart, _nEnd )
157 {
158 assert(rAttr.Which() == EE_CHAR_FONTHEIGHT || rAttr.Which() == EE_CHAR_FONTHEIGHT_CJK || rAttr.Which() == EE_CHAR_FONTHEIGHT_CTL);
159 }
160
SetFont(SvxFont & rFont,OutputDevice *)161 void EditCharAttribFontHeight::SetFont( SvxFont& rFont, OutputDevice* )
162 {
163 // Property is ignored
164 rFont.SetFontSize( Size( rFont.GetFontSize().Width(), static_cast<const SvxFontHeightItem*>(GetItem())->GetHeight() ) );
165 }
166
167
168
EditCharAttribFontWidth(const SvxCharScaleWidthItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)169 EditCharAttribFontWidth::EditCharAttribFontWidth( const SvxCharScaleWidthItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
170 : EditCharAttrib( rAttr, _nStart, _nEnd )
171 {
172 assert(rAttr.Which() == EE_CHAR_FONTWIDTH);
173 }
174
SetFont(SvxFont &,OutputDevice *)175 void EditCharAttribFontWidth::SetFont( SvxFont& /*rFont*/, OutputDevice* )
176 {
177 // must be calculated outside, because f(device)...
178 }
179
180
181
EditCharAttribStrikeout(const SvxCrossedOutItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)182 EditCharAttribStrikeout::EditCharAttribStrikeout( const SvxCrossedOutItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
183 : EditCharAttrib( rAttr, _nStart, _nEnd )
184 {
185 assert(rAttr.Which() == EE_CHAR_STRIKEOUT);
186 }
187
SetFont(SvxFont & rFont,OutputDevice *)188 void EditCharAttribStrikeout::SetFont( SvxFont& rFont, OutputDevice* )
189 {
190 rFont.SetStrikeout( static_cast<const SvxCrossedOutItem*>(GetItem())->GetValue() );
191 }
192
193
194
EditCharAttribCaseMap(const SvxCaseMapItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)195 EditCharAttribCaseMap::EditCharAttribCaseMap( const SvxCaseMapItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
196 : EditCharAttrib( rAttr, _nStart, _nEnd )
197 {
198 assert(rAttr.Which() == EE_CHAR_CASEMAP);
199 }
200
SetFont(SvxFont & rFont,OutputDevice *)201 void EditCharAttribCaseMap::SetFont( SvxFont& rFont, OutputDevice* )
202 {
203 rFont.SetCaseMap( static_cast<const SvxCaseMapItem*>(GetItem())->GetCaseMap() );
204 }
205
206
207
EditCharAttribColor(const SvxColorItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)208 EditCharAttribColor::EditCharAttribColor( const SvxColorItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
209 : EditCharAttrib( rAttr, _nStart, _nEnd )
210 {
211 assert(rAttr.Which() == EE_CHAR_COLOR);
212 }
213
SetFont(SvxFont & rFont,OutputDevice *)214 void EditCharAttribColor::SetFont( SvxFont& rFont, OutputDevice* )
215 {
216 Color aColor = static_cast<const SvxColorItem*>(GetItem())->GetValue();
217 rFont.SetColor( aColor);
218 }
219
220
EditCharAttribBackgroundColor(const SvxColorItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)221 EditCharAttribBackgroundColor::EditCharAttribBackgroundColor(
222 const SvxColorItem& rAttr,
223 sal_Int32 _nStart,
224 sal_Int32 _nEnd )
225 : EditCharAttrib( rAttr, _nStart, _nEnd )
226 {
227 assert(rAttr.Which() == EE_CHAR_BKGCOLOR);
228 }
229
SetFont(SvxFont & rFont,OutputDevice *)230 void EditCharAttribBackgroundColor::SetFont( SvxFont& rFont, OutputDevice* )
231 {
232 Color aColor = static_cast<const SvxColorItem*>(GetItem())->GetValue();
233 rFont.SetTransparent(false);
234 rFont.SetFillColor(aColor);
235 }
236
EditCharAttribLanguage(const SvxLanguageItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)237 EditCharAttribLanguage::EditCharAttribLanguage( const SvxLanguageItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
238 : EditCharAttrib( rAttr, _nStart, _nEnd )
239 {
240 assert((rAttr.Which() == EE_CHAR_LANGUAGE) || (rAttr.Which() == EE_CHAR_LANGUAGE_CJK) || (rAttr.Which() == EE_CHAR_LANGUAGE_CTL));
241 }
242
SetFont(SvxFont & rFont,OutputDevice *)243 void EditCharAttribLanguage::SetFont( SvxFont& rFont, OutputDevice* )
244 {
245 rFont.SetLanguage( static_cast<const SvxLanguageItem*>(GetItem())->GetLanguage() );
246 }
247
248
249
EditCharAttribShadow(const SvxShadowedItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)250 EditCharAttribShadow::EditCharAttribShadow( const SvxShadowedItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
251 : EditCharAttrib( rAttr, _nStart, _nEnd )
252 {
253 assert(rAttr.Which() == EE_CHAR_SHADOW);
254 }
255
SetFont(SvxFont & rFont,OutputDevice *)256 void EditCharAttribShadow::SetFont( SvxFont& rFont, OutputDevice* )
257 {
258 rFont.SetShadow( static_cast<const SvxShadowedItem*>(GetItem())->GetValue() );
259 }
260
261
262
EditCharAttribEscapement(const SvxEscapementItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)263 EditCharAttribEscapement::EditCharAttribEscapement( const SvxEscapementItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
264 : EditCharAttrib( rAttr, _nStart, _nEnd )
265 {
266 assert(rAttr.Which() == EE_CHAR_ESCAPEMENT);
267 }
268
SetFont(SvxFont & rFont,OutputDevice * pOutDev)269 void EditCharAttribEscapement::SetFont( SvxFont& rFont, OutputDevice* pOutDev )
270 {
271 sal_uInt16 const nProp = static_cast<const SvxEscapementItem*>(GetItem())->GetProportionalHeight();
272 rFont.SetPropr( static_cast<sal_uInt8>(nProp) );
273
274 short nEsc = static_cast<const SvxEscapementItem*>(GetItem())->GetEsc();
275 rFont.SetNonAutoEscapement( nEsc, pOutDev );
276 }
277
278
279
EditCharAttribOutline(const SvxContourItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)280 EditCharAttribOutline::EditCharAttribOutline( const SvxContourItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
281 : EditCharAttrib( rAttr, _nStart, _nEnd )
282 {
283 assert(rAttr.Which() == EE_CHAR_OUTLINE);
284 }
285
SetFont(SvxFont & rFont,OutputDevice *)286 void EditCharAttribOutline::SetFont( SvxFont& rFont, OutputDevice* )
287 {
288 rFont.SetOutline( static_cast<const SvxContourItem*>(GetItem())->GetValue() );
289 }
290
291
292
EditCharAttribTab(const SfxVoidItem & rAttr,sal_Int32 nPos)293 EditCharAttribTab::EditCharAttribTab( const SfxVoidItem& rAttr, sal_Int32 nPos )
294 : EditCharAttrib( rAttr, nPos, nPos+1 )
295 {
296 SetFeature( true );
297 }
298
SetFont(SvxFont &,OutputDevice *)299 void EditCharAttribTab::SetFont( SvxFont&, OutputDevice* )
300 {
301 }
302
303
304
EditCharAttribLineBreak(const SfxVoidItem & rAttr,sal_Int32 nPos)305 EditCharAttribLineBreak::EditCharAttribLineBreak( const SfxVoidItem& rAttr, sal_Int32 nPos )
306 : EditCharAttrib( rAttr, nPos, nPos+1 )
307 {
308 SetFeature( true );
309 }
310
SetFont(SvxFont &,OutputDevice *)311 void EditCharAttribLineBreak::SetFont( SvxFont&, OutputDevice* )
312 {
313 }
314
315
316
EditCharAttribField(const SvxFieldItem & rAttr,sal_Int32 nPos)317 EditCharAttribField::EditCharAttribField( const SvxFieldItem& rAttr, sal_Int32 nPos )
318 : EditCharAttrib( rAttr, nPos, nPos+1 )
319 {
320 SetFeature( true ); // !!!
321 }
322
SetFont(SvxFont & rFont,OutputDevice *)323 void EditCharAttribField::SetFont( SvxFont& rFont, OutputDevice* )
324 {
325 if ( mxFldColor )
326 {
327 rFont.SetFillColor( *mxFldColor );
328 rFont.SetTransparent( false );
329 }
330 if ( mxTxtColor )
331 rFont.SetColor( *mxTxtColor );
332 }
333
334
SetFieldValue(const OUString & rVal)335 void EditCharAttribField::SetFieldValue(const OUString& rVal)
336 {
337 aFieldValue = rVal;
338 }
339
Reset()340 void EditCharAttribField::Reset()
341 {
342 aFieldValue.clear();
343 mxTxtColor.reset();
344 mxFldColor.reset();
345 }
346
EditCharAttribField(const EditCharAttribField & rAttr)347 EditCharAttribField::EditCharAttribField( const EditCharAttribField& rAttr )
348 : EditCharAttrib( *rAttr.GetItem(), rAttr.GetStart(), rAttr.GetEnd() ),
349 aFieldValue( rAttr.aFieldValue )
350 {
351 // Use this constructor only for temporary Objects, Item is not pooled.
352 mxTxtColor = rAttr.mxTxtColor;
353 mxFldColor = rAttr.mxFldColor;
354 }
355
~EditCharAttribField()356 EditCharAttribField::~EditCharAttribField()
357 {
358 Reset();
359 }
360
operator ==(const EditCharAttribField & rAttr) const361 bool EditCharAttribField::operator == ( const EditCharAttribField& rAttr ) const
362 {
363 if ( aFieldValue != rAttr.aFieldValue )
364 return false;
365
366 if ( ( mxTxtColor && !rAttr.mxTxtColor ) || ( !mxTxtColor && rAttr.mxTxtColor ) )
367 return false;
368 if ( ( mxTxtColor && rAttr.mxTxtColor ) && ( *mxTxtColor != *rAttr.mxTxtColor ) )
369 return false;
370
371 if ( ( mxFldColor && !rAttr.mxFldColor ) || ( !mxFldColor && rAttr.mxFldColor ) )
372 return false;
373 if ( ( mxFldColor && rAttr.mxFldColor ) && ( *mxFldColor != *rAttr.mxFldColor ) )
374 return false;
375
376 return true;
377 }
378
379
380
EditCharAttribPairKerning(const SvxAutoKernItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)381 EditCharAttribPairKerning::EditCharAttribPairKerning( const SvxAutoKernItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
382 : EditCharAttrib( rAttr, _nStart, _nEnd )
383 {
384 assert(rAttr.Which() == EE_CHAR_PAIRKERNING);
385 }
386
SetFont(SvxFont & rFont,OutputDevice *)387 void EditCharAttribPairKerning::SetFont( SvxFont& rFont, OutputDevice* )
388 {
389 rFont.SetKerning( static_cast<const SvxAutoKernItem*>(GetItem())->GetValue() ? FontKerning::FontSpecific : FontKerning::NONE );
390 }
391
392
393
EditCharAttribKerning(const SvxKerningItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)394 EditCharAttribKerning::EditCharAttribKerning( const SvxKerningItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
395 : EditCharAttrib( rAttr, _nStart, _nEnd )
396 {
397 assert(rAttr.Which() == EE_CHAR_KERNING);
398 }
399
SetFont(SvxFont & rFont,OutputDevice *)400 void EditCharAttribKerning::SetFont( SvxFont& rFont, OutputDevice* )
401 {
402 rFont.SetFixKerning( static_cast<const SvxKerningItem*>(GetItem())->GetValue() );
403 }
404
405
406
EditCharAttribWordLineMode(const SvxWordLineModeItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)407 EditCharAttribWordLineMode::EditCharAttribWordLineMode( const SvxWordLineModeItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
408 : EditCharAttrib( rAttr, _nStart, _nEnd )
409 {
410 assert(rAttr.Which() == EE_CHAR_WLM);
411 }
412
SetFont(SvxFont & rFont,OutputDevice *)413 void EditCharAttribWordLineMode::SetFont( SvxFont& rFont, OutputDevice* )
414 {
415 rFont.SetWordLineMode( static_cast<const SvxWordLineModeItem*>(GetItem())->GetValue() );
416 }
417
418
419
EditCharAttribEmphasisMark(const SvxEmphasisMarkItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)420 EditCharAttribEmphasisMark::EditCharAttribEmphasisMark( const SvxEmphasisMarkItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
421 : EditCharAttrib( rAttr, _nStart, _nEnd )
422 {
423 assert(rAttr.Which() == EE_CHAR_EMPHASISMARK);
424 }
425
SetFont(SvxFont & rFont,OutputDevice *)426 void EditCharAttribEmphasisMark::SetFont( SvxFont& rFont, OutputDevice* )
427 {
428 rFont.SetEmphasisMark( static_cast<const SvxEmphasisMarkItem*>(GetItem())->GetEmphasisMark() );
429 }
430
431
432
EditCharAttribRelief(const SvxCharReliefItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)433 EditCharAttribRelief::EditCharAttribRelief( const SvxCharReliefItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
434 : EditCharAttrib( rAttr, _nStart, _nEnd )
435 {
436 assert(rAttr.Which() == EE_CHAR_RELIEF);
437 }
438
SetFont(SvxFont & rFont,OutputDevice *)439 void EditCharAttribRelief::SetFont( SvxFont& rFont, OutputDevice* )
440 {
441 rFont.SetRelief( static_cast<const SvxCharReliefItem*>(GetItem())->GetValue() );
442 }
443
444
EditCharAttribGrabBag(const SfxGrabBagItem & rAttr,sal_Int32 _nStart,sal_Int32 _nEnd)445 EditCharAttribGrabBag::EditCharAttribGrabBag( const SfxGrabBagItem& rAttr, sal_Int32 _nStart, sal_Int32 _nEnd )
446 : EditCharAttrib( rAttr, _nStart, _nEnd )
447 {
448 assert(rAttr.Which() == EE_CHAR_GRABBAG);
449 }
450
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
452