LCOV - code coverage report
Current view: top level - sw/inc - EnhancedPDFExportHelper.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 4 12 33.3 %
Date: 2015-06-13 12:38:46 Functions: 3 10 30.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <vcl/pdfextoutdevdata.hxx>
      24             : #include <i18nlangtag/lang.h>
      25             : #include <swrect.hxx>
      26             : #include <swtypes.hxx>
      27             : 
      28             : #include <map>
      29             : #include <vector>
      30             : #include <set>
      31             : 
      32             : namespace vcl
      33             : {
      34             :     class PDFExtOutDevData;
      35             : }
      36             : class OutputDevice;
      37             : class SwFrm;
      38             : class SwLinePortion;
      39             : class SwPageFrm;
      40             : class SwPrintData;
      41             : class SwTextPainter;
      42             : class SwEditShell;
      43             : class StringRangeEnumerator;
      44             : class SwTextNode;
      45             : class SwNumRule;
      46             : class SwTable;
      47             : class SwNumberTreeNode;
      48             : class SvxLanguageItem;
      49             : 
      50             : /*
      51             :  * Mapping of OOo elements to tagged pdf elements:
      52             :  *
      53             :  * OOo element                              tagged pdf element
      54             :  * -----------                              ------------------
      55             :  *
      56             :  * Grouping elements:
      57             :  *
      58             :  * SwRootFrm                                Document
      59             :  *                                          Part
      60             :  *                                          Art
      61             :  * SwSection                                Sect
      62             :  * SwFootnoteContFrm and SwFlyFrm                Div
      63             :  * SwFormat "Quotations"                       BlockQuote
      64             :  * SwFormat "Caption"                          Caption
      65             :  * SwSection (TOC)                          TOC
      66             :  * SwTextNode in TOC                         TOCI
      67             :  * SwSection (Index)                        Index
      68             :  *
      69             :  * Block-Level Structure Elements:
      70             :  *
      71             :  * SwTextNode                                P
      72             :  * SwFormat "Heading"                          H
      73             :  * SwTextNode with Outline                   H1 - H6
      74             :  * SwTextNode with NumRule                   L, LI, LBody
      75             :  * SwTable                                  Table
      76             :  * SwRowFrm                                 TR
      77             :  * SwCellFrm in Headline row or
      78             :  * SwFtm "Table Heading"                    TH
      79             :  * SwCellFrm                                TD
      80             :  *
      81             :  * Inline-Level Structure Elements:
      82             :  *
      83             :  * SwTextPortion                             Span
      84             :  * SwFormat "Quotation"                        Quote
      85             :  * SwFootnoteFrm                                 Note
      86             :  *                                          Form
      87             :  *                                          Reference
      88             :  * SwFieldPortion (AuthorityField)            BibEntry
      89             :  * SwFormat "Source Text"                      Code
      90             :  * SwFootnotePortion, SwFieldPortion (RefField)    Link
      91             :  *
      92             :  * Illustration elements:
      93             :  *
      94             :  * SwFlyFrm with SwNoTextFrm                 Figure
      95             :  * SwFlyFrm with Math OLE Object            Formula
      96             :  *
      97             :  */
      98             : 
      99             : struct Num_Info
     100             : {
     101             :     const SwFrm& mrFrm;
     102       17715 :     Num_Info( const SwFrm& rFrm ) : mrFrm( rFrm ) {};
     103             : };
     104             : 
     105             : struct Frm_Info
     106             : {
     107             :     const SwFrm& mrFrm;
     108       44026 :     Frm_Info( const SwFrm& rFrm ) : mrFrm( rFrm ) {};
     109             : };
     110             : 
     111             : struct Por_Info
     112             : {
     113             :     const SwLinePortion& mrPor;
     114             :     const SwTextPainter& mrTextPainter;
     115       34236 :     Por_Info( const SwLinePortion& rPor, const SwTextPainter& rTextPainer )
     116       34236 :             : mrPor( rPor ), mrTextPainter( rTextPainer ) {};
     117             : };
     118             : 
     119             : struct lt_TableColumn
     120             : {
     121           0 :     bool operator()( long nVal1, long nVal2 ) const
     122             :     {
     123           0 :         return nVal1 + ( MINLAY - 1 ) < nVal2;
     124             :     }
     125             : };
     126             : 
     127             : // Analyses a given frame during painting and generates the appropriate
     128             : // structure elements.
     129             : class SwTaggedPDFHelper
     130             : {
     131             :     private:
     132             : 
     133             :     // This will be incremented for each BeginTag() call.
     134             :     // It denotes the number of tags to close during EndStructureElements();
     135             :     sal_uInt8 nEndStructureElement;
     136             : 
     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;
     140             : 
     141             :     vcl::PDFExtOutDevData* mpPDFExtOutDevData;
     142             : 
     143             :     const Num_Info* mpNumInfo;
     144             :     const Frm_Info* mpFrmInfo;
     145             :     const Por_Info* mpPorInfo;
     146             : 
     147             :     void BeginTag( vcl::PDFWriter::StructElement aTagRole, const OUString& rTagName );
     148             :     void EndTag();
     149             : 
     150             :     void SetAttributes( vcl::PDFWriter::StructElement eType );
     151             : 
     152             :     // These functions are called by the c'tor, d'tor
     153             :     void BeginNumberedListStructureElements();
     154             :     void BeginBlockStructureElements();
     155             :     void BeginInlineStructureElements();
     156             :     void EndStructureElements();
     157             : 
     158             :     bool CheckReopenTag();
     159             :     bool CheckRestoreTag() const;
     160             : 
     161             :     public:
     162             : 
     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();
     169             : 
     170             :     static bool IsExportTaggedPDF( const OutputDevice& rOut );
     171             : };
     172             : 
     173             : /*
     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.
     183             :  */
     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;
     191             : 
     192             : class SwEnhancedPDFExportHelper
     193             : {
     194             :     private:
     195             : 
     196             :     SwEditShell& mrSh;
     197             :     OutputDevice& mrOut;
     198             : 
     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.
     204             :      *
     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;
     208             : 
     209             :     bool mbSkipEmptyPages;
     210             :     bool mbEditEngineOnly;
     211             : 
     212             :     const SwPrintData& mrPrintData;
     213             : 
     214             :     static TableColumnsMap aTableColumnsMap;
     215             :     static LinkIdMap aLinkIdMap;
     216             :     static NumListIdMap aNumListIdMap;
     217             :     static NumListBodyIdMap aNumListBodyIdMap;
     218             :     static FrmTagIdMap aFrmTagIdMap;
     219             : 
     220             :     static LanguageType eLanguageDefault;
     221             : 
     222             :     void EnhancedPDFExport();
     223             :     sal_Int32 CalcOutputPageNum( const SwRect& rRect ) const;
     224             :     std::vector< sal_Int32 > CalcOutputPageNums( const SwRect& rRect ) const;
     225             : 
     226             :     void MakeHeaderFooterLinks( vcl::PDFExtOutDevData& rPDFExtOutDevData,
     227             :                                 const SwTextNode& rTNd, const SwRect& rLinkRect,
     228             :                                 sal_Int32 nDestId, const OUString& rURL, bool bIntern ) const;
     229             : 
     230             :     public:
     231             : 
     232             :     SwEnhancedPDFExportHelper( SwEditShell& rSh,
     233             :                                OutputDevice& rOut,
     234             :                                const OUString& rPageRange,
     235             :                                bool bSkipEmptyPages,
     236             :                                bool bEditEngineOnly,
     237             :                                const SwPrintData& rPrintData );
     238             : 
     239             :     ~SwEnhancedPDFExportHelper();
     240             : 
     241           0 :     static TableColumnsMap& GetTableColumnsMap() {return aTableColumnsMap; }
     242           0 :     static LinkIdMap& GetLinkIdMap() { return aLinkIdMap; }
     243           0 :     static NumListIdMap& GetNumListIdMap() {return aNumListIdMap; }
     244           0 :     static NumListBodyIdMap& GetNumListBodyIdMap() {return aNumListBodyIdMap; }
     245           0 :     static FrmTagIdMap& GetFrmTagIdMap() { return aFrmTagIdMap; }
     246             : 
     247           0 :     static LanguageType GetDefaultLanguage() {return eLanguageDefault; }
     248             : 
     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;
     252             : };
     253             : 
     254             : #endif
     255             : 
     256             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11