Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / EnhancedPDFExportHelper.hxx
blobc9804130acd5b845ceb65021379beee384179b1a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SW_INC_ENHANCEDPDFEXPORTHELPER_HXX
21 #define INCLUDED_SW_INC_ENHANCEDPDFEXPORTHELPER_HXX
23 #include <vcl/pdfextoutdevdata.hxx>
24 #include <i18nlangtag/lang.h>
25 #include <swrect.hxx>
26 #include <swtypes.hxx>
28 #include <map>
29 #include <memory>
30 #include <vector>
31 #include <set>
33 namespace vcl
35 class PDFExtOutDevData;
37 class OutputDevice;
38 class SwFrame;
39 class SwLinePortion;
40 class SwPageFrame;
41 class SwPrintData;
42 class SwTextPainter;
43 class SwEditShell;
44 class StringRangeEnumerator;
45 class SwTextNode;
46 class SwNumRule;
47 class SwTable;
48 class SwNumberTreeNode;
49 class SvxLanguageItem;
52 * Mapping of OOo elements to tagged pdf elements:
54 * OOo element tagged pdf element
55 * ----------- ------------------
57 * Grouping elements:
59 * SwRootFrame Document
60 * Part
61 * Art
62 * SwSection Sect
63 * SwFootnoteContFrame and SwFlyFrame Div
64 * SwFormat "Quotations" BlockQuote
65 * SwFormat "Caption" Caption
66 * SwSection (TOC) TOC
67 * SwTextNode in TOC TOCI
68 * SwSection (Index) Index
70 * Block-Level Structure Elements:
72 * SwTextNode P
73 * SwFormat "Heading" H
74 * SwTextNode with Outline H1 - H6
75 * SwTextNode with NumRule L, LI, LBody
76 * SwTable Table
77 * SwRowFrame TR
78 * SwCellFrame in Headline row or
79 * SwFtm "Table Heading" TH
80 * SwCellFrame TD
82 * Inline-Level Structure Elements:
84 * SwTextPortion Span
85 * SwFormat "Quotation" Quote
86 * SwFootnoteFrame Note
87 * Form
88 * Reference
89 * SwFieldPortion (AuthorityField) BibEntry
90 * SwFormat "Source Text" Code
91 * SwFootnotePortion, SwFieldPortion (RefField) Link
93 * Illustration elements:
95 * SwFlyFrame with SwNoTextFrame Figure
96 * SwFlyFrame with Math OLE Object Formula
100 struct Num_Info
102 const SwFrame& mrFrame;
103 Num_Info( const SwFrame& rFrame ) : mrFrame( rFrame ) {};
106 struct Frame_Info
108 const SwFrame& mrFrame;
109 Frame_Info( const SwFrame& rFrame ) : mrFrame( rFrame ) {};
112 struct Por_Info
114 const SwLinePortion& mrPor;
115 const SwTextPainter& mrTextPainter;
116 Por_Info( const SwLinePortion& rPor, const SwTextPainter& rTextPainer )
117 : mrPor( rPor ), mrTextPainter( rTextPainer ) {};
120 struct lt_TableColumn
122 bool operator()( long nVal1, long nVal2 ) const
124 return nVal1 + ( MINLAY - 1 ) < nVal2;
128 // Analyses a given frame during painting and generates the appropriate
129 // structure elements.
130 class SwTaggedPDFHelper
132 private:
134 // This will be incremented for each BeginTag() call.
135 // It denotes the number of tags to close during EndStructureElements();
136 sal_uInt8 nEndStructureElement;
138 // If an already existing tag is reopened for follows of flow frames,
139 // this value stores the tag id which has to be restored.
140 sal_Int32 nRestoreCurrentTag;
142 vcl::PDFExtOutDevData* mpPDFExtOutDevData;
144 const Num_Info* mpNumInfo;
145 const Frame_Info* mpFrameInfo;
146 const Por_Info* mpPorInfo;
148 void BeginTag( vcl::PDFWriter::StructElement aTagRole, const OUString& rTagName );
149 void EndTag();
151 void SetAttributes( vcl::PDFWriter::StructElement eType );
153 // These functions are called by the c'tor, d'tor
154 void BeginNumberedListStructureElements();
155 void BeginBlockStructureElements();
156 void BeginInlineStructureElements();
157 void EndStructureElements();
159 bool CheckReopenTag();
160 bool CheckRestoreTag() const;
162 public:
164 // pFrameInfo != 0 => BeginBlockStructureElement
165 // pPorInfo != 0 => BeginInlineStructureElement
166 // pFrameInfo, pPorInfo = 0 => BeginNonStructureElement
167 SwTaggedPDFHelper( const Num_Info* pNumInfo, const Frame_Info* pFrameInfo, const Por_Info* pPorInfo,
168 OutputDevice& rOut );
169 ~SwTaggedPDFHelper();
171 static bool IsExportTaggedPDF( const OutputDevice& rOut );
175 * Analyses the document structure and export Notes, Hyperlinks, References,
176 * and Outline. Link ids created during pdf export are stored in
177 * aReferenceIdMap and aHyperlinkIdMap, in order to use them during
178 * tagged pdf output. Therefore the SwEnhancedPDFExportHelper is used
179 * before painting. Unfortunately links from the EditEngine into the
180 * Writer document require to be exported after they have been painted.
181 * Therefore SwEnhancedPDFExportHelper also has to be used after the
182 * painting process, the parameter bEditEngineOnly indicated that only
183 * the bookmarks from the EditEngine have to be processed.
185 typedef std::set< long, lt_TableColumn > TableColumnsMapEntry;
186 typedef std::pair< SwRect, sal_Int32 > IdMapEntry;
187 typedef std::vector< IdMapEntry > LinkIdMap;
188 typedef std::map< const SwTable*, TableColumnsMapEntry > TableColumnsMap;
189 typedef std::map< const SwNumberTreeNode*, sal_Int32 > NumListIdMap;
190 typedef std::map< const SwNumberTreeNode*, sal_Int32 > NumListBodyIdMap;
191 typedef std::map< const void*, sal_Int32 > FrameTagIdMap;
193 class SwEnhancedPDFExportHelper
195 private:
197 SwEditShell& mrSh;
198 OutputDevice& mrOut;
200 std::unique_ptr<StringRangeEnumerator> mpRangeEnum;
201 /** The problem is that numbers in StringRangeEnumerator aren't accordant
202 * to real page numbers if mbSkipEmptyPages is true, because in this case
203 * empty pages are excluded from a page range and numbers in
204 * StringRangeEnumerator are shifted.
206 * maPageNumberMap[real_page_number] is either a corresponding page number
207 * in a page range without empty pages, or -1 if this page is empty. */
208 std::vector< sal_Int32 > maPageNumberMap;
210 bool mbSkipEmptyPages;
211 bool mbEditEngineOnly;
213 const SwPrintData& mrPrintData;
215 static TableColumnsMap aTableColumnsMap;
216 static LinkIdMap aLinkIdMap;
217 static NumListIdMap aNumListIdMap;
218 static NumListBodyIdMap aNumListBodyIdMap;
219 static FrameTagIdMap aFrameTagIdMap;
221 static LanguageType eLanguageDefault;
223 void EnhancedPDFExport();
224 sal_Int32 CalcOutputPageNum( const SwRect& rRect ) const;
225 std::vector< sal_Int32 > CalcOutputPageNums( const SwRect& rRect ) const;
227 void MakeHeaderFooterLinks( vcl::PDFExtOutDevData& rPDFExtOutDevData,
228 const SwTextNode& rTNd, const SwRect& rLinkRect,
229 sal_Int32 nDestId, const OUString& rURL, bool bIntern ) const;
231 public:
233 SwEnhancedPDFExportHelper( SwEditShell& rSh,
234 OutputDevice& rOut,
235 const OUString& rPageRange,
236 bool bSkipEmptyPages,
237 bool bEditEngineOnly,
238 const SwPrintData& rPrintData );
240 ~SwEnhancedPDFExportHelper();
242 static TableColumnsMap& GetTableColumnsMap() {return aTableColumnsMap; }
243 static LinkIdMap& GetLinkIdMap() { return aLinkIdMap; }
244 static NumListIdMap& GetNumListIdMap() {return aNumListIdMap; }
245 static NumListBodyIdMap& GetNumListBodyIdMap() {return aNumListBodyIdMap; }
246 static FrameTagIdMap& GetFrameTagIdMap() { return aFrameTagIdMap; }
248 static LanguageType GetDefaultLanguage() {return eLanguageDefault; }
250 //scale and position rRectangle if we're scaling due to notes in margins.
251 tools::Rectangle SwRectToPDFRect(const SwPageFrame* pCurrPage,
252 const tools::Rectangle& rRectangle) const;
255 #endif
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */