LCOV - code coverage report
Current view: top level - vcl/inc/generic - printergfx.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 25 66 37.9 %
Date: 2014-11-03 Functions: 14 34 41.2 %
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_VCL_INC_GENERIC_PRINTERGFX_HXX
      21             : #define INCLUDED_VCL_INC_GENERIC_PRINTERGFX_HXX
      22             : 
      23             : #include "vcl/helper.hxx"
      24             : #include "sallayout.hxx"
      25             : #include "osl/file.hxx"
      26             : #include "tools/gen.hxx"
      27             : #include "vclpluginapi.h"
      28             : 
      29             : #include <list>
      30             : #include <boost/unordered_map.hpp>
      31             : 
      32             : namespace psp {
      33             : 
      34             : // forwards
      35             : struct JobData;
      36             : 
      37             : /*
      38             :  * lightweight container to handle RGB values
      39             :  */
      40             : 
      41             : class PrinterColor
      42             : {
      43             : public:
      44             : 
      45             :     enum    ColorSpace { eInvalid, eRGB };
      46             : 
      47             : private:
      48             : 
      49             :     sal_uInt8       mnRed;
      50             :     sal_uInt8       mnGreen;
      51             :     sal_uInt8       mnBlue;
      52             :     ColorSpace      meColorspace;
      53             : 
      54             : public:
      55             : 
      56        1360 :     PrinterColor()
      57             :         : mnRed(0)
      58             :         , mnGreen(0)
      59             :         , mnBlue(0)
      60        1360 :         , meColorspace(eInvalid)
      61        1360 :     {}
      62        2040 :     PrinterColor (sal_uInt16 nRed, sal_uInt16 nGreen,
      63             :                   sal_uInt16 nBlue) :
      64             :             mnRed   (nRed),
      65             :             mnGreen (nGreen),
      66             :             mnBlue  (nBlue),
      67        2040 :             meColorspace (eRGB)
      68        2040 :     {}
      69           0 :     PrinterColor (sal_uInt32 nRGB) :
      70           0 :             mnRed   ((nRGB & 0x00ff0000) >> 16),
      71           0 :             mnGreen ((nRGB & 0x0000ff00) >>  8),
      72             :             mnBlue  ((nRGB & 0x000000ff)      ),
      73           0 :             meColorspace (eRGB)
      74           0 :     {}
      75        4065 :     ~PrinterColor ()
      76        4065 :     {}
      77             : 
      78           0 :     bool        Is () const
      79           0 :     { return meColorspace != eInvalid; }
      80             : 
      81             :     ColorSpace      GetColorSpace () const
      82             :     { return meColorspace; }
      83           0 :     sal_uInt16      GetRed () const
      84           0 :     { return mnRed; }
      85           0 :     sal_uInt16      GetGreen () const
      86           0 :     { return mnGreen; }
      87           0 :     sal_uInt16      GetBlue () const
      88           0 :     { return mnBlue; }
      89           0 :     bool        operator== (const PrinterColor& aColor) const
      90             :     {
      91           0 :         return aColor.Is() && this->Is()
      92           0 :             && mnRed   == aColor.mnRed
      93           0 :             && mnGreen == aColor.mnGreen
      94           0 :             && mnBlue  == aColor.mnBlue;
      95             :     }
      96           0 :     bool        operator!= (const PrinterColor& aColor) const
      97           0 :     { return ! (aColor==*this); }
      98           0 :     PrinterColor&   operator= (const PrinterColor& aColor)
      99             :     {
     100           0 :         meColorspace = aColor.meColorspace;
     101           0 :         mnRed   = aColor.mnRed;
     102           0 :         mnGreen = aColor.mnGreen;
     103           0 :         mnBlue  = aColor.mnBlue;
     104             : 
     105           0 :         return *this;
     106             :     }
     107             : 
     108             :     PrinterColor&   operator= (sal_uInt32 nRGB)
     109             :     {
     110             :         meColorspace = eRGB;
     111             :         mnBlue  = (nRGB & 0x000000ff);
     112             :         mnGreen = (nRGB & 0x0000ff00) >>  8;
     113             :         mnRed   = (nRGB & 0x00ff0000) >> 16;
     114             : 
     115             :         return *this;
     116             :     }
     117             : };
     118             : 
     119             : /*
     120             :  * forward declarations
     121             :  */
     122             : 
     123             : class Font2;
     124             : class GlyphSet;
     125             : class PrinterJob;
     126             : class PrintFontManager;
     127             : struct CharacterMetric;
     128             : 
     129             : /*
     130             :  * Bitmap Interface, this has to be filled with your actual bitmap implementation
     131             :  * sample implementations can be found in:
     132             :  *      psprint/workben/cui/pspdem.cxx
     133             :  *      vcl/unx/source/gdi/salgdi2.cxx
     134             :  */
     135             : 
     136           0 : class VCL_DLLPUBLIC PrinterBmp
     137             : {
     138             : public:
     139             : 
     140             :     virtual             ~PrinterBmp ()  = 0;
     141             :     virtual sal_uInt32  GetPaletteColor (sal_uInt32 nIdx) const = 0;
     142             :     virtual sal_uInt32  GetPaletteEntryCount ()           const = 0;
     143             :     virtual sal_uInt32  GetPixelRGB  (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0;
     144             :     virtual sal_uInt8   GetPixelGray (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0;
     145             :     virtual sal_uInt8   GetPixelIdx  (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0;
     146             :     virtual sal_uInt32  GetWidth ()     const = 0;
     147             :     virtual sal_uInt32  GetHeight ()    const = 0;
     148             :     virtual sal_uInt32  GetDepth ()     const = 0;
     149             : };
     150             : 
     151             : typedef enum {
     152             :     InvalidType = 0,
     153             :     TrueColorImage,
     154             :     MonochromeImage,
     155             :     PaletteImage,
     156             :     GrayScaleImage
     157             : } ImageType;
     158             : 
     159             : /*
     160             :  * printer raster operations
     161             :  */
     162             : 
     163        2714 : struct GraphicsStatus
     164             : {
     165             :     OString        maFont;
     166             :     rtl_TextEncoding    maEncoding;
     167             :     bool                mbArtItalic;
     168             :     bool                mbArtBold;
     169             :     sal_Int32           mnTextHeight;
     170             :     sal_Int32           mnTextWidth;
     171             :     PrinterColor        maColor;
     172             :     double             mfLineWidth;
     173             : 
     174             :     GraphicsStatus();
     175             : };
     176             : 
     177             : class Font2;
     178             : 
     179             : class VCL_DLLPUBLIC PrinterGfx
     180             : {
     181             : private:
     182             : 
     183             :     /* common settings */
     184             : 
     185             :     double          mfScaleX;
     186             :     double          mfScaleY;
     187             : 
     188             :     sal_uInt32      mnDpi;
     189             :     sal_uInt16      mnDepth;
     190             : 
     191             :     sal_uInt16      mnPSLevel;
     192             :     bool        mbColor;
     193             :     bool        mbUploadPS42Fonts;
     194             : 
     195             :     osl::File*      mpPageHeader;
     196             :     osl::File*      mpPageBody;
     197             : 
     198             :     void            TranslateCoordinates (sal_Int32 &rXOut, sal_Int32 &rYOut,
     199             :                                           sal_Int32 nXIn, sal_Int32 nYIn )
     200             :     { rXOut = nXIn; rYOut = nYIn; }
     201             :     void            TranslateCoordinates (Point& rOut, const Point& rIn)
     202             :     { rOut = rIn; }
     203             : 
     204             :     /* text/font related data, for a type1 font it has to be checked
     205             :        whether this font has already been downloaded. A TrueType font
     206             :        will be converted into one or more Type3 fonts, containing glyphs
     207             :        in no particular order. In addition to the existence of the
     208             :        glyph in one of the subfonts, the mapping from unicode to the
     209             :        glyph has to be remembered */
     210             : 
     211             :     std::list< sal_Int32 > maPS1Font;
     212             :     std::list< GlyphSet > maPS3Font;
     213             : 
     214             :     sal_Int32       mnFontID;
     215             :     sal_Int32       mnFallbackID;
     216             :     sal_Int32       mnTextAngle;
     217             :     bool           mbTextVertical;
     218             :     PrintFontManager& mrFontMgr;
     219             : 
     220             :     /* bitmap drawing implementation */
     221             : 
     222             :     bool    mbCompressBmp;
     223             : 
     224             :     void    DrawPS1GrayImage      (const PrinterBmp& rBitmap, const Rectangle& rArea);
     225             :     void    writePS2ImageHeader   (const Rectangle& rArea, psp::ImageType nType);
     226             :     void    writePS2Colorspace    (const PrinterBmp& rBitmap, psp::ImageType nType);
     227             :     void    DrawPS2GrayImage      (const PrinterBmp& rBitmap, const Rectangle& rArea);
     228             :     void    DrawPS2PaletteImage   (const PrinterBmp& rBitmap, const Rectangle& rArea);
     229             :     void    DrawPS2TrueColorImage (const PrinterBmp& rBitmap, const Rectangle& rArea);
     230             :     void    DrawPS2MonoImage      (const PrinterBmp& rBitmap, const Rectangle& rArea);
     231             : 
     232             :     /* clip region */
     233             : 
     234             :     std::list< Rectangle > maClipRegion;
     235             :     bool JoinVerticalClipRectangles( std::list< Rectangle >::iterator& it,
     236             :                                          Point& aOldPoint, sal_Int32& nColumn );
     237             : 
     238             :     /* color settings */
     239             :     PrinterColor    maFillColor;
     240             :     PrinterColor    maTextColor;
     241             :     PrinterColor    maLineColor;
     242             : 
     243             :     /* graphics state */
     244             :     GraphicsStatus                  maVirtualStatus;
     245             :     std::list< GraphicsStatus >     maGraphicsStack;
     246           0 :     GraphicsStatus& currentState() { return maGraphicsStack.front(); }
     247             : 
     248             :     /* font */
     249             :     friend class Font2;
     250             :     int             getCharWidth (bool b_vert, sal_Unicode n_char,
     251             :                                   CharacterMetric *p_bbox);
     252             :     fontID          getCharMetric (const Font2 &rFont, sal_Unicode n_char,
     253             :                                    CharacterMetric *p_bbox);
     254        4172 :     fontID          getFallbackID () const { return mnFallbackID; }
     255             : 
     256             : public:
     257             :     /* grahics status update */
     258             :     void            PSSetColor ();
     259             :     void            PSSetLineWidth ();
     260             :     void            PSSetFont ();
     261             : 
     262             :     /* graphics status functions */
     263           0 :     void            PSSetColor (const PrinterColor& rColor)
     264           0 :     { maVirtualStatus.maColor = rColor; }
     265             : 
     266             :     void            PSUploadPS1Font (sal_Int32 nFontID);
     267           0 :     void            PSSetFont (const OString& rName,
     268             :                                rtl_TextEncoding nEncoding = RTL_TEXTENCODING_DONTKNOW)
     269           0 :     { maVirtualStatus.maFont = rName; maVirtualStatus.maEncoding = nEncoding; }
     270             : 
     271             :     /* graphics status stack */
     272             :     void            PSGSave ();
     273             :     void            PSGRestore ();
     274             : 
     275             :     /* PS helpers */
     276             :     enum pspath_t { moveto = 0, lineto = 1 };
     277             :     void            PSBinLineTo (const Point& rCurrent, Point& rOld,
     278             :                                  sal_Int32& nColumn);
     279             :     void            PSBinMoveTo (const Point& rCurrent, Point& rOld,
     280             :                                  sal_Int32& nColumn);
     281             :     void            PSBinStartPath ();
     282             :     void            PSBinEndPath ();
     283             :     void            PSBinCurrentPath (sal_uInt32 nPoints, const Point* pPath);
     284             :     void            PSBinPath (const Point& rCurrent, Point& rOld,
     285             :                                pspath_t eType, sal_Int32& nColumn);
     286             : 
     287             :     void            PSRotate (sal_Int32 nAngle);
     288             :     void            PSTranslate (const Point& rPoint);
     289             :     void            PSMoveTo (const Point& rPoint);
     290             :     void            PSScale (double fScaleX, double fScaleY);
     291             :     void            PSLineTo(const Point& rPoint );
     292             :     void            PSPointOp (const Point& rPoint, const sal_Char* pOperator);
     293             :     void            PSHexString (const unsigned char* pString, sal_Int16 nLen);
     294             :     void            PSDeltaArray (const sal_Int32 *pArray, sal_Int16 nEntries);
     295             :     void            PSShowText (const unsigned char* pString,
     296             :                                 sal_Int16 nGlyphs, sal_Int16 nBytes,
     297             :                                 const sal_Int32* pDeltaArray = NULL);
     298             :     void            PSComment (const sal_Char* pComment );
     299             :     void            LicenseWarning (const Point& rPoint, const sal_Unicode* pStr,
     300             :                                     sal_Int16 nLen, const sal_Int32* pDeltaArray);
     301             : 
     302             :     void            OnEndPage ();
     303             :     void            OnEndJob ();
     304             :     void            writeResources( osl::File* pFile, std::list< OString >& rSuppliedFonts );
     305        5426 :     PrintFontManager& GetFontMgr () { return mrFontMgr; }
     306             : 
     307             :     bool            drawVerticalizedText (const Point& rPoint,
     308             :                                           const sal_Unicode* pStr,
     309             :                                           sal_Int16 nLen,
     310             :                                           const sal_Int32* pDeltaArray );
     311             :     void            drawText (const Point& rPoint,
     312             :                               const sal_Unicode* pStr, sal_Int16 nLen,
     313             :                               const sal_Int32* pDeltaArray = NULL);
     314             : 
     315             :     void            drawGlyphs( const Point& rPoint,
     316             :                                 sal_GlyphId* pGlyphIds,
     317             :                                 sal_Unicode* pUnicodes,
     318             :                                 sal_Int16 nLen,
     319             :                                 sal_Int32* pDeltaArray );
     320             : public:
     321             :     PrinterGfx();
     322             :     ~PrinterGfx();
     323             :     bool        Init (PrinterJob &rPrinterSpec);
     324             :     bool        Init (const JobData& rData);
     325             :     void            Clear();
     326             : 
     327             :     // query depth
     328           0 :     sal_uInt16      GetBitCount () { return mnDepth;}
     329             : 
     330             :     // clip region
     331             :     void            ResetClipRegion ();
     332             :     void            BeginSetClipRegion (sal_uInt32);
     333             :     bool        UnionClipRegion (sal_Int32 nX, sal_Int32 nY,
     334             :                                      sal_Int32 nDX, sal_Int32 nDY);
     335             :     void            EndSetClipRegion ();
     336             : 
     337             :     // set xy color
     338           0 :     void            SetLineColor (const PrinterColor& rLineColor = PrinterColor())
     339           0 :     { maLineColor = rLineColor; }
     340           0 :     void            SetFillColor (const PrinterColor& rFillColor = PrinterColor())
     341           0 :     { maFillColor = rFillColor; }
     342             : 
     343             :     // drawing primitives
     344             :     void            DrawPixel (const Point& rPoint, const PrinterColor& rPixelColor);
     345           0 :     void            DrawPixel (const Point& rPoint)
     346           0 :     { DrawPixel (rPoint, maLineColor); }
     347             :     void            DrawLine  (const Point& rFrom, const Point& rTo);
     348             :     void            DrawRect  (const Rectangle& rRectangle);
     349             :     void            DrawPolyLine (sal_uInt32 nPoints, const Point* pPath );
     350             :     void            DrawPolygon  (sal_uInt32 nPoints, const Point* pPath);
     351             :     void            DrawPolyPolygon (sal_uInt32 nPoly,
     352             :                                      const sal_uInt32 *pPolygonSize,
     353             :                                      const Point** pPolygonList);
     354             :     void            DrawPolyLineBezier (sal_uInt32 nPoints,
     355             :                                      const Point* pPath,
     356             :                                      const sal_uInt8* pFlgAry );
     357             :     void            DrawPolygonBezier  (sal_uInt32 nPoints,
     358             :                                      const Point* pPath,
     359             :                                      const sal_uInt8* pFlgAry);
     360             :     void            DrawPolyPolygonBezier  (sal_uInt32 nPoly,
     361             :                                      const sal_uInt32* pPoints,
     362             :                                      const Point* const* pPtAry,
     363             :                                      const sal_uInt8* const* pFlgAry);
     364             : 
     365             :     // eps
     366             :     bool        DrawEPS ( const Rectangle& rBoundingBox, void* pPtr, sal_uInt32 nSize);
     367             : 
     368             :     // image drawing
     369             :     void            DrawBitmap (const Rectangle& rDest, const Rectangle& rSrc,
     370             :                                 const PrinterBmp& rBitmap);
     371             : 
     372             :     // font and text handling
     373             :     sal_uInt16      SetFont (
     374             :                              sal_Int32 nFontID,
     375             :                              sal_Int32 nPointHeight,
     376             :                              sal_Int32 nPointWidth,
     377             :                              sal_Int32 nAngle,
     378             :                              bool bVertical,
     379             :                              bool bArtItalic,
     380             :                              bool bArtBold
     381             :                              );
     382         575 :     sal_Int32       GetFontAngle () const
     383         575 :     { return mnTextAngle; }
     384       16983 :     sal_Int32       GetFontID () const
     385       16983 :     { return mnFontID; }
     386        6163 :     bool            GetFontVertical() const
     387        6163 :     { return mbTextVertical; }
     388        6648 :     sal_Int32       GetFontHeight () const
     389        6648 :     { return maVirtualStatus.mnTextHeight; }
     390        6648 :     sal_Int32       GetFontWidth () const
     391        6648 :     { return maVirtualStatus.mnTextWidth; }
     392        6163 :     bool            GetArtificialItalic() const
     393        6163 :     { return maVirtualStatus.mbArtItalic; }
     394        6163 :     bool            GetArtificialBold() const
     395        6163 :     { return maVirtualStatus.mbArtBold; }
     396             :     void            DrawText (const Point& rPoint,
     397             :                               const sal_Unicode* pStr, sal_Int16 nLen,
     398             :                               const sal_Int32* pDeltaArray = NULL);
     399           0 :     void            SetTextColor (PrinterColor& rTextColor)
     400           0 :     { maTextColor = rTextColor; }
     401             :     sal_Int32       GetCharWidth (sal_uInt16 nFrom, sal_uInt16 nTo,
     402             :                                   long *pWidthArray);
     403             :     // for CTL
     404             :     void            DrawGlyphs( const Point& rPoint,
     405             :                                 sal_GlyphId* pGlyphIds,
     406             :                                 sal_Unicode* pUnicodes,
     407             :                                 sal_Int16 nLen,
     408             :                                 sal_Int32* pDeltaArray );
     409             : 
     410             : };
     411             : 
     412             : } /* namespace psp */
     413             : 
     414             : #endif // INCLUDED_VCL_INC_GENERIC_PRINTERGFX_HXX
     415             : 
     416             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10