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

Generated by: LCOV version 1.10