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