/* -*- 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_INC_MSFILTER_HXX #define INCLUDED_SW_SOURCE_FILTER_INC_MSFILTER_HXX #include #include #include #include #include #include "wwstyles.hxx" #include #include #include #include #include #include #include #include class SwDoc; class SwPaM; class SwTableNode; class SwNodeIndex; class SwNoTextNode; class SwTextNode; class WW8TabDesc; namespace myImplHelpers { template class StyleMapperImpl; } class SwTextFormatColl; class SwCharFormat; namespace sw { namespace ms { /** MSOffice appears to set the charset of unicode fonts to MS 932 But we do "default", whatever that means. @param eTextEncoding the OOo encoding to convert from @return a msoffice equivalent charset identifier @author Caolán McNamara */ sal_uInt8 rtl_TextEncodingToWinCharset(rtl_TextEncoding eTextEncoding); /** MSOffice appears to set the charset of unicode fonts to MS 932 Arial Unicode MS for example is a unicode font, but word sets exported uses of it to the MS 932 charset */ sal_uInt8 rtl_TextEncodingToWinCharsetRTF(OUString const& rFontName, OUString const& rAltName, rtl_TextEncoding eTextEncoding); /** Import a MSWord XE field. Suitable for .doc and .rtf @param rDoc the document to insert into @param rPaM the position in the document to insert into @param rXE the arguments of the original word XE field @author Caolán McNamara */ void ImportXE(SwDoc &rDoc, SwPaM &rPaM, const OUString &rXE); /** Convert from DTTM to Writer's DateTime @author Martin MaherMartin MaherMartin MaherMartin Maher AuthorInfos; /** Clips a value to MAX/MIN 16bit value to make it safe for use as a position value to give to writer. i.e. +-57.8cm. Sometimes we see ridiculous values for positioning in rtf and word document, this captures such ones and clips them to values which are still outside the document, but of a value that doesn't cause problems for writer's layout, e.g. see http://www.openoffice.org/issues/show_bug.cgi?id=i9245 @param nIn @return nIn clipped to min/max 16bit value @author Caolán McNamara */ SwTwips MakeSafePositioningValue(SwTwips nIn); /** Knows which writer style a given word style should be imported as Mapping a word style to a writer style has to consider mapping the word builtin styles like "Normal" as the default root style to our default root style which is called "Default" in english, and "Normal" in german. Additionally it then has to avoid name collisions such as a) styles "Normal" and "Default" in a single document, where we can use the original distinct names "Normal" and "Default" and.. b) styles "Normal" and "Default" in a single document, where we can not use the original names, and must come up with an alternative name for one of them.. And it needs to report to the importer if the style being mapped to was already in existence, for the cut and paste/insert file mode we should not modify the returned style if it is already in use as it is does not belong to us to change. @author Caolán McNamara */ class ParaStyleMapper { private: //I hate these things stupid pImpl things, but its warranted here std::unique_ptr<::myImplHelpers::StyleMapperImpl > mpImpl; public: explicit ParaStyleMapper(SwDoc &rDoc); ~ParaStyleMapper(); /** StyleResult StyleResult is a std::pair of a pointer to a style and a flag which is true if the style existed previously in the document. */ typedef std::pair StyleResult; /** Get the writer style which the word style should map to @param rName The name of the word style @param eSti The style id of the word style, we are really only interested in knowing if the style has either a builtin standard id, or is a user defined style. @return The equivalent writer style packaged as a StyleResult to use for this word style. It will only return a failure in the pathological case of catastropic failure elsewhere of there exist already styles rName and WW-rName[0..SAL_MAX_INT32], which is both unlikely and impossible. */ StyleResult GetStyle(const OUString& rName, ww::sti eSti); }; /** Knows which writer style a given word style should be imported as Mapping a word style to a writer style has to consider mapping the word builtin styles like "Normal" as the default root style to our default root style which is called "Default" in english, and "Normal" in german. Additionally it then has to avoid name collisions such as a) styles "Normal" and "Default" in a single document, where we can use the original distinct names "Normal" and "Default" and.. b) styles "Normal" and "Default" in a single document, where we can not use the original names, and must come up with an alternative name for one of them.. And it needs to report to the importer if the style being mapped to was already in existence, for the cut and paste/insert file mode we should not modify the returned style if it is already in use as it is does not belong to us to change. @author Caolán McNamara */ class CharStyleMapper { private: //I hate these things stupid pImpl things, but its warranted here ::myImplHelpers::StyleMapperImpl *mpImpl; public: explicit CharStyleMapper(SwDoc &rDoc); ~CharStyleMapper(); /** StyleResult StyleResult is a std::pair of a pointer to a style and a flag which is true if the style existed previously in the document. */ typedef std::pair StyleResult; /** Get the writer style which the word style should map to @param rName The name of the word style @param eSti The style id of the word style, we are really only interested in knowing if the style has either a builtin standard id, or is a user defined style. @return The equivalent writer style packaged as a StyleResult to use for this word style. It will only return a failure in the pathological case of catastropic failure elsewhere of there exist already styles rName and WW-rName[0..SAL_MAX_INT32], which is both unlikely and impossible. */ StyleResult GetStyle(const OUString& rName, ww::sti eSti); }; /** Find suitable names for exporting this font Given a fontname description find the best primary and secondary fallback font to use from MSWord's persp font @author Caolán McNamara @see #i10242#/#i19164# for examples */ class FontMapExport { public: OUString msPrimary; OUString msSecondary; explicit FontMapExport(const OUString &rFontDescription); }; class InsertedTableClient : public SwClient { public: explicit InsertedTableClient(SwTableNode & rNode); SwTableNode * GetTableNode(); }; /** Handle requirements for table formatting in insert->file mode. When inserting a table into a document which already has been formatted and laid out (e.g using insert->file) then tables must be handled in a special way, (or so previous comments and code in the filters leads me to believe). Before the document is finalized the new tables need to have their layout frms deleted and recalculated. This TableManager detects the necessity to do this, and all tables inserted into a document should be registered with this manager with InsertTable, and before finialization DelAndMakeTableFrms should be called. @author Caolán McNamara @see #i25782# for examples */ class InsertedTablesManager { public: typedef std::map TableMap; typedef TableMap::iterator TableMapIter; void DelAndMakeTableFrms(); void InsertTable(SwTableNode &rTableNode, SwPaM &rPaM); explicit InsertedTablesManager(const SwDoc &rDoc); private: bool mbHasRoot; TableMap maTables; }; /** @author Martin Maher */ class RedlineStack : public boost::noncopyable { private: std::vector maStack; typedef std::vector::reverse_iterator myriter; SwDoc &mrDoc; public: explicit RedlineStack(SwDoc &rDoc) : mrDoc(rDoc) {} void open(const SwPosition& rPos, const SfxPoolItem& rAttr); bool close(const SwPosition& rPos, RedlineType_t eType); void close(const SwPosition& rPos, RedlineType_t eType, WW8TabDesc* pTabDesc ); void closeall(const SwPosition& rPos); ~RedlineStack(); }; /** @author Martin Maher */ class SetInDocAndDelete { private: SwDoc &mrDoc; public: explicit SetInDocAndDelete(SwDoc &rDoc) : mrDoc(rDoc) {} void operator()(SwFltStackEntry *pEntry); private: SetInDocAndDelete& operator=(const SetInDocAndDelete&) = delete; }; /** @author Martin Maher */ class SetEndIfOpen //Subclass from something ? { private: const SwPosition &mrPos; public: explicit SetEndIfOpen(const SwPosition &rPos) : mrPos(rPos) {} void operator()(SwFltStackEntry *pEntry) const { if (pEntry->bOpen) pEntry->SetEndPos(mrPos); } private: SetEndIfOpen& operator=(const SetEndIfOpen&) = delete; }; /** @author Martin Maher */ class CompareRedlines: public std::binary_function { public: bool operator()(const SwFltStackEntry *pOneE, const SwFltStackEntry *pTwoE) const; }; class WrtRedlineAuthor : public boost::noncopyable { protected: std::vector maAuthors; // Array of Sw - Bookmarknames public: WrtRedlineAuthor() {} virtual ~WrtRedlineAuthor() {} sal_uInt16 AddName( const OUString& rNm ); virtual void Write(Writer &rWrt) = 0; }; struct CharRunEntry { sal_Int32 mnEndPos; sal_uInt16 mnScript; rtl_TextEncoding meCharSet; bool mbRTL; CharRunEntry(sal_Int32 nEndPos, sal_uInt16 nScript, rtl_TextEncoding eCharSet, bool bRTL) : mnEndPos(nEndPos), mnScript(nScript), meCharSet(eCharSet), mbRTL(bRTL) { } }; typedef std::vector CharRuns; typedef CharRuns::const_iterator cCharRunIter; /** Collect the ranges of Text which share Word generally requires characters which share the same direction, the same script, and occasionally (depending on the format) the same charset to be exported in independent chunks. So this function finds these ranges and returns a STL container of CharRuns @param rTextNd The TextNode we want to ranges from @param nStart The position in the TextNode to start processing from @return STL container of CharRuns which describe the shared direction, script and optionally script of the contiguous sequences of characters @author Caolán McNamara @see #i22537# for example */ CharRuns GetPseudoCharRuns(const SwTextNode& rTextNd, sal_Int32 nStart = 0); } } #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */