LCOV - code coverage report
Current view: top level - vcl/generic/print - genpspgraphics.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 205 580 35.3 %
Date: 2014-11-03 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             :     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         780 : GenPspGraphics::GenPspGraphics()
     266             :     : m_pJobData( NULL ),
     267             :       m_pPrinterGfx( NULL ),
     268             :       m_bFontVertical( false ),
     269         780 :       m_pInfoPrinter( NULL )
     270             : {
     271       13260 :     for( int i = 0; i < MAX_FALLBACK; i++ )
     272       12480 :         m_pServerFont[i] = NULL;
     273         780 : }
     274             : 
     275         780 : void GenPspGraphics::Init(psp::JobData* pJob, psp::PrinterGfx* pGfx,
     276             :                            SalInfoPrinter* pInfoPrinter)
     277             : {
     278         780 :     m_pJobData = pJob;
     279         780 :     m_pPrinterGfx = pGfx;
     280         780 :     m_pInfoPrinter = pInfoPrinter;
     281         780 :     SetLayout( 0 );
     282         780 : }
     283             : 
     284        2331 : GenPspGraphics::~GenPspGraphics()
     285             : {
     286         777 :     ReleaseFonts();
     287        1554 : }
     288             : 
     289         780 : void GenPspGraphics::GetResolution( sal_Int32 &rDPIX, sal_Int32 &rDPIY )
     290             : {
     291         780 :     if (m_pJobData != NULL)
     292             :     {
     293         780 :         int x = m_pJobData->m_aContext.getRenderResolution();
     294             : 
     295         780 :         rDPIX = x;
     296         780 :         rDPIY = x;
     297             :     }
     298         780 : }
     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 vcl::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           0 :                     aRectIter->Left(),
     334           0 :                     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         780 : void GenPspGraphics::SetXORMode( bool bSet, bool )
     397             : {
     398             :     (void)bSet;
     399             :     DBG_ASSERT( !bSet, "Error: PrinterGfx::SetXORMode() not implemented" );
     400         780 : }
     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      236256 : 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        2176 :     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      118560 : ImplPspFontData::ImplPspFontData( const psp::FastPrintFontInfo& rInfo )
     572             : :   PhysicalFontFace( GenPspGraphics::Info2DevFontAttributes(rInfo), PSPFD_MAGIC ),
     573      118560 :     mnFontId( rInfo.m_nID )
     574      118560 : {}
     575             : 
     576         487 : ImplFontEntry* ImplPspFontData::CreateFontInstance( FontSelectPattern& rFSD ) const
     577             : {
     578         487 :     ImplServerFontEntry* pEntry = new ImplServerFontEntry( rFSD );
     579         487 :     return pEntry;
     580             : }
     581             : 
     582         180 : 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          90 : PspFontLayout::PspFontLayout( ::psp::PrinterGfx& rGfx )
     600          90 : :   mrPrinterGfx( rGfx )
     601             : {
     602          90 :     mnFontID     = mrPrinterGfx.GetFontID();
     603          90 :     mnFontHeight = mrPrinterGfx.GetFontHeight();
     604          90 :     mnFontWidth  = mrPrinterGfx.GetFontWidth();
     605          90 :     mbVertical   = mrPrinterGfx.GetFontVertical();
     606          90 :     mbArtItalic  = mrPrinterGfx.GetArtificialItalic();
     607          90 :     mbArtBold    = mrPrinterGfx.GetArtificialBold();
     608          90 : }
     609             : 
     610          90 : bool PspFontLayout::LayoutText( ImplLayoutArgs& rArgs )
     611             : {
     612          90 :     mbVertical = ((rArgs.mnFlags & SAL_LAYOUT_VERTICAL) != 0);
     613             : 
     614          90 :     long nUnitsPerPixel = 1;
     615          90 :     sal_GlyphId aOldGlyphId( GF_DROPPED);
     616          90 :     long nGlyphWidth = 0;
     617          90 :     int nCharPos = -1;
     618          90 :     Point aNewPos( 0, 0 );
     619          90 :     GlyphItem aPrevItem;
     620          90 :     rtl_TextEncoding aFontEnc = mrPrinterGfx.GetFontMgr().getFontEncoding( mnFontID );
     621             : 
     622          90 :     Reserve(rArgs.mnLength);
     623             : 
     624             :     for(;;)
     625             :     {
     626             :         bool bRightToLeft;
     627        4262 :         if( !rArgs.GetNextPos( &nCharPos, &bRightToLeft ) )
     628          90 :             break;
     629             : 
     630        4172 :         sal_Unicode cChar = rArgs.mpStr[ nCharPos ];
     631        4172 :         if( bRightToLeft )
     632           0 :             cChar = GetMirroredChar( cChar );
     633             :         // symbol font aliasing: 0x0020-0x00ff -> 0xf020 -> 0xf0ff
     634        4172 :         if( aFontEnc == RTL_TEXTENCODING_SYMBOL )
     635           0 :             if( cChar < 256 )
     636           0 :                 cChar += 0xf000;
     637        4172 :         sal_GlyphId aGlyphId( cChar);  // printer glyphs = unicode
     638             : 
     639             :         // update fallback_runs if needed
     640        4172 :         psp::CharacterMetric aMetric;
     641             :         // coverity[array_vs_singleton]
     642        4172 :         mrPrinterGfx.GetFontMgr().getMetrics( mnFontID, cChar, cChar, &aMetric, mbVertical );
     643        4172 :         if( aMetric.width == -1 && aMetric.height == -1 )
     644           0 :             rArgs.NeedFallback( nCharPos, bRightToLeft );
     645             : 
     646             :         // finish previous glyph
     647        4172 :         if( aOldGlyphId != GF_DROPPED )
     648        4082 :             AppendGlyph( aPrevItem );
     649        4172 :         aOldGlyphId = aGlyphId;
     650        4172 :         aNewPos.X() += nGlyphWidth;
     651             : 
     652             :         // prepare GlyphItem for appending it in next round
     653        4172 :         nUnitsPerPixel = mrPrinterGfx.GetCharWidth( cChar, cChar, &nGlyphWidth );
     654        4172 :         int nGlyphFlags = bRightToLeft ? GlyphItem::IS_RTL_GLYPH : 0;
     655        4172 :         aGlyphId |= GF_ISCHAR;
     656        4172 :         aPrevItem = GlyphItem( nCharPos, aGlyphId, aNewPos, nGlyphFlags, nGlyphWidth );
     657        4172 :     }
     658             : 
     659             :     // append last glyph item if any
     660          90 :     if( aOldGlyphId != GF_DROPPED )
     661          90 :         AppendGlyph( aPrevItem );
     662             : 
     663          90 :     SetOrientation( mrPrinterGfx.GetFontAngle() );
     664          90 :     SetUnitsPerPixel( nUnitsPerPixel );
     665          90 :     return (aOldGlyphId != GF_DROPPED);
     666             : }
     667             : 
     668       12146 : class PspServerFontLayout : public ServerFontLayout
     669             : {
     670             : public:
     671             :     PspServerFontLayout( psp::PrinterGfx&, ServerFont& rFont, const ImplLayoutArgs& rArgs );
     672             : 
     673             :     virtual void        InitFont() const SAL_OVERRIDE;
     674           0 :     const sal_Unicode*  getTextPtr() const { return maText.getStr() - mnMinCharPos; }
     675           0 :     int                 getMinCharPos() const { return mnMinCharPos; }
     676           0 :     int                 getMaxCharPos() const { return mnMinCharPos+maText.getLength()-1; }
     677             : private:
     678             :     ::psp::PrinterGfx&  mrPrinterGfx;
     679             :     sal_IntPtr          mnFontID;
     680             :     int                 mnFontHeight;
     681             :     int                 mnFontWidth;
     682             :     bool                mbVertical;
     683             :     bool                mbArtItalic;
     684             :     bool                mbArtBold;
     685             :     OUString       maText;
     686             :     int                 mnMinCharPos;
     687             : };
     688             : 
     689        6073 : PspServerFontLayout::PspServerFontLayout( ::psp::PrinterGfx& rGfx, ServerFont& rFont, const ImplLayoutArgs& rArgs )
     690             :         :   ServerFontLayout( rFont ),
     691        6073 :             mrPrinterGfx( rGfx )
     692             : {
     693        6073 :     mnFontID     = mrPrinterGfx.GetFontID();
     694        6073 :     mnFontHeight = mrPrinterGfx.GetFontHeight();
     695        6073 :     mnFontWidth  = mrPrinterGfx.GetFontWidth();
     696        6073 :     mbVertical   = mrPrinterGfx.GetFontVertical();
     697        6073 :     mbArtItalic  = mrPrinterGfx.GetArtificialItalic();
     698        6073 :     mbArtBold    = mrPrinterGfx.GetArtificialBold();
     699        6073 :     maText       = OUString( rArgs.mpStr + rArgs.mnMinCharPos, rArgs.mnEndCharPos - rArgs.mnMinCharPos+1 );
     700        6073 :     mnMinCharPos = rArgs.mnMinCharPos;
     701        6073 : }
     702             : 
     703           4 : void PspServerFontLayout::InitFont() const
     704             : {
     705             :     mrPrinterGfx.SetFont( mnFontID, mnFontHeight, mnFontWidth,
     706           4 :                           mnOrientation, mbVertical, mbArtItalic, mbArtBold );
     707           4 : }
     708             : 
     709           0 : static void DrawPrinterLayout( const SalLayout& rLayout, ::psp::PrinterGfx& rGfx, bool bIsPspServerFontLayout )
     710             : {
     711           0 :     const int nMaxGlyphs = 200;
     712             :     sal_GlyphId aGlyphAry[ nMaxGlyphs ];
     713             :     DeviceCoordinate aWidthAry[ nMaxGlyphs ];
     714             :     sal_Int32   aIdxAry  [ nMaxGlyphs ];
     715             :     sal_Unicode aUnicodes[ nMaxGlyphs ];
     716             :     int         aCharPosAry [ nMaxGlyphs ];
     717             : 
     718           0 :     Point aPos;
     719           0 :     long nUnitsPerPixel = rLayout.GetUnitsPerPixel();
     720           0 :     const sal_Unicode* pText = NULL;
     721           0 :     int nMinCharPos = 0;
     722           0 :     int nMaxCharPos = 0;
     723           0 :     if (bIsPspServerFontLayout)
     724             :     {
     725           0 :         const PspServerFontLayout * pPspLayout = dynamic_cast<const PspServerFontLayout*>(&rLayout);
     726             : #if ENABLE_GRAPHITE
     727           0 :         const GraphiteServerFontLayout * pGrLayout = dynamic_cast<const GraphiteServerFontLayout*>(&rLayout);
     728             : #endif
     729           0 :         if (pPspLayout)
     730             :         {
     731           0 :             pText = pPspLayout->getTextPtr();
     732           0 :             nMinCharPos = pPspLayout->getMinCharPos();
     733           0 :             nMaxCharPos = pPspLayout->getMaxCharPos();
     734             :         }
     735             : #if ENABLE_GRAPHITE
     736             :         else if (pGrLayout)
     737             :         {
     738             :         }
     739             : #endif
     740             :     }
     741           0 :     for( int nStart = 0;; )
     742             :     {
     743           0 :         int nGlyphCount = rLayout.GetNextGlyphs( nMaxGlyphs, aGlyphAry, aPos, nStart, aWidthAry, pText ? aCharPosAry : NULL );
     744           0 :         if( !nGlyphCount )
     745           0 :             break;
     746             : 
     747           0 :         DeviceCoordinate nXOffset = 0;
     748           0 :         for( int i = 0; i < nGlyphCount; ++i )
     749             :         {
     750           0 :             nXOffset += aWidthAry[ i ];
     751           0 :             aIdxAry[ i ] = nXOffset / nUnitsPerPixel;
     752           0 :             sal_GlyphId aGlyphId = aGlyphAry[i] & (GF_IDXMASK | GF_ROTMASK);
     753           0 :             if( pText )
     754           0 :                 aUnicodes[i] = (aCharPosAry[i] >= nMinCharPos && aCharPosAry[i] <= nMaxCharPos) ? pText[ aCharPosAry[i] ] : 0;
     755             :             else
     756           0 :                 aUnicodes[i] = (aGlyphAry[i] & GF_ISCHAR) ? aGlyphId : 0;
     757           0 :             aGlyphAry[i] = aGlyphId;
     758             :         }
     759             : 
     760           0 :         rGfx.DrawGlyphs( aPos, aGlyphAry, aUnicodes, nGlyphCount, aIdxAry );
     761           0 :     }
     762           0 : }
     763             : 
     764           0 : void PspFontLayout::InitFont() const
     765             : {
     766             :     mrPrinterGfx.SetFont( mnFontID, mnFontHeight, mnFontWidth,
     767           0 :         mnOrientation, mbVertical, mbArtItalic, mbArtBold );
     768           0 : }
     769             : 
     770           0 : void PspFontLayout::DrawText( SalGraphics& ) const
     771             : {
     772           0 :     DrawPrinterLayout( *this, mrPrinterGfx, false );
     773           0 : }
     774             : 
     775           0 : void GenPspGraphics::DrawServerFontLayout( const ServerFontLayout& rLayout )
     776             : {
     777             :     // print complex text
     778           0 :     DrawPrinterLayout( rLayout, *m_pPrinterGfx, true );
     779           0 : }
     780             : 
     781           0 : const FontCharMapPtr GenPspGraphics::GetFontCharMap() const
     782             : {
     783           0 :     if( !m_pServerFont[0] )
     784           0 :         return NULL;
     785             : 
     786           0 :     const FontCharMapPtr pFCMap = m_pServerFont[0]->GetFontCharMap();
     787           0 :     return pFCMap;
     788             : }
     789             : 
     790           0 : bool GenPspGraphics::GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const
     791             : {
     792           0 :     if (!m_pServerFont[0])
     793           0 :         return false;
     794           0 :     return m_pServerFont[0]->GetFontCapabilities(rFontCapabilities);
     795             : }
     796             : 
     797        2742 : sal_uInt16 GenPspGraphics::SetFont( FontSelectPattern *pEntry, int nFallbackLevel )
     798             : {
     799             :     // release all fonts that are to be overridden
     800       46614 :     for( int i = nFallbackLevel; i < MAX_FALLBACK; ++i )
     801             :     {
     802       43872 :         if( m_pServerFont[i] != NULL )
     803             :         {
     804             :             // old server side font is no longer referenced
     805        1088 :             GlyphCache::GetInstance().UncacheFont( *m_pServerFont[i] );
     806        1088 :             m_pServerFont[i] = NULL;
     807             :         }
     808             :     }
     809             : 
     810             :     // return early if there is no new font
     811        2742 :     if( !pEntry )
     812        1654 :         return 0;
     813             : 
     814        1088 :     sal_IntPtr nID = pEntry->mpFontData ? pEntry->mpFontData->GetFontId() : 0;
     815             : 
     816             :     // determine which font attributes need to be emulated
     817        1088 :     bool bArtItalic = false;
     818        1088 :     bool bArtBold = false;
     819        1088 :     if( pEntry->GetSlant() == ITALIC_OBLIQUE || pEntry->GetSlant() == ITALIC_NORMAL )
     820             :     {
     821          76 :         FontItalic eItalic = m_pPrinterGfx->GetFontMgr().getFontItalic( nID );
     822          76 :         if( eItalic != ITALIC_NORMAL && eItalic != ITALIC_OBLIQUE )
     823           0 :             bArtItalic = true;
     824             :     }
     825        1088 :     int nWeight = (int)pEntry->GetWeight();
     826        1088 :     int nRealWeight = (int)m_pPrinterGfx->GetFontMgr().getFontWeight( nID );
     827        1088 :     if( nRealWeight <= (int)WEIGHT_MEDIUM && nWeight > (int)WEIGHT_MEDIUM )
     828             :     {
     829           0 :         bArtBold = true;
     830             :     }
     831             : 
     832             :     // also set the serverside font for layouting
     833        1088 :     m_bFontVertical = pEntry->mbVertical;
     834        1088 :     if( pEntry->mpFontData )
     835             :     {
     836             :         // requesting a font provided by builtin rasterizer
     837        1088 :         ServerFont* pServerFont = GlyphCache::GetInstance().CacheFont( *pEntry );
     838        1088 :         if( pServerFont != NULL )
     839             :         {
     840        1088 :             if( pServerFont->TestFont() )
     841        1088 :                 m_pServerFont[ nFallbackLevel ] = pServerFont;
     842             :             else
     843           0 :                 GlyphCache::GetInstance().UncacheFont( *pServerFont );
     844             :         }
     845             :     }
     846             : 
     847             :     // set the printer font
     848             :     return m_pPrinterGfx->SetFont( nID,
     849             :                                    pEntry->mnHeight,
     850             :                                    pEntry->mnWidth,
     851             :                                    pEntry->mnOrientation,
     852             :                                    pEntry->mbVertical,
     853             :                                    bArtItalic,
     854             :                                    bArtBold
     855        1088 :                                    );
     856             : }
     857             : 
     858           0 : void GenPspGraphics::SetTextColor( SalColor nSalColor )
     859             : {
     860           0 :     psp::PrinterColor aColor (SALCOLOR_RED   (nSalColor),
     861           0 :                               SALCOLOR_GREEN (nSalColor),
     862           0 :                               SALCOLOR_BLUE  (nSalColor));
     863           0 :     m_pPrinterGfx->SetTextColor (aColor);
     864           0 : }
     865             : 
     866           0 : bool GenPspGraphics::AddTempDevFont( PhysicalFontCollection*, const OUString&,const OUString& )
     867             : {
     868           0 :     return false;
     869             : }
     870             : 
     871         780 : void GenPspGraphics::GetDevFontList( PhysicalFontCollection *pFontCollection )
     872             : {
     873         780 :     ::std::list< psp::fontID > aList;
     874         780 :     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
     875         780 :     rMgr.getFontList( aList );
     876             : 
     877         780 :     ::std::list< psp::fontID >::iterator it;
     878        1560 :     psp::FastPrintFontInfo aInfo;
     879      119340 :     for (it = aList.begin(); it != aList.end(); ++it)
     880      118560 :         if (rMgr.getFontFastInfo (*it, aInfo))
     881      118560 :             AnnounceFonts( pFontCollection, aInfo );
     882             : 
     883             :     // register platform specific font substitutions if available
     884        1560 :     SalGenericInstance::RegisterFontSubstitutors( pFontCollection );
     885         780 : }
     886             : 
     887           0 : void GenPspGraphics::ClearDevFontCache()
     888             : {
     889           0 :     GlyphCache::GetInstance().ClearFontCache();
     890           0 : }
     891             : 
     892         485 : void GenPspGraphics::GetFontMetric( ImplFontMetricData *pMetric, int )
     893             : {
     894         485 :     const psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
     895         485 :     psp::PrintFontInfo aInfo;
     896             : 
     897         485 :     if (rMgr.getFontInfo (m_pPrinterGfx->GetFontID(), aInfo))
     898             :     {
     899         485 :         ImplDevFontAttributes aDFA = Info2DevFontAttributes( aInfo );
     900         485 :         static_cast<ImplFontAttributes&>(*pMetric) = aDFA;
     901         485 :         pMetric->mbDevice       = aDFA.mbDevice;
     902         485 :         pMetric->mbScalableFont = true;
     903             : 
     904         485 :         pMetric->mnOrientation  = m_pPrinterGfx->GetFontAngle();
     905         485 :         pMetric->mnSlant        = 0;
     906             : 
     907         485 :         sal_Int32 nTextHeight   = m_pPrinterGfx->GetFontHeight();
     908         485 :         sal_Int32 nTextWidth    = m_pPrinterGfx->GetFontWidth();
     909         485 :         if( ! nTextWidth )
     910         485 :             nTextWidth = nTextHeight;
     911             : 
     912         485 :         pMetric->mnWidth        = nTextWidth;
     913         485 :         pMetric->mnAscent       = ( aInfo.m_nAscend * nTextHeight + 500 ) / 1000;
     914         485 :         pMetric->mnDescent      = ( aInfo.m_nDescend * nTextHeight + 500 ) / 1000;
     915         485 :         pMetric->mnIntLeading   = ( aInfo.m_nLeading * nTextHeight + 500 ) / 1000;
     916         485 :         pMetric->mnExtLeading   = 0;
     917         485 :     }
     918         485 : }
     919             : 
     920           0 : bool GenPspGraphics::GetGlyphBoundRect( sal_GlyphId aGlyphId, Rectangle& rRect )
     921             : {
     922           0 :     const int nLevel = aGlyphId >> GF_FONTSHIFT;
     923           0 :     if( nLevel >= MAX_FALLBACK )
     924           0 :         return false;
     925             : 
     926           0 :     ServerFont* pSF = m_pServerFont[ nLevel ];
     927           0 :     if( !pSF )
     928           0 :         return false;
     929             : 
     930           0 :     aGlyphId &= GF_IDXMASK;
     931           0 :     const GlyphMetric& rGM = pSF->GetGlyphMetric( aGlyphId );
     932           0 :     rRect = Rectangle( rGM.GetOffset(), rGM.GetSize() );
     933           0 :     return true;
     934             : }
     935             : 
     936           0 : bool GenPspGraphics::GetGlyphOutline( sal_GlyphId aGlyphId,
     937             :     ::basegfx::B2DPolyPolygon& rB2DPolyPoly )
     938             : {
     939           0 :     const int nLevel = aGlyphId >> GF_FONTSHIFT;
     940           0 :     if( nLevel >= MAX_FALLBACK )
     941           0 :         return false;
     942             : 
     943           0 :     ServerFont* pSF = m_pServerFont[ nLevel ];
     944           0 :     if( !pSF )
     945           0 :         return false;
     946             : 
     947           0 :     aGlyphId &= GF_IDXMASK;
     948           0 :     if( pSF->GetGlyphOutline( aGlyphId, rB2DPolyPoly ) )
     949           0 :         return true;
     950             : 
     951           0 :     return false;
     952             : }
     953             : 
     954        6163 : SalLayout* GenPspGraphics::GetTextLayout( ImplLayoutArgs& rArgs, int nFallbackLevel )
     955             : {
     956             :     // workaround for printers not handling glyph indexing for non-TT fonts
     957        6163 :     int nFontId = m_pPrinterGfx->GetFontID();
     958        6163 :     if( psp::fonttype::TrueType != psp::PrintFontManager::get().getFontType( nFontId ) )
     959          90 :         rArgs.mnFlags |= SAL_LAYOUT_DISABLE_GLYPH_PROCESSING;
     960        6073 :     else if( nFallbackLevel > 0 )
     961           0 :         rArgs.mnFlags &= ~SAL_LAYOUT_DISABLE_GLYPH_PROCESSING;
     962             : 
     963        6163 :     GenericSalLayout* pLayout = NULL;
     964             : 
     965        6163 :     if( m_pServerFont[ nFallbackLevel ]
     966        6163 :         && !(rArgs.mnFlags & SAL_LAYOUT_DISABLE_GLYPH_PROCESSING) )
     967             :     {
     968             : #if ENABLE_GRAPHITE
     969             :         // Is this a Graphite font?
     970       12146 :         if (GraphiteServerFontLayout::IsGraphiteEnabledFont(*m_pServerFont[nFallbackLevel]))
     971             :         {
     972           0 :             pLayout = new GraphiteServerFontLayout(*m_pServerFont[nFallbackLevel]);
     973             :         }
     974             :         else
     975             : #endif
     976        6073 :             pLayout = new PspServerFontLayout( *m_pPrinterGfx, *m_pServerFont[nFallbackLevel], rArgs );
     977             :     }
     978             :     else
     979          90 :         pLayout = new PspFontLayout( *m_pPrinterGfx );
     980             : 
     981        6163 :     return pLayout;
     982             : }
     983             : 
     984           0 : bool GenPspGraphics::CreateFontSubset(
     985             :                                    const OUString& rToFile,
     986             :                                    const PhysicalFontFace* pFont,
     987             :                                    sal_GlyphId* pGlyphIds,
     988             :                                    sal_uInt8* pEncoding,
     989             :                                    sal_Int32* pWidths,
     990             :                                    int nGlyphCount,
     991             :                                    FontSubsetInfo& rInfo
     992             :                                    )
     993             : {
     994             :     // in this context the pFont->GetFontId() is a valid PSP
     995             :     // font since they are the only ones left after the PDF
     996             :     // export has filtered its list of subsettable fonts (for
     997             :     // which this method was created). The correct way would
     998             :     // be to have the GlyphCache search for the PhysicalFontFace pFont
     999           0 :     psp::fontID aFont = pFont->GetFontId();
    1000             : 
    1001           0 :     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
    1002             :     bool bSuccess = rMgr.createFontSubset( rInfo,
    1003             :                                  aFont,
    1004             :                                  rToFile,
    1005             :                                  pGlyphIds,
    1006             :                                  pEncoding,
    1007             :                                  pWidths,
    1008           0 :                                  nGlyphCount );
    1009           0 :     return bSuccess;
    1010             : }
    1011             : 
    1012           0 : const Ucs2SIntMap* GenPspGraphics::GetFontEncodingVector( const PhysicalFontFace* pFont, const Ucs2OStrMap** pNonEncoded )
    1013             : {
    1014             :     // in this context the pFont->GetFontId() is a valid PSP
    1015             :     // font since they are the only ones left after the PDF
    1016             :     // export has filtered its list of subsettable fonts (for
    1017             :     // which this method was created). The correct way would
    1018             :     // be to have the GlyphCache search for the PhysicalFontFace pFont
    1019           0 :     psp::fontID aFont = pFont->GetFontId();
    1020           0 :     return GenPspGraphics::DoGetFontEncodingVector( aFont, pNonEncoded );
    1021             : }
    1022             : 
    1023           0 : void GenPspGraphics::GetGlyphWidths( const PhysicalFontFace* pFont,
    1024             :                                   bool bVertical,
    1025             :                                   Int32Vector& rWidths,
    1026             :                                   Ucs2UIntMap& rUnicodeEnc )
    1027             : {
    1028             :     // in this context the pFont->GetFontId() is a valid PSP
    1029             :     // font since they are the only ones left after the PDF
    1030             :     // export has filtered its list of subsettable fonts (for
    1031             :     // which this method was created). The correct way would
    1032             :     // be to have the GlyphCache search for the PhysicalFontFace pFont
    1033           0 :     psp::fontID aFont = pFont->GetFontId();
    1034           0 :     GenPspGraphics::DoGetGlyphWidths( aFont, bVertical, rWidths, rUnicodeEnc );
    1035           0 : }
    1036             : 
    1037           0 : const Ucs2SIntMap* GenPspGraphics::DoGetFontEncodingVector( fontID aFont, const Ucs2OStrMap** pNonEncoded )
    1038             : {
    1039           0 :     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
    1040             : 
    1041           0 :     psp::PrintFontInfo aFontInfo;
    1042           0 :     if( ! rMgr.getFontInfo( aFont, aFontInfo ) )
    1043             :     {
    1044           0 :         if( pNonEncoded )
    1045           0 :             *pNonEncoded = NULL;
    1046           0 :         return NULL;
    1047             :     }
    1048             : 
    1049           0 :     return rMgr.getEncodingMap( aFont, pNonEncoded );
    1050             : }
    1051             : 
    1052           0 : void GenPspGraphics::DoGetGlyphWidths( psp::fontID aFont,
    1053             :                                     bool bVertical,
    1054             :                                     Int32Vector& rWidths,
    1055             :                                     Ucs2UIntMap& rUnicodeEnc )
    1056             : {
    1057           0 :     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
    1058           0 :     rMgr.getGlyphWidths( aFont, bVertical, rWidths, rUnicodeEnc );
    1059           0 : }
    1060             : 
    1061      166469 : ImplDevFontAttributes GenPspGraphics::Info2DevFontAttributes( const psp::FastPrintFontInfo& rInfo )
    1062             : {
    1063      166469 :     ImplDevFontAttributes aDFA;
    1064      166469 :     aDFA.SetFamilyName( rInfo.m_aFamilyName );
    1065      166469 :     aDFA.SetStyleName( rInfo.m_aStyleName );
    1066      166469 :     aDFA.SetFamilyType( rInfo.m_eFamilyStyle );
    1067      166469 :     aDFA.SetWeight( rInfo.m_eWeight );
    1068      166469 :     aDFA.SetItalic( rInfo.m_eItalic );
    1069      166469 :     aDFA.SetWidthType( rInfo.m_eWidth );
    1070      166469 :     aDFA.SetPitch( rInfo.m_ePitch );
    1071      166469 :     aDFA.SetSymbolFlag( (rInfo.m_aEncoding == RTL_TEXTENCODING_SYMBOL) );
    1072      166469 :     aDFA.mbSubsettable  = rInfo.m_bSubsettable;
    1073      166469 :     aDFA.mbEmbeddable   = rInfo.m_bEmbeddable;
    1074             : 
    1075      166469 :     switch( rInfo.m_eType )
    1076             :     {
    1077             :         case psp::fonttype::TrueType:
    1078      115139 :             aDFA.mnQuality       = 512;
    1079      115139 :             aDFA.mbDevice        = false;
    1080      115139 :             break;
    1081             :         case psp::fonttype::Type1:
    1082       51330 :             aDFA.mnQuality       = 0;
    1083       51330 :             aDFA.mbDevice        = false;
    1084       51330 :             break;
    1085             :         default:
    1086           0 :             aDFA.mnQuality       = 0;
    1087           0 :             aDFA.mbDevice        = false;
    1088           0 :             break;
    1089             :     }
    1090             : 
    1091      166469 :     aDFA.mbOrientation   = true;
    1092             : 
    1093             :     // add font family name aliases
    1094      166469 :     ::std::list< OUString >::const_iterator it = rInfo.m_aAliases.begin();
    1095      166469 :     bool bHasMapNames = false;
    1096      166469 :     for(; it != rInfo.m_aAliases.end(); ++it )
    1097             :     {
    1098           0 :         if( bHasMapNames )
    1099           0 :             aDFA.maMapNames += OUString(';');
    1100           0 :         aDFA.maMapNames += *it;
    1101           0 :         bHasMapNames = true;
    1102             :     }
    1103             : 
    1104             : #if OSL_DEBUG_LEVEL > 2
    1105             :     if( bHasMapNames )
    1106             :     {
    1107             :         OString aOrigName(OUStringToOString(aDFA.GetFamilyName(), osl_getThreadTextEncoding()));
    1108             :         OString aAliasNames(OUStringToOString(aDFA.GetAliasNames(), osl_getThreadTextEncoding()));
    1109             :         SAL_INFO( "vcl.fonts", "using alias names " << aAliasNames.getStr() << " for font family " << aOrigName.getStr() );
    1110             :     }
    1111             : #endif
    1112             : 
    1113      166469 :     return aDFA;
    1114             : }
    1115             : 
    1116             : namespace vcl
    1117             : {
    1118         378 :     const char* getLangBoost()
    1119             :     {
    1120             :         const char* pLangBoost;
    1121         378 :         const LanguageType eLang = Application::GetSettings().GetUILanguageTag().getLanguageType();
    1122         378 :         if (eLang == LANGUAGE_JAPANESE)
    1123           0 :             pLangBoost = "jan";
    1124         378 :         else if (MsLangId::isKorean(eLang))
    1125           0 :             pLangBoost = "kor";
    1126         378 :         else if (MsLangId::isSimplifiedChinese(eLang))
    1127           0 :             pLangBoost = "zhs";
    1128         378 :         else if (MsLangId::isTraditionalChinese(eLang))
    1129           0 :             pLangBoost = "zht";
    1130             :         else
    1131         378 :             pLangBoost = NULL;
    1132         378 :         return pLangBoost;
    1133             :     }
    1134             : }
    1135             : 
    1136      118560 : void GenPspGraphics::AnnounceFonts( PhysicalFontCollection* pFontCollection, const psp::FastPrintFontInfo& aInfo )
    1137             : {
    1138      118560 :     int nQuality = 0;
    1139             : 
    1140      118560 :     if( aInfo.m_eType == psp::fonttype::TrueType )
    1141             :     {
    1142             :         // asian type 1 fonts are not known
    1143       81900 :         psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
    1144       81900 :         OString aFileName( rMgr.getFontFileSysPath( aInfo.m_nID ) );
    1145       81900 :         int nPos = aFileName.lastIndexOf( '_' );
    1146       81900 :         if( nPos == -1 || aFileName[nPos+1] == '.' )
    1147       70980 :             nQuality += 5;
    1148             :         else
    1149             :         {
    1150             :             static const char* pLangBoost = NULL;
    1151             :             static bool bOnce = true;
    1152       10920 :             if( bOnce )
    1153             :             {
    1154          74 :                 bOnce = false;
    1155          74 :                 pLangBoost = vcl::getLangBoost();
    1156             :             }
    1157             : 
    1158       10920 :             if( pLangBoost )
    1159           0 :                 if( aFileName.copy( nPos+1, 3 ).equalsIgnoreAsciiCase( pLangBoost ) )
    1160           0 :                     nQuality += 10;
    1161       81900 :         }
    1162             :     }
    1163             : 
    1164      118560 :     ImplPspFontData* pFD = new ImplPspFontData( aInfo );
    1165      118560 :     pFD->mnQuality += nQuality;
    1166      118560 :     pFontCollection->Add( pFD );
    1167      118560 : }
    1168             : 
    1169           0 : bool GenPspGraphics::drawAlphaBitmap( const SalTwoRect&,
    1170             :                                    const SalBitmap&,
    1171             :                                    const SalBitmap& )
    1172             : {
    1173           0 :     return false;
    1174             : }
    1175             : 
    1176           0 : bool GenPspGraphics::drawTransformedBitmap(
    1177             :     const basegfx::B2DPoint& rNull,
    1178             :     const basegfx::B2DPoint& rX,
    1179             :     const basegfx::B2DPoint& rY,
    1180             :     const SalBitmap& rSourceBitmap,
    1181             :     const SalBitmap* pAlphaBitmap)
    1182             : {
    1183             :     // here direct support for transformed bitmaps can be impemented
    1184             :     (void)rNull; (void)rX; (void)rY; (void)rSourceBitmap; (void)pAlphaBitmap;
    1185           0 :     return false;
    1186             : }
    1187             : 
    1188           0 : bool GenPspGraphics::drawAlphaRect( long, long, long, long, sal_uInt8 )
    1189             : {
    1190           0 :     return false;
    1191             : }
    1192             : 
    1193           0 : SystemGraphicsData GenPspGraphics::GetGraphicsData() const
    1194             : {
    1195           0 :     return SystemGraphicsData();
    1196             : }
    1197             : 
    1198           0 : SystemFontData GenPspGraphics::GetSysFontData( int /* nFallbacklevel */ ) const
    1199             : {
    1200           0 :     return SystemFontData();
    1201             : }
    1202             : 
    1203           0 : bool GenPspGraphics::supportsOperation( OutDevSupportType ) const
    1204             : {
    1205           0 :     return false;
    1206             : }
    1207             : 
    1208           0 : void GenPspGraphics::DoFreeEmbedFontData( const void* pData, long nLen )
    1209             : {
    1210             : #if defined( UNX )
    1211           0 :     if( pData )
    1212           0 :         munmap( (char*)pData, nLen );
    1213             : #else
    1214             :     (void)nLen;
    1215             :     rtl_freeMemory( (void *)pData );
    1216             : #endif
    1217           0 : }
    1218             : 
    1219           0 : const void* GenPspGraphics::DoGetEmbedFontData( psp::fontID aFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, FontSubsetInfo& rInfo, long* pDataLen )
    1220             : {
    1221             : 
    1222           0 :     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
    1223             : 
    1224           0 :     psp::PrintFontInfo aFontInfo;
    1225           0 :     if( ! rMgr.getFontInfo( aFont, aFontInfo ) )
    1226           0 :         return NULL;
    1227             : 
    1228             :     // fill in font info
    1229           0 :     rInfo.m_nAscent     = aFontInfo.m_nAscend;
    1230           0 :     rInfo.m_nDescent    = aFontInfo.m_nDescend;
    1231           0 :     rInfo.m_aPSName     = rMgr.getPSName( aFont );
    1232             : 
    1233             :     int xMin, yMin, xMax, yMax;
    1234           0 :     rMgr.getFontBoundingBox( aFont, xMin, yMin, xMax, yMax );
    1235             : 
    1236           0 :     psp::CharacterMetric aMetrics[256];
    1237             :     sal_Ucs aUnicodes[256];
    1238           0 :     if( aFontInfo.m_aEncoding == RTL_TEXTENCODING_SYMBOL && aFontInfo.m_eType == psp::fonttype::Type1 )
    1239             :     {
    1240           0 :         for( int i = 0; i < 256; i++ )
    1241           0 :             aUnicodes[i] = pUnicodes[i] < 0x0100 ? pUnicodes[i] + 0xf000 : pUnicodes[i];
    1242           0 :         pUnicodes = aUnicodes;
    1243             :     }
    1244           0 :     if( ! rMgr.getMetrics( aFont, pUnicodes, 256, aMetrics ) )
    1245           0 :         return NULL;
    1246             : 
    1247           0 :     OString aSysPath = rMgr.getFontFileSysPath( aFont );
    1248             : 
    1249             : #if defined( UNX )
    1250             :     struct stat aStat;
    1251           0 :     if( stat( aSysPath.getStr(), &aStat ) )
    1252           0 :         return NULL;
    1253           0 :     int fd = open( aSysPath.getStr(), O_RDONLY );
    1254           0 :     if( fd < 0 )
    1255           0 :         return NULL;
    1256           0 :     void* pFile = mmap( NULL, aStat.st_size, PROT_READ, MAP_SHARED, fd, 0 );
    1257           0 :     close( fd );
    1258           0 :     if( pFile == MAP_FAILED )
    1259           0 :         return NULL;
    1260           0 :     *pDataLen = aStat.st_size;
    1261             : #else
    1262             :     // FIXME: test me ! ...
    1263             :     OUString aURL;
    1264             :     if( osl::File::getFileURLFromSystemPath( OStringToOUString( aSysPath, osl_getThreadTextEncoding() ), aURL ) != osl::File::E_None )
    1265             :         return NULL;
    1266             :     osl::File aFile( aURL );
    1267             :     if( aFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_NoLock ) != osl::File::E_None )
    1268             :         return NULL;
    1269             : 
    1270             :     osl::DirectoryItem aItem;
    1271             :     osl::DirectoryItem::get( aURL, aItem );
    1272             :     osl::FileStatus aFileStatus( osl_FileStatus_Mask_FileSize );
    1273             :     aItem.getFileStatus( aFileStatus );
    1274             : 
    1275             :     void *pFile = rtl_allocateMemory( aFileStatus.getFileSize() );
    1276             :     sal_uInt64 nRead = 0;
    1277             :     aFile.read( pFile, aFileStatus.getFileSize(), nRead );
    1278             :     *pDataLen = (long) nRead;
    1279             : #endif
    1280             : 
    1281           0 :     rInfo.m_aFontBBox   = Rectangle( Point( xMin, yMin ), Size( xMax-xMin, yMax-yMin ) );
    1282           0 :     rInfo.m_nCapHeight  = yMax; // Well ...
    1283             : 
    1284           0 :     for( int i = 0; i < 256; i++ )
    1285           0 :         pWidths[i] = (aMetrics[i].width > 0 ? aMetrics[i].width : 0);
    1286             : 
    1287           0 :     switch( aFontInfo.m_eType )
    1288             :     {
    1289             :         case psp::fonttype::TrueType:
    1290           0 :             rInfo.m_nFontType = FontSubsetInfo::SFNT_TTF;
    1291           0 :             break;
    1292             :         case psp::fonttype::Type1: {
    1293           0 :             const bool bPFA = ((*(unsigned char*)pFile) < 0x80);
    1294           0 :             rInfo.m_nFontType = bPFA ? FontSubsetInfo::TYPE1_PFA : FontSubsetInfo::TYPE1_PFB;
    1295             :             }
    1296           0 :             break;
    1297             :         default:
    1298           0 :             DoFreeEmbedFontData( pFile, *pDataLen );
    1299           0 :             return NULL;
    1300             :     }
    1301             : 
    1302           0 :     return pFile;
    1303             : }
    1304             : 
    1305           0 : void GenPspGraphics::FreeEmbedFontData( const void* pData, long nLen )
    1306             : {
    1307           0 :     DoFreeEmbedFontData( pData, nLen );
    1308           0 : }
    1309             : 
    1310           0 : const void* GenPspGraphics::GetEmbedFontData( const PhysicalFontFace* pFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, FontSubsetInfo& rInfo, long* pDataLen )
    1311             : {
    1312             :     // in this context the pFont->GetFontId() is a valid PSP
    1313             :     // font since they are the only ones left after the PDF
    1314             :     // export has filtered its list of subsettable fonts (for
    1315             :     // which this method was created). The correct way would
    1316             :     // be to have the GlyphCache search for the PhysicalFontFace pFont
    1317           0 :     psp::fontID aFont = pFont->GetFontId();
    1318           0 :     return DoGetEmbedFontData( aFont, pUnicodes, pWidths, rInfo, pDataLen );
    1319        1233 : }
    1320             : 
    1321             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10