1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <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>
36 #include <rtl/strbuf.hxx>
38 #include <IDocumentDrawModelAccess.hxx>
41 #include <dcontact.hxx>
43 #include "wrthtml.hxx"
48 const HtmlFrmOpts HTML_FRMOPTS_MARQUEE
=
52 const HtmlFrmOpts HTML_FRMOPTS_MARQUEE_CSS1
=
56 const SdrObject
*SwHTMLWriter::GetMarqueeTextObj( const SwDrawFrameFormat
& rFormat
)
58 const SdrObject
* pObj
= rFormat
.FindSdrObject();
59 return (pObj
&& ::IsMarqueeTextObj( *pObj
)) ? pObj
: nullptr;
62 void SwHTMLWriter::GetEEAttrsFromDrwObj( SfxItemSet
& rItemSet
,
63 const SdrObject
*pObj
)
65 // get the edit script::Engine attributes from object
66 const SfxItemSet
& rObjItemSet
= pObj
->GetMergedItemSet();
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();
74 const SfxPoolItem
*pEEItem
;
75 bool bSet
= SfxItemState::SET
== aIter
.GetItemState( false, &pEEItem
);
77 sal_uInt16 nSwWhich
= 0;
80 case EE_CHAR_COLOR
: nSwWhich
= RES_CHRATR_COLOR
; break;
81 case EE_CHAR_STRIKEOUT
: nSwWhich
= RES_CHRATR_CROSSEDOUT
; break;
82 case EE_CHAR_ESCAPEMENT
: nSwWhich
= RES_CHRATR_ESCAPEMENT
; break;
83 case EE_CHAR_FONTINFO
: nSwWhich
= RES_CHRATR_FONT
; break;
84 case EE_CHAR_FONTINFO_CJK
: nSwWhich
= RES_CHRATR_CJK_FONT
; break;
85 case EE_CHAR_FONTINFO_CTL
: nSwWhich
= RES_CHRATR_CTL_FONT
; break;
86 case EE_CHAR_FONTHEIGHT
: nSwWhich
= RES_CHRATR_FONTSIZE
; break;
87 case EE_CHAR_FONTHEIGHT_CJK
:nSwWhich
= RES_CHRATR_CJK_FONTSIZE
; break;
88 case EE_CHAR_FONTHEIGHT_CTL
:nSwWhich
= RES_CHRATR_CTL_FONTSIZE
; break;
89 case EE_CHAR_KERNING
: nSwWhich
= RES_CHRATR_KERNING
; break;
90 case EE_CHAR_ITALIC
: nSwWhich
= RES_CHRATR_POSTURE
; break;
91 case EE_CHAR_ITALIC_CJK
: nSwWhich
= RES_CHRATR_CJK_POSTURE
; break;
92 case EE_CHAR_ITALIC_CTL
: nSwWhich
= RES_CHRATR_CTL_POSTURE
; break;
93 case EE_CHAR_UNDERLINE
: nSwWhich
= RES_CHRATR_UNDERLINE
; break;
94 case EE_CHAR_WEIGHT
: nSwWhich
= RES_CHRATR_WEIGHT
; break;
95 case EE_CHAR_WEIGHT_CJK
: nSwWhich
= RES_CHRATR_CJK_WEIGHT
; break;
96 case EE_CHAR_WEIGHT_CTL
: nSwWhich
= RES_CHRATR_CTL_WEIGHT
; break;
101 // if the item isn't set we maybe take the default item
103 pEEItem
= &rObjItemSet
.GetPool()->GetUserOrPoolDefaultItem(nEEWhich
);
105 // now we clone the item with the which id of the writer
106 rItemSet
.Put( pEEItem
->CloneSetWhich(nSwWhich
) );
109 nEEWhich
= aIter
.NextWhich();
113 SwHTMLWriter
& OutHTML_DrawFrameFormatAsMarquee( SwHTMLWriter
& rWrt
,
114 const SwDrawFrameFormat
& rFormat
,
115 const SdrObject
& rSdrObject
)
117 OSL_ENSURE( rWrt
.m_pDoc
->getIDocumentDrawModelAccess().GetDrawModel(),
118 "There is a Draw-Obj with no Draw-Model?" );
119 const SdrTextObj
*pTextObj
= static_cast<const SdrTextObj
*>(&rSdrObject
);
121 // Is there text to output
122 const OutlinerParaObject
*pOutlinerParaObj
=
123 pTextObj
->GetOutlinerParaObject();
124 if( !pOutlinerParaObj
)
127 OStringBuffer
sOut("<" OOO_STRING_SVTOOLS_HTML_marquee
);
129 // get attributes of the object
130 const SfxItemSet
& rItemSet
= pTextObj
->GetMergedItemSet();
133 SdrTextAniKind eAniKind
= pTextObj
->GetTextAniKind();
134 OSL_ENSURE( SdrTextAniKind::Scroll
==eAniKind
||
135 SdrTextAniKind::Alternate
==eAniKind
||
136 SdrTextAniKind::Slide
==eAniKind
,
137 "Text-Draw-Object not suitable for marquee" );
139 const char *pStr
= nullptr;
142 case SdrTextAniKind::Scroll
: pStr
= OOO_STRING_SVTOOLS_HTML_BEHAV_scroll
; break;
143 case SdrTextAniKind::Slide
: pStr
= OOO_STRING_SVTOOLS_HTML_BEHAV_slide
; break;
144 case SdrTextAniKind::Alternate
: pStr
= OOO_STRING_SVTOOLS_HTML_BEHAV_alternate
; break;
151 sOut
.append(OString::Concat(" " OOO_STRING_SVTOOLS_HTML_O_behavior
"=\"") +
157 SdrTextAniDirection eAniDir
= pTextObj
->GetTextAniDirection();
160 case SdrTextAniDirection::Left
: pStr
= OOO_STRING_SVTOOLS_HTML_AL_left
; break;
161 case SdrTextAniDirection::Right
: pStr
= OOO_STRING_SVTOOLS_HTML_AL_right
; break;
168 sOut
.append(OString::Concat(" " OOO_STRING_SVTOOLS_HTML_O_direction
169 "=\"") + pStr
+ "\"");
173 sal_Int32 nCount
= rItemSet
.Get( SDRATTR_TEXT_ANICOUNT
).GetValue();
175 nCount
= SdrTextAniKind::Slide
==eAniKind
? 1 : -1;
176 sOut
.append(" " OOO_STRING_SVTOOLS_HTML_O_loop
"=\"" +
177 OString::number(nCount
) + "\"");
180 sal_uInt16 nDelay
= rItemSet
.Get( SDRATTR_TEXT_ANIDELAY
).GetValue();
181 sOut
.append(" " OOO_STRING_SVTOOLS_HTML_O_scrolldelay
182 "=\"" + OString::number(nDelay
) + "\"");
185 sal_Int16 nAmount
= rItemSet
.Get( SDRATTR_TEXT_ANIAMOUNT
).GetValue();
192 nAmount
= SwHTMLWriter::ToPixel(nAmount
);
196 sOut
.append(" " OOO_STRING_SVTOOLS_HTML_O_scrollamount
197 "=\"" + OString::number(nAmount
) + "\"");
200 Size
aTwipSz( pTextObj
->GetLogicRect().GetSize() );
201 if( pTextObj
->IsAutoGrowWidth() )
202 aTwipSz
.setWidth( 0 );
203 // The height is at MS a minimum height, therefore we output the minimum
204 // height, if they exist. Because a minimum height MINFLY is coming with
205 // high probability from import, we aren't outputting it. You can't
206 // do anything wrong, because every font is higher.
207 if( pTextObj
->IsAutoGrowHeight() )
209 aTwipSz
.setHeight( pTextObj
->GetMinTextFrameHeight() );
210 if( MINFLY
==aTwipSz
.Height() )
211 aTwipSz
.setHeight( 0 );
214 if( (aTwipSz
.Width() || aTwipSz
.Height()) &&
215 Application::GetDefaultDevice() )
218 Application::GetDefaultDevice()->LogicToPixel( aTwipSz
,
219 MapMode(MapUnit::MapTwip
) );
220 if( !aPixelSz
.Width() && aTwipSz
.Width() )
221 aPixelSz
.setWidth( 1 );
222 if( !aPixelSz
.Height() && aTwipSz
.Height() )
223 aPixelSz
.setHeight( 1 );
225 if( aPixelSz
.Width() )
227 sOut
.append(" " OOO_STRING_SVTOOLS_HTML_O_width
228 "=\"" + OString::number(aPixelSz
.Width()) + "\"");
231 if( aPixelSz
.Height() )
233 sOut
.append(" " OOO_STRING_SVTOOLS_HTML_O_height
234 "=\"" + OString::number(aPixelSz
.Height()) + "\"");
239 drawing::FillStyle eFillStyle
=
240 rItemSet
.Get(XATTR_FILLSTYLE
).GetValue();
241 if( drawing::FillStyle_SOLID
==eFillStyle
)
243 const Color
& rFillColor
=
244 rItemSet
.Get(XATTR_FILLCOLOR
).GetColorValue();
246 sOut
.append(" " OOO_STRING_SVTOOLS_HTML_O_bgcolor
"=");
247 rWrt
.Strm().WriteOString( sOut
);
249 HTMLOutFuncs::Out_Color( rWrt
.Strm(), rFillColor
);
254 rWrt
.Strm().WriteOString( sOut
);
258 // and now ALIGN, HSPACE and VSPACE
259 HtmlFrmOpts nFrameFlags
= HTML_FRMOPTS_MARQUEE
;
260 if( rWrt
.IsHTMLMode( HTMLMODE_ABS_POS_DRAW
) )
261 nFrameFlags
|= HTML_FRMOPTS_MARQUEE_CSS1
;
262 OString aEndTags
= rWrt
.OutFrameFormatOptions(rFormat
, u
"", nFrameFlags
);
263 if( rWrt
.IsHTMLMode( HTMLMODE_ABS_POS_DRAW
) )
264 rWrt
.OutCSS1_FrameFormatOptions( rFormat
, nFrameFlags
, &rSdrObject
);
266 rWrt
.Strm().WriteChar( '>' );
268 // What follows now is the counterpart of SdrTextObject::SetText()
269 Outliner
aOutliner(nullptr, OutlinerMode::TextObject
);
270 aOutliner
.SetUpdateLayout( false );
271 aOutliner
.SetText( *pOutlinerParaObj
);
272 OUString
aText( aOutliner
.GetText( aOutliner
.GetParagraph(0),
273 aOutliner
.GetParagraphCount() ) );
274 HTMLOutFuncs::Out_String( rWrt
.Strm(), aText
);
276 HTMLOutFuncs::Out_AsciiTag( rWrt
.Strm(), Concat2View(rWrt
.GetNamespace() + OOO_STRING_SVTOOLS_HTML_marquee
), false );
278 if( !aEndTags
.isEmpty() )
279 rWrt
.Strm().WriteOString( aEndTags
);
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */