/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #ifndef INCLUDED_SW_SOURCE_FILTER_HTML_SWHTML_HXX #define INCLUDED_SW_SOURCE_FILTER_HTML_SWHTML_HXX #include #include #include #include #include #include #include #include "calbck.hxx" #include "htmlvsh.hxx" #include #include #include class SfxMedium; class SfxViewFrame; class SdrObject; class SvxMacroTableDtor; class SwDoc; class SwPaM; class SwViewShell; class SwStartNode; class SwFormatColl; class SwField; class SwHTMLForm_Impl; class SwApplet_Impl; struct SwHTMLFootEndNote_Impl; class HTMLTableCnts; struct SwPendingStack; class SvxCSS1PropertyInfo; struct ImplSVEvent; #define HTML_PARSPACE (MM50) #define HTML_CJK_PARSPACE (MM50/2) #define HTML_CTL_PARSPACE (MM50/2) #define HTML_DFLT_IMG_WIDTH (MM50*4) #define HTML_DFLT_IMG_HEIGHT (MM50*2) // ein par Sachen, die man oefter mal braucht extern HTMLOptionEnum aHTMLPAlignTable[]; extern HTMLOptionEnum aHTMLImgHAlignTable[]; extern HTMLOptionEnum aHTMLImgVAlignTable[]; // der Attribut Stack: class _HTMLAttr; typedef std::deque<_HTMLAttr *> _HTMLAttrs; class _HTMLAttr { friend class SwHTMLParser; friend class _CellSaveStruct; SwNodeIndex nSttPara, nEndPara; sal_Int32 nSttContent, nEndContent; bool bInsAtStart : 1; bool bLikePara : 1; // Attribut ueber dem gesamten Absatz setzen bool bValid : 1; // ist das Attribut gueltig? SfxPoolItem* pItem; sal_uInt16 nCount; // Anzahl noch zu schliessender Attrs mit einem Wert _HTMLAttr *pNext; // noch zu schliessene Attrs mit unterschiedl. Werten _HTMLAttr *pPrev; // bereits geschlossene aber noch nicht gesetze Attrs _HTMLAttr **ppHead; // der Listenkopf _HTMLAttr( const SwPosition& rPos, const SfxPoolItem& rItem, _HTMLAttr **pHd=nullptr ); _HTMLAttr( const _HTMLAttr &rAttr, const SwNodeIndex &rEndPara, sal_Int32 nEndCnt, _HTMLAttr **pHd ); public: ~_HTMLAttr(); _HTMLAttr *Clone( const SwNodeIndex& rEndPara, sal_Int32 nEndCnt ) const; void Reset( const SwNodeIndex& rSttPara, sal_Int32 nSttCnt, _HTMLAttr **pHd ); inline void SetStart( const SwPosition& rPos ); sal_uInt32 GetSttParaIdx() const { return nSttPara.GetIndex(); } sal_uInt32 GetEndParaIdx() const { return nEndPara.GetIndex(); } const SwNodeIndex& GetSttPara() const { return nSttPara; } const SwNodeIndex& GetEndPara() const { return nEndPara; } sal_Int32 GetSttCnt() const { return nSttContent; } sal_Int32 GetEndCnt() const { return nEndContent; } bool IsLikePara() const { return bLikePara; } void SetLikePara( bool bPara=true ) { bLikePara = bPara; } SfxPoolItem& GetItem() { return *pItem; } const SfxPoolItem& GetItem() const { return *pItem; } _HTMLAttr *GetNext() const { return pNext; } void InsertNext( _HTMLAttr *pNxt ) { pNext = pNxt; } _HTMLAttr *GetPrev() const { return pPrev; } void InsertPrev( _HTMLAttr *pPrv ); void ClearPrev() { pPrev = nullptr; } void SetHead( _HTMLAttr **ppHd ) { ppHead = ppHd; } // Beim Setzen von Attributen aus Vorlagen kann es passieren, // dass Attribute doch nicht mehr gesetzt werden sollen. Die zu loeschen // waere sehr aufwendig, da man nicht so genau weiss, wo sie eingekettet // sind. Sie werden deshalb einfach invalidiert und erst beim naechsten // _SetAttr() geloescht. void Invalidate() { bValid = false; } }; // Tabelle der Attribute: Hier ist die Reihenfolge wichtig: Die Attribute // vorne in der Tabelle werden in EndAllAttrs auch zuerst gesetzt. struct _HTMLAttrTable { _HTMLAttr *pKeep, // Frame-Attribute *pBox, *pBrush, *pBreak, *pPageDesc, *pLRSpace, // Absatz-Attribute *pULSpace, *pLineSpacing, *pAdjust, *pDropCap, *pSplit, *pWidows, *pOrphans, *pDirection, *pCharFormats, // Text-Attribute *pINetFormat, *pBold, // Zeichen-Attribute *pBoldCJK, *pBoldCTL, *pItalic, *pItalicCJK, *pItalicCTL, *pStrike, *pUnderline, *pBlink, *pFont, *pFontCJK, *pFontCTL, *pFontHeight, *pFontHeightCJK, *pFontHeightCTL, *pFontColor, *pEscapement, *pCaseMap, *pKerning, // (nur fuer SPACER) *pCharBrush, // Zeichen-Hintergrund *pLanguage, *pLanguageCJK, *pLanguageCTL, *pCharBox ; }; class _HTMLAttrContext_SaveDoc; enum SwHTMLAppendMode { AM_NORMAL, // keine Absatz-Abstand-Behandlung AM_NOSPACE, // Abstand hart auf 0cm setzen AM_SPACE, // Abstand hart auf 0.5cm setzen AM_SOFTNOSPACE, // Abstand nicht setzen aber 0cm merken AM_NONE // gar kein Append }; class _HTMLAttrContext { _HTMLAttrs aAttrs; // die in dem Kontext gestarteten Attribute OUString aClass; // die Klasse des Kontexts _HTMLAttrContext_SaveDoc *pSaveDocContext; SfxItemSet *pFrmItemSet; sal_uInt16 nToken; // das Token, zu dem der Kontext gehoehrt sal_uInt16 nTextFormatColl; // eine in dem Kontext begonnene Vorlage oder 0 sal_uInt16 nLeftMargin; // ein veraenderter linker Rand sal_uInt16 nRightMargin; // ein veraenderter rechter Rand sal_uInt16 nFirstLineIndent; // ein veraenderter Erstzeilen-Einzug sal_uInt16 nUpperSpace; sal_uInt16 nLowerSpace; SwHTMLAppendMode eAppend; bool bLRSpaceChanged : 1;// linker/rechtr Rand, Einzug veraendert? bool bULSpaceChanged : 1;// oberer/unterer Rand veraendert? bool bDfltTextFormatColl : 1;// nTextFormatColl ist nur ein default bool bSpansSection : 1; // Der Kontext spannt eine SwSection auf bool bPopStack : 1; // Oberhalb liegende Stack-Elemente entf. bool bFinishPREListingXMP : 1; bool bRestartPRE : 1; bool bRestartXMP : 1; bool bRestartListing : 1; public: void ClearSaveDocContext(); _HTMLAttrContext( sal_uInt16 nTokn, sal_uInt16 nPoolId, const OUString& rClass, bool bDfltColl=false ) : aClass( rClass ), pSaveDocContext( nullptr ), pFrmItemSet( nullptr ), nToken( nTokn ), nTextFormatColl( nPoolId ), nLeftMargin( 0 ), nRightMargin( 0 ), nFirstLineIndent( 0 ), nUpperSpace( 0 ), nLowerSpace( 0 ), eAppend( AM_NONE ), bLRSpaceChanged( false ), bULSpaceChanged( false ), bDfltTextFormatColl( bDfltColl ), bSpansSection( false ), bPopStack( false ), bFinishPREListingXMP( false ), bRestartPRE( false ), bRestartXMP( false ), bRestartListing( false ) {} explicit _HTMLAttrContext( sal_uInt16 nTokn ) : pSaveDocContext( nullptr ), pFrmItemSet( nullptr ), nToken( nTokn ), nTextFormatColl( 0 ), nLeftMargin( 0 ), nRightMargin( 0 ), nFirstLineIndent( 0 ), nUpperSpace( 0 ), nLowerSpace( 0 ), eAppend( AM_NONE ), bLRSpaceChanged( false ), bULSpaceChanged( false ), bDfltTextFormatColl( false ), bSpansSection( false ), bPopStack( false ), bFinishPREListingXMP( false ), bRestartPRE( false ), bRestartXMP( false ), bRestartListing( false ) {} ~_HTMLAttrContext() { ClearSaveDocContext(); delete pFrmItemSet; } sal_uInt16 GetToken() const { return nToken; } sal_uInt16 GetTextFormatColl() const { return bDfltTextFormatColl ? 0 : nTextFormatColl; } sal_uInt16 GetDfltTextFormatColl() const { return bDfltTextFormatColl ? nTextFormatColl : 0; } const OUString& GetClass() const { return aClass; } inline void SetMargins( sal_uInt16 nLeft, sal_uInt16 nRight, short nIndent ); inline bool IsLRSpaceChanged() const { return bLRSpaceChanged; } inline void GetMargins( sal_uInt16& nLeft, sal_uInt16& nRight, short &nIndent ) const; inline void SetULSpace( sal_uInt16 nUpper, sal_uInt16 nLower ); inline bool IsULSpaceChanged() const { return bULSpaceChanged; } inline void GetULSpace( sal_uInt16& rUpper, sal_uInt16& rLower ) const; bool HasAttrs() const { return !aAttrs.empty(); } const _HTMLAttrs& GetAttrs() const { return aAttrs; } _HTMLAttrs& GetAttrs() { return aAttrs; } void SetSpansSection( bool bSet ) { bSpansSection = bSet; } bool GetSpansSection() const { return bSpansSection; } void SetPopStack( bool bSet ) { bPopStack = bSet; } bool GetPopStack() const { return bPopStack; } bool HasSaveDocContext() const { return pSaveDocContext!=nullptr; } _HTMLAttrContext_SaveDoc *GetSaveDocContext( bool bCreate=false ); const SfxItemSet *GetFrmItemSet() const { return pFrmItemSet; } SfxItemSet *GetFrmItemSet( SwDoc *pCreateDoc ); void SetFinishPREListingXMP( bool bSet ) { bFinishPREListingXMP = bSet; } bool IsFinishPREListingXMP() const { return bFinishPREListingXMP; } void SetRestartPRE( bool bSet ) { bRestartPRE = bSet; } bool IsRestartPRE() const { return bRestartPRE; } void SetRestartXMP( bool bSet ) { bRestartXMP = bSet; } bool IsRestartXMP() const { return bRestartXMP; } void SetRestartListing( bool bSet ) { bRestartListing = bSet; } bool IsRestartListing() const { return bRestartListing; } void SetAppendMode( SwHTMLAppendMode eMode=AM_NORMAL ) { eAppend = eMode; } SwHTMLAppendMode GetAppendMode() const { return eAppend; } }; typedef std::vector<_HTMLAttrContext *> _HTMLAttrContexts; class HTMLTable; class SwCSS1Parser; class SwHTMLNumRuleInfo; typedef ::std::vector> ImageMaps; #define HTML_CNTXT_PROTECT_STACK 0x0001 #define HTML_CNTXT_STRIP_PARA 0x0002 #define HTML_CNTXT_KEEP_NUMRULE 0x0004 #define HTML_CNTXT_HEADER_DIST 0x0008 #define HTML_CNTXT_FOOTER_DIST 0x0010 #define HTML_CNTXT_KEEP_ATTRS 0x0020 #define CONTEXT_FLAGS_ABSPOS \ (HTML_CNTXT_PROTECT_STACK | \ HTML_CNTXT_STRIP_PARA) #define HTML_FF_BOX 0x0001 #define HTML_FF_BACKGROUND 0x0002 #define HTML_FF_PADDING 0x0004 #define HTML_FF_DIRECTION 0x0008 class SwHTMLParser : public SfxHTMLParser, public SwClient { friend class _SectionSaveStruct; friend class _CellSaveStruct; friend class _CaptionSaveStruct; OUString m_aPathToFile; OUString m_sBaseURL; OUString m_aBasicLib; OUString m_aBasicModule; OUString m_aScriptSource; // Inhalt des aktuellen Script-Blocks OUString m_aScriptType; // Type des gelesenen Scripts (StarBasic/VB/JAVA) OUString m_aScriptURL; // URL eines Scripts OUString m_aStyleSource; // Inhalt des aktuellen Style-Sheets OUString m_aContents; // Text des akteullen Marquee, Feldes etc. OUString m_sTitle; OUString m_aUnknownToken; // ein gestartetes unbekanntes Token OUString m_aBulletGrfs[MAXLEVEL]; OUString m_sJmpMark; std::vector m_aBaseFontStack; // Stack fuer // Bit 0-2: Fontgroesse (1-7) std::vector m_aFontStack; // Stack fuer , , // Bit 0-2: Fontgroesse (1-7) // Bit 15: Fontfarbe wurde gesetzt _HTMLAttrs m_aSetAttrTab;// "geschlossene", noch nicht gesetzte Attr. _HTMLAttrs m_aParaAttrs; // vorlauefige Absatz-Attribute _HTMLAttrTable m_aAttrTab; // "offene" Attribute _HTMLAttrContexts m_aContexts;// der aktuelle Attribut/Token-Kontext std::vector m_aMoveFlyFrms;// Fly-Frames, the anchor is moved std::deque m_aMoveFlyCnts;// and the Content-Positions SwApplet_Impl *m_pAppletImpl; // das aktuelle Applet SwCSS1Parser *m_pCSS1Parser; // der Style-Sheet-Parser SwHTMLNumRuleInfo *m_pNumRuleInfo; SwPendingStack *m_pPendStack; SwDoc *m_pDoc; SwPaM *m_pPam; // SwPosition duerfte doch reichen, oder ?? SwViewShell *m_pActionViewShell; // SwViewShell, an der das StartAction // gerufen wurde. SwNodeIndex *m_pSttNdIdx; HTMLTable *m_pTable; // die aktuelle "auesserste" Tabelle SwHTMLForm_Impl *m_pFormImpl;// die aktuelle Form SdrObject *m_pMarquee; // aktuelles Marquee SwField *m_pField; // aktuelles Feld ImageMap *m_pImageMap; // aktuelle Image-Map ImageMaps *m_pImageMaps; ///< all Image-Maps that have been read SwHTMLFootEndNote_Impl *m_pFootEndNoteImpl; Size m_aHTMLPageSize; // die Seitengroesse der HTML-Vorlage sal_uInt32 m_aFontHeights[7]; // die Font-Hoehen 1-7 sal_uInt32 m_nScriptStartLineNr; // Zeilennummer eines Script-Blocks ImplSVEvent * m_nEventId; sal_uInt16 m_nBaseFontStMin; sal_uInt16 m_nFontStMin; sal_uInt16 m_nDefListDeep; sal_uInt16 m_nFontStHeadStart; // Elemente im Font-Stack bei sal_uInt16 m_nSBModuleCnt; // Zaehler fuer Basic-Module sal_uInt16 m_nMissingImgMaps; // Wie viele Image-Maps fehlen noch? size_t m_nParaCnt; size_t m_nContextStMin; // Untergrenze fuer PopContext size_t m_nContextStAttrMin; // Untergrenze fuer Attributierung sal_uInt16 m_nSelectEntryCnt; // Anzahl der Eintraege der akt. Listbox sal_uInt16 m_nOpenParaToken; // ein geoeffnetes Absatz-Element enum JumpToMarks { JUMPTO_NONE, JUMPTO_MARK, JUMPTO_TABLE, JUMPTO_FRAME, JUMPTO_REGION, JUMPTO_GRAPHIC } m_eJumpTo; #ifdef DBG_UTIL sal_uInt16 m_nContinue; // depth of Continue calls #endif SvxAdjust m_eParaAdjust; // Ausrichtung des aktuellen Absatz HTMLScriptLanguage m_eScriptLang; // die aktuelle Script-Language bool m_bOldIsHTMLMode : 1; // War's mal ein HTML-Dokument? bool m_bDocInitalized : 1; // Dokument bzw. Shell wurden initialisiert // Flag um doppeltes init durch Rekursion // zu verhindern. bool m_bViewCreated : 1; // die View wurde schon erzeugt (asynchron) bool m_bSetCrsr : 1; // Crsr wieder auf den Anfang setzen bool m_bSetModEnabled : 1; bool m_bInFloatingFrame : 1; // Wir sind in einen Floating Frame bool m_bInField : 1; bool m_bKeepUnknown : 1; // unbekannte/nicht unterstuetze Tokens beh. // 8 bool m_bCallNextToken : 1; // In Tabellen: NextToken in jedem Fall rufen bool m_bIgnoreRawData : 1; // Inhalt eines Scripts/Styles ignorieren. bool m_bLBEntrySelected : 1; // Ist der aktuelle Listbox-Eintrag selekt. bool m_bTAIgnoreNewPara : 1; // naechstes LF in TextArea ignorieren? bool m_bFixMarqueeWidth : 1; // Groesse einer Laufschrift anpassen? bool m_bUpperSpace : 1; // obererer Absatz-Abstand wird benoetigt bool m_bNoParSpace : 1; // 16 bool m_bAnyStarBasic : 1; // gibt es ueberhaupt ein StarBasic-Modul bool m_bInNoEmbed : 1; // Wir sind in einem NOEMBED-Bereich bool m_bInTitle : 1; // Wir sind im Titel bool m_bChkJumpMark : 1; // springe ggfs. zu einem vorgegebenem Mark bool m_bUpdateDocStat : 1; bool m_bFixSelectWidth : 1; // Breite eines Selects neu setzen? bool m_bFixSelectHeight : 1; // Breite eines Selects neu setzen? bool m_bTextArea : 1; // 24 bool m_bSelect : 1; bool m_bInFootEndNoteAnchor : 1; bool m_bInFootEndNoteSymbol : 1; bool m_bIgnoreHTMLComments : 1; bool m_bRemoveHidden : 1; // the filter implementation might set the hidden flag /// the names corresponding to the DOCINFO field subtypes INFO[1-4] OUString m_InfoNames[4]; SfxViewFrame* m_pTempViewFrame; void DeleteFormImpl(); void DocumentDetected(); void Show(); void ShowStatline(); SwViewShell *CallStartAction( SwViewShell *pVSh = nullptr, bool bChkPtr = true ); SwViewShell *CallEndAction( bool bChkAction = false, bool bChkPtr = true ); SwViewShell *CheckActionViewShell(); DECL_LINK_TYPED( AsyncCallback, void*, void ); // Attribute am Dok setzen void _SetAttr( bool bChkEnd, bool bBeforeTable, _HTMLAttrs *pPostIts ); inline void SetAttr( bool bChkEnd = true, bool bBeforeTable = false, _HTMLAttrs *pPostIts = nullptr ) { if( !m_aSetAttrTab.empty() || !m_aMoveFlyFrms.empty() ) _SetAttr( bChkEnd, bBeforeTable, pPostIts ); } _HTMLAttr **GetAttrTabEntry( sal_uInt16 nWhich ); // Einen neuen Textknoten an PaM-Position anlegen bool AppendTextNode( SwHTMLAppendMode eMode=AM_NORMAL, bool bUpdateNum=true ); void AddParSpace(); // Ein Attribut beginnen/beenden // ppDepAttr gibt einen Attribut-Tabellen-Eintrag an, dessen Attribute // gesetzt sein muessen, bevor das Attribut beendet werden darf void NewAttr( _HTMLAttr **ppAttr, const SfxPoolItem& rItem ); bool EndAttr( _HTMLAttr *pAttr, _HTMLAttr **ppDepAttr=nullptr, bool bChkEmpty=true ); void DeleteAttr( _HTMLAttr* pAttr ); void EndContextAttrs( _HTMLAttrContext *pContext, bool bRemove=false ); void SaveAttrTab( _HTMLAttrTable& rNewAttrTab ); void SplitAttrTab( const SwPosition& rNewPos ); void SplitAttrTab( _HTMLAttrTable& rNewAttrTab, bool bMoveEndBack = true ); void RestoreAttrTab( _HTMLAttrTable& rNewAttrTab, bool bSetNewStart = false ); void InsertAttr( const SfxPoolItem& rItem, bool bLikePara = false, bool bInsAtStart=false ); void InsertAttrs( _HTMLAttrs& rAttrs ); bool DoPositioning( SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo, _HTMLAttrContext *pContext ); bool CreateContainer( const OUString& rClass, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo, _HTMLAttrContext *pContext ); bool EndSection( bool bLFStripped=false ); void InsertAttrs( SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo, _HTMLAttrContext *pContext, bool bCharLvl=false ); void InsertAttr( _HTMLAttr **ppAttr, const SfxPoolItem & rItem, _HTMLAttrContext *pCntxt ); void SplitPREListingXMP( _HTMLAttrContext *pCntxt ); void FixHeaderFooterDistance( bool bHeader, const SwPosition *pOldPos ); void EndContext( _HTMLAttrContext *pContext ); void ClearContext( _HTMLAttrContext *pContext ); const SwFormatColl *GetCurrFormatColl() const; SwTwips GetCurrentBrowseWidth(); SwHTMLNumRuleInfo& GetNumInfo() { return *m_pNumRuleInfo; } // add parameter void SetNodeNum( sal_uInt8 nLevel, bool bCountedInList ); // Verwalten von Absatz-Vorlagen // die Vorlagen auf dem Stack bzw. deren Attribute setzen void SetTextCollAttrs( _HTMLAttrContext *pContext = nullptr ); void InsertParaAttrs( const SfxItemSet& rItemSet ); // Verwalten des Attribut-Kontexts // aktuellen Kontext merken inline void PushContext( _HTMLAttrContext *pCntxt ); // den obersten/spezifizierten Kontext holen, aber nicht ausserhalb // des Kontexts mit Token nLimit suchen. Wenn bRemove gesetzt ist, // wird er entfernt _HTMLAttrContext *PopContext( sal_uInt16 nToken=0, sal_uInt16 nLimit=0, bool bRemove=true ); bool GetMarginsFromContext( sal_uInt16 &nLeft, sal_uInt16 &nRight, short& nIndent, bool bIgnoreCurrent=false ) const; bool GetMarginsFromContextWithNumBul( sal_uInt16 &nLeft, sal_uInt16 &nRight, short& nIndent ) const; void GetULSpaceFromContext( sal_uInt16 &rUpper, sal_uInt16 &rLower ) const; void MovePageDescAttrs( SwNode *pSrcNd, sal_uLong nDestIdx, bool bFormatBreak ); // Behandlung von Tags auf Absatz-Ebene //

und

bis

void NewPara(); void EndPara( bool bReal = false ); void NewHeading( int nToken ); void EndHeading(); //
,
und
    void NewTextFormatColl( int nToken, sal_uInt16 nPoolId );
    void EndTextFormatColl( int nToken );

    // 
und
void NewDivision( int nToken ); void EndDivision( int nToken ); // Fly-Frames einfuegen/verlassen void InsertFlyFrame( const SfxItemSet& rItemSet, _HTMLAttrContext *pCntxt, const OUString& rId, sal_uInt16 nFlags ); void SaveDocContext( _HTMLAttrContext *pCntxt, sal_uInt16 nFlags, const SwPosition *pNewPos ); void RestoreDocContext( _HTMLAttrContext *pCntxt ); // alle durch
aufgespannten Bereiche verlassen bool EndSections( bool bLFStripped ); // void NewMultiCol( sal_uInt16 columnsFromCss=0 ); // void NewMarquee( HTMLTable *pCurTable=nullptr ); void EndMarquee(); void InsertMarqueeText(); // Behandluung von Listen // Numerierungs
    und Aufzaehlungs-Listen