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