Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_WRITERFILTER_INC_RESOURCEMODEL_TABLEMANAGER_HXX
21 : #define INCLUDED_WRITERFILTER_INC_RESOURCEMODEL_TABLEMANAGER_HXX
22 :
23 : #include <resourcemodel/TableData.hxx>
24 :
25 : #include <resourcemodel/WW8ResourceModel.hxx>
26 :
27 : #include <ooxml/resourceids.hxx>
28 :
29 : #include <boost/shared_ptr.hpp>
30 : #include <stack>
31 : #include "util.hxx"
32 : #include "TagLogger.hxx"
33 :
34 : #include <rtl/strbuf.hxx>
35 :
36 : namespace writerfilter
37 : {
38 :
39 : /**
40 : Class to handle events generated by TableManager::resolveCurrentTable
41 : */
42 : template <typename T, typename PropertiesPointer>
43 3530 : class TableDataHandler
44 : {
45 : public:
46 : typedef boost::shared_ptr<TableDataHandler> Pointer_t;
47 :
48 : /**
49 : Handle start of table.
50 :
51 : @param nRows number of rows in the table
52 : @param nDepth depth of the table in surrounding table hierarchy
53 : @param pProps properties of the table
54 : */
55 : virtual void startTable(unsigned int nRows, unsigned int nDepth,
56 : PropertiesPointer pProps) = 0;
57 :
58 : /**
59 : Handle end of table.
60 : */
61 : virtual void endTable(unsigned int nestedTableLevel) = 0;
62 :
63 : /**
64 : Handle start of row.
65 :
66 : @param nCols number of columns in the table
67 : @param pProps properties of the row
68 : */
69 : virtual void startRow(unsigned int nCols,
70 : PropertiesPointer pProps) = 0;
71 :
72 : /**
73 : Handle end of row.
74 : */
75 : virtual void endRow() = 0;
76 :
77 : /**
78 : Handle start of cell.
79 :
80 : @param rT start handle of the cell
81 : @param pProps properties of the cell
82 : */
83 : virtual void startCell(const T & rT, PropertiesPointer pProps) = 0;
84 :
85 : /**
86 : Handle end of cell.
87 :
88 : @param rT end handle of cell
89 : */
90 : virtual void endCell(const T & rT) = 0;
91 :
92 : protected:
93 3530 : ~TableDataHandler() {}
94 : };
95 :
96 : template <typename T, typename PropertiesPointer>
97 : /**
98 : The table manager.
99 :
100 : This class gets forwarded events from the tokenizer. It gathers the
101 : table data and after ending the table generates events for the
102 : table structure. The events have to be handles by a TableDataHandler.
103 :
104 : */
105 : class TableManager
106 : {
107 : #ifdef DEBUG_WRITERFILTER
108 : TagLogger::Pointer_t mpTableLogger;
109 : #endif
110 :
111 : class TableManagerState
112 : {
113 : /**
114 : properties at the current point in document
115 : */
116 : PropertiesPointer mpProps;
117 :
118 : /**
119 : properties of the current cell
120 : */
121 : PropertiesPointer mpCellProps;
122 :
123 : /**
124 : properties of the current row
125 : */
126 : PropertiesPointer mpRowProps;
127 :
128 : /**
129 : properties of the current table
130 : */
131 : std::stack<PropertiesPointer> mTableProps;
132 :
133 : /**
134 : true if at the end of a row
135 : */
136 : bool mbRowEnd;
137 :
138 : /**
139 : true when in a cell
140 : */
141 : bool mbInCell;
142 :
143 : /**
144 : true when at the end of a cell
145 : */
146 : bool mbCellEnd;
147 :
148 : public:
149 : /**
150 : Constructor
151 : */
152 9026 : TableManagerState()
153 9026 : : mbRowEnd(false), mbInCell(false), mbCellEnd(false)
154 : {
155 9026 : }
156 :
157 9026 : virtual ~TableManagerState()
158 : {
159 9026 : }
160 :
161 10166 : void startLevel()
162 : {
163 10166 : PropertiesPointer pProps;
164 10166 : mTableProps.push(pProps);
165 10166 : }
166 :
167 10110 : void endLevel()
168 : {
169 10110 : mTableProps.pop();
170 10110 : }
171 :
172 : /**
173 : Reset to initial state at beginning of row.
174 : */
175 57266 : void resetCellSpecifics()
176 : {
177 57266 : mbRowEnd = false;
178 57266 : mbInCell = false;
179 57266 : mbCellEnd = false;
180 57266 : }
181 :
182 : void resetProps()
183 : {
184 : mpProps.reset();
185 : }
186 :
187 0 : void setProps(PropertiesPointer pProps)
188 : {
189 0 : mpProps = pProps;
190 0 : }
191 :
192 : PropertiesPointer getProps()
193 : {
194 : return mpProps;
195 : }
196 :
197 22344 : void resetCellProps()
198 : {
199 22344 : mpCellProps.reset();
200 22344 : }
201 :
202 11096 : void setCellProps(PropertiesPointer pProps)
203 : {
204 11096 : mpCellProps = pProps;
205 11096 : }
206 :
207 75238 : PropertiesPointer getCellProps()
208 : {
209 75238 : return mpCellProps;
210 : }
211 :
212 5440 : void resetRowProps()
213 : {
214 5440 : mpRowProps.reset();
215 5440 : }
216 :
217 5398 : void setRowProps(PropertiesPointer pProps)
218 : {
219 5398 : mpRowProps = pProps;
220 5398 : }
221 :
222 18058 : PropertiesPointer getRowProps()
223 : {
224 18058 : return mpRowProps;
225 : }
226 :
227 10110 : void resetTableProps()
228 : {
229 10110 : if (mTableProps.size() > 0)
230 10110 : mTableProps.top().reset();
231 10110 : }
232 :
233 1114 : void setTableProps(PropertiesPointer pProps)
234 : {
235 1114 : if (mTableProps.size() > 0)
236 1114 : mTableProps.top() = pProps;
237 1114 : }
238 :
239 24202 : PropertiesPointer getTableProps()
240 : {
241 24202 : PropertiesPointer pResult;
242 :
243 24202 : if (mTableProps.size() > 0)
244 24202 : pResult = mTableProps.top();
245 :
246 24202 : return pResult;
247 : }
248 :
249 45772 : void setInCell(bool bInCell)
250 : {
251 45772 : mbInCell = bInCell;
252 45772 : }
253 :
254 70304 : bool isInCell() const
255 : {
256 70304 : return mbInCell;
257 : }
258 :
259 24128 : void setCellEnd(bool bCellEnd)
260 : {
261 24128 : mbCellEnd = bCellEnd;
262 24128 : }
263 :
264 16904 : bool isCellEnd() const
265 : {
266 16904 : return mbCellEnd;
267 : }
268 :
269 17198 : void setRowEnd(bool bRowEnd)
270 : {
271 17198 : mbRowEnd = bRowEnd;
272 17198 : }
273 :
274 170528 : bool isRowEnd() const
275 : {
276 170528 : return mbRowEnd;
277 : }
278 : };
279 :
280 : /**
281 : handle for the current position in document
282 : */
283 : T mCurHandle;
284 :
285 : TableManagerState mState;
286 :
287 : protected:
288 : PropertiesPointer getProps()
289 : {
290 : return mState.getProps();
291 : }
292 :
293 0 : void setProps(PropertiesPointer pProps)
294 : {
295 0 : mState.setProps(pProps);
296 0 : }
297 :
298 : void resetProps()
299 : {
300 : mState.resetProps();
301 : }
302 :
303 75238 : PropertiesPointer getCellProps()
304 : {
305 75238 : return mState.getCellProps();
306 : }
307 :
308 11096 : void setCellProps(PropertiesPointer pProps)
309 : {
310 11096 : mState.setCellProps(pProps);
311 11096 : }
312 :
313 22344 : void resetCellProps()
314 : {
315 22344 : mState.resetCellProps();
316 22344 : }
317 :
318 18058 : PropertiesPointer getRowProps()
319 : {
320 18058 : return mState.getRowProps();
321 : }
322 :
323 5398 : void setRowProps(PropertiesPointer pProps)
324 : {
325 5398 : mState.setRowProps(pProps);
326 5398 : }
327 :
328 5440 : void resetRowProps()
329 : {
330 5440 : mState.resetRowProps();
331 5440 : }
332 :
333 45772 : void setInCell(bool bInCell)
334 : {
335 45772 : mState.setInCell(bInCell);
336 45772 : }
337 :
338 70304 : bool isInCell() const
339 : {
340 70304 : return mState.isInCell();
341 : }
342 :
343 24128 : void setCellEnd(bool bCellEnd)
344 : {
345 24128 : mState.setCellEnd(bCellEnd);
346 24128 : }
347 :
348 16904 : bool isCellEnd() const
349 : {
350 16904 : return mState.isCellEnd();
351 : }
352 :
353 17198 : void setRowEnd(bool bRowEnd)
354 : {
355 17198 : mState.setRowEnd(bRowEnd);
356 17198 : }
357 :
358 170528 : bool isRowEnd() const
359 : {
360 170528 : return mState.isRowEnd();
361 : }
362 :
363 24202 : PropertiesPointer getTableProps()
364 : {
365 24202 : return mState.getTableProps();
366 : }
367 :
368 1114 : void setTableProps(PropertiesPointer pProps)
369 : {
370 1114 : mState.setTableProps(pProps);
371 1114 : }
372 :
373 10110 : void resetTableProps()
374 : {
375 10110 : mState.resetTableProps();
376 10110 : }
377 :
378 31016 : T getHandle()
379 : {
380 31016 : return mCurHandle;
381 : }
382 :
383 48526 : void setHandle(const T & rHandle)
384 : {
385 48526 : mCurHandle = rHandle;
386 48526 : }
387 :
388 : private:
389 : typedef boost::shared_ptr<T> T_p;
390 :
391 : /**
392 : depth of the current cell
393 : */
394 : sal_uInt32 mnTableDepthNew;
395 :
396 : /**
397 : depth of the previous cell
398 : */
399 : sal_uInt32 mnTableDepth;
400 :
401 : /**
402 : stack of table data
403 :
404 : for each level of nested tables there is one frame in the stack
405 : */
406 : std::stack<typename TableData<T, PropertiesPointer>::Pointer_t > mTableDataStack;
407 : typename RowData<T, PropertiesPointer>::Pointer_t mpUnfinishedRow;
408 : bool mbKeepUnfinishedRow;
409 :
410 : typedef typename TableDataHandler<T, PropertiesPointer>::Pointer_t TableDataHandlerPointer_t;
411 :
412 : /**
413 : handler for resolveCurrentTable
414 : */
415 : TableDataHandlerPointer_t mpTableDataHandler;
416 :
417 : /**
418 : Set flag which indicates the current handle is in a cell.
419 : */
420 : void inCell();
421 :
422 : /**
423 : Set flag which indicate the current handle is at the end of a cell.
424 : */
425 : void endCell();
426 :
427 : /**
428 : Set the table depth of the current cell.
429 :
430 : @param nDepth the cell depth
431 : */
432 : void cellDepth(sal_uInt32 nDepth);
433 :
434 : /**
435 : Set flag indication the current handle is at the end of a row.
436 : */
437 : void endRow();
438 :
439 : /**
440 : Resolve the current table to the TableDataHandler.
441 : */
442 : void resolveCurrentTable();
443 :
444 : /**
445 : Open a cell at current level.
446 : */
447 :
448 : void openCell(const T & handle, PropertiesPointer pProps);
449 :
450 : /**
451 : Close a cell at current level.
452 : */
453 : void closeCell(const T & handle);
454 :
455 : /**
456 : Ensure a cell is open at the current level.
457 : */
458 : void ensureOpenCell(PropertiesPointer pProps);
459 :
460 : protected:
461 :
462 : /**
463 : Return current table depth.
464 : */
465 : sal_uInt32 getTableDepthNew() { return mnTableDepthNew; }
466 :
467 : /**
468 : Return the current table difference, i.e. 1 if we are in the first cell of a new table, etc.
469 : */
470 14388 : sal_uInt32 getTableDepthDifference() { return mnTableDepthNew - mnTableDepth; }
471 :
472 : /**
473 : Action to be carried out at the end of the last paragraph of a
474 : cell.
475 : */
476 : virtual void endOfCellAction();
477 :
478 : /**
479 : Action to be carried out at the end of the "table row"
480 : paragraph.
481 : */
482 : virtual void endOfRowAction();
483 : /** let the derived class clear their table related data
484 : */
485 : virtual void clearData();
486 :
487 : /** Should we keep the unfinished row in endLevel to initialize the table
488 : data in the following startLevel.
489 : */
490 20 : void setKeepUnfinishedRow(bool bKeep)
491 : {
492 20 : mbKeepUnfinishedRow = bKeep;
493 20 : }
494 :
495 :
496 : public:
497 : TableManager();
498 9026 : virtual ~TableManager(){}
499 :
500 : /**
501 : Set handler for resolveCurrentTable.
502 :
503 : @param pTableDataHandler the handler
504 : */
505 : void setHandler(TableDataHandlerPointer_t pTableDataHandler);
506 :
507 : /**
508 : Set the current handle.
509 :
510 : @param rHandle the handle
511 : */
512 : virtual void handle(const T & rHandle);
513 :
514 : /**
515 : Start a new table level.
516 :
517 : A new context is pushed onto the table data stack,
518 : */
519 : virtual void startLevel();
520 :
521 : /**
522 : End a table level.
523 :
524 : The current table is resolved and the context is popped from
525 : the stack.
526 : */
527 : virtual void endLevel();
528 :
529 : /**
530 : * Signal that the next paragraph definitely won't be part of any table.
531 : */
532 2728 : void endTable()
533 : {
534 2728 : setRowEnd(false);
535 2728 : }
536 :
537 : /**
538 : Tells whether a table has been started or not
539 : */
540 : bool isInTable();
541 :
542 : /**
543 : Handle the start of a paragraph group.
544 : */
545 : virtual void startParagraphGroup();
546 :
547 : /**
548 : Handle the end of a paragraph group.
549 : */
550 : virtual void endParagraphGroup();
551 :
552 : /**
553 : Handle an SPRM at curent handle.
554 :
555 : @param rSprm the SPRM
556 : */
557 : virtual bool sprm(Sprm & rSprm);
558 :
559 : /**
560 : Handle properties at current handle.
561 :
562 : @param pProps the properites
563 : */
564 : virtual void props(PropertiesPointer pProps);
565 :
566 : /**
567 : Handle occurrence of character 0x7.
568 : */
569 : virtual void handle0x7();
570 :
571 : /**
572 : Handle 8 bit text at current handle.
573 :
574 : @param data array of characters
575 : @param len number of characters to handle
576 : */
577 : virtual void text(const sal_uInt8 * data, size_t len);
578 :
579 : /**
580 : Handle 16 bit text at current handle.
581 :
582 : @param data array of characters
583 : @param len number of characters to handle
584 : */
585 : virtual void utext(const sal_uInt8 * data, size_t len);
586 :
587 : /**
588 : Handle properties of the current cell.
589 :
590 : @param pProps the properties
591 : */
592 : virtual void cellProps(PropertiesPointer pProps);
593 :
594 : /**
595 : Handle properties of a certain cell in the current row.
596 :
597 : @paran i index of the cell in the current row
598 : @param pProps the properties
599 : */
600 : virtual void cellPropsByCell(unsigned int i, PropertiesPointer pProps);
601 :
602 : /**
603 : Handle properties of the current row.
604 :
605 : @param pProps the properties
606 : */
607 : virtual void insertRowProps(PropertiesPointer pProps);
608 :
609 : /**
610 : Handle properties of the current table.
611 :
612 : @param pProps the properties
613 : */
614 : virtual void insertTableProps(PropertiesPointer pProps);
615 :
616 : /**
617 : Return if table manager has detected paragraph to ignore.
618 :
619 : If this function returns true the current paragraph contains
620 : only control information, e.g. end of row.
621 : */
622 : virtual bool isIgnore() const;
623 :
624 :
625 : #ifdef DEBUG_WRITERFILTER
626 : void setTagLogger(TagLogger::Pointer_t _tagLogger)
627 : {
628 : mpTableLogger = _tagLogger;
629 : }
630 : #endif
631 : };
632 :
633 : template <typename T, typename PropertiesPointer>
634 9026 : TableManager<T, PropertiesPointer>::TableManager()
635 9026 : : mnTableDepthNew(0), mnTableDepth(0), mbKeepUnfinishedRow( false )
636 : {
637 9026 : setRowEnd(false);
638 9026 : setInCell(false);
639 9026 : setCellEnd(false);
640 9026 : }
641 :
642 : template <typename T, typename PropertiesPointer>
643 36246 : void TableManager<T, PropertiesPointer>::cellDepth(sal_uInt32 nDepth)
644 : {
645 : #ifdef DEBUG_WRITERFILTER
646 : if (mpTableLogger != nullptr)
647 : {
648 : mpTableLogger->startElement("tablemanager.cellDepth");
649 : mpTableLogger->attribute("depth", nDepth);
650 : mpTableLogger->endElement();
651 : }
652 : #endif
653 :
654 36246 : mnTableDepthNew = nDepth;
655 36246 : }
656 :
657 : template <typename T, typename PropertiesPointer>
658 36746 : void TableManager<T, PropertiesPointer>::inCell()
659 : {
660 : #ifdef DEBUG_WRITERFILTER
661 : if (mpTableLogger != nullptr)
662 : mpTableLogger->element("tablemanager.inCell");
663 : #endif
664 36746 : setInCell(true);
665 :
666 36746 : if (mnTableDepthNew < 1)
667 852 : mnTableDepthNew = 1;
668 36746 : }
669 :
670 : template <typename T, typename PropertiesPointer>
671 15102 : void TableManager<T, PropertiesPointer>::endCell()
672 : {
673 : #ifdef DEBUG_WRITERFILTER
674 : if (mpTableLogger != nullptr)
675 : mpTableLogger->element("tablemanager.endCell");
676 : #endif
677 :
678 15102 : setCellEnd(true);
679 15102 : }
680 :
681 : template <typename T, typename PropertiesPointer>
682 5444 : void TableManager<T, PropertiesPointer>::endRow()
683 : {
684 : #ifdef DEBUG_WRITERFILTER
685 : if (mpTableLogger != nullptr)
686 : mpTableLogger->element("tablemanager.endRow");
687 : #endif
688 :
689 5444 : setRowEnd(true);
690 5444 : }
691 :
692 : template <typename T, typename PropertiesPointer>
693 9024 : void TableManager<T, PropertiesPointer>::setHandler
694 : (typename TableDataHandler<T, PropertiesPointer>::Pointer_t pTableDataHandler)
695 : {
696 9024 : mpTableDataHandler = pTableDataHandler;
697 9024 : }
698 :
699 : template <typename T, typename PropertiesPointer>
700 48526 : void TableManager<T, PropertiesPointer>::handle(const T & rHandle)
701 : {
702 : #ifdef DEBUG_WRITERFILTER
703 : if (mpTableLogger)
704 : {
705 : mpTableLogger->startElement("tablemanager.handle");
706 : mpTableLogger->chars(toString(rHandle));
707 : mpTableLogger->endElement();
708 : }
709 : #endif
710 :
711 48526 : setHandle(rHandle);
712 48526 : }
713 :
714 : template <typename T, typename PropertiesPointer>
715 224 : bool TableManager<T, PropertiesPointer>::isInTable()
716 : {
717 224 : bool bInTable = false;
718 224 : if ( !mTableDataStack.empty() )
719 224 : bInTable = mTableDataStack.top()->getDepth() > 0;
720 224 : return bInTable;
721 : }
722 :
723 : template <typename T, typename PropertiesPointer>
724 10166 : void TableManager<T, PropertiesPointer>::startLevel()
725 : {
726 : #ifdef DEBUG_WRITERFILTER
727 : if (mpTableLogger != nullptr)
728 : {
729 : typename TableData<T, PropertiesPointer>::Pointer_t pTableData;
730 :
731 : if (mTableDataStack.size() > 0)
732 : pTableData = mTableDataStack.top();
733 :
734 : mpTableLogger->startElement("tablemanager.startLevel");
735 : mpTableLogger->attribute("level", mTableDataStack.size());
736 :
737 : if (pTableData.get() != nullptr)
738 : mpTableLogger->attribute("openCell",
739 : pTableData->isCellOpen() ? "yes" : "no");
740 :
741 : mpTableLogger->endElement();
742 : }
743 : #endif
744 :
745 : typename TableData<T, PropertiesPointer>::Pointer_t pTableData
746 10166 : (new TableData<T, PropertiesPointer>(mTableDataStack.size()));
747 :
748 : // If we have an unfinished row stored here, then push it to the new TableData
749 10166 : if ( mpUnfinishedRow )
750 : {
751 26 : for (unsigned int i = 0; i < mpUnfinishedRow->getCellCount(); ++i)
752 : {
753 16 : pTableData->addCell( mpUnfinishedRow->getCellStart(i),
754 : mpUnfinishedRow->getCellProperties(i) );
755 16 : pTableData->endCell( mpUnfinishedRow->getCellEnd(i) );
756 : }
757 10 : mpUnfinishedRow.reset();
758 : }
759 :
760 10166 : mTableDataStack.push(pTableData);
761 10166 : mState.startLevel();
762 10166 : }
763 :
764 : template <typename T, typename PropertiesPointer>
765 10110 : void TableManager<T, PropertiesPointer>::endLevel()
766 : {
767 10110 : if (mpTableDataHandler.get() != nullptr)
768 10110 : resolveCurrentTable();
769 :
770 : // Store the unfinished row as it will be used for the next table
771 10110 : if ( mbKeepUnfinishedRow )
772 10 : mpUnfinishedRow = mTableDataStack.top()->getCurrentRow();
773 10110 : mState.endLevel();
774 10110 : mTableDataStack.pop();
775 :
776 : #ifdef DEBUG_WRITERFILTER
777 : if (mpTableLogger != nullptr)
778 : {
779 : typename TableData<T, PropertiesPointer>::Pointer_t pTableData;
780 :
781 : if (mTableDataStack.size() > 0)
782 : pTableData = mTableDataStack.top();
783 :
784 : mpTableLogger->startElement("tablemanager.endLevel");
785 : mpTableLogger->attribute("level", mTableDataStack.size());
786 :
787 : if (pTableData.get() != nullptr)
788 : mpTableLogger->attribute("openCell",
789 : pTableData->isCellOpen() ? "yes" : "no");
790 :
791 : mpTableLogger->endElement();
792 : }
793 : #endif
794 10110 : }
795 :
796 : template <typename T, typename PropertiesPointer>
797 57266 : void TableManager<T, PropertiesPointer>::startParagraphGroup()
798 : {
799 57266 : mState.resetCellSpecifics();
800 57266 : mnTableDepthNew = 0;
801 57266 : }
802 :
803 : template <typename T, typename PropertiesPointer>
804 57234 : void TableManager<T, PropertiesPointer>::endParagraphGroup()
805 : {
806 57234 : sal_Int32 nTableDepthDifference = mnTableDepthNew - mnTableDepth;
807 :
808 57234 : PropertiesPointer pEmptyProps;
809 :
810 115600 : while (nTableDepthDifference > 0)
811 : {
812 1132 : ensureOpenCell(pEmptyProps);
813 1132 : startLevel();
814 :
815 1132 : --nTableDepthDifference;
816 : }
817 115544 : while (nTableDepthDifference < 0)
818 : {
819 1076 : endLevel();
820 :
821 1076 : ++nTableDepthDifference;
822 : }
823 :
824 57234 : mnTableDepth = mnTableDepthNew;
825 :
826 57234 : if (mnTableDepth > 0)
827 : {
828 : typename TableData<T, PropertiesPointer>::Pointer_t pTableData =
829 22344 : mTableDataStack.top();
830 :
831 22344 : if (isRowEnd())
832 : {
833 5440 : endOfRowAction();
834 5440 : mTableDataStack.top()->endRow(getRowProps());
835 5440 : resetRowProps();
836 : }
837 :
838 16904 : else if (isInCell())
839 : {
840 16904 : ensureOpenCell(getCellProps());
841 :
842 16904 : if (isCellEnd())
843 : {
844 15100 : endOfCellAction();
845 15100 : closeCell(getHandle());
846 : }
847 : }
848 22344 : resetCellProps();
849 57234 : }
850 57234 : }
851 :
852 : template <typename T, typename PropertiesPointer>
853 873252 : bool TableManager<T, PropertiesPointer>::sprm(Sprm & rSprm)
854 : {
855 873252 : bool bRet = true;
856 873252 : switch (rSprm.getId())
857 : {
858 : case NS_ooxml::LN_tblDepth:
859 : {
860 36246 : Value::Pointer_t pValue = rSprm.getValue();
861 :
862 36246 : cellDepth(pValue->getInt());
863 : }
864 36246 : break;
865 : case NS_ooxml::LN_inTbl:
866 36746 : inCell();
867 36746 : break;
868 : case NS_ooxml::LN_tblCell:
869 15102 : endCell();
870 15102 : break;
871 : case NS_ooxml::LN_tblRow:
872 5426 : endRow();
873 5426 : break;
874 : default:
875 779732 : bRet = false;
876 : }
877 873252 : return bRet;
878 : }
879 : template <typename T, typename PropertiesPointer>
880 0 : void TableManager<T, PropertiesPointer>::props(PropertiesPointer pProps)
881 : {
882 0 : setProps(pProps);
883 0 : }
884 :
885 : template <typename T, typename PropertiesPointer>
886 18 : void TableManager<T, PropertiesPointer>::handle0x7()
887 : {
888 : #ifdef DEBUG_WRITERFILTER
889 : if (mpTableLogger != nullptr)
890 : mpTableLogger->startElement("tablemanager.handle0x7");
891 : #endif
892 :
893 18 : if (mnTableDepthNew < 1)
894 14 : mnTableDepthNew = 1;
895 :
896 18 : if (isInCell())
897 0 : endCell();
898 : else
899 18 : endRow();
900 :
901 : #ifdef DEBUG_WRITERFILTER
902 : if (mpTableLogger != nullptr)
903 : mpTableLogger->endElement();
904 : #endif
905 18 : }
906 :
907 : template <typename T, typename PropertiesPointer>
908 0 : void TableManager<T, PropertiesPointer>::text(const sal_uInt8 * data, size_t len)
909 : {
910 : // optimization: cell/row end characters are the last characters in a run
911 0 : if (len > 0)
912 : {
913 0 : if (data[len - 1] == 0x7)
914 0 : handle0x7();
915 : }
916 0 : }
917 :
918 : template <typename T, typename PropertiesPointer>
919 152406 : void TableManager<T, PropertiesPointer>::utext(const sal_uInt8 * data, size_t len)
920 : {
921 : // optimization: cell/row end characters are the last characters in a run
922 :
923 152406 : if (len > 0)
924 : {
925 152406 : sal_Unicode nChar = data[(len - 1) * 2] + (data[(len - 1) * 2 + 1] << 8);
926 152406 : if (nChar == 0x7)
927 18 : handle0x7();
928 : }
929 152406 : }
930 :
931 : template <typename T, typename PropertiesPointer>
932 34652 : void TableManager<T, PropertiesPointer>::cellProps(PropertiesPointer pProps)
933 : {
934 : #ifdef DEBUG_WRITERFILTER
935 : if (mpTableLogger != nullptr)
936 : mpTableLogger->startElement("tablemanager.cellProps");
937 : #endif
938 :
939 34652 : if(getCellProps().get())
940 23556 : getCellProps()->InsertProps(pProps);
941 : else
942 11096 : setCellProps(pProps);
943 :
944 : #ifdef DEBUG_WRITERFILTER
945 : if (mpTableLogger != nullptr)
946 : mpTableLogger->endElement();
947 : #endif
948 34652 : }
949 :
950 : template <typename T, typename PropertiesPointer>
951 0 : void TableManager<T, PropertiesPointer>::cellPropsByCell
952 : (unsigned int i, PropertiesPointer pProps)
953 : {
954 : #ifdef DEBUG_WRITERFILTER
955 : if (mpTableLogger != nullptr)
956 : mpTableLogger->startElement("tablemanager.cellPropsByCell");
957 : #endif
958 :
959 0 : mTableDataStack.top()->insertCellProperties(i, pProps);
960 :
961 : #ifdef DEBUG_WRITERFILTER
962 : if (mpTableLogger != nullptr)
963 : mpTableLogger->endElement();
964 : #endif
965 0 : }
966 :
967 : template <typename T, typename PropertiesPointer>
968 9008 : void TableManager<T, PropertiesPointer>::insertRowProps(PropertiesPointer pProps)
969 : {
970 : #ifdef DEBUG_WRITERFILTER
971 : if (mpTableLogger != nullptr)
972 : mpTableLogger->startElement("tablemanager.insertRowProps");
973 : #endif
974 :
975 9008 : if( getRowProps().get() )
976 3610 : getRowProps()->InsertProps(pProps);
977 : else
978 5398 : setRowProps(pProps);
979 :
980 : #ifdef DEBUG_WRITERFILTER
981 : if (mpTableLogger != nullptr)
982 : mpTableLogger->endElement();
983 : #endif
984 9008 : }
985 :
986 : template <typename T, typename PropertiesPointer>
987 5440 : void TableManager<T, PropertiesPointer>::insertTableProps(PropertiesPointer pProps)
988 : {
989 : #ifdef DEBUG_WRITERFILTER
990 : if (mpTableLogger != nullptr)
991 : mpTableLogger->startElement("tablemanager.insertTableProps");
992 : #endif
993 :
994 5440 : if( getTableProps().get() && getTableProps() != pProps)
995 4326 : getTableProps()->InsertProps(pProps);
996 : else
997 1114 : setTableProps(pProps);
998 :
999 : #ifdef DEBUG_WRITERFILTER
1000 : if (mpTableLogger != nullptr)
1001 : mpTableLogger->endElement();
1002 : #endif
1003 5440 : }
1004 :
1005 : template <typename T, typename PropertiesPointer>
1006 10110 : void TableManager<T, PropertiesPointer>::resolveCurrentTable()
1007 : {
1008 : #ifdef DEBUG_WRITERFILTER
1009 : if (mpTableLogger != nullptr)
1010 : mpTableLogger->startElement("tablemanager.resolveCurrentTable");
1011 : #endif
1012 :
1013 10110 : if (mpTableDataHandler.get() != nullptr)
1014 : {
1015 : try
1016 : {
1017 : typename TableData<T, PropertiesPointer>::Pointer_t
1018 10110 : pTableData = mTableDataStack.top();
1019 :
1020 10110 : unsigned int nRows = pTableData->getRowCount();
1021 :
1022 10110 : mpTableDataHandler->startTable(nRows, pTableData->getDepth(), getTableProps());
1023 :
1024 15550 : for (unsigned int nRow = 0; nRow < nRows; ++nRow)
1025 : {
1026 5440 : typename RowData<T, PropertiesPointer>::Pointer_t pRowData = pTableData->getRow(nRow);
1027 :
1028 5440 : unsigned int nCells = pRowData->getCellCount();
1029 :
1030 5440 : mpTableDataHandler->startRow(nCells, pRowData->getProperties());
1031 :
1032 20536 : for (unsigned int nCell = 0; nCell < nCells; ++nCell)
1033 : {
1034 15104 : mpTableDataHandler->startCell
1035 : (pRowData->getCellStart(nCell),
1036 : pRowData->getCellProperties(nCell));
1037 :
1038 15096 : mpTableDataHandler->endCell(pRowData->getCellEnd(nCell));
1039 : }
1040 :
1041 5436 : mpTableDataHandler->endRow();
1042 : }
1043 :
1044 10110 : mpTableDataHandler->endTable(mTableDataStack.size() - 1);
1045 : }
1046 4 : catch (css::uno::Exception const& e)
1047 : {
1048 : SAL_WARN("writerfilter", "resolving of current table failed with: " << e.Message);
1049 : }
1050 : }
1051 10110 : resetTableProps();
1052 10110 : clearData();
1053 :
1054 : #ifdef DEBUG_WRITERFILTER
1055 : if (mpTableLogger != nullptr)
1056 : mpTableLogger->endElement();
1057 : #endif
1058 10110 : }
1059 :
1060 : template <typename T, typename PropertiesPointer>
1061 0 : void TableManager<T, PropertiesPointer>::endOfCellAction()
1062 : {
1063 0 : }
1064 :
1065 : template <typename T, typename PropertiesPointer>
1066 0 : void TableManager<T, PropertiesPointer>::endOfRowAction()
1067 : {
1068 0 : }
1069 :
1070 : template <typename T, typename PropertiesPointer>
1071 148184 : bool TableManager<T, PropertiesPointer>::isIgnore() const
1072 : {
1073 148184 : return isRowEnd();
1074 : }
1075 :
1076 : template <typename T, typename PropertiesPointer>
1077 0 : void TableManager<T, PropertiesPointer>::clearData()
1078 : {
1079 0 : }
1080 :
1081 : template <typename T, typename PropertiesPointer>
1082 15916 : void TableManager<T, PropertiesPointer>::openCell
1083 : (const T & rHandle, PropertiesPointer pProps)
1084 : {
1085 : #ifdef DEBUG_WRITERFILTER
1086 : mpTableLogger->startElement("tablemanager.openCell");
1087 : mpTableLogger->chars(toString(rHandle));
1088 : mpTableLogger->endElement();
1089 : #endif
1090 :
1091 15916 : if (mTableDataStack.size() > 0)
1092 : {
1093 : typename TableData<T, PropertiesPointer>::Pointer_t
1094 15916 : pTableData = mTableDataStack.top();
1095 :
1096 15916 : pTableData->addCell(rHandle, pProps);
1097 : }
1098 15916 : }
1099 :
1100 : template <typename T, typename PropertiesPointer>
1101 15100 : void TableManager<T, PropertiesPointer>::closeCell
1102 : (const T & rHandle)
1103 : {
1104 : #ifdef DEBUG_WRITERFILTER
1105 : mpTableLogger->startElement("tablemanager.closeCell");
1106 : mpTableLogger->chars(toString(rHandle));
1107 : mpTableLogger->endElement();
1108 : #endif
1109 :
1110 15100 : if (mTableDataStack.size() > 0)
1111 : {
1112 : typename TableData<T, PropertiesPointer>::Pointer_t
1113 15100 : pTableData = mTableDataStack.top();
1114 :
1115 15100 : pTableData->endCell(rHandle);
1116 : }
1117 15100 : }
1118 :
1119 : template <typename T, typename PropertiesPointer>
1120 18036 : void TableManager<T, PropertiesPointer>::ensureOpenCell(PropertiesPointer pProps)
1121 : {
1122 : #ifdef DEBUG_WRITERFILTER
1123 : mpTableLogger->startElement("tablemanager.ensureOpenCell");
1124 : #endif
1125 :
1126 18036 : if (mTableDataStack.size() > 0)
1127 : {
1128 : typename TableData<T, PropertiesPointer>::Pointer_t
1129 18036 : pTableData = mTableDataStack.top();
1130 :
1131 18036 : if (pTableData.get() != nullptr)
1132 : {
1133 18036 : if (!pTableData->isCellOpen())
1134 15916 : openCell(getHandle(), pProps);
1135 : else
1136 2120 : pTableData->insertCellProperties(pProps);
1137 18036 : }
1138 : }
1139 : #ifdef DEBUG_WRITERFILTER
1140 : mpTableLogger->endElement();
1141 : #endif
1142 18036 : }
1143 :
1144 : }
1145 :
1146 : #endif // INCLUDED_WRITERFILTER_INC_RESOURCEMODEL_TABLEMANAGER_HXX
1147 :
1148 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|