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 SwHTMLWriter & rHTMLWrt = static_cast<SwHTMLWriter&>(rWrt);
118
119 OSL_ENSURE( rWrt.m_pDoc->getIDocumentDrawModelAccess().GetDrawModel(),
120 "There is a Draw-Obj with no Draw-Model?" );
121 const SdrTextObj *pTextObj = static_cast<const SdrTextObj *>(&rSdrObject);
122
123 // Is there text to output
124 const OutlinerParaObject *pOutlinerParaObj =
125 pTextObj->GetOutlinerParaObject();
126 if( !pOutlinerParaObj )
127 return rWrt;
128
129 OStringBuffer sOut;
130 sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_marquee);
131
132 // get attributes of the object
133 const SfxItemSet& rItemSet = pTextObj->GetMergedItemSet();
134
135 // BEHAVIOUR
136 SdrTextAniKind eAniKind = pTextObj->GetTextAniKind();
137 OSL_ENSURE( SdrTextAniKind::Scroll==eAniKind ||
138 SdrTextAniKind::Alternate==eAniKind ||
139 SdrTextAniKind::Slide==eAniKind,
140 "Text-Draw-Object not suitable for marquee" );
141
142 const char *pStr = nullptr;
143 switch( eAniKind )
144 {
145 case SdrTextAniKind::Scroll: pStr = OOO_STRING_SVTOOLS_HTML_BEHAV_scroll; break;
146 case SdrTextAniKind::Slide: pStr = OOO_STRING_SVTOOLS_HTML_BEHAV_slide; break;
147 case SdrTextAniKind::Alternate: pStr = OOO_STRING_SVTOOLS_HTML_BEHAV_alternate; break;
148 default:
149 ;
150 }
151
152 if( pStr )
153 {
154 sOut.append(OString::Concat(" " OOO_STRING_SVTOOLS_HTML_O_behavior "=\"") +
155 pStr + "\"");
156 }
157
158 // DIRECTION
159 pStr = nullptr;
160 SdrTextAniDirection eAniDir = pTextObj->GetTextAniDirection();
161 switch( eAniDir )
162 {
163 case SdrTextAniDirection::Left: pStr = OOO_STRING_SVTOOLS_HTML_AL_left; break;
164 case SdrTextAniDirection::Right: pStr = OOO_STRING_SVTOOLS_HTML_AL_right; break;
165 default:
166 ;
167 }
168
169 if( pStr )
170 {
171 sOut.append(OString::Concat(" " OOO_STRING_SVTOOLS_HTML_O_direction
172 "=\"") + pStr + "\"");
173 }
174
175 // LOOP
176 sal_Int32 nCount = rItemSet.Get( SDRATTR_TEXT_ANICOUNT ).GetValue();
177 if( 0==nCount )
178 nCount = SdrTextAniKind::Slide==eAniKind ? 1 : -1;
179 sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_loop "=\"" +
180 OString::number(nCount) + "\"");
181
182 // SCROLLDELAY
183 sal_uInt16 nDelay = rItemSet.Get( SDRATTR_TEXT_ANIDELAY ).GetValue();
185 "=\"" + OString::number(nDelay) + "\"");
186
187 // SCROLLAMOUNT
188 sal_Int16 nAmount = rItemSet.Get( SDRATTR_TEXT_ANIAMOUNT ).GetValue();
189 if( nAmount < 0 )
190 {
191 nAmount = -nAmount;
192 }
193 else if( nAmount && Application::GetDefaultDevice() )
194 {
196 ->LogicToPixel( Size(nAmount,0),
197 MapMode(MapUnit::MapTwip) ).Width();
198 }
199 if( nAmount )
200 {
202 "=\"" + OString::number(nAmount) + "\"");
203 }
204
205 Size aTwipSz( pTextObj->GetLogicRect().GetSize() );
206 if( pTextObj->IsAutoGrowWidth() )
207 aTwipSz.setWidth( 0 );
208 // The height is at MS a minimum height, therefore we output the minimum
209 // height, if they exist. Because a minimum height MINFLY is coming with
210 // high probability from import, we aren't outputting it. You can't
211 // do anything wrong, because every font is higher.
212 if( pTextObj->IsAutoGrowHeight() )
213 {
214 aTwipSz.setHeight( pTextObj->GetMinTextFrameHeight() );
215 if( MINFLY==aTwipSz.Height() )
216 aTwipSz.setHeight( 0 );
217 }
218
219 if( (aTwipSz.Width() || aTwipSz.Height()) &&
221 {
222 Size aPixelSz =
224 MapMode(MapUnit::MapTwip) );
225 if( !aPixelSz.Width() && aTwipSz.Width() )
226 aPixelSz.setWidth( 1 );
227 if( !aPixelSz.Height() && aTwipSz.Height() )
228 aPixelSz.setHeight( 1 );
229
230 if( aPixelSz.Width() )
231 {
232 sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_width
233 "=\"" + OString::number(aPixelSz.Width()) + "\"");
234 }
235
236 if( aPixelSz.Height() )
237 {
239 "=\"" + OString::number(aPixelSz.Height()) + "\"");
240 }
241 }
242
243 // BGCOLOR
244 drawing::FillStyle eFillStyle =
245 rItemSet.Get(XATTR_FILLSTYLE).GetValue();
246 if( drawing::FillStyle_SOLID==eFillStyle )
247 {
248 const Color& rFillColor =
249 rItemSet.Get(XATTR_FILLCOLOR).GetColorValue();
250
251 sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_bgcolor "=");
252 rWrt.Strm().WriteOString( sOut );
253 sOut.setLength(0);
254 HTMLOutFuncs::Out_Color( rWrt.Strm(), rFillColor );
255 }
256
257 if (!sOut.isEmpty())
258 {
259 rWrt.Strm().WriteOString( sOut );
260 sOut.setLength(0);
261 }
262
263 // and now ALIGN, HSPACE and VSPACE
264 HtmlFrmOpts nFrameFlags = HTML_FRMOPTS_MARQUEE;
265 if( rHTMLWrt.IsHTMLMode( HTMLMODE_ABS_POS_DRAW ) )
266 nFrameFlags |= HTML_FRMOPTS_MARQUEE_CSS1;
267 OString aEndTags = rHTMLWrt.OutFrameFormatOptions(rFormat, OUString(), nFrameFlags);
268 if( rHTMLWrt.IsHTMLMode( HTMLMODE_ABS_POS_DRAW ) )
269 rHTMLWrt.OutCSS1_FrameFormatOptions( rFormat, nFrameFlags, &rSdrObject );
270
271 rWrt.Strm().WriteChar( '>' );
272
273 // What follows now is the counterpart of SdrTextObject::SetText()
274 Outliner aOutliner(nullptr, OutlinerMode::TextObject);
275 aOutliner.SetUpdateLayout( false );
276 aOutliner.SetText( *pOutlinerParaObj );
277 OUString aText( aOutliner.GetText( aOutliner.GetParagraph(0),
278 aOutliner.GetParagraphCount() ) );
279 HTMLOutFuncs::Out_String( rWrt.Strm(), aText );
280
281 HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), Concat2View(rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_marquee), false );
282
283 if( !aEndTags.isEmpty() )
284 rWrt.Strm().WriteOString( aEndTags );
285
286 return rWrt;
287}
288
289/* 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:163
SdrObject * FindSdrObject()
Definition: frmfmt.hxx:141
static const SdrObject * GetMarqueeTextObj(const SwDrawFrameFormat &rFormat)
OString GetNamespace() const
Determines the prefix string needed to respect the requested namespace alias.
Definition: wrthtml.cxx:1570
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:1853
bool IsHTMLMode(sal_uInt32 nMode) const
Definition: wrthtml.hxx:598
static void GetEEAttrsFromDrwObj(SfxItemSet &rItemSet, const SdrObject *pObj)
SvStream & Strm()
Definition: writer.cxx:214
SwDoc * m_pDoc
Definition: shellio.hxx:399
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)
Writer & OutHTML_DrawFrameFormatAsMarquee(Writer &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)