LibreOffice Module sw (master)  1
EnhancedPDFExportHelper.hxx
Go to the documentation of this file.
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 <i18nlangtag/lang.h>
24 #include <vcl/pdfwriter.hxx>
25 #include "swrect.hxx"
26 #include "swtypes.hxx"
27 
28 #include <map>
29 #include <memory>
30 #include <vector>
31 #include <set>
32 
33 namespace vcl
34 {
35  class PDFExtOutDevData;
36 }
37 class OutputDevice;
38 class SwFrame;
39 class SwLinePortion;
40 class SwPageFrame;
41 class SwPrintData;
42 class SwTextPainter;
43 class SwEditShell;
45 class SwTextNode;
46 class SwTable;
47 class SwNumberTreeNode;
48 
49 /*
50  * Mapping of OOo elements to tagged pdf elements:
51  *
52  * OOo element tagged pdf element
53  * ----------- ------------------
54  *
55  * Grouping elements:
56  *
57  * SwRootFrame Document
58  * Part
59  * Art
60  * SwSection Sect
61  * SwFootnoteContFrame and SwFlyFrame Div
62  * SwFormat "Quotations" BlockQuote
63  * SwFormat "Caption" Caption
64  * SwSection (TOC) TOC
65  * SwTextNode in TOC TOCI
66  * SwSection (Index) Index
67  *
68  * Block-Level Structure Elements:
69  *
70  * SwTextNode P
71  * SwFormat "Heading" H
72  * SwTextNode with Outline H1 - H6
73  * SwTextNode with NumRule L, LI, LBody
74  * SwTable Table
75  * SwRowFrame TR
76  * SwCellFrame in Headline row or
77  * SwFtm "Table Heading" TH
78  * SwCellFrame TD
79  *
80  * Inline-Level Structure Elements:
81  *
82  * SwTextPortion Span
83  * SwFormat "Quotation" Quote
84  * SwFootnoteFrame Note
85  * Form
86  * Reference
87  * SwFieldPortion (AuthorityField) BibEntry
88  * SwFormat "Source Text" Code
89  * SwFootnotePortion, SwFieldPortion (RefField) Link
90  *
91  * Illustration elements:
92  *
93  * SwFlyFrame with SwNoTextFrame Figure
94  * SwFlyFrame with Math OLE Object Formula
95  *
96  */
97 
98 struct Num_Info
99 {
100  const SwFrame& mrFrame;
101  Num_Info( const SwFrame& rFrame ) : mrFrame( rFrame ) {};
102 };
103 
105 {
106  const SwFrame& mrFrame;
107  Frame_Info( const SwFrame& rFrame ) : mrFrame( rFrame ) {};
108 };
109 
110 struct Por_Info
111 {
114  Por_Info( const SwLinePortion& rPor, const SwTextPainter& rTextPainer )
115  : mrPor( rPor ), mrTextPainter( rTextPainer ) {};
116 };
117 
119 {
120  bool operator()( long nVal1, long nVal2 ) const
121  {
122  return nVal1 + ( MINLAY - 1 ) < nVal2;
123  }
124 };
125 
126 // Analyses a given frame during painting and generates the appropriate
127 // structure elements.
129 {
130  private:
131 
132  // This will be incremented for each BeginTag() call.
133  // It denotes the number of tags to close during EndStructureElements();
135 
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.
139 
141 
145 
146  void BeginTag( vcl::PDFWriter::StructElement aTagRole, const OUString& rTagName );
147  void EndTag();
148 
150 
151  // These functions are called by the c'tor, d'tor
155  void EndStructureElements();
156 
157  bool CheckReopenTag();
158  void CheckRestoreTag() const;
159 
160  public:
161 
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 );
168 
169  static bool IsExportTaggedPDF( const OutputDevice& rOut );
170 };
171 
172 /*
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.
182  */
183 typedef std::set< 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;
190 
192 {
193  private:
194 
197 
198  std::unique_ptr<StringRangeEnumerator> mpRangeEnum;
206  std::vector< sal_Int32 > maPageNumberMap;
207 
208  bool const mbSkipEmptyPages;
209  bool const mbEditEngineOnly;
210 
212 
218 
220 
221  void EnhancedPDFExport();
222  sal_Int32 CalcOutputPageNum( const SwRect& rRect ) const;
223  std::vector< sal_Int32 > CalcOutputPageNums( const SwRect& rRect ) const;
224 
225  void MakeHeaderFooterLinks( vcl::PDFExtOutDevData& rPDFExtOutDevData,
226  const SwTextNode& rTNd, const SwRect& rLinkRect,
227  sal_Int32 nDestId, const OUString& rURL, bool bIntern ) const;
228 
229  public:
230 
232  OutputDevice& rOut,
233  const OUString& rPageRange,
234  bool bSkipEmptyPages,
235  bool bEditEngineOnly,
236  const SwPrintData& rPrintData );
237 
239 
241  static LinkIdMap& GetLinkIdMap() { return aLinkIdMap; }
245 
247 
248  //scale and position rRectangle if we're scaling due to notes in margins.
250  const tools::Rectangle& rRectangle) const;
251 };
252 
253 #endif
254 
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class of the Writer layout elements.
Definition: frame.hxx:295
static LanguageType GetDefaultLanguage()
A tree of numbered nodes.
vcl::PDFExtOutDevData * mpPDFExtOutDevData
std::unique_ptr< StringRangeEnumerator > mpRangeEnum
#define MINLAY
Definition: swtypes.hxx:66
void BeginTag(vcl::PDFWriter::StructElement aTagRole, const OUString &rTagName)
void MakeHeaderFooterLinks(vcl::PDFExtOutDevData &rPDFExtOutDevData, const SwTextNode &rTNd, const SwRect &rLinkRect, sal_Int32 nDestId, const OUString &rURL, bool bIntern) const
bool operator()(long nVal1, long nVal2) const
std::vector< IdMapEntry > LinkIdMap
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
void SetAttributes(vcl::PDFWriter::StructElement eType)
const SwLinePortion & mrPor
Num_Info(const SwFrame &rFrame)
static FrameTagIdMap & GetFrameTagIdMap()
std::map< const SwTable *, TableColumnsMapEntry > TableColumnsMap
static TableColumnsMap aTableColumnsMap
const SwTextPainter & mrTextPainter
Frame_Info(const SwFrame &rFrame)
SwTaggedPDFHelper(const Num_Info *pNumInfo, const Frame_Info *pFrameInfo, const Por_Info *pPorInfo, OutputDevice const &rOut)
std::pair< SwRect, sal_Int32 > IdMapEntry
const SwFrame & mrFrame
sal_Int32 CalcOutputPageNum(const SwRect &rRect) const
static bool IsExportTaggedPDF(const OutputDevice &rOut)
std::vector< sal_Int32 > maPageNumberMap
The problem is that numbers in StringRangeEnumerator aren't accordant to real page numbers if mbSkipE...
A page of the document layout.
Definition: pagefrm.hxx:40
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:110
Base class for anything that can be part of a line in the Writer layout.
Definition: porlin.hxx:50
const SwFrame & mrFrame
std::map< const SwNumberTreeNode *, sal_Int32 > NumListBodyIdMap
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
const Frame_Info * mpFrameInfo
std::map< const SwNumberTreeNode *, sal_Int32 > NumListIdMap
static TableColumnsMap & GetTableColumnsMap()
unsigned char sal_uInt8
std::set< long, lt_TableColumn > TableColumnsMapEntry
std::map< const void *, sal_Int32 > FrameTagIdMap
Por_Info(const SwLinePortion &rPor, const SwTextPainter &rTextPainer)
std::vector< sal_Int32 > CalcOutputPageNums(const SwRect &rRect) const
static NumListIdMap & GetNumListIdMap()
SwEnhancedPDFExportHelper(SwEditShell &rSh, OutputDevice &rOut, const OUString &rPageRange, bool bSkipEmptyPages, bool bEditEngineOnly, const SwPrintData &rPrintData)
static NumListBodyIdMap & GetNumListBodyIdMap()
static NumListBodyIdMap aNumListBodyIdMap
tools::Rectangle SwRectToPDFRect(const SwPageFrame *pCurrPage, const tools::Rectangle &rRectangle) const