1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <com/sun/star/awt/Size.hpp>
11 #include <com/sun/star/lang/Locale.hpp>
12 #include <rtl/ustring.hxx>
13 #include <rtl/character.hxx>
14 #include <comphelper/string.hxx>
15 #include <unotools/fontcvt.hxx>
16 #include <unotools/fontdefs.hxx>
18 #include <vcl/BitmapPalette.hxx>
19 #include <filter/msfilter/escherex.hxx>
20 #include <filter/msfilter/util.hxx>
21 #include <o3tl/string_view.hxx>
23 #include <unordered_map>
25 namespace msfilter::util
{
27 rtl_TextEncoding
getBestTextEncodingFromLocale(const css::lang::Locale
&rLocale
)
29 // Obviously not comprehensive, feel free to expand these, they're for ultimate fallbacks
30 // in last-ditch broken-file-format cases to guess the right 8bit encodings
31 const OUString
&rLanguage
= rLocale
.Language
;
32 if (rLanguage
== "cs" || rLanguage
== "hu" || rLanguage
== "pl")
33 return RTL_TEXTENCODING_MS_1250
;
34 if (rLanguage
== "ru" || rLanguage
== "uk")
35 return RTL_TEXTENCODING_MS_1251
;
36 if (rLanguage
== "el")
37 return RTL_TEXTENCODING_MS_1253
;
38 if (rLanguage
== "tr")
39 return RTL_TEXTENCODING_MS_1254
;
40 if (rLanguage
== "lt")
41 return RTL_TEXTENCODING_MS_1257
;
42 if (rLanguage
== "th")
43 return RTL_TEXTENCODING_MS_874
;
44 if (rLanguage
== "vi")
45 return RTL_TEXTENCODING_MS_1258
;
46 return RTL_TEXTENCODING_MS_1252
;
49 ::Color
BGRToRGB(sal_uInt32 nColor
)
52 r(static_cast<sal_uInt8
>(nColor
&0xFF)),
53 g(static_cast<sal_uInt8
>((nColor
>>8)&0xFF)),
54 b(static_cast<sal_uInt8
>((nColor
>>16)&0xFF)),
55 t(static_cast<sal_uInt8
>((nColor
>>24)&0xFF));
56 return ::Color(ColorTransparency
, t
, r
, g
, b
);
59 DateTime
DTTM2DateTime( tools::Long lDTTM
)
62 mint short :6 0000003F minutes (0-59)
63 hr short :5 000007C0 hours (0-23)
64 dom short :5 0000F800 days of month (1-31)
65 mon short :4 000F0000 months (1-12)
66 yr short :9 1FF00000 years (1900-2411)-1900
67 wdy short :3 E0000000 weekday(Sunday=0
69 ( wdy can be ignored ) Tuesday=2
75 DateTime
aDateTime(Date( 0 ), ::tools::Time( tools::Time::EMPTY
));
78 sal_uInt16 lMin
= static_cast<sal_uInt16
>(lDTTM
& 0x0000003F);
80 sal_uInt16 lHour
= static_cast<sal_uInt16
>(lDTTM
& 0x0000001F);
82 sal_uInt16 lDay
= static_cast<sal_uInt16
>(lDTTM
& 0x0000001F);
84 sal_uInt16 lMon
= static_cast<sal_uInt16
>(lDTTM
& 0x0000000F);
86 sal_uInt16 lYear
= static_cast<sal_uInt16
>(lDTTM
& 0x000001FF) + 1900;
87 aDateTime
= DateTime(Date(lDay
, lMon
, lYear
), tools::Time(lHour
, lMin
));
92 sal_Unicode
bestFitOpenSymbolToMSFont(sal_Unicode cChar
,
93 rtl_TextEncoding
& rChrSet
, OUString
& rFontName
)
95 std::unique_ptr
<StarSymbolToMSMultiFont
> pConvert(CreateStarSymbolToMSMultiFont());
96 OUString sFont
= pConvert
->ConvertChar(cChar
);
100 cChar
= static_cast< sal_Unicode
>(cChar
| 0xF000);
102 rChrSet
= RTL_TEXTENCODING_SYMBOL
;
104 else if (cChar
< 0xE000 || cChar
> 0xF8FF)
107 Ok we can't fit into a known windows unicode font, but
108 we are not in the private area, so we are a
109 standardized symbol, so turn off the symbol bit and
110 let words own font substitution kick in
112 rChrSet
= RTL_TEXTENCODING_UNICODE
;
113 sal_Int32 nIndex
= 0;
114 rFontName
= ::GetNextFontToken(rFontName
, nIndex
);
119 Well we don't have an available substitution, and we're
120 in our private area, so give up and show a standard
123 rFontName
= "Wingdings";
130 OString
ConvertColor( const Color
&rColor
)
132 static constexpr OStringLiteral
AUTO( "auto" );
134 if ( rColor
== COL_AUTO
)
137 const char pHexDigits
[] = "0123456789ABCDEF";
138 char pBuffer
[] = "000000";
140 pBuffer
[0] = pHexDigits
[ ( rColor
.GetRed() >> 4 ) & 0x0F ];
141 pBuffer
[1] = pHexDigits
[ rColor
.GetRed() & 0x0F ];
142 pBuffer
[2] = pHexDigits
[ ( rColor
.GetGreen() >> 4 ) & 0x0F ];
143 pBuffer
[3] = pHexDigits
[ rColor
.GetGreen() & 0x0F ];
144 pBuffer
[4] = pHexDigits
[ ( rColor
.GetBlue() >> 4 ) & 0x0F ];
145 pBuffer
[5] = pHexDigits
[ rColor
.GetBlue() & 0x0F ];
147 return OString( pBuffer
);
150 OUString
ConvertColorOU( const Color
&rColor
)
152 static constexpr OUStringLiteral
AUTO( u
"auto" );
154 if ( rColor
== COL_AUTO
)
157 const char pHexDigits
[] = "0123456789ABCDEF";
158 sal_Unicode pBuffer
[] = u
"000000";
160 pBuffer
[0] = pHexDigits
[ ( rColor
.GetRed() >> 4 ) & 0x0F ];
161 pBuffer
[1] = pHexDigits
[ rColor
.GetRed() & 0x0F ];
162 pBuffer
[2] = pHexDigits
[ ( rColor
.GetGreen() >> 4 ) & 0x0F ];
163 pBuffer
[3] = pHexDigits
[ rColor
.GetGreen() & 0x0F ];
164 pBuffer
[4] = pHexDigits
[ ( rColor
.GetBlue() >> 4 ) & 0x0F ];
165 pBuffer
[5] = pHexDigits
[ rColor
.GetBlue() & 0x0F ];
167 return OUString( pBuffer
);
178 constexpr sal_Int32
IN2MM100(double v
) { return o3tl::convert(v
, o3tl::Length::in
, o3tl::Length::mm100
) + 0.5; }
179 constexpr sal_Int32
MM2MM100(double v
) { return o3tl::convert(v
, o3tl::Length::mm
, o3tl::Length::mm100
) + 0.5; }
181 // see XclPaperSize pPaperSizeTable in calc and aDinTab in i18nutil
182 constexpr ApiPaperSize spPaperSizeTable
[] =
184 { 0, 0 }, // 0 - (undefined)
185 { IN2MM100( 8.5 ), IN2MM100( 11 ) }, // 1 - Letter paper
186 { IN2MM100( 8.5 ), IN2MM100( 11 ) }, // 2 - Letter small paper
187 { IN2MM100( 11 ), IN2MM100( 17 ) }, // 3 - Tabloid paper
188 { IN2MM100( 17 ), IN2MM100( 11 ) }, // 4 - Ledger paper
189 { IN2MM100( 8.5 ), IN2MM100( 14 ) }, // 5 - Legal paper
190 { IN2MM100( 5.5 ), IN2MM100( 8.5 ) }, // 6 - Statement paper
191 { IN2MM100( 7.25 ), IN2MM100( 10.5 ) }, // 7 - Executive paper
192 { MM2MM100( 297 ), MM2MM100( 420 ) }, // 8 - A3 paper
193 { MM2MM100( 210 ), MM2MM100( 297 ) }, // 9 - A4 paper
194 { MM2MM100( 210 ), MM2MM100( 297 ) }, // 10 - A4 small paper
195 { MM2MM100( 148 ), MM2MM100( 210 ) }, // 11 - A5 paper
196 /* for JIS vs ISO B confusion see:
197 https://docs.microsoft.com/en-us/windows/win32/intl/paper-sizes
198 http://wiki.openoffice.org/wiki/DefaultPaperSize comments
199 http://partners.adobe.com/public/developer/en/ps/5003.PPD_Spec_v4.3.pdf */
200 { MM2MM100( 257 ), MM2MM100( 364 ) }, // 12 - B4 (JIS) paper
201 { MM2MM100( 182 ), MM2MM100( 257 ) }, // 13 - B5 (JIS) paper
202 { IN2MM100( 8.5 ), IN2MM100( 13 ) }, // 14 - Folio paper
203 { MM2MM100( 215 ), MM2MM100( 275 ) }, // 15 - Quarto paper
204 { IN2MM100( 10 ), IN2MM100( 14 ) }, // 16 - Standard paper
205 { IN2MM100( 11 ), IN2MM100( 17 ) }, // 17 - Standard paper
206 { IN2MM100( 8.5 ), IN2MM100( 11 ) }, // 18 - Note paper
207 { IN2MM100( 3.875 ), IN2MM100( 8.875 ) }, // 19 - #9 envelope
208 { IN2MM100( 4.125 ), IN2MM100( 9.5 ) }, // 20 - #10 envelope
209 { IN2MM100( 4.5 ), IN2MM100( 10.375 ) }, // 21 - #11 envelope
210 { IN2MM100( 4.75 ), IN2MM100( 11 ) }, // 22 - #12 envelope
211 { IN2MM100( 5 ), IN2MM100( 11.5 ) }, // 23 - #14 envelope
212 { IN2MM100( 17 ), IN2MM100( 22 ) }, // 24 - C paper
213 { IN2MM100( 22 ), IN2MM100( 34 ) }, // 25 - D paper
214 { IN2MM100( 34 ), IN2MM100( 44 ) }, // 26 - E paper
215 { MM2MM100( 110 ), MM2MM100( 220 ) }, // 27 - DL envelope
216 { MM2MM100( 162 ), MM2MM100( 229 ) }, // 28 - C5 envelope
217 { MM2MM100( 324 ), MM2MM100( 458 ) }, // 29 - C3 envelope
218 { MM2MM100( 229 ), MM2MM100( 324 ) }, // 30 - C4 envelope
219 { MM2MM100( 114 ), MM2MM100( 162 ) }, // 31 - C6 envelope
220 { MM2MM100( 114 ), MM2MM100( 229 ) }, // 32 - C65 envelope
221 { MM2MM100( 250 ), MM2MM100( 353 ) }, // 33 - B4 envelope
222 { MM2MM100( 176 ), MM2MM100( 250 ) }, // 34 - B5 envelope
223 { MM2MM100( 176 ), MM2MM100( 125 ) }, // 35 - B6 envelope
224 { MM2MM100( 110 ), MM2MM100( 230 ) }, // 36 - Italy envelope
225 { IN2MM100( 3.875 ), IN2MM100( 7.5 ) }, // 37 - Monarch envelope
226 { IN2MM100( 3.625 ), IN2MM100( 6.5 ) }, // 38 - 6 3/4 envelope
227 { IN2MM100( 14.875 ), IN2MM100( 11 ) }, // 39 - US standard fanfold
228 { IN2MM100( 8.5 ), IN2MM100( 12 ) }, // 40 - German standard fanfold
229 { IN2MM100( 8.5 ), IN2MM100( 13 ) }, // 41 - German legal fanfold
230 { MM2MM100( 250 ), MM2MM100( 353 ) }, // 42 - ISO B4
231 { MM2MM100( 200 ), MM2MM100( 148 ) }, // 43 - Japanese double postcard
232 { IN2MM100( 9 ), IN2MM100( 11 ) }, // 44 - Standard paper
233 { IN2MM100( 10 ), IN2MM100( 11 ) }, // 45 - Standard paper
234 { IN2MM100( 15 ), IN2MM100( 11 ) }, // 46 - Standard paper
235 { MM2MM100( 220 ), MM2MM100( 220 ) }, // 47 - Invite envelope
236 { 0, 0 }, // 48 - (undefined)
237 { 0, 0 }, // 49 - (undefined)
238 /* See: https://docs.microsoft.com/en-us/windows/win32/intl/paper-sizes */
239 { IN2MM100( 9.5 ), IN2MM100( 12 ) }, // 50 - Letter extra paper
240 { IN2MM100( 9.5 ), IN2MM100( 15 ) }, // 51 - Legal extra paper
241 { IN2MM100( 11.69 ), IN2MM100( 18 ) }, // 52 - Tabloid extra paper
242 { MM2MM100( 235 ), MM2MM100( 322 ) }, // 53 - A4 extra paper
243 { IN2MM100( 8.5 ), IN2MM100( 11 ) }, // 54 - Letter transverse paper
244 { MM2MM100( 210 ), MM2MM100( 297 ) }, // 55 - A4 transverse paper
245 { IN2MM100( 9.5 ), IN2MM100( 12 ) }, // 56 - Letter extra transverse paper
246 { MM2MM100( 227 ), MM2MM100( 356 ) }, // 57 - SuperA/SuperA/A4 paper
247 { MM2MM100( 305 ), MM2MM100( 487 ) }, // 58 - SuperB/SuperB/A3 paper
248 { IN2MM100( 8.5 ), IN2MM100( 12.69 ) }, // 59 - Letter plus paper
249 { MM2MM100( 210 ), MM2MM100( 330 ) }, // 60 - A4 plus paper
250 { MM2MM100( 148 ), MM2MM100( 210 ) }, // 61 - A5 transverse paper
251 { MM2MM100( 182 ), MM2MM100( 257 ) }, // 62 - JIS B5 transverse paper
252 { MM2MM100( 322 ), MM2MM100( 445 ) }, // 63 - A3 extra paper
253 { MM2MM100( 174 ), MM2MM100( 235 ) }, // 64 - A5 extra paper
254 { MM2MM100( 201 ), MM2MM100( 276 ) }, // 65 - ISO B5 extra paper
255 { MM2MM100( 420 ), MM2MM100( 594 ) }, // 66 - A2 paper
256 { MM2MM100( 297 ), MM2MM100( 420 ) }, // 67 - A3 transverse paper
257 { MM2MM100( 322 ), MM2MM100( 445 ) }, // 68 - A3 extra transverse paper
258 { MM2MM100( 200 ), MM2MM100( 148 ) }, // 69 - Japanese double postcard
259 { MM2MM100( 105 ), MM2MM100( 148 ) }, // 70 - A6 paper
260 { 0, 0 }, // 71 - Japanese Envelope Kaku #2
261 { 0, 0 }, // 72 - Japanese Envelope Kaku #3
262 { 0, 0 }, // 73 - Japanese Envelope Chou #3
263 { 0, 0 }, // 74 - Japanese Envelope Chou #4
264 { IN2MM100( 11 ), IN2MM100( 8.5 ) }, // 75 - Letter Rotated
265 { MM2MM100( 420 ), MM2MM100( 297 ) }, // 76 - A3 Rotated
266 { MM2MM100( 297 ), MM2MM100( 210 ) }, // 77 - A4 Rotated
267 { MM2MM100( 210 ), MM2MM100( 148 ) }, // 78 - A5 Rotated
268 { MM2MM100( 364 ), MM2MM100( 257 ) }, // 79 - B4 (JIS) Rotated
269 { MM2MM100( 257 ), MM2MM100( 182 ) }, // 80 - B5 (JIS) Rotated
270 { MM2MM100( 148 ), MM2MM100( 100 ) }, // 81 - Japanese Postcard Rotated
271 { MM2MM100( 148 ), MM2MM100( 200 ) }, // 82 - Double Japanese Postcard Rotated
272 { MM2MM100( 148 ), MM2MM100( 105 ) }, // 83 - A6 Rotated
273 { 0, 0 }, // 84 - Japanese Envelope Kaku #2 Rotated
274 { 0, 0 }, // 85 - Japanese Envelope Kaku #3 Rotated
275 { 0, 0 }, // 86 - Japanese Envelope Chou #3 Rotated
276 { 0, 0 }, // 87 - Japanese Envelope Chou #4 Rotated
277 { MM2MM100( 128 ), MM2MM100( 182 ) }, // 88 - B6 (JIS)
278 { MM2MM100( 182 ), MM2MM100( 128 ) }, // 89 - B6 (JIS) Rotated
279 { IN2MM100( 12 ), IN2MM100( 11 ) }, // 90 - 12x11
281 } // unnamed namespace
283 sal_Int32
PaperSizeConv::getMSPaperSizeIndex( const css::awt::Size
& rSize
)
285 // Need to find the best match for current size
286 sal_Int32 nDeltaWidth
= rSize
.Width
;
287 sal_Int32 nDeltaHeight
= rSize
.Height
;
288 sal_Int32 nTol
= 10; // hmm not sure is this the best way
290 sal_Int32 nPaperSizeIndex
= 0; // Undefined
291 for (size_t i
= 1; i
< std::size(spPaperSizeTable
); ++i
)
293 sal_Int32 nCurDeltaHeight
= std::abs(spPaperSizeTable
[i
].mnHeight
- rSize
.Height
);
294 sal_Int32 nCurDeltaWidth
= std::abs(spPaperSizeTable
[i
].mnWidth
- rSize
.Width
);
295 if (nCurDeltaWidth
<= nTol
&& nCurDeltaHeight
<= nTol
296 && nCurDeltaWidth
+ nCurDeltaHeight
< nDeltaWidth
+ nDeltaHeight
)
298 nDeltaWidth
= nCurDeltaWidth
;
299 nDeltaHeight
= nCurDeltaHeight
;
303 return nPaperSizeIndex
;
306 css::awt::Size
PaperSizeConv::getApiSizeForMSPaperSizeIndex(sal_Int32 nMSOPaperIndex
)
308 if (nMSOPaperIndex
< 0 || nMSOPaperIndex
>= std::ssize(spPaperSizeTable
))
310 return { spPaperSizeTable
[nMSOPaperIndex
].mnWidth
, spPaperSizeTable
[nMSOPaperIndex
].mnHeight
};
313 OUString
CreateDOCXStyleId(std::u16string_view
const aName
)
315 // tdf#161509: some special style names have standard style IDs that don't match case
316 static constexpr std::pair
<std::u16string_view
, OUString
> specialCases
[] = {
317 { u
"heading 1", u
"Heading1"_ustr
},
318 { u
"heading 2", u
"Heading2"_ustr
},
319 { u
"heading 3", u
"Heading3"_ustr
},
320 { u
"heading 4", u
"Heading4"_ustr
},
321 { u
"heading 5", u
"Heading5"_ustr
},
322 { u
"heading 6", u
"Heading6"_ustr
},
323 { u
"heading 7", u
"Heading7"_ustr
},
324 { u
"heading 8", u
"Heading8"_ustr
},
325 { u
"heading 9", u
"Heading9"_ustr
},
326 { u
"index 1", u
"Index1"_ustr
},
327 { u
"index 2", u
"Index2"_ustr
},
328 { u
"index 3", u
"Index3"_ustr
},
329 { u
"index 4", u
"Index4"_ustr
},
330 { u
"index 5", u
"Index5"_ustr
},
331 { u
"index 6", u
"Index6"_ustr
},
332 { u
"index 7", u
"Index7"_ustr
},
333 { u
"index 8", u
"Index8"_ustr
},
334 { u
"index 9", u
"Index9"_ustr
},
335 { u
"toc 1", u
"TOC1"_ustr
},
336 { u
"toc 2", u
"TOC2"_ustr
},
337 { u
"toc 3", u
"TOC3"_ustr
},
338 { u
"toc 4", u
"TOC4"_ustr
},
339 { u
"toc 5", u
"TOC5"_ustr
},
340 { u
"toc 6", u
"TOC6"_ustr
},
341 { u
"toc 7", u
"TOC7"_ustr
},
342 { u
"toc 8", u
"TOC8"_ustr
},
343 { u
"toc 9", u
"TOC9"_ustr
},
344 { u
"footnote text", u
"FootnoteText"_ustr
},
345 { u
"annotation text", u
"CommentText"_ustr
},
346 { u
"header", u
"Header"_ustr
},
347 { u
"footer", u
"Footer"_ustr
},
348 { u
"index heading", u
"IndexHeading"_ustr
},
349 { u
"caption", u
"Caption"_ustr
},
350 { u
"table of figures", u
"TableofFigures"_ustr
},
351 { u
"envelope address", u
"EnvelopeAddress"_ustr
},
352 { u
"envelope return", u
"EnvelopeReturn"_ustr
},
353 { u
"footnote reference", u
"FootnoteReference"_ustr
},
354 { u
"annotation reference", u
"CommentReference"_ustr
},
355 { u
"line number", u
"LineNumber"_ustr
},
356 { u
"page number", u
"PageNumber"_ustr
},
357 { u
"endnote reference", u
"EndnoteReference"_ustr
},
358 { u
"endnote text", u
"EndnoteText"_ustr
},
359 { u
"table of authorities", u
"TableofAuthorities"_ustr
},
360 { u
"macro", u
"MacroText"_ustr
},
362 for (const auto& [stiName
, id
] : specialCases
)
363 if (aName
== stiName
)
366 OUStringBuffer
aStyleIdBuf(aName
.size());
367 for (size_t i
= 0; i
< aName
.size(); ++i
)
369 sal_Unicode nChar
= aName
[i
];
370 if (rtl::isAsciiAlphanumeric(nChar
) || nChar
== '-')
372 // do not uppercase first letter
373 aStyleIdBuf
.append(char(nChar
));
376 return aStyleIdBuf
.makeStringAndClear();
379 std::u16string_view
findQuotedText( std::u16string_view rCommand
,
380 std::u16string_view sStartQuote
, const sal_Unicode uEndQuote
)
382 std::u16string_view sRet
;
383 size_t nStartIndex
= rCommand
.find( sStartQuote
);
384 if( nStartIndex
!= std::u16string_view::npos
)
386 sal_Int32 nStartLength
= sStartQuote
.size();
387 size_t nEndIndex
= rCommand
.find( uEndQuote
, nStartIndex
+ nStartLength
);
388 if( nEndIndex
!= std::u16string_view::npos
&& nEndIndex
> nStartIndex
)
390 sRet
= rCommand
.substr( nStartIndex
+ nStartLength
, nEndIndex
- nStartIndex
- nStartLength
);
397 WW8ReadFieldParams::WW8ReadFieldParams( OUString _aData
)
398 : aData(std::move( _aData
))
405 First look for an opening bracket or a space or a question mark or a backslash, so that the field (i.e. INCLUDEPICTURE or EINFUEGENGRAFIK or...) gets read over
407 const sal_Int32 nLen
= aData
.getLength();
409 while ( nNext
<nLen
&& aData
[nNext
]==' ' )
414 const sal_Unicode c
= aData
[nNext
];
415 if ( c
==' ' || c
=='"' || c
=='\\' || c
==132 || c
==0x201c )
424 OUString
WW8ReadFieldParams::GetResult() const
426 if (nFnd
<0 && nSavPtr
>nFnd
)
430 return nSavPtr
< nFnd
? aData
.copy(nFnd
) : aData
.copy(nFnd
, nSavPtr
-nFnd
);
435 bool WW8ReadFieldParams::GoToTokenParam()
437 const sal_Int32 nOld
= nNext
;
438 if( -2 == SkipToNextToken() )
439 return GetTokenSttPtr()>=0;
444 // ret: -2: NOT a '\' parameter but normal text
445 sal_Int32
WW8ReadFieldParams::SkipToNextToken()
447 if ( nNext
<0 || nNext
>=aData
.getLength() )
450 nFnd
= FindNextStringPiece(nNext
);
456 if (nFnd
+1<aData
.getLength() && aData
[nFnd
+1]!='\\' && aData
[nFnd
]=='\\')
458 const sal_Int32 nRet
= aData
[++nFnd
];
459 nNext
= ++nFnd
; // and set after
463 if ( nSavPtr
>0 && (aData
[nSavPtr
-1]=='"' || aData
[nSavPtr
-1]==0x201d ) )
470 // FindNextPara searches the next backslash parameter or the next string
471 // until the next blank or "\" or closing quotation mark
472 // or the end of the string of pStr.
474 // Output ppNext (if ppNext != 0) search begin of next parameter resp. 0
476 // Return value: 0 if end of string reached,
477 // otherwise beginning of the parameter resp. string
479 sal_Int32
WW8ReadFieldParams::FindNextStringPiece(const sal_Int32 nStart
)
481 const sal_Int32 nLen
= aData
.getLength();
482 sal_Int32 n
= nStart
<0 ? nFnd
: nStart
; // start
485 nNext
= -1; // if not found -> Default
487 while ( n
<nLen
&& aData
[n
]==' ' )
493 if ( aData
[n
]==0x13 )
495 // Skip the nested field code since it's not supported
496 while ( n
<nLen
&& aData
[n
]!=0x14 )
502 // quotation marks before paragraph?
503 if ( aData
[n
]=='"' || aData
[n
]==0x201c || aData
[n
]==132 || aData
[n
]==0x14 )
505 n
++; // read over quotation marks
506 n2
= n
; // search for the end from here on
508 && (aData
[n2
] != '"')
509 && (aData
[n2
] != 0x201d)
510 && (aData
[n2
] != 147)
511 && (aData
[n2
] != 0x15) )
512 n2
++; // search for the end of the paragraph
514 else // no quotation mark
516 n2
= n
; // search for the end from here on
517 while ( n2
<nLen
&& aData
[n2
]!=' ' ) // search for the end of the paragraph
519 if ( aData
[n2
]=='\\' )
521 if ( n2
+1<nLen
&& aData
[n2
+1]=='\\' )
522 n2
+= 2; // double backslash -> OK
527 break; // single backslash -> end
531 n2
++; // no backslash -> OK
536 if (aData
[n2
]!=' ') ++n2
;
543 // read parameters "1-3" or 1-3 with both values between 1 and nMax
544 bool WW8ReadFieldParams::GetTokenSttFromTo(sal_Int32
* pFrom
, sal_Int32
* pTo
, sal_Int32 nMax
)
546 sal_Int32 nStart
= 0;
548 if ( GoToTokenParam() )
551 const OUString
sParams( GetResult() );
553 sal_Int32 nIndex
= 0;
554 const std::u16string_view sStart
= o3tl::getToken(sParams
, 0, '-', nIndex
);
557 nStart
= o3tl::toInt32(sStart
);
558 nEnd
= o3tl::toInt32(sParams
.subView(nIndex
));
561 if( pFrom
) *pFrom
= nStart
;
562 if( pTo
) *pTo
= nEnd
;
564 return nStart
&& nEnd
&& (nMax
>= nStart
) && (nMax
>= nEnd
);
567 static EquationResult
Read_SubF_Combined(WW8ReadFieldParams
& rReadParam
)
569 EquationResult aResult
;
571 OUString sCombinedCharacters
;
572 WW8ReadFieldParams aOriFldParam
= rReadParam
;
573 const sal_Int32 cGetChar
= rReadParam
.SkipToNextToken();
578 if ( !rReadParam
.GetResult().startsWithIgnoreAsciiCase("d") )
582 (void)rReadParam
.SkipToNextToken();
586 if ( rReadParam
.GetResult().startsWithIgnoreAsciiCase("(") )
588 for (int i
=0;i
<2;i
++)
590 if ('s' == rReadParam
.SkipToNextToken())
592 const sal_Int32 cChar
= rReadParam
.SkipToNextToken();
593 if (-2 != rReadParam
.SkipToNextToken())
595 const OUString sF
= rReadParam
.GetResult();
596 if ((('u' == cChar
) && sF
.startsWithIgnoreAsciiCase("p"))
597 || (('d' == cChar
) && sF
.startsWithIgnoreAsciiCase("o")))
599 if (-2 == rReadParam
.SkipToNextToken())
601 OUString sPart
= rReadParam
.GetResult();
602 sal_Int32 nBegin
= sPart
.indexOf('(');
604 // Word disallows brackets in this field, which
605 // aids figuring out the case of an end of )) vs )
606 sal_Int32 nEnd
= sPart
.indexOf(')');
608 if (nBegin
!= -1 && nEnd
!= -1)
610 sCombinedCharacters
+=
611 sPart
.subView(nBegin
+1,nEnd
-nBegin
-1);
617 if (!sCombinedCharacters
.isEmpty())
619 aResult
.sType
= "CombinedCharacters";
620 aResult
.sResult
= sCombinedCharacters
;
624 const OUString sPart
= aOriFldParam
.GetResult();
625 sal_Int32 nBegin
= sPart
.indexOf('(');
626 sal_Int32 nEnd
= sPart
.indexOf(',');
629 nEnd
= sPart
.indexOf(')');
631 if ( nBegin
!= -1 && nEnd
!= -1 )
633 // skip certain leading characters
634 for (int i
= nBegin
;i
< nEnd
-1;i
++)
636 const sal_Unicode cC
= sPart
[nBegin
+1];
644 sCombinedCharacters
= sPart
.copy( nBegin
+1, nEnd
-nBegin
-1 );
645 if ( !sCombinedCharacters
.isEmpty() )
647 aResult
.sType
= "Input";
648 aResult
.sResult
= sCombinedCharacters
;
661 EquationResult
ParseCombinedChars(const OUString
& rStr
)
663 EquationResult aResult
;
664 WW8ReadFieldParams
aReadParam( rStr
);
665 const sal_Int32 cChar
= aReadParam
.SkipToNextToken();
666 if ('o' == cChar
|| 'O' == cChar
)
667 aResult
= Read_SubF_Combined(aReadParam
);
671 OString
GetOOXMLPresetGeometry( std::u16string_view rShapeType
)
673 typedef std::unordered_map
<std::u16string_view
, OString
> CustomShapeTypeTranslationHashMap
;
674 static const CustomShapeTypeTranslationHashMap aCustomShapeTypeTranslationHashMap
{
675 // { "non-primitive", mso_sptMin },
676 { u
"frame", "frame" },
677 { u
"rectangle", "rect" },
678 { u
"round-rectangle", "roundRect" },
679 { u
"ellipse", "ellipse" },
680 { u
"diamond", "diamond" },
681 { u
"isosceles-triangle", "triangle" },
682 { u
"right-triangle", "rtTriangle" },
683 { u
"parallelogram", "parallelogram" },
684 { u
"trapezoid", "trapezoid" },
685 { u
"hexagon", "hexagon" },
686 { u
"octagon", "octagon" },
687 { u
"cross", "plus" },
688 { u
"star5", "star5" },
689 { u
"right-arrow", "rightArrow" },
690 // { u"mso-spt14", mso_sptThickArrow },
691 { u
"pentagon-right", "homePlate" },
693 // { u"mso-spt17", mso_sptBalloon },
694 // { u"mso-spt18", mso_sptSeal },
695 { u
"mso-spt19", "arc" },
696 { u
"mso-spt20", "line" },
697 { u
"mso-spt21", "plaque" },
699 { u
"ring", "donut" },
700 { u
"mso-spt24", "textPlain" },
701 { u
"mso-spt25", "textStop" },
702 { u
"mso-spt26", "textTriangle" },
703 { u
"mso-spt27", "textCanDown" },
704 { u
"mso-spt28", "textWave1" },
705 { u
"mso-spt29", "textArchUpPour" },
706 { u
"mso-spt30", "textCanDown" },
707 { u
"mso-spt31", "textArchUp" },
708 { u
"mso-spt32", "straightConnector1" },
709 { u
"mso-spt33", "bentConnector2" },
710 { u
"mso-spt34", "bentConnector3" },
711 { u
"mso-spt35", "bentConnector4" },
712 { u
"mso-spt36", "bentConnector5" },
713 { u
"mso-spt37", "curvedConnector2" },
714 { u
"mso-spt38", "curvedConnector3" },
715 { u
"mso-spt39", "curvedConnector4" },
716 { u
"mso-spt40", "curvedConnector5" },
717 { u
"mso-spt41", "callout1" },
718 { u
"mso-spt42", "callout2" },
719 { u
"mso-spt43", "callout3" },
720 { u
"mso-spt44", "accentCallout1" },
721 { u
"mso-spt45", "accentCallout2" },
722 { u
"mso-spt46", "accentCallout3" },
723 { u
"line-callout-1", "borderCallout1" },
724 { u
"line-callout-2", "borderCallout2" },
725 { u
"line-callout-3", "borderCallout3" },
726 { u
"mso-spt49", "borderCallout3" },
727 { u
"mso-spt50", "accentBorderCallout1" },
728 { u
"mso-spt51", "accentBorderCallout2" },
729 { u
"mso-spt52", "accentBorderCallout3" },
730 { u
"mso-spt53", "ribbon" },
731 { u
"mso-spt54", "ribbon2" },
732 { u
"chevron", "chevron" },
733 { u
"pentagon", "pentagon" },
734 { u
"forbidden", "noSmoking" },
735 { u
"star8", "star8" },
736 { u
"mso-spt59", "star16" },
737 { u
"mso-spt60", "star32" },
738 { u
"rectangular-callout", "wedgeRectCallout" },
739 { u
"round-rectangular-callout", "wedgeRoundRectCallout" },
740 { u
"round-callout", "wedgeEllipseCallout" },
741 { u
"mso-spt64", "wave" },
742 { u
"paper", "foldedCorner" },
743 { u
"left-arrow", "leftArrow" },
744 { u
"down-arrow", "downArrow" },
745 { u
"up-arrow", "upArrow" },
746 { u
"left-right-arrow", "leftRightArrow" },
747 { u
"up-down-arrow", "upDownArrow" },
748 { u
"mso-spt71", "irregularSeal1" },
749 { u
"bang", "irregularSeal2" },
750 { u
"lightning", "lightningBolt" },
751 { u
"heart", "heart" },
752 { u
"quad-arrow", "quadArrow" },
753 { u
"left-arrow-callout", "leftArrowCallout" },
754 { u
"right-arrow-callout", "rightArrowCallout" },
755 { u
"up-arrow-callout", "upArrowCallout" },
756 { u
"down-arrow-callout", "downArrowCallout" },
757 { u
"left-right-arrow-callout", "leftRightArrowCallout" },
758 { u
"up-down-arrow-callout", "upDownArrowCallout" },
759 { u
"quad-arrow-callout", "quadArrowCallout" },
760 { u
"quad-bevel", "bevel" },
761 { u
"left-bracket", "leftBracket" },
762 { u
"right-bracket", "rightBracket" },
763 { u
"left-brace", "leftBrace" },
764 { u
"right-brace", "rightBrace" },
765 { u
"mso-spt89", "leftUpArrow" },
766 { u
"mso-spt90", "bentUpArrow" },
767 { u
"mso-spt91", "bentArrow" },
768 { u
"star24", "star24" },
769 { u
"striped-right-arrow", "stripedRightArrow" },
770 { u
"notched-right-arrow", "notchedRightArrow" },
771 { u
"block-arc", "blockArc" },
772 { u
"smiley", "smileyFace" },
773 { u
"vertical-scroll", "verticalScroll" },
774 { u
"horizontal-scroll", "horizontalScroll" },
775 { u
"circular-arrow", "circularArrow" },
776 { u
"mso-spt100", "pie" }, // looks like MSO_SPT is wrong here
777 { u
"mso-spt101", "uturnArrow" },
778 { u
"mso-spt102", "curvedRightArrow" },
779 { u
"mso-spt103", "curvedLeftArrow" },
780 { u
"mso-spt104", "curvedUpArrow" },
781 { u
"mso-spt105", "curvedDownArrow" },
782 { u
"cloud-callout", "cloudCallout" },
783 { u
"mso-spt107", "ellipseRibbon" },
784 { u
"mso-spt108", "ellipseRibbon2" },
785 { u
"flowchart-process", "flowChartProcess" },
786 { u
"flowchart-decision", "flowChartDecision" },
787 { u
"flowchart-data", "flowChartInputOutput" },
788 { u
"flowchart-predefined-process", "flowChartPredefinedProcess" },
789 { u
"flowchart-internal-storage", "flowChartInternalStorage" },
790 { u
"flowchart-document", "flowChartDocument" },
791 { u
"flowchart-multidocument", "flowChartMultidocument" },
792 { u
"flowchart-terminator", "flowChartTerminator" },
793 { u
"flowchart-preparation", "flowChartPreparation" },
794 { u
"flowchart-manual-input", "flowChartManualInput" },
795 { u
"flowchart-manual-operation", "flowChartManualOperation" },
796 { u
"flowchart-connector", "flowChartConnector" },
797 { u
"flowchart-card", "flowChartPunchedCard" },
798 { u
"flowchart-punched-tape", "flowChartPunchedTape" },
799 { u
"flowchart-summing-junction", "flowChartSummingJunction" },
800 { u
"flowchart-or", "flowChartOr" },
801 { u
"flowchart-collate", "flowChartCollate" },
802 { u
"flowchart-sort", "flowChartSort" },
803 { u
"flowchart-extract", "flowChartExtract" },
804 { u
"flowchart-merge", "flowChartMerge" },
805 { u
"mso-spt129", "flowChartOfflineStorage" },
806 { u
"flowchart-stored-data", "flowChartOnlineStorage" },
807 { u
"flowchart-sequential-access", "flowChartMagneticTape" },
808 { u
"flowchart-magnetic-disk", "flowChartMagneticDisk" },
809 { u
"flowchart-direct-access-storage", "flowChartMagneticDrum" },
810 { u
"flowchart-display", "flowChartDisplay" },
811 { u
"flowchart-delay", "flowChartDelay" },
812 // { u"fontwork-plain-text", "textPlainText" },
813 // { u"fontwork-stop", "textStop" },
814 // { u"fontwork-triangle-up", "textTriangle" },
815 // { u"fontwork-triangle-down", "textTriangleInverted" },
816 // { u"fontwork-chevron-up", "textChevron" },
817 // { u"fontwork-chevron-down", "textChevronInverted" },
818 // { u"mso-spt142", "textRingInside" },
819 // { u"mso-spt143", "textRingOutside" },
820 // { u"fontwork-arch-up-curve", "textArchUpCurve" },
821 // { u"fontwork-arch-down-curve", "textArchDownCurve" },
822 // { u"fontwork-circle-curve", "textCircleCurve" },
823 // { u"fontwork-open-circle-curve", "textButtonCurve" },
824 // { u"fontwork-arch-up-pour", "textArchUpPour" },
825 // { u"fontwork-arch-down-pour", "textArchDownPour" },
826 // { u"fontwork-circle-pour", "textCirclePour" },
827 // { u"fontwork-open-circle-pour", "textButtonPour" },
828 // { u"fontwork-curve-up", "textCurveUp" },
829 // { u"fontwork-curve-down", "textCurveDown" },
830 // { u"fontwork-fade-up-and-right", "textCascadeUp" },
831 // { u"fontwork-fade-up-and-left", "textCascadeDown" },
832 // { u"fontwork-wave", "textWave1" },
833 // { u"mso-spt157", "textWave2" },
834 // { u"mso-spt158", "textWave3" },
835 // { u"mso-spt159", "textWave4" },
836 // { u"fontwork-inflate", "textInflate" },
837 // { u"mso-spt161", "textDeflate" },
838 // { u"mso-spt162", "textInflateBottom" },
839 // { u"mso-spt163", "textDeflateBottom" },
840 // { u"mso-spt164", "textInflateTop" },
841 // { u"mso-spt165", "textDeflateTop" },
842 // { u"mso-spt166", "textDeflateInflate" },
843 // { u"mso-spt167", "textDeflateInflateDeflate" },
844 // { u"fontwork-fade-right", "textFadeRight" },
845 // { u"fontwork-fade-left", "textFadeLeft" },
846 // { u"fontwork-fade-up", "textFadeUp" },
847 // { u"fontwork-fade-down", "textFadeDown" },
848 // { u"fontwork-slant-up", "textSlantUp" },
849 // { u"fontwork-slant-down", "textSlantDown" },
850 // { u"mso-spt174", "textCanUp" },
851 // { u"mso-spt175", "textCanDown" },
852 { u
"flowchart-alternate-process", "flowChartAlternateProcess" },
853 { u
"flowchart-off-page-connector", "flowChartOffpageConnector" },
854 { u
"mso-spt178", "callout1" },
855 { u
"mso-spt179", "accentCallout1" },
856 { u
"mso-spt180", "borderCallout1" },
857 { u
"mso-spt182", "leftRightUpArrow" },
860 { u
"bracket-pair", "bracketPair" },
861 { u
"brace-pair", "bracePair" },
862 { u
"star4", "star4" },
863 { u
"mso-spt188", "doubleWave" },
864 { u
"mso-spt189", "actionButtonBlank" },
865 { u
"mso-spt190", "actionButtonHome" },
866 { u
"mso-spt191", "actionButtonHelp" },
867 { u
"mso-spt192", "actionButtonInformation" },
868 { u
"mso-spt193", "actionButtonForwardNext" },
869 { u
"mso-spt194", "actionButtonBackPrevious" },
870 { u
"mso-spt195", "actionButtonEnd" },
871 { u
"mso-spt196", "actionButtonBeginning" },
872 { u
"mso-spt197", "actionButtonReturn" },
873 { u
"mso-spt198", "actionButtonDocument" },
874 { u
"mso-spt199", "actionButtonSound" },
875 { u
"mso-spt200", "actionButtonMovie" },
876 // { u"mso-spt201", "hostControl" },
877 { u
"mso-spt202", "rect" },
878 { u
"ooxml-actionButtonSound", "actionButtonSound" },
879 { u
"ooxml-borderCallout1", "borderCallout1" },
880 { u
"ooxml-plaqueTabs", "plaqueTabs" },
881 { u
"ooxml-curvedLeftArrow", "curvedLeftArrow" },
882 { u
"ooxml-octagon", "octagon" },
883 { u
"ooxml-leftRightRibbon", "leftRightRibbon" },
884 { u
"ooxml-actionButtonInformation", "actionButtonInformation" },
885 { u
"ooxml-bentConnector5", "bentConnector5" },
886 { u
"ooxml-circularArrow", "circularArrow" },
887 { u
"ooxml-downArrowCallout", "downArrowCallout" },
888 { u
"ooxml-mathMinus", "mathMinus" },
889 { u
"ooxml-gear9", "gear9" },
890 { u
"ooxml-round1Rect", "round1Rect" },
891 { u
"ooxml-sun", "sun" },
892 { u
"ooxml-plaque", "plaque" },
893 { u
"ooxml-chevron", "chevron" },
894 { u
"ooxml-flowChartPreparation", "flowChartPreparation" },
895 { u
"ooxml-diagStripe", "diagStripe" },
896 { u
"ooxml-pentagon", "pentagon" },
897 { u
"ooxml-funnel", "funnel" },
898 { u
"ooxml-chartStar", "chartStar" },
899 { u
"ooxml-accentBorderCallout1", "accentBorderCallout1" },
900 { u
"ooxml-notchedRightArrow", "notchedRightArrow" },
901 { u
"ooxml-rightBracket", "rightBracket" },
902 { u
"ooxml-flowChartOffpageConnector", "flowChartOffpageConnector" },
903 { u
"ooxml-leftRightArrow", "leftRightArrow" },
904 { u
"ooxml-decagon", "decagon" },
905 { u
"ooxml-actionButtonHelp", "actionButtonHelp" },
906 { u
"ooxml-star24", "star24" },
907 { u
"ooxml-mathDivide", "mathDivide" },
908 { u
"ooxml-curvedConnector4", "curvedConnector4" },
909 { u
"ooxml-flowChartOr", "flowChartOr" },
910 { u
"ooxml-borderCallout3", "borderCallout3" },
911 { u
"ooxml-upDownArrowCallout", "upDownArrowCallout" },
912 { u
"ooxml-flowChartDecision", "flowChartDecision" },
913 { u
"ooxml-leftRightArrowCallout", "leftRightArrowCallout" },
914 { u
"ooxml-flowChartManualOperation", "flowChartManualOperation" },
915 { u
"ooxml-snipRoundRect", "snipRoundRect" },
916 { u
"ooxml-mathPlus", "mathPlus" },
917 { u
"ooxml-actionButtonForwardNext", "actionButtonForwardNext" },
918 { u
"ooxml-can", "can" },
919 { u
"ooxml-foldedCorner", "foldedCorner" },
920 { u
"ooxml-star32", "star32" },
921 { u
"ooxml-flowChartInternalStorage", "flowChartInternalStorage" },
922 { u
"ooxml-upDownArrow", "upDownArrow" },
923 { u
"ooxml-irregularSeal2", "irregularSeal2" },
924 { u
"ooxml-mathEqual", "mathEqual" },
925 { u
"ooxml-star12", "star12" },
926 { u
"ooxml-uturnArrow", "uturnArrow" },
927 { u
"ooxml-squareTabs", "squareTabs" },
928 { u
"ooxml-leftRightUpArrow", "leftRightUpArrow" },
929 { u
"ooxml-homePlate", "homePlate" },
930 { u
"ooxml-dodecagon", "dodecagon" },
931 { u
"ooxml-leftArrowCallout", "leftArrowCallout" },
932 { u
"ooxml-chord", "chord" },
933 { u
"ooxml-quadArrowCallout", "quadArrowCallout" },
934 { u
"ooxml-actionButtonBeginning", "actionButtonBeginning" },
935 { u
"ooxml-ellipse", "ellipse" },
936 { u
"ooxml-actionButtonEnd", "actionButtonEnd" },
937 { u
"ooxml-arc", "arc" },
938 { u
"ooxml-star16", "star16" },
939 { u
"ooxml-parallelogram", "parallelogram" },
940 { u
"ooxml-bevel", "bevel" },
941 { u
"ooxml-roundRect", "roundRect" },
942 { u
"ooxml-accentCallout1", "accentCallout1" },
943 { u
"ooxml-flowChartSort", "flowChartSort" },
944 { u
"ooxml-star8", "star8" },
945 { u
"ooxml-flowChartAlternateProcess", "flowChartAlternateProcess" },
946 { u
"ooxml-moon", "moon" },
947 { u
"ooxml-star6", "star6" },
948 { u
"ooxml-round2SameRect", "round2SameRect" },
949 { u
"ooxml-nonIsoscelesTrapezoid", "nonIsoscelesTrapezoid" },
950 { u
"ooxml-diamond", "diamond" },
951 { u
"ooxml-ellipseRibbon", "ellipseRibbon" },
952 { u
"ooxml-callout2", "callout2" },
953 { u
"ooxml-pie", "pie" },
954 { u
"ooxml-star4", "star4" },
955 { u
"ooxml-flowChartPredefinedProcess", "flowChartPredefinedProcess" },
956 { u
"ooxml-flowChartPunchedTape", "flowChartPunchedTape" },
957 { u
"ooxml-curvedConnector2", "curvedConnector2" },
958 { u
"ooxml-bentConnector3", "bentConnector3" },
959 { u
"ooxml-cornerTabs", "cornerTabs" },
960 { u
"ooxml-hexagon", "hexagon" },
961 { u
"ooxml-flowChartConnector", "flowChartConnector" },
962 { u
"ooxml-flowChartMagneticDisk", "flowChartMagneticDisk" },
963 { u
"ooxml-heart", "heart" },
964 { u
"ooxml-ribbon2", "ribbon2" },
965 { u
"ooxml-bracePair", "bracePair" },
966 { u
"ooxml-flowChartExtract", "flowChartExtract" },
967 { u
"ooxml-actionButtonHome", "actionButtonHome" },
968 { u
"ooxml-accentBorderCallout3", "accentBorderCallout3" },
969 { u
"ooxml-flowChartOfflineStorage", "flowChartOfflineStorage" },
970 { u
"ooxml-irregularSeal1", "irregularSeal1" },
971 { u
"ooxml-quadArrow", "quadArrow" },
972 { u
"ooxml-leftBrace", "leftBrace" },
973 { u
"ooxml-leftBracket", "leftBracket" },
974 { u
"ooxml-blockArc", "blockArc" },
975 { u
"ooxml-curvedConnector3", "curvedConnector3" },
976 { u
"ooxml-wedgeRoundRectCallout", "wedgeRoundRectCallout" },
977 { u
"ooxml-actionButtonMovie", "actionButtonMovie" },
978 { u
"ooxml-flowChartOnlineStorage", "flowChartOnlineStorage" },
979 { u
"ooxml-gear6", "gear6" },
980 { u
"ooxml-halfFrame", "halfFrame" },
981 { u
"ooxml-snip2SameRect", "snip2SameRect" },
982 { u
"ooxml-triangle", "triangle" },
983 { u
"ooxml-teardrop", "teardrop" },
984 { u
"ooxml-flowChartDocument", "flowChartDocument" },
985 { u
"ooxml-rightArrowCallout", "rightArrowCallout" },
986 { u
"ooxml-rightBrace", "rightBrace" },
987 { u
"ooxml-chartPlus", "chartPlus" },
988 { u
"ooxml-flowChartManualInput", "flowChartManualInput" },
989 { u
"ooxml-flowChartMerge", "flowChartMerge" },
990 { u
"ooxml-line", "line" },
991 { u
"ooxml-downArrow", "downArrow" },
992 { u
"ooxml-upArrow", "upArrow" },
993 { u
"ooxml-curvedDownArrow", "curvedDownArrow" },
994 { u
"ooxml-actionButtonReturn", "actionButtonReturn" },
995 { u
"ooxml-flowChartInputOutput", "flowChartInputOutput" },
996 { u
"ooxml-bracketPair", "bracketPair" },
997 { u
"ooxml-smileyFace", "smileyFace" },
998 { u
"ooxml-actionButtonBlank", "actionButtonBlank" },
999 { u
"ooxml-wave", "wave" },
1000 { u
"ooxml-swooshArrow", "swooshArrow" },
1001 { u
"ooxml-flowChartSummingJunction", "flowChartSummingJunction" },
1002 { u
"ooxml-lightningBolt", "lightningBolt" },
1003 { u
"ooxml-flowChartDisplay", "flowChartDisplay" },
1004 { u
"ooxml-actionButtonBackPrevious", "actionButtonBackPrevious" },
1005 { u
"ooxml-frame", "frame" },
1006 { u
"ooxml-rtTriangle", "rtTriangle" },
1007 { u
"ooxml-flowChartMagneticTape", "flowChartMagneticTape" },
1008 { u
"ooxml-curvedRightArrow", "curvedRightArrow" },
1009 { u
"ooxml-leftUpArrow", "leftUpArrow" },
1010 { u
"ooxml-wedgeEllipseCallout", "wedgeEllipseCallout" },
1011 { u
"ooxml-doubleWave", "doubleWave" },
1012 { u
"ooxml-bentArrow", "bentArrow" },
1013 { u
"ooxml-star10", "star10" },
1014 { u
"ooxml-leftArrow", "leftArrow" },
1015 { u
"ooxml-curvedUpArrow", "curvedUpArrow" },
1016 { u
"ooxml-snip1Rect", "snip1Rect" },
1017 { u
"ooxml-ellipseRibbon2", "ellipseRibbon2" },
1018 { u
"ooxml-plus", "plus" },
1019 { u
"ooxml-accentCallout3", "accentCallout3" },
1020 { u
"ooxml-leftCircularArrow", "leftCircularArrow" },
1021 { u
"ooxml-rightArrow", "rightArrow" },
1022 { u
"ooxml-flowChartPunchedCard", "flowChartPunchedCard" },
1023 { u
"ooxml-snip2DiagRect", "snip2DiagRect" },
1024 { u
"ooxml-verticalScroll", "verticalScroll" },
1025 { u
"ooxml-star7", "star7" },
1026 { u
"ooxml-chartX", "chartX" },
1027 { u
"ooxml-cloud", "cloud" },
1028 { u
"ooxml-cube", "cube" },
1029 { u
"ooxml-round2DiagRect", "round2DiagRect" },
1030 { u
"ooxml-flowChartMultidocument", "flowChartMultidocument" },
1031 { u
"ooxml-actionButtonDocument", "actionButtonDocument" },
1032 { u
"ooxml-flowChartTerminator", "flowChartTerminator" },
1033 { u
"ooxml-flowChartDelay", "flowChartDelay" },
1034 { u
"ooxml-curvedConnector5", "curvedConnector5" },
1035 { u
"ooxml-horizontalScroll", "horizontalScroll" },
1036 { u
"ooxml-bentConnector4", "bentConnector4" },
1037 { u
"ooxml-leftRightCircularArrow", "leftRightCircularArrow" },
1038 { u
"ooxml-wedgeRectCallout", "wedgeRectCallout" },
1039 { u
"ooxml-accentCallout2", "accentCallout2" },
1040 { u
"ooxml-flowChartMagneticDrum", "flowChartMagneticDrum" },
1041 { u
"ooxml-corner", "corner" },
1042 { u
"ooxml-borderCallout2", "borderCallout2" },
1043 { u
"ooxml-donut", "donut" },
1044 { u
"ooxml-flowChartCollate", "flowChartCollate" },
1045 { u
"ooxml-mathNotEqual", "mathNotEqual" },
1046 { u
"ooxml-bentConnector2", "bentConnector2" },
1047 { u
"ooxml-mathMultiply", "mathMultiply" },
1048 { u
"ooxml-heptagon", "heptagon" },
1049 { u
"ooxml-rect", "rect" },
1050 { u
"ooxml-accentBorderCallout2", "accentBorderCallout2" },
1051 { u
"ooxml-pieWedge", "pieWedge" },
1052 { u
"ooxml-upArrowCallout", "upArrowCallout" },
1053 { u
"ooxml-flowChartProcess", "flowChartProcess" },
1054 { u
"ooxml-star5", "star5" },
1055 { u
"ooxml-lineInv", "lineInv" },
1056 { u
"ooxml-straightConnector1", "straightConnector1" },
1057 { u
"ooxml-stripedRightArrow", "stripedRightArrow" },
1058 { u
"ooxml-callout3", "callout3" },
1059 { u
"ooxml-bentUpArrow", "bentUpArrow" },
1060 { u
"ooxml-noSmoking", "noSmoking" },
1061 { u
"ooxml-trapezoid", "trapezoid" },
1062 { u
"ooxml-cloudCallout", "cloudCallout" },
1063 { u
"ooxml-callout1", "callout1" },
1064 { u
"ooxml-ribbon", "ribbon" },
1066 auto i(aCustomShapeTypeTranslationHashMap
.find(rShapeType
));
1067 return i
== aCustomShapeTypeTranslationHashMap
.end() ? "rect"_ostr
: i
->second
;
1070 MSO_SPT
GETVMLShapeType(std::u16string_view aType
)
1072 typedef std::unordered_map
<std::string_view
, MSO_SPT
> DMLToVMLTranslationHashMap
;
1073 static const DMLToVMLTranslationHashMap aDMLToVMLMap
{
1074 {"notPrimitive", mso_sptNotPrimitive
},
1075 {"rectangle", mso_sptRectangle
},
1076 {"roundRectangle", mso_sptRoundRectangle
},
1077 {"ellipse", mso_sptEllipse
},
1078 {"diamond", mso_sptDiamond
},
1079 {"triangle", mso_sptIsocelesTriangle
},
1080 {"rtTriangle", mso_sptRightTriangle
},
1081 {"parallelogram", mso_sptParallelogram
},
1082 {"trapezoid", mso_sptTrapezoid
},
1083 {"hexagon", mso_sptHexagon
},
1084 {"octagon", mso_sptOctagon
},
1085 {"plus", mso_sptPlus
},
1086 {"star5", mso_sptStar
},
1087 {"rightArrow", mso_sptArrow
},
1088 {"thickArrow", mso_sptThickArrow
},
1089 {"homePlate", mso_sptHomePlate
},
1090 {"cube", mso_sptCube
},
1091 {"wedgeRoundRectCallout", mso_sptBalloon
},
1092 {"star16", mso_sptSeal
},
1093 {"arc", mso_sptArc
},
1094 {"line", mso_sptLine
},
1095 {"plaque", mso_sptPlaque
},
1096 {"can", mso_sptCan
},
1097 {"donut", mso_sptDonut
},
1098 {"textPlain", mso_sptTextSimple
},
1099 {"textStop", mso_sptTextOctagon
},
1100 {"textTriangle", mso_sptTextHexagon
},
1101 {"textCanDown", mso_sptTextCurve
},
1102 {"textWave1", mso_sptTextWave
},
1103 {"textArchUpPour", mso_sptTextRing
},
1104 {"textCanDown", mso_sptTextOnCurve
},
1105 {"textArchUp", mso_sptTextOnRing
},
1106 {"straightConnector1", mso_sptStraightConnector1
},
1107 {"bentConnector2", mso_sptBentConnector2
},
1108 {"bentConnector3", mso_sptBentConnector3
},
1109 {"bentConnector4", mso_sptBentConnector4
},
1110 {"bentConnector5", mso_sptBentConnector5
},
1111 {"curvedConnector2", mso_sptCurvedConnector2
},
1112 {"curvedConnector3", mso_sptCurvedConnector3
},
1113 {"curvedConnector4", mso_sptCurvedConnector4
},
1114 {"curvedConnector5", mso_sptCurvedConnector5
},
1115 {"callout1", mso_sptCallout1
},
1116 {"callout2", mso_sptCallout2
},
1117 {"callout3", mso_sptCallout3
},
1118 {"accentCallout1", mso_sptAccentCallout1
},
1119 {"accentCallout2", mso_sptAccentCallout2
},
1120 {"accentCallout3", mso_sptAccentCallout3
},
1121 {"borderCallout1", mso_sptBorderCallout1
},
1122 {"borderCallout2", mso_sptBorderCallout2
},
1123 {"borderCallout3", mso_sptBorderCallout3
},
1124 {"accentBorderCallout1", mso_sptAccentBorderCallout1
},
1125 {"accentBorderCallout2", mso_sptAccentBorderCallout2
},
1126 {"accentBorderCallout3", mso_sptAccentBorderCallout3
},
1127 {"ribbon", mso_sptRibbon
},
1128 {"ribbon2", mso_sptRibbon2
},
1129 {"chevron", mso_sptChevron
},
1130 {"pentagon", mso_sptPentagon
},
1131 {"noSmoking", mso_sptNoSmoking
},
1132 {"star8", mso_sptSeal8
},
1133 {"star16", mso_sptSeal16
},
1134 {"star32", mso_sptSeal32
},
1135 {"wedgeRectCallout", mso_sptWedgeRectCallout
},
1136 {"wedgeRoundRectCallout", mso_sptWedgeRRectCallout
},
1137 {"wedgeEllipseCallout", mso_sptWedgeEllipseCallout
},
1138 {"wave", mso_sptWave
},
1139 {"foldedCorner", mso_sptFoldedCorner
},
1140 {"leftArrow", mso_sptLeftArrow
},
1141 {"downArrow", mso_sptDownArrow
},
1142 {"upArrow", mso_sptUpArrow
},
1143 {"leftRightArrow", mso_sptLeftRightArrow
},
1144 {"upDownArrow", mso_sptUpDownArrow
},
1145 {"irregularSeal1", mso_sptIrregularSeal1
},
1146 {"irregularSeal2", mso_sptIrregularSeal2
},
1147 {"lightningBolt", mso_sptLightningBolt
},
1148 {"heart", mso_sptHeart
},
1149 {"pictureFrame", mso_sptPictureFrame
},
1150 {"quadArrow", mso_sptQuadArrow
},
1151 {"leftArrowCallout", mso_sptLeftArrowCallout
},
1152 {"rightArrowCallout", mso_sptRightArrowCallout
},
1153 {"upArrowCallout", mso_sptUpArrowCallout
},
1154 {"downArrowCallout", mso_sptDownArrowCallout
},
1155 {"leftRightArrowCallout", mso_sptLeftRightArrowCallout
},
1156 {"upDownArrowCallout", mso_sptUpDownArrowCallout
},
1157 {"quadArrowCallout", mso_sptQuadArrowCallout
},
1158 {"bevel", mso_sptBevel
},
1159 {"leftBracket", mso_sptLeftBracket
},
1160 {"rightBracket", mso_sptRightBracket
},
1161 {"leftBrace", mso_sptLeftBrace
},
1162 {"rightBrace", mso_sptRightBrace
},
1163 {"leftUpArrow", mso_sptLeftUpArrow
},
1164 {"bentUpArrow", mso_sptBentUpArrow
},
1165 {"bentArrow", mso_sptBentArrow
},
1166 {"star24", mso_sptSeal24
},
1167 {"stripedRightArrow", mso_sptStripedRightArrow
},
1168 {"notchedRightArrow", mso_sptNotchedRightArrow
},
1169 {"blockArc", mso_sptBlockArc
},
1170 {"smileyFace", mso_sptSmileyFace
},
1171 {"verticalScroll", mso_sptVerticalScroll
},
1172 {"horizontalScroll", mso_sptHorizontalScroll
},
1173 {"circularArrow", mso_sptCircularArrow
},
1174 {"notchedCircularArrow", mso_sptNotchedCircularArrow
},
1175 {"uturnArrow", mso_sptUturnArrow
},
1176 {"curvedRightArrow", mso_sptCurvedRightArrow
},
1177 {"curvedLeftArrow", mso_sptCurvedLeftArrow
},
1178 {"curvedUpArrow", mso_sptCurvedUpArrow
},
1179 {"curvedDownArrow", mso_sptCurvedDownArrow
},
1180 {"cloudCallout", mso_sptCloudCallout
},
1181 {"ellipseRibbon", mso_sptEllipseRibbon
},
1182 {"ellipseRibbon2", mso_sptEllipseRibbon2
},
1183 {"flowChartProcess", mso_sptFlowChartProcess
},
1184 {"flowChartDecision", mso_sptFlowChartDecision
},
1185 {"flowChartInputOutput", mso_sptFlowChartInputOutput
},
1186 {"flowChartPredefinedProcess", mso_sptFlowChartPredefinedProcess
},
1187 {"flowChartInternalStorage", mso_sptFlowChartInternalStorage
},
1188 {"flowChartDocument", mso_sptFlowChartDocument
},
1189 {"flowChartMultidocument", mso_sptFlowChartMultidocument
},
1190 {"flowChartTerminator", mso_sptFlowChartTerminator
},
1191 {"flowChartPreparation", mso_sptFlowChartPreparation
},
1192 {"flowChartManualInput", mso_sptFlowChartManualInput
},
1193 {"flowChartManualOperation", mso_sptFlowChartManualOperation
},
1194 {"flowChartConnector", mso_sptFlowChartConnector
},
1195 {"flowChartPunchedCard", mso_sptFlowChartPunchedCard
},
1196 {"flowChartPunchedTape", mso_sptFlowChartPunchedTape
},
1197 {"flowChartSummingJunction", mso_sptFlowChartSummingJunction
},
1198 {"flowChartOr", mso_sptFlowChartOr
},
1199 {"flowChartCollate", mso_sptFlowChartCollate
},
1200 {"flowChartSort", mso_sptFlowChartSort
},
1201 {"flowChartExtract", mso_sptFlowChartExtract
},
1202 {"flowChartMerge", mso_sptFlowChartMerge
},
1203 {"flowChartOfflineStorage", mso_sptFlowChartOfflineStorage
},
1204 {"flowChartOnlineStorage", mso_sptFlowChartOnlineStorage
},
1205 {"flowChartMagneticTape", mso_sptFlowChartMagneticTape
},
1206 {"flowChartMagneticDisk", mso_sptFlowChartMagneticDisk
},
1207 {"flowChartMagneticDrum", mso_sptFlowChartMagneticDrum
},
1208 {"flowChartDisplay", mso_sptFlowChartDisplay
},
1209 {"flowChartDelay", mso_sptFlowChartDelay
},
1210 {"textPlain", mso_sptTextPlainText
},
1211 {"textStop", mso_sptTextStop
},
1212 {"textTriangle", mso_sptTextTriangle
},
1213 {"textTriangleInverted", mso_sptTextTriangleInverted
},
1214 {"textChevron", mso_sptTextChevron
},
1215 {"textChevronInverted", mso_sptTextChevronInverted
},
1216 {"textRingInside", mso_sptTextRingInside
},
1217 {"textRingOutside", mso_sptTextRingOutside
},
1218 {"textArchUp", mso_sptTextArchUpCurve
},
1219 {"textArchDown", mso_sptTextArchDownCurve
},
1220 {"textCircle", mso_sptTextCircleCurve
},
1221 {"textButton", mso_sptTextButtonCurve
},
1222 {"textArchUpPour", mso_sptTextArchUpPour
},
1223 {"textArchDownPour", mso_sptTextArchDownPour
},
1224 {"textCirclePour", mso_sptTextCirclePour
},
1225 {"textButtonPour", mso_sptTextButtonPour
},
1226 {"textCurveUp", mso_sptTextCurveUp
},
1227 {"textCurveDown", mso_sptTextCurveDown
},
1228 {"textCascadeUp", mso_sptTextCascadeUp
},
1229 {"textCascadeDown", mso_sptTextCascadeDown
},
1230 {"textWave1", mso_sptTextWave1
},
1231 {"textWave2", mso_sptTextWave2
},
1232 {"textWave3", mso_sptTextWave3
},
1233 {"textWave4", mso_sptTextWave4
},
1234 {"textInflate", mso_sptTextInflate
},
1235 {"textDeflate", mso_sptTextDeflate
},
1236 {"textInflateBottom", mso_sptTextInflateBottom
},
1237 {"textDeflateBottom", mso_sptTextDeflateBottom
},
1238 {"textInflateTop", mso_sptTextInflateTop
},
1239 {"textDeflateTop", mso_sptTextDeflateTop
},
1240 {"textDeflateInflate", mso_sptTextDeflateInflate
},
1241 {"textDeflateInflateDeflate", mso_sptTextDeflateInflateDeflate
},
1242 {"textFadeRight", mso_sptTextFadeRight
},
1243 {"textFadeLeft", mso_sptTextFadeLeft
},
1244 {"textFadeUp", mso_sptTextFadeUp
},
1245 {"textFadeDown", mso_sptTextFadeDown
},
1246 {"textSlantUp", mso_sptTextSlantUp
},
1247 {"textSlantDown", mso_sptTextSlantDown
},
1248 {"textCanUp", mso_sptTextCanUp
},
1249 {"textCanDown", mso_sptTextCanDown
},
1250 {"flowChartAlternateProcess", mso_sptFlowChartAlternateProcess
},
1251 {"flowChartOffpageConnector", mso_sptFlowChartOffpageConnector
},
1252 {"callout1", mso_sptCallout90
},
1253 {"accentCallout1", mso_sptAccentCallout90
},
1254 {"borderCallout1", mso_sptBorderCallout90
},
1255 {"accentBorderCallout1", mso_sptAccentBorderCallout90
},
1256 {"leftRightUpArrow", mso_sptLeftRightUpArrow
},
1257 {"sun", mso_sptSun
},
1258 {"moon", mso_sptMoon
},
1259 {"bracketPair", mso_sptBracketPair
},
1260 {"bracePair", mso_sptBracePair
},
1261 {"star4", mso_sptSeal4
},
1262 {"doubleWave", mso_sptDoubleWave
},
1263 {"actionButtonBlank", mso_sptActionButtonBlank
},
1264 {"actionButtonHome", mso_sptActionButtonHome
},
1265 {"actionButtonHelp", mso_sptActionButtonHelp
},
1266 {"actionButtonInformation", mso_sptActionButtonInformation
},
1267 {"actionButtonForwardNext", mso_sptActionButtonForwardNext
},
1268 {"actionButtonBackPrevious", mso_sptActionButtonBackPrevious
},
1269 {"actionButtonEnd", mso_sptActionButtonEnd
},
1270 {"actionButtonBeginning", mso_sptActionButtonBeginning
},
1271 {"actionButtonReturn", mso_sptActionButtonReturn
},
1272 {"actionButtonDocument", mso_sptActionButtonDocument
},
1273 {"actionButtonSound", mso_sptActionButtonSound
},
1274 {"actionButtonMovie", mso_sptActionButtonMovie
},
1275 {"hostControl", mso_sptHostControl
},
1276 {"textBox", mso_sptTextBox
},
1277 {"roundRect", mso_sptRoundRectangle
},
1280 auto i(aDMLToVMLMap
.find(GetOOXMLPresetGeometry(aType
)));
1281 return i
== aDMLToVMLMap
.end() ? mso_sptNil
: i
->second
;
1284 bool HasTextBoxContent(sal_uInt32 nShapeType
)
1288 case ESCHER_ShpInst_TextPlainText
:
1289 case ESCHER_ShpInst_TextSlantUp
:
1290 case ESCHER_ShpInst_TextDeflateInflateDeflate
:
1300 // Scheme means pattern of chromatic values.
1301 // [2,2,1] -> red and green are approximately equal and blue is the dominant color (e.g. blue)
1302 // [1,1,1] -> all chromatic values are approximately equal (e.g. white, gray, black)
1303 void CalculateScheme(const BitmapColor
& rBitmapColor
, std::vector
<int> &vScheme
, sal_uInt16 nVariance
)
1305 vScheme
.resize(3,1);
1306 if( rBitmapColor
.GetRed() < rBitmapColor
.GetGreen() + nVariance
)
1308 if( rBitmapColor
.GetRed() < rBitmapColor
.GetBlue() + nVariance
)
1310 if( rBitmapColor
.GetGreen() < rBitmapColor
.GetRed() + nVariance
)
1312 if( rBitmapColor
.GetGreen() < rBitmapColor
.GetBlue() + nVariance
)
1314 if( rBitmapColor
.GetBlue() < rBitmapColor
.GetRed() + nVariance
)
1316 if( rBitmapColor
.GetBlue() < rBitmapColor
.GetGreen() + nVariance
)
1320 bool HasSimilarScheme(const BitmapColor
& rBitmapColor1
, const BitmapColor
& rBitmapColor2
, sal_uInt16 nVariance
)
1322 std::vector
<int> vScheme1
, vScheme2
;
1323 CalculateScheme(rBitmapColor1
, vScheme1
, nVariance
);
1324 CalculateScheme(rBitmapColor2
, vScheme2
, nVariance
);
1325 for( int i
= 0; i
< 3; ++i
)
1327 if( vScheme1
[i
] != vScheme2
[i
] )
1333 // Find the best match in the color palette using scheme of the input color
1334 sal_uInt16
GetBestIndex(const BitmapPalette
& rPalette
, const BitmapColor
& rBitmapColor
)
1336 sal_uInt16 nReturn
= 0;
1337 sal_uInt16 nLastErr
= SAL_MAX_UINT16
;
1338 bool bFound
= false;
1340 // Prefer those colors which have similar scheme as the input
1341 // Allow bigger and bigger variance of the schemes until we find
1342 // a color in the palette with similar scheme.
1343 for( sal_uInt16 nVariance
= 0; nVariance
<= 255; ++nVariance
)
1345 for( sal_uInt16 i
= 0; i
< rPalette
.GetEntryCount(); ++i
)
1347 if( HasSimilarScheme(rBitmapColor
, rPalette
[i
], nVariance
) )
1349 const sal_uInt16 nActErr
= rBitmapColor
.GetColorError( rPalette
[i
] );
1350 if( nActErr
< nLastErr
)
1365 sal_uInt8
TransColToIco( const Color
& rCol
)
1367 sal_uInt8 nCol
= 0; // ->Auto
1368 switch( sal_uInt32(rCol
) )
1370 case sal_uInt32(COL_BLACK
): nCol
= 1; break;
1371 case sal_uInt32(COL_BLUE
): nCol
= 9; break;
1372 case sal_uInt32(COL_GREEN
): nCol
= 11; break;
1373 case sal_uInt32(COL_CYAN
): nCol
= 10; break;
1374 case sal_uInt32(COL_RED
): nCol
= 13; break;
1375 case sal_uInt32(COL_MAGENTA
): nCol
= 12; break;
1376 case sal_uInt32(COL_BROWN
): nCol
= 14; break;
1377 case sal_uInt32(COL_GRAY
): nCol
= 15; break;
1378 case sal_uInt32(COL_LIGHTGRAY
): nCol
= 16; break;
1379 case sal_uInt32(COL_LIGHTBLUE
): nCol
= 2; break;
1380 case sal_uInt32(COL_LIGHTGREEN
): nCol
= 4; break;
1381 case sal_uInt32(COL_LIGHTCYAN
): nCol
= 3; break;
1382 case sal_uInt32(COL_LIGHTRED
): nCol
= 6; break;
1383 case sal_uInt32(COL_LIGHTMAGENTA
): nCol
= 5; break;
1384 case sal_uInt32(COL_YELLOW
): nCol
= 7; break;
1385 case sal_uInt32(COL_WHITE
): nCol
= 8; break;
1386 case sal_uInt32(COL_AUTO
): nCol
= 0; break;
1389 static const BitmapPalette aBmpPal
{
1390 COL_BLACK
, COL_LIGHTBLUE
, COL_LIGHTCYAN
, COL_LIGHTGREEN
,
1391 COL_LIGHTMAGENTA
,COL_LIGHTRED
, COL_YELLOW
, COL_WHITE
,
1392 COL_BLUE
, COL_CYAN
, COL_GREEN
, COL_MAGENTA
,
1393 COL_RED
, COL_BROWN
, COL_GRAY
, COL_LIGHTGRAY
1396 nCol
= static_cast< sal_uInt8
>(GetBestIndex(aBmpPal
, rCol
) + 1);
1404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */