LibreOffice Module sw (master) 1
htmldrawwriter.cxx
Go to the documentation of this file.
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
39#include <frmfmt.hxx>
40#include <doc.hxx>
41#include <dcontact.hxx>
42
43#include "wrthtml.hxx"
44
45
46using namespace css;
47
51
55
57{
58 const SdrObject* pObj = rFormat.FindSdrObject();
59 return (pObj && ::IsMarqueeTextObj( *pObj )) ? pObj : nullptr;
60}
61
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 == aIter.GetItemState( false, &pEEItem );
76
77 sal_uInt16 nSwWhich = 0;
78 switch( nEEWhich )
79 {
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;
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;
97 }
98
99 if( nSwWhich )
100 {
101 // if the item isn't set we maybe take the default item
102 if( !bSet )
103 pEEItem = &rObjItemSet.GetPool()->GetDefaultItem(nEEWhich);
104
105 // now we clone the item with the which id of the writer
106 rItemSet.Put( pEEItem->CloneSetWhich(nSwWhich) );
107 }
108
109 nEEWhich = aIter.NextWhich();
110 }
111}
112
114 const SwDrawFrameFormat& rFormat,
115 const SdrObject& rSdrObject )
116{
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);
120
121 // Is there text to output
122 const OutlinerParaObject *pOutlinerParaObj =
123 pTextObj->GetOutlinerParaObject();
124 if( !pOutlinerParaObj )
125 return rWrt;
126
127 OStringBuffer sOut("<" OOO_STRING_SVTOOLS_HTML_marquee);
128
129 // get attributes of the object
130 const SfxItemSet& rItemSet = pTextObj->GetMergedItemSet();
131
132 // BEHAVIOUR
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" );
138
139 const char *pStr = nullptr;
140 switch( eAniKind )
141 {
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;
145 default:
146 ;
147 }
148
149 if( pStr )
150 {
151 sOut.append(OString::Concat(" " OOO_STRING_SVTOOLS_HTML_O_behavior "=\"") +
152 pStr + "\"");
153 }
154
155 // DIRECTION
156 pStr = nullptr;
157 SdrTextAniDirection eAniDir = pTextObj->GetTextAniDirection();
158 switch( eAniDir )
159 {
160 case SdrTextAniDirection::Left: pStr = OOO_STRING_SVTOOLS_HTML_AL_left; break;
161 case SdrTextAniDirection::Right: pStr = OOO_STRING_SVTOOLS_HTML_AL_right; break;
162 default:
163 ;
164 }
165
166 if( pStr )
167 {
168 sOut.append(OString::Concat(" " OOO_STRING_SVTOOLS_HTML_O_direction
169 "=\"") + pStr + "\"");
170 }
171
172 // LOOP
173 sal_Int32 nCount = rItemSet.Get( SDRATTR_TEXT_ANICOUNT ).GetValue();
174 if( 0==nCount )
175 nCount = SdrTextAniKind::Slide==eAniKind ? 1 : -1;
176 sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_loop "=\"" +
177 OString::number(nCount) + "\"");
178
179 // SCROLLDELAY
180 sal_uInt16 nDelay = rItemSet.Get( SDRATTR_TEXT_ANIDELAY ).GetValue();
182 "=\"" + OString::number(nDelay) + "\"");
183
184 // SCROLLAMOUNT
185 sal_Int16 nAmount = rItemSet.Get( SDRATTR_TEXT_ANIAMOUNT ).GetValue();
186 if( nAmount < 0 )
187 {
188 nAmount = -nAmount;
189 }
190 else if( nAmount && Application::GetDefaultDevice() )
191 {
193 ->LogicToPixel( Size(nAmount,0),
194 MapMode(MapUnit::MapTwip) ).Width();
195 }
196 if( nAmount )
197 {
199 "=\"" + OString::number(nAmount) + "\"");
200 }
201
202 Size aTwipSz( pTextObj->GetLogicRect().GetSize() );
203 if( pTextObj->IsAutoGrowWidth() )
204 aTwipSz.setWidth( 0 );
205 // The height is at MS a minimum height, therefore we output the minimum
206 // height, if they exist. Because a minimum height MINFLY is coming with
207 // high probability from import, we aren't outputting it. You can't
208 // do anything wrong, because every font is higher.
209 if( pTextObj->IsAutoGrowHeight() )
210 {
211 aTwipSz.setHeight( pTextObj->GetMinTextFrameHeight() );
212 if( MINFLY==aTwipSz.Height() )
213 aTwipSz.setHeight( 0 );
214 }
215
216 if( (aTwipSz.Width() || aTwipSz.Height()) &&
218 {
219 Size aPixelSz =
221 MapMode(MapUnit::MapTwip) );
222 if( !aPixelSz.Width() && aTwipSz.Width() )
223 aPixelSz.setWidth( 1 );
224 if( !aPixelSz.Height() && aTwipSz.Height() )
225 aPixelSz.setHeight( 1 );
226
227 if( aPixelSz.Width() )
228 {
229 sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_width
230 "=\"" + OString::number(aPixelSz.Width()) + "\"");
231 }
232
233 if( aPixelSz.Height() )
234 {
236 "=\"" + OString::number(aPixelSz.Height()) + "\"");
237 }
238 }
239
240 // BGCOLOR
241 drawing::FillStyle eFillStyle =
242 rItemSet.Get(XATTR_FILLSTYLE).GetValue();
243 if( drawing::FillStyle_SOLID==eFillStyle )
244 {
245 const Color& rFillColor =
246 rItemSet.Get(XATTR_FILLCOLOR).GetColorValue();
247
248 sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_bgcolor "=");
249 rWrt.Strm().WriteOString( sOut );
250 sOut.setLength(0);
251 HTMLOutFuncs::Out_Color( rWrt.Strm(), rFillColor );
252 }
253
254 if (!sOut.isEmpty())
255 {
256 rWrt.Strm().WriteOString( sOut );
257 sOut.setLength(0);
258 }
259
260 // and now ALIGN, HSPACE and VSPACE
261 HtmlFrmOpts nFrameFlags = HTML_FRMOPTS_MARQUEE;
263 nFrameFlags |= HTML_FRMOPTS_MARQUEE_CSS1;
264 OString aEndTags = rWrt.OutFrameFormatOptions(rFormat, OUString(), nFrameFlags);
266 rWrt.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.SetUpdateLayout( false );
273 aOutliner.SetText( *pOutlinerParaObj );
274 OUString aText( aOutliner.GetText( aOutliner.GetParagraph(0),
275 aOutliner.GetParagraphCount() ) );
276 HTMLOutFuncs::Out_String( rWrt.Strm(), aText );
277
278 HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), Concat2View(rWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_marquee), false );
279
280 if( !aEndTags.isEmpty() )
281 rWrt.Strm().WriteOString( aEndTags );
282
283 return rWrt;
284}
285
286/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OutputDevice * GetDefaultDevice()
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
void SetText(const OutlinerParaObject &)
OUString GetText(Paragraph const *pPara, sal_Int32 nParaCount=1) const
Paragraph * GetParagraph(sal_Int32 nAbsPos) const
bool SetUpdateLayout(bool bUpdate)
sal_Int32 GetParagraphCount() const
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
const SfxItemSet & GetMergedItemSet() const
virtual bool IsAutoGrowWidth() const
tools::Long GetMinTextFrameHeight() const
virtual OutlinerParaObject * GetOutlinerParaObject() const override
virtual bool IsAutoGrowHeight() const
virtual const tools::Rectangle & GetLogicRect() const override
SdrTextAniDirection GetTextAniDirection() const
SdrTextAniKind GetTextAniKind() const
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
SfxItemPool * GetPool() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
std::unique_ptr< SfxPoolItem > CloneSetWhich(sal_uInt16 nNewWhich) const
sal_uInt16 FirstWhich()
SfxItemState GetItemState(bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
sal_uInt16 NextWhich()
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
SvStream & WriteOString(std::string_view rStr)
SvStream & WriteChar(char nChar)
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
Definition: doc.cxx:169
SdrObject * FindSdrObject()
Definition: frmfmt.hxx:153
static const SdrObject * GetMarqueeTextObj(const SwDrawFrameFormat &rFormat)
OString GetNamespace() const
Determines the prefix string needed to respect the requested namespace alias.
Definition: wrthtml.cxx:1586
OString OutFrameFormatOptions(const SwFrameFormat &rFrameFormat, const OUString &rAltText, HtmlFrmOpts nFrameOpts)
void OutCSS1_FrameFormatOptions(const SwFrameFormat &rFrameFormat, HtmlFrmOpts nFrameOpts, const SdrObject *pSdrObj=nullptr, const SfxItemSet *pItemSet=nullptr)
Definition: css1atr.cxx:1840
bool IsHTMLMode(sal_uInt32 nMode) const
Definition: wrthtml.hxx:598
static void GetEEAttrsFromDrwObj(SfxItemSet &rItemSet, const SdrObject *pObj)
SvStream & Strm()
Definition: writer.cxx:193
SwDoc * m_pDoc
Definition: shellio.hxx:407
constexpr Size GetSize() const
int nCount
bool IsMarqueeTextObj(const SdrObject &rObj)
Returns true if the SrdObject is a Marquee-Object (scrolling text)
Definition: dcontact.cxx:183
constexpr TypedWhichId< SvxKerningItem > EE_CHAR_KERNING(EE_CHAR_START+12)
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO_CJK(EE_CHAR_START+17)
constexpr TypedWhichId< SvxUnderlineItem > EE_CHAR_UNDERLINE(EE_CHAR_START+5)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT(EE_CHAR_START+2)
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT(EE_CHAR_START+4)
constexpr TypedWhichId< SvxColorItem > EE_CHAR_COLOR(EE_CHAR_START+0)
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT_CTL(EE_CHAR_START+22)
constexpr TypedWhichId< SvxCrossedOutItem > EE_CHAR_STRIKEOUT(EE_CHAR_START+6)
constexpr TypedWhichId< SvxPostureItem > EE_CHAR_ITALIC(EE_CHAR_START+7)
constexpr TypedWhichId< SvxEscapementItem > EE_CHAR_ESCAPEMENT(EE_CHAR_START+10)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CTL(EE_CHAR_START+20)
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT_CJK(EE_CHAR_START+21)
constexpr TypedWhichId< SvxPostureItem > EE_CHAR_ITALIC_CJK(EE_CHAR_START+23)
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO_CTL(EE_CHAR_START+18)
constexpr TypedWhichId< SvxPostureItem > EE_CHAR_ITALIC_CTL(EE_CHAR_START+24)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CJK(EE_CHAR_START+19)
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO(EE_CHAR_START+1)
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CTL_FONTSIZE(28)
constexpr TypedWhichId< SvxCrossedOutItem > RES_CHRATR_CROSSEDOUT(5)
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_CJK_FONT(22)
constexpr TypedWhichId< SvxUnderlineItem > RES_CHRATR_UNDERLINE(14)
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_FONTSIZE(8)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_WEIGHT(15)
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CJK_FONTSIZE(23)
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_CTL_FONT(27)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_CTL_WEIGHT(31)
constexpr TypedWhichId< SvxEscapementItem > RES_CHRATR_ESCAPEMENT(6)
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_CTL_POSTURE(30)
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_POSTURE(11)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_CJK_WEIGHT(26)
constexpr TypedWhichId< SvxKerningItem > RES_CHRATR_KERNING(9)
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_FONT(7)
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_CJK_POSTURE(25)
constexpr TypedWhichId< SvxColorItem > RES_CHRATR_COLOR(3)
SwHTMLWriter & OutHTML_DrawFrameFormatAsMarquee(SwHTMLWriter &rWrt, const SwDrawFrameFormat &rFormat, const SdrObject &rSdrObject)
const HtmlFrmOpts HTML_FRMOPTS_MARQUEE_CSS1
const HtmlFrmOpts HTML_FRMOPTS_MARQUEE
#define OOO_STRING_SVTOOLS_HTML_O_height
#define OOO_STRING_SVTOOLS_HTML_AL_left
#define OOO_STRING_SVTOOLS_HTML_O_behavior
#define OOO_STRING_SVTOOLS_HTML_O_scrollamount
#define OOO_STRING_SVTOOLS_HTML_BEHAV_slide
#define OOO_STRING_SVTOOLS_HTML_BEHAV_scroll
#define OOO_STRING_SVTOOLS_HTML_marquee
#define OOO_STRING_SVTOOLS_HTML_O_scrolldelay
#define OOO_STRING_SVTOOLS_HTML_AL_right
#define OOO_STRING_SVTOOLS_HTML_O_direction
#define OOO_STRING_SVTOOLS_HTML_BEHAV_alternate
#define OOO_STRING_SVTOOLS_HTML_O_bgcolor
#define OOO_STRING_SVTOOLS_HTML_O_width
#define OOO_STRING_SVTOOLS_HTML_O_loop
SdrTextAniDirection
SdrTextAniKind
static SVT_DLLPUBLIC SvStream & Out_AsciiTag(SvStream &, std::string_view rStr, bool bOn=true)
static SVT_DLLPUBLIC SvStream & Out_String(SvStream &, const OUString &, OUString *pNonConvertableChars=nullptr)
static SVT_DLLPUBLIC SvStream & Out_Color(SvStream &, const Color &, bool bXHTML=false)
constexpr TypedWhichId< SdrTextAniDelayItem > SDRATTR_TEXT_ANIDELAY(SDRATTR_MISC_FIRST+19)
constexpr TypedWhichId< SdrTextAniCountItem > SDRATTR_TEXT_ANICOUNT(SDRATTR_MISC_FIRST+18)
constexpr TypedWhichId< SdrTextAniAmountItem > SDRATTR_TEXT_ANIAMOUNT(SDRATTR_MISC_FIRST+20)
#define MINFLY
Definition: swtypes.hxx:61
HtmlFrmOpts
Definition: wrthtml.hxx:76
#define HTMLMODE_ABS_POS_DRAW
Definition: wrthtml.hxx:124
constexpr TypedWhichId< XFillColorItem > XATTR_FILLCOLOR(XATTR_FILL_FIRST+1)
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)