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 <hintids.hxx>
21 #include <vcl/svapp.hxx>
22 #include <svx/svdobj.hxx>
23 #include <svx/svdotext.hxx>
24 #include <svx/sdtacitm.hxx>
25 #include <svx/sdtayitm.hxx>
26 #include <svx/sdtaaitm.hxx>
27 #include <editeng/eeitem.hxx>
28 #include <editeng/outliner.hxx>
29 #include <svx/xfillit0.hxx>
30 #include <svx/xflclit.hxx>
31 #include <svl/whiter.hxx>
32 #include <svtools/htmlout.hxx>
33 #include <svtools/htmlkywd.hxx>
34 #include <osl/diagnose.h>
35
36 #include <rtl/strbuf.hxx>
37
38 #include <IDocumentDrawModelAccess.hxx>
39 #include <frmfmt.hxx>
40 #include <doc.hxx>
41 #include <dcontact.hxx>
42
43 #include "wrthtml.hxx"
44
45
46 using namespace css;
47
48 const HtmlFrmOpts HTML_FRMOPTS_MARQUEE =
49 HtmlFrmOpts::Align |
50 HtmlFrmOpts::Space;
51
52 const HtmlFrmOpts HTML_FRMOPTS_MARQUEE_CSS1 =
53 HtmlFrmOpts::SAlign |
54 HtmlFrmOpts::SSpace;
55
GetMarqueeTextObj(const SwDrawFrameFormat & rFormat)56 const SdrObject *SwHTMLWriter::GetMarqueeTextObj( const SwDrawFrameFormat& rFormat )
57 {
58 const SdrObject* pObj = rFormat.FindSdrObject();
59 return (pObj && ::IsMarqueeTextObj( *pObj )) ? pObj : nullptr;
60 }
61
GetEEAttrsFromDrwObj(SfxItemSet & rItemSet,const SdrObject * pObj)62 void SwHTMLWriter::GetEEAttrsFromDrwObj( SfxItemSet& rItemSet,
63 const SdrObject *pObj )
64 {
65 // get the edit script::Engine attributes from object
66 const SfxItemSet& rObjItemSet = pObj->GetMergedItemSet();
67
68 // iterate over Edit script::Engine attributes and convert them
69 // into SW-Attrs resp. set default
70 SfxWhichIter aIter( rObjItemSet );
71 sal_uInt16 nEEWhich = aIter.FirstWhich();
72 while( nEEWhich )
73 {
74 const SfxPoolItem *pEEItem;
75 bool bSet = SfxItemState::SET == rObjItemSet.GetItemState( nEEWhich, false,
76 &pEEItem );
77
78 sal_uInt16 nSwWhich = 0;
79 switch( nEEWhich )
80 {
81 case EE_CHAR_COLOR: nSwWhich = RES_CHRATR_COLOR; break;
82 case EE_CHAR_STRIKEOUT: nSwWhich = RES_CHRATR_CROSSEDOUT; break;
83 case EE_CHAR_ESCAPEMENT: nSwWhich = RES_CHRATR_ESCAPEMENT; break;
84 case EE_CHAR_FONTINFO: nSwWhich = RES_CHRATR_FONT; break;
85 case EE_CHAR_FONTINFO_CJK: nSwWhich = RES_CHRATR_CJK_FONT; break;
86 case EE_CHAR_FONTINFO_CTL: nSwWhich = RES_CHRATR_CTL_FONT; break;
87 case EE_CHAR_FONTHEIGHT: nSwWhich = RES_CHRATR_FONTSIZE; break;
88 case EE_CHAR_FONTHEIGHT_CJK:nSwWhich = RES_CHRATR_CJK_FONTSIZE; break;
89 case EE_CHAR_FONTHEIGHT_CTL:nSwWhich = RES_CHRATR_CTL_FONTSIZE; break;
90 case EE_CHAR_KERNING: nSwWhich = RES_CHRATR_KERNING; break;
91 case EE_CHAR_ITALIC: nSwWhich = RES_CHRATR_POSTURE; break;
92 case EE_CHAR_ITALIC_CJK: nSwWhich = RES_CHRATR_CJK_POSTURE; break;
93 case EE_CHAR_ITALIC_CTL: nSwWhich = RES_CHRATR_CTL_POSTURE; break;
94 case EE_CHAR_UNDERLINE: nSwWhich = RES_CHRATR_UNDERLINE; break;
95 case EE_CHAR_WEIGHT: nSwWhich = RES_CHRATR_WEIGHT; break;
96 case EE_CHAR_WEIGHT_CJK: nSwWhich = RES_CHRATR_CJK_WEIGHT; break;
97 case EE_CHAR_WEIGHT_CTL: nSwWhich = RES_CHRATR_CTL_WEIGHT; break;
98 }
99
100 if( nSwWhich )
101 {
102 // if the item isn't set we maybe take the default item
103 if( !bSet )
104 pEEItem = &rObjItemSet.GetPool()->GetDefaultItem(nEEWhich);
105
106 // now we clone the item with the which id of the writer
107 rItemSet.Put( pEEItem->CloneSetWhich(nSwWhich) );
108 }
109
110 nEEWhich = aIter.NextWhich();
111 }
112 }
113
OutHTML_DrawFrameFormatAsMarquee(Writer & rWrt,const SwDrawFrameFormat & rFormat,const SdrObject & rSdrObject)114 Writer& OutHTML_DrawFrameFormatAsMarquee( Writer& rWrt,
115 const SwDrawFrameFormat& rFormat,
116 const SdrObject& rSdrObject )
117 {
118 SwHTMLWriter & rHTMLWrt = static_cast<SwHTMLWriter&>(rWrt);
119
120 OSL_ENSURE( rWrt.m_pDoc->getIDocumentDrawModelAccess().GetDrawModel(),
121 "There is a Draw-Obj with no Draw-Model?" );
122 const SdrTextObj *pTextObj = static_cast<const SdrTextObj *>(&rSdrObject);
123
124 // Is there text to output
125 const OutlinerParaObject *pOutlinerParaObj =
126 pTextObj->GetOutlinerParaObject();
127 if( !pOutlinerParaObj )
128 return rWrt;
129
130 OStringBuffer sOut;
131 sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_marquee);
132
133 // get attributes of the object
134 const SfxItemSet& rItemSet = pTextObj->GetMergedItemSet();
135
136 // BEHAVIOUR
137 SdrTextAniKind eAniKind = pTextObj->GetTextAniKind();
138 OSL_ENSURE( SdrTextAniKind::Scroll==eAniKind ||
139 SdrTextAniKind::Alternate==eAniKind ||
140 SdrTextAniKind::Slide==eAniKind,
141 "Text-Draw-Object not suitable for marquee" );
142
143 const char *pStr = nullptr;
144 switch( eAniKind )
145 {
146 case SdrTextAniKind::Scroll: pStr = OOO_STRING_SVTOOLS_HTML_BEHAV_scroll; break;
147 case SdrTextAniKind::Slide: pStr = OOO_STRING_SVTOOLS_HTML_BEHAV_slide; break;
148 case SdrTextAniKind::Alternate: pStr = OOO_STRING_SVTOOLS_HTML_BEHAV_alternate; break;
149 default:
150 ;
151 }
152
153 if( pStr )
154 {
155 sOut.append(OString::Concat(" " OOO_STRING_SVTOOLS_HTML_O_behavior "=\"") +
156 pStr + "\"");
157 }
158
159 // DIRECTION
160 pStr = nullptr;
161 SdrTextAniDirection eAniDir = pTextObj->GetTextAniDirection();
162 switch( eAniDir )
163 {
164 case SdrTextAniDirection::Left: pStr = OOO_STRING_SVTOOLS_HTML_AL_left; break;
165 case SdrTextAniDirection::Right: pStr = OOO_STRING_SVTOOLS_HTML_AL_right; break;
166 default:
167 ;
168 }
169
170 if( pStr )
171 {
172 sOut.append(OString::Concat(" " OOO_STRING_SVTOOLS_HTML_O_direction
173 "=\"") + pStr + "\"");
174 }
175
176 // LOOP
177 sal_Int32 nCount = rItemSet.Get( SDRATTR_TEXT_ANICOUNT ).GetValue();
178 if( 0==nCount )
179 nCount = SdrTextAniKind::Slide==eAniKind ? 1 : -1;
180 sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_loop "=\"" +
181 OString::number(nCount) + "\"");
182
183 // SCROLLDELAY
184 sal_uInt16 nDelay = rItemSet.Get( SDRATTR_TEXT_ANIDELAY ).GetValue();
185 sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_scrolldelay
186 "=\"" + OString::number(nDelay) + "\"");
187
188 // SCROLLAMOUNT
189 sal_Int16 nAmount = rItemSet.Get( SDRATTR_TEXT_ANIAMOUNT ).GetValue();
190 if( nAmount < 0 )
191 {
192 nAmount = -nAmount;
193 }
194 else if( nAmount && Application::GetDefaultDevice() )
195 {
196 nAmount = Application::GetDefaultDevice()
197 ->LogicToPixel( Size(nAmount,0),
198 MapMode(MapUnit::MapTwip) ).Width();
199 }
200 if( nAmount )
201 {
202 sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_scrollamount
203 "=\"" + OString::number(nAmount) + "\"");
204 }
205
206 Size aTwipSz( pTextObj->GetLogicRect().GetSize() );
207 if( pTextObj->IsAutoGrowWidth() )
208 aTwipSz.setWidth( 0 );
209 // The height is at MS a minimum height, therefore we output the minimum
210 // height, if they exist. Because a minimum height MINFLY is coming with
211 // high probability from import, we aren't outputting it. You can't
212 // do anything wrong, because every font is higher.
213 if( pTextObj->IsAutoGrowHeight() )
214 {
215 aTwipSz.setHeight( pTextObj->GetMinTextFrameHeight() );
216 if( MINFLY==aTwipSz.Height() )
217 aTwipSz.setHeight( 0 );
218 }
219
220 if( (aTwipSz.Width() || aTwipSz.Height()) &&
221 Application::GetDefaultDevice() )
222 {
223 Size aPixelSz =
224 Application::GetDefaultDevice()->LogicToPixel( aTwipSz,
225 MapMode(MapUnit::MapTwip) );
226 if( !aPixelSz.Width() && aTwipSz.Width() )
227 aPixelSz.setWidth( 1 );
228 if( !aPixelSz.Height() && aTwipSz.Height() )
229 aPixelSz.setHeight( 1 );
230
231 if( aPixelSz.Width() )
232 {
233 sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_width
234 "=\"" + OString::number(aPixelSz.Width()) + "\"");
235 }
236
237 if( aPixelSz.Height() )
238 {
239 sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_height
240 "=\"" + OString::number(aPixelSz.Height()) + "\"");
241 }
242 }
243
244 // BGCOLOR
245 drawing::FillStyle eFillStyle =
246 rItemSet.Get(XATTR_FILLSTYLE).GetValue();
247 if( drawing::FillStyle_SOLID==eFillStyle )
248 {
249 const Color& rFillColor =
250 rItemSet.Get(XATTR_FILLCOLOR).GetColorValue();
251
252 sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_bgcolor "=");
253 rWrt.Strm().WriteOString( sOut.makeStringAndClear() );
254 HTMLOutFuncs::Out_Color( rWrt.Strm(), rFillColor );
255 }
256
257 if (!sOut.isEmpty())
258 rWrt.Strm().WriteOString( sOut.makeStringAndClear() );
259
260 // and now ALIGN, HSPACE and VSPACE
261 HtmlFrmOpts nFrameFlags = HTML_FRMOPTS_MARQUEE;
262 if( rHTMLWrt.IsHTMLMode( HTMLMODE_ABS_POS_DRAW ) )
263 nFrameFlags |= HTML_FRMOPTS_MARQUEE_CSS1;
264 OString aEndTags = rHTMLWrt.OutFrameFormatOptions(rFormat, OUString(), nFrameFlags);
265 if( rHTMLWrt.IsHTMLMode( HTMLMODE_ABS_POS_DRAW ) )
266 rHTMLWrt.OutCSS1_FrameFormatOptions( rFormat, nFrameFlags, &rSdrObject );
267
268 rWrt.Strm().WriteChar( '>' );
269
270 // What follows now is the counterpart of SdrTextObject::SetText()
271 Outliner aOutliner(nullptr, OutlinerMode::TextObject);
272 aOutliner.SetUpdateMode( false );
273 aOutliner.SetText( *pOutlinerParaObj );
274 OUString aText( aOutliner.GetText( aOutliner.GetParagraph(0),
275 aOutliner.GetParagraphCount() ) );
276 HTMLOutFuncs::Out_String( rWrt.Strm(), aText,
277 rHTMLWrt.m_eDestEnc, &rHTMLWrt.m_aNonConvertableCharacters );
278
279 HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), OString(rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_marquee), false );
280
281 if( !aEndTags.isEmpty() )
282 rWrt.Strm().WriteOString( aEndTags );
283
284 return rWrt;
285 }
286
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
288