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 <vcl/pdfextoutdevdata.hxx>
24 #include <i18nlangtag/lang.h>
26 #include <swtypes.hxx>
34 class PDFExtOutDevData
;
43 class StringRangeEnumerator
;
47 class SwNumberTreeNode
;
48 class SvxLanguageItem
;
51 * Mapping of OOo elements to tagged pdf elements:
53 * OOo element tagged pdf element
54 * ----------- ------------------
62 * SwFootnoteContFrm and SwFlyFrm Div
63 * SwFormat "Quotations" BlockQuote
64 * SwFormat "Caption" Caption
66 * SwTextNode in TOC TOCI
67 * SwSection (Index) Index
69 * Block-Level Structure Elements:
72 * SwFormat "Heading" H
73 * SwTextNode with Outline H1 - H6
74 * SwTextNode with NumRule L, LI, LBody
77 * SwCellFrm in Headline row or
78 * SwFtm "Table Heading" TH
81 * Inline-Level Structure Elements:
84 * SwFormat "Quotation" Quote
88 * SwFieldPortion (AuthorityField) BibEntry
89 * SwFormat "Source Text" Code
90 * SwFootnotePortion, SwFieldPortion (RefField) Link
92 * Illustration elements:
94 * SwFlyFrm with SwNoTextFrm Figure
95 * SwFlyFrm with Math OLE Object Formula
102 Num_Info( const SwFrm
& rFrm
) : mrFrm( rFrm
) {};
108 Frm_Info( const SwFrm
& rFrm
) : mrFrm( rFrm
) {};
113 const SwLinePortion
& mrPor
;
114 const SwTextPainter
& mrTextPainter
;
115 Por_Info( const SwLinePortion
& rPor
, const SwTextPainter
& rTextPainer
)
116 : mrPor( rPor
), mrTextPainter( rTextPainer
) {};
119 struct lt_TableColumn
121 bool operator()( long nVal1
, long nVal2
) const
123 return nVal1
+ ( MINLAY
- 1 ) < nVal2
;
127 // Analyses a given frame during painting and generates the appropriate
128 // structure elements.
129 class SwTaggedPDFHelper
133 // This will be incremented for each BeginTag() call.
134 // It denotes the number of tags to close during EndStructureElements();
135 sal_uInt8 nEndStructureElement
;
137 // If an already existing tag is reopened for follows of flow frames,
138 // this value stores the tag id which has to be restored.
139 sal_Int32 nRestoreCurrentTag
;
141 vcl::PDFExtOutDevData
* mpPDFExtOutDevData
;
143 const Num_Info
* mpNumInfo
;
144 const Frm_Info
* mpFrmInfo
;
145 const Por_Info
* mpPorInfo
;
147 void BeginTag( vcl::PDFWriter::StructElement aTagRole
, const OUString
& rTagName
);
150 void SetAttributes( vcl::PDFWriter::StructElement eType
);
152 // These functions are called by the c'tor, d'tor
153 void BeginNumberedListStructureElements();
154 void BeginBlockStructureElements();
155 void BeginInlineStructureElements();
156 void EndStructureElements();
158 bool CheckReopenTag();
159 bool CheckRestoreTag() const;
163 // pFrmInfo != 0 => BeginBlockStructureElement
164 // pPorInfo != 0 => BeginInlineStructureElement
165 // pFrmInfo, pPorInfo = 0 => BeginNonStructureElement
166 SwTaggedPDFHelper( const Num_Info
* pNumInfo
, const Frm_Info
* pFrmInfo
, const Por_Info
* pPorInfo
,
167 OutputDevice
& rOut
);
168 ~SwTaggedPDFHelper();
170 static bool IsExportTaggedPDF( const OutputDevice
& rOut
);
174 * Analyses the document structure and export Notes, Hyperlinks, References,
175 * and Outline. Link ids created during pdf export are stored in
176 * aReferenceIdMap and aHyperlinkIdMap, in order to use them during
177 * tagged pdf output. Therefore the SwEnhancedPDFExportHelper is used
178 * before painting. Unfortunately links from the EditEngine into the
179 * Writer document require to be exported after they have been painted.
180 * Therefore SwEnhancedPDFExportHelper also has to be used after the
181 * painting process, the parameter bEditEngineOnly indicated that only
182 * the bookmarks from the EditEngine have to be processed.
184 typedef std::set
< long, lt_TableColumn
> TableColumnsMapEntry
;
185 typedef std::pair
< SwRect
, sal_Int32
> IdMapEntry
;
186 typedef std::vector
< IdMapEntry
> LinkIdMap
;
187 typedef std::map
< const SwTable
*, TableColumnsMapEntry
> TableColumnsMap
;
188 typedef std::map
< const SwNumberTreeNode
*, sal_Int32
> NumListIdMap
;
189 typedef std::map
< const SwNumberTreeNode
*, sal_Int32
> NumListBodyIdMap
;
190 typedef std::map
< const void*, sal_Int32
> FrmTagIdMap
;
192 class SwEnhancedPDFExportHelper
199 StringRangeEnumerator
* mpRangeEnum
;
200 /** The problem is that numbers in StringRangeEnumerator aren't accordant
201 * to real page numbers if mbSkipEmptyPages is true, because in this case
202 * empty pages are excluded from a page range and numbers in
203 * StringRangeEnumerator are shifted.
205 * maPageNumberMap[real_page_number] is either a corresponding page number
206 * in a page range without empty pages, or -1 if this page is empty. */
207 std::vector
< sal_Int32
> maPageNumberMap
;
209 bool mbSkipEmptyPages
;
210 bool mbEditEngineOnly
;
212 const SwPrintData
& mrPrintData
;
214 static TableColumnsMap aTableColumnsMap
;
215 static LinkIdMap aLinkIdMap
;
216 static NumListIdMap aNumListIdMap
;
217 static NumListBodyIdMap aNumListBodyIdMap
;
218 static FrmTagIdMap aFrmTagIdMap
;
220 static LanguageType eLanguageDefault
;
222 void EnhancedPDFExport();
223 sal_Int32
CalcOutputPageNum( const SwRect
& rRect
) const;
224 std::vector
< sal_Int32
> CalcOutputPageNums( const SwRect
& rRect
) const;
226 void MakeHeaderFooterLinks( vcl::PDFExtOutDevData
& rPDFExtOutDevData
,
227 const SwTextNode
& rTNd
, const SwRect
& rLinkRect
,
228 sal_Int32 nDestId
, const OUString
& rURL
, bool bIntern
) const;
232 SwEnhancedPDFExportHelper( SwEditShell
& rSh
,
234 const OUString
& rPageRange
,
235 bool bSkipEmptyPages
,
236 bool bEditEngineOnly
,
237 const SwPrintData
& rPrintData
);
239 ~SwEnhancedPDFExportHelper();
241 static TableColumnsMap
& GetTableColumnsMap() {return aTableColumnsMap
; }
242 static LinkIdMap
& GetLinkIdMap() { return aLinkIdMap
; }
243 static NumListIdMap
& GetNumListIdMap() {return aNumListIdMap
; }
244 static NumListBodyIdMap
& GetNumListBodyIdMap() {return aNumListBodyIdMap
; }
245 static FrmTagIdMap
& GetFrmTagIdMap() { return aFrmTagIdMap
; }
247 static LanguageType
GetDefaultLanguage() {return eLanguageDefault
; }
249 //scale and position rRectangle if we're scaling due to notes in margins.
250 Rectangle
SwRectToPDFRect(const SwPageFrm
* pCurrPage
,
251 const Rectangle
& rRectangle
) const;
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */