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