Avoid potential negative array index access to cached text.
[LibreOffice.git] / writerfilter / source / rtftok / rtfdispatchflag.cxx
blob753f1c3fbba93f26fc3b55c46ec012456312e914
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/.
8 */
10 #include <sal/config.h>
12 #include <string_view>
14 #include "rtfdocumentimpl.hxx"
16 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
17 #include <com/sun/star/drawing/XEnhancedCustomShapeDefaulter.hpp>
18 #include <com/sun/star/text/RelOrientation.hpp>
19 #include <com/sun/star/text/VertOrientation.hpp>
20 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 #include <filter/msfilter/escherex.hxx>
24 #include <ooxml/resourceids.hxx>
26 #include <sal/log.hxx>
28 #include "rtfsdrimport.hxx"
29 #include "rtfskipdestination.hxx"
31 using namespace com::sun::star;
33 namespace writerfilter::rtftok
35 bool RTFDocumentImpl::dispatchFloatingTableFlag(RTFKeyword nKeyword)
37 // Positioned Wrapped Tables
38 OUString aParam;
39 switch (nKeyword)
41 case RTFKeyword::TPVPARA:
42 aParam = "text";
43 break;
44 case RTFKeyword::TPVMRG:
45 aParam = "margin";
46 break;
47 case RTFKeyword::TPVPG:
48 aParam = "page";
49 break;
50 default:
51 break;
53 if (!aParam.isEmpty())
55 putNestedAttribute(m_aStates.top().getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblpPr,
56 NS_ooxml::LN_CT_TblPPr_vertAnchor, new RTFValue(aParam));
57 return true;
59 switch (nKeyword)
61 case RTFKeyword::TPHCOL:
62 aParam = "text";
63 break;
64 case RTFKeyword::TPHMRG:
65 aParam = "margin";
66 break;
67 case RTFKeyword::TPHPG:
68 aParam = "page";
69 break;
70 default:
71 break;
73 if (!aParam.isEmpty())
75 putNestedAttribute(m_aStates.top().getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblpPr,
76 NS_ooxml::LN_CT_TblPPr_horzAnchor, new RTFValue(aParam));
77 return true;
79 switch (nKeyword)
81 case RTFKeyword::TPOSYC:
82 aParam = "center";
83 break;
84 case RTFKeyword::TPOSYB:
85 aParam = "bottom";
86 break;
87 default:
88 break;
90 if (!aParam.isEmpty())
92 putNestedAttribute(m_aStates.top().getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblpPr,
93 NS_ooxml::LN_CT_TblPPr_tblpYSpec, new RTFValue(aParam));
94 return true;
96 switch (nKeyword)
98 case RTFKeyword::TPOSXC:
99 aParam = "center";
100 break;
101 case RTFKeyword::TPOSXR:
102 aParam = "right";
103 break;
104 default:
105 break;
107 if (!aParam.isEmpty())
109 putNestedAttribute(m_aStates.top().getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblpPr,
110 NS_ooxml::LN_CT_TblPPr_tblpXSpec, new RTFValue(aParam));
111 return true;
114 if (nKeyword == RTFKeyword::TABSNOOVRLP)
116 m_aStates.top().getTableRowSprms().set(
117 NS_ooxml::LN_CT_TblPrBase_tblOverlap,
118 new RTFValue(NS_ooxml::LN_Value_ST_TblOverlap_never));
119 return true;
122 return false;
125 RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
127 setNeedSect(true);
128 checkUnicode(/*bUnicode =*/true, /*bHex =*/true);
129 RTFSkipDestination aSkip(*this);
130 int nParam = -1;
131 int nSprm = -1;
133 // Underline flags.
134 switch (nKeyword)
136 case RTFKeyword::ULD:
137 nSprm = NS_ooxml::LN_Value_ST_Underline_dotted;
138 break;
139 case RTFKeyword::ULW:
140 nSprm = NS_ooxml::LN_Value_ST_Underline_words;
141 break;
142 default:
143 break;
145 if (nSprm >= 0)
147 auto pValue = new RTFValue(nSprm);
148 m_aStates.top().getCharacterAttributes().set(NS_ooxml::LN_CT_Underline_val, pValue);
149 return RTFError::OK;
152 // Indentation
153 switch (nKeyword)
155 case RTFKeyword::QC:
156 nParam = NS_ooxml::LN_Value_ST_Jc_center;
157 break;
158 case RTFKeyword::QJ:
159 nParam = NS_ooxml::LN_Value_ST_Jc_both;
160 break;
161 case RTFKeyword::QL:
162 nParam = NS_ooxml::LN_Value_ST_Jc_left;
163 break;
164 case RTFKeyword::QR:
165 nParam = NS_ooxml::LN_Value_ST_Jc_right;
166 break;
167 case RTFKeyword::QD:
168 nParam = NS_ooxml::LN_Value_ST_Jc_distribute;
169 break;
170 default:
171 break;
173 if (nParam >= 0)
175 auto pValue = new RTFValue(nParam);
176 m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_jc, pValue);
177 m_bNeedPap = true;
178 return RTFError::OK;
181 // Font Alignment
182 switch (nKeyword)
184 case RTFKeyword::FAFIXED:
185 case RTFKeyword::FAAUTO:
186 nParam = NS_ooxml::LN_Value_doc_ST_TextAlignment_auto;
187 break;
188 case RTFKeyword::FAHANG:
189 nParam = NS_ooxml::LN_Value_doc_ST_TextAlignment_top;
190 break;
191 case RTFKeyword::FACENTER:
192 nParam = NS_ooxml::LN_Value_doc_ST_TextAlignment_center;
193 break;
194 case RTFKeyword::FAROMAN:
195 nParam = NS_ooxml::LN_Value_doc_ST_TextAlignment_baseline;
196 break;
197 case RTFKeyword::FAVAR:
198 nParam = NS_ooxml::LN_Value_doc_ST_TextAlignment_bottom;
199 break;
200 default:
201 break;
203 if (nParam >= 0)
205 auto pValue = new RTFValue(nParam);
206 m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_textAlignment, pValue);
207 return RTFError::OK;
210 // Tab kind.
211 switch (nKeyword)
213 case RTFKeyword::TQR:
214 nParam = NS_ooxml::LN_Value_ST_TabJc_right;
215 break;
216 case RTFKeyword::TQC:
217 nParam = NS_ooxml::LN_Value_ST_TabJc_center;
218 break;
219 case RTFKeyword::TQDEC:
220 nParam = NS_ooxml::LN_Value_ST_TabJc_decimal;
221 break;
222 default:
223 break;
225 if (nParam >= 0)
227 auto pValue = new RTFValue(nParam);
228 m_aStates.top().getTabAttributes().set(NS_ooxml::LN_CT_TabStop_val, pValue);
229 return RTFError::OK;
232 // Tab lead.
233 switch (nKeyword)
235 case RTFKeyword::TLDOT:
236 nParam = NS_ooxml::LN_Value_ST_TabTlc_dot;
237 break;
238 case RTFKeyword::TLMDOT:
239 nParam = NS_ooxml::LN_Value_ST_TabTlc_middleDot;
240 break;
241 case RTFKeyword::TLHYPH:
242 nParam = NS_ooxml::LN_Value_ST_TabTlc_hyphen;
243 break;
244 case RTFKeyword::TLUL:
245 case RTFKeyword::TLTH:
246 nParam = NS_ooxml::LN_Value_ST_TabTlc_underscore;
247 break;
248 case RTFKeyword::TLEQ:
249 default:
250 break;
252 if (nParam >= 0)
254 auto pValue = new RTFValue(nParam);
255 m_aStates.top().getTabAttributes().set(NS_ooxml::LN_CT_TabStop_leader, pValue);
256 return RTFError::OK;
259 // Border types
261 switch (nKeyword)
263 // brdrhair and brdrs are the same, brdrw will make a difference
264 // map to values in ooxml/model.xml resource ST_Border
265 case RTFKeyword::BRDRHAIR:
266 case RTFKeyword::BRDRS:
267 nParam = NS_ooxml::LN_Value_ST_Border_single;
268 break;
269 case RTFKeyword::BRDRDOT:
270 nParam = NS_ooxml::LN_Value_ST_Border_dotted;
271 break;
272 case RTFKeyword::BRDRDASH:
273 nParam = NS_ooxml::LN_Value_ST_Border_dashed;
274 break;
275 case RTFKeyword::BRDRDB:
276 nParam = NS_ooxml::LN_Value_ST_Border_double;
277 break;
278 case RTFKeyword::BRDRTNTHSG:
279 nParam = NS_ooxml::LN_Value_ST_Border_thinThickSmallGap;
280 break;
281 case RTFKeyword::BRDRTNTHMG:
282 nParam = NS_ooxml::LN_Value_ST_Border_thinThickMediumGap;
283 break;
284 case RTFKeyword::BRDRTNTHLG:
285 nParam = NS_ooxml::LN_Value_ST_Border_thinThickLargeGap;
286 break;
287 case RTFKeyword::BRDRTHTNSG:
288 nParam = NS_ooxml::LN_Value_ST_Border_thickThinSmallGap;
289 break;
290 case RTFKeyword::BRDRTHTNMG:
291 nParam = NS_ooxml::LN_Value_ST_Border_thickThinMediumGap;
292 break;
293 case RTFKeyword::BRDRTHTNLG:
294 nParam = NS_ooxml::LN_Value_ST_Border_thickThinLargeGap;
295 break;
296 case RTFKeyword::BRDREMBOSS:
297 nParam = NS_ooxml::LN_Value_ST_Border_threeDEmboss;
298 break;
299 case RTFKeyword::BRDRENGRAVE:
300 nParam = NS_ooxml::LN_Value_ST_Border_threeDEngrave;
301 break;
302 case RTFKeyword::BRDROUTSET:
303 nParam = NS_ooxml::LN_Value_ST_Border_outset;
304 break;
305 case RTFKeyword::BRDRINSET:
306 nParam = NS_ooxml::LN_Value_ST_Border_inset;
307 break;
308 case RTFKeyword::BRDRDASHSM:
309 nParam = NS_ooxml::LN_Value_ST_Border_dashSmallGap;
310 break;
311 case RTFKeyword::BRDRDASHD:
312 nParam = NS_ooxml::LN_Value_ST_Border_dotDash;
313 break;
314 case RTFKeyword::BRDRDASHDD:
315 nParam = NS_ooxml::LN_Value_ST_Border_dotDotDash;
316 break;
317 case RTFKeyword::BRDRNONE:
318 nParam = NS_ooxml::LN_Value_ST_Border_none;
319 break;
320 default:
321 break;
323 if (nParam >= 0)
325 auto pValue = new RTFValue(nParam);
326 putBorderProperty(m_aStates, NS_ooxml::LN_CT_Border_val, pValue);
327 return RTFError::OK;
331 // Section breaks
332 switch (nKeyword)
334 case RTFKeyword::SBKNONE:
335 nParam = NS_ooxml::LN_Value_ST_SectionMark_continuous;
336 break;
337 case RTFKeyword::SBKCOL:
338 nParam = NS_ooxml::LN_Value_ST_SectionMark_nextColumn;
339 break;
340 case RTFKeyword::SBKPAGE:
341 nParam = NS_ooxml::LN_Value_ST_SectionMark_nextPage;
342 break;
343 case RTFKeyword::SBKEVEN:
344 nParam = NS_ooxml::LN_Value_ST_SectionMark_evenPage;
345 break;
346 case RTFKeyword::SBKODD:
347 nParam = NS_ooxml::LN_Value_ST_SectionMark_oddPage;
348 break;
349 default:
350 break;
352 if (nParam >= 0)
354 if (m_nResetBreakOnSectBreak != RTFKeyword::invalid)
356 m_nResetBreakOnSectBreak = nKeyword;
358 auto pValue = new RTFValue(nParam);
359 m_aStates.top().getSectionSprms().set(NS_ooxml::LN_EG_SectPrContents_type, pValue);
360 return RTFError::OK;
363 // Footnote numbering
364 switch (nKeyword)
366 case RTFKeyword::FTNNAR:
367 nParam = NS_ooxml::LN_Value_ST_NumberFormat_decimal;
368 break;
369 case RTFKeyword::FTNNALC:
370 nParam = NS_ooxml::LN_Value_ST_NumberFormat_lowerLetter;
371 break;
372 case RTFKeyword::FTNNAUC:
373 nParam = NS_ooxml::LN_Value_ST_NumberFormat_upperLetter;
374 break;
375 case RTFKeyword::FTNNRLC:
376 nParam = NS_ooxml::LN_Value_ST_NumberFormat_lowerRoman;
377 break;
378 case RTFKeyword::FTNNRUC:
379 nParam = NS_ooxml::LN_Value_ST_NumberFormat_upperRoman;
380 break;
381 case RTFKeyword::FTNNCHI:
382 nParam = NS_ooxml::LN_Value_ST_NumberFormat_chicago;
383 break;
384 default:
385 break;
387 if (nParam >= 0)
389 auto pInner = new RTFValue(nParam);
390 RTFSprms aAttributes;
391 aAttributes.set(NS_ooxml::LN_CT_NumFmt_val, pInner);
392 auto pOuter = new RTFValue(aAttributes);
393 putNestedSprm(m_aDefaultState.getParagraphSprms(),
394 NS_ooxml::LN_EG_SectPrContents_footnotePr, NS_ooxml::LN_CT_FtnProps_numFmt,
395 pOuter);
396 return RTFError::OK;
399 // Footnote restart type
400 switch (nKeyword)
402 case RTFKeyword::FTNRSTPG:
403 nParam = NS_ooxml::LN_Value_ST_RestartNumber_eachPage;
404 break;
405 case RTFKeyword::FTNRESTART:
406 nParam = NS_ooxml::LN_Value_ST_RestartNumber_eachSect;
407 break;
408 case RTFKeyword::FTNRSTCONT:
409 nParam = NS_ooxml::LN_Value_ST_RestartNumber_continuous;
410 break;
411 default:
412 break;
414 if (nParam >= 0)
416 auto pValue = new RTFValue(nParam);
417 putNestedSprm(m_aDefaultState.getParagraphSprms(),
418 NS_ooxml::LN_EG_SectPrContents_footnotePr,
419 NS_ooxml::LN_EG_FtnEdnNumProps_numRestart, pValue);
420 return RTFError::OK;
423 // Endnote numbering
424 switch (nKeyword)
426 case RTFKeyword::AFTNNAR:
427 nParam = NS_ooxml::LN_Value_ST_NumberFormat_decimal;
428 break;
429 case RTFKeyword::AFTNNALC:
430 nParam = NS_ooxml::LN_Value_ST_NumberFormat_lowerLetter;
431 break;
432 case RTFKeyword::AFTNNAUC:
433 nParam = NS_ooxml::LN_Value_ST_NumberFormat_upperLetter;
434 break;
435 case RTFKeyword::AFTNNRLC:
436 nParam = NS_ooxml::LN_Value_ST_NumberFormat_lowerRoman;
437 break;
438 case RTFKeyword::AFTNNRUC:
439 nParam = NS_ooxml::LN_Value_ST_NumberFormat_upperRoman;
440 break;
441 case RTFKeyword::AFTNNCHI:
442 nParam = NS_ooxml::LN_Value_ST_NumberFormat_chicago;
443 break;
444 default:
445 break;
447 if (nParam >= 0)
449 auto pInner = new RTFValue(nParam);
450 RTFSprms aAttributes;
451 aAttributes.set(NS_ooxml::LN_CT_NumFmt_val, pInner);
452 auto pOuter = new RTFValue(aAttributes);
453 putNestedSprm(m_aDefaultState.getParagraphSprms(), NS_ooxml::LN_EG_SectPrContents_endnotePr,
454 NS_ooxml::LN_CT_EdnProps_numFmt, pOuter);
455 return RTFError::OK;
458 switch (nKeyword)
460 case RTFKeyword::TRQL:
461 nParam = NS_ooxml::LN_Value_ST_Jc_left;
462 break;
463 case RTFKeyword::TRQC:
464 nParam = NS_ooxml::LN_Value_ST_Jc_center;
465 break;
466 case RTFKeyword::TRQR:
467 nParam = NS_ooxml::LN_Value_ST_Jc_right;
468 break;
469 default:
470 break;
472 if (nParam >= 0)
474 auto pValue = new RTFValue(nParam);
475 m_aStates.top().getTableRowSprms().set(NS_ooxml::LN_CT_TrPrBase_jc, pValue);
476 return RTFError::OK;
479 // Cell Text Flow
480 switch (nKeyword)
482 case RTFKeyword::CLTXLRTB:
483 nParam = NS_ooxml::LN_Value_ST_TextDirection_lrTb;
484 break;
485 case RTFKeyword::CLTXTBRL:
486 nParam = NS_ooxml::LN_Value_ST_TextDirection_tbRl;
487 break;
488 case RTFKeyword::CLTXBTLR:
489 nParam = NS_ooxml::LN_Value_ST_TextDirection_btLr;
490 break;
491 case RTFKeyword::CLTXLRTBV:
492 nParam = NS_ooxml::LN_Value_ST_TextDirection_lrTbV;
493 break;
494 case RTFKeyword::CLTXTBRLV:
495 nParam = NS_ooxml::LN_Value_ST_TextDirection_tbRlV;
496 break;
497 default:
498 break;
500 if (nParam >= 0)
502 auto pValue = new RTFValue(nParam);
503 m_aStates.top().getTableCellSprms().set(NS_ooxml::LN_CT_TcPrBase_textDirection, pValue);
506 // Trivial paragraph flags
507 switch (nKeyword)
509 case RTFKeyword::KEEP:
510 if (m_aStates.top().getCurrentBuffer() != &m_aTableBufferStack.back())
511 nParam = NS_ooxml::LN_CT_PPrBase_keepLines;
512 break;
513 case RTFKeyword::KEEPN:
514 nParam = NS_ooxml::LN_CT_PPrBase_keepNext;
515 break;
516 case RTFKeyword::INTBL:
518 m_aStates.top().setCurrentBuffer(&m_aTableBufferStack.back());
519 nParam = NS_ooxml::LN_inTbl;
521 break;
522 case RTFKeyword::PAGEBB:
523 // ignore a page break that is defined before the document content has even started
524 if (!m_bFirstRun)
525 nParam = NS_ooxml::LN_CT_PPrBase_pageBreakBefore;
526 break;
527 default:
528 break;
530 if (nParam >= 0)
532 auto pValue = new RTFValue(1);
533 m_aStates.top().getParagraphSprms().set(nParam, pValue);
534 return RTFError::OK;
537 if (dispatchFloatingTableFlag(nKeyword))
539 return RTFError::OK;
542 switch (nKeyword)
544 case RTFKeyword::FNIL:
545 case RTFKeyword::FROMAN:
546 case RTFKeyword::FSWISS:
547 case RTFKeyword::FMODERN:
548 case RTFKeyword::FSCRIPT:
549 case RTFKeyword::FDECOR:
550 case RTFKeyword::FTECH:
551 case RTFKeyword::FBIDI:
552 // TODO ooxml:CT_Font_family seems to be ignored by the domain mapper
553 break;
554 case RTFKeyword::ANSI:
555 m_aStates.top().setCurrentEncoding(RTL_TEXTENCODING_MS_1252);
556 break;
557 case RTFKeyword::MAC:
558 m_aDefaultState.setCurrentEncoding(RTL_TEXTENCODING_APPLE_ROMAN);
559 m_aStates.top().setCurrentEncoding(m_aDefaultState.getCurrentEncoding());
560 break;
561 case RTFKeyword::PC:
562 m_aDefaultState.setCurrentEncoding(RTL_TEXTENCODING_IBM_437);
563 m_aStates.top().setCurrentEncoding(m_aDefaultState.getCurrentEncoding());
564 break;
565 case RTFKeyword::PCA:
566 m_aDefaultState.setCurrentEncoding(RTL_TEXTENCODING_IBM_850);
567 m_aStates.top().setCurrentEncoding(m_aDefaultState.getCurrentEncoding());
568 break;
569 case RTFKeyword::PLAIN:
571 m_aStates.top().getCharacterSprms() = getDefaultState().getCharacterSprms();
572 m_aStates.top().setCurrentEncoding(getEncoding(getFontIndex(m_nDefaultFontIndex)));
573 m_aStates.top().getCharacterAttributes() = getDefaultState().getCharacterAttributes();
574 m_aStates.top().setCurrentCharacterStyleIndex(-1);
575 m_aStates.top().setRunType(RTFParserState::RunType::NONE);
577 break;
578 case RTFKeyword::PARD:
580 if (m_bHadPicture)
581 dispatchSymbol(RTFKeyword::PAR);
582 // \pard is allowed between \cell and \row, but in that case it should not reset the fact that we're inside a table.
583 // It should not reset the paragraph style, either, so remember the old paragraph style.
584 m_aStates.top().getParagraphSprms() = m_aDefaultState.getParagraphSprms();
585 m_aStates.top().getParagraphAttributes() = m_aDefaultState.getParagraphAttributes();
587 if (m_nTopLevelCells == 0 && m_nNestedCells == 0)
589 // Reset that we're in a table.
590 m_aStates.top().setCurrentBuffer(nullptr);
592 else
594 // We are still in a table.
595 m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_inTbl, new RTFValue(1));
596 // Ideally getDefaultSPRM() would take care of this, but it would not when we're buffering.
597 m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_tabs,
598 new RTFValue());
600 resetFrame();
602 // Reset currently selected paragraph style as well.
603 // By default the style with index 0 is applied.
605 OUString const aName = getStyleName(0);
606 // But only in case it's not a character style.
607 if (!aName.isEmpty()
608 && getStyleType(0) != NS_ooxml::LN_Value_ST_StyleType_character)
610 m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_pStyle,
611 new RTFValue(aName));
613 m_aStates.top().setCurrentStyleIndex(0);
615 // Need to send paragraph properties again, if there will be any.
616 m_bNeedPap = true;
617 break;
619 case RTFKeyword::SECTD:
621 m_aStates.top().getSectionSprms() = m_aDefaultState.getSectionSprms();
622 m_aStates.top().getSectionAttributes() = m_aDefaultState.getSectionAttributes();
624 break;
625 case RTFKeyword::TROWD:
627 // Back these up, in case later we still need this info.
628 backupTableRowProperties();
629 resetTableRowProperties();
630 // In case the table definition is in the middle of the row
631 // (invalid), make sure table definition is emitted.
632 m_bNeedPap = true;
634 break;
635 case RTFKeyword::WIDCTLPAR:
636 case RTFKeyword::NOWIDCTLPAR:
638 auto pValue = new RTFValue(int(nKeyword == RTFKeyword::WIDCTLPAR));
639 m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_widowControl, pValue);
641 break;
642 case RTFKeyword::BOX:
644 RTFSprms aAttributes;
645 auto pValue = new RTFValue(aAttributes);
646 for (int i = 0; i < 4; i++)
647 m_aStates.top().getParagraphSprms().set(getParagraphBorder(i), pValue);
648 m_aStates.top().setBorderState(RTFBorderState::PARAGRAPH_BOX);
650 break;
651 case RTFKeyword::LTRSECT:
652 case RTFKeyword::RTLSECT:
654 auto pValue = new RTFValue(nKeyword == RTFKeyword::LTRSECT ? 0 : 1);
655 m_aStates.top().setRunType(RTFParserState::RunType::NONE);
656 m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_EG_SectPrContents_textDirection,
657 pValue);
659 break;
660 case RTFKeyword::LTRPAR:
661 case RTFKeyword::RTLPAR:
663 auto pValue = new RTFValue(nKeyword == RTFKeyword::LTRPAR ? 0 : 1);
664 m_aStates.top().setRunType(RTFParserState::RunType::NONE);
665 m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_bidi, pValue);
667 break;
668 case RTFKeyword::LTRROW:
669 case RTFKeyword::RTLROW:
670 m_aStates.top().setRunType(RTFParserState::RunType::NONE);
671 m_aStates.top().getTableRowSprms().set(
672 NS_ooxml::LN_CT_TblPrBase_bidiVisual,
673 new RTFValue(int(nKeyword == RTFKeyword::RTLROW)));
674 break;
675 case RTFKeyword::LTRCH:
676 // dmapper does not support this.
677 if (m_aStates.top().getRunType() == RTFParserState::RunType::RTLCH_LTRCH_1)
678 m_aStates.top().setRunType(RTFParserState::RunType::RTLCH_LTRCH_2);
679 else
680 m_aStates.top().setRunType(RTFParserState::RunType::LTRCH_RTLCH_1);
681 break;
682 case RTFKeyword::RTLCH:
683 if (m_aStates.top().getRunType() == RTFParserState::RunType::LTRCH_RTLCH_1)
684 m_aStates.top().setRunType(RTFParserState::RunType::LTRCH_RTLCH_2);
685 else
686 m_aStates.top().setRunType(RTFParserState::RunType::RTLCH_LTRCH_1);
688 if (m_aDefaultState.getCurrentEncoding() == RTL_TEXTENCODING_MS_1255)
689 m_aStates.top().setCurrentEncoding(m_aDefaultState.getCurrentEncoding());
690 break;
691 case RTFKeyword::ULNONE:
693 auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_Underline_none);
694 m_aStates.top().getCharacterAttributes().set(NS_ooxml::LN_CT_Underline_val, pValue);
696 break;
697 case RTFKeyword::NONSHPPICT:
698 case RTFKeyword::MMATHPICT: // Picture group used by readers not understanding \moMath group
699 m_aStates.top().setDestination(Destination::SKIP);
700 break;
701 case RTFKeyword::CLBRDRT:
702 case RTFKeyword::CLBRDRL:
703 case RTFKeyword::CLBRDRB:
704 case RTFKeyword::CLBRDRR:
706 RTFSprms aAttributes;
707 RTFSprms aSprms;
708 auto pValue = new RTFValue(aAttributes, aSprms);
709 switch (nKeyword)
711 case RTFKeyword::CLBRDRT:
712 nSprm = NS_ooxml::LN_CT_TcBorders_top;
713 break;
714 case RTFKeyword::CLBRDRL:
715 nSprm = NS_ooxml::LN_CT_TcBorders_left;
716 break;
717 case RTFKeyword::CLBRDRB:
718 nSprm = NS_ooxml::LN_CT_TcBorders_bottom;
719 break;
720 case RTFKeyword::CLBRDRR:
721 nSprm = NS_ooxml::LN_CT_TcBorders_right;
722 break;
723 default:
724 break;
726 putNestedSprm(m_aStates.top().getTableCellSprms(), NS_ooxml::LN_CT_TcPrBase_tcBorders,
727 nSprm, pValue);
728 m_aStates.top().setBorderState(RTFBorderState::CELL);
730 break;
731 case RTFKeyword::PGBRDRT:
732 case RTFKeyword::PGBRDRL:
733 case RTFKeyword::PGBRDRB:
734 case RTFKeyword::PGBRDRR:
736 RTFSprms aAttributes;
737 RTFSprms aSprms;
738 auto pValue = new RTFValue(aAttributes, aSprms);
739 switch (nKeyword)
741 case RTFKeyword::PGBRDRT:
742 nSprm = NS_ooxml::LN_CT_PageBorders_top;
743 break;
744 case RTFKeyword::PGBRDRL:
745 nSprm = NS_ooxml::LN_CT_PageBorders_left;
746 break;
747 case RTFKeyword::PGBRDRB:
748 nSprm = NS_ooxml::LN_CT_PageBorders_bottom;
749 break;
750 case RTFKeyword::PGBRDRR:
751 nSprm = NS_ooxml::LN_CT_PageBorders_right;
752 break;
753 default:
754 break;
756 putNestedSprm(m_aStates.top().getSectionSprms(),
757 NS_ooxml::LN_EG_SectPrContents_pgBorders, nSprm, pValue);
758 m_aStates.top().setBorderState(RTFBorderState::PAGE);
760 break;
761 case RTFKeyword::BRDRT:
762 case RTFKeyword::BRDRL:
763 case RTFKeyword::BRDRB:
764 case RTFKeyword::BRDRR:
765 case RTFKeyword::BRDRBTW:
767 RTFSprms aAttributes;
768 RTFSprms aSprms;
769 auto pValue = new RTFValue(aAttributes, aSprms);
770 switch (nKeyword)
772 case RTFKeyword::BRDRT:
773 nSprm = getParagraphBorder(0);
774 break;
775 case RTFKeyword::BRDRL:
776 nSprm = getParagraphBorder(1);
777 break;
778 case RTFKeyword::BRDRB:
779 nSprm = getParagraphBorder(2);
780 break;
781 case RTFKeyword::BRDRR:
782 nSprm = getParagraphBorder(3);
783 break;
784 case RTFKeyword::BRDRBTW:
785 nSprm = getParagraphBorder(4);
786 break;
787 default:
788 break;
790 putNestedSprm(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PrBase_pBdr, nSprm,
791 pValue);
792 m_aStates.top().setBorderState(RTFBorderState::PARAGRAPH);
794 break;
795 case RTFKeyword::CHBRDR:
797 RTFSprms aAttributes;
798 auto pValue = new RTFValue(aAttributes);
799 m_aStates.top().getCharacterSprms().set(NS_ooxml::LN_EG_RPrBase_bdr, pValue);
800 m_aStates.top().setBorderState(RTFBorderState::CHARACTER);
802 break;
803 case RTFKeyword::CLMGF:
805 auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_Merge_restart);
806 m_aStates.top().getTableCellSprms().set(NS_ooxml::LN_CT_TcPrBase_hMerge, pValue);
808 break;
809 case RTFKeyword::CLMRG:
811 auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_Merge_continue);
812 m_aStates.top().getTableCellSprms().set(NS_ooxml::LN_CT_TcPrBase_hMerge, pValue);
814 break;
815 case RTFKeyword::CLVMGF:
817 auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_Merge_restart);
818 m_aStates.top().getTableCellSprms().set(NS_ooxml::LN_CT_TcPrBase_vMerge, pValue);
820 break;
821 case RTFKeyword::CLVMRG:
823 auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_Merge_continue);
824 m_aStates.top().getTableCellSprms().set(NS_ooxml::LN_CT_TcPrBase_vMerge, pValue);
826 break;
827 case RTFKeyword::CLVERTALT:
828 case RTFKeyword::CLVERTALC:
829 case RTFKeyword::CLVERTALB:
831 switch (nKeyword)
833 case RTFKeyword::CLVERTALT:
834 nParam = NS_ooxml::LN_Value_ST_VerticalJc_top;
835 break;
836 case RTFKeyword::CLVERTALC:
837 nParam = NS_ooxml::LN_Value_ST_VerticalJc_center;
838 break;
839 case RTFKeyword::CLVERTALB:
840 nParam = NS_ooxml::LN_Value_ST_VerticalJc_bottom;
841 break;
842 default:
843 break;
845 auto pValue = new RTFValue(nParam);
846 m_aStates.top().getTableCellSprms().set(NS_ooxml::LN_CT_TcPrBase_vAlign, pValue);
848 break;
849 case RTFKeyword::TRKEEP:
851 auto pValue = new RTFValue(1);
852 m_aStates.top().getTableRowSprms().set(NS_ooxml::LN_CT_TrPrBase_cantSplit, pValue);
854 break;
855 case RTFKeyword::SECTUNLOCKED:
857 auto pValue = new RTFValue(0);
858 m_aStates.top().getSectionSprms().set(NS_ooxml::LN_EG_SectPrContents_formProt, pValue);
860 break;
861 case RTFKeyword::PGNBIDIA:
862 case RTFKeyword::PGNBIDIB:
863 // These should be mapped to NS_ooxml::LN_EG_SectPrContents_pgNumType, but dmapper has no API for that at the moment.
864 break;
865 case RTFKeyword::LOCH:
866 m_aStates.top().setRunType(RTFParserState::RunType::LOCH);
867 break;
868 case RTFKeyword::HICH:
869 m_aStates.top().setRunType(RTFParserState::RunType::HICH);
870 break;
871 case RTFKeyword::DBCH:
872 m_aStates.top().setRunType(RTFParserState::RunType::DBCH);
873 break;
874 case RTFKeyword::TITLEPG:
876 auto pValue = new RTFValue(1);
877 m_aStates.top().getSectionSprms().set(NS_ooxml::LN_EG_SectPrContents_titlePg, pValue);
879 break;
880 case RTFKeyword::SUPER:
882 // Make sure character properties are not lost if the document
883 // starts with a footnote.
884 if (!isStyleSheetImport())
886 checkFirstRun();
887 checkNeedPap();
890 if (!m_aStates.top().getCurrentBuffer())
891 m_aStates.top().setCurrentBuffer(&m_aSuperBuffer);
893 auto pValue = new RTFValue("superscript");
894 m_aStates.top().getCharacterSprms().set(NS_ooxml::LN_EG_RPrBase_vertAlign, pValue);
896 break;
897 case RTFKeyword::SUB:
899 auto pValue = new RTFValue("subscript");
900 m_aStates.top().getCharacterSprms().set(NS_ooxml::LN_EG_RPrBase_vertAlign, pValue);
902 break;
903 case RTFKeyword::NOSUPERSUB:
905 if (m_aStates.top().getCurrentBuffer() == &m_aSuperBuffer)
907 replayBuffer(m_aSuperBuffer, nullptr, nullptr);
908 m_aStates.top().setCurrentBuffer(nullptr);
910 m_aStates.top().getCharacterSprms().erase(NS_ooxml::LN_EG_RPrBase_vertAlign);
912 break;
913 case RTFKeyword::LINEPPAGE:
914 case RTFKeyword::LINECONT:
916 auto pValue = new RTFValue(nKeyword == RTFKeyword::LINEPPAGE
917 ? NS_ooxml::LN_Value_ST_LineNumberRestart_newPage
918 : NS_ooxml::LN_Value_ST_LineNumberRestart_continuous);
919 putNestedAttribute(m_aStates.top().getSectionSprms(),
920 NS_ooxml::LN_EG_SectPrContents_lnNumType,
921 NS_ooxml::LN_CT_LineNumber_restart, pValue);
923 break;
924 case RTFKeyword::AENDDOC:
925 // Noop, this is the default in Writer.
926 case RTFKeyword::AENDNOTES:
927 // Noop
928 case RTFKeyword::AFTNRSTCONT:
929 // Noop, this is the default in Writer.
930 case RTFKeyword::AFTNRESTART:
931 // Noop
932 case RTFKeyword::FTNBJ:
933 // Noop, this is the default in Writer.
934 break;
935 case RTFKeyword::ENDDOC:
937 auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_RestartNumber_eachSect);
938 putNestedSprm(m_aDefaultState.getParagraphSprms(),
939 NS_ooxml::LN_EG_SectPrContents_footnotePr,
940 NS_ooxml::LN_EG_FtnEdnNumProps_numRestart, pValue);
942 break;
943 case RTFKeyword::NOLINE:
944 eraseNestedAttribute(m_aStates.top().getSectionSprms(),
945 NS_ooxml::LN_EG_SectPrContents_lnNumType,
946 NS_ooxml::LN_CT_LineNumber_distance);
947 break;
948 case RTFKeyword::FORMSHADE:
949 // Noop, this is the default in Writer.
950 break;
951 case RTFKeyword::PNGBLIP:
952 m_aStates.top().getPicture().eStyle = RTFBmpStyle::PNG;
953 break;
954 case RTFKeyword::JPEGBLIP:
955 m_aStates.top().getPicture().eStyle = RTFBmpStyle::JPEG;
956 break;
957 case RTFKeyword::POSYT:
958 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_yAlign,
959 NS_ooxml::LN_Value_doc_ST_YAlign_top);
960 break;
961 case RTFKeyword::POSYB:
962 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_yAlign,
963 NS_ooxml::LN_Value_doc_ST_YAlign_bottom);
964 break;
965 case RTFKeyword::POSYC:
966 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_yAlign,
967 NS_ooxml::LN_Value_doc_ST_YAlign_center);
968 break;
969 case RTFKeyword::POSYIN:
970 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_yAlign,
971 NS_ooxml::LN_Value_doc_ST_YAlign_inside);
972 break;
973 case RTFKeyword::POSYOUT:
974 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_yAlign,
975 NS_ooxml::LN_Value_doc_ST_YAlign_outside);
976 break;
977 case RTFKeyword::POSYIL:
978 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_yAlign,
979 NS_ooxml::LN_Value_doc_ST_YAlign_inline);
980 break;
982 case RTFKeyword::PHMRG:
983 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_hAnchor,
984 NS_ooxml::LN_Value_doc_ST_HAnchor_margin);
985 break;
986 case RTFKeyword::PVMRG:
987 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_vAnchor,
988 NS_ooxml::LN_Value_doc_ST_VAnchor_margin);
989 break;
990 case RTFKeyword::PHPG:
991 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_hAnchor,
992 NS_ooxml::LN_Value_doc_ST_HAnchor_page);
993 break;
994 case RTFKeyword::PVPG:
995 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_vAnchor,
996 NS_ooxml::LN_Value_doc_ST_VAnchor_page);
997 break;
998 case RTFKeyword::PHCOL:
999 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_hAnchor,
1000 NS_ooxml::LN_Value_doc_ST_HAnchor_text);
1001 break;
1002 case RTFKeyword::PVPARA:
1003 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_vAnchor,
1004 NS_ooxml::LN_Value_doc_ST_VAnchor_text);
1005 break;
1007 case RTFKeyword::POSXC:
1008 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_xAlign,
1009 NS_ooxml::LN_Value_doc_ST_XAlign_center);
1010 break;
1011 case RTFKeyword::POSXI:
1012 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_xAlign,
1013 NS_ooxml::LN_Value_doc_ST_XAlign_inside);
1014 break;
1015 case RTFKeyword::POSXO:
1016 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_xAlign,
1017 NS_ooxml::LN_Value_doc_ST_XAlign_outside);
1018 break;
1019 case RTFKeyword::POSXL:
1020 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_xAlign,
1021 NS_ooxml::LN_Value_doc_ST_XAlign_left);
1022 break;
1023 case RTFKeyword::POSXR:
1024 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_xAlign,
1025 NS_ooxml::LN_Value_doc_ST_XAlign_right);
1026 break;
1028 case RTFKeyword::DPLINE:
1029 case RTFKeyword::DPRECT:
1030 case RTFKeyword::DPELLIPSE:
1031 case RTFKeyword::DPTXBX:
1032 case RTFKeyword::DPPOLYLINE:
1033 case RTFKeyword::DPPOLYGON:
1035 sal_Int32 nType = 0;
1036 switch (nKeyword)
1038 case RTFKeyword::DPLINE:
1040 uno::Reference<drawing::XShape> xShape(
1041 getModelFactory()->createInstance("com.sun.star.drawing.LineShape"),
1042 uno::UNO_QUERY);
1043 m_aStates.top().getDrawingObject().setShape(xShape);
1044 break;
1046 case RTFKeyword::DPPOLYLINE:
1048 // The reason this is not a simple CustomShape is that in the old syntax we have no ViewBox info.
1049 uno::Reference<drawing::XShape> xShape(
1050 getModelFactory()->createInstance("com.sun.star.drawing.PolyLineShape"),
1051 uno::UNO_QUERY);
1052 m_aStates.top().getDrawingObject().setShape(xShape);
1053 break;
1055 case RTFKeyword::DPPOLYGON:
1057 uno::Reference<drawing::XShape> xShape(
1058 getModelFactory()->createInstance("com.sun.star.drawing.PolyPolygonShape"),
1059 uno::UNO_QUERY);
1060 m_aStates.top().getDrawingObject().setShape(xShape);
1061 break;
1063 case RTFKeyword::DPRECT:
1065 uno::Reference<drawing::XShape> xShape(
1066 getModelFactory()->createInstance("com.sun.star.drawing.RectangleShape"),
1067 uno::UNO_QUERY);
1068 m_aStates.top().getDrawingObject().setShape(xShape);
1069 break;
1071 case RTFKeyword::DPELLIPSE:
1072 nType = ESCHER_ShpInst_Ellipse;
1073 break;
1074 case RTFKeyword::DPTXBX:
1076 uno::Reference<drawing::XShape> xShape(
1077 getModelFactory()->createInstance("com.sun.star.text.TextFrame"),
1078 uno::UNO_QUERY);
1079 m_aStates.top().getDrawingObject().setShape(xShape);
1080 std::vector<beans::PropertyValue> aDefaults
1081 = RTFSdrImport::getTextFrameDefaults(false);
1082 for (const auto& rDefault : aDefaults)
1084 if (!findPropertyName(
1085 m_aStates.top().getDrawingObject().getPendingProperties(),
1086 rDefault.Name))
1087 m_aStates.top().getDrawingObject().getPendingProperties().push_back(
1088 rDefault);
1090 checkFirstRun();
1091 Mapper().startShape(m_aStates.top().getDrawingObject().getShape());
1092 m_aStates.top().getDrawingObject().setHadShapeText(true);
1094 break;
1095 default:
1096 break;
1098 if (nType)
1100 uno::Reference<drawing::XShape> xShape(
1101 getModelFactory()->createInstance("com.sun.star.drawing.CustomShape"),
1102 uno::UNO_QUERY);
1103 m_aStates.top().getDrawingObject().setShape(xShape);
1105 uno::Reference<drawing::XDrawPageSupplier> xDrawSupplier(m_xDstDoc, uno::UNO_QUERY);
1106 uno::Reference<beans::XPropertySet> xPropertySet(
1107 m_aStates.top().getDrawingObject().getShape(), uno::UNO_QUERY);
1108 m_aStates.top().getDrawingObject().setPropertySet(xPropertySet);
1109 if (xDrawSupplier.is())
1111 uno::Reference<drawing::XShapes> xShapes = xDrawSupplier->getDrawPage();
1112 if (xShapes.is() && nKeyword != RTFKeyword::DPTXBX)
1114 // set default VertOrient before inserting
1115 m_aStates.top().getDrawingObject().getPropertySet()->setPropertyValue(
1116 "VertOrient", uno::Any(text::VertOrientation::NONE));
1117 xShapes->add(m_aStates.top().getDrawingObject().getShape());
1120 if (nType)
1122 uno::Reference<drawing::XEnhancedCustomShapeDefaulter> xDefaulter(
1123 m_aStates.top().getDrawingObject().getShape(), uno::UNO_QUERY);
1124 xDefaulter->createCustomShapeDefaults(OUString::number(nType));
1126 std::vector<beans::PropertyValue>& rPendingProperties
1127 = m_aStates.top().getDrawingObject().getPendingProperties();
1128 for (const auto& rPendingProperty : rPendingProperties)
1129 m_aStates.top().getDrawingObject().getPropertySet()->setPropertyValue(
1130 rPendingProperty.Name, rPendingProperty.Value);
1131 m_pSdrImport->resolveDhgt(m_aStates.top().getDrawingObject().getPropertySet(),
1132 m_aStates.top().getDrawingObject().getDhgt(),
1133 /*bOldStyle=*/true);
1135 break;
1136 case RTFKeyword::DOBXMARGIN:
1137 case RTFKeyword::DOBYMARGIN:
1139 beans::PropertyValue aPropertyValue;
1140 aPropertyValue.Name
1141 = (nKeyword == RTFKeyword::DOBXMARGIN ? std::u16string_view(u"HoriOrientRelation")
1142 : std::u16string_view(u"VertOrientRelation"));
1143 aPropertyValue.Value <<= text::RelOrientation::PAGE_PRINT_AREA;
1144 m_aStates.top().getDrawingObject().getPendingProperties().push_back(aPropertyValue);
1146 break;
1147 case RTFKeyword::DOBXPAGE:
1148 case RTFKeyword::DOBYPAGE:
1150 beans::PropertyValue aPropertyValue;
1151 aPropertyValue.Name
1152 = (nKeyword == RTFKeyword::DOBXPAGE ? std::u16string_view(u"HoriOrientRelation")
1153 : std::u16string_view(u"VertOrientRelation"));
1154 aPropertyValue.Value <<= text::RelOrientation::PAGE_FRAME;
1155 m_aStates.top().getDrawingObject().getPendingProperties().push_back(aPropertyValue);
1157 break;
1158 case RTFKeyword::DOBYPARA:
1160 beans::PropertyValue aPropertyValue;
1161 aPropertyValue.Name = "VertOrientRelation";
1162 aPropertyValue.Value <<= text::RelOrientation::FRAME;
1163 m_aStates.top().getDrawingObject().getPendingProperties().push_back(aPropertyValue);
1165 break;
1166 case RTFKeyword::CONTEXTUALSPACE:
1168 auto pValue = new RTFValue(1);
1169 m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_contextualSpacing,
1170 pValue);
1172 break;
1173 case RTFKeyword::LINKSTYLES:
1175 auto pValue = new RTFValue(1);
1176 m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_linkStyles, pValue);
1178 break;
1179 case RTFKeyword::PNLVLBODY:
1181 auto pValue = new RTFValue(2);
1182 m_aStates.top().getTableAttributes().set(NS_ooxml::LN_CT_AbstractNum_nsid, pValue);
1184 break;
1185 case RTFKeyword::PNDEC:
1187 auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_NumberFormat_decimal);
1188 putNestedAttribute(m_aStates.top().getTableSprms(), NS_ooxml::LN_CT_Lvl_numFmt,
1189 NS_ooxml::LN_CT_NumFmt_val, pValue);
1191 break;
1192 case RTFKeyword::PNLVLBLT:
1194 m_aStates.top().getTableAttributes().set(NS_ooxml::LN_CT_AbstractNum_nsid,
1195 new RTFValue(1));
1196 putNestedAttribute(m_aStates.top().getTableSprms(), NS_ooxml::LN_CT_Lvl_numFmt,
1197 NS_ooxml::LN_CT_NumFmt_val,
1198 new RTFValue(NS_ooxml::LN_Value_ST_NumberFormat_bullet));
1200 break;
1201 case RTFKeyword::LANDSCAPE:
1203 auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_PageOrientation_landscape);
1204 putNestedAttribute(m_aDefaultState.getSectionSprms(),
1205 NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_orient,
1206 pValue);
1207 [[fallthrough]]; // set the default + current value
1209 case RTFKeyword::LNDSCPSXN:
1211 auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_PageOrientation_landscape);
1212 putNestedAttribute(m_aStates.top().getSectionSprms(),
1213 NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_orient,
1214 pValue);
1216 break;
1217 case RTFKeyword::SHPBXPAGE:
1218 m_aStates.top().getShape().setHoriOrientRelation(text::RelOrientation::PAGE_FRAME);
1219 m_aStates.top().getShape().setHoriOrientRelationToken(
1220 NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_page);
1221 break;
1222 case RTFKeyword::SHPBYPAGE:
1223 m_aStates.top().getShape().setVertOrientRelation(text::RelOrientation::PAGE_FRAME);
1224 m_aStates.top().getShape().setVertOrientRelationToken(
1225 NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_page);
1226 break;
1227 case RTFKeyword::DPLINEHOLLOW:
1228 m_aStates.top().getDrawingObject().setFLine(0);
1229 break;
1230 case RTFKeyword::DPROUNDR:
1231 if (m_aStates.top().getDrawingObject().getPropertySet().is())
1232 // Seems this old syntax has no way to specify a custom radius, and this is the default
1233 m_aStates.top().getDrawingObject().getPropertySet()->setPropertyValue(
1234 "CornerRadius", uno::Any(sal_Int32(83)));
1235 break;
1236 case RTFKeyword::NOWRAP:
1237 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_wrap,
1238 NS_ooxml::LN_Value_doc_ST_Wrap_notBeside);
1239 break;
1240 case RTFKeyword::OVERLAY:
1241 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_wrap,
1242 NS_ooxml::LN_Value_doc_ST_Wrap_none);
1243 break;
1244 case RTFKeyword::WRAPAROUND:
1245 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_wrap,
1246 NS_ooxml::LN_Value_doc_ST_Wrap_around);
1247 break;
1248 case RTFKeyword::WRAPTHROUGH:
1249 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_wrap,
1250 NS_ooxml::LN_Value_doc_ST_Wrap_through);
1251 break;
1252 case RTFKeyword::WRAPTIGHT:
1253 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_wrap,
1254 NS_ooxml::LN_Value_doc_ST_Wrap_tight);
1255 break;
1256 case RTFKeyword::WRAPDEFAULT:
1257 m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_wrap,
1258 NS_ooxml::LN_Value_doc_ST_Wrap_auto);
1259 break;
1260 case RTFKeyword::MNOR:
1261 m_bMathNor = true;
1262 break;
1263 case RTFKeyword::REVISIONS:
1264 m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_trackRevisions, new RTFValue(1));
1265 break;
1266 case RTFKeyword::BRDRSH:
1267 putBorderProperty(m_aStates, NS_ooxml::LN_CT_Border_shadow, new RTFValue(1));
1268 break;
1269 case RTFKeyword::NOCOLBAL:
1270 m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Compat_noColumnBalance, new RTFValue(1));
1271 break;
1272 case RTFKeyword::MARGMIRROR:
1273 m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_mirrorMargins, new RTFValue(1));
1274 break;
1275 case RTFKeyword::SAUTOUPD:
1276 m_aStates.top().getTableSprms().set(NS_ooxml::LN_CT_Style_autoRedefine,
1277 new RTFValue(1));
1278 break;
1279 case RTFKeyword::WIDOWCTRL:
1280 m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_widowControl, new RTFValue(1));
1281 break;
1282 case RTFKeyword::LINEBETCOL:
1283 putNestedAttribute(m_aStates.top().getSectionSprms(),
1284 NS_ooxml::LN_EG_SectPrContents_cols, NS_ooxml::LN_CT_Columns_sep,
1285 new RTFValue(1));
1286 break;
1287 case RTFKeyword::PGNRESTART:
1288 putNestedAttribute(m_aStates.top().getSectionSprms(),
1289 NS_ooxml::LN_EG_SectPrContents_pgNumType,
1290 NS_ooxml::LN_CT_PageNumber_start, new RTFValue(1));
1291 break;
1292 case RTFKeyword::PGNUCLTR:
1294 auto pIntValue = new RTFValue(NS_ooxml::LN_Value_ST_NumberFormat_upperLetter);
1295 putNestedAttribute(m_aStates.top().getSectionSprms(),
1296 NS_ooxml::LN_EG_SectPrContents_pgNumType,
1297 NS_ooxml::LN_CT_PageNumber_fmt, pIntValue);
1299 break;
1300 case RTFKeyword::PGNLCLTR:
1302 auto pIntValue = new RTFValue(NS_ooxml::LN_Value_ST_NumberFormat_lowerLetter);
1303 putNestedAttribute(m_aStates.top().getSectionSprms(),
1304 NS_ooxml::LN_EG_SectPrContents_pgNumType,
1305 NS_ooxml::LN_CT_PageNumber_fmt, pIntValue);
1307 break;
1308 case RTFKeyword::PGNUCRM:
1310 auto pIntValue = new RTFValue(NS_ooxml::LN_Value_ST_NumberFormat_upperRoman);
1311 putNestedAttribute(m_aStates.top().getSectionSprms(),
1312 NS_ooxml::LN_EG_SectPrContents_pgNumType,
1313 NS_ooxml::LN_CT_PageNumber_fmt, pIntValue);
1315 break;
1316 case RTFKeyword::PGNLCRM:
1318 auto pIntValue = new RTFValue(NS_ooxml::LN_Value_ST_NumberFormat_lowerRoman);
1319 putNestedAttribute(m_aStates.top().getSectionSprms(),
1320 NS_ooxml::LN_EG_SectPrContents_pgNumType,
1321 NS_ooxml::LN_CT_PageNumber_fmt, pIntValue);
1323 break;
1324 case RTFKeyword::PGNDEC:
1326 auto pIntValue = new RTFValue(NS_ooxml::LN_Value_ST_NumberFormat_decimal);
1327 putNestedAttribute(m_aStates.top().getSectionSprms(),
1328 NS_ooxml::LN_EG_SectPrContents_pgNumType,
1329 NS_ooxml::LN_CT_PageNumber_fmt, pIntValue);
1331 break;
1332 case RTFKeyword::HTMAUTSP:
1333 m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Compat_doNotUseHTMLParagraphAutoSpacing,
1334 new RTFValue(0));
1335 break;
1336 case RTFKeyword::DNTBLNSBDB:
1337 // tdf#128428 switch off longer space sequence
1338 m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_longerSpaceSequence,
1339 new RTFValue(0));
1340 break;
1341 case RTFKeyword::GUTTERPRL:
1342 m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_gutterAtTop, new RTFValue(1));
1343 break;
1344 case RTFKeyword::RTLGUTTER:
1346 m_aStates.top().getSectionSprms().set(NS_ooxml::LN_EG_SectPrContents_rtlGutter,
1347 new RTFValue(1));
1349 break;
1350 case RTFKeyword::FLDLOCK:
1352 if (m_aStates.top().getDestination() == Destination::FIELD)
1353 m_aStates.top().setFieldLocked(true);
1355 break;
1356 case RTFKeyword::NOBRKWRPTBL:
1358 m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Compat_doNotBreakWrappedTables,
1359 new RTFValue(0));
1361 break;
1362 case RTFKeyword::SPLTPGPAR:
1364 // if flag is present, it is turned *off* - opposite to what spec says
1365 m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Compat_splitPgBreakAndParaMark,
1366 new RTFValue(0));
1368 break;
1369 default:
1371 SAL_INFO("writerfilter", "TODO handle flag '" << keywordToString(nKeyword) << "'");
1372 aSkip.setParsed(false);
1374 break;
1376 return RTFError::OK;
1379 } // namespace writerfilter
1381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */