LCOV - code coverage report
Current view: top level - vcl/generic/print - genpspgraphics.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 210 578 36.3 %
Date: 2014-04-11 Functions: 28 105 26.7 %
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             : #include <sal/types.h>
      21             : 
      22             : // for mmap etc.
      23             : #if defined( UNX )
      24             : #include <unistd.h>
      25             : #include <fcntl.h>
      26             : #include <sys/mman.h>
      27             : #include <sys/stat.h>
      28             : #include <sys/types.h>
      29             : #endif
      30             : 
      31             : #include <comphelper/string.hxx>
      32             : #include <i18nlangtag/mslangid.hxx>
      33             : #include <vcl/bmpacc.hxx>
      34             : #include <vcl/jobdata.hxx>
      35             : #include <vcl/printerinfomanager.hxx>
      36             : #include <vcl/settings.hxx>
      37             : #include <vcl/svapp.hxx>
      38             : #include <vcl/sysdata.hxx>
      39             : 
      40             : #include "fontsubset.hxx"
      41             : #include "generic/geninst.h"
      42             : #include "generic/genpspgraphics.h"
      43             : #include "generic/glyphcache.hxx"
      44             : #include "generic/printergfx.hxx"
      45             : #include "impfont.hxx"
      46             : #include "langboost.hxx"
      47             : #include "outfont.hxx"
      48             : #include "PhysicalFontCollection.hxx"
      49             : #include "PhysicalFontFace.hxx"
      50             : #include "salbmp.hxx"
      51             : #include "salprn.hxx"
      52             : 
      53             : #include <config_graphite.h>
      54             : #if ENABLE_GRAPHITE
      55             : #include <graphite_layout.hxx>
      56             : #include <graphite_serverfont.hxx>
      57             : #endif
      58             : 
      59             : using namespace psp;
      60             : 
      61             : // ----- Implementation of PrinterBmp by means of SalBitmap/BitmapBuffer ---------------
      62             : 
      63             : class SalPrinterBmp : public psp::PrinterBmp
      64             : {
      65             : private:
      66             :     BitmapBuffer*       mpBmpBuffer;
      67             : 
      68             :     FncGetPixel         mpFncGetPixel;
      69             :     Scanline            mpScanAccess;
      70             :     sal_PtrDiff         mnScanOffset;
      71             : 
      72             :     sal_uInt32          ColorOf (BitmapColor& rColor) const;
      73             :     sal_uInt8           GrayOf  (BitmapColor& rColor) const;
      74             : 
      75             :     public:
      76             : 
      77             :                             SalPrinterBmp (BitmapBuffer* pBitmap);
      78             :         virtual             ~SalPrinterBmp ();
      79             :         virtual sal_uInt32  GetPaletteColor (sal_uInt32 nIdx) const SAL_OVERRIDE;
      80             :         virtual sal_uInt32  GetPaletteEntryCount () const SAL_OVERRIDE;
      81             :         virtual sal_uInt32  GetPixelRGB  (sal_uInt32 nRow, sal_uInt32 nColumn) const SAL_OVERRIDE;
      82             :         virtual sal_uInt8   GetPixelGray (sal_uInt32 nRow, sal_uInt32 nColumn) const SAL_OVERRIDE;
      83             :         virtual sal_uInt8   GetPixelIdx  (sal_uInt32 nRow, sal_uInt32 nColumn) const SAL_OVERRIDE;
      84             :         virtual sal_uInt32  GetWidth () const SAL_OVERRIDE;
      85             :         virtual sal_uInt32  GetHeight() const SAL_OVERRIDE;
      86             :         virtual sal_uInt32  GetDepth () const SAL_OVERRIDE;
      87             : };
      88             : 
      89           0 : SalPrinterBmp::SalPrinterBmp (BitmapBuffer* pBuffer) :
      90           0 :         mpBmpBuffer (pBuffer)
      91             : {
      92             :     DBG_ASSERT (mpBmpBuffer, "SalPrinterBmp::SalPrinterBmp () can't acquire Bitmap");
      93             : 
      94             :     // calibrate scanline buffer
      95           0 :     if( BMP_SCANLINE_ADJUSTMENT( mpBmpBuffer->mnFormat ) == BMP_FORMAT_TOP_DOWN )
      96             :     {
      97           0 :         mpScanAccess = mpBmpBuffer->mpBits;
      98           0 :         mnScanOffset = mpBmpBuffer->mnScanlineSize;
      99             :     }
     100             :     else
     101             :     {
     102             :         mpScanAccess = mpBmpBuffer->mpBits
     103           0 :                        + (mpBmpBuffer->mnHeight - 1) * mpBmpBuffer->mnScanlineSize;
     104           0 :         mnScanOffset = - mpBmpBuffer->mnScanlineSize;
     105             :     }
     106             : 
     107             :     // request read access to the pixels
     108           0 :     switch( BMP_SCANLINE_FORMAT( mpBmpBuffer->mnFormat ) )
     109             :     {
     110             :         case BMP_FORMAT_1BIT_MSB_PAL:
     111           0 :             mpFncGetPixel = BitmapReadAccess::GetPixelFor_1BIT_MSB_PAL;  break;
     112             :         case BMP_FORMAT_1BIT_LSB_PAL:
     113           0 :             mpFncGetPixel = BitmapReadAccess::GetPixelFor_1BIT_LSB_PAL;  break;
     114             :         case BMP_FORMAT_4BIT_MSN_PAL:
     115           0 :             mpFncGetPixel = BitmapReadAccess::GetPixelFor_4BIT_MSN_PAL;  break;
     116             :         case BMP_FORMAT_4BIT_LSN_PAL:
     117           0 :             mpFncGetPixel = BitmapReadAccess::GetPixelFor_4BIT_LSN_PAL;  break;
     118             :         case BMP_FORMAT_8BIT_PAL:
     119           0 :             mpFncGetPixel = BitmapReadAccess::GetPixelFor_8BIT_PAL;      break;
     120             :         case BMP_FORMAT_8BIT_TC_MASK:
     121           0 :             mpFncGetPixel = BitmapReadAccess::GetPixelFor_8BIT_TC_MASK;  break;
     122             :         case BMP_FORMAT_16BIT_TC_MSB_MASK:
     123           0 :             mpFncGetPixel = BitmapReadAccess::GetPixelFor_16BIT_TC_MSB_MASK; break;
     124             :         case BMP_FORMAT_16BIT_TC_LSB_MASK:
     125           0 :             mpFncGetPixel = BitmapReadAccess::GetPixelFor_16BIT_TC_LSB_MASK; break;
     126             :         case BMP_FORMAT_24BIT_TC_BGR:
     127           0 :             mpFncGetPixel = BitmapReadAccess::GetPixelFor_24BIT_TC_BGR;  break;
     128             :         case BMP_FORMAT_24BIT_TC_RGB:
     129           0 :             mpFncGetPixel = BitmapReadAccess::GetPixelFor_24BIT_TC_RGB;  break;
     130             :         case BMP_FORMAT_24BIT_TC_MASK:
     131           0 :             mpFncGetPixel = BitmapReadAccess::GetPixelFor_24BIT_TC_MASK; break;
     132             :         case BMP_FORMAT_32BIT_TC_ABGR:
     133           0 :             mpFncGetPixel = BitmapReadAccess::GetPixelFor_32BIT_TC_ABGR; break;
     134             :         case BMP_FORMAT_32BIT_TC_ARGB:
     135           0 :             mpFncGetPixel = BitmapReadAccess::GetPixelFor_32BIT_TC_ARGB; break;
     136             :         case BMP_FORMAT_32BIT_TC_BGRA:
     137           0 :             mpFncGetPixel = BitmapReadAccess::GetPixelFor_32BIT_TC_BGRA; break;
     138             :         case BMP_FORMAT_32BIT_TC_RGBA:
     139           0 :             mpFncGetPixel = BitmapReadAccess::GetPixelFor_32BIT_TC_RGBA; break;
     140             :         case BMP_FORMAT_32BIT_TC_MASK:
     141           0 :             mpFncGetPixel = BitmapReadAccess::GetPixelFor_32BIT_TC_MASK; break;
     142             : 
     143             :         default:
     144             :             OSL_FAIL("Error: SalPrinterBmp::SalPrinterBmp() unknown bitmap format");
     145           0 :             mpFncGetPixel = NULL;
     146           0 :         break;
     147             :     }
     148           0 : }
     149             : 
     150           0 : SalPrinterBmp::~SalPrinterBmp ()
     151             : {
     152           0 : }
     153             : 
     154             : sal_uInt32
     155           0 : SalPrinterBmp::GetWidth () const
     156             : {
     157           0 :     return mpBmpBuffer->mnWidth;
     158             : }
     159             : 
     160             : sal_uInt32
     161           0 : SalPrinterBmp::GetHeight () const
     162             : {
     163           0 :     return mpBmpBuffer->mnHeight;
     164             : }
     165             : 
     166             : sal_uInt32
     167           0 : SalPrinterBmp::GetDepth () const
     168             : {
     169             :     sal_uInt32 nDepth;
     170             : 
     171           0 :     switch (mpBmpBuffer->mnBitCount)
     172             :     {
     173             :         case 1:
     174           0 :             nDepth = 1;
     175           0 :             break;
     176             : 
     177             :         case 4:
     178             :         case 8:
     179           0 :             nDepth = 8;
     180           0 :             break;
     181             : 
     182             :         case 16:
     183             :         case 24:
     184             :         case 32:
     185           0 :             nDepth = 24;
     186           0 :             break;
     187             : 
     188             :         default:
     189           0 :             nDepth = 1;
     190             :             OSL_FAIL("Error: unsupported bitmap depth in SalPrinterBmp::GetDepth()");
     191           0 :             break;
     192             :     }
     193             : 
     194           0 :     return nDepth;
     195             : }
     196             : 
     197             : sal_uInt32
     198           0 : SalPrinterBmp::ColorOf (BitmapColor& rColor) const
     199             : {
     200           0 :     if (rColor.IsIndex())
     201           0 :         return ColorOf (mpBmpBuffer->maPalette[rColor.GetIndex()]);
     202             :     else
     203           0 :         return    ((rColor.GetBlue())        & 0x000000ff)
     204           0 :                 | ((rColor.GetGreen() <<  8) & 0x0000ff00)
     205           0 :                 | ((rColor.GetRed()   << 16) & 0x00ff0000);
     206             : }
     207             : 
     208             : sal_uInt8
     209           0 : SalPrinterBmp::GrayOf (BitmapColor& rColor) const
     210             : {
     211           0 :     if (rColor.IsIndex())
     212           0 :         return GrayOf (mpBmpBuffer->maPalette[rColor.GetIndex()]);
     213             :     else
     214           0 :         return (  rColor.GetBlue()  *  28UL
     215           0 :                 + rColor.GetGreen() * 151UL
     216           0 :                 + rColor.GetRed()   *  77UL ) >> 8;
     217             : }
     218             : 
     219             : sal_uInt32
     220           0 : SalPrinterBmp::GetPaletteEntryCount () const
     221             : {
     222           0 :     return mpBmpBuffer->maPalette.GetEntryCount ();
     223             : }
     224             : 
     225             : sal_uInt32
     226           0 : SalPrinterBmp::GetPaletteColor (sal_uInt32 nIdx) const
     227             : {
     228           0 :     return ColorOf (mpBmpBuffer->maPalette[nIdx]);
     229             : }
     230             : 
     231             : sal_uInt32
     232           0 : SalPrinterBmp::GetPixelRGB (sal_uInt32 nRow, sal_uInt32 nColumn) const
     233             : {
     234           0 :     Scanline pScan = mpScanAccess + nRow * mnScanOffset;
     235           0 :     BitmapColor aColor = mpFncGetPixel (pScan, nColumn, mpBmpBuffer->maColorMask);
     236             : 
     237           0 :     return ColorOf (aColor);
     238             : }
     239             : 
     240             : sal_uInt8
     241           0 : SalPrinterBmp::GetPixelGray (sal_uInt32 nRow, sal_uInt32 nColumn) const
     242             : {
     243           0 :     Scanline pScan = mpScanAccess + nRow * mnScanOffset;
     244           0 :     BitmapColor aColor = mpFncGetPixel (pScan, nColumn, mpBmpBuffer->maColorMask);
     245             : 
     246           0 :     return GrayOf (aColor);
     247             : }
     248             : 
     249             : sal_uInt8
     250           0 : SalPrinterBmp::GetPixelIdx (sal_uInt32 nRow, sal_uInt32 nColumn) const
     251             : {
     252           0 :     Scanline pScan = mpScanAccess + nRow * mnScanOffset;
     253           0 :     BitmapColor aColor = mpFncGetPixel (pScan, nColumn, mpBmpBuffer->maColorMask);
     254             : 
     255           0 :     if (aColor.IsIndex())
     256           0 :         return aColor.GetIndex();
     257             :     else
     258           0 :         return 0;
     259             : }
     260             : 
     261             : /*******************************************************
     262             :  * GenPspGraphics                                         *
     263             :  *******************************************************/
     264             : 
     265         321 : GenPspGraphics::GenPspGraphics()
     266             :     : m_pJobData( NULL ),
     267             :       m_pPrinterGfx( NULL ),
     268             :       m_bFontVertical( false ),
     269         321 :       m_pInfoPrinter( NULL )
     270             : {
     271        5457 :     for( int i = 0; i < MAX_FALLBACK; i++ )
     272        5136 :         m_pServerFont[i] = NULL;
     273         321 : }
     274             : 
     275         321 : void GenPspGraphics::Init(psp::JobData* pJob, psp::PrinterGfx* pGfx,
     276             :                            SalInfoPrinter* pInfoPrinter)
     277             : {
     278         321 :     m_pJobData = pJob;
     279         321 :     m_pPrinterGfx = pGfx;
     280         321 :     m_pInfoPrinter = pInfoPrinter;
     281         321 :     SetLayout( 0 );
     282         321 : }
     283             : 
     284         933 : GenPspGraphics::~GenPspGraphics()
     285             : {
     286         311 :     ReleaseFonts();
     287         622 : }
     288             : 
     289         321 : void GenPspGraphics::GetResolution( sal_Int32 &rDPIX, sal_Int32 &rDPIY )
     290             : {
     291         321 :     if (m_pJobData != NULL)
     292             :     {
     293         321 :         int x = m_pJobData->m_aContext.getRenderResolution();
     294             : 
     295         321 :         rDPIX = x;
     296         321 :         rDPIY = x;
     297             :     }
     298         321 : }
     299             : 
     300           0 : sal_uInt16 GenPspGraphics::GetBitCount() const
     301             : {
     302           0 :     return m_pPrinterGfx->GetBitCount();
     303             : }
     304             : 
     305           0 : long GenPspGraphics::GetGraphicsWidth() const
     306             : {
     307           0 :     return 0;
     308             : }
     309             : 
     310           0 : void GenPspGraphics::ResetClipRegion()
     311             : {
     312           0 :     m_pPrinterGfx->ResetClipRegion();
     313           0 : }
     314             : 
     315           0 : bool GenPspGraphics::setClipRegion( const Region& i_rClip )
     316             : {
     317             :     // TODO: support polygonal clipregions here
     318           0 :     RectangleVector aRectangles;
     319           0 :     i_rClip.GetRegionRectangles(aRectangles);
     320           0 :     m_pPrinterGfx->BeginSetClipRegion(aRectangles.size());
     321             : 
     322           0 :     for(RectangleVector::const_iterator aRectIter(aRectangles.begin()); aRectIter != aRectangles.end(); ++aRectIter)
     323             :     {
     324           0 :         const long nW(aRectIter->GetWidth());
     325             : 
     326           0 :         if(nW)
     327             :         {
     328           0 :             const long nH(aRectIter->GetHeight());
     329             : 
     330           0 :             if(nH)
     331             :             {
     332             :                 m_pPrinterGfx->UnionClipRegion(
     333             :                     aRectIter->Left(),
     334             :                     aRectIter->Top(),
     335             :                     nW,
     336           0 :                     nH);
     337             :             }
     338             :         }
     339             :     }
     340             : 
     341           0 :     m_pPrinterGfx->EndSetClipRegion();
     342             : 
     343             :     //m_pPrinterGfx->BeginSetClipRegion( i_rClip.GetRectCount() );
     344             : 
     345             :     //ImplRegionInfo aInfo;
     346             :     //long nX, nY, nW, nH;
     347             :     //bool bRegionRect = i_rClip.ImplGetFirstRect(aInfo, nX, nY, nW, nH );
     348             :     //while( bRegionRect )
     349             :     //{
     350             :     //    if ( nW && nH )
     351             :     //    {
     352             :     //        m_pPrinterGfx->UnionClipRegion( nX, nY, nW, nH );
     353             :     //    }
     354             :     //    bRegionRect = i_rClip.ImplGetNextRect( aInfo, nX, nY, nW, nH );
     355             :     //}
     356             :     //m_pPrinterGfx->EndSetClipRegion();
     357           0 :     return true;
     358             : }
     359             : 
     360           0 : void GenPspGraphics::SetLineColor()
     361             : {
     362           0 :     m_pPrinterGfx->SetLineColor ();
     363           0 : }
     364             : 
     365           0 : void GenPspGraphics::SetLineColor( SalColor nSalColor )
     366             : {
     367           0 :     psp::PrinterColor aColor (SALCOLOR_RED   (nSalColor),
     368           0 :                               SALCOLOR_GREEN (nSalColor),
     369           0 :                               SALCOLOR_BLUE  (nSalColor));
     370           0 :     m_pPrinterGfx->SetLineColor (aColor);
     371           0 : }
     372             : 
     373           0 : void GenPspGraphics::SetFillColor()
     374             : {
     375           0 :     m_pPrinterGfx->SetFillColor ();
     376           0 : }
     377             : 
     378           0 : void GenPspGraphics::SetFillColor( SalColor nSalColor )
     379             : {
     380           0 :     psp::PrinterColor aColor (SALCOLOR_RED   (nSalColor),
     381           0 :                               SALCOLOR_GREEN (nSalColor),
     382           0 :                               SALCOLOR_BLUE  (nSalColor));
     383           0 :     m_pPrinterGfx->SetFillColor (aColor);
     384           0 : }
     385             : 
     386           0 : void GenPspGraphics::SetROPLineColor( SalROPColor )
     387             : {
     388             :     DBG_ASSERT( false, "Error: PrinterGfx::SetROPLineColor() not implemented" );
     389           0 : }
     390             : 
     391           0 : void GenPspGraphics::SetROPFillColor( SalROPColor )
     392             : {
     393             :     DBG_ASSERT( false, "Error: PrinterGfx::SetROPFillColor() not implemented" );
     394           0 : }
     395             : 
     396         321 : void GenPspGraphics::SetXORMode( bool bSet, bool )
     397             : {
     398             :     (void)bSet;
     399             :     DBG_ASSERT( !bSet, "Error: PrinterGfx::SetXORMode() not implemented" );
     400         321 : }
     401             : 
     402           0 : void GenPspGraphics::drawPixel( long nX, long nY )
     403             : {
     404           0 :     m_pPrinterGfx->DrawPixel (Point(nX, nY));
     405           0 : }
     406             : 
     407           0 : void GenPspGraphics::drawPixel( long nX, long nY, SalColor nSalColor )
     408             : {
     409           0 :     psp::PrinterColor aColor (SALCOLOR_RED   (nSalColor),
     410           0 :                               SALCOLOR_GREEN (nSalColor),
     411           0 :                               SALCOLOR_BLUE  (nSalColor));
     412           0 :     m_pPrinterGfx->DrawPixel (Point(nX, nY), aColor);
     413           0 : }
     414             : 
     415           0 : void GenPspGraphics::drawLine( long nX1, long nY1, long nX2, long nY2 )
     416             : {
     417           0 :     m_pPrinterGfx->DrawLine (Point(nX1, nY1), Point(nX2, nY2));
     418           0 : }
     419             : 
     420           0 : void GenPspGraphics::drawRect( long nX, long nY, long nDX, long nDY )
     421             : {
     422           0 :     m_pPrinterGfx->DrawRect (Rectangle(Point(nX, nY), Size(nDX, nDY)));
     423           0 : }
     424             : 
     425           0 : void GenPspGraphics::drawPolyLine( sal_uInt32 nPoints, const SalPoint *pPtAry )
     426             : {
     427           0 :     m_pPrinterGfx->DrawPolyLine (nPoints, (Point*)pPtAry);
     428           0 : }
     429             : 
     430           0 : void GenPspGraphics::drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry )
     431             : {
     432             :     // Point must be equal to SalPoint! see vcl/inc/salgtype.hxx
     433           0 :     m_pPrinterGfx->DrawPolygon (nPoints, (Point*)pPtAry);
     434           0 : }
     435             : 
     436           0 : void GenPspGraphics::drawPolyPolygon( sal_uInt32           nPoly,
     437             :                                    const sal_uInt32   *pPoints,
     438             :                                    PCONSTSALPOINT  *pPtAry )
     439             : {
     440           0 :     m_pPrinterGfx->DrawPolyPolygon (nPoly, pPoints, (const Point**)pPtAry);
     441           0 : }
     442             : 
     443           0 : bool GenPspGraphics::drawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double /*fTransparency*/ )
     444             : {
     445             :         // TODO: implement and advertise OutDevSupport_B2DDraw support
     446           0 :         return false;
     447             : }
     448             : 
     449           0 : bool GenPspGraphics::drawPolyLine(
     450             :     const basegfx::B2DPolygon&,
     451             :     double /*fTranspareny*/,
     452             :     const basegfx::B2DVector& /*rLineWidths*/,
     453             :     basegfx::B2DLineJoin /*eJoin*/,
     454             :     com::sun::star::drawing::LineCap /*eLineCap*/)
     455             : {
     456             :     // TODO: a PS printer can draw B2DPolyLines almost directly
     457           0 :     return false;
     458             : }
     459             : 
     460           0 : bool GenPspGraphics::drawPolyLineBezier( sal_uInt32 nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry )
     461             : {
     462           0 :     m_pPrinterGfx->DrawPolyLineBezier (nPoints, (Point*)pPtAry, pFlgAry);
     463           0 :     return true;
     464             : }
     465             : 
     466           0 : bool GenPspGraphics::drawPolygonBezier( sal_uInt32 nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry )
     467             : {
     468           0 :     m_pPrinterGfx->DrawPolygonBezier (nPoints, (Point*)pPtAry, pFlgAry);
     469           0 :     return true;
     470             : }
     471             : 
     472           0 : bool GenPspGraphics::drawPolyPolygonBezier( sal_uInt32 nPoly,
     473             :                                              const sal_uInt32* pPoints,
     474             :                                              const SalPoint* const* pPtAry,
     475             :                                              const sal_uInt8* const* pFlgAry )
     476             : {
     477             :     // Point must be equal to SalPoint! see vcl/inc/salgtype.hxx
     478           0 :     m_pPrinterGfx->DrawPolyPolygonBezier (nPoly, pPoints, (Point**)pPtAry, (sal_uInt8**)pFlgAry);
     479           0 :     return true;
     480             : }
     481             : 
     482           0 : void GenPspGraphics::invert( sal_uInt32,
     483             :                           const SalPoint*,
     484             :                           SalInvert )
     485             : {
     486             :     DBG_ASSERT( false, "Error: PrinterGfx::Invert() not implemented" );
     487           0 : }
     488             : 
     489           0 : bool GenPspGraphics::drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uLong nSize )
     490             : {
     491           0 :     return m_pPrinterGfx->DrawEPS( Rectangle( Point( nX, nY ), Size( nWidth, nHeight ) ), pPtr, nSize );
     492             : }
     493             : 
     494           0 : void GenPspGraphics::copyBits( const SalTwoRect&,
     495             :                             SalGraphics* )
     496             : {
     497             :     OSL_FAIL( "Error: PrinterGfx::CopyBits() not implemented" );
     498           0 : }
     499             : 
     500           0 : void GenPspGraphics::copyArea ( long,long,long,long,long,long,sal_uInt16 )
     501             : {
     502             :     OSL_FAIL( "Error: PrinterGfx::CopyArea() not implemented" );
     503           0 : }
     504             : 
     505           0 : void GenPspGraphics::drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap )
     506             : {
     507             :     Rectangle aSrc (Point(rPosAry.mnSrcX, rPosAry.mnSrcY),
     508           0 :                     Size(rPosAry.mnSrcWidth, rPosAry.mnSrcHeight));
     509             :     Rectangle aDst (Point(rPosAry.mnDestX, rPosAry.mnDestY),
     510           0 :                     Size(rPosAry.mnDestWidth, rPosAry.mnDestHeight));
     511             : 
     512           0 :     BitmapBuffer* pBuffer= const_cast<SalBitmap&>(rSalBitmap).AcquireBuffer(true);
     513             : 
     514           0 :     SalPrinterBmp aBmp (pBuffer);
     515           0 :     m_pPrinterGfx->DrawBitmap (aDst, aSrc, aBmp);
     516             : 
     517           0 :     const_cast<SalBitmap&>(rSalBitmap).ReleaseBuffer (pBuffer, true);
     518           0 : }
     519             : 
     520           0 : void GenPspGraphics::drawBitmap( const SalTwoRect&,
     521             :                               const SalBitmap&,
     522             :                               const SalBitmap& )
     523             : {
     524             :     OSL_FAIL("Error: no PrinterGfx::DrawBitmap() for transparent bitmap");
     525           0 : }
     526             : 
     527           0 : void GenPspGraphics::drawBitmap( const SalTwoRect&,
     528             :                               const SalBitmap&,
     529             :                               SalColor )
     530             : {
     531             :     OSL_FAIL("Error: no PrinterGfx::DrawBitmap() for transparent color");
     532           0 : }
     533             : 
     534           0 : void GenPspGraphics::drawMask( const SalTwoRect&,
     535             :                             const SalBitmap &,
     536             :                             SalColor )
     537             : {
     538             :     OSL_FAIL("Error: PrinterGfx::DrawMask() not implemented");
     539           0 : }
     540             : 
     541           0 : SalBitmap* GenPspGraphics::getBitmap( long, long, long, long )
     542             : {
     543             :     DBG_WARNING ("Warning: PrinterGfx::GetBitmap() not implemented");
     544           0 :     return NULL;
     545             : }
     546             : 
     547           0 : SalColor GenPspGraphics::getPixel( long, long )
     548             : {
     549             :     OSL_FAIL("Warning: PrinterGfx::GetPixel() not implemented");
     550           0 :     return 0;
     551             : }
     552             : 
     553           0 : void GenPspGraphics::invert(long,long,long,long,SalInvert)
     554             : {
     555             :     OSL_FAIL("Warning: PrinterGfx::Invert() not implemented");
     556           0 : }
     557             : 
     558      131280 : class ImplPspFontData : public PhysicalFontFace
     559             : {
     560             : private:
     561             :     enum { PSPFD_MAGIC = 0xb5bf01f0 };
     562             :     sal_IntPtr              mnFontId;
     563             : 
     564             : public:
     565             :                             ImplPspFontData( const psp::FastPrintFontInfo& );
     566         752 :     virtual sal_IntPtr      GetFontId() const SAL_OVERRIDE { return mnFontId; }
     567           0 :     virtual PhysicalFontFace*   Clone() const SAL_OVERRIDE { return new ImplPspFontData( *this ); }
     568             :     virtual ImplFontEntry*  CreateFontInstance( FontSelectPattern& ) const SAL_OVERRIDE;
     569             : };
     570             : 
     571       67410 : ImplPspFontData::ImplPspFontData( const psp::FastPrintFontInfo& rInfo )
     572             : :   PhysicalFontFace( GenPspGraphics::Info2DevFontAttributes(rInfo), PSPFD_MAGIC ),
     573       67410 :     mnFontId( rInfo.m_nID )
     574       67410 : {}
     575             : 
     576         193 : ImplFontEntry* ImplPspFontData::CreateFontInstance( FontSelectPattern& rFSD ) const
     577             : {
     578         193 :     ImplServerFontEntry* pEntry = new ImplServerFontEntry( rFSD );
     579         193 :     return pEntry;
     580             : }
     581             : 
     582          90 : class PspFontLayout : public GenericSalLayout
     583             : {
     584             : public:
     585             :                         PspFontLayout( ::psp::PrinterGfx& );
     586             :     virtual bool        LayoutText( ImplLayoutArgs& ) SAL_OVERRIDE;
     587             :     virtual void        InitFont() const SAL_OVERRIDE;
     588             :     virtual void        DrawText( SalGraphics& ) const SAL_OVERRIDE;
     589             : private:
     590             :     ::psp::PrinterGfx&  mrPrinterGfx;
     591             :     sal_IntPtr          mnFontID;
     592             :     int                 mnFontHeight;
     593             :     int                 mnFontWidth;
     594             :     bool                mbVertical;
     595             :     bool                mbArtItalic;
     596             :     bool                mbArtBold;
     597             : };
     598             : 
     599          45 : PspFontLayout::PspFontLayout( ::psp::PrinterGfx& rGfx )
     600          45 : :   mrPrinterGfx( rGfx )
     601             : {
     602          45 :     mnFontID     = mrPrinterGfx.GetFontID();
     603          45 :     mnFontHeight = mrPrinterGfx.GetFontHeight();
     604          45 :     mnFontWidth  = mrPrinterGfx.GetFontWidth();
     605          45 :     mbVertical   = mrPrinterGfx.GetFontVertical();
     606          45 :     mbArtItalic  = mrPrinterGfx.GetArtificialItalic();
     607          45 :     mbArtBold    = mrPrinterGfx.GetArtificialBold();
     608          45 : }
     609             : 
     610          45 : bool PspFontLayout::LayoutText( ImplLayoutArgs& rArgs )
     611             : {
     612          45 :     mbVertical = ((rArgs.mnFlags & SAL_LAYOUT_VERTICAL) != 0);
     613             : 
     614          45 :     long nUnitsPerPixel = 1;
     615          45 :     sal_GlyphId aOldGlyphId( GF_DROPPED);
     616          45 :     long nGlyphWidth = 0;
     617          45 :     int nCharPos = -1;
     618          45 :     Point aNewPos( 0, 0 );
     619          45 :     GlyphItem aPrevItem;
     620          45 :     rtl_TextEncoding aFontEnc = mrPrinterGfx.GetFontMgr().getFontEncoding( mnFontID );
     621             : 
     622          45 :     Reserve(rArgs.mnLength);
     623             : 
     624             :     for(;;)
     625             :     {
     626             :         bool bRightToLeft;
     627        2131 :         if( !rArgs.GetNextPos( &nCharPos, &bRightToLeft ) )
     628          45 :             break;
     629             : 
     630        2086 :         sal_Unicode cChar = rArgs.mpStr[ nCharPos ];
     631        2086 :         if( bRightToLeft )
     632           0 :             cChar = GetMirroredChar( cChar );
     633             :         // symbol font aliasing: 0x0020-0x00ff -> 0xf020 -> 0xf0ff
     634        2086 :         if( aFontEnc == RTL_TEXTENCODING_SYMBOL )
     635           0 :             if( cChar < 256 )
     636           0 :                 cChar += 0xf000;
     637        2086 :         sal_GlyphId aGlyphId( cChar);  // printer glyphs = unicode
     638             : 
     639             :         // update fallback_runs if needed
     640        2086 :         psp::CharacterMetric aMetric;
     641        2086 :         mrPrinterGfx.GetFontMgr().getMetrics( mnFontID, cChar, cChar, &aMetric, mbVertical );
     642        2086 :         if( aMetric.width == -1 && aMetric.height == -1 )
     643           0 :             rArgs.NeedFallback( nCharPos, bRightToLeft );
     644             : 
     645             :         // finish previous glyph
     646        2086 :         if( aOldGlyphId != GF_DROPPED )
     647        2041 :             AppendGlyph( aPrevItem );
     648        2086 :         aOldGlyphId = aGlyphId;
     649        2086 :         aNewPos.X() += nGlyphWidth;
     650             : 
     651             :         // prepare GlyphItem for appending it in next round
     652        2086 :         nUnitsPerPixel = mrPrinterGfx.GetCharWidth( cChar, cChar, &nGlyphWidth );
     653        2086 :         int nGlyphFlags = bRightToLeft ? GlyphItem::IS_RTL_GLYPH : 0;
     654        2086 :         aGlyphId |= GF_ISCHAR;
     655        2086 :         aPrevItem = GlyphItem( nCharPos, aGlyphId, aNewPos, nGlyphFlags, nGlyphWidth );
     656        2086 :     }
     657             : 
     658             :     // append last glyph item if any
     659          45 :     if( aOldGlyphId != GF_DROPPED )
     660          45 :         AppendGlyph( aPrevItem );
     661             : 
     662          45 :     SetOrientation( mrPrinterGfx.GetFontAngle() );
     663          45 :     SetUnitsPerPixel( nUnitsPerPixel );
     664          45 :     return (aOldGlyphId != GF_DROPPED);
     665             : }
     666             : 
     667        4454 : class PspServerFontLayout : public ServerFontLayout
     668             : {
     669             : public:
     670             :     PspServerFontLayout( psp::PrinterGfx&, ServerFont& rFont, const ImplLayoutArgs& rArgs );
     671             : 
     672             :     virtual void        InitFont() const SAL_OVERRIDE;
     673           0 :     const sal_Unicode*  getTextPtr() const { return maText.getStr() - mnMinCharPos; }
     674           0 :     int                 getMinCharPos() const { return mnMinCharPos; }
     675           0 :     int                 getMaxCharPos() const { return mnMinCharPos+maText.getLength()-1; }
     676             : private:
     677             :     ::psp::PrinterGfx&  mrPrinterGfx;
     678             :     sal_IntPtr          mnFontID;
     679             :     int                 mnFontHeight;
     680             :     int                 mnFontWidth;
     681             :     bool                mbVertical;
     682             :     bool                mbArtItalic;
     683             :     bool                mbArtBold;
     684             :     OUString       maText;
     685             :     int                 mnMinCharPos;
     686             : };
     687             : 
     688        2227 : PspServerFontLayout::PspServerFontLayout( ::psp::PrinterGfx& rGfx, ServerFont& rFont, const ImplLayoutArgs& rArgs )
     689             :         :   ServerFontLayout( rFont ),
     690        2227 :             mrPrinterGfx( rGfx )
     691             : {
     692        2227 :     mnFontID     = mrPrinterGfx.GetFontID();
     693        2227 :     mnFontHeight = mrPrinterGfx.GetFontHeight();
     694        2227 :     mnFontWidth  = mrPrinterGfx.GetFontWidth();
     695        2227 :     mbVertical   = mrPrinterGfx.GetFontVertical();
     696        2227 :     mbArtItalic  = mrPrinterGfx.GetArtificialItalic();
     697        2227 :     mbArtBold    = mrPrinterGfx.GetArtificialBold();
     698        2227 :     maText       = OUString( rArgs.mpStr + rArgs.mnMinCharPos, rArgs.mnEndCharPos - rArgs.mnMinCharPos+1 );
     699        2227 :     mnMinCharPos = rArgs.mnMinCharPos;
     700        2227 : }
     701             : 
     702           2 : void PspServerFontLayout::InitFont() const
     703             : {
     704             :     mrPrinterGfx.SetFont( mnFontID, mnFontHeight, mnFontWidth,
     705           2 :                           mnOrientation, mbVertical, mbArtItalic, mbArtBold );
     706           2 : }
     707             : 
     708           0 : static void DrawPrinterLayout( const SalLayout& rLayout, ::psp::PrinterGfx& rGfx, bool bIsPspServerFontLayout )
     709             : {
     710           0 :     const int nMaxGlyphs = 200;
     711             :     sal_GlyphId aGlyphAry[ nMaxGlyphs ];
     712             :     sal_Int32   aWidthAry[ nMaxGlyphs ];
     713             :     sal_Int32   aIdxAry  [ nMaxGlyphs ];
     714             :     sal_Unicode aUnicodes[ nMaxGlyphs ];
     715             :     int         aCharPosAry [ nMaxGlyphs ];
     716             : 
     717           0 :     Point aPos;
     718           0 :     long nUnitsPerPixel = rLayout.GetUnitsPerPixel();
     719           0 :     const sal_Unicode* pText = NULL;
     720           0 :     int nMinCharPos = 0;
     721           0 :     int nMaxCharPos = 0;
     722           0 :     if (bIsPspServerFontLayout)
     723             :     {
     724           0 :         const PspServerFontLayout * pPspLayout = dynamic_cast<const PspServerFontLayout*>(&rLayout);
     725             : #if ENABLE_GRAPHITE
     726           0 :         const GraphiteServerFontLayout * pGrLayout = dynamic_cast<const GraphiteServerFontLayout*>(&rLayout);
     727             : #endif
     728           0 :         if (pPspLayout)
     729             :         {
     730           0 :             pText = pPspLayout->getTextPtr();
     731           0 :             nMinCharPos = pPspLayout->getMinCharPos();
     732           0 :             nMaxCharPos = pPspLayout->getMaxCharPos();
     733             :         }
     734             : #if ENABLE_GRAPHITE
     735             :         else if (pGrLayout)
     736             :         {
     737             :         }
     738             : #endif
     739             :     }
     740           0 :     for( int nStart = 0;; )
     741             :     {
     742           0 :         int nGlyphCount = rLayout.GetNextGlyphs( nMaxGlyphs, aGlyphAry, aPos, nStart, aWidthAry, pText ? aCharPosAry : NULL );
     743           0 :         if( !nGlyphCount )
     744           0 :             break;
     745             : 
     746           0 :         sal_Int32 nXOffset = 0;
     747           0 :         for( int i = 0; i < nGlyphCount; ++i )
     748             :         {
     749           0 :             nXOffset += aWidthAry[ i ];
     750           0 :             aIdxAry[ i ] = nXOffset / nUnitsPerPixel;
     751           0 :             sal_GlyphId aGlyphId = aGlyphAry[i] & (GF_IDXMASK | GF_ROTMASK);
     752           0 :             if( pText )
     753           0 :                 aUnicodes[i] = (aCharPosAry[i] >= nMinCharPos && aCharPosAry[i] <= nMaxCharPos) ? pText[ aCharPosAry[i] ] : 0;
     754             :             else
     755           0 :                 aUnicodes[i] = (aGlyphAry[i] & GF_ISCHAR) ? aGlyphId : 0;
     756           0 :             aGlyphAry[i] = aGlyphId;
     757             :         }
     758             : 
     759           0 :         rGfx.DrawGlyphs( aPos, aGlyphAry, aUnicodes, nGlyphCount, aIdxAry );
     760           0 :     }
     761           0 : }
     762             : 
     763           0 : void PspFontLayout::InitFont() const
     764             : {
     765             :     mrPrinterGfx.SetFont( mnFontID, mnFontHeight, mnFontWidth,
     766           0 :         mnOrientation, mbVertical, mbArtItalic, mbArtBold );
     767           0 : }
     768             : 
     769           0 : void PspFontLayout::DrawText( SalGraphics& ) const
     770             : {
     771           0 :     DrawPrinterLayout( *this, mrPrinterGfx, false );
     772           0 : }
     773             : 
     774           0 : void GenPspGraphics::DrawServerFontLayout( const ServerFontLayout& rLayout )
     775             : {
     776             :     // print complex text
     777           0 :     DrawPrinterLayout( rLayout, *m_pPrinterGfx, true );
     778           0 : }
     779             : 
     780           0 : const ImplFontCharMap* GenPspGraphics::GetImplFontCharMap() const
     781             : {
     782           0 :     if( !m_pServerFont[0] )
     783           0 :         return NULL;
     784             : 
     785           0 :     const ImplFontCharMap* pIFCMap = m_pServerFont[0]->GetImplFontCharMap();
     786           0 :     return pIFCMap;
     787             : }
     788             : 
     789           0 : bool GenPspGraphics::GetImplFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const
     790             : {
     791           0 :     if (!m_pServerFont[0])
     792           0 :         return false;
     793           0 :     return m_pServerFont[0]->GetFontCapabilities(rFontCapabilities);
     794             : }
     795             : 
     796         729 : sal_uInt16 GenPspGraphics::SetFont( FontSelectPattern *pEntry, int nFallbackLevel )
     797             : {
     798             :     // release all fonts that are to be overridden
     799       12376 :     for( int i = nFallbackLevel; i < MAX_FALLBACK; ++i )
     800             :     {
     801       11647 :         if( m_pServerFont[i] != NULL )
     802             :         {
     803             :             // old server side font is no longer referenced
     804         367 :             GlyphCache::GetInstance().UncacheFont( *m_pServerFont[i] );
     805         367 :             m_pServerFont[i] = NULL;
     806             :         }
     807             :     }
     808             : 
     809             :     // return early if there is no new font
     810         729 :     if( !pEntry )
     811         353 :         return 0;
     812             : 
     813         376 :     sal_IntPtr nID = pEntry->mpFontData ? pEntry->mpFontData->GetFontId() : 0;
     814             : 
     815             :     // determine which font attributes need to be emulated
     816         376 :     bool bArtItalic = false;
     817         376 :     bool bArtBold = false;
     818         376 :     if( pEntry->GetSlant() == ITALIC_OBLIQUE || pEntry->GetSlant() == ITALIC_NORMAL )
     819             :     {
     820          38 :         FontItalic eItalic = m_pPrinterGfx->GetFontMgr().getFontItalic( nID );
     821          38 :         if( eItalic != ITALIC_NORMAL && eItalic != ITALIC_OBLIQUE )
     822           0 :             bArtItalic = true;
     823             :     }
     824         376 :     int nWeight = (int)pEntry->GetWeight();
     825         376 :     int nRealWeight = (int)m_pPrinterGfx->GetFontMgr().getFontWeight( nID );
     826         376 :     if( nRealWeight <= (int)WEIGHT_MEDIUM && nWeight > (int)WEIGHT_MEDIUM )
     827             :     {
     828           0 :         bArtBold = true;
     829             :     }
     830             : 
     831             :     // also set the serverside font for layouting
     832         376 :     m_bFontVertical = pEntry->mbVertical;
     833         376 :     if( pEntry->mpFontData )
     834             :     {
     835             :         // requesting a font provided by builtin rasterizer
     836         376 :         ServerFont* pServerFont = GlyphCache::GetInstance().CacheFont( *pEntry );
     837         376 :         if( pServerFont != NULL )
     838             :         {
     839         376 :             if( pServerFont->TestFont() )
     840         376 :                 m_pServerFont[ nFallbackLevel ] = pServerFont;
     841             :             else
     842           0 :                 GlyphCache::GetInstance().UncacheFont( *pServerFont );
     843             :         }
     844             :     }
     845             : 
     846             :     // set the printer font
     847             :     return m_pPrinterGfx->SetFont( nID,
     848             :                                    pEntry->mnHeight,
     849             :                                    pEntry->mnWidth,
     850             :                                    pEntry->mnOrientation,
     851             :                                    pEntry->mbVertical,
     852             :                                    bArtItalic,
     853             :                                    bArtBold
     854         376 :                                    );
     855             : }
     856             : 
     857           0 : void GenPspGraphics::SetTextColor( SalColor nSalColor )
     858             : {
     859           0 :     psp::PrinterColor aColor (SALCOLOR_RED   (nSalColor),
     860           0 :                               SALCOLOR_GREEN (nSalColor),
     861           0 :                               SALCOLOR_BLUE  (nSalColor));
     862           0 :     m_pPrinterGfx->SetTextColor (aColor);
     863           0 : }
     864             : 
     865           0 : bool GenPspGraphics::AddTempDevFont( PhysicalFontCollection*, const OUString&,const OUString& )
     866             : {
     867           0 :     return false;
     868             : }
     869             : 
     870         321 : void GenPspGraphics::GetDevFontList( PhysicalFontCollection *pFontCollection )
     871             : {
     872         321 :     ::std::list< psp::fontID > aList;
     873         321 :     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
     874         321 :     rMgr.getFontList( aList );
     875             : 
     876         321 :     ::std::list< psp::fontID >::iterator it;
     877         642 :     psp::FastPrintFontInfo aInfo;
     878       67731 :     for (it = aList.begin(); it != aList.end(); ++it)
     879       67410 :         if (rMgr.getFontFastInfo (*it, aInfo))
     880       67410 :             AnnounceFonts( pFontCollection, aInfo );
     881             : 
     882             :     // register platform specific font substitutions if available
     883         642 :     SalGenericInstance::RegisterFontSubstitutors( pFontCollection );
     884         321 : }
     885             : 
     886           0 : void GenPspGraphics::ClearDevFontCache()
     887             : {
     888           0 :     GlyphCache::GetInstance().ClearFontCache();
     889           0 : }
     890             : 
     891         192 : void GenPspGraphics::GetFontMetric( ImplFontMetricData *pMetric, int )
     892             : {
     893         192 :     const psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
     894         192 :     psp::PrintFontInfo aInfo;
     895             : 
     896         192 :     if (rMgr.getFontInfo (m_pPrinterGfx->GetFontID(), aInfo))
     897             :     {
     898         192 :         ImplDevFontAttributes aDFA = Info2DevFontAttributes( aInfo );
     899         192 :         static_cast<ImplFontAttributes&>(*pMetric) = aDFA;
     900         192 :         pMetric->mbDevice       = aDFA.mbDevice;
     901         192 :         pMetric->mbScalableFont = true;
     902             : 
     903         192 :         pMetric->mnOrientation  = m_pPrinterGfx->GetFontAngle();
     904         192 :         pMetric->mnSlant        = 0;
     905             : 
     906         192 :         sal_Int32 nTextHeight   = m_pPrinterGfx->GetFontHeight();
     907         192 :         sal_Int32 nTextWidth    = m_pPrinterGfx->GetFontWidth();
     908         192 :         if( ! nTextWidth )
     909         192 :             nTextWidth = nTextHeight;
     910             : 
     911         192 :         pMetric->mnWidth        = nTextWidth;
     912         192 :         pMetric->mnAscent       = ( aInfo.m_nAscend * nTextHeight + 500 ) / 1000;
     913         192 :         pMetric->mnDescent      = ( aInfo.m_nDescend * nTextHeight + 500 ) / 1000;
     914         192 :         pMetric->mnIntLeading   = ( aInfo.m_nLeading * nTextHeight + 500 ) / 1000;
     915         192 :         pMetric->mnExtLeading   = 0;
     916         192 :     }
     917         192 : }
     918             : 
     919           0 : bool GenPspGraphics::GetGlyphBoundRect( sal_GlyphId aGlyphId, Rectangle& rRect )
     920             : {
     921           0 :     const int nLevel = aGlyphId >> GF_FONTSHIFT;
     922           0 :     if( nLevel >= MAX_FALLBACK )
     923           0 :         return false;
     924             : 
     925           0 :     ServerFont* pSF = m_pServerFont[ nLevel ];
     926           0 :     if( !pSF )
     927           0 :         return false;
     928             : 
     929           0 :     aGlyphId &= GF_IDXMASK;
     930           0 :     const GlyphMetric& rGM = pSF->GetGlyphMetric( aGlyphId );
     931           0 :     rRect = Rectangle( rGM.GetOffset(), rGM.GetSize() );
     932           0 :     return true;
     933             : }
     934             : 
     935           0 : bool GenPspGraphics::GetGlyphOutline( sal_GlyphId aGlyphId,
     936             :     ::basegfx::B2DPolyPolygon& rB2DPolyPoly )
     937             : {
     938           0 :     const int nLevel = aGlyphId >> GF_FONTSHIFT;
     939           0 :     if( nLevel >= MAX_FALLBACK )
     940           0 :         return false;
     941             : 
     942           0 :     ServerFont* pSF = m_pServerFont[ nLevel ];
     943           0 :     if( !pSF )
     944           0 :         return false;
     945             : 
     946           0 :     aGlyphId &= GF_IDXMASK;
     947           0 :     if( pSF->GetGlyphOutline( aGlyphId, rB2DPolyPoly ) )
     948           0 :         return true;
     949             : 
     950           0 :     return false;
     951             : }
     952             : 
     953        2272 : SalLayout* GenPspGraphics::GetTextLayout( ImplLayoutArgs& rArgs, int nFallbackLevel )
     954             : {
     955             :     // workaround for printers not handling glyph indexing for non-TT fonts
     956        2272 :     int nFontId = m_pPrinterGfx->GetFontID();
     957        2272 :     if( psp::fonttype::TrueType != psp::PrintFontManager::get().getFontType( nFontId ) )
     958          45 :         rArgs.mnFlags |= SAL_LAYOUT_DISABLE_GLYPH_PROCESSING;
     959        2227 :     else if( nFallbackLevel > 0 )
     960           2 :         rArgs.mnFlags &= ~SAL_LAYOUT_DISABLE_GLYPH_PROCESSING;
     961             : 
     962        2272 :     GenericSalLayout* pLayout = NULL;
     963             : 
     964        2272 :     if( m_pServerFont[ nFallbackLevel ]
     965        2272 :         && !(rArgs.mnFlags & SAL_LAYOUT_DISABLE_GLYPH_PROCESSING) )
     966             :     {
     967             : #if ENABLE_GRAPHITE
     968             :         // Is this a Graphite font?
     969        4454 :         if (GraphiteServerFontLayout::IsGraphiteEnabledFont(*m_pServerFont[nFallbackLevel]))
     970             :         {
     971           0 :             pLayout = new GraphiteServerFontLayout(*m_pServerFont[nFallbackLevel]);
     972             :         }
     973             :         else
     974             : #endif
     975        2227 :             pLayout = new PspServerFontLayout( *m_pPrinterGfx, *m_pServerFont[nFallbackLevel], rArgs );
     976             :     }
     977             :     else
     978          45 :         pLayout = new PspFontLayout( *m_pPrinterGfx );
     979             : 
     980        2272 :     return pLayout;
     981             : }
     982             : 
     983           0 : bool GenPspGraphics::CreateFontSubset(
     984             :                                    const OUString& rToFile,
     985             :                                    const PhysicalFontFace* pFont,
     986             :                                    sal_GlyphId* pGlyphIds,
     987             :                                    sal_uInt8* pEncoding,
     988             :                                    sal_Int32* pWidths,
     989             :                                    int nGlyphCount,
     990             :                                    FontSubsetInfo& rInfo
     991             :                                    )
     992             : {
     993             :     // in this context the pFont->GetFontId() is a valid PSP
     994             :     // font since they are the only ones left after the PDF
     995             :     // export has filtered its list of subsettable fonts (for
     996             :     // which this method was created). The correct way would
     997             :     // be to have the GlyphCache search for the PhysicalFontFace pFont
     998           0 :     psp::fontID aFont = pFont->GetFontId();
     999             : 
    1000           0 :     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
    1001             :     bool bSuccess = rMgr.createFontSubset( rInfo,
    1002             :                                  aFont,
    1003             :                                  rToFile,
    1004             :                                  pGlyphIds,
    1005             :                                  pEncoding,
    1006             :                                  pWidths,
    1007           0 :                                  nGlyphCount );
    1008           0 :     return bSuccess;
    1009             : }
    1010             : 
    1011           0 : const Ucs2SIntMap* GenPspGraphics::GetFontEncodingVector( const PhysicalFontFace* pFont, const Ucs2OStrMap** pNonEncoded )
    1012             : {
    1013             :     // in this context the pFont->GetFontId() is a valid PSP
    1014             :     // font since they are the only ones left after the PDF
    1015             :     // export has filtered its list of subsettable fonts (for
    1016             :     // which this method was created). The correct way would
    1017             :     // be to have the GlyphCache search for the PhysicalFontFace pFont
    1018           0 :     psp::fontID aFont = pFont->GetFontId();
    1019           0 :     return GenPspGraphics::DoGetFontEncodingVector( aFont, pNonEncoded );
    1020             : }
    1021             : 
    1022           0 : void GenPspGraphics::GetGlyphWidths( const PhysicalFontFace* pFont,
    1023             :                                   bool bVertical,
    1024             :                                   Int32Vector& rWidths,
    1025             :                                   Ucs2UIntMap& rUnicodeEnc )
    1026             : {
    1027             :     // in this context the pFont->GetFontId() is a valid PSP
    1028             :     // font since they are the only ones left after the PDF
    1029             :     // export has filtered its list of subsettable fonts (for
    1030             :     // which this method was created). The correct way would
    1031             :     // be to have the GlyphCache search for the PhysicalFontFace pFont
    1032           0 :     psp::fontID aFont = pFont->GetFontId();
    1033           0 :     GenPspGraphics::DoGetGlyphWidths( aFont, bVertical, rWidths, rUnicodeEnc );
    1034           0 : }
    1035             : 
    1036           0 : const Ucs2SIntMap* GenPspGraphics::DoGetFontEncodingVector( fontID aFont, const Ucs2OStrMap** pNonEncoded )
    1037             : {
    1038           0 :     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
    1039             : 
    1040           0 :     psp::PrintFontInfo aFontInfo;
    1041           0 :     if( ! rMgr.getFontInfo( aFont, aFontInfo ) )
    1042             :     {
    1043           0 :         if( pNonEncoded )
    1044           0 :             *pNonEncoded = NULL;
    1045           0 :         return NULL;
    1046             :     }
    1047             : 
    1048           0 :     return rMgr.getEncodingMap( aFont, pNonEncoded );
    1049             : }
    1050             : 
    1051           0 : void GenPspGraphics::DoGetGlyphWidths( psp::fontID aFont,
    1052             :                                     bool bVertical,
    1053             :                                     Int32Vector& rWidths,
    1054             :                                     Ucs2UIntMap& rUnicodeEnc )
    1055             : {
    1056           0 :     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
    1057           0 :     rMgr.getGlyphWidths( aFont, bVertical, rWidths, rUnicodeEnc );
    1058           0 : }
    1059             : 
    1060       96582 : ImplDevFontAttributes GenPspGraphics::Info2DevFontAttributes( const psp::FastPrintFontInfo& rInfo )
    1061             : {
    1062       96582 :     ImplDevFontAttributes aDFA;
    1063       96582 :     aDFA.SetFamilyName( rInfo.m_aFamilyName );
    1064       96582 :     aDFA.SetStyleName( rInfo.m_aStyleName );
    1065       96582 :     aDFA.SetFamilyType( rInfo.m_eFamilyStyle );
    1066       96582 :     aDFA.SetWeight( rInfo.m_eWeight );
    1067       96582 :     aDFA.SetItalic( rInfo.m_eItalic );
    1068       96582 :     aDFA.SetWidthType( rInfo.m_eWidth );
    1069       96582 :     aDFA.SetPitch( rInfo.m_ePitch );
    1070       96582 :     aDFA.SetSymbolFlag( (rInfo.m_aEncoding == RTL_TEXTENCODING_SYMBOL) );
    1071       96582 :     aDFA.mbSubsettable  = rInfo.m_bSubsettable;
    1072       96582 :     aDFA.mbEmbeddable   = rInfo.m_bEmbeddable;
    1073             : 
    1074       96582 :     switch( rInfo.m_eType )
    1075             :     {
    1076             :         case psp::fonttype::TrueType:
    1077       75006 :             aDFA.mnQuality       = 512;
    1078       75006 :             aDFA.mbDevice        = false;
    1079       75006 :             break;
    1080             :         case psp::fonttype::Type1:
    1081       21576 :             aDFA.mnQuality       = 0;
    1082       21576 :             aDFA.mbDevice        = false;
    1083       21576 :             break;
    1084             :         default:
    1085           0 :             aDFA.mnQuality       = 0;
    1086           0 :             aDFA.mbDevice        = false;
    1087           0 :             break;
    1088             :     }
    1089             : 
    1090       96582 :     aDFA.mbOrientation   = true;
    1091             : 
    1092             :     // add font family name aliases
    1093       96582 :     ::std::list< OUString >::const_iterator it = rInfo.m_aAliases.begin();
    1094       96582 :     bool bHasMapNames = false;
    1095      101172 :     for(; it != rInfo.m_aAliases.end(); ++it )
    1096             :     {
    1097        4590 :         if( bHasMapNames )
    1098        1377 :             aDFA.maMapNames += OUString(';');
    1099        4590 :         aDFA.maMapNames += *it;
    1100        4590 :         bHasMapNames = true;
    1101             :     }
    1102             : 
    1103             : #if OSL_DEBUG_LEVEL > 2
    1104             :     if( bHasMapNames )
    1105             :     {
    1106             :         OString aOrigName(OUStringToOString(aDFA.GetFamilyName(), osl_getThreadTextEncoding()));
    1107             :         OString aAliasNames(OUStringToOString(aDFA.GetAliasNames(), osl_getThreadTextEncoding()));
    1108             :         SAL_INFO( "vcl.fonts", "using alias names " << aAliasNames.getStr() << " for font family " << aOrigName.getStr() );
    1109             :     }
    1110             : #endif
    1111             : 
    1112       96582 :     return aDFA;
    1113             : }
    1114             : 
    1115             : namespace vcl
    1116             : {
    1117         166 :     const char* getLangBoost()
    1118             :     {
    1119             :         const char* pLangBoost;
    1120         166 :         const LanguageType eLang = Application::GetSettings().GetUILanguageTag().getLanguageType();
    1121         166 :         if (eLang == LANGUAGE_JAPANESE)
    1122           0 :             pLangBoost = "jan";
    1123         166 :         else if (MsLangId::isKorean(eLang))
    1124           0 :             pLangBoost = "kor";
    1125         166 :         else if (MsLangId::isSimplifiedChinese(eLang))
    1126           0 :             pLangBoost = "zhs";
    1127         166 :         else if (MsLangId::isTraditionalChinese(eLang))
    1128           0 :             pLangBoost = "zht";
    1129             :         else
    1130         166 :             pLangBoost = NULL;
    1131         166 :         return pLangBoost;
    1132             :     }
    1133             : }
    1134             : 
    1135       67410 : void GenPspGraphics::AnnounceFonts( PhysicalFontCollection* pFontCollection, const psp::FastPrintFontInfo& aInfo )
    1136             : {
    1137       67410 :     int nQuality = 0;
    1138             : 
    1139       67410 :     if( aInfo.m_eType == psp::fonttype::TrueType )
    1140             :     {
    1141             :         // asian type 1 fonts are not known
    1142       52323 :         psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
    1143       52323 :         OString aFileName( rMgr.getFontFileSysPath( aInfo.m_nID ) );
    1144       52323 :         int nPos = aFileName.lastIndexOf( '_' );
    1145       52323 :         if( nPos == -1 || aFileName[nPos+1] == '.' )
    1146       46866 :             nQuality += 5;
    1147             :         else
    1148             :         {
    1149             :             static const char* pLangBoost = NULL;
    1150             :             static bool bOnce = true;
    1151        5457 :             if( bOnce )
    1152             :             {
    1153          30 :                 bOnce = false;
    1154          30 :                 pLangBoost = vcl::getLangBoost();
    1155             :             }
    1156             : 
    1157        5457 :             if( pLangBoost )
    1158           0 :                 if( aFileName.copy( nPos+1, 3 ).equalsIgnoreAsciiCase( pLangBoost ) )
    1159           0 :                     nQuality += 10;
    1160       52323 :         }
    1161             :     }
    1162             : 
    1163       67410 :     ImplPspFontData* pFD = new ImplPspFontData( aInfo );
    1164       67410 :     pFD->mnQuality += nQuality;
    1165       67410 :     pFontCollection->Add( pFD );
    1166       67410 : }
    1167             : 
    1168           0 : bool GenPspGraphics::drawAlphaBitmap( const SalTwoRect&,
    1169             :                                    const SalBitmap&,
    1170             :                                    const SalBitmap& )
    1171             : {
    1172           0 :     return false;
    1173             : }
    1174             : 
    1175           0 : bool GenPspGraphics::drawTransformedBitmap(
    1176             :     const basegfx::B2DPoint& rNull,
    1177             :     const basegfx::B2DPoint& rX,
    1178             :     const basegfx::B2DPoint& rY,
    1179             :     const SalBitmap& rSourceBitmap,
    1180             :     const SalBitmap* pAlphaBitmap)
    1181             : {
    1182             :     // here direct support for transformed bitmaps can be impemented
    1183             :     (void)rNull; (void)rX; (void)rY; (void)rSourceBitmap; (void)pAlphaBitmap;
    1184           0 :     return false;
    1185             : }
    1186             : 
    1187           0 : bool GenPspGraphics::drawAlphaRect( long, long, long, long, sal_uInt8 )
    1188             : {
    1189           0 :     return false;
    1190             : }
    1191             : 
    1192           0 : SystemGraphicsData GenPspGraphics::GetGraphicsData() const
    1193             : {
    1194           0 :     return SystemGraphicsData();
    1195             : }
    1196             : 
    1197           0 : SystemFontData GenPspGraphics::GetSysFontData( int /* nFallbacklevel */ ) const
    1198             : {
    1199           0 :     return SystemFontData();
    1200             : }
    1201             : 
    1202           0 : bool GenPspGraphics::supportsOperation( OutDevSupportType ) const
    1203             : {
    1204           0 :     return false;
    1205             : }
    1206             : 
    1207           0 : void GenPspGraphics::DoFreeEmbedFontData( const void* pData, long nLen )
    1208             : {
    1209             : #if defined( UNX )
    1210           0 :     if( pData )
    1211           0 :         munmap( (char*)pData, nLen );
    1212             : #else
    1213             :     (void)nLen;
    1214             :     rtl_freeMemory( (void *)pData );
    1215             : #endif
    1216           0 : }
    1217             : 
    1218           0 : const void* GenPspGraphics::DoGetEmbedFontData( psp::fontID aFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, FontSubsetInfo& rInfo, long* pDataLen )
    1219             : {
    1220             : 
    1221           0 :     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
    1222             : 
    1223           0 :     psp::PrintFontInfo aFontInfo;
    1224           0 :     if( ! rMgr.getFontInfo( aFont, aFontInfo ) )
    1225           0 :         return NULL;
    1226             : 
    1227             :     // fill in font info
    1228           0 :     rInfo.m_nAscent     = aFontInfo.m_nAscend;
    1229           0 :     rInfo.m_nDescent    = aFontInfo.m_nDescend;
    1230           0 :     rInfo.m_aPSName     = rMgr.getPSName( aFont );
    1231             : 
    1232             :     int xMin, yMin, xMax, yMax;
    1233           0 :     rMgr.getFontBoundingBox( aFont, xMin, yMin, xMax, yMax );
    1234             : 
    1235           0 :     psp::CharacterMetric aMetrics[256];
    1236             :     sal_Ucs aUnicodes[256];
    1237           0 :     if( aFontInfo.m_aEncoding == RTL_TEXTENCODING_SYMBOL && aFontInfo.m_eType == psp::fonttype::Type1 )
    1238             :     {
    1239           0 :         for( int i = 0; i < 256; i++ )
    1240           0 :             aUnicodes[i] = pUnicodes[i] < 0x0100 ? pUnicodes[i] + 0xf000 : pUnicodes[i];
    1241           0 :         pUnicodes = aUnicodes;
    1242             :     }
    1243           0 :     if( ! rMgr.getMetrics( aFont, pUnicodes, 256, aMetrics ) )
    1244           0 :         return NULL;
    1245             : 
    1246           0 :     OString aSysPath = rMgr.getFontFileSysPath( aFont );
    1247             : 
    1248             : #if defined( UNX )
    1249             :     struct stat aStat;
    1250           0 :     if( stat( aSysPath.getStr(), &aStat ) )
    1251           0 :         return NULL;
    1252           0 :     int fd = open( aSysPath.getStr(), O_RDONLY );
    1253           0 :     if( fd < 0 )
    1254           0 :         return NULL;
    1255           0 :     void* pFile = mmap( NULL, aStat.st_size, PROT_READ, MAP_SHARED, fd, 0 );
    1256           0 :     close( fd );
    1257           0 :     if( pFile == MAP_FAILED )
    1258           0 :         return NULL;
    1259           0 :     *pDataLen = aStat.st_size;
    1260             : #else
    1261             :     // FIXME: test me ! ...
    1262             :     OUString aURL;
    1263             :     if( osl::File::getFileURLFromSystemPath( OStringToOUString( aSysPath, osl_getThreadTextEncoding() ), aURL ) != osl::File::E_None )
    1264             :         return NULL;
    1265             :     osl::File aFile( aURL );
    1266             :     if( aFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_NoLock ) != osl::File::E_None )
    1267             :         return NULL;
    1268             : 
    1269             :     osl::DirectoryItem aItem;
    1270             :     osl::DirectoryItem::get( aURL, aItem );
    1271             :     osl::FileStatus aFileStatus( osl_FileStatus_Mask_FileSize );
    1272             :     aItem.getFileStatus( aFileStatus );
    1273             : 
    1274             :     void *pFile = rtl_allocateMemory( aFileStatus.getFileSize() );
    1275             :     sal_uInt64 nRead = 0;
    1276             :     aFile.read( pFile, aFileStatus.getFileSize(), nRead );
    1277             :     *pDataLen = (long) nRead;
    1278             : #endif
    1279             : 
    1280           0 :     rInfo.m_aFontBBox   = Rectangle( Point( xMin, yMin ), Size( xMax-xMin, yMax-yMin ) );
    1281           0 :     rInfo.m_nCapHeight  = yMax; // Well ...
    1282             : 
    1283           0 :     for( int i = 0; i < 256; i++ )
    1284           0 :         pWidths[i] = (aMetrics[i].width > 0 ? aMetrics[i].width : 0);
    1285             : 
    1286           0 :     switch( aFontInfo.m_eType )
    1287             :     {
    1288             :         case psp::fonttype::TrueType:
    1289           0 :             rInfo.m_nFontType = FontSubsetInfo::SFNT_TTF;
    1290           0 :             break;
    1291             :         case psp::fonttype::Type1: {
    1292           0 :             const bool bPFA = ((*(unsigned char*)pFile) < 0x80);
    1293           0 :             rInfo.m_nFontType = bPFA ? FontSubsetInfo::TYPE1_PFA : FontSubsetInfo::TYPE1_PFB;
    1294             :             }
    1295           0 :             break;
    1296             :         default:
    1297           0 :             DoFreeEmbedFontData( pFile, *pDataLen );
    1298           0 :             return NULL;
    1299             :     }
    1300             : 
    1301           0 :     return pFile;
    1302             : }
    1303             : 
    1304           0 : void GenPspGraphics::FreeEmbedFontData( const void* pData, long nLen )
    1305             : {
    1306           0 :     DoFreeEmbedFontData( pData, nLen );
    1307           0 : }
    1308             : 
    1309           0 : const void* GenPspGraphics::GetEmbedFontData( const PhysicalFontFace* pFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, FontSubsetInfo& rInfo, long* pDataLen )
    1310             : {
    1311             :     // in this context the pFont->GetFontId() is a valid PSP
    1312             :     // font since they are the only ones left after the PDF
    1313             :     // export has filtered its list of subsettable fonts (for
    1314             :     // which this method was created). The correct way would
    1315             :     // be to have the GlyphCache search for the PhysicalFontFace pFont
    1316           0 :     psp::fontID aFont = pFont->GetFontId();
    1317           0 :     return DoGetEmbedFontData( aFont, pUnicodes, pWidths, rInfo, pDataLen );
    1318         516 : }
    1319             : 
    1320             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10