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