LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/vcl - ppdparser.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 25 0.0 %
Date: 2012-12-27 Functions: 0 22 0.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             : #ifndef _PSPRINT_PPDPARSER_HXX_
      20             : #define _PSPRINT_PPDPARSER_HXX_
      21             : 
      22             : #include <list>
      23             : #include <vector>
      24             : #include <boost/unordered_map.hpp>
      25             : 
      26             : #include "tools/string.hxx"
      27             : #include "tools/stream.hxx"
      28             : #include "rtl/string.hxx"
      29             : 
      30             : #include "vcl/dllapi.h"
      31             : 
      32             : #include "com/sun/star/lang/Locale.hpp"
      33             : 
      34             : #define PRINTER_PPDDIR "driver"
      35             : 
      36             : namespace psp {
      37             : 
      38             : class PPDParser;
      39             : class PPDTranslator;
      40             : 
      41             : enum PPDValueType { eInvocation, eQuoted, eSymbol, eString, eNo };
      42             : 
      43           0 : struct VCL_DLLPUBLIC PPDValue
      44             : {
      45             :     PPDValueType    m_eType;
      46             :     String          m_aOption;
      47             :     String          m_aValue;
      48             : };
      49             : 
      50             : // ----------------------------------------------------------------------
      51             : 
      52             : /*
      53             :  * PPDKey - a container for the available options (=values) of a PPD keyword
      54             :  */
      55             : 
      56             : class VCL_DLLPUBLIC PPDKey
      57             : {
      58             :     friend class PPDParser;
      59             : 
      60             :     typedef ::boost::unordered_map< ::rtl::OUString, PPDValue, ::rtl::OUStringHash > hash_type;
      61             :     typedef ::std::vector< PPDValue* > value_type;
      62             : 
      63             :     String              m_aKey;
      64             :     hash_type           m_aValues;
      65             :     value_type          m_aOrderedValues;
      66             :     const PPDValue*     m_pDefaultValue;
      67             :     bool                m_bQueryValue;
      68             :     PPDValue            m_aQueryValue;
      69             : 
      70             : public:
      71             :     enum UIType { PickOne, PickMany, Boolean };
      72             :     enum SetupType { ExitServer, Prolog, DocumentSetup, PageSetup, JCLSetup, AnySetup };
      73             : private:
      74             : 
      75             :     bool                m_bUIOption;
      76             :     UIType              m_eUIType;
      77             :     int                 m_nOrderDependency;
      78             :     SetupType           m_eSetupType;
      79             : 
      80             :     void eraseValue( const String& rOption );
      81             : public:
      82             :     PPDKey( const String& rKey );
      83             :     ~PPDKey();
      84             : 
      85             :     PPDValue*           insertValue( const String& rOption );
      86           0 :     int                 countValues() const
      87           0 :     { return m_aValues.size(); }
      88             :     // neither getValue will return the query option
      89             :     const PPDValue*         getValue( int n ) const;
      90             :     const PPDValue*         getValue( const String& rOption ) const;
      91             :     const PPDValue*         getValueCaseInsensitive( const String& rOption ) const;
      92           0 :     const PPDValue*         getDefaultValue() const { return m_pDefaultValue; }
      93             :     const PPDValue*     getQueryValue() const { return m_bQueryValue ? &m_aQueryValue : NULL; }
      94             : 
      95           0 :     const String&       getKey() const { return m_aKey; }
      96           0 :     bool                isUIKey() const { return m_bUIOption; }
      97             :     UIType              getUIType() const { return m_eUIType; }
      98           0 :     SetupType           getSetupType() const { return m_eSetupType; }
      99           0 :     int                 getOrderDependency() const { return m_nOrderDependency; }
     100             : };
     101             : 
     102             : // define a hash for PPDKey
     103             : struct PPDKeyhash
     104             : {
     105           0 :     size_t operator()( const PPDKey * pKey) const
     106           0 :         { return (size_t)pKey; }
     107             : };
     108             : 
     109             : // ----------------------------------------------------------------------
     110             : 
     111             : /*
     112             :  * PPDParser - parses a PPD file and contains all available keys from it
     113             :  */
     114             : 
     115             : class PPDContext;
     116             : class CUPSManager;
     117             : 
     118             : class VCL_DLLPUBLIC PPDParser
     119             : {
     120             :     friend class PPDContext;
     121             :     friend class CUPSManager;
     122             :     friend class PPDCache;
     123             : 
     124             :     typedef ::boost::unordered_map< ::rtl::OUString, PPDKey*, ::rtl::OUStringHash > hash_type;
     125             :     typedef ::std::vector< PPDKey* > value_type;
     126             : 
     127             :     void insertKey( const String& rKey, PPDKey* pKey );
     128             : public:
     129             :     struct PPDConstraint
     130             :     {
     131             :         const PPDKey*       m_pKey1;
     132             :         const PPDValue*     m_pOption1;
     133             :         const PPDKey*       m_pKey2;
     134             :         const PPDValue*     m_pOption2;
     135             : 
     136           0 :         PPDConstraint() : m_pKey1( NULL ), m_pOption1( NULL ), m_pKey2( NULL ), m_pOption2( NULL ) {}
     137             :     };
     138             : private:
     139             :     hash_type                                   m_aKeys;
     140             :     value_type                                  m_aOrderedKeys;
     141             :     ::std::list< PPDConstraint >                m_aConstraints;
     142             : 
     143             :     // some identifying fields
     144             :     String                                      m_aPrinterName;
     145             :     String                                      m_aNickName;
     146             :     // the full path of the PPD file
     147             :     String                                      m_aFile;
     148             :     // some basic attributes
     149             :     bool                                        m_bColorDevice;
     150             :     bool                                        m_bType42Capable;
     151             :     sal_uLong                                       m_nLanguageLevel;
     152             :     rtl_TextEncoding                            m_aFileEncoding;
     153             : 
     154             : 
     155             :     // shortcuts to important keys and their default values
     156             :     // imageable area
     157             :     const PPDValue*                             m_pDefaultImageableArea;
     158             :     const PPDKey*                               m_pImageableAreas;
     159             :     // paper dimensions
     160             :     const PPDValue*                             m_pDefaultPaperDimension;
     161             :     const PPDKey*                               m_pPaperDimensions;
     162             :     // paper trays
     163             :     const PPDValue*                             m_pDefaultInputSlot;
     164             :     const PPDKey*                               m_pInputSlots;
     165             :     // resolutions
     166             :     const PPDValue*                             m_pDefaultResolution;
     167             :     const PPDKey*                               m_pResolutions;
     168             :     // duplex commands
     169             :     const PPDValue*                             m_pDefaultDuplexType;
     170             :     const PPDKey*                               m_pDuplexTypes;
     171             : 
     172             :     // fonts
     173             :     const PPDKey*                               m_pFontList;
     174             : 
     175             :     // translations
     176             :     PPDTranslator*                              m_pTranslator;
     177             : 
     178             :     PPDParser( const String& rFile );
     179             :     ~PPDParser();
     180             : 
     181             :     void parseOrderDependency(const rtl::OString& rLine);
     182             :     void parseOpenUI(const rtl::OString& rLine);
     183             :     void parseConstraint(const rtl::OString& rLine);
     184             :     void parse( std::list< rtl::OString >& rLines );
     185             : 
     186             :     String handleTranslation(const rtl::OString& i_rString, bool i_bIsGlobalized);
     187             : 
     188             :     static void scanPPDDir( const String& rDir );
     189             :     static void initPPDFiles();
     190             :     static String getPPDFile( const String& rFile );
     191             : public:
     192             :     static const PPDParser* getParser( const String& rFile );
     193             :     static String getPPDPrinterName( const String& rFile );
     194             :     static void freeAll();
     195             :     static void getKnownPPDDrivers( std::list< rtl::OUString >& o_rDrivers, bool bRefresh = false );
     196             : 
     197           0 :     const String&   getFilename() const { return m_aFile; }
     198             : 
     199             :     const PPDKey*   getKey( int n ) const;
     200             :     const PPDKey*   getKey( const String& rKey ) const;
     201           0 :     int             getKeys() const { return m_aKeys.size(); }
     202             :     bool            hasKey( const PPDKey* ) const;
     203             : 
     204           0 :     const ::std::list< PPDConstraint >& getConstraints() const { return m_aConstraints; }
     205             : 
     206           0 :     const String&   getPrinterName() const
     207           0 :     { return m_aPrinterName.Len() ? m_aPrinterName : m_aNickName; }
     208             :     const String&   getNickName() const
     209             :     { return m_aNickName.Len() ? m_aNickName : m_aPrinterName; }
     210             : 
     211           0 :     bool            isColorDevice() const { return m_bColorDevice; }
     212           0 :     bool            isType42Capable() const { return m_bType42Capable; }
     213           0 :     sal_uLong           getLanguageLevel() const { return m_nLanguageLevel; }
     214             : 
     215             :     String          getDefaultPaperDimension() const;
     216           0 :     void            getDefaultPaperDimension( int& rWidth, int& rHeight ) const
     217           0 :     { getPaperDimension( getDefaultPaperDimension(), rWidth, rHeight ); }
     218             :     bool getPaperDimension( const String& rPaperName,
     219             :                             int& rWidth, int& rHeight ) const;
     220             :     // width and height in pt
     221             :     // returns false if paper not found
     222             :     int             getPaperDimensions() const
     223             :     { return m_pPaperDimensions ? m_pPaperDimensions->countValues() : 0; }
     224             : 
     225             :     // match the best paper for width and height
     226             :     String          matchPaper( int nWidth, int nHeight ) const;
     227             : 
     228             :     bool getMargins( const String& rPaperName,
     229             :                      int &rLeft, int& rRight,
     230             :                      int &rUpper, int& rLower ) const;
     231             :     // values in pt
     232             :     // returns true if paper found
     233             : 
     234             :     // values int pt
     235             : 
     236             :     String          getDefaultInputSlot() const;
     237             :     int             getInputSlots() const
     238             :     { return m_pInputSlots ? m_pInputSlots->countValues() : 0; }
     239             : 
     240             :     void            getDefaultResolution( int& rXRes, int& rYRes ) const;
     241             :     // values in dpi
     242             :     void            getResolutionFromString( const String&, int&, int& ) const;
     243             :     // helper function
     244             : 
     245             :     int             getDuplexTypes() const
     246             :     { return m_pDuplexTypes ? m_pDuplexTypes->countValues() : 0; }
     247             : 
     248           0 :     int             getFonts() const
     249           0 :     { return m_pFontList ? m_pFontList->countValues() : 0; }
     250             :     String          getFont( int ) const;
     251             : 
     252             : 
     253             :     rtl::OUString   translateKey( const rtl::OUString& i_rKey,
     254             :                                   const com::sun::star::lang::Locale& i_rLocale = com::sun::star::lang::Locale() ) const;
     255             :     rtl::OUString   translateOption( const rtl::OUString& i_rKey,
     256             :                                      const rtl::OUString& i_rOption,
     257             :                                      const com::sun::star::lang::Locale& i_rLocale = com::sun::star::lang::Locale() ) const;
     258             : };
     259             : 
     260             : // ----------------------------------------------------------------------
     261             : 
     262             : /*
     263             :  * PPDContext - a class to manage user definable states based on the
     264             :  * contents of a PPDParser.
     265             :  */
     266             : 
     267             : class VCL_DLLPUBLIC PPDContext
     268             : {
     269             :     typedef ::boost::unordered_map< const PPDKey*, const PPDValue*, PPDKeyhash > hash_type;
     270             :     hash_type m_aCurrentValues;
     271             :     const PPDParser*                                    m_pParser;
     272             : 
     273             :     // returns false: check failed, new value is constrained
     274             :     //         true:  check succeded, new value can be set
     275             :     bool checkConstraints( const PPDKey*, const PPDValue*, bool bDoReset );
     276             :     bool resetValue( const PPDKey*, bool bDefaultable = false );
     277             : public:
     278             :     PPDContext( const PPDParser* pParser = NULL );
     279             :     PPDContext( const PPDContext& rContext ) { operator=( rContext ); }
     280             :     PPDContext& operator=( const PPDContext& rContext );
     281             :     ~PPDContext();
     282             : 
     283             :     void setParser( const PPDParser* );
     284           0 :     const PPDParser* getParser() const { return m_pParser; }
     285             : 
     286             :     const PPDValue* getValue( const PPDKey* ) const;
     287             :     const PPDValue* setValue( const PPDKey*, const PPDValue*, bool bDontCareForConstraints = false );
     288             : 
     289           0 :     int countValuesModified() const { return m_aCurrentValues.size(); }
     290             :     const PPDKey* getModifiedKey( int n ) const;
     291             : 
     292             :     // public wrapper for the private method
     293             :     bool checkConstraints( const PPDKey*, const PPDValue* );
     294             : 
     295             :     // for printer setup
     296             :     char*   getStreamableBuffer( sal_uLong& rBytes ) const;
     297             :     void    rebuildFromStreamBuffer( char* pBuffer, sal_uLong nBytes );
     298             : 
     299             :     // convenience
     300             :     int getRenderResolution() const;
     301             : 
     302             :     // width, height in points, paper will contain the name of the selected
     303             :     // paper after the call
     304             :     void getPageSize( rtl::OUString& rPaper, int& rWidth, int& rHeight ) const;
     305             : };
     306             : 
     307             : } // namespace
     308             : 
     309             : #endif // _PSPRINT_PPDPARSER_HXX_
     310             : 
     311             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10