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