build fix
[LibreOffice.git] / sw / source / filter / html / htmldrawwriter.cxx
blob2debe01231ba1cc76b547eb168bc9e18727ac0c6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "hintids.hxx"
21 #include <vcl/svapp.hxx>
22 #include <vcl/wrkwin.hxx>
23 #include <svx/svdmodel.hxx>
24 #include <svx/svdpage.hxx>
25 #include <svx/svdobj.hxx>
26 #include <svx/svdotext.hxx>
27 #include <editeng/eeitem.hxx>
28 #include <editeng/outliner.hxx>
29 #include <svx/xfillit.hxx>
30 #include <editeng/colritem.hxx>
31 #include <editeng/brushitem.hxx>
32 #include <editeng/lrspitem.hxx>
33 #include <editeng/ulspitem.hxx>
34 #include <svl/itemiter.hxx>
35 #include <svl/whiter.hxx>
36 #include <svtools/htmlout.hxx>
37 #include <svtools/htmltokn.h>
38 #include <svtools/htmlkywd.hxx>
39 #include <svx/svdpool.hxx>
41 #include <rtl/strbuf.hxx>
43 #include <IDocumentDrawModelAccess.hxx>
44 #include "charatr.hxx"
45 #include <frmfmt.hxx>
46 #include <fmtanchr.hxx>
47 #include <fmtsrnd.hxx>
48 #include "ndtxt.hxx"
49 #include "doc.hxx"
50 #include "dcontact.hxx"
51 #include "poolfmt.hxx"
53 #include "wrthtml.hxx"
56 using namespace css;
58 const sal_uInt32 HTML_FRMOPTS_MARQUEE =
59 HTML_FRMOPT_ALIGN |
60 HTML_FRMOPT_SPACE;
62 const sal_uInt32 HTML_FRMOPTS_MARQUEE_CSS1 =
63 HTML_FRMOPT_S_ALIGN |
64 HTML_FRMOPT_S_SPACE;
66 const SdrObject *SwHTMLWriter::GetMarqueeTextObj( const SwDrawFrameFormat& rFormat )
68 const SdrObject* pObj = rFormat.FindSdrObject();
69 return (pObj && ::IsMarqueeTextObj( *pObj )) ? pObj : nullptr;
72 void SwHTMLWriter::GetEEAttrsFromDrwObj( SfxItemSet& rItemSet,
73 const SdrObject *pObj,
74 bool bSetDefaults )
76 // die Edit script::Engine-Attribute aus dem Objekt holen
77 SfxItemSet rObjItemSet = pObj->GetMergedItemSet();
79 // ueber die Edit script::Engine-Attribute iterieren und die Attribute
80 // in SW-Attrs wandeln bzw. default setzen
81 SfxWhichIter aIter( rObjItemSet );
82 sal_uInt16 nEEWhich = aIter.FirstWhich();
83 while( nEEWhich )
85 const SfxPoolItem *pEEItem;
86 bool bSet = SfxItemState::SET == rObjItemSet.GetItemState( nEEWhich, false,
87 &pEEItem );
89 if( bSet || bSetDefaults )
91 sal_uInt16 nSwWhich = 0;
92 switch( nEEWhich )
94 case EE_CHAR_COLOR: nSwWhich = RES_CHRATR_COLOR; break;
95 case EE_CHAR_STRIKEOUT: nSwWhich = RES_CHRATR_CROSSEDOUT; break;
96 case EE_CHAR_ESCAPEMENT: nSwWhich = RES_CHRATR_ESCAPEMENT; break;
97 case EE_CHAR_FONTINFO: nSwWhich = RES_CHRATR_FONT; break;
98 case EE_CHAR_FONTINFO_CJK: nSwWhich = RES_CHRATR_CJK_FONT; break;
99 case EE_CHAR_FONTINFO_CTL: nSwWhich = RES_CHRATR_CTL_FONT; break;
100 case EE_CHAR_FONTHEIGHT: nSwWhich = RES_CHRATR_FONTSIZE; break;
101 case EE_CHAR_FONTHEIGHT_CJK:nSwWhich = RES_CHRATR_CJK_FONTSIZE; break;
102 case EE_CHAR_FONTHEIGHT_CTL:nSwWhich = RES_CHRATR_CTL_FONTSIZE; break;
103 case EE_CHAR_KERNING: nSwWhich = RES_CHRATR_KERNING; break;
104 case EE_CHAR_ITALIC: nSwWhich = RES_CHRATR_POSTURE; break;
105 case EE_CHAR_ITALIC_CJK: nSwWhich = RES_CHRATR_CJK_POSTURE; break;
106 case EE_CHAR_ITALIC_CTL: nSwWhich = RES_CHRATR_CTL_POSTURE; break;
107 case EE_CHAR_UNDERLINE: nSwWhich = RES_CHRATR_UNDERLINE; break;
108 case EE_CHAR_WEIGHT: nSwWhich = RES_CHRATR_WEIGHT; break;
109 case EE_CHAR_WEIGHT_CJK: nSwWhich = RES_CHRATR_CJK_WEIGHT; break;
110 case EE_CHAR_WEIGHT_CTL: nSwWhich = RES_CHRATR_CTL_WEIGHT; break;
113 if( nSwWhich )
115 // wenn das Item nicht gesetzt ist nehmen wir ggf. das
116 // Default-Item
117 if( !bSet )
118 pEEItem = &rObjItemSet.GetPool()->GetDefaultItem(nEEWhich);
120 // jetzt Clonen wir das Item mit der Which-Id des Writers
121 SfxPoolItem *pSwItem = pEEItem->Clone();
122 pSwItem->SetWhich( nSwWhich );
123 rItemSet.Put( *pSwItem );
124 delete pSwItem;
128 nEEWhich = aIter.NextWhich();
132 Writer& OutHTML_DrawFrameFormatAsMarquee( Writer& rWrt,
133 const SwDrawFrameFormat& rFormat,
134 const SdrObject& rSdrObject )
136 SwHTMLWriter & rHTMLWrt = static_cast<SwHTMLWriter&>(rWrt);
138 OSL_ENSURE( rWrt.pDoc->getIDocumentDrawModelAccess().GetDrawModel(),
139 "There is a Draw-Obj with no Draw-Model?" );
140 const SdrTextObj *pTextObj = static_cast<const SdrTextObj *>(&rSdrObject);
142 // Gibt es ueberhaupt auszugebenden Text
143 const OutlinerParaObject *pOutlinerParaObj =
144 pTextObj->GetOutlinerParaObject();
145 if( !pOutlinerParaObj )
146 return rWrt;
148 OStringBuffer sOut;
149 sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_marquee);
151 // Die Attribute des Objektd holen
152 const SfxItemSet& rItemSet = pTextObj->GetMergedItemSet();
154 // BEHAVIOUR
155 SdrTextAniKind eAniKind = pTextObj->GetTextAniKind();
156 OSL_ENSURE( SDRTEXTANI_SCROLL==eAniKind ||
157 SDRTEXTANI_ALTERNATE==eAniKind ||
158 SDRTEXTANI_SLIDE==eAniKind,
159 "Text-Draw-Objekt nicht fuer Marquee geeignet" );
161 const sal_Char *pStr = nullptr;
162 switch( eAniKind )
164 case SDRTEXTANI_SCROLL: pStr = OOO_STRING_SVTOOLS_HTML_BEHAV_scroll; break;
165 case SDRTEXTANI_SLIDE: pStr = OOO_STRING_SVTOOLS_HTML_BEHAV_slide; break;
166 case SDRTEXTANI_ALTERNATE: pStr = OOO_STRING_SVTOOLS_HTML_BEHAV_alternate; break;
167 default:
171 if( pStr )
173 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_behavior).
174 append("=\"").append(pStr).append("\"");
177 // DIRECTION
178 pStr = nullptr;
179 SdrTextAniDirection eAniDir = pTextObj->GetTextAniDirection();
180 switch( eAniDir )
182 case SdrTextAniDirection::Left: pStr = OOO_STRING_SVTOOLS_HTML_AL_left; break;
183 case SdrTextAniDirection::Right: pStr = OOO_STRING_SVTOOLS_HTML_AL_right; break;
184 default:
188 if( pStr )
190 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_direction).
191 append("=\"").append(pStr).append("\"");
194 // LOOP
195 sal_Int32 nCount =
196 static_cast<const SdrTextAniCountItem&>(rItemSet.Get( SDRATTR_TEXT_ANICOUNT ))
197 .GetValue();
198 if( 0==nCount )
199 nCount = SDRTEXTANI_SLIDE==eAniKind ? 1 : -1;
200 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_loop).append("=\"").
201 append(nCount).append("\"");
203 // SCROLLDELAY
204 sal_uInt16 nDelay =
205 static_cast<const SdrTextAniDelayItem&>(rItemSet.Get( SDRATTR_TEXT_ANIDELAY ))
206 .GetValue();
207 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_scrolldelay).
208 append("=\"").append(static_cast<sal_Int32>(nDelay)).append("\"");
210 // SCROLLAMOUNT
211 sal_Int16 nAmount =
212 static_cast<const SdrTextAniAmountItem&>(rItemSet.Get( SDRATTR_TEXT_ANIAMOUNT ))
213 .GetValue();
214 if( nAmount < 0 )
216 nAmount = -nAmount;
218 else if( nAmount && Application::GetDefaultDevice() )
220 nAmount = Application::GetDefaultDevice()
221 ->LogicToPixel( Size(nAmount,0),
222 MapMode(MapUnit::MapTwip) ).Width();
224 if( nAmount )
226 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_scrollamount).
227 append("=\"").append(static_cast<sal_Int32>(nAmount)).append("\"");
230 Size aTwipSz( pTextObj->GetLogicRect().GetSize() );
231 if( pTextObj->IsAutoGrowWidth() )
232 aTwipSz.Width() = 0;
233 // Die Hoehe ist bei MS eine Mindesthoehe, also geben wir auch die
234 // Mindestheoehe aus, wenn es sie gibt. Da eine Mindesthoehe MINFLY
235 // mit hoher Wahrscheinlichkeit vom Import kommt, wird sie nicht mit
236 // ausgegeben. Falsch machen kann man da nichst, denn jeder Font ist
237 // hoeher.
238 if( pTextObj->IsAutoGrowHeight() )
240 aTwipSz.Height() = pTextObj->GetMinTextFrameHeight();
241 if( MINFLY==aTwipSz.Height() )
242 aTwipSz.Height() = 0;
245 if( (aTwipSz.Width() || aTwipSz.Height()) &&
246 Application::GetDefaultDevice() )
248 Size aPixelSz =
249 Application::GetDefaultDevice()->LogicToPixel( aTwipSz,
250 MapMode(MapUnit::MapTwip) );
251 if( !aPixelSz.Width() && aTwipSz.Width() )
252 aPixelSz.Width() = 1;
253 if( !aPixelSz.Height() && aTwipSz.Height() )
254 aPixelSz.Height() = 1;
256 if( aPixelSz.Width() )
258 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_width).
259 append("=\"").append(static_cast<sal_Int32>(aPixelSz.Width())).append("\"");
262 if( aPixelSz.Height() )
264 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_height).
265 append("=\"").append(static_cast<sal_Int32>(aPixelSz.Height())).append("\"");
269 // BGCOLOR
270 drawing::FillStyle eFillStyle =
271 static_cast<const XFillStyleItem&>(rItemSet.Get(XATTR_FILLSTYLE)).GetValue();
272 if( drawing::FillStyle_SOLID==eFillStyle )
274 const Color& rFillColor =
275 static_cast<const XFillColorItem&>(rItemSet.Get(XATTR_FILLCOLOR)).GetColorValue();
277 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_bgcolor).append("=");
278 rWrt.Strm().WriteCharPtr( sOut.makeStringAndClear().getStr() );
279 HTMLOutFuncs::Out_Color( rWrt.Strm(), rFillColor, rHTMLWrt.m_eDestEnc );
282 if (!sOut.isEmpty())
283 rWrt.Strm().WriteCharPtr( sOut.makeStringAndClear().getStr() );
285 // und nun noch ALIGN, HSPACE und VSPACE
286 sal_uInt32 nFrameFlags = HTML_FRMOPTS_MARQUEE;
287 if( rHTMLWrt.IsHTMLMode( HTMLMODE_ABS_POS_DRAW ) )
288 nFrameFlags |= HTML_FRMOPTS_MARQUEE_CSS1;
289 OString aEndTags = rHTMLWrt.OutFrameFormatOptions( rFormat, aEmptyOUStr, nFrameFlags );
290 if( rHTMLWrt.IsHTMLMode( HTMLMODE_ABS_POS_DRAW ) )
291 rHTMLWrt.OutCSS1_FrameFormatOptions( rFormat, nFrameFlags, &rSdrObject );
293 rWrt.Strm().WriteChar( '>' );
295 // Was jetzt kommt ist das Gegenstueck zu SdrTextObjectt::SetText()
296 Outliner aOutliner(nullptr, OutlinerMode::TextObject);
297 aOutliner.SetUpdateMode( false );
298 aOutliner.SetText( *pOutlinerParaObj );
299 OUString aText( aOutliner.GetText( aOutliner.GetParagraph(0),
300 aOutliner.GetParagraphCount() ) );
301 HTMLOutFuncs::Out_String( rWrt.Strm(), aText,
302 rHTMLWrt.m_eDestEnc, &rHTMLWrt.m_aNonConvertableCharacters );
304 HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), OOO_STRING_SVTOOLS_HTML_marquee, false );
306 if( !aEndTags.isEmpty() )
307 rWrt.Strm().WriteCharPtr( aEndTags.getStr() );
309 return rWrt;
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */