tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sw / inc / EnhancedPDFExportHelper.hxx
blob450c9c2fe71ab4ebf3d944ebed7e330533a2dac4
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 #pragma once
22 #include <i18nlangtag/lang.h>
23 #include <vcl/pdfwriter.hxx>
24 #include "swrect.hxx"
25 #include "swtypes.hxx"
27 #include <memory>
28 #include <vector>
30 namespace vcl
32 class PDFExtOutDevData;
34 class OutputDevice;
35 class SwFrame;
36 class SwLinePortion;
37 class SwPageFrame;
38 class SwPrintData;
39 class SwTextPainter;
40 class SwEditShell;
41 class StringRangeEnumerator;
42 class SwTextAttr;
43 class SwTextNode;
44 class SwTable;
45 class SwNumberTreeNode;
46 class SwTextPaintInfo;
47 class SwTextFrame;
50 * Mapping of OOo elements to tagged pdf elements:
52 * OOo element tagged pdf element
53 * ----------- ------------------
55 * Grouping elements:
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
68 * Block-Level Structure Elements:
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
80 * Inline-Level Structure Elements:
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
91 * Illustration elements:
93 * SwFlyFrame with SwNoTextFrame Figure
94 * SwFlyFrame with Math OLE Object Formula
98 struct Num_Info
100 const SwTextFrame& mrFrame;
101 Num_Info( const SwTextFrame& rFrame ) : mrFrame( rFrame ) {};
104 struct Frame_Info
106 const SwFrame& mrFrame;
107 bool const m_isLink;
109 Frame_Info(const SwFrame& rFrame, bool const isLink)
110 : mrFrame(rFrame), m_isLink(isLink) {}
113 struct Por_Info
115 const SwLinePortion& mrPor;
116 const SwTextPainter& mrTextPainter;
117 /** this can be used to generate multiple different SE for the same portion:
118 FootnoteNum: 0-> Link 1-> Lbl
119 Double: 0-> Warichu 1-> WP 2-> WT
120 Ruby: 0-> Ruby 1-> RT 2-> RB
122 int const m_Mode;
124 Por_Info(const SwLinePortion& rPor, const SwTextPainter& rTextPainer, int const nMode)
125 : mrPor(rPor), mrTextPainter(rTextPainer), m_Mode(nMode) {};
128 struct lt_TableColumn
130 bool operator()( tools::Long nVal1, tools::Long nVal2 ) const
132 return nVal1 + ( MINLAY - 1 ) < nVal2;
136 // Analyses a given frame during painting and generates the appropriate
137 // structure elements.
138 class SwTaggedPDFHelper
140 private:
142 // This will be incremented for each BeginTag() call.
143 // It denotes the number of tags to close during EndStructureElements();
144 sal_uInt8 m_nEndStructureElement;
146 // If an already existing tag is reopened for follows of flow frames,
147 // this value stores the tag id which has to be restored.
148 sal_Int32 m_nRestoreCurrentTag;
150 vcl::PDFExtOutDevData* mpPDFExtOutDevData;
152 const Num_Info* mpNumInfo;
153 const Frame_Info* mpFrameInfo;
154 const Por_Info* mpPorInfo;
156 void OpenTagImpl(void const* pKey);
157 sal_Int32 BeginTagImpl(void const* pKey,vcl::PDFWriter::StructElement aTagRole, const OUString& rTagName);
158 void BeginTag( vcl::PDFWriter::StructElement aTagRole, const OUString& rTagName );
159 void EndTag();
161 void SetAttributes( vcl::PDFWriter::StructElement eType );
163 // These functions are called by the c'tor, d'tor
164 void BeginNumberedListStructureElements();
165 void BeginBlockStructureElements();
166 void BeginInlineStructureElements();
167 void EndStructureElements();
169 void EndCurrentAll();
170 void EndCurrentSpan();
171 void CreateCurrentSpan(SwTextPaintInfo const& rInf, OUString const& rStyleName);
172 bool CheckContinueSpan(SwTextPaintInfo const& rInf, std::u16string_view rStyleName, SwTextAttr const* pInetFormatAttr);
174 bool CheckReopenTag();
175 void CheckRestoreTag() const;
177 public:
179 // pFrameInfo != 0 => BeginBlockStructureElement
180 // pPorInfo != 0 => BeginInlineStructureElement
181 // pFrameInfo, pPorInfo = 0 => BeginNonStructureElement
182 SwTaggedPDFHelper( const Num_Info* pNumInfo, const Frame_Info* pFrameInfo, const Por_Info* pPorInfo,
183 OutputDevice const & rOut );
184 ~SwTaggedPDFHelper();
186 static bool IsExportTaggedPDF( const OutputDevice& rOut );
187 static void EndCurrentLink(OutputDevice const&);
191 * Analyses the document structure and export Notes, Hyperlinks, References,
192 * and Outline. Link ids created during pdf export are stored in
193 * SwEnhancedPDFState, in order to use them during
194 * tagged pdf output. Therefore the SwEnhancedPDFExportHelper is used
195 * before painting. Unfortunately links from the EditEngine into the
196 * Writer document require to be exported after they have been painted.
197 * Therefore SwEnhancedPDFExportHelper also has to be used after the
198 * painting process, the parameter bEditEngineOnly indicated that only
199 * the bookmarks from the EditEngine have to be processed.
201 class SwEnhancedPDFExportHelper
203 private:
205 SwEditShell& mrSh;
206 OutputDevice& mrOut;
208 std::unique_ptr<StringRangeEnumerator> mpRangeEnum;
209 /** The problem is that numbers in StringRangeEnumerator aren't accordant
210 * to real page numbers if mbSkipEmptyPages is true, because in this case
211 * empty pages are excluded from a page range and numbers in
212 * StringRangeEnumerator are shifted.
214 * maPageNumberMap[real_page_number] is either a corresponding page number
215 * in a page range without empty pages, or -1 if this page is empty. */
216 std::vector< sal_Int32 > maPageNumberMap;
218 bool mbSkipEmptyPages;
219 bool mbEditEngineOnly;
221 const SwPrintData& mrPrintData;
223 void EnhancedPDFExport(LanguageType const eLanguageDefault);
225 /// Exports bibliography entry links.
226 void ExportAuthorityEntryLinks();
228 sal_Int32 CalcOutputPageNum( const SwRect& rRect ) const;
229 std::vector< sal_Int32 > CalcOutputPageNums( const SwRect& rRect ) const;
231 void MakeHeaderFooterLinks( vcl::PDFExtOutDevData& rPDFExtOutDevData,
232 const SwTextNode& rTNd, const SwRect& rLinkRect,
233 sal_Int32 nDestId, const OUString& rURL,
234 bool bIntern, OUString const& rContent) const;
236 public:
238 SwEnhancedPDFExportHelper( SwEditShell& rSh,
239 OutputDevice& rOut,
240 const OUString& rPageRange,
241 bool bSkipEmptyPages,
242 bool bEditEngineOnly,
243 const SwPrintData& rPrintData );
245 ~SwEnhancedPDFExportHelper();
247 //scale and position rRectangle if we're scaling due to notes in margins.
248 tools::Rectangle SwRectToPDFRect(const SwPageFrame* pCurrPage,
249 const tools::Rectangle& rRectangle) const;
251 static tools::Rectangle MapSwRectToPDFRect(const SwPageFrame* pCurrPage,
252 const tools::Rectangle& rRectangle);
253 static double GetSwRectToPDFRectScale();
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */