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

Generated by: LCOV version 1.11