1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <i18nlangtag/lang.h>
24 #include <vcl/pdfwriter.hxx>
26 #include "swtypes.hxx"
35 class PDFExtOutDevData
;
44 class StringRangeEnumerator
;
47 class SwNumberTreeNode
;
50 * Mapping of OOo elements to tagged pdf elements:
52 * OOo element tagged pdf element
53 * ----------- ------------------
57 * SwRootFrame Document
61 * SwFootnoteContFrame and SwFlyFrame Div
62 * SwFormat "Quotations" BlockQuote
63 * SwFormat "Caption" Caption
65 * SwTextNode in TOC TOCI
66 * SwSection (Index) Index
68 * Block-Level Structure Elements:
71 * SwFormat "Heading" H
72 * SwTextNode with Outline H1 - H6
73 * SwTextNode with NumRule L, LI, LBody
76 * SwCellFrame in Headline row or
77 * SwFtm "Table Heading" TH
80 * Inline-Level Structure Elements:
83 * SwFormat "Quotation" Quote
84 * SwFootnoteFrame Note
87 * SwFieldPortion (AuthorityField) BibEntry
88 * SwFormat "Source Text" Code
89 * SwFootnotePortion, SwFieldPortion (RefField) Link
91 * Illustration elements:
93 * SwFlyFrame with SwNoTextFrame Figure
94 * SwFlyFrame with Math OLE Object Formula
100 const SwFrame
& mrFrame
;
101 Num_Info( const SwFrame
& rFrame
) : mrFrame( rFrame
) {};
106 const SwFrame
& mrFrame
;
107 Frame_Info( const SwFrame
& rFrame
) : mrFrame( rFrame
) {};
112 const SwLinePortion
& mrPor
;
113 const SwTextPainter
& mrTextPainter
;
114 Por_Info( const SwLinePortion
& rPor
, const SwTextPainter
& rTextPainer
)
115 : mrPor( rPor
), mrTextPainter( rTextPainer
) {};
118 struct lt_TableColumn
120 bool operator()( tools::Long nVal1
, tools::Long nVal2
) const
122 return nVal1
+ ( MINLAY
- 1 ) < nVal2
;
126 // Analyses a given frame during painting and generates the appropriate
127 // structure elements.
128 class SwTaggedPDFHelper
132 // This will be incremented for each BeginTag() call.
133 // It denotes the number of tags to close during EndStructureElements();
134 sal_uInt8 nEndStructureElement
;
136 // If an already existing tag is reopened for follows of flow frames,
137 // this value stores the tag id which has to be restored.
138 sal_Int32 nRestoreCurrentTag
;
140 vcl::PDFExtOutDevData
* mpPDFExtOutDevData
;
142 const Num_Info
* mpNumInfo
;
143 const Frame_Info
* mpFrameInfo
;
144 const Por_Info
* mpPorInfo
;
146 void BeginTag( vcl::PDFWriter::StructElement aTagRole
, const OUString
& rTagName
);
149 void SetAttributes( vcl::PDFWriter::StructElement eType
);
151 // These functions are called by the c'tor, d'tor
152 void BeginNumberedListStructureElements();
153 void BeginBlockStructureElements();
154 void BeginInlineStructureElements();
155 void EndStructureElements();
157 bool CheckReopenTag();
158 void CheckRestoreTag() const;
162 // pFrameInfo != 0 => BeginBlockStructureElement
163 // pPorInfo != 0 => BeginInlineStructureElement
164 // pFrameInfo, pPorInfo = 0 => BeginNonStructureElement
165 SwTaggedPDFHelper( const Num_Info
* pNumInfo
, const Frame_Info
* pFrameInfo
, const Por_Info
* pPorInfo
,
166 OutputDevice
const & rOut
);
167 ~SwTaggedPDFHelper();
169 static bool IsExportTaggedPDF( const OutputDevice
& rOut
);
173 * Analyses the document structure and export Notes, Hyperlinks, References,
174 * and Outline. Link ids created during pdf export are stored in
175 * aReferenceIdMap and aHyperlinkIdMap, in order to use them during
176 * tagged pdf output. Therefore the SwEnhancedPDFExportHelper is used
177 * before painting. Unfortunately links from the EditEngine into the
178 * Writer document require to be exported after they have been painted.
179 * Therefore SwEnhancedPDFExportHelper also has to be used after the
180 * painting process, the parameter bEditEngineOnly indicated that only
181 * the bookmarks from the EditEngine have to be processed.
183 typedef std::set
< tools::Long
, lt_TableColumn
> TableColumnsMapEntry
;
184 typedef std::pair
< SwRect
, sal_Int32
> IdMapEntry
;
185 typedef std::vector
< IdMapEntry
> LinkIdMap
;
186 typedef std::map
< const SwTable
*, TableColumnsMapEntry
> TableColumnsMap
;
187 typedef std::map
< const SwNumberTreeNode
*, sal_Int32
> NumListIdMap
;
188 typedef std::map
< const SwNumberTreeNode
*, sal_Int32
> NumListBodyIdMap
;
189 typedef std::map
< const void*, sal_Int32
> FrameTagIdMap
;
191 class SwEnhancedPDFExportHelper
198 std::unique_ptr
<StringRangeEnumerator
> mpRangeEnum
;
199 /** The problem is that numbers in StringRangeEnumerator aren't accordant
200 * to real page numbers if mbSkipEmptyPages is true, because in this case
201 * empty pages are excluded from a page range and numbers in
202 * StringRangeEnumerator are shifted.
204 * maPageNumberMap[real_page_number] is either a corresponding page number
205 * in a page range without empty pages, or -1 if this page is empty. */
206 std::vector
< sal_Int32
> maPageNumberMap
;
208 bool mbSkipEmptyPages
;
209 bool mbEditEngineOnly
;
211 const SwPrintData
& mrPrintData
;
213 static TableColumnsMap aTableColumnsMap
;
214 static LinkIdMap aLinkIdMap
;
215 static NumListIdMap aNumListIdMap
;
216 static NumListBodyIdMap aNumListBodyIdMap
;
217 static FrameTagIdMap aFrameTagIdMap
;
219 static LanguageType eLanguageDefault
;
221 void EnhancedPDFExport();
222 sal_Int32
CalcOutputPageNum( const SwRect
& rRect
) const;
223 std::vector
< sal_Int32
> CalcOutputPageNums( const SwRect
& rRect
) const;
225 void MakeHeaderFooterLinks( vcl::PDFExtOutDevData
& rPDFExtOutDevData
,
226 const SwTextNode
& rTNd
, const SwRect
& rLinkRect
,
227 sal_Int32 nDestId
, const OUString
& rURL
, bool bIntern
) const;
231 SwEnhancedPDFExportHelper( SwEditShell
& rSh
,
233 const OUString
& rPageRange
,
234 bool bSkipEmptyPages
,
235 bool bEditEngineOnly
,
236 const SwPrintData
& rPrintData
);
238 ~SwEnhancedPDFExportHelper();
240 static TableColumnsMap
& GetTableColumnsMap() {return aTableColumnsMap
; }
241 static LinkIdMap
& GetLinkIdMap() { return aLinkIdMap
; }
242 static NumListIdMap
& GetNumListIdMap() {return aNumListIdMap
; }
243 static NumListBodyIdMap
& GetNumListBodyIdMap() {return aNumListBodyIdMap
; }
244 static FrameTagIdMap
& GetFrameTagIdMap() { return aFrameTagIdMap
; }
246 static LanguageType
GetDefaultLanguage() {return eLanguageDefault
; }
248 //scale and position rRectangle if we're scaling due to notes in margins.
249 tools::Rectangle
SwRectToPDFRect(const SwPageFrame
* pCurrPage
,
250 const tools::Rectangle
& rRectangle
) const;
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */