android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / filter / inc / msfilter.hxx
blob70ef8d12aa809fdb72627a0f0d6b41e817ae6bef
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SW_SOURCE_FILTER_INC_MSFILTER_HXX
21 #define INCLUDED_SW_SOURCE_FILTER_INC_MSFILTER_HXX
23 #include <sal/config.h>
25 #include <map>
26 #include <vector>
27 #include <memory>
28 #include <swtypes.hxx>
29 #include "wwstyles.hxx"
30 #include <rtl/textenc.h>
31 #include "fltshell.hxx"
32 #include <shellio.hxx>
33 #include <svl/listener.hxx>
35 class SwDoc;
36 class SwPaM;
37 class SwTableNode;
38 class SwNodeIndex;
39 class SwNoTextNode;
40 class SwTextNode;
41 class WW8TabDesc;
43 namespace myImplHelpers
45 template<class C> class StyleMapperImpl;
48 class SwTextFormatColl;
49 class SwCharFormat;
51 namespace sw
53 namespace ms
55 /** MSOffice appears to set the charset of unicode fonts to MS 932
57 But we do "default", whatever that means.
59 @param eTextEncoding
60 the OOo encoding to convert from
62 @return
63 a msoffice equivalent charset identifier
65 sal_uInt8 rtl_TextEncodingToWinCharset(rtl_TextEncoding eTextEncoding);
67 /** MSOffice appears to set the charset of unicode fonts to MS 932
69 Arial Unicode MS for example is a unicode font, but word sets
70 exported uses of it to the MS 932 charset
73 sal_uInt8 rtl_TextEncodingToWinCharsetRTF(OUString const& rFontName,
74 OUString const& rAltName, rtl_TextEncoding eTextEncoding);
76 /** Convert from DTTM to Writer's DateTime
79 sal_uInt32 DateTime2DTTM( const DateTime& rDT );
81 /** Convert from Word Date/Time field str to Writer's Date Time str
84 sal_uLong MSDateTimeFormatToSwFormat(OUString& rParams, SvNumberFormatter *pFormatter, LanguageType &rLang, bool bHijri, LanguageType nDocLang);
86 /*Used to identify if the previous token is AM time field*/
87 bool IsPreviousAM(std::u16string_view rParams, sal_Int32 nPos);
89 /*Used to identify if the next token is PM time field*/
90 bool IsNextPM(std::u16string_view rParams, sal_Int32 nPos);
92 /** Used by MSDateTimeFormatToSwFormat to identify AM time fields
95 bool IsNotAM(std::u16string_view rParams, sal_Int32 nPos);
97 /** Another function used by MSDateTimeFormatToSwFormat
100 void SwapQuotesInField(OUString &rFormat);
104 namespace util
106 /** Clips a value to MAX/MIN 16bit value to make it safe for use
107 as a position value to give to writer. i.e. +-57.8cm. Sometimes
108 we see ridiculous values for positioning in rtf and word document,
109 this captures such ones and clips them to values which are
110 still outside the document, but of a value that doesn't cause
111 problems for writer's layout, e.g. see
112 https://bz.apache.org/ooo/show_bug.cgi?id=i9245
114 @param nIn
116 @return nIn clipped to min/max 16bit value
118 SwTwips MakeSafePositioningValue(SwTwips nIn);
120 /** Knows which writer style a given word style should be imported as
122 Mapping a word style to a writer style has to consider mapping
123 the word builtin styles like "Normal" as the default root style
124 to our default root style which is called "Default" in english,
125 and "Normal" in german.
127 Additionally it then has to avoid name collisions such as
129 a) styles "Normal" and "Default" in a single document, where
130 we can use the original distinct names "Normal" and "Default" and...
131 b) styles "Normal" and "Default" in a single document, where
132 we can not use the original names, and must come up with an
133 alternative name for one of them...
135 And it needs to report to the importer if the style being mapped to
136 was already in existence, for the cut and paste/insert file mode we
137 should not modify the returned style if it is already in use as it
138 does not belong to us to change.
140 class ParaStyleMapper
142 private:
143 //I hate these things stupid pImpl things, but it's warranted here
144 std::unique_ptr<::myImplHelpers::StyleMapperImpl<SwTextFormatColl> > mpImpl;
145 public:
146 explicit ParaStyleMapper(SwDoc &rDoc);
147 ~ParaStyleMapper();
149 /** StyleResult
150 StyleResult is a std::pair of a pointer to a style and a flag
151 which is true if the style existed previously in the document.
153 typedef std::pair<SwTextFormatColl*, bool> StyleResult;
155 /** Get the writer style which the word style should map to
157 @param rName
158 The name of the word style
160 @param eSti
161 The style id of the word style, we are really only interested
162 in knowing if the style has either a builtin standard id, or is
163 a user defined style.
165 @param rCollisions
166 Cache of previous name collisions to speed up resolution
167 of later duplicates.
169 @return
170 The equivalent writer style packaged as a StyleResult to use
171 for this word style.
173 It will only return a failure in the pathological case of
174 catastrophic failure elsewhere of there exist already styles
175 rName and WW-rName[0..SAL_MAX_INT32], which is both unlikely
176 and impossible.
178 StyleResult GetStyle(const OUString& rName, ww::sti eSti,
179 std::map<OUString, sal_Int32>& rCollisions);
182 /** Knows which writer style a given word style should be imported as
184 Mapping a word style to a writer style has to consider mapping
185 the word builtin styles like "Normal" as the default root style
186 to our default root style which is called "Default" in english,
187 and "Normal" in german.
189 Additionally it then has to avoid name collisions such as
191 a) styles "Normal" and "Default" in a single document, where
192 we can use the original distinct names "Normal" and "Default" and...
193 b) styles "Normal" and "Default" in a single document, where
194 we can not use the original names, and must come up with an
195 alternative name for one of them...
197 And it needs to report to the importer if the style being mapped to
198 was already in existence, for the cut and paste/insert file mode we
199 should not modify the returned style if it is already in use as it
200 does not belong to us to change.
202 class CharStyleMapper
204 private:
205 //I hate these things stupid pImpl things, but it's warranted here
206 std::unique_ptr<::myImplHelpers::StyleMapperImpl<SwCharFormat>> mpImpl;
207 public:
208 explicit CharStyleMapper(SwDoc &rDoc);
209 ~CharStyleMapper();
211 /** StyleResult
212 StyleResult is a std::pair of a pointer to a style and a flag
213 which is true if the style existed previously in the document.
215 typedef std::pair<SwCharFormat*, bool> StyleResult;
217 /** Get the writer style which the word style should map to
219 @param rName
220 The name of the word style
222 @param eSti
223 The style id of the word style, we are really only interested
224 in knowing if the style has either a builtin standard id, or is
225 a user defined style.
227 @param rCollisions
228 Cache of previous name collisions to speed up resolution
229 of later duplicates.
231 @return
232 The equivalent writer style packaged as a StyleResult to use
233 for this word style.
235 It will only return a failure in the pathological case of
236 catastrophic failure elsewhere of there exist already styles
237 rName and WW-rName[0..SAL_MAX_INT32], which is both unlikely
238 and impossible.
240 StyleResult GetStyle(const OUString& rName, ww::sti eSti,
241 std::map<OUString, sal_Int32>& rCollisions);
244 /** Find suitable names for exporting this font
246 Given a fontname description find the best primary and secondary
247 fallback font to use from MSWord's persp font
249 @see #i10242#/#i19164# for examples
251 class FontMapExport
253 public:
254 OUString msPrimary;
255 OUString msSecondary;
256 explicit FontMapExport(std::u16string_view rFontDescription);
259 class InsertedTableListener final : public SvtListener
261 SwTableNode* m_pTableNode;
262 public:
263 explicit InsertedTableListener(SwTableNode& rNode);
264 SwTableNode* GetTableNode();
265 virtual void Notify(const SfxHint&) override;
268 /** Handle requirements for table formatting in insert->file mode.
270 When inserting a table into a document which already has been
271 formatted and laid out (e.g using insert->file) then tables
272 must be handled in a special way, (or so previous comments and
273 code in the filters leads me to believe).
275 Before the document is finalized the new tables need to have
276 their layout frms deleted and recalculated. This TableManager
277 detects the necessity to do this, and all tables inserted into
278 a document should be registered with this manager with
279 InsertTable, and before finalization DelAndMakeTableFrames should
280 be called.
282 @see #i25782# for examples
284 class InsertedTablesManager
286 public:
287 void DelAndMakeTableFrames();
288 void InsertTable(SwTableNode &rTableNode, SwPaM &rPaM);
289 explicit InsertedTablesManager(const SwDoc &rDoc);
290 private:
291 bool mbHasRoot;
292 std::map<std::unique_ptr<InsertedTableListener>, SwPosition*> maTables;
295 void MoveAttrFieldmarkInserted(SwFltPosition& rMkPos, SwFltPosition& rPtPos, const SwPosition& rPos);
297 class RedlineStack
299 private:
300 std::vector<std::unique_ptr<SwFltStackEntry>> maStack;
301 SwDoc &mrDoc;
303 RedlineStack(RedlineStack const&) = delete;
304 RedlineStack& operator=(RedlineStack const&) = delete;
306 public:
307 explicit RedlineStack(SwDoc &rDoc) : mrDoc(rDoc) {}
308 void MoveAttrsFieldmarkInserted(const SwPosition& rPos);
309 void open(const SwPosition& rPos, const SfxPoolItem& rAttr);
310 bool close(const SwPosition& rPos, RedlineType eType);
311 void close(const SwPosition& rPos, RedlineType eType,
312 WW8TabDesc* pTabDesc );
313 void closeall(const SwPosition& rPos);
314 ~RedlineStack();
317 class SetInDocAndDelete
319 private:
320 SwDoc &mrDoc;
321 public:
322 explicit SetInDocAndDelete(SwDoc &rDoc) : mrDoc(rDoc) {}
323 SetInDocAndDelete(SetInDocAndDelete const &) = default;
324 void operator()(std::unique_ptr<SwFltStackEntry> & pEntry);
325 private:
326 SetInDocAndDelete& operator=(const SetInDocAndDelete&) = delete;
329 class SetEndIfOpen //Subclass from something ?
331 private:
332 const SwPosition &mrPos;
333 public:
334 explicit SetEndIfOpen(const SwPosition &rPos) : mrPos(rPos) {}
335 void operator()(const std::unique_ptr<SwFltStackEntry> & pEntry) const
337 if (pEntry->m_bOpen)
338 pEntry->SetEndPos(mrPos);
340 SetEndIfOpen(SetEndIfOpen const &) = default;
341 private:
342 SetEndIfOpen& operator=(const SetEndIfOpen&) = delete;
345 class CompareRedlines
347 public:
348 bool operator()(const std::unique_ptr<SwFltStackEntry> & pOneE, const std::unique_ptr<SwFltStackEntry> & pTwoE)
349 const;
352 class WrtRedlineAuthor
354 protected:
355 std::vector<OUString> maAuthors; // Array of Sw - Bookmarknames
357 private:
358 WrtRedlineAuthor(WrtRedlineAuthor const&) = delete;
359 WrtRedlineAuthor& operator=(WrtRedlineAuthor const&) = delete;
361 public:
362 WrtRedlineAuthor() = default;
363 virtual ~WrtRedlineAuthor() {}
365 sal_uInt16 AddName( const OUString& rNm );
366 virtual void Write(Writer &rWrt) = 0;
369 struct CharRunEntry
371 sal_Int32 mnEndPos;
372 sal_uInt16 mnScript;
373 rtl_TextEncoding meCharSet;
374 bool mbRTL;
375 CharRunEntry(sal_Int32 nEndPos, sal_uInt16 nScript,
376 rtl_TextEncoding eCharSet, bool bRTL)
377 : mnEndPos(nEndPos), mnScript(nScript), meCharSet(eCharSet),
378 mbRTL(bRTL)
383 typedef std::vector<CharRunEntry> CharRuns;
385 /** Collect the ranges of Text which share
387 Word generally requires characters which share the same direction,
388 the same script, and occasionally (depending on the format) the
389 same charset to be exported in independent chunks.
391 So this function finds these ranges and returns a STL container
392 of CharRuns
394 @param rTextNd
395 The TextNode we want to ranges from
397 @return STL container of CharRuns which describe the shared
398 direction, script and optionally script of the contiguous sequences
399 of characters
401 @see #i22537# for example
403 CharRuns GetPseudoCharRuns(const SwTextNode& rTextNd);
407 #endif
409 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */