1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _ENHANCEDPDFEXPORTHELPER_HXX
25 #define _ENHANCEDPDFEXPORTHELPER_HXX
26 
27 #include <vcl/pdfextoutdevdata.hxx>
28 #include <i18npool/lang.h>
29 #include <swrect.hxx>
30 #include <swtypes.hxx>
31 
32 #include <map>
33 #include <vector>
34 #include <set>
35 
36 namespace vcl
37 {
38     class PDFExtOutDevData;
39 }
40 class OutputDevice;
41 class SwFrm;
42 class SwLinePortion;
43 class SwTxtPainter;
44 class SwEditShell;
45 namespace rtl
46 {
47     class OUString;
48 }
49 class MultiSelection;
50 class SwTxtNode;
51 class SwNumRule;
52 class SwTable;
53 class SwNumberTreeNode;
54 class String;
55 class SvxLanguageItem;
56 
57 
58 /*
59  * Mapping of OOo elements to tagged pdf elements:
60  *
61  * OOo element                              tagged pdf element
62  * -----------                              ------------------
63  *
64  * Grouping elements:
65  *
66  * SwRootFrm                                Document
67  *                                          Part
68  *                                          Art
69  * SwSection                                Sect
70  * SwFtnContFrm and SwFlyFrm                Div
71  * SwFmt "Quotations"                       BlockQuote
72  * SwFmt "Caption"                          Caption
73  * SwSection (TOC)                          TOC
74  * SwTxtNode in TOC                         TOCI
75  * SwSection (Index)                        Index
76  *
77  * Block-Level Structure Elements:
78  *
79  * SwTxtNode                                P
80  * SwFmt "Heading"                          H
81  * SwTxtNode with Outline                   H1 - H6
82  * SwTxtNode with NumRule                   L, LI, LBody
83  * SwTable                                  Table
84  * SwRowFrm                                 TR
85  * SwCellFrm in Headline row or
86  * SwFtm "Table Heading"                    TH
87  * SwCellFrm                                TD
88  *
89  * Inline-Level Structure Elements:
90  *
91  * SwTxtPortion                             Span
92  * SwFmt "Quotation"                        Quote
93  * SwFtnFrm                                 Note
94  *                                          Form
95  *                                          Reference
96  * SwFldPortion (AuthorityField)            BibEntry
97  * SwFmt "Source Text"                      Code
98  * SwFtnPortion, SwFldPortion (RefField)    Link
99  *
100  * Illustration elements:
101  *
102  * SwFlyFrm with SwNoTxtFrm                 Figure
103  * SwFlyFrm with Math OLE Object            Formula
104  *
105  */
106 
107 struct Num_Info
108 {
109     const SwFrm& mrFrm;
Num_InfoNum_Info110     Num_Info( const SwFrm& rFrm ) : mrFrm( rFrm ) {};
111 };
112 
113 struct Frm_Info
114 {
115     const SwFrm& mrFrm;
Frm_InfoFrm_Info116     Frm_Info( const SwFrm& rFrm ) : mrFrm( rFrm ) {};
117 };
118 
119 struct Por_Info
120 {
121     const SwLinePortion& mrPor;
122     const SwTxtPainter& mrTxtPainter;
Por_InfoPor_Info123     Por_Info( const SwLinePortion& rPor, const SwTxtPainter& rTxtPainer )
124             : mrPor( rPor ), mrTxtPainter( rTxtPainer ) {};
125 };
126 
127 struct lt_TableColumn
128 {
operator ()lt_TableColumn129     bool operator()( long nVal1, long nVal2 ) const
130     {
131         return nVal1 + ( MINLAY - 1 ) < nVal2;
132     }
133 };
134 
135 /*************************************************************************
136  *                class SwTaggedPDFHelper
137  * Analyses a given frame during painting and generates the appropriate
138  * structure elements.
139  *************************************************************************/
140 
141 class SwTaggedPDFHelper
142 {
143     private:
144 
145     // This will be incremented for each BeginTag() call.
146     // It denotes the number of tags to close during EndStructureElements();
147     sal_uInt8 nEndStructureElement;
148 
149     //  If an already existing tag is reopened for follows of flow frames,
150     // this value stores the tag id which has to be restored.
151     sal_Int32 nRestoreCurrentTag;
152 
153     vcl::PDFExtOutDevData* mpPDFExtOutDevData;
154 
155     const Num_Info* mpNumInfo;
156     const Frm_Info* mpFrmInfo;
157     const Por_Info* mpPorInfo;
158 
159     void BeginTag( vcl::PDFWriter::StructElement aTagRole, const String& rTagName );
160     void EndTag();
161 
162     void SetAttributes( vcl::PDFWriter::StructElement eType );
163 
164     // These functions are called by the c'tor, d'tor
165     void BeginNumberedListStructureElements();
166     void BeginBlockStructureElements();
167     void BeginInlineStructureElements();
168     void EndStructureElements();
169 
170     bool CheckReopenTag();
171     bool CheckRestoreTag() const;
172 
173     public:
174 
175     // pFrmInfo != 0 => BeginBlockStructureElement
176     // pPorInfo != 0 => BeginInlineStructureElement
177     // pFrmInfo, pPorInfo = 0 => BeginNonStructureElement
178     SwTaggedPDFHelper( const Num_Info* pNumInfo, const Frm_Info* pFrmInfo, const Por_Info* pPorInfo,
179                        OutputDevice& rOut );
180     ~SwTaggedPDFHelper();
181 
182     static bool IsExportTaggedPDF( const OutputDevice& rOut );
183 };
184 
185 /*************************************************************************
186  *                class SwEnhancedPDFExportHelper
187  * Analyses the document structure and export Notes, Hyperlinks, References,
188  * and Outline. Link ids created during pdf export are stored in
189  * aReferenceIdMap and aHyperlinkIdMap, in order to use them during
190  * tagged pdf output. Therefore the SwEnhancedPDFExportHelper is used
191  * before painting. Unfortunately links from the EditEngine into the
192  * Writer document require to be exported after they have been painted.
193  * Therefore SwEnhancedPDFExportHelper also has to be used after the
194  * painting process, the parameter bEditEngineOnly indicated that only
195  * the bookmarks from the EditEngine have to be processed.
196  *************************************************************************/
197 
198 typedef std::set< long, lt_TableColumn > TableColumnsMapEntry;
199 typedef std::pair< SwRect, sal_Int32 > IdMapEntry;
200 typedef std::vector< IdMapEntry > LinkIdMap;
201 typedef std::map< const SwTable*, TableColumnsMapEntry > TableColumnsMap;
202 typedef std::map< const SwNumberTreeNode*, sal_Int32 > NumListIdMap;
203 typedef std::map< const SwNumberTreeNode*, sal_Int32 > NumListBodyIdMap;
204 typedef std::map< const void*, sal_Int32 > FrmTagIdMap;
205 
206 class SwEnhancedPDFExportHelper
207 {
208     private:
209 
210     SwEditShell& mrSh;
211     OutputDevice& mrOut;
212 
213     MultiSelection* pPageRange;
214 
215     bool mbSkipEmptyPages;
216     bool mbEditEngineOnly;
217 
218     static TableColumnsMap aTableColumnsMap;
219     static LinkIdMap aLinkIdMap;
220     static NumListIdMap aNumListIdMap;
221     static NumListBodyIdMap aNumListBodyIdMap;
222     static FrmTagIdMap aFrmTagIdMap;
223 
224     static LanguageType eLanguageDefault;
225 
226     void EnhancedPDFExport();
227     sal_Int32 CalcOutputPageNum( const SwRect& rRect ) const;
228 
229     void MakeHeaderFooterLinks( vcl::PDFExtOutDevData& rPDFExtOutDevData,
230                                 const SwTxtNode& rTNd, const SwRect& rLinkRect,
231                                 sal_Int32 nDestId, const String& rURL, bool bIntern ) const;
232 
233     public:
234 
235     SwEnhancedPDFExportHelper( SwEditShell& rSh,
236                                OutputDevice& rOut,
237                                const rtl::OUString& rPageRange,
238                                bool bSkipEmptyPages,
239                                bool bEditEngineOnly );
240 
241     ~SwEnhancedPDFExportHelper();
242 
GetTableColumnsMap()243     static TableColumnsMap& GetTableColumnsMap() {return aTableColumnsMap; }
GetLinkIdMap()244     static LinkIdMap& GetLinkIdMap() { return aLinkIdMap; }
GetNumListIdMap()245     static NumListIdMap& GetNumListIdMap() {return aNumListIdMap; }
GetNumListBodyIdMap()246     static NumListBodyIdMap& GetNumListBodyIdMap() {return aNumListBodyIdMap; }
GetFrmTagIdMap()247     static FrmTagIdMap& GetFrmTagIdMap() { return aFrmTagIdMap; }
248 
GetDefaultLanguage()249     static LanguageType GetDefaultLanguage() {return eLanguageDefault; }
250 };
251 
252 #endif
253