LCOV - code coverage report
Current view: top level - libreoffice/sw/inc - EnhancedPDFExportHelper.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 4 12 33.3 %
Date: 2012-12-27 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 _ENHANCEDPDFEXPORTHELPER_HXX
      21             : #define _ENHANCEDPDFEXPORTHELPER_HXX
      22             : 
      23             : #include <vcl/pdfextoutdevdata.hxx>
      24             : #include <i18npool/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 SwTxtPainter;
      40             : class SwEditShell;
      41             : namespace rtl
      42             : {
      43             :     class OUString;
      44             : }
      45             : class StringRangeEnumerator;
      46             : class SwTxtNode;
      47             : class SwNumRule;
      48             : class SwTable;
      49             : class SwNumberTreeNode;
      50             : class String;
      51             : class SvxLanguageItem;
      52             : 
      53             : 
      54             : /*
      55             :  * Mapping of OOo elements to tagged pdf elements:
      56             :  *
      57             :  * OOo element                              tagged pdf element
      58             :  * -----------                              ------------------
      59             :  *
      60             :  * Grouping elements:
      61             :  *
      62             :  * SwRootFrm                                Document
      63             :  *                                          Part
      64             :  *                                          Art
      65             :  * SwSection                                Sect
      66             :  * SwFtnContFrm and SwFlyFrm                Div
      67             :  * SwFmt "Quotations"                       BlockQuote
      68             :  * SwFmt "Caption"                          Caption
      69             :  * SwSection (TOC)                          TOC
      70             :  * SwTxtNode in TOC                         TOCI
      71             :  * SwSection (Index)                        Index
      72             :  *
      73             :  * Block-Level Structure Elements:
      74             :  *
      75             :  * SwTxtNode                                P
      76             :  * SwFmt "Heading"                          H
      77             :  * SwTxtNode with Outline                   H1 - H6
      78             :  * SwTxtNode with NumRule                   L, LI, LBody
      79             :  * SwTable                                  Table
      80             :  * SwRowFrm                                 TR
      81             :  * SwCellFrm in Headline row or
      82             :  * SwFtm "Table Heading"                    TH
      83             :  * SwCellFrm                                TD
      84             :  *
      85             :  * Inline-Level Structure Elements:
      86             :  *
      87             :  * SwTxtPortion                             Span
      88             :  * SwFmt "Quotation"                        Quote
      89             :  * SwFtnFrm                                 Note
      90             :  *                                          Form
      91             :  *                                          Reference
      92             :  * SwFldPortion (AuthorityField)            BibEntry
      93             :  * SwFmt "Source Text"                      Code
      94             :  * SwFtnPortion, SwFldPortion (RefField)    Link
      95             :  *
      96             :  * Illustration elements:
      97             :  *
      98             :  * SwFlyFrm with SwNoTxtFrm                 Figure
      99             :  * SwFlyFrm with Math OLE Object            Formula
     100             :  *
     101             :  */
     102             : 
     103             : struct Num_Info
     104             : {
     105             :     const SwFrm& mrFrm;
     106         705 :     Num_Info( const SwFrm& rFrm ) : mrFrm( rFrm ) {};
     107             : };
     108             : 
     109             : struct Frm_Info
     110             : {
     111             :     const SwFrm& mrFrm;
     112        1818 :     Frm_Info( const SwFrm& rFrm ) : mrFrm( rFrm ) {};
     113             : };
     114             : 
     115             : struct Por_Info
     116             : {
     117             :     const SwLinePortion& mrPor;
     118             :     const SwTxtPainter& mrTxtPainter;
     119         775 :     Por_Info( const SwLinePortion& rPor, const SwTxtPainter& rTxtPainer )
     120         775 :             : mrPor( rPor ), mrTxtPainter( rTxtPainer ) {};
     121             : };
     122             : 
     123             : struct lt_TableColumn
     124             : {
     125           0 :     bool operator()( long nVal1, long nVal2 ) const
     126             :     {
     127           0 :         return nVal1 + ( MINLAY - 1 ) < nVal2;
     128             :     }
     129             : };
     130             : 
     131             : /*************************************************************************
     132             :  *                class SwTaggedPDFHelper
     133             :  * Analyses a given frame during painting and generates the appropriate
     134             :  * structure elements.
     135             :  *************************************************************************/
     136             : 
     137             : class SwTaggedPDFHelper
     138             : {
     139             :     private:
     140             : 
     141             :     // This will be incremented for each BeginTag() call.
     142             :     // It denotes the number of tags to close during EndStructureElements();
     143             :     sal_uInt8 nEndStructureElement;
     144             : 
     145             :     //  If an already existing tag is reopened for follows of flow frames,
     146             :     // this value stores the tag id which has to be restored.
     147             :     sal_Int32 nRestoreCurrentTag;
     148             : 
     149             :     vcl::PDFExtOutDevData* mpPDFExtOutDevData;
     150             : 
     151             :     const Num_Info* mpNumInfo;
     152             :     const Frm_Info* mpFrmInfo;
     153             :     const Por_Info* mpPorInfo;
     154             : 
     155             :     void BeginTag( vcl::PDFWriter::StructElement aTagRole, const String& rTagName );
     156             :     void EndTag();
     157             : 
     158             :     void SetAttributes( vcl::PDFWriter::StructElement eType );
     159             : 
     160             :     // These functions are called by the c'tor, d'tor
     161             :     void BeginNumberedListStructureElements();
     162             :     void BeginBlockStructureElements();
     163             :     void BeginInlineStructureElements();
     164             :     void EndStructureElements();
     165             : 
     166             :     bool CheckReopenTag();
     167             :     bool CheckRestoreTag() const;
     168             : 
     169             :     public:
     170             : 
     171             :     // pFrmInfo != 0 => BeginBlockStructureElement
     172             :     // pPorInfo != 0 => BeginInlineStructureElement
     173             :     // pFrmInfo, pPorInfo = 0 => BeginNonStructureElement
     174             :     SwTaggedPDFHelper( const Num_Info* pNumInfo, const Frm_Info* pFrmInfo, const Por_Info* pPorInfo,
     175             :                        OutputDevice& rOut );
     176             :     ~SwTaggedPDFHelper();
     177             : 
     178             :     static bool IsExportTaggedPDF( const OutputDevice& rOut );
     179             : };
     180             : 
     181             : /*************************************************************************
     182             :  *                class SwEnhancedPDFExportHelper
     183             :  * Analyses the document structure and export Notes, Hyperlinks, References,
     184             :  * and Outline. Link ids created during pdf export are stored in
     185             :  * aReferenceIdMap and aHyperlinkIdMap, in order to use them during
     186             :  * tagged pdf output. Therefore the SwEnhancedPDFExportHelper is used
     187             :  * before painting. Unfortunately links from the EditEngine into the
     188             :  * Writer document require to be exported after they have been painted.
     189             :  * Therefore SwEnhancedPDFExportHelper also has to be used after the
     190             :  * painting process, the parameter bEditEngineOnly indicated that only
     191             :  * the bookmarks from the EditEngine have to be processed.
     192             :  *************************************************************************/
     193             : 
     194             : typedef std::set< long, lt_TableColumn > TableColumnsMapEntry;
     195             : typedef std::pair< SwRect, sal_Int32 > IdMapEntry;
     196             : typedef std::vector< IdMapEntry > LinkIdMap;
     197             : typedef std::map< const SwTable*, TableColumnsMapEntry > TableColumnsMap;
     198             : typedef std::map< const SwNumberTreeNode*, sal_Int32 > NumListIdMap;
     199             : typedef std::map< const SwNumberTreeNode*, sal_Int32 > NumListBodyIdMap;
     200             : typedef std::map< const void*, sal_Int32 > FrmTagIdMap;
     201             : 
     202             : class SwEnhancedPDFExportHelper
     203             : {
     204             :     private:
     205             : 
     206             :     SwEditShell& mrSh;
     207             :     OutputDevice& mrOut;
     208             : 
     209             :     StringRangeEnumerator* mpRangeEnum;
     210             :     /** The problem is that numbers in StringRangeEnumerator aren't accordant
     211             :      * to real page numbers if mbSkipEmptyPages is true, because in this case
     212             :      * empty pages are excluded from a page range and numbers in
     213             :      * StringRangeEnumerator are shifted.
     214             :      *
     215             :      * maPageNumberMap[real_page_number] is either a corresponding page number
     216             :      * in a page range without empty pages, or -1 if this page is empty. */
     217             :     std::vector< sal_Int32 > maPageNumberMap;
     218             : 
     219             :     bool mbSkipEmptyPages;
     220             :     bool mbEditEngineOnly;
     221             : 
     222             :     static TableColumnsMap aTableColumnsMap;
     223             :     static LinkIdMap aLinkIdMap;
     224             :     static NumListIdMap aNumListIdMap;
     225             :     static NumListBodyIdMap aNumListBodyIdMap;
     226             :     static FrmTagIdMap aFrmTagIdMap;
     227             : 
     228             :     static LanguageType eLanguageDefault;
     229             : 
     230             :     void EnhancedPDFExport();
     231             :     sal_Int32 CalcOutputPageNum( const SwRect& rRect ) const;
     232             :     std::vector< sal_Int32 > CalcOutputPageNums( const SwRect& rRect ) const;
     233             : 
     234             :     void MakeHeaderFooterLinks( vcl::PDFExtOutDevData& rPDFExtOutDevData,
     235             :                                 const SwTxtNode& rTNd, const SwRect& rLinkRect,
     236             :                                 sal_Int32 nDestId, const String& rURL, bool bIntern ) const;
     237             : 
     238             :     public:
     239             : 
     240             :     SwEnhancedPDFExportHelper( SwEditShell& rSh,
     241             :                                OutputDevice& rOut,
     242             :                                const rtl::OUString& rPageRange,
     243             :                                bool bSkipEmptyPages,
     244             :                                bool bEditEngineOnly );
     245             : 
     246             :     ~SwEnhancedPDFExportHelper();
     247             : 
     248           0 :     static TableColumnsMap& GetTableColumnsMap() {return aTableColumnsMap; }
     249           0 :     static LinkIdMap& GetLinkIdMap() { return aLinkIdMap; }
     250           0 :     static NumListIdMap& GetNumListIdMap() {return aNumListIdMap; }
     251           0 :     static NumListBodyIdMap& GetNumListBodyIdMap() {return aNumListBodyIdMap; }
     252           0 :     static FrmTagIdMap& GetFrmTagIdMap() { return aFrmTagIdMap; }
     253             : 
     254           0 :     static LanguageType GetDefaultLanguage() {return eLanguageDefault; }
     255             : };
     256             : 
     257             : #endif
     258             : 
     259             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10