Add Marathi autocorrect
[LibreOffice.git] / sw / source / filter / inc / msfilter.hxx
blob39c1c465cb168bb906352e07d43c28383d598a98
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 void ImplDestroy();
308 public:
309 explicit RedlineStack(SwDoc &rDoc) : mrDoc(rDoc) {}
310 void MoveAttrsFieldmarkInserted(const SwPosition& rPos);
311 void open(const SwPosition& rPos, const SfxPoolItem& rAttr);
312 bool close(const SwPosition& rPos, RedlineType eType);
313 void close(const SwPosition& rPos, RedlineType eType,
314 WW8TabDesc* pTabDesc );
315 void closeall(const SwPosition& rPos);
316 ~RedlineStack();
319 class SetInDocAndDelete
321 private:
322 SwDoc &mrDoc;
323 public:
324 explicit SetInDocAndDelete(SwDoc &rDoc) : mrDoc(rDoc) {}
325 SetInDocAndDelete(SetInDocAndDelete const &) = default;
326 void operator()(std::unique_ptr<SwFltStackEntry> & pEntry);
327 private:
328 SetInDocAndDelete& operator=(const SetInDocAndDelete&) = delete;
331 class SetEndIfOpen //Subclass from something ?
333 private:
334 const SwPosition &mrPos;
335 public:
336 explicit SetEndIfOpen(const SwPosition &rPos) : mrPos(rPos) {}
337 void operator()(const std::unique_ptr<SwFltStackEntry> & pEntry) const
339 if (pEntry->m_bOpen)
340 pEntry->SetEndPos(mrPos);
342 SetEndIfOpen(SetEndIfOpen const &) = default;
343 private:
344 SetEndIfOpen& operator=(const SetEndIfOpen&) = delete;
347 class CompareRedlines
349 public:
350 bool operator()(const std::unique_ptr<SwFltStackEntry> & pOneE, const std::unique_ptr<SwFltStackEntry> & pTwoE)
351 const;
354 class WrtRedlineAuthor
356 protected:
357 std::vector<OUString> maAuthors; // Array of Sw - Bookmarknames
359 private:
360 WrtRedlineAuthor(WrtRedlineAuthor const&) = delete;
361 WrtRedlineAuthor& operator=(WrtRedlineAuthor const&) = delete;
363 public:
364 WrtRedlineAuthor() = default;
365 virtual ~WrtRedlineAuthor() {}
367 sal_uInt16 AddName( const OUString& rNm );
368 virtual void Write(Writer &rWrt) = 0;
371 struct CharRunEntry
373 sal_Int32 mnEndPos;
374 sal_uInt16 mnScript;
375 rtl_TextEncoding meCharSet;
376 bool mbRTL;
377 CharRunEntry(sal_Int32 nEndPos, sal_uInt16 nScript,
378 rtl_TextEncoding eCharSet, bool bRTL)
379 : mnEndPos(nEndPos), mnScript(nScript), meCharSet(eCharSet),
380 mbRTL(bRTL)
385 typedef std::vector<CharRunEntry> CharRuns;
387 /** Collect the ranges of Text which share
389 Word generally requires characters which share the same direction,
390 the same script, and occasionally (depending on the format) the
391 same charset to be exported in independent chunks.
393 So this function finds these ranges and returns a STL container
394 of CharRuns
396 @param rTextNd
397 The TextNode we want to ranges from
399 @return STL container of CharRuns which describe the shared
400 direction, script and optionally script of the contiguous sequences
401 of characters
403 @see #i22537# for example
405 CharRuns GetPseudoCharRuns(const SwTextNode& rTextNd);
409 #endif
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */