19 #ifndef INCLUDED_SW_SOURCE_FILTER_HTML_WRTHTML_HXX
20 #define INCLUDED_SW_SOURCE_FILTER_HTML_WRTHTML_HXX
27 #include <com/sun/star/container/XIndexContainer.hpp>
28 #include <com/sun/star/form/XForm.hpp>
33 #include <rtl/ref.hxx>
64 namespace
utl {
class TempFile; }
68 #define HTML_PARSPACE (MM50)
114 #define HTMLMODE_BLOCK_SPACER 0x00010000
115 #define HTMLMODE_FLOAT_FRAME 0x00020000
116 #define HTMLMODE_VERT_SPACER 0x00040000
117 #define HTMLMODE_NBSP_IN_TABLES 0x00080000
118 #define HTMLMODE_LSPACE_IN_NUMBUL 0x00100000
120 #define HTMLMODE_PRINT_EXT 0x00400000
121 #define HTMLMODE_ABS_POS_FLY 0x00800000
122 #define HTMLMODE_ABS_POS_DRAW 0x01000000
123 #define HTMLMODE_FLY_MARGINS 0x02000000
124 #define HTMLMODE_BORDER_NONE 0x04000000
125 #define HTMLMODE_FONT_GENERIC 0x08000000
126 #define HTMLMODE_FRSTLINE_IN_NUMBUL 0x10000000
127 #define HTMLMODE_NO_CONTROL_CENTERING 0x20000000
129 #define HTML_DLCOLL_DD 0x4000
130 #define HTML_DLCOLL_DT 0x8000
132 #define CSS1_FMT_ISTAG (USHRT_MAX)
133 #define CSS1_FMT_CMPREF (USHRT_MAX-1)
134 #define CSS1_FMT_SPECIAL (USHRT_MAX-1)
139 #define CSS1_OUTMODE_SPAN_NO_ON 0x0000U
140 #define CSS1_OUTMODE_SPAN_TAG_ON 0x0001U
141 #define CSS1_OUTMODE_STYLE_OPT_ON 0x0002U
142 #define CSS1_OUTMODE_RULE_ON 0x0003U
143 #define CSS1_OUTMODE_SPAN_TAG1_ON 0x0004U
144 #define CSS1_OUTMODE_ANY_ON 0x0007U
147 #define CSS1_OUTMODE_SPAN_NO_OFF 0x0000U
148 #define CSS1_OUTMODE_SPAN_TAG_OFF (sal_uInt16(0x0001U << 3))
149 #define CSS1_OUTMODE_STYLE_OPT_OFF (sal_uInt16(0x0002U << 3))
150 #define CSS1_OUTMODE_RULE_OFF (sal_uInt16(0x0003U << 3))
151 #define CSS1_OUTMODE_ANY_OFF (sal_uInt16(0x0007U << 3))
153 #define CSS1_OUTMODE_ONOFF(a) (CSS1_OUTMODE_##a##_ON|CSS1_OUTMODE_##a##_OFF)
154 #define CSS1_OUTMODE_SPAN_TAG CSS1_OUTMODE_ONOFF(SPAN_TAG)
155 #define CSS1_OUTMODE_STYLE_OPT CSS1_OUTMODE_ONOFF(STYLE_OPT)
156 #define CSS1_OUTMODE_RULE CSS1_OUTMODE_ONOFF(RULE)
160 #define CSS1_OUTMODE_TEMPLATE 0x0000U
161 #define CSS1_OUTMODE_BODY (sal_uInt16(0x0001U << 6))
162 #define CSS1_OUTMODE_PARA (sal_uInt16(0x0002U << 6))
163 #define CSS1_OUTMODE_HINT (sal_uInt16(0x0003U << 6))
164 #define CSS1_OUTMODE_FRAME (sal_uInt16(0x0004U << 6))
165 #define CSS1_OUTMODE_TABLE (sal_uInt16(0x0005U << 6))
166 #define CSS1_OUTMODE_TABLEBOX (sal_uInt16(0x0006U << 6))
167 #define CSS1_OUTMODE_DROPCAP (sal_uInt16(0x0007U << 6))
168 #define CSS1_OUTMODE_SECTION (sal_uInt16(0x0008U << 6))
169 #define CSS1_OUTMODE_SOURCE (sal_uInt16(0x000fU << 6))
172 #define CSS1_OUTMODE_ENCODE (sal_uInt16(0x0001U << 10))
176 #define CSS1_OUTMODE_ANY_SCRIPT 0x0000U
178 #define CSS1_OUTMODE_WESTERN (sal_uInt16(0x0001U << 11))
180 #define CSS1_OUTMODE_CJK (sal_uInt16(0x0002U << 11))
182 #define CSS1_OUTMODE_CTL (sal_uInt16(0x0003U << 11))
184 #define CSS1_OUTMODE_NO_SCRIPT (sal_uInt16(0x0004U << 11))
185 #define CSS1_OUTMODE_SCRIPT (sal_uInt16(0x0007U << 11))
191 css::uno::Reference<css::container::XIndexContainer> xFormComps;
195 HTMLControl( const css::uno::Reference<css::container::XIndexContainer>& rForm, sal_uInt32 nIdx );
199 bool operator<( const HTMLControl& rCtrl ) const
201 return nNdIdx < rCtrl.nNdIdx;
205 class HTMLControls : public o3tl::sorted_vector<std::unique_ptr<HTMLControl>, o3tl::less_uniqueptr_to<HTMLControl> > {
208 struct SwHTMLFormatInfo
210 const SwFormat *pFormat;
215 std::unique_ptr<SfxItemSet> pItemSet;
217 sal_Int32 nLeftMargin;
218 sal_Int32 nRightMargin;
219 short nFirstLineIndent;
221 sal_uInt16 nTopMargin;
222 sal_uInt16 nBottomMargin;
224 bool bScriptDependent;
227 explicit SwHTMLFormatInfo( const SwFormat *pF ) :
234 bScriptDependent(false)
238 SwHTMLFormatInfo( const SwFormat *pFormat, SwDoc *pDoc, SwDoc *pTemplate,
239 bool bOutStyles, LanguageType eDfltLang=LANGUAGE_DONTKNOW,
240 sal_uInt16 nScript=CSS1_OUTMODE_ANY_SCRIPT );
243 friend bool operator<( const SwHTMLFormatInfo& rInfo1,
244 const SwHTMLFormatInfo& rInfo2 )
246 return reinterpret_cast<sal_IntPtr>(rInfo1.pFormat) < reinterpret_cast<sal_IntPtr>(rInfo2.pFormat);
251 typedef std::set<std::unique_ptr<SwHTMLFormatInfo>,
252 comphelper::UniquePtrValueLess<SwHTMLFormatInfo>> SwHTMLFormatInfos;
254 class IDocumentStylePoolAccess;
256 class SW_DLLPUBLIC SwHTMLWriter : public Writer
258 std::unique_ptr<SwHTMLPosFlyFrames> m_pHTMLPosFlyFrames;
259 std::unique_ptr<SwHTMLNumRuleInfo> m_pNumRuleInfo;
260 std::unique_ptr<SwHTMLNumRuleInfo> m_pNextNumRuleInfo;
261 sal_uInt32 m_nHTMLMode;
263 FieldUnit m_eCSS1Unit;
265 sal_uInt16 OutHeaderAttrs();
266 const SwPageDesc *MakeHeader( sal_uInt16& rHeaderAtrs );
269 void AddLinkTarget( const OUString& rURL );
270 void CollectLinkTargets();
272 void SetupFilterOptions(const OUString& rFilterOptions);
275 ErrCode WriteStream() override;
276 void SetupFilterOptions(SfxMedium& rMedium) override;
279 std::vector<OUString> m_aImgMapNames;
280 std::set<OUString> m_aImplicitMarks;
281 std::set<OUString> m_aNumRuleNames;
282 std::set<OUString> m_aScriptParaStyles;
283 std::set<OUString> m_aScriptTextStyles;
284 std::vector<OUString> m_aOutlineMarks;
285 std::vector<sal_uInt32> m_aOutlineMarkPoss;
286 HTMLControls m_aHTMLControls;
287 SwHTMLFormatInfos m_CharFormatInfos;
288 SwHTMLFormatInfos m_TextCollInfos;
289 std::vector<SwFormatINetFormat*> m_aINetFormats;
290 std::unique_ptr<std::vector<SwTextFootnote*>> m_pFootEndNotes;
292 OUString m_aCSS1Selector;
293 OUString m_aNonConvertableCharacters;
294 OUString m_aBulletGrfs[MAXLEVEL];
296 css::uno::Reference<css::container::XIndexContainer> mxFormComps;
298 rtl::Reference<SwDoc> m_xTemplate;
299 o3tl::optional<Color> m_xDfltColor;
300 SwNodeIndex *m_pStartNdIdx;
301 const SwPageDesc *m_pCurrPageDesc;
302 const SwFormatFootnote *m_pFormatFootnote;
304 sal_uInt32 m_aFontHeights[7];
307 sal_uInt32 m_nLastLFPos;
309 HtmlTokenId m_nLastParaToken;
310 sal_Int32 m_nBkmkTabPos;
311 sal_uInt16 m_nImgMapCnt;
312 sal_uInt16 m_nFormCntrlCnt;
313 sal_uInt16 m_nEndNote;
314 sal_uInt16 m_nFootNote;
315 sal_Int32 m_nLeftMargin;
316 sal_Int32 m_nDfltLeftMargin;
317 sal_Int32 m_nDfltRightMargin;
318 short m_nFirstLineIndent;
319 short m_nDfltFirstLineIndent;
320 sal_uInt16 m_nDfltTopMargin;
321 sal_uInt16 m_nDfltBottomMargin;
322 sal_uInt16 m_nIndentLvl;
323 sal_Int32 m_nWhishLineLen;
324 sal_uInt16 m_nDefListLvl;
325 sal_Int32 m_nDefListMargin;
326 sal_uInt16 m_nHeaderFooterSpace;
327 sal_uInt16 m_nTextAttrsToIgnore;
328 sal_uInt16 m_nExportMode;
329 sal_uInt16 m_nCSS1OutMode;
330 sal_uInt16 m_nCSS1Script;
332 SvxFrameDirection m_nDirection;
334 rtl_TextEncoding m_eDestEnc;
335 LanguageType m_eLang;
339 bool m_bCfgOutStyles : 1;
340 bool m_bCfgPreferStyles : 1;
341 bool m_bCfgFormFeed : 1;
342 bool m_bCfgStarBasic : 1;
343 bool m_bCfgCpyLinkedGrfs : 1;
347 bool m_bFirstLine : 1;
357 bool m_bTextAttr : 1;
361 bool m_bOutTable : 1;
362 bool m_bOutHeader : 1;
363 bool m_bOutFooter : 1;
364 bool m_bOutFlyFrame : 1;
368 bool m_bFirstCSS1Rule : 1;
369 bool m_bFirstCSS1Property : 1;
372 bool m_bCSS1IgnoreFirstPageDesc : 1;
377 bool m_bClearLeft : 1;
378 bool m_bClearRight : 1;
379 bool m_bLFPossible : 1;
383 bool m_bPreserveForm : 1;
385 bool m_bCfgNetscape4 : 1;
387 bool mbSkipImages : 1;
389 bool mbSkipHeaderFooter : 1;
390 bool mbEmbedImages : 1;
392 std::unique_ptr<utl::TempFile> mpTempBaseURL;
394 bool mbXHTML = false;
398 bool mbReqIF = false;
400 #define sCSS2_P_CLASS_leaders "leaders"
401 bool m_bCfgPrintLayout : 1;
402 bool m_bParaDotLeaders : 1;
406 std::map<sal_uInt16, int> maStartedAttributes;
410 explicit SwHTMLWriter( const OUString& rBaseURL, const OUString& rFilterOptions = "" );
411 virtual ~SwHTMLWriter() override;
413 void Out_SwDoc( SwPaM* );
416 void OutAnchor( const OUString& rName );
418 void OutPointFieldmarks( const SwPosition& rPos );
419 void OutImplicitMark( const OUString& rMark, const sal_Char *pMarkType );
421 OUString convertHyperlinkHRefValue(const OUString& rURL);
423 void OutHyperlinkHRefValue( const OUString& rURL );
426 bool OutFlyFrame( sal_uLong nNdIdx, sal_Int32 nContentIdx,
427 HtmlPosition nPos, HTMLOutContext *pContext = nullptr );
428 void OutFrameFormat( AllHtmlFlags nType, const SwFrameFormat& rFormat,
429 const SdrObject *pSdrObj );
431 void OutForm( bool bTagOn=true, const SwStartNode *pStNd=nullptr );
432 void OutHiddenForms();
433 void OutHiddenForm( const css::uno::Reference<css::form::XForm>& rForm );
435 void OutForm( bool bOn, const css::uno::Reference<css::container::XIndexContainer>& rFormComps );
436 void OutHiddenControls( const css::uno::Reference<css::container::XIndexContainer>& rFormComps,
437 const css::uno::Reference<css::beans::XPropertySet>& rPropSet );
438 bool HasControls() const;
440 void OutFootEndNoteInfo();
441 void OutFootEndNotes();
442 OUString GetFootEndNoteSym( const SwFormatFootnote& rFormatFootnote );
443 void OutFootEndNoteSym( const SwFormatFootnote& rFormatFootnote, const OUString& rNum,
444 sal_uInt16 nScript );
448 void OutAndSetDefList( sal_uInt16 nNewLvl );
450 void OutStyleSheet( const SwPageDesc& rPageDesc );
452 inline void OutCSS1_PropertyAscii( const sal_Char *pProp,
453 const sal_Char *pVal );
454 inline void OutCSS1_PropertyAscii( const sal_Char *pProp,
455 const OString& rVal );
456 inline void OutCSS1_Property( const sal_Char *pProp, const OUString& rVal );
457 void OutCSS1_Property( const sal_Char *pProp, const sal_Char *pVal,
458 const OUString *pSVal );
459 void OutCSS1_UnitProperty( const sal_Char *pProp, long nVal );
460 void OutCSS1_PixelProperty( const sal_Char *pProp, long nVal, bool bVert );
461 void OutCSS1_SfxItemSet( const SfxItemSet& rItemSet, bool bDeep=true );
464 void OutBasicBodyEvents();
467 void OutBackground( const SvxBrushItem *pBrushItem, bool bGraphic );
468 void OutBackground( const SfxItemSet& rItemSet, bool bGraphic );
470 void OutLanguage( LanguageType eLang );
471 SvxFrameDirection GetHTMLDirection( SvxFrameDirection nDir ) const;
472 SvxFrameDirection GetHTMLDirection( const SfxItemSet& rItemSet ) const;
473 void OutDirection( SvxFrameDirection nDir );
474 static OString convertDirection(SvxFrameDirection nDirection);
479 OString OutFrameFormatOptions( const SwFrameFormat& rFrameFormat, const OUString& rAltText,
480 HtmlFrmOpts nFrameOpts );
482 void writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameFormat& rFrameFormat, const OUString& rAltText, HtmlFrmOpts nFrameOpts);
484 void OutCSS1_TableFrameFormatOptions( const SwFrameFormat& rFrameFormat );
485 void OutCSS1_TableCellBorderHack(const SwFrameFormat& rFrameFormat);
486 void OutCSS1_SectionFormatOptions( const SwFrameFormat& rFrameFormat, const SwFormatCol *pCol );
487 void OutCSS1_FrameFormatOptions( const SwFrameFormat& rFrameFormat, HtmlFrmOpts nFrameOpts,
488 const SdrObject *pSdrObj=nullptr,
489 const SfxItemSet *pItemSet=nullptr );
490 void OutCSS1_FrameFormatBackground( const SwFrameFormat& rFrameFormat );
492 void ChangeParaToken( HtmlTokenId nNew );
494 void IncIndentLevel()
498 void DecIndentLevel()
500 if ( m_nIndentLvl ) m_nIndentLvl--;
502 OString GetIndentString(sal_uInt16 nIncLvl = 0);
504 sal_Int32 GetLineLen()
506 return static_cast<sal_Int32>(Strm().Tell()-m_nLastLFPos);
508 void OutNewLine( bool bCheck=false );
511 SwPaM* GetEndPaM() { return m_pOrigPam; }
512 void SetEndPaM( SwPaM* pPam ) { m_pOrigPam = pPam; }
514 static sal_uInt32 ToPixel( sal_uInt32 nVal, const bool bVert );
516 sal_uInt16 GuessFrameType( const SwFrameFormat& rFrameFormat,
517 const SdrObject*& rpStrObj );
518 static sal_uInt16 GuessOLENodeFrameType( const SwNode& rNd );
520 void CollectFlyFrames();
522 sal_uInt16 GetHTMLFontSize( sal_uInt32 nFontHeight ) const;
525 SwHTMLNumRuleInfo& GetNumInfo() { return *m_pNumRuleInfo; }
529 SwHTMLNumRuleInfo *GetNextNumInfo() { return m_pNextNumRuleInfo.get(); }
530 std::unique_ptr<SwHTMLNumRuleInfo> ReleaseNextNumInfo();
533 void SetNextNumInfo( std::unique_ptr<SwHTMLNumRuleInfo> pNxt );
536 void FillNextNumInfo();
539 void ClearNextNumInfo();
541 static const SdrObject* GetHTMLControl( const SwDrawFrameFormat& rFormat );
542 static const SdrObject* GetMarqueeTextObj( const SwDrawFrameFormat& rFormat );
543 static sal_uInt16 GetCSS1Selector( const SwFormat *pFormat, OString& rToken,
544 OUString& rClass, sal_uInt16& rRefPoolId,
545 OUString *pPseudo=nullptr );
547 static const SwFormat *GetTemplateFormat( sal_uInt16 nPoolId, IDocumentStylePoolAccess* pTemplate );
548 static const SwFormat *GetParentFormat( const SwFormat& rFormat, sal_uInt16 nDeep );
550 static void SubtractItemSet( SfxItemSet& rItemSet,
551 const SfxItemSet& rRefItemSet,
553 bool bClearSame = true,
554 const SfxItemSet *pRefScriptItemSet=nullptr );
555 static bool HasScriptDependentItems( const SfxItemSet& rItemSet,
556 bool bCheckDropCap );
558 static void GetEEAttrsFromDrwObj( SfxItemSet& rItemSet,
559 const SdrObject *pObj );
561 static sal_uInt16 GetDefListLvl( const OUString& rNm, sal_uInt16 nPoolId );
563 sal_uInt32 GetHTMLMode() const
567 bool IsHTMLMode( sal_uInt32 nMode ) const
569 return (m_nHTMLMode & nMode) != 0;
572 inline bool IsCSS1Source( sal_uInt16 n ) const;
573 inline bool IsCSS1Script( sal_uInt16 n ) const;
575 static const sal_Char *GetNumFormat( sal_uInt16 nFormat );
576 static void PrepareFontList( const SvxFontItem& rFontItem, OUString& rNames,
577 sal_Unicode cQuote, bool bGeneric );
578 static sal_uInt16 GetCSS1ScriptForScriptType( sal_uInt16 nScriptType );
579 static sal_uInt16 GetLangWhichIdFromScript( sal_uInt16 nScript );
581 FieldUnit GetCSS1Unit() const { return m_eCSS1Unit; }
583 sal_Int32 indexOfDotLeaders( sal_uInt16 nPoolId, const OUString& rText );
586 OString GetNamespace() const;
589 inline bool SwHTMLWriter::IsCSS1Source( sal_uInt16 n ) const
591 return n == (m_nCSS1OutMode & CSS1_OUTMODE_SOURCE);
594 inline bool SwHTMLWriter::IsCSS1Script( sal_uInt16 n ) const
596 sal_uInt16 nScript = (m_nCSS1OutMode & CSS1_OUTMODE_SCRIPT);
597 return CSS1_OUTMODE_ANY_SCRIPT == nScript || n == nScript;
600 inline void SwHTMLWriter::OutCSS1_PropertyAscii( const sal_Char *pProp,
601 const sal_Char *pVal )
603 OutCSS1_Property( pProp, pVal, nullptr );
606 inline void SwHTMLWriter::OutCSS1_PropertyAscii( const sal_Char *pProp,
607 const OString& rVal )
609 OutCSS1_Property( pProp, rVal.getStr(), nullptr );
612 inline void SwHTMLWriter::OutCSS1_Property( const sal_Char *pProp,
613 const OUString& rVal )
615 OutCSS1_Property( pProp, nullptr, &rVal );
628 std::shared_ptr<SwUnoCursor> pOldPam;
630 std::unique_ptr<SwHTMLNumRuleInfo> pOldNumRuleInfo;
631 std::unique_ptr<SwHTMLNumRuleInfo> pOldNextNumRuleInfo;
632 sal_uInt16 const nOldDefListLvl;
633 SvxFrameDirection const nOldDirection;
634 bool bOldWriteAll : 1;
635 bool const bOldOutHeader : 1;
636 bool const bOldOutFooter : 1;
637 bool const bOldOutFlyFrame : 1;
639 HTMLSaveData( SwHTMLWriter&, sal_uLong nStt, sal_uLong nEnd,
641 const SwFrameFormat *pFrameFormat=nullptr );
646 Writer& OutHTML_FrameFormatOLENode( Writer& rWrt, const SwFrameFormat& rFormat,
648 Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFormat,
651 Writer& OutHTML_SwTextNode( Writer&, const SwContentNode& );
652 Writer& OutHTML_SwTableNode( Writer& , SwTableNode &, const SwFrameFormat *,
653 const OUString* pCaption=nullptr, bool bTopCaption=false );
655 Writer& OutHTML_DrawFrameFormatAsControl( Writer& rWrt, const SwDrawFrameFormat& rFormat,
656 const SdrUnoObj& rSdrObj, bool bInCntnr );
657 Writer& OutHTML_DrawFrameFormatAsMarquee( Writer& rWrt, const SwDrawFrameFormat& rFormat,
658 const SdrObject& rSdrObj );
660 Writer& OutHTML_HeaderFooter( Writer& rWrt, const SwFrameFormat& rFrameFormat,
663 Writer& OutHTML_Image( Writer&, const SwFrameFormat& rFormat,
664 const OUString& rGraphicURL,
665 Graphic const & rGraphic, const OUString& rAlternateText,
666 const Size& rRealSize, HtmlFrmOpts nFrameOpts,
667 const sal_Char *pMarkType,
668 const ImageMap *pGenImgMap,
669 const OUString& rMimeType = OUString() );
671 Writer& OutHTML_BulletImage( Writer& rWrt, const sal_Char *pTag,
672 const SvxBrushItem* pBrush,
673 const OUString& rGraphicURL);
675 Writer& OutHTML_SwFormatField( Writer& rWrt, const SfxPoolItem& rHt );
676 Writer& OutHTML_SwFormatFootnote( Writer& rWrt, const SfxPoolItem& rHt );
677 Writer& OutHTML_INetFormat( Writer&, const SwFormatINetFormat& rINetFormat, bool bOn );
679 Writer& OutCSS1_BodyTagStyleOpt( Writer& rWrt, const SfxItemSet& rItemSet );
680 Writer& OutCSS1_ParaTagStyleOpt( Writer& rWrt, const SfxItemSet& rItemSet );
682 Writer& OutCSS1_HintSpanTag( Writer& rWrt, const SfxPoolItem& rHt );
683 Writer& OutCSS1_HintStyleOpt( Writer& rWrt, const SfxPoolItem& rHt );
685 Writer& OutCSS1_TableBGStyleOpt( Writer& rWrt, const SfxPoolItem& rHt );
686 Writer& OutCSS1_NumBulListStyleOpt( Writer& rWrt, const SwNumRule& rNumRule,
689 Writer& OutHTML_NumBulListStart( SwHTMLWriter& rWrt,
690 const SwHTMLNumRuleInfo& rInfo );
691 Writer& OutHTML_NumBulListEnd( SwHTMLWriter& rWrt,
692 const SwHTMLNumRuleInfo& rNextInfo );
694 Writer& OutCSS1_SvxBox( Writer& rWrt, const SfxPoolItem& rHt );
696 OString GetCSS1_Color(const Color& rColor);
Starts a section of nodes in the document model.
FnAttrOut SwAttrFnTab[POOLATTR_END-POOLATTR_BEGIN]
The graphic frame is a replacement image of an OLE object.
SwAttrFnTab aHTMLAttrFnTab
Marks a node in the document model.