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 <editeng/svxfont.hxx>
27 : #include <editeng/flditem.hxx>
28 : #include <editeng/fontitem.hxx>
29 : #include <editeng/postitem.hxx>
30 : #include <editeng/wghtitem.hxx>
31 : #include <editeng/udlnitem.hxx>
32 : #include <editeng/cntritem.hxx>
33 : #include <editeng/shdditem.hxx>
34 : #include <editeng/escpitem.hxx>
35 : #include <editeng/colritem.hxx>
36 : #include <editeng/wrlmitem.hxx>
37 : #include <editeng/fhgtitem.hxx>
38 : #include <editeng/crsditem.hxx>
39 : #include <editeng/cscoitem.hxx>
40 : #include <editeng/kernitem.hxx>
41 : #include <editeng/akrnitem.hxx>
42 : #include <editeng/langitem.hxx>
43 : #include <editeng/emphitem.hxx>
44 : #include <editeng/charscaleitem.hxx>
45 : #include <editeng/charreliefitem.hxx>
46 :
47 : #include "editattr.hxx"
48 :
49 : DBG_NAME( EE_EditAttrib )
50 :
51 : // -------------------------------------------------------------------------
52 : // class EditCharAttrib
53 : // -------------------------------------------------------------------------
54 74392 : EditCharAttrib::EditCharAttrib( const SfxPoolItem& rAttr, sal_uInt16 nS, sal_uInt16 nE ) :
55 74392 : nStart(nS), nEnd(nE), bFeature(false), bEdge(false)
56 : {
57 : DBG_CTOR( EE_EditAttrib, 0 );
58 74392 : 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 74392 : }
63 :
64 74091 : EditCharAttrib::~EditCharAttrib()
65 : {
66 : DBG_DTOR( EE_EditAttrib, 0 );
67 74091 : }
68 :
69 80 : void EditCharAttrib::SetFont( SvxFont&, OutputDevice* )
70 : {
71 80 : }
72 :
73 :
74 : // -------------------------------------------------------------------------
75 : // class EditCharAttribFont
76 : // -------------------------------------------------------------------------
77 17959 : EditCharAttribFont::EditCharAttribFont( const SvxFontItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
78 17959 : : EditCharAttrib( rAttr, _nStart, _nEnd )
79 : {
80 : DBG_ASSERT( rAttr.Which() == EE_CHAR_FONTINFO || rAttr.Which() == EE_CHAR_FONTINFO_CJK || rAttr.Which() == EE_CHAR_FONTINFO_CTL, "Not a Font attribute!" );
81 17959 : }
82 :
83 7008 : void EditCharAttribFont::SetFont( SvxFont& rFont, OutputDevice* )
84 : {
85 7008 : const SvxFontItem& rAttr = (const SvxFontItem&)(*GetItem());
86 :
87 7008 : rFont.SetName( rAttr.GetFamilyName() );
88 7008 : rFont.SetFamily( rAttr.GetFamily() );
89 7008 : rFont.SetPitch( rAttr.GetPitch() );
90 7008 : rFont.SetCharSet( rAttr.GetCharSet() );
91 7008 : }
92 :
93 : // -------------------------------------------------------------------------
94 : // class EditCharAttribItalic
95 : // -------------------------------------------------------------------------
96 1029 : EditCharAttribItalic::EditCharAttribItalic( const SvxPostureItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
97 1029 : : EditCharAttrib( rAttr, _nStart, _nEnd )
98 : {
99 : DBG_ASSERT( rAttr.Which() == EE_CHAR_ITALIC || rAttr.Which() == EE_CHAR_ITALIC_CJK || rAttr.Which() == EE_CHAR_ITALIC_CTL, "Not a Italic attribute!" );
100 1029 : }
101 :
102 431 : void EditCharAttribItalic::SetFont( SvxFont& rFont, OutputDevice* )
103 : {
104 431 : rFont.SetItalic( ((const SvxPostureItem*)GetItem())->GetPosture() );
105 431 : }
106 :
107 : // -------------------------------------------------------------------------
108 : // class EditCharAttribWeight
109 : // -------------------------------------------------------------------------
110 13824 : EditCharAttribWeight::EditCharAttribWeight( const SvxWeightItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
111 13824 : : EditCharAttrib( rAttr, _nStart, _nEnd )
112 : {
113 : DBG_ASSERT( rAttr.Which() == EE_CHAR_WEIGHT || rAttr.Which() == EE_CHAR_WEIGHT_CJK || rAttr.Which() == EE_CHAR_WEIGHT_CTL, "Not a Weight attribute!" );
114 13824 : }
115 :
116 5892 : void EditCharAttribWeight::SetFont( SvxFont& rFont, OutputDevice* )
117 : {
118 5892 : rFont.SetWeight( (FontWeight)((const SvxWeightItem*)GetItem())->GetValue() );
119 5892 : }
120 :
121 : // -------------------------------------------------------------------------
122 : // class EditCharAttribUnderline
123 : // -------------------------------------------------------------------------
124 348 : EditCharAttribUnderline::EditCharAttribUnderline( const SvxUnderlineItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
125 348 : : EditCharAttrib( rAttr, _nStart, _nEnd )
126 : {
127 : DBG_ASSERT( rAttr.Which() == EE_CHAR_UNDERLINE, "Not a Underline attribute!" );
128 348 : }
129 :
130 417 : void EditCharAttribUnderline::SetFont( SvxFont& rFont, OutputDevice* pOutDev )
131 : {
132 417 : rFont.SetUnderline( (FontUnderline)((const SvxUnderlineItem*)GetItem())->GetValue() );
133 417 : if ( pOutDev )
134 20 : pOutDev->SetTextLineColor( ((const SvxUnderlineItem*)GetItem())->GetColor() );
135 417 : }
136 :
137 : // -------------------------------------------------------------------------
138 : // class EditCharAttribOverline
139 : // -------------------------------------------------------------------------
140 16 : EditCharAttribOverline::EditCharAttribOverline( const SvxOverlineItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
141 16 : : EditCharAttrib( rAttr, _nStart, _nEnd )
142 : {
143 : DBG_ASSERT( rAttr.Which() == EE_CHAR_OVERLINE, "Not a overline attribute!" );
144 16 : }
145 :
146 84 : void EditCharAttribOverline::SetFont( SvxFont& rFont, OutputDevice* pOutDev )
147 : {
148 84 : rFont.SetOverline( (FontUnderline)((const SvxOverlineItem*)GetItem())->GetValue() );
149 84 : if ( pOutDev )
150 12 : pOutDev->SetOverlineColor( ((const SvxOverlineItem*)GetItem())->GetColor() );
151 84 : }
152 :
153 : // -------------------------------------------------------------------------
154 : // class EditCharAttribFontHeight
155 : // -------------------------------------------------------------------------
156 18071 : EditCharAttribFontHeight::EditCharAttribFontHeight( const SvxFontHeightItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
157 18071 : : EditCharAttrib( rAttr, _nStart, _nEnd )
158 : {
159 : DBG_ASSERT( rAttr.Which() == EE_CHAR_FONTHEIGHT || rAttr.Which() == EE_CHAR_FONTHEIGHT_CJK || rAttr.Which() == EE_CHAR_FONTHEIGHT_CTL, "Not a Height attribute!" );
160 18071 : }
161 :
162 7531 : void EditCharAttribFontHeight::SetFont( SvxFont& rFont, OutputDevice* )
163 : {
164 : // Property is ignored
165 7531 : rFont.SetSize( Size( rFont.GetSize().Width(), ((const SvxFontHeightItem*)GetItem())->GetHeight() ) );
166 7531 : }
167 :
168 : // -------------------------------------------------------------------------
169 : // class EditCharAttribFontWidth
170 : // -------------------------------------------------------------------------
171 6 : EditCharAttribFontWidth::EditCharAttribFontWidth( const SvxCharScaleWidthItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
172 6 : : EditCharAttrib( rAttr, _nStart, _nEnd )
173 : {
174 : DBG_ASSERT( rAttr.Which() == EE_CHAR_FONTWIDTH, "Not a Width attribute!" );
175 6 : }
176 :
177 80 : void EditCharAttribFontWidth::SetFont( SvxFont& /*rFont*/, OutputDevice* )
178 : {
179 : // must be calculated outside, because f(device)...
180 80 : }
181 :
182 : // -------------------------------------------------------------------------
183 : // class EditCharAttribStrikeout
184 : // -------------------------------------------------------------------------
185 320 : EditCharAttribStrikeout::EditCharAttribStrikeout( const SvxCrossedOutItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
186 320 : : EditCharAttrib( rAttr, _nStart, _nEnd )
187 : {
188 : DBG_ASSERT( rAttr.Which() == EE_CHAR_STRIKEOUT, "Not a Size attribute!" );
189 320 : }
190 :
191 403 : void EditCharAttribStrikeout::SetFont( SvxFont& rFont, OutputDevice* )
192 : {
193 403 : rFont.SetStrikeout( (FontStrikeout)((const SvxCrossedOutItem*)GetItem())->GetValue() );
194 403 : }
195 :
196 : // -------------------------------------------------------------------------
197 : // class EditCharAttribColor
198 : // -------------------------------------------------------------------------
199 6436 : EditCharAttribColor::EditCharAttribColor( const SvxColorItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
200 6436 : : EditCharAttrib( rAttr, _nStart, _nEnd )
201 : {
202 : DBG_ASSERT( rAttr.Which() == EE_CHAR_COLOR, "Not a Color attribute!" );
203 6436 : }
204 :
205 7398 : void EditCharAttribColor::SetFont( SvxFont& rFont, OutputDevice* )
206 : {
207 7398 : rFont.SetColor( ((const SvxColorItem*)GetItem())->GetValue() );
208 7398 : }
209 :
210 : // -------------------------------------------------------------------------
211 : // class EditCharAttribLanguage
212 : // -------------------------------------------------------------------------
213 12798 : EditCharAttribLanguage::EditCharAttribLanguage( const SvxLanguageItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
214 12798 : : EditCharAttrib( rAttr, _nStart, _nEnd )
215 : {
216 : DBG_ASSERT( ( rAttr.Which() == EE_CHAR_LANGUAGE ) || ( rAttr.Which() == EE_CHAR_LANGUAGE_CJK ) || ( rAttr.Which() == EE_CHAR_LANGUAGE_CTL ), "Not a Language attribute!" );
217 12798 : }
218 :
219 7552 : void EditCharAttribLanguage::SetFont( SvxFont& rFont, OutputDevice* )
220 : {
221 7552 : rFont.SetLanguage( ((const SvxLanguageItem*)GetItem())->GetLanguage() );
222 7552 : }
223 :
224 : // -------------------------------------------------------------------------
225 : // class EditCharAttribShadow
226 : // -------------------------------------------------------------------------
227 257 : EditCharAttribShadow::EditCharAttribShadow( const SvxShadowedItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
228 257 : : EditCharAttrib( rAttr, _nStart, _nEnd )
229 : {
230 : DBG_ASSERT( rAttr.Which() == EE_CHAR_SHADOW, "Not a Shadow attribute!" );
231 257 : }
232 :
233 298 : void EditCharAttribShadow::SetFont( SvxFont& rFont, OutputDevice* )
234 : {
235 298 : rFont.SetShadow( (sal_Bool)((const SvxShadowedItem*)GetItem())->GetValue() );
236 298 : }
237 :
238 : // -------------------------------------------------------------------------
239 : // class EditCharAttribEscapement
240 : // -------------------------------------------------------------------------
241 470 : EditCharAttribEscapement::EditCharAttribEscapement( const SvxEscapementItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
242 470 : : EditCharAttrib( rAttr, _nStart, _nEnd )
243 : {
244 : DBG_ASSERT( rAttr.Which() == EE_CHAR_ESCAPEMENT, "Not a escapement attribute!" );
245 470 : }
246 :
247 496 : void EditCharAttribEscapement::SetFont( SvxFont& rFont, OutputDevice* )
248 : {
249 496 : sal_uInt16 nProp = ((const SvxEscapementItem*)GetItem())->GetProp();
250 496 : rFont.SetPropr( (sal_uInt8)nProp );
251 :
252 496 : short nEsc = ((const SvxEscapementItem*)GetItem())->GetEsc();
253 496 : if ( nEsc == DFLT_ESC_AUTO_SUPER )
254 0 : nEsc = 100 - nProp;
255 496 : else if ( nEsc == DFLT_ESC_AUTO_SUB )
256 0 : nEsc = sal::static_int_cast< short >( -( 100 - nProp ) );
257 496 : rFont.SetEscapement( nEsc );
258 496 : }
259 :
260 : // -------------------------------------------------------------------------
261 : // class EditCharAttribOutline
262 : // -------------------------------------------------------------------------
263 239 : EditCharAttribOutline::EditCharAttribOutline( const SvxContourItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
264 239 : : EditCharAttrib( rAttr, _nStart, _nEnd )
265 : {
266 : DBG_ASSERT( rAttr.Which() == EE_CHAR_OUTLINE, "Not a Outline attribute!" );
267 239 : }
268 :
269 280 : void EditCharAttribOutline::SetFont( SvxFont& rFont, OutputDevice* )
270 : {
271 280 : rFont.SetOutline( (sal_Bool)((const SvxContourItem*)GetItem())->GetValue() );
272 280 : }
273 :
274 : // -------------------------------------------------------------------------
275 : // class EditCharAttribTab
276 : // -------------------------------------------------------------------------
277 108 : EditCharAttribTab::EditCharAttribTab( const SfxVoidItem& rAttr, sal_uInt16 nPos )
278 108 : : EditCharAttrib( rAttr, nPos, nPos+1 )
279 : {
280 108 : SetFeature( sal_True );
281 108 : }
282 :
283 36 : void EditCharAttribTab::SetFont( SvxFont&, OutputDevice* )
284 : {
285 36 : }
286 :
287 : // -------------------------------------------------------------------------
288 : // class EditCharAttribLineBreak
289 : // -------------------------------------------------------------------------
290 6 : EditCharAttribLineBreak::EditCharAttribLineBreak( const SfxVoidItem& rAttr, sal_uInt16 nPos )
291 6 : : EditCharAttrib( rAttr, nPos, nPos+1 )
292 : {
293 6 : SetFeature( sal_True );
294 6 : }
295 :
296 3 : void EditCharAttribLineBreak::SetFont( SvxFont&, OutputDevice* )
297 : {
298 3 : }
299 :
300 : // -------------------------------------------------------------------------
301 : // class EditCharAttribField
302 : // -------------------------------------------------------------------------
303 1706 : EditCharAttribField::EditCharAttribField( const SvxFieldItem& rAttr, sal_uInt16 nPos )
304 1706 : : EditCharAttrib( rAttr, nPos, nPos+1 )
305 : {
306 1706 : SetFeature( sal_True ); // !!!
307 1706 : pTxtColor = 0;
308 1706 : pFldColor = 0;
309 1706 : }
310 :
311 1192 : void EditCharAttribField::SetFont( SvxFont& rFont, OutputDevice* )
312 : {
313 1192 : if ( pFldColor )
314 : {
315 0 : rFont.SetFillColor( *pFldColor );
316 0 : rFont.SetTransparent( sal_False );
317 : }
318 1192 : if ( pTxtColor )
319 0 : rFont.SetColor( *pTxtColor );
320 1192 : }
321 :
322 2827 : const rtl::OUString& EditCharAttribField::GetFieldValue() const
323 : {
324 2827 : return aFieldValue;
325 : }
326 :
327 652 : void EditCharAttribField::SetFieldValue(const rtl::OUString& rVal)
328 : {
329 652 : aFieldValue = rVal;
330 652 : }
331 :
332 3010 : void EditCharAttribField::Reset()
333 : {
334 3010 : aFieldValue = rtl::OUString();
335 3010 : delete pTxtColor; pTxtColor = NULL;
336 3010 : delete pFldColor; pFldColor = NULL;
337 3010 : }
338 :
339 652 : EditCharAttribField::EditCharAttribField( const EditCharAttribField& rAttr )
340 1956 : : EditCharAttrib( *rAttr.GetItem(), rAttr.GetStart(), rAttr.GetEnd() ),
341 1956 : aFieldValue( rAttr.aFieldValue )
342 : {
343 : // Use this constructor only for temporary Objects, Item is not pooled.
344 652 : pTxtColor = rAttr.pTxtColor ? new Color( *rAttr.pTxtColor ) : 0;
345 652 : pFldColor = rAttr.pFldColor ? new Color( *rAttr.pFldColor ) : 0;
346 652 : }
347 :
348 7074 : EditCharAttribField::~EditCharAttribField()
349 : {
350 2358 : Reset();
351 4716 : }
352 :
353 652 : bool EditCharAttribField::operator == ( const EditCharAttribField& rAttr ) const
354 : {
355 652 : if ( aFieldValue != rAttr.aFieldValue )
356 576 : return false;
357 :
358 76 : if ( ( pTxtColor && !rAttr.pTxtColor ) || ( !pTxtColor && rAttr.pTxtColor ) )
359 0 : return false;
360 76 : if ( ( pTxtColor && rAttr.pTxtColor ) && ( *pTxtColor != *rAttr.pTxtColor ) )
361 0 : return false;
362 :
363 76 : if ( ( pFldColor && !rAttr.pFldColor ) || ( !pFldColor && rAttr.pFldColor ) )
364 0 : return false;
365 76 : if ( ( pFldColor && rAttr.pFldColor ) && ( *pFldColor != *rAttr.pFldColor ) )
366 0 : return false;
367 :
368 76 : return true;
369 : }
370 :
371 : // -------------------------------------------------------------------------
372 : // class EditCharAttribPairKerning
373 : // -------------------------------------------------------------------------
374 6 : EditCharAttribPairKerning::EditCharAttribPairKerning( const SvxAutoKernItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
375 6 : : EditCharAttrib( rAttr, _nStart, _nEnd )
376 : {
377 : DBG_ASSERT( rAttr.Which() == EE_CHAR_PAIRKERNING, "Not a Pair Kerning!" );
378 6 : }
379 :
380 80 : void EditCharAttribPairKerning::SetFont( SvxFont& rFont, OutputDevice* )
381 : {
382 80 : rFont.SetKerning( ((const SvxAutoKernItem*)GetItem())->GetValue() );
383 80 : }
384 :
385 : // -------------------------------------------------------------------------
386 : // class EditCharAttribKerning
387 : // -------------------------------------------------------------------------
388 73 : EditCharAttribKerning::EditCharAttribKerning( const SvxKerningItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
389 73 : : EditCharAttrib( rAttr, _nStart, _nEnd )
390 : {
391 : DBG_ASSERT( rAttr.Which() == EE_CHAR_KERNING, "Not a Kerning!" );
392 73 : }
393 :
394 197 : void EditCharAttribKerning::SetFont( SvxFont& rFont, OutputDevice* )
395 : {
396 197 : rFont.SetFixKerning( ((const SvxKerningItem*)GetItem())->GetValue() );
397 197 : }
398 :
399 : // -------------------------------------------------------------------------
400 : // class EditCharAttribWordLineMode
401 : // -------------------------------------------------------------------------
402 16 : EditCharAttribWordLineMode::EditCharAttribWordLineMode( const SvxWordLineModeItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
403 16 : : EditCharAttrib( rAttr, _nStart, _nEnd )
404 : {
405 : DBG_ASSERT( rAttr.Which() == EE_CHAR_WLM, "Not a Kerning!" );
406 16 : }
407 :
408 84 : void EditCharAttribWordLineMode::SetFont( SvxFont& rFont, OutputDevice* )
409 : {
410 84 : rFont.SetWordLineMode( ((const SvxWordLineModeItem*)GetItem())->GetValue() );
411 84 : }
412 :
413 : // -------------------------------------------------------------------------
414 : // class EditCharAttribEmphasisMark
415 : // -------------------------------------------------------------------------
416 16 : EditCharAttribEmphasisMark::EditCharAttribEmphasisMark( const SvxEmphasisMarkItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
417 16 : : EditCharAttrib( rAttr, _nStart, _nEnd )
418 : {
419 : DBG_ASSERT( rAttr.Which() == EE_CHAR_EMPHASISMARK, "Not a Emphasis attribute!" );
420 16 : }
421 :
422 84 : void EditCharAttribEmphasisMark::SetFont( SvxFont& rFont, OutputDevice* )
423 : {
424 84 : rFont.SetEmphasisMark( ((const SvxEmphasisMarkItem*)GetItem())->GetEmphasisMark() );
425 84 : }
426 :
427 : // -------------------------------------------------------------------------
428 : // class EditCharAttribRelief
429 : // -------------------------------------------------------------------------
430 30 : EditCharAttribRelief::EditCharAttribRelief( const SvxCharReliefItem& rAttr, sal_uInt16 _nStart, sal_uInt16 _nEnd )
431 30 : : EditCharAttrib( rAttr, _nStart, _nEnd )
432 : {
433 : DBG_ASSERT( rAttr.Which() == EE_CHAR_RELIEF, "Not a relief attribute!" );
434 30 : }
435 :
436 90 : void EditCharAttribRelief::SetFont( SvxFont& rFont, OutputDevice* )
437 : {
438 90 : rFont.SetRelief( (FontRelief)((const SvxCharReliefItem*)GetItem())->GetValue() );
439 90 : }
440 :
441 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|