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