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 <editeng/colritem.hxx>
32 #include <svl/whiter.hxx>
33 #include <svtools/htmlout.hxx>
34 #include <svtools/htmlkywd.hxx>
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 
46 using 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 == 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 
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(' ').append(OOO_STRING_SVTOOLS_HTML_O_behavior).
156  append("=\"").append(pStr).append("\"");
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(' ').append(OOO_STRING_SVTOOLS_HTML_O_direction).
173  append("=\"").append(pStr).append("\"");
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(' ').append(OOO_STRING_SVTOOLS_HTML_O_loop).append("=\"").
181  append(nCount).append("\"");
182 
183  // SCROLLDELAY
184  sal_uInt16 nDelay = rItemSet.Get( SDRATTR_TEXT_ANIDELAY ).GetValue();
185  sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_scrolldelay).
186  append("=\"").append(static_cast<sal_Int32>(nDelay)).append("\"");
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  {
197  ->LogicToPixel( Size(nAmount,0),
198  MapMode(MapUnit::MapTwip) ).Width();
199  }
200  if( nAmount )
201  {
202  sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_scrollamount).
203  append("=\"").append(static_cast<sal_Int32>(nAmount)).append("\"");
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()) &&
222  {
223  Size aPixelSz =
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(' ').append(OOO_STRING_SVTOOLS_HTML_O_width).
234  append("=\"").append(static_cast<sal_Int32>(aPixelSz.Width())).append("\"");
235  }
236 
237  if( aPixelSz.Height() )
238  {
239  sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_height).
240  append("=\"").append(static_cast<sal_Int32>(aPixelSz.Height())).append("\"");
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(' ').append(OOO_STRING_SVTOOLS_HTML_O_bgcolor).append("=");
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 
280 
281  if( !aEndTags.isEmpty() )
282  rWrt.Strm().WriteOString( aEndTags );
283 
284  return rWrt;
285 }
286 
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
static const SdrObject * GetMarqueeTextObj(const SwDrawFrameFormat &rFormat)
constexpr TypedWhichId< SvxCrossedOutItem > RES_CHRATR_CROSSEDOUT(5)
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO_CJK(EE_CHAR_START+17)
#define OOO_STRING_SVTOOLS_HTML_BEHAV_alternate
constexpr TypedWhichId< SvxKerningItem > EE_CHAR_KERNING(EE_CHAR_START+12)
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_CTL_FONT(27)
constexpr TypedWhichId< SvxEscapementItem > RES_CHRATR_ESCAPEMENT(6)
static SVT_DLLPUBLIC SvStream & Out_String(SvStream &, const OUString &, rtl_TextEncoding eDestEnc, OUString *pNonConvertableChars=nullptr)
long Height() const
#define OOO_STRING_SVTOOLS_HTML_O_bgcolor
#define MINFLY
Definition: swtypes.hxx:65
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_FONTSIZE(8)
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)
constexpr TypedWhichId< SvxPostureItem > EE_CHAR_ITALIC(EE_CHAR_START+7)
#define OOO_STRING_SVTOOLS_HTML_O_behavior
OUString m_aNonConvertableCharacters
Definition: wrthtml.hxx:293
sal_uInt16 FirstWhich()
const HtmlFrmOpts HTML_FRMOPTS_MARQUEE
constexpr TypedWhichId< SvxUnderlineItem > RES_CHRATR_UNDERLINE(14)
sal_Int32 GetParagraphCount() const
SvStream & WriteOString(const OString &rStr)
constexpr TypedWhichId< SdrTextAniCountItem > SDRATTR_TEXT_ANICOUNT(SDRATTR_MISC_FIRST+18)
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_CJK_POSTURE(25)
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_FONT(7)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT(EE_CHAR_START+2)
static SVT_DLLPUBLIC SvStream & Out_Color(SvStream &, const Color &, bool bXHTML=false)
sal_uInt16 NextWhich()
SdrTextAniKind
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
Definition: doc.cxx:154
static OutputDevice * GetDefaultDevice()
static SVT_DLLPUBLIC SvStream & Out_AsciiTag(SvStream &, const OString &rStr, bool bOn=true)
#define OOO_STRING_SVTOOLS_HTML_O_height
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO_CTL(EE_CHAR_START+18)
int nCount
bool IsHTMLMode(sal_uInt32 nMode) const
Definition: wrthtml.hxx:569
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT(EE_CHAR_START+4)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_WEIGHT(15)
bool IsMarqueeTextObj(const SdrObject &rObj)
Returns true if the SrdObject is a Marquee-Object (scrolling text)
Definition: dcontact.cxx:182
rtl_TextEncoding m_eDestEnc
Definition: wrthtml.hxx:334
void SetText(const OutlinerParaObject &)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define OOO_STRING_SVTOOLS_HTML_O_direction
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
#define OOO_STRING_SVTOOLS_HTML_AL_left
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT_CJK(EE_CHAR_START+21)
constexpr TypedWhichId< SvxPostureItem > EE_CHAR_ITALIC_CTL(EE_CHAR_START+24)
OUString GetText(Paragraph const *pPara, sal_Int32 nParaCount=1) const
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
Writer & OutHTML_DrawFrameFormatAsMarquee(Writer &rWrt, const SwDrawFrameFormat &rFormat, const SdrObject &rSdrObject)
std::unique_ptr< SfxPoolItem > CloneSetWhich(sal_uInt16 nNewWhich) const
SfxItemPool * GetPool() const
const HtmlFrmOpts HTML_FRMOPTS_MARQUEE_CSS1
Paragraph * GetParagraph(sal_Int32 nAbsPos) const
Point LogicToPixel(const Point &rLogicPt) const
HtmlFrmOpts
Definition: wrthtml.hxx:74
constexpr TypedWhichId< SvxColorItem > RES_CHRATR_COLOR(3)
constexpr TypedWhichId< XFillColorItem > XATTR_FILLCOLOR(XATTR_FILL_FIRST+1)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
constexpr TypedWhichId< SvxCrossedOutItem > EE_CHAR_STRIKEOUT(EE_CHAR_START+6)
#define OOO_STRING_SVTOOLS_HTML_AL_right
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_CJK_WEIGHT(26)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CTL(EE_CHAR_START+20)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
#define OOO_STRING_SVTOOLS_HTML_BEHAV_slide
constexpr TypedWhichId< SvxEscapementItem > EE_CHAR_ESCAPEMENT(EE_CHAR_START+10)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_CTL_WEIGHT(31)
const SfxItemSet & GetMergedItemSet() const
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT_CTL(EE_CHAR_START+22)
constexpr TypedWhichId< SvxColorItem > EE_CHAR_COLOR(EE_CHAR_START+0)
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_CJK_FONT(22)
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_CTL_POSTURE(30)
OString GetNamespace() const
Determines the prefix string needed to respect the requested namespace alias.
Definition: wrthtml.cxx:1481
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO(EE_CHAR_START+1)
#define OOO_STRING_SVTOOLS_HTML_BEHAV_scroll
void SetUpdateMode(bool bUpdate)
SdrTextAniDirection
SvStream & WriteChar(char nChar)
#define OOO_STRING_SVTOOLS_HTML_O_scrollamount
#define OOO_STRING_SVTOOLS_HTML_O_scrolldelay
SvStream & Strm()
Definition: writer.cxx:215
constexpr TypedWhichId< SvxPostureItem > EE_CHAR_ITALIC_CJK(EE_CHAR_START+23)
constexpr TypedWhichId< SvxUnderlineItem > EE_CHAR_UNDERLINE(EE_CHAR_START+5)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CJK(EE_CHAR_START+19)
constexpr TypedWhichId< SdrTextAniDelayItem > SDRATTR_TEXT_ANIDELAY(SDRATTR_MISC_FIRST+19)
static void GetEEAttrsFromDrwObj(SfxItemSet &rItemSet, const SdrObject *pObj)
#define OOO_STRING_SVTOOLS_HTML_marquee
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CTL_FONTSIZE(28)
void setWidth(long nWidth)
constexpr TypedWhichId< SvxFontHeightItem > RES_CHRATR_CJK_FONTSIZE(23)
constexpr TypedWhichId< SvxKerningItem > RES_CHRATR_KERNING(9)
#define HTMLMODE_ABS_POS_DRAW
Definition: wrthtml.hxx:122
SdrObject * FindSdrObject()
Definition: frmfmt.hxx:137
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_POSTURE(11)
#define OOO_STRING_SVTOOLS_HTML_O_width
#define OOO_STRING_SVTOOLS_HTML_O_loop
SwDoc * m_pDoc
Definition: shellio.hxx:409
OString OutFrameFormatOptions(const SwFrameFormat &rFrameFormat, const OUString &rAltText, HtmlFrmOpts nFrameOpts)
constexpr TypedWhichId< SdrTextAniAmountItem > SDRATTR_TEXT_ANIAMOUNT(SDRATTR_MISC_FIRST+20)
void OutCSS1_FrameFormatOptions(const SwFrameFormat &rFrameFormat, HtmlFrmOpts nFrameOpts, const SdrObject *pSdrObj=nullptr, const SfxItemSet *pItemSet=nullptr)
Definition: css1atr.cxx:1887
void setHeight(long nHeight)