xref: /aoo42x/main/vcl/unx/generic/gdi/pspgraphics.cxx (revision 54ae6a37)
1c82f2877SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3c82f2877SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4c82f2877SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5c82f2877SAndrew Rist  * distributed with this work for additional information
6c82f2877SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7c82f2877SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8c82f2877SAndrew Rist  * "License"); you may not use this file except in compliance
9c82f2877SAndrew Rist  * with the License.  You may obtain a copy of the License at
10c82f2877SAndrew Rist  *
11c82f2877SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12c82f2877SAndrew Rist  *
13c82f2877SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14c82f2877SAndrew Rist  * software distributed under the License is distributed on an
15c82f2877SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16c82f2877SAndrew Rist  * KIND, either express or implied.  See the License for the
17c82f2877SAndrew Rist  * specific language governing permissions and limitations
18c82f2877SAndrew Rist  * under the License.
19c82f2877SAndrew Rist  *
20c82f2877SAndrew Rist  *************************************************************/
21c82f2877SAndrew Rist 
22c82f2877SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <stdlib.h>
28cdf0e10cSrcweir #include <unistd.h>
29cdf0e10cSrcweir #include <fcntl.h>
30cdf0e10cSrcweir #include <sys/mman.h>
31cdf0e10cSrcweir #include <sys/stat.h>
32cdf0e10cSrcweir #include <sys/types.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "unx/pspgraphics.h"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "vcl/jobdata.hxx"
37cdf0e10cSrcweir #include "vcl/printerinfomanager.hxx"
38cdf0e10cSrcweir #include "vcl/bmpacc.hxx"
39cdf0e10cSrcweir #include "vcl/svapp.hxx"
40cdf0e10cSrcweir #include "vcl/sysdata.hxx"
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include "printergfx.hxx"
43cdf0e10cSrcweir #include "salbmp.hxx"
44cdf0e10cSrcweir #include "glyphcache.hxx"
45cdf0e10cSrcweir #include "impfont.hxx"
46cdf0e10cSrcweir #include "outfont.hxx"
47cdf0e10cSrcweir #include "fontsubset.hxx"
48cdf0e10cSrcweir #include "salprn.hxx"
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #ifdef ENABLE_GRAPHITE
51cdf0e10cSrcweir #include <graphite_layout.hxx>
52cdf0e10cSrcweir #include <graphite_serverfont.hxx>
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir 
55cdf0e10cSrcweir using namespace psp;
56cdf0e10cSrcweir using namespace rtl;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir // ----- Implementation of PrinterBmp by means of SalBitmap/BitmapBuffer ---------------
59cdf0e10cSrcweir 
60cdf0e10cSrcweir class SalPrinterBmp : public psp::PrinterBmp
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	private:
63cdf0e10cSrcweir     BitmapBuffer*		mpBmpBuffer;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     FncGetPixel			mpFncGetPixel;
66cdf0e10cSrcweir     Scanline			mpScanAccess;
67cdf0e10cSrcweir     sal_PtrDiff			mnScanOffset;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     sal_uInt32			ColorOf (BitmapColor& rColor) const;
70cdf0e10cSrcweir     sal_uInt8			GrayOf  (BitmapColor& rColor) const;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     SalPrinterBmp ();
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	public:
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 							SalPrinterBmp (BitmapBuffer* pBitmap);
77cdf0e10cSrcweir 		virtual				~SalPrinterBmp ();
78cdf0e10cSrcweir 		virtual sal_uInt32	GetPaletteColor (sal_uInt32 nIdx) const;
79cdf0e10cSrcweir 		virtual sal_uInt32	GetPaletteEntryCount () const;
80cdf0e10cSrcweir 		virtual sal_uInt32	GetPixelRGB  (sal_uInt32 nRow, sal_uInt32 nColumn) const;
81cdf0e10cSrcweir 		virtual sal_uInt8	GetPixelGray (sal_uInt32 nRow, sal_uInt32 nColumn) const;
82cdf0e10cSrcweir 		virtual sal_uInt8	GetPixelIdx  (sal_uInt32 nRow, sal_uInt32 nColumn) const;
83cdf0e10cSrcweir 		virtual sal_uInt32	GetWidth () const;
84cdf0e10cSrcweir 		virtual sal_uInt32	GetHeight() const;
85cdf0e10cSrcweir 		virtual sal_uInt32	GetDepth ()	const;
86cdf0e10cSrcweir };
87cdf0e10cSrcweir 
SalPrinterBmp(BitmapBuffer * pBuffer)88cdf0e10cSrcweir SalPrinterBmp::SalPrinterBmp (BitmapBuffer* pBuffer) :
89cdf0e10cSrcweir 		mpBmpBuffer (pBuffer)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 	DBG_ASSERT (mpBmpBuffer, "SalPrinterBmp::SalPrinterBmp () can't acquire Bitmap");
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	// calibrate scanline buffer
94cdf0e10cSrcweir 	if( BMP_SCANLINE_ADJUSTMENT( mpBmpBuffer->mnFormat ) == BMP_FORMAT_TOP_DOWN )
95cdf0e10cSrcweir 	{
96cdf0e10cSrcweir 		mpScanAccess = mpBmpBuffer->mpBits;
97cdf0e10cSrcweir 		mnScanOffset = mpBmpBuffer->mnScanlineSize;
98cdf0e10cSrcweir 	}
99cdf0e10cSrcweir 	else
100cdf0e10cSrcweir 	{
101cdf0e10cSrcweir 		mpScanAccess = mpBmpBuffer->mpBits
102cdf0e10cSrcweir 					   + (mpBmpBuffer->mnHeight - 1) * mpBmpBuffer->mnScanlineSize;
103cdf0e10cSrcweir 		mnScanOffset = - mpBmpBuffer->mnScanlineSize;
104cdf0e10cSrcweir 	}
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	// request read access to the pixels
107cdf0e10cSrcweir 	switch( BMP_SCANLINE_FORMAT( mpBmpBuffer->mnFormat ) )
108cdf0e10cSrcweir 	{
109cdf0e10cSrcweir 		case BMP_FORMAT_1BIT_MSB_PAL:
110cdf0e10cSrcweir 			mpFncGetPixel = BitmapReadAccess::GetPixelFor_1BIT_MSB_PAL;	 break;
111cdf0e10cSrcweir 		case BMP_FORMAT_1BIT_LSB_PAL:
112cdf0e10cSrcweir 			mpFncGetPixel = BitmapReadAccess::GetPixelFor_1BIT_LSB_PAL;	 break;
113cdf0e10cSrcweir 		case BMP_FORMAT_4BIT_MSN_PAL:
114cdf0e10cSrcweir 			mpFncGetPixel = BitmapReadAccess::GetPixelFor_4BIT_MSN_PAL;	 break;
115cdf0e10cSrcweir 		case BMP_FORMAT_4BIT_LSN_PAL:
116cdf0e10cSrcweir 			mpFncGetPixel = BitmapReadAccess::GetPixelFor_4BIT_LSN_PAL;	 break;
117cdf0e10cSrcweir 		case BMP_FORMAT_8BIT_PAL:
118cdf0e10cSrcweir 			mpFncGetPixel = BitmapReadAccess::GetPixelFor_8BIT_PAL; 	 break;
119cdf0e10cSrcweir 		case BMP_FORMAT_8BIT_TC_MASK:
120cdf0e10cSrcweir 			mpFncGetPixel = BitmapReadAccess::GetPixelFor_8BIT_TC_MASK;	 break;
121cdf0e10cSrcweir 		case BMP_FORMAT_16BIT_TC_MSB_MASK:
122cdf0e10cSrcweir 			mpFncGetPixel = BitmapReadAccess::GetPixelFor_16BIT_TC_MSB_MASK; break;
123cdf0e10cSrcweir 		case BMP_FORMAT_16BIT_TC_LSB_MASK:
124cdf0e10cSrcweir 			mpFncGetPixel = BitmapReadAccess::GetPixelFor_16BIT_TC_LSB_MASK; break;
125cdf0e10cSrcweir 		case BMP_FORMAT_24BIT_TC_BGR:
126cdf0e10cSrcweir 			mpFncGetPixel = BitmapReadAccess::GetPixelFor_24BIT_TC_BGR;  break;
127cdf0e10cSrcweir 		case BMP_FORMAT_24BIT_TC_RGB:
128cdf0e10cSrcweir 			mpFncGetPixel = BitmapReadAccess::GetPixelFor_24BIT_TC_RGB;  break;
129cdf0e10cSrcweir 		case BMP_FORMAT_24BIT_TC_MASK:
130cdf0e10cSrcweir 			mpFncGetPixel = BitmapReadAccess::GetPixelFor_24BIT_TC_MASK; break;
131cdf0e10cSrcweir 		case BMP_FORMAT_32BIT_TC_ABGR:
132cdf0e10cSrcweir 			mpFncGetPixel = BitmapReadAccess::GetPixelFor_32BIT_TC_ABGR; break;
133cdf0e10cSrcweir 		case BMP_FORMAT_32BIT_TC_ARGB:
134cdf0e10cSrcweir 			mpFncGetPixel = BitmapReadAccess::GetPixelFor_32BIT_TC_ARGB; break;
135cdf0e10cSrcweir 		case BMP_FORMAT_32BIT_TC_BGRA:
136cdf0e10cSrcweir 			mpFncGetPixel = BitmapReadAccess::GetPixelFor_32BIT_TC_BGRA; break;
137cdf0e10cSrcweir 		case BMP_FORMAT_32BIT_TC_RGBA:
138cdf0e10cSrcweir 			mpFncGetPixel = BitmapReadAccess::GetPixelFor_32BIT_TC_RGBA; break;
139cdf0e10cSrcweir 		case BMP_FORMAT_32BIT_TC_MASK:
140cdf0e10cSrcweir 			mpFncGetPixel = BitmapReadAccess::GetPixelFor_32BIT_TC_MASK; break;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 		default:
143cdf0e10cSrcweir 			DBG_ERROR("Error: SalPrinterBmp::SalPrinterBmp() unknown bitmap format");
144cdf0e10cSrcweir 		break;
145cdf0e10cSrcweir 	}
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
~SalPrinterBmp()148cdf0e10cSrcweir SalPrinterBmp::~SalPrinterBmp ()
149cdf0e10cSrcweir {
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir sal_uInt32
GetWidth() const153cdf0e10cSrcweir SalPrinterBmp::GetWidth () const
154cdf0e10cSrcweir {
155cdf0e10cSrcweir 	return mpBmpBuffer->mnWidth;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir sal_uInt32
GetHeight() const159cdf0e10cSrcweir SalPrinterBmp::GetHeight () const
160cdf0e10cSrcweir {
161cdf0e10cSrcweir 	return mpBmpBuffer->mnHeight;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir sal_uInt32
GetDepth() const165cdf0e10cSrcweir SalPrinterBmp::GetDepth () const
166cdf0e10cSrcweir {
167cdf0e10cSrcweir 	sal_uInt32 nDepth;
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 	switch (mpBmpBuffer->mnBitCount)
170cdf0e10cSrcweir 	{
171cdf0e10cSrcweir 		case 1:
172cdf0e10cSrcweir 			nDepth = 1;
173cdf0e10cSrcweir 			break;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 		case 4:
176cdf0e10cSrcweir 		case 8:
177cdf0e10cSrcweir 			nDepth = 8;
178cdf0e10cSrcweir 			break;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 		case 16:
181cdf0e10cSrcweir 		case 24:
182cdf0e10cSrcweir 		case 32:
183cdf0e10cSrcweir 			nDepth = 24;
184cdf0e10cSrcweir 			break;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 		default:
187cdf0e10cSrcweir 			nDepth = 1;
188cdf0e10cSrcweir 			DBG_ERROR ("Error: unsupported bitmap depth in SalPrinterBmp::GetDepth()");
189cdf0e10cSrcweir 			break;
190cdf0e10cSrcweir 	}
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 	return nDepth;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir sal_uInt32
ColorOf(BitmapColor & rColor) const196cdf0e10cSrcweir SalPrinterBmp::ColorOf (BitmapColor& rColor) const
197cdf0e10cSrcweir {
198cdf0e10cSrcweir 	if (rColor.IsIndex())
199cdf0e10cSrcweir 		return ColorOf (mpBmpBuffer->maPalette[rColor.GetIndex()]);
200cdf0e10cSrcweir 	else
201cdf0e10cSrcweir 		return 	  ((rColor.GetBlue()) 		 & 0x000000ff)
202cdf0e10cSrcweir 				| ((rColor.GetGreen() <<  8) & 0x0000ff00)
203cdf0e10cSrcweir 				| ((rColor.GetRed()   << 16) & 0x00ff0000);
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir sal_uInt8
GrayOf(BitmapColor & rColor) const207cdf0e10cSrcweir SalPrinterBmp::GrayOf (BitmapColor& rColor) const
208cdf0e10cSrcweir {
209cdf0e10cSrcweir 	if (rColor.IsIndex())
210cdf0e10cSrcweir 		return GrayOf (mpBmpBuffer->maPalette[rColor.GetIndex()]);
211cdf0e10cSrcweir 	else
212cdf0e10cSrcweir 		return (  rColor.GetBlue()  *  28UL
213cdf0e10cSrcweir 				+ rColor.GetGreen() * 151UL
214cdf0e10cSrcweir 				+ rColor.GetRed()   *  77UL ) >> 8;
215cdf0e10cSrcweir }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir sal_uInt32
GetPaletteEntryCount() const218cdf0e10cSrcweir SalPrinterBmp::GetPaletteEntryCount () const
219cdf0e10cSrcweir {
220cdf0e10cSrcweir 	return mpBmpBuffer->maPalette.GetEntryCount ();
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir sal_uInt32
GetPaletteColor(sal_uInt32 nIdx) const224cdf0e10cSrcweir SalPrinterBmp::GetPaletteColor (sal_uInt32 nIdx) const
225cdf0e10cSrcweir {
226cdf0e10cSrcweir 	return ColorOf (mpBmpBuffer->maPalette[nIdx]);
227cdf0e10cSrcweir }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir sal_uInt32
GetPixelRGB(sal_uInt32 nRow,sal_uInt32 nColumn) const230cdf0e10cSrcweir SalPrinterBmp::GetPixelRGB (sal_uInt32 nRow, sal_uInt32 nColumn) const
231cdf0e10cSrcweir {
232cdf0e10cSrcweir 	Scanline pScan = mpScanAccess + nRow * mnScanOffset;
233cdf0e10cSrcweir 	BitmapColor aColor = mpFncGetPixel (pScan, nColumn, mpBmpBuffer->maColorMask);
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 	return ColorOf (aColor);
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir sal_uInt8
GetPixelGray(sal_uInt32 nRow,sal_uInt32 nColumn) const239cdf0e10cSrcweir SalPrinterBmp::GetPixelGray (sal_uInt32 nRow, sal_uInt32 nColumn) const
240cdf0e10cSrcweir {
241cdf0e10cSrcweir 	Scanline pScan = mpScanAccess + nRow * mnScanOffset;
242cdf0e10cSrcweir 	BitmapColor aColor = mpFncGetPixel (pScan, nColumn, mpBmpBuffer->maColorMask);
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 	return GrayOf (aColor);
245cdf0e10cSrcweir }
246cdf0e10cSrcweir 
247cdf0e10cSrcweir sal_uInt8
GetPixelIdx(sal_uInt32 nRow,sal_uInt32 nColumn) const248cdf0e10cSrcweir SalPrinterBmp::GetPixelIdx (sal_uInt32 nRow, sal_uInt32 nColumn) const
249cdf0e10cSrcweir {
250cdf0e10cSrcweir 	Scanline pScan = mpScanAccess + nRow * mnScanOffset;
251cdf0e10cSrcweir 	BitmapColor aColor = mpFncGetPixel (pScan, nColumn, mpBmpBuffer->maColorMask);
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 	if (aColor.IsIndex())
254cdf0e10cSrcweir 		return aColor.GetIndex();
255cdf0e10cSrcweir 	else
256cdf0e10cSrcweir 		return 0;
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir /*******************************************************
260cdf0e10cSrcweir  * PspGraphics                                         *
261cdf0e10cSrcweir  *******************************************************/
262cdf0e10cSrcweir 
~PspGraphics()263cdf0e10cSrcweir PspGraphics::~PspGraphics()
264cdf0e10cSrcweir {
265cdf0e10cSrcweir     ReleaseFonts();
266cdf0e10cSrcweir }
267cdf0e10cSrcweir 
GetResolution(sal_Int32 & rDPIX,sal_Int32 & rDPIY)268cdf0e10cSrcweir void PspGraphics::GetResolution( sal_Int32 &rDPIX, sal_Int32 &rDPIY )
269cdf0e10cSrcweir {
270cdf0e10cSrcweir 	if (m_pJobData != NULL)
271cdf0e10cSrcweir 	{
272cdf0e10cSrcweir 		int x = m_pJobData->m_aContext.getRenderResolution();
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 		rDPIX = x;
275cdf0e10cSrcweir 		rDPIY = x;
276cdf0e10cSrcweir 	}
277cdf0e10cSrcweir }
278cdf0e10cSrcweir 
GetBitCount()279cdf0e10cSrcweir sal_uInt16 PspGraphics::GetBitCount()
280cdf0e10cSrcweir {
281cdf0e10cSrcweir     return m_pPrinterGfx->GetBitCount();
282cdf0e10cSrcweir }
283cdf0e10cSrcweir 
GetGraphicsWidth() const284cdf0e10cSrcweir long PspGraphics::GetGraphicsWidth() const
285cdf0e10cSrcweir {
286cdf0e10cSrcweir     return 0;
287cdf0e10cSrcweir }
288cdf0e10cSrcweir 
ResetClipRegion()289cdf0e10cSrcweir void PspGraphics::ResetClipRegion()
290cdf0e10cSrcweir {
291cdf0e10cSrcweir     m_pPrinterGfx->ResetClipRegion();
292cdf0e10cSrcweir }
293cdf0e10cSrcweir 
setClipRegion(const Region & i_rClip)294cdf0e10cSrcweir bool PspGraphics::setClipRegion( const Region& i_rClip )
295cdf0e10cSrcweir {
296cdf0e10cSrcweir     // TODO: support polygonal clipregions here
297e6f63103SArmin Le Grand     RectangleVector aRectangles;
298e6f63103SArmin Le Grand     i_rClip.GetRegionRectangles(aRectangles);
299e6f63103SArmin Le Grand     m_pPrinterGfx->BeginSetClipRegion(aRectangles.size());
300cdf0e10cSrcweir 
301e6f63103SArmin Le Grand     for(RectangleVector::const_iterator aRectIter(aRectangles.begin()); aRectIter != aRectangles.end(); aRectIter++)
302cdf0e10cSrcweir     {
303e6f63103SArmin Le Grand         const long nW(aRectIter->GetWidth());
304e6f63103SArmin Le Grand 
305e6f63103SArmin Le Grand         if(nW)
306cdf0e10cSrcweir         {
307e6f63103SArmin Le Grand             const long nH(aRectIter->GetHeight());
308e6f63103SArmin Le Grand 
309e6f63103SArmin Le Grand             if(nH)
310e6f63103SArmin Le Grand             {
311e6f63103SArmin Le Grand                 m_pPrinterGfx->UnionClipRegion(
312e6f63103SArmin Le Grand                     aRectIter->Left(),
313e6f63103SArmin Le Grand                     aRectIter->Top(),
314e6f63103SArmin Le Grand                     nW,
315e6f63103SArmin Le Grand                     nH);
316e6f63103SArmin Le Grand             }
317cdf0e10cSrcweir         }
318cdf0e10cSrcweir     }
319e6f63103SArmin Le Grand 
320cdf0e10cSrcweir     m_pPrinterGfx->EndSetClipRegion();
321e6f63103SArmin Le Grand 
322e6f63103SArmin Le Grand     //m_pPrinterGfx->BeginSetClipRegion( i_rClip.GetRectCount() );
323e6f63103SArmin Le Grand     //
324e6f63103SArmin Le Grand     //ImplRegionInfo aInfo;
325e6f63103SArmin Le Grand     //long nX, nY, nW, nH;
326e6f63103SArmin Le Grand     //bool bRegionRect = i_rClip.ImplGetFirstRect(aInfo, nX, nY, nW, nH );
327e6f63103SArmin Le Grand     //while( bRegionRect )
328e6f63103SArmin Le Grand     //{
329e6f63103SArmin Le Grand     //    if ( nW && nH )
330e6f63103SArmin Le Grand     //    {
331e6f63103SArmin Le Grand     //        m_pPrinterGfx->UnionClipRegion( nX, nY, nW, nH );
332e6f63103SArmin Le Grand     //    }
333e6f63103SArmin Le Grand     //    bRegionRect = i_rClip.ImplGetNextRect( aInfo, nX, nY, nW, nH );
334e6f63103SArmin Le Grand     //}
335e6f63103SArmin Le Grand     //m_pPrinterGfx->EndSetClipRegion();
336cdf0e10cSrcweir     return true;
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
SetLineColor()339cdf0e10cSrcweir void PspGraphics::SetLineColor()
340cdf0e10cSrcweir {
341cdf0e10cSrcweir     m_pPrinterGfx->SetLineColor ();
342cdf0e10cSrcweir }
343cdf0e10cSrcweir 
SetLineColor(SalColor nSalColor)344cdf0e10cSrcweir void PspGraphics::SetLineColor( SalColor nSalColor )
345cdf0e10cSrcweir {
346cdf0e10cSrcweir     psp::PrinterColor aColor (SALCOLOR_RED   (nSalColor),
347cdf0e10cSrcweir                               SALCOLOR_GREEN (nSalColor),
348cdf0e10cSrcweir                               SALCOLOR_BLUE  (nSalColor));
349cdf0e10cSrcweir     m_pPrinterGfx->SetLineColor (aColor);
350cdf0e10cSrcweir }
351cdf0e10cSrcweir 
SetFillColor()352cdf0e10cSrcweir void PspGraphics::SetFillColor()
353cdf0e10cSrcweir {
354cdf0e10cSrcweir     m_pPrinterGfx->SetFillColor ();
355cdf0e10cSrcweir }
356cdf0e10cSrcweir 
SetFillColor(SalColor nSalColor)357cdf0e10cSrcweir void PspGraphics::SetFillColor( SalColor nSalColor )
358cdf0e10cSrcweir {
359cdf0e10cSrcweir     psp::PrinterColor aColor (SALCOLOR_RED   (nSalColor),
360cdf0e10cSrcweir                               SALCOLOR_GREEN (nSalColor),
361cdf0e10cSrcweir                               SALCOLOR_BLUE  (nSalColor));
362cdf0e10cSrcweir     m_pPrinterGfx->SetFillColor (aColor);
363cdf0e10cSrcweir }
364cdf0e10cSrcweir 
SetROPLineColor(SalROPColor)365cdf0e10cSrcweir void PspGraphics::SetROPLineColor( SalROPColor )
366cdf0e10cSrcweir {
367cdf0e10cSrcweir     DBG_ASSERT( 0, "Error: PrinterGfx::SetROPLineColor() not implemented" );
368cdf0e10cSrcweir }
369cdf0e10cSrcweir 
SetROPFillColor(SalROPColor)370cdf0e10cSrcweir void PspGraphics::SetROPFillColor( SalROPColor )
371cdf0e10cSrcweir {
372cdf0e10cSrcweir     DBG_ASSERT( 0, "Error: PrinterGfx::SetROPFillColor() not implemented" );
373cdf0e10cSrcweir }
374cdf0e10cSrcweir 
SetXORMode(bool bSet,bool)375cdf0e10cSrcweir void PspGraphics::SetXORMode( bool bSet, bool )
376cdf0e10cSrcweir {
377cdf0e10cSrcweir     (void)bSet;
378cdf0e10cSrcweir     DBG_ASSERT( !bSet, "Error: PrinterGfx::SetXORMode() not implemented" );
379cdf0e10cSrcweir }
380cdf0e10cSrcweir 
drawPixel(long nX,long nY)381cdf0e10cSrcweir void PspGraphics::drawPixel( long nX, long nY )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir     m_pPrinterGfx->DrawPixel (Point(nX, nY));
384cdf0e10cSrcweir }
385cdf0e10cSrcweir 
drawPixel(long nX,long nY,SalColor nSalColor)386cdf0e10cSrcweir void PspGraphics::drawPixel( long nX, long nY, SalColor nSalColor )
387cdf0e10cSrcweir {
388cdf0e10cSrcweir     psp::PrinterColor aColor (SALCOLOR_RED   (nSalColor),
389cdf0e10cSrcweir                               SALCOLOR_GREEN (nSalColor),
390cdf0e10cSrcweir                               SALCOLOR_BLUE  (nSalColor));
391cdf0e10cSrcweir     m_pPrinterGfx->DrawPixel (Point(nX, nY), aColor);
392cdf0e10cSrcweir }
393cdf0e10cSrcweir 
drawLine(long nX1,long nY1,long nX2,long nY2)394cdf0e10cSrcweir void PspGraphics::drawLine( long nX1, long nY1, long nX2, long nY2 )
395cdf0e10cSrcweir {
396cdf0e10cSrcweir     m_pPrinterGfx->DrawLine (Point(nX1, nY1), Point(nX2, nY2));
397cdf0e10cSrcweir }
398cdf0e10cSrcweir 
drawRect(long nX,long nY,long nDX,long nDY)399cdf0e10cSrcweir void PspGraphics::drawRect( long nX, long nY, long nDX, long nDY )
400cdf0e10cSrcweir {
401cdf0e10cSrcweir     m_pPrinterGfx->DrawRect (Rectangle(Point(nX, nY), Size(nDX, nDY)));
402cdf0e10cSrcweir }
403cdf0e10cSrcweir 
drawPolyLine(sal_uInt32 nPoints,const SalPoint * pPtAry)404*54ae6a37SHerbert Dürr void PspGraphics::drawPolyLine( sal_uInt32 nPoints, const SalPoint *pPtAry )
405cdf0e10cSrcweir {
406cdf0e10cSrcweir     m_pPrinterGfx->DrawPolyLine (nPoints, (Point*)pPtAry);
407cdf0e10cSrcweir }
408cdf0e10cSrcweir 
drawPolygon(sal_uInt32 nPoints,const SalPoint * pPtAry)409*54ae6a37SHerbert Dürr void PspGraphics::drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry )
410cdf0e10cSrcweir {
411cdf0e10cSrcweir 	// Point must be equal to SalPoint! see vcl/inc/salgtype.hxx
412cdf0e10cSrcweir     m_pPrinterGfx->DrawPolygon (nPoints, (Point*)pPtAry);
413cdf0e10cSrcweir }
414cdf0e10cSrcweir 
drawPolyPolygon(sal_uInt32 nPoly,const sal_uInt32 * pPoints,PCONSTSALPOINT * pPtAry)415cdf0e10cSrcweir void PspGraphics::drawPolyPolygon( sal_uInt32			nPoly,
416cdf0e10cSrcweir 								   const sal_uInt32   *pPoints,
417cdf0e10cSrcweir 								   PCONSTSALPOINT  *pPtAry )
418cdf0e10cSrcweir {
419cdf0e10cSrcweir     m_pPrinterGfx->DrawPolyPolygon (nPoly, pPoints, (const Point**)pPtAry);
420cdf0e10cSrcweir }
421cdf0e10cSrcweir 
drawPolyPolygon(const::basegfx::B2DPolyPolygon &,double)422cdf0e10cSrcweir bool PspGraphics::drawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double /*fTransparency*/ )
423cdf0e10cSrcweir {
424cdf0e10cSrcweir         // TODO: implement and advertise OutDevSupport_B2DDraw support
425cdf0e10cSrcweir         return false;
426cdf0e10cSrcweir }
427cdf0e10cSrcweir 
drawPolyLine(const basegfx::B2DPolygon &,double,const basegfx::B2DVector &,basegfx::B2DLineJoin,com::sun::star::drawing::LineCap)4285aaf853bSArmin Le Grand bool PspGraphics::drawPolyLine(
4295aaf853bSArmin Le Grand     const basegfx::B2DPolygon&,
4305aaf853bSArmin Le Grand     double /*fTranspareny*/,
4315aaf853bSArmin Le Grand     const basegfx::B2DVector& /*rLineWidths*/,
4325aaf853bSArmin Le Grand     basegfx::B2DLineJoin /*eJoin*/,
4335aaf853bSArmin Le Grand     com::sun::star::drawing::LineCap /*eLineCap*/)
434cdf0e10cSrcweir {
435cdf0e10cSrcweir     // TODO: a PS printer can draw B2DPolyLines almost directly
436cdf0e10cSrcweir     return false;
437cdf0e10cSrcweir }
438cdf0e10cSrcweir 
drawPolyLineBezier(sal_uInt32 nPoints,const SalPoint * pPtAry,const sal_uInt8 * pFlgAry)439*54ae6a37SHerbert Dürr sal_Bool PspGraphics::drawPolyLineBezier( sal_uInt32 nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry )
440cdf0e10cSrcweir {
441cdf0e10cSrcweir     m_pPrinterGfx->DrawPolyLineBezier (nPoints, (Point*)pPtAry, pFlgAry);
442cdf0e10cSrcweir     return sal_True;
443cdf0e10cSrcweir }
444cdf0e10cSrcweir 
drawPolygonBezier(sal_uInt32 nPoints,const SalPoint * pPtAry,const sal_uInt8 * pFlgAry)445*54ae6a37SHerbert Dürr sal_Bool PspGraphics::drawPolygonBezier( sal_uInt32 nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry )
446cdf0e10cSrcweir {
447cdf0e10cSrcweir     m_pPrinterGfx->DrawPolygonBezier (nPoints, (Point*)pPtAry, pFlgAry);
448cdf0e10cSrcweir     return sal_True;
449cdf0e10cSrcweir }
450cdf0e10cSrcweir 
drawPolyPolygonBezier(sal_uInt32 nPoly,const sal_uInt32 * pPoints,const SalPoint * const * pPtAry,const sal_uInt8 * const * pFlgAry)451cdf0e10cSrcweir sal_Bool PspGraphics::drawPolyPolygonBezier( sal_uInt32 nPoly,
452cdf0e10cSrcweir                                              const sal_uInt32* pPoints,
453cdf0e10cSrcweir                                              const SalPoint* const* pPtAry,
454cdf0e10cSrcweir                                              const sal_uInt8* const* pFlgAry )
455cdf0e10cSrcweir {
456cdf0e10cSrcweir 	// Point must be equal to SalPoint! see vcl/inc/salgtype.hxx
457cdf0e10cSrcweir     m_pPrinterGfx->DrawPolyPolygonBezier (nPoly, pPoints, (Point**)pPtAry, (sal_uInt8**)pFlgAry);
458cdf0e10cSrcweir     return sal_True;
459cdf0e10cSrcweir }
460cdf0e10cSrcweir 
invert(sal_uInt32,const SalPoint *,SalInvert)461*54ae6a37SHerbert Dürr void PspGraphics::invert( sal_uInt32, const SalPoint*, SalInvert )
462cdf0e10cSrcweir {
463cdf0e10cSrcweir     DBG_ASSERT( 0, "Error: PrinterGfx::Invert() not implemented" );
464cdf0e10cSrcweir }
465*54ae6a37SHerbert Dürr 
drawEPS(long nX,long nY,long nWidth,long nHeight,void * pPtr,sal_uLong nSize)466cdf0e10cSrcweir sal_Bool PspGraphics::drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uLong nSize )
467cdf0e10cSrcweir {
468cdf0e10cSrcweir     return m_pPrinterGfx->DrawEPS( Rectangle( Point( nX, nY ), Size( nWidth, nHeight ) ), pPtr, nSize );
469cdf0e10cSrcweir }
470cdf0e10cSrcweir 
copyBits(const SalTwoRect &,SalGraphics *)4715f27b83cSArmin Le Grand void PspGraphics::copyBits( const SalTwoRect&,
472cdf0e10cSrcweir                             SalGraphics* )
473cdf0e10cSrcweir {
474cdf0e10cSrcweir     DBG_ERROR( "Error: PrinterGfx::CopyBits() not implemented" );
475cdf0e10cSrcweir }
476cdf0e10cSrcweir 
copyArea(long,long,long,long,long,long,sal_uInt16)477cdf0e10cSrcweir void PspGraphics::copyArea ( long,long,long,long,long,long,sal_uInt16 )
478cdf0e10cSrcweir {
479cdf0e10cSrcweir     DBG_ERROR( "Error: PrinterGfx::CopyArea() not implemented" );
480cdf0e10cSrcweir }
481cdf0e10cSrcweir 
drawBitmap(const SalTwoRect & rPosAry,const SalBitmap & rSalBitmap)4825f27b83cSArmin Le Grand void PspGraphics::drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap )
483cdf0e10cSrcweir {
4845f27b83cSArmin Le Grand     Rectangle aSrc (Point(rPosAry.mnSrcX, rPosAry.mnSrcY),
4855f27b83cSArmin Le Grand                     Size(rPosAry.mnSrcWidth, rPosAry.mnSrcHeight));
4865f27b83cSArmin Le Grand     Rectangle aDst (Point(rPosAry.mnDestX, rPosAry.mnDestY),
4875f27b83cSArmin Le Grand                     Size(rPosAry.mnDestWidth, rPosAry.mnDestHeight));
488cdf0e10cSrcweir 
489cdf0e10cSrcweir     BitmapBuffer* pBuffer= const_cast<SalBitmap&>(rSalBitmap).AcquireBuffer(sal_True);
490cdf0e10cSrcweir 
491cdf0e10cSrcweir     SalPrinterBmp aBmp (pBuffer);
492cdf0e10cSrcweir     m_pPrinterGfx->DrawBitmap (aDst, aSrc, aBmp);
493cdf0e10cSrcweir 
494cdf0e10cSrcweir     const_cast<SalBitmap&>(rSalBitmap).ReleaseBuffer (pBuffer, sal_True);
495cdf0e10cSrcweir }
496cdf0e10cSrcweir 
drawBitmap(const SalTwoRect &,const SalBitmap &,const SalBitmap &)4975f27b83cSArmin Le Grand void PspGraphics::drawBitmap( const SalTwoRect&,
498cdf0e10cSrcweir                               const SalBitmap&,
499cdf0e10cSrcweir                               const SalBitmap& )
500cdf0e10cSrcweir {
501cdf0e10cSrcweir     DBG_ERROR("Error: no PrinterGfx::DrawBitmap() for transparent bitmap");
502cdf0e10cSrcweir }
503cdf0e10cSrcweir 
drawBitmap(const SalTwoRect &,const SalBitmap &,SalColor)5045f27b83cSArmin Le Grand void PspGraphics::drawBitmap( const SalTwoRect&,
505cdf0e10cSrcweir                               const SalBitmap&,
506cdf0e10cSrcweir                               SalColor )
507cdf0e10cSrcweir {
508cdf0e10cSrcweir     DBG_ERROR("Error: no PrinterGfx::DrawBitmap() for transparent color");
509cdf0e10cSrcweir }
510cdf0e10cSrcweir 
drawMask(const SalTwoRect &,const SalBitmap &,SalColor)5115f27b83cSArmin Le Grand void PspGraphics::drawMask( const SalTwoRect&,
512cdf0e10cSrcweir                             const SalBitmap &,
513cdf0e10cSrcweir                             SalColor )
514cdf0e10cSrcweir {
515cdf0e10cSrcweir     DBG_ERROR("Error: PrinterGfx::DrawMask() not implemented");
516cdf0e10cSrcweir }
517cdf0e10cSrcweir 
getBitmap(long,long,long,long)518cdf0e10cSrcweir SalBitmap* PspGraphics::getBitmap( long, long, long, long )
519cdf0e10cSrcweir {
520cdf0e10cSrcweir     DBG_WARNING ("Warning: PrinterGfx::GetBitmap() not implemented");
521cdf0e10cSrcweir     return NULL;
522cdf0e10cSrcweir }
523cdf0e10cSrcweir 
getPixel(long,long)524cdf0e10cSrcweir SalColor PspGraphics::getPixel( long, long )
525cdf0e10cSrcweir {
526cdf0e10cSrcweir     DBG_ERROR ("Warning: PrinterGfx::GetPixel() not implemented");
527cdf0e10cSrcweir     return 0;
528cdf0e10cSrcweir }
529cdf0e10cSrcweir 
invert(long,long,long,long,SalInvert)530cdf0e10cSrcweir void PspGraphics::invert(long,long,long,long,SalInvert)
531cdf0e10cSrcweir {
532cdf0e10cSrcweir     DBG_ERROR ("Warning: PrinterGfx::Invert() not implemented");
533cdf0e10cSrcweir }
534cdf0e10cSrcweir 
535cdf0e10cSrcweir //==========================================================================
536cdf0e10cSrcweir 
537cdf0e10cSrcweir class ImplPspFontData : public ImplFontData
538cdf0e10cSrcweir {
539cdf0e10cSrcweir private:
540cdf0e10cSrcweir     enum { PSPFD_MAGIC = 0xb5bf01f0 };
541cdf0e10cSrcweir     sal_IntPtr              mnFontId;
542cdf0e10cSrcweir 
543cdf0e10cSrcweir public:
544cdf0e10cSrcweir                             ImplPspFontData( const psp::FastPrintFontInfo& );
GetFontId() const545cdf0e10cSrcweir     virtual sal_IntPtr      GetFontId() const { return mnFontId; }
Clone() const546cdf0e10cSrcweir     virtual ImplFontData*   Clone() const { return new ImplPspFontData( *this ); }
547cdf0e10cSrcweir     virtual ImplFontEntry*  CreateFontInstance( ImplFontSelectData& ) const;
CheckFontData(const ImplFontData & r)548cdf0e10cSrcweir     static bool             CheckFontData( const ImplFontData& r ) { return r.CheckMagic( PSPFD_MAGIC ); }
549cdf0e10cSrcweir };
550cdf0e10cSrcweir 
551cdf0e10cSrcweir //--------------------------------------------------------------------------
552cdf0e10cSrcweir 
ImplPspFontData(const psp::FastPrintFontInfo & rInfo)553cdf0e10cSrcweir ImplPspFontData::ImplPspFontData( const psp::FastPrintFontInfo& rInfo )
554cdf0e10cSrcweir :   ImplFontData( PspGraphics::Info2DevFontAttributes(rInfo), PSPFD_MAGIC ),
555cdf0e10cSrcweir     mnFontId( rInfo.m_nID )
556cdf0e10cSrcweir {}
557cdf0e10cSrcweir 
558cdf0e10cSrcweir //--------------------------------------------------------------------------
559cdf0e10cSrcweir 
CreateFontInstance(ImplFontSelectData & rFSD) const560cdf0e10cSrcweir ImplFontEntry* ImplPspFontData::CreateFontInstance( ImplFontSelectData& rFSD ) const
561cdf0e10cSrcweir {
562cdf0e10cSrcweir     ImplServerFontEntry* pEntry = new ImplServerFontEntry( rFSD );
563cdf0e10cSrcweir     return pEntry;
564cdf0e10cSrcweir }
565cdf0e10cSrcweir 
566cdf0e10cSrcweir //==========================================================================
567cdf0e10cSrcweir 
568cdf0e10cSrcweir class PspFontLayout : public GenericSalLayout
569cdf0e10cSrcweir {
570cdf0e10cSrcweir public:
571cdf0e10cSrcweir                         PspFontLayout( ::psp::PrinterGfx& );
572cdf0e10cSrcweir     virtual bool        LayoutText( ImplLayoutArgs& );
573cdf0e10cSrcweir     virtual void        InitFont() const;
574cdf0e10cSrcweir     virtual void        DrawText( SalGraphics& ) const;
575cdf0e10cSrcweir private:
576cdf0e10cSrcweir     ::psp::PrinterGfx&  mrPrinterGfx;
577cdf0e10cSrcweir     sal_IntPtr          mnFontID;
578cdf0e10cSrcweir     int                 mnFontHeight;
579cdf0e10cSrcweir     int                 mnFontWidth;
580cdf0e10cSrcweir     bool                mbVertical;
581cdf0e10cSrcweir     bool                mbArtItalic;
582cdf0e10cSrcweir     bool                mbArtBold;
583cdf0e10cSrcweir };
584cdf0e10cSrcweir 
585cdf0e10cSrcweir //--------------------------------------------------------------------------
586cdf0e10cSrcweir 
PspFontLayout(::psp::PrinterGfx & rGfx)587cdf0e10cSrcweir PspFontLayout::PspFontLayout( ::psp::PrinterGfx& rGfx )
588cdf0e10cSrcweir :   mrPrinterGfx( rGfx )
589cdf0e10cSrcweir {
590cdf0e10cSrcweir     mnFontID     = mrPrinterGfx.GetFontID();
591cdf0e10cSrcweir     mnFontHeight = mrPrinterGfx.GetFontHeight();
592cdf0e10cSrcweir     mnFontWidth  = mrPrinterGfx.GetFontWidth();
593cdf0e10cSrcweir     mbVertical   = mrPrinterGfx.GetFontVertical();
594cdf0e10cSrcweir     mbArtItalic	 = mrPrinterGfx.GetArtificialItalic();
595cdf0e10cSrcweir     mbArtBold	 = mrPrinterGfx.GetArtificialBold();
596cdf0e10cSrcweir }
597cdf0e10cSrcweir 
598cdf0e10cSrcweir //--------------------------------------------------------------------------
599cdf0e10cSrcweir 
LayoutText(ImplLayoutArgs & rArgs)600cdf0e10cSrcweir bool PspFontLayout::LayoutText( ImplLayoutArgs& rArgs )
601cdf0e10cSrcweir {
602cdf0e10cSrcweir     mbVertical = ((rArgs.mnFlags & SAL_LAYOUT_VERTICAL) != 0);
603cdf0e10cSrcweir 
604cdf0e10cSrcweir     long nUnitsPerPixel = 1;
605248a599fSHerbert Dürr     sal_GlyphId aOldGlyphId( GF_DROPPED);
606cdf0e10cSrcweir     long nGlyphWidth = 0;
607cdf0e10cSrcweir     int nCharPos = -1;
608cdf0e10cSrcweir     Point aNewPos( 0, 0 );
609cdf0e10cSrcweir     GlyphItem aPrevItem;
610cdf0e10cSrcweir     rtl_TextEncoding aFontEnc = mrPrinterGfx.GetFontMgr().getFontEncoding( mnFontID );
611cdf0e10cSrcweir     for(;;)
612cdf0e10cSrcweir     {
613cdf0e10cSrcweir         bool bRightToLeft;
614cdf0e10cSrcweir         if( !rArgs.GetNextPos( &nCharPos, &bRightToLeft ) )
615cdf0e10cSrcweir             break;
616cdf0e10cSrcweir 
617cdf0e10cSrcweir         sal_Unicode cChar = rArgs.mpStr[ nCharPos ];
618cdf0e10cSrcweir         if( bRightToLeft )
619cdf0e10cSrcweir             cChar = GetMirroredChar( cChar );
620cdf0e10cSrcweir         // symbol font aliasing: 0x0020-0x00ff -> 0xf020 -> 0xf0ff
621cdf0e10cSrcweir         if( aFontEnc == RTL_TEXTENCODING_SYMBOL )
622cdf0e10cSrcweir             if( cChar < 256 )
623cdf0e10cSrcweir                 cChar += 0xf000;
624248a599fSHerbert Dürr         sal_GlyphId aGlyphId( cChar);  // printer glyphs = unicode
625cdf0e10cSrcweir 
626cdf0e10cSrcweir         // update fallback_runs if needed
627cdf0e10cSrcweir         psp::CharacterMetric aMetric;
628cdf0e10cSrcweir         mrPrinterGfx.GetFontMgr().getMetrics( mnFontID, cChar, cChar, &aMetric, mbVertical );
629cdf0e10cSrcweir         if( aMetric.width == -1 && aMetric.height == -1 )
630cdf0e10cSrcweir             rArgs.NeedFallback( nCharPos, bRightToLeft );
631cdf0e10cSrcweir 
632cdf0e10cSrcweir         // apply pair kerning to prev glyph if requested
633cdf0e10cSrcweir         if( SAL_LAYOUT_KERNING_PAIRS & rArgs.mnFlags )
634cdf0e10cSrcweir         {
635248a599fSHerbert Dürr             if( aOldGlyphId > 0 )
636cdf0e10cSrcweir             {
637cdf0e10cSrcweir                 const std::list< KernPair >& rKernPairs = mrPrinterGfx.getKernPairs(mbVertical);
638cdf0e10cSrcweir                 for( std::list< KernPair >::const_iterator it = rKernPairs.begin();
639cdf0e10cSrcweir                      it != rKernPairs.end(); ++it )
640cdf0e10cSrcweir                 {
641248a599fSHerbert Dürr                     if( (it->first == aOldGlyphId) && (it->second == aGlyphId) )
642cdf0e10cSrcweir                     {
643cdf0e10cSrcweir                         int nTextScale = mrPrinterGfx.GetFontWidth();
644cdf0e10cSrcweir                         if( ! nTextScale )
645cdf0e10cSrcweir                             nTextScale = mrPrinterGfx.GetFontHeight();
646cdf0e10cSrcweir                         int nKern = (mbVertical ? it->kern_y : it->kern_x) * nTextScale;
647cdf0e10cSrcweir                         nGlyphWidth += nKern;
648cdf0e10cSrcweir                         aPrevItem.mnNewWidth = nGlyphWidth;
649cdf0e10cSrcweir                         break;
650cdf0e10cSrcweir                     }
651cdf0e10cSrcweir                 }
652cdf0e10cSrcweir             }
653cdf0e10cSrcweir         }
654cdf0e10cSrcweir 
655cdf0e10cSrcweir         // finish previous glyph
656248a599fSHerbert Dürr         if( aOldGlyphId != GF_DROPPED )
657cdf0e10cSrcweir             AppendGlyph( aPrevItem );
658248a599fSHerbert Dürr         aOldGlyphId = aGlyphId;
659cdf0e10cSrcweir         aNewPos.X() += nGlyphWidth;
660cdf0e10cSrcweir 
661cdf0e10cSrcweir         // prepare GlyphItem for appending it in next round
662cdf0e10cSrcweir         nUnitsPerPixel = mrPrinterGfx.GetCharWidth( cChar, cChar, &nGlyphWidth );
663cdf0e10cSrcweir         int nGlyphFlags = bRightToLeft ? GlyphItem::IS_RTL_GLYPH : 0;
664248a599fSHerbert Dürr         aGlyphId |= GF_ISCHAR;
665248a599fSHerbert Dürr         aPrevItem = GlyphItem( nCharPos, aGlyphId, aNewPos, nGlyphFlags, nGlyphWidth );
666cdf0e10cSrcweir     }
667cdf0e10cSrcweir 
668cdf0e10cSrcweir     // append last glyph item if any
669248a599fSHerbert Dürr     if( aOldGlyphId != GF_DROPPED )
670cdf0e10cSrcweir         AppendGlyph( aPrevItem );
671cdf0e10cSrcweir 
672cdf0e10cSrcweir     SetOrientation( mrPrinterGfx.GetFontAngle() );
673cdf0e10cSrcweir     SetUnitsPerPixel( nUnitsPerPixel );
674248a599fSHerbert Dürr     return (aOldGlyphId != GF_DROPPED);
675cdf0e10cSrcweir }
676cdf0e10cSrcweir 
677cdf0e10cSrcweir class PspServerFontLayout : public ServerFontLayout
678cdf0e10cSrcweir {
679cdf0e10cSrcweir public:
680cdf0e10cSrcweir     PspServerFontLayout( psp::PrinterGfx&, ServerFont& rFont, const ImplLayoutArgs& rArgs );
681cdf0e10cSrcweir 
682cdf0e10cSrcweir     virtual void        InitFont() const;
getTextPtr() const683cdf0e10cSrcweir     const sal_Unicode*	getTextPtr() const { return maText.getStr() - mnMinCharPos; }
getMinCharPos() const684cdf0e10cSrcweir     int					getMinCharPos() const { return mnMinCharPos; }
getMaxCharPos() const685cdf0e10cSrcweir     int					getMaxCharPos() const { return mnMinCharPos+maText.getLength()-1; }
686cdf0e10cSrcweir private:
687cdf0e10cSrcweir     ::psp::PrinterGfx&  mrPrinterGfx;
688cdf0e10cSrcweir     sal_IntPtr          mnFontID;
689cdf0e10cSrcweir     int                 mnFontHeight;
690cdf0e10cSrcweir     int                 mnFontWidth;
691cdf0e10cSrcweir     bool                mbVertical;
692cdf0e10cSrcweir     bool				mbArtItalic;
693cdf0e10cSrcweir     bool				mbArtBold;
694cdf0e10cSrcweir     rtl::OUString		maText;
695cdf0e10cSrcweir     int					mnMinCharPos;
696cdf0e10cSrcweir };
697cdf0e10cSrcweir 
PspServerFontLayout(::psp::PrinterGfx & rGfx,ServerFont & rFont,const ImplLayoutArgs & rArgs)698cdf0e10cSrcweir PspServerFontLayout::PspServerFontLayout( ::psp::PrinterGfx& rGfx, ServerFont& rFont, const ImplLayoutArgs& rArgs )
699cdf0e10cSrcweir         :   ServerFontLayout( rFont ),
700cdf0e10cSrcweir             mrPrinterGfx( rGfx )
701cdf0e10cSrcweir {
702cdf0e10cSrcweir     mnFontID     = mrPrinterGfx.GetFontID();
703cdf0e10cSrcweir     mnFontHeight = mrPrinterGfx.GetFontHeight();
704cdf0e10cSrcweir     mnFontWidth  = mrPrinterGfx.GetFontWidth();
705cdf0e10cSrcweir     mbVertical   = mrPrinterGfx.GetFontVertical();
706cdf0e10cSrcweir     mbArtItalic	 = mrPrinterGfx.GetArtificialItalic();
707cdf0e10cSrcweir     mbArtBold	 = mrPrinterGfx.GetArtificialBold();
708cdf0e10cSrcweir     maText		 = OUString( rArgs.mpStr + rArgs.mnMinCharPos, rArgs.mnEndCharPos - rArgs.mnMinCharPos+1 );
709cdf0e10cSrcweir     mnMinCharPos = rArgs.mnMinCharPos;
710cdf0e10cSrcweir }
711cdf0e10cSrcweir 
InitFont() const712cdf0e10cSrcweir void PspServerFontLayout::InitFont() const
713cdf0e10cSrcweir {
714cdf0e10cSrcweir     mrPrinterGfx.SetFont( mnFontID, mnFontHeight, mnFontWidth,
715cdf0e10cSrcweir                           mnOrientation, mbVertical, mbArtItalic, mbArtBold );
716cdf0e10cSrcweir }
717cdf0e10cSrcweir 
718cdf0e10cSrcweir //--------------------------------------------------------------------------
719cdf0e10cSrcweir 
DrawPrinterLayout(const SalLayout & rLayout,::psp::PrinterGfx & rGfx,bool bIsPspServerFontLayout)720cdf0e10cSrcweir static void DrawPrinterLayout( const SalLayout& rLayout, ::psp::PrinterGfx& rGfx, bool bIsPspServerFontLayout )
721cdf0e10cSrcweir {
722cdf0e10cSrcweir     const int nMaxGlyphs = 200;
723248a599fSHerbert Dürr     sal_GlyphId aGlyphAry[ nMaxGlyphs ];
724cdf0e10cSrcweir     sal_Int32   aWidthAry[ nMaxGlyphs ];
725cdf0e10cSrcweir     sal_Int32   aIdxAry  [ nMaxGlyphs ];
726cdf0e10cSrcweir     sal_Unicode aUnicodes[ nMaxGlyphs ];
727cdf0e10cSrcweir     int			aCharPosAry	[ nMaxGlyphs ];
728cdf0e10cSrcweir 
729cdf0e10cSrcweir     Point aPos;
730cdf0e10cSrcweir     long nUnitsPerPixel = rLayout.GetUnitsPerPixel();
731cdf0e10cSrcweir     const sal_Unicode* pText = NULL;
732cdf0e10cSrcweir     int nMinCharPos = 0;
733cdf0e10cSrcweir     int nMaxCharPos = 0;
734cdf0e10cSrcweir     if (bIsPspServerFontLayout)
735cdf0e10cSrcweir     {
736cdf0e10cSrcweir         const PspServerFontLayout * pPspLayout = dynamic_cast<const PspServerFontLayout*>(&rLayout);
737cdf0e10cSrcweir #ifdef ENABLE_GRAPHITE
738cdf0e10cSrcweir         const GraphiteServerFontLayout * pGrLayout = dynamic_cast<const GraphiteServerFontLayout*>(&rLayout);
739cdf0e10cSrcweir #endif
740cdf0e10cSrcweir         if (pPspLayout)
741cdf0e10cSrcweir         {
742cdf0e10cSrcweir             pText = pPspLayout->getTextPtr();
743cdf0e10cSrcweir             nMinCharPos = pPspLayout->getMinCharPos();
744cdf0e10cSrcweir             nMaxCharPos = pPspLayout->getMaxCharPos();
745cdf0e10cSrcweir         }
746cdf0e10cSrcweir #ifdef ENABLE_GRAPHITE
747cdf0e10cSrcweir         else if (pGrLayout)
748cdf0e10cSrcweir         {
749cdf0e10cSrcweir         #if 0 // HACK: disabled for now due to #i114460#, see #desc12 there
750cdf0e10cSrcweir               // TODO: get rid of glyph->string mapping altogether for printing
751cdf0e10cSrcweir 	      // TODO: fix GraphiteServerFontLayout's returned aCharPosAry
752cdf0e10cSrcweir 	      // TODO: fix PrinterGfx's caching?
753cdf0e10cSrcweir             pText = pGrLayout->getTextPtr();
754cdf0e10cSrcweir             nMinCharPos = pGrLayout->getMinCharPos();
755cdf0e10cSrcweir             nMaxCharPos = pGrLayout->getMaxCharPos();
756cdf0e10cSrcweir 	#endif
757cdf0e10cSrcweir         }
758cdf0e10cSrcweir #endif
759cdf0e10cSrcweir     }
760cdf0e10cSrcweir     for( int nStart = 0;; )
761cdf0e10cSrcweir     {
762cdf0e10cSrcweir         int nGlyphCount = rLayout.GetNextGlyphs( nMaxGlyphs, aGlyphAry, aPos, nStart, aWidthAry, pText ? aCharPosAry : NULL );
763cdf0e10cSrcweir         if( !nGlyphCount )
764cdf0e10cSrcweir             break;
765cdf0e10cSrcweir 
766cdf0e10cSrcweir         sal_Int32 nXOffset = 0;
767cdf0e10cSrcweir         for( int i = 0; i < nGlyphCount; ++i )
768cdf0e10cSrcweir         {
769cdf0e10cSrcweir             nXOffset += aWidthAry[ i ];
770cdf0e10cSrcweir             aIdxAry[ i ] = nXOffset / nUnitsPerPixel;
771248a599fSHerbert Dürr             sal_GlyphId aGlyphId = aGlyphAry[i] & (GF_IDXMASK | GF_ROTMASK);
772cdf0e10cSrcweir             if( pText )
773cdf0e10cSrcweir                 aUnicodes[i] = (aCharPosAry[i] >= nMinCharPos && aCharPosAry[i] <= nMaxCharPos) ? pText[ aCharPosAry[i] ] : 0;
774cdf0e10cSrcweir             else
775248a599fSHerbert Dürr                 aUnicodes[i] = (aGlyphAry[i] & GF_ISCHAR) ? aGlyphId : 0;
776248a599fSHerbert Dürr             aGlyphAry[i] = aGlyphId;
777cdf0e10cSrcweir         }
778cdf0e10cSrcweir 
779248a599fSHerbert Dürr         rGfx.DrawGlyphs( aPos, aGlyphAry, aUnicodes, nGlyphCount, aIdxAry );
780cdf0e10cSrcweir     }
781cdf0e10cSrcweir }
782cdf0e10cSrcweir 
783cdf0e10cSrcweir //--------------------------------------------------------------------------
784cdf0e10cSrcweir 
InitFont() const785cdf0e10cSrcweir void PspFontLayout::InitFont() const
786cdf0e10cSrcweir {
787cdf0e10cSrcweir     mrPrinterGfx.SetFont( mnFontID, mnFontHeight, mnFontWidth,
788cdf0e10cSrcweir         mnOrientation, mbVertical, mbArtItalic, mbArtBold );
789cdf0e10cSrcweir }
790cdf0e10cSrcweir 
791cdf0e10cSrcweir //--------------------------------------------------------------------------
792cdf0e10cSrcweir 
DrawText(SalGraphics &) const793cdf0e10cSrcweir void PspFontLayout::DrawText( SalGraphics& ) const
794cdf0e10cSrcweir {
795cdf0e10cSrcweir     DrawPrinterLayout( *this, mrPrinterGfx, false );
796cdf0e10cSrcweir }
797cdf0e10cSrcweir 
DrawServerFontLayout(const ServerFontLayout & rLayout)798cdf0e10cSrcweir void PspGraphics::DrawServerFontLayout( const ServerFontLayout& rLayout )
799cdf0e10cSrcweir {
800cdf0e10cSrcweir     // print complex text
801cdf0e10cSrcweir     DrawPrinterLayout( rLayout, *m_pPrinterGfx, true );
802cdf0e10cSrcweir }
803cdf0e10cSrcweir 
GetImplFontCharMap() const804cdf0e10cSrcweir const ImplFontCharMap* PspGraphics::GetImplFontCharMap() const
805cdf0e10cSrcweir {
806cdf0e10cSrcweir     if( !m_pServerFont[0] )
807cdf0e10cSrcweir         return NULL;
808cdf0e10cSrcweir 
809cdf0e10cSrcweir     const ImplFontCharMap* pIFCMap = m_pServerFont[0]->GetImplFontCharMap();
810cdf0e10cSrcweir     return pIFCMap;
811cdf0e10cSrcweir }
812cdf0e10cSrcweir 
SetFont(ImplFontSelectData * pEntry,int nFallbackLevel)813cdf0e10cSrcweir sal_uInt16 PspGraphics::SetFont( ImplFontSelectData *pEntry, int nFallbackLevel )
814cdf0e10cSrcweir {
815cdf0e10cSrcweir     // release all fonts that are to be overridden
816cdf0e10cSrcweir     for( int i = nFallbackLevel; i < MAX_FALLBACK; ++i )
817cdf0e10cSrcweir     {
818cdf0e10cSrcweir         if( m_pServerFont[i] != NULL )
819cdf0e10cSrcweir         {
820cdf0e10cSrcweir             // old server side font is no longer referenced
821cdf0e10cSrcweir             GlyphCache::GetInstance().UncacheFont( *m_pServerFont[i] );
822cdf0e10cSrcweir             m_pServerFont[i] = NULL;
823cdf0e10cSrcweir         }
824cdf0e10cSrcweir     }
825cdf0e10cSrcweir 
826cdf0e10cSrcweir     // return early if there is no new font
827cdf0e10cSrcweir     if( !pEntry )
828cdf0e10cSrcweir         return 0;
829cdf0e10cSrcweir 
830cdf0e10cSrcweir     sal_IntPtr nID = pEntry->mpFontData ? pEntry->mpFontData->GetFontId() : 0;
831cdf0e10cSrcweir 
832cdf0e10cSrcweir     // determine which font attributes need to be emulated
833cdf0e10cSrcweir     bool bArtItalic = false;
834cdf0e10cSrcweir     bool bArtBold = false;
835cdf0e10cSrcweir     if( pEntry->meItalic == ITALIC_OBLIQUE || pEntry->meItalic == ITALIC_NORMAL )
836cdf0e10cSrcweir     {
837cdf0e10cSrcweir         psp::italic::type eItalic = m_pPrinterGfx->GetFontMgr().getFontItalic( nID );
838cdf0e10cSrcweir         if( eItalic != psp::italic::Italic && eItalic != psp::italic::Oblique )
839cdf0e10cSrcweir             bArtItalic = true;
840cdf0e10cSrcweir     }
841cdf0e10cSrcweir     int nWeight = (int)pEntry->meWeight;
842cdf0e10cSrcweir     int nRealWeight = (int)m_pPrinterGfx->GetFontMgr().getFontWeight( nID );
843cdf0e10cSrcweir     if( nRealWeight <= (int)psp::weight::Medium && nWeight > (int)WEIGHT_MEDIUM )
844cdf0e10cSrcweir     {
845cdf0e10cSrcweir         bArtBold = true;
846cdf0e10cSrcweir     }
847cdf0e10cSrcweir 
848cdf0e10cSrcweir     // also set the serverside font for layouting
849cdf0e10cSrcweir     m_bFontVertical = pEntry->mbVertical;
850cdf0e10cSrcweir     if( pEntry->mpFontData )
851cdf0e10cSrcweir     {
852cdf0e10cSrcweir         // requesting a font provided by builtin rasterizer
853cdf0e10cSrcweir         ServerFont* pServerFont = GlyphCache::GetInstance().CacheFont( *pEntry );
854cdf0e10cSrcweir         if( pServerFont != NULL )
855cdf0e10cSrcweir         {
856cdf0e10cSrcweir             if( pServerFont->TestFont() )
857cdf0e10cSrcweir                 m_pServerFont[ nFallbackLevel ] = pServerFont;
858cdf0e10cSrcweir             else
859cdf0e10cSrcweir                 GlyphCache::GetInstance().UncacheFont( *pServerFont );
860cdf0e10cSrcweir         }
861cdf0e10cSrcweir     }
862cdf0e10cSrcweir 
863cdf0e10cSrcweir     // set the printer font
864cdf0e10cSrcweir     return m_pPrinterGfx->SetFont( nID,
865cdf0e10cSrcweir                                    pEntry->mnHeight,
866cdf0e10cSrcweir                                    pEntry->mnWidth,
867cdf0e10cSrcweir                                    pEntry->mnOrientation,
868cdf0e10cSrcweir                                    pEntry->mbVertical,
869cdf0e10cSrcweir                                    bArtItalic,
870cdf0e10cSrcweir                                    bArtBold
871cdf0e10cSrcweir                                    );
872cdf0e10cSrcweir }
873cdf0e10cSrcweir 
SetTextColor(SalColor nSalColor)874cdf0e10cSrcweir void PspGraphics::SetTextColor( SalColor nSalColor )
875cdf0e10cSrcweir {
876cdf0e10cSrcweir     psp::PrinterColor aColor (SALCOLOR_RED   (nSalColor),
877cdf0e10cSrcweir                               SALCOLOR_GREEN (nSalColor),
878cdf0e10cSrcweir                               SALCOLOR_BLUE  (nSalColor));
879cdf0e10cSrcweir     m_pPrinterGfx->SetTextColor (aColor);
880cdf0e10cSrcweir }
881cdf0e10cSrcweir 
AddTempDevFont(ImplDevFontList *,const String &,const String &)882cdf0e10cSrcweir bool PspGraphics::AddTempDevFont( ImplDevFontList*, const String&,const String& )
883cdf0e10cSrcweir {
884cdf0e10cSrcweir     return false;
885cdf0e10cSrcweir }
886cdf0e10cSrcweir 
887cdf0e10cSrcweir void RegisterFontSubstitutors( ImplDevFontList* );
888cdf0e10cSrcweir 
GetDevFontList(ImplDevFontList * pList)889cdf0e10cSrcweir void PspGraphics::GetDevFontList( ImplDevFontList *pList )
890cdf0e10cSrcweir {
891cdf0e10cSrcweir     ::std::list< psp::fontID > aList;
892cdf0e10cSrcweir     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
893cdf0e10cSrcweir     rMgr.getFontList( aList, m_pJobData->m_pParser, m_pInfoPrinter->m_bCompatMetrics );
894cdf0e10cSrcweir 
895cdf0e10cSrcweir     ::std::list< psp::fontID >::iterator it;
896cdf0e10cSrcweir     psp::FastPrintFontInfo aInfo;
897cdf0e10cSrcweir     for (it = aList.begin(); it != aList.end(); ++it)
898cdf0e10cSrcweir         if (rMgr.getFontFastInfo (*it, aInfo))
899cdf0e10cSrcweir             AnnounceFonts( pList, aInfo );
900cdf0e10cSrcweir 
901cdf0e10cSrcweir    // register platform specific font substitutions if available
902cdf0e10cSrcweir    if( rMgr.hasFontconfig() )
903cdf0e10cSrcweir 	RegisterFontSubstitutors( pList );
904cdf0e10cSrcweir }
905cdf0e10cSrcweir 
GetDevFontSubstList(OutputDevice * pOutDev)906cdf0e10cSrcweir void PspGraphics::GetDevFontSubstList( OutputDevice* pOutDev )
907cdf0e10cSrcweir {
908cdf0e10cSrcweir     const psp::PrinterInfo& rInfo = psp::PrinterInfoManager::get().getPrinterInfo( m_pJobData->m_aPrinterName );
909cdf0e10cSrcweir     if( rInfo.m_bPerformFontSubstitution )
910cdf0e10cSrcweir     {
911cdf0e10cSrcweir         for( std::hash_map< rtl::OUString, rtl::OUString, rtl::OUStringHash >::const_iterator it = rInfo.m_aFontSubstitutes.begin(); it != rInfo.m_aFontSubstitutes.end(); ++it )
912cdf0e10cSrcweir             pOutDev->ImplAddDevFontSubstitute( it->first, it->second, FONT_SUBSTITUTE_ALWAYS );
913cdf0e10cSrcweir     }
914cdf0e10cSrcweir }
915cdf0e10cSrcweir 
GetFontMetric(ImplFontMetricData * pMetric,int)916cdf0e10cSrcweir void PspGraphics::GetFontMetric( ImplFontMetricData *pMetric, int )
917cdf0e10cSrcweir {
918cdf0e10cSrcweir     const psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
919cdf0e10cSrcweir     psp::PrintFontInfo aInfo;
920cdf0e10cSrcweir 
921cdf0e10cSrcweir     if (rMgr.getFontInfo (m_pPrinterGfx->GetFontID(), aInfo))
922cdf0e10cSrcweir     {
923cdf0e10cSrcweir         ImplDevFontAttributes aDFA = Info2DevFontAttributes( aInfo );
924cdf0e10cSrcweir         static_cast<ImplFontAttributes&>(*pMetric) = aDFA;
925cdf0e10cSrcweir         pMetric->mbDevice       = aDFA.mbDevice;
926cdf0e10cSrcweir         pMetric->mbScalableFont = true;
927cdf0e10cSrcweir 
928cdf0e10cSrcweir         pMetric->mnOrientation 	= m_pPrinterGfx->GetFontAngle();
929cdf0e10cSrcweir         pMetric->mnSlant		= 0;
930cdf0e10cSrcweir 
931cdf0e10cSrcweir         sal_Int32 nTextHeight	= m_pPrinterGfx->GetFontHeight();
932cdf0e10cSrcweir         sal_Int32 nTextWidth	= m_pPrinterGfx->GetFontWidth();
933cdf0e10cSrcweir         if( ! nTextWidth )
934cdf0e10cSrcweir             nTextWidth = nTextHeight;
935cdf0e10cSrcweir 
936cdf0e10cSrcweir         pMetric->mnWidth		= nTextWidth;
937cdf0e10cSrcweir         pMetric->mnAscent		= ( aInfo.m_nAscend * nTextHeight + 500 ) / 1000;
938cdf0e10cSrcweir         pMetric->mnDescent		= ( aInfo.m_nDescend * nTextHeight + 500 ) / 1000;
939cdf0e10cSrcweir         pMetric->mnIntLeading	= ( aInfo.m_nLeading * nTextHeight + 500 ) / 1000;
940cdf0e10cSrcweir         pMetric->mnExtLeading	= 0;
941cdf0e10cSrcweir     }
942cdf0e10cSrcweir }
943cdf0e10cSrcweir 
GetKernPairs(sal_uLong nPairs,ImplKernPairData * pKernPairs)944cdf0e10cSrcweir sal_uLong PspGraphics::GetKernPairs( sal_uLong nPairs, ImplKernPairData *pKernPairs )
945cdf0e10cSrcweir {
946cdf0e10cSrcweir     const ::std::list< ::psp::KernPair >& rPairs( m_pPrinterGfx->getKernPairs() );
947cdf0e10cSrcweir     sal_uLong nHavePairs = rPairs.size();
948cdf0e10cSrcweir     if( pKernPairs && nPairs )
949cdf0e10cSrcweir     {
950cdf0e10cSrcweir         ::std::list< ::psp::KernPair >::const_iterator it;
951cdf0e10cSrcweir         unsigned int i;
952cdf0e10cSrcweir         int nTextScale = m_pPrinterGfx->GetFontWidth();
953cdf0e10cSrcweir         if( ! nTextScale )
954cdf0e10cSrcweir             nTextScale = m_pPrinterGfx->GetFontHeight();
955cdf0e10cSrcweir         for( i = 0, it = rPairs.begin(); i < nPairs && i < nHavePairs; i++, ++it )
956cdf0e10cSrcweir         {
957cdf0e10cSrcweir             pKernPairs[i].mnChar1	= it->first;
958cdf0e10cSrcweir             pKernPairs[i].mnChar2	= it->second;
959cdf0e10cSrcweir             pKernPairs[i].mnKern	= it->kern_x * nTextScale / 1000;
960cdf0e10cSrcweir         }
961cdf0e10cSrcweir 
962cdf0e10cSrcweir     }
963cdf0e10cSrcweir     return nHavePairs;
964cdf0e10cSrcweir }
965cdf0e10cSrcweir 
GetGlyphBoundRect(sal_GlyphId aGlyphId,Rectangle & rRect)966248a599fSHerbert Dürr bool PspGraphics::GetGlyphBoundRect( sal_GlyphId aGlyphId, Rectangle& rRect )
967cdf0e10cSrcweir {
968248a599fSHerbert Dürr     const int nLevel = aGlyphId >> GF_FONTSHIFT;
969cdf0e10cSrcweir     if( nLevel >= MAX_FALLBACK )
970248a599fSHerbert Dürr         return false;
971cdf0e10cSrcweir 
972cdf0e10cSrcweir     ServerFont* pSF = m_pServerFont[ nLevel ];
973cdf0e10cSrcweir     if( !pSF )
974248a599fSHerbert Dürr         return false;
975cdf0e10cSrcweir 
976248a599fSHerbert Dürr     aGlyphId &= ~GF_FONTMASK;
977248a599fSHerbert Dürr     const GlyphMetric& rGM = pSF->GetGlyphMetric( aGlyphId );
978cdf0e10cSrcweir     rRect = Rectangle( rGM.GetOffset(), rGM.GetSize() );
979248a599fSHerbert Dürr     return true;
980cdf0e10cSrcweir }
981cdf0e10cSrcweir 
GetGlyphOutline(sal_GlyphId aGlyphId,::basegfx::B2DPolyPolygon & rB2DPolyPoly)982248a599fSHerbert Dürr bool PspGraphics::GetGlyphOutline( sal_GlyphId aGlyphId,
983cdf0e10cSrcweir     ::basegfx::B2DPolyPolygon& rB2DPolyPoly )
984cdf0e10cSrcweir {
985248a599fSHerbert Dürr     const int nLevel = aGlyphId >> GF_FONTSHIFT;
986cdf0e10cSrcweir     if( nLevel >= MAX_FALLBACK )
987248a599fSHerbert Dürr         return false;
988cdf0e10cSrcweir 
989cdf0e10cSrcweir     ServerFont* pSF = m_pServerFont[ nLevel ];
990cdf0e10cSrcweir     if( !pSF )
991248a599fSHerbert Dürr         return false;
992cdf0e10cSrcweir 
993248a599fSHerbert Dürr     aGlyphId &= ~GF_FONTMASK;
994248a599fSHerbert Dürr     bool bOK = pSF->GetGlyphOutline( aGlyphId, rB2DPolyPoly );
995248a599fSHerbert Dürr     return bOK;
996cdf0e10cSrcweir }
997cdf0e10cSrcweir 
GetTextLayout(ImplLayoutArgs & rArgs,int nFallbackLevel)998cdf0e10cSrcweir SalLayout* PspGraphics::GetTextLayout( ImplLayoutArgs& rArgs, int nFallbackLevel )
999cdf0e10cSrcweir {
1000cdf0e10cSrcweir     // workaround for printers not handling glyph indexing for non-TT fonts
1001cdf0e10cSrcweir     int nFontId = m_pPrinterGfx->GetFontID();
1002cdf0e10cSrcweir     if( psp::fonttype::TrueType != psp::PrintFontManager::get().getFontType( nFontId ) )
1003cdf0e10cSrcweir         rArgs.mnFlags |= SAL_LAYOUT_DISABLE_GLYPH_PROCESSING;
1004cdf0e10cSrcweir     else if( nFallbackLevel > 0 )
1005cdf0e10cSrcweir         rArgs.mnFlags &= ~SAL_LAYOUT_DISABLE_GLYPH_PROCESSING;
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir     GenericSalLayout* pLayout = NULL;
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir     if( m_pServerFont[ nFallbackLevel ]
1010cdf0e10cSrcweir         && !(rArgs.mnFlags & SAL_LAYOUT_DISABLE_GLYPH_PROCESSING) )
1011cdf0e10cSrcweir     {
1012cdf0e10cSrcweir #ifdef ENABLE_GRAPHITE
1013cdf0e10cSrcweir         // Is this a Graphite font?
1014cdf0e10cSrcweir         if (GraphiteFontAdaptor::IsGraphiteEnabledFont(*m_pServerFont[nFallbackLevel]))
1015cdf0e10cSrcweir         {
1016cdf0e10cSrcweir             sal_Int32 xdpi, ydpi;
1017cdf0e10cSrcweir             GetResolution(xdpi, ydpi);
1018cdf0e10cSrcweir             GraphiteFontAdaptor * pGrfont = new GraphiteFontAdaptor( *m_pServerFont[nFallbackLevel], xdpi, ydpi);
1019cdf0e10cSrcweir             if (!pGrfont) return NULL;
1020cdf0e10cSrcweir             pLayout = new GraphiteServerFontLayout(pGrfont);
1021cdf0e10cSrcweir         }
1022cdf0e10cSrcweir         else
1023cdf0e10cSrcweir #endif
1024cdf0e10cSrcweir             pLayout = new PspServerFontLayout( *m_pPrinterGfx, *m_pServerFont[nFallbackLevel], rArgs );
1025cdf0e10cSrcweir     }
1026cdf0e10cSrcweir     else
1027cdf0e10cSrcweir         pLayout = new PspFontLayout( *m_pPrinterGfx );
1028cdf0e10cSrcweir 
1029cdf0e10cSrcweir     return pLayout;
1030cdf0e10cSrcweir }
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir //--------------------------------------------------------------------------
1033cdf0e10cSrcweir 
CreateFontSubset(const rtl::OUString & rToFile,const ImplFontData * pFont,sal_GlyphId * pGlyphIds,sal_uInt8 * pEncoding,sal_Int32 * pWidths,int nGlyphCount,FontSubsetInfo & rInfo)1034cdf0e10cSrcweir sal_Bool PspGraphics::CreateFontSubset(
1035cdf0e10cSrcweir                                    const rtl::OUString& rToFile,
1036cdf0e10cSrcweir                                    const ImplFontData* pFont,
1037248a599fSHerbert Dürr                                    sal_GlyphId* pGlyphIds,
1038cdf0e10cSrcweir                                    sal_uInt8* pEncoding,
1039cdf0e10cSrcweir                                    sal_Int32* pWidths,
1040cdf0e10cSrcweir                                    int nGlyphCount,
1041cdf0e10cSrcweir                                    FontSubsetInfo& rInfo
1042cdf0e10cSrcweir                                    )
1043cdf0e10cSrcweir {
1044cdf0e10cSrcweir     // in this context the pFont->GetFontId() is a valid PSP
1045cdf0e10cSrcweir     // font since they are the only ones left after the PDF
1046cdf0e10cSrcweir     // export has filtered its list of subsettable fonts (for
1047cdf0e10cSrcweir     // which this method was created). The correct way would
1048cdf0e10cSrcweir     // be to have the GlyphCache search for the ImplFontData pFont
1049cdf0e10cSrcweir     psp::fontID aFont = pFont->GetFontId();
1050cdf0e10cSrcweir 
1051cdf0e10cSrcweir     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
1052cdf0e10cSrcweir     bool bSuccess = rMgr.createFontSubset( rInfo,
1053cdf0e10cSrcweir                                  aFont,
1054cdf0e10cSrcweir                                  rToFile,
1055248a599fSHerbert Dürr                                  pGlyphIds,
1056cdf0e10cSrcweir                                  pEncoding,
1057cdf0e10cSrcweir                                  pWidths,
1058cdf0e10cSrcweir                                  nGlyphCount );
1059cdf0e10cSrcweir     return bSuccess;
1060cdf0e10cSrcweir }
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir //--------------------------------------------------------------------------
1063cdf0e10cSrcweir 
GetEmbedFontData(const ImplFontData * pFont,const sal_Ucs * pUnicodes,sal_Int32 * pWidths,FontSubsetInfo & rInfo,long * pDataLen)1064cdf0e10cSrcweir const void* PspGraphics::GetEmbedFontData( const ImplFontData* pFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, FontSubsetInfo& rInfo, long* pDataLen )
1065cdf0e10cSrcweir {
1066cdf0e10cSrcweir     // in this context the pFont->GetFontId() is a valid PSP
1067cdf0e10cSrcweir     // font since they are the only ones left after the PDF
1068cdf0e10cSrcweir     // export has filtered its list of subsettable fonts (for
1069cdf0e10cSrcweir     // which this method was created). The correct way would
1070cdf0e10cSrcweir     // be to have the GlyphCache search for the ImplFontData pFont
1071cdf0e10cSrcweir     psp::fontID aFont = pFont->GetFontId();
1072cdf0e10cSrcweir     return PspGraphics::DoGetEmbedFontData( aFont, pUnicodes, pWidths, rInfo, pDataLen );
1073cdf0e10cSrcweir }
1074cdf0e10cSrcweir 
1075cdf0e10cSrcweir //--------------------------------------------------------------------------
1076cdf0e10cSrcweir 
FreeEmbedFontData(const void * pData,long nLen)1077cdf0e10cSrcweir void PspGraphics::FreeEmbedFontData( const void* pData, long nLen )
1078cdf0e10cSrcweir {
1079cdf0e10cSrcweir     PspGraphics::DoFreeEmbedFontData( pData, nLen );
1080cdf0e10cSrcweir }
1081cdf0e10cSrcweir 
1082cdf0e10cSrcweir //--------------------------------------------------------------------------
1083cdf0e10cSrcweir 
GetFontEncodingVector(const ImplFontData * pFont,const Ucs2OStrMap ** pNonEncoded)1084cdf0e10cSrcweir const Ucs2SIntMap* PspGraphics::GetFontEncodingVector( const ImplFontData* pFont, const Ucs2OStrMap** pNonEncoded )
1085cdf0e10cSrcweir {
1086cdf0e10cSrcweir     // in this context the pFont->GetFontId() is a valid PSP
1087cdf0e10cSrcweir     // font since they are the only ones left after the PDF
1088cdf0e10cSrcweir     // export has filtered its list of subsettable fonts (for
1089cdf0e10cSrcweir     // which this method was created). The correct way would
1090cdf0e10cSrcweir     // be to have the GlyphCache search for the ImplFontData pFont
1091cdf0e10cSrcweir     psp::fontID aFont = pFont->GetFontId();
1092cdf0e10cSrcweir     return PspGraphics::DoGetFontEncodingVector( aFont, pNonEncoded );
1093cdf0e10cSrcweir }
1094cdf0e10cSrcweir 
1095cdf0e10cSrcweir //--------------------------------------------------------------------------
1096cdf0e10cSrcweir 
GetGlyphWidths(const ImplFontData * pFont,bool bVertical,Int32Vector & rWidths,Ucs2UIntMap & rUnicodeEnc)1097cdf0e10cSrcweir void PspGraphics::GetGlyphWidths( const ImplFontData* pFont,
1098cdf0e10cSrcweir                                   bool bVertical,
1099cdf0e10cSrcweir                                   Int32Vector& rWidths,
1100cdf0e10cSrcweir                                   Ucs2UIntMap& rUnicodeEnc )
1101cdf0e10cSrcweir {
1102cdf0e10cSrcweir     // in this context the pFont->GetFontId() is a valid PSP
1103cdf0e10cSrcweir     // font since they are the only ones left after the PDF
1104cdf0e10cSrcweir     // export has filtered its list of subsettable fonts (for
1105cdf0e10cSrcweir     // which this method was created). The correct way would
1106cdf0e10cSrcweir     // be to have the GlyphCache search for the ImplFontData pFont
1107cdf0e10cSrcweir     psp::fontID aFont = pFont->GetFontId();
1108cdf0e10cSrcweir     PspGraphics::DoGetGlyphWidths( aFont, bVertical, rWidths, rUnicodeEnc );
1109cdf0e10cSrcweir }
1110cdf0e10cSrcweir 
1111cdf0e10cSrcweir 
1112cdf0e10cSrcweir // static helpers of PspGraphics
1113cdf0e10cSrcweir 
DoGetEmbedFontData(fontID aFont,const sal_Ucs * pUnicodes,sal_Int32 * pWidths,FontSubsetInfo & rInfo,long * pDataLen)1114cdf0e10cSrcweir const void* PspGraphics::DoGetEmbedFontData( fontID aFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, FontSubsetInfo& rInfo, long* pDataLen )
1115cdf0e10cSrcweir {
1116cdf0e10cSrcweir     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir     psp::PrintFontInfo aFontInfo;
1119cdf0e10cSrcweir     if( ! rMgr.getFontInfo( aFont, aFontInfo ) )
1120cdf0e10cSrcweir         return NULL;
1121cdf0e10cSrcweir 
1122cdf0e10cSrcweir     // fill in font info
1123cdf0e10cSrcweir     rInfo.m_nAscent		= aFontInfo.m_nAscend;
1124cdf0e10cSrcweir     rInfo.m_nDescent	= aFontInfo.m_nDescend;
1125cdf0e10cSrcweir     rInfo.m_aPSName		= rMgr.getPSName( aFont );
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir     int xMin, yMin, xMax, yMax;
1128cdf0e10cSrcweir     rMgr.getFontBoundingBox( aFont, xMin, yMin, xMax, yMax );
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir     psp::CharacterMetric aMetrics[256];
1131cdf0e10cSrcweir     sal_Ucs aUnicodes[256];
1132cdf0e10cSrcweir     if( aFontInfo.m_aEncoding == RTL_TEXTENCODING_SYMBOL && aFontInfo.m_eType == psp::fonttype::Type1 )
1133cdf0e10cSrcweir     {
1134cdf0e10cSrcweir         for( int i = 0; i < 256; i++ )
1135cdf0e10cSrcweir             aUnicodes[i] = pUnicodes[i] < 0x0100 ? pUnicodes[i] + 0xf000 : pUnicodes[i];
1136cdf0e10cSrcweir         pUnicodes = aUnicodes;
1137cdf0e10cSrcweir     }
1138cdf0e10cSrcweir     if( ! rMgr.getMetrics( aFont, pUnicodes, 256, aMetrics ) )
1139cdf0e10cSrcweir         return NULL;
1140cdf0e10cSrcweir 
1141cdf0e10cSrcweir     OString aSysPath = rMgr.getFontFileSysPath( aFont );
1142cdf0e10cSrcweir     struct stat aStat;
1143cdf0e10cSrcweir     if( stat( aSysPath.getStr(), &aStat ) )
1144cdf0e10cSrcweir         return NULL;
1145cdf0e10cSrcweir     int fd = open( aSysPath.getStr(), O_RDONLY );
1146cdf0e10cSrcweir     if( fd < 0 )
1147cdf0e10cSrcweir         return NULL;
1148cdf0e10cSrcweir     void* pFile = mmap( NULL, aStat.st_size, PROT_READ, MAP_SHARED, fd, 0 );
1149cdf0e10cSrcweir     close( fd );
1150cdf0e10cSrcweir     if( pFile == MAP_FAILED )
1151cdf0e10cSrcweir         return NULL;
1152cdf0e10cSrcweir 
1153cdf0e10cSrcweir     *pDataLen = aStat.st_size;
1154cdf0e10cSrcweir 
1155cdf0e10cSrcweir     rInfo.m_aFontBBox	= Rectangle( Point( xMin, yMin ), Size( xMax-xMin, yMax-yMin ) );
1156cdf0e10cSrcweir     rInfo.m_nCapHeight	= yMax; // Well ...
1157cdf0e10cSrcweir 
1158cdf0e10cSrcweir     for( int i = 0; i < 256; i++ )
1159cdf0e10cSrcweir         pWidths[i] = (aMetrics[i].width > 0 ? aMetrics[i].width : 0);
1160cdf0e10cSrcweir 
1161cdf0e10cSrcweir     switch( aFontInfo.m_eType )
1162cdf0e10cSrcweir     {
1163cdf0e10cSrcweir         case psp::fonttype::TrueType:
1164cdf0e10cSrcweir             rInfo.m_nFontType = FontSubsetInfo::SFNT_TTF;
1165cdf0e10cSrcweir             break;
1166cdf0e10cSrcweir         case psp::fonttype::Type1: {
1167cdf0e10cSrcweir             const bool bPFA = ((*(unsigned char*)pFile) < 0x80);
1168cdf0e10cSrcweir             rInfo.m_nFontType = bPFA ? FontSubsetInfo::TYPE1_PFA : FontSubsetInfo::TYPE1_PFB;
1169cdf0e10cSrcweir             }
1170cdf0e10cSrcweir             break;
1171cdf0e10cSrcweir         default:
1172cdf0e10cSrcweir             return NULL;
1173cdf0e10cSrcweir     }
1174cdf0e10cSrcweir 
1175cdf0e10cSrcweir     return pFile;
1176cdf0e10cSrcweir }
1177cdf0e10cSrcweir 
DoFreeEmbedFontData(const void * pData,long nLen)1178cdf0e10cSrcweir void PspGraphics::DoFreeEmbedFontData( const void* pData, long nLen )
1179cdf0e10cSrcweir {
1180cdf0e10cSrcweir     if( pData )
1181cdf0e10cSrcweir         munmap( (char*)pData, nLen );
1182cdf0e10cSrcweir }
1183cdf0e10cSrcweir 
DoGetFontEncodingVector(fontID aFont,const Ucs2OStrMap ** pNonEncoded)1184cdf0e10cSrcweir const Ucs2SIntMap* PspGraphics::DoGetFontEncodingVector( fontID aFont, const Ucs2OStrMap** pNonEncoded )
1185cdf0e10cSrcweir {
1186cdf0e10cSrcweir     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
1187cdf0e10cSrcweir 
1188cdf0e10cSrcweir     psp::PrintFontInfo aFontInfo;
1189cdf0e10cSrcweir     if( ! rMgr.getFontInfo( aFont, aFontInfo ) )
1190cdf0e10cSrcweir     {
1191cdf0e10cSrcweir         if( pNonEncoded )
1192cdf0e10cSrcweir             *pNonEncoded = NULL;
1193cdf0e10cSrcweir         return NULL;
1194cdf0e10cSrcweir     }
1195cdf0e10cSrcweir 
1196cdf0e10cSrcweir     return rMgr.getEncodingMap( aFont, pNonEncoded );
1197cdf0e10cSrcweir }
1198cdf0e10cSrcweir 
DoGetGlyphWidths(psp::fontID aFont,bool bVertical,Int32Vector & rWidths,Ucs2UIntMap & rUnicodeEnc)1199cdf0e10cSrcweir void PspGraphics::DoGetGlyphWidths( psp::fontID aFont,
1200cdf0e10cSrcweir                                     bool bVertical,
1201cdf0e10cSrcweir                                     Int32Vector& rWidths,
1202cdf0e10cSrcweir                                     Ucs2UIntMap& rUnicodeEnc )
1203cdf0e10cSrcweir {
1204cdf0e10cSrcweir     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
1205cdf0e10cSrcweir     rMgr.getGlyphWidths( aFont, bVertical, rWidths, rUnicodeEnc );
1206cdf0e10cSrcweir }
1207cdf0e10cSrcweir // ----------------------------------------------------------------------------
1208cdf0e10cSrcweir 
ToFontWidth(psp::width::type eWidth)1209cdf0e10cSrcweir FontWidth PspGraphics::ToFontWidth (psp::width::type eWidth)
1210cdf0e10cSrcweir {
1211cdf0e10cSrcweir 	switch (eWidth)
1212cdf0e10cSrcweir 	{
1213cdf0e10cSrcweir 		case psp::width::UltraCondensed: return WIDTH_ULTRA_CONDENSED;
1214cdf0e10cSrcweir 		case psp::width::ExtraCondensed: return WIDTH_EXTRA_CONDENSED;
1215cdf0e10cSrcweir 		case psp::width::Condensed:		 return WIDTH_CONDENSED;
1216cdf0e10cSrcweir 		case psp::width::SemiCondensed:	 return WIDTH_SEMI_CONDENSED;
1217cdf0e10cSrcweir 		case psp::width::Normal:		 return WIDTH_NORMAL;
1218cdf0e10cSrcweir 		case psp::width::SemiExpanded:	 return WIDTH_SEMI_EXPANDED;
1219cdf0e10cSrcweir 		case psp::width::Expanded:		 return WIDTH_EXPANDED;
1220cdf0e10cSrcweir 		case psp::width::ExtraExpanded:	 return WIDTH_EXTRA_EXPANDED;
1221cdf0e10cSrcweir 		case psp::width::UltraExpanded:	 return WIDTH_ULTRA_EXPANDED;
1222cdf0e10cSrcweir         case psp::width::Unknown:        return WIDTH_DONTKNOW;
1223cdf0e10cSrcweir         default:
1224cdf0e10cSrcweir             DBG_ERROR( "unknown width mapping" );
1225cdf0e10cSrcweir             break;
1226cdf0e10cSrcweir 	}
1227cdf0e10cSrcweir 	return WIDTH_DONTKNOW;
1228cdf0e10cSrcweir }
1229cdf0e10cSrcweir 
ToFontWeight(psp::weight::type eWeight)1230cdf0e10cSrcweir FontWeight PspGraphics::ToFontWeight (psp::weight::type eWeight)
1231cdf0e10cSrcweir {
1232cdf0e10cSrcweir 	switch (eWeight)
1233cdf0e10cSrcweir 	{
1234cdf0e10cSrcweir 		case psp::weight::Thin:		  return WEIGHT_THIN;
1235cdf0e10cSrcweir 		case psp::weight::UltraLight: return WEIGHT_ULTRALIGHT;
1236cdf0e10cSrcweir 		case psp::weight::Light:	  return WEIGHT_LIGHT;
1237cdf0e10cSrcweir 		case psp::weight::SemiLight:  return WEIGHT_SEMILIGHT;
1238cdf0e10cSrcweir 		case psp::weight::Normal:	  return WEIGHT_NORMAL;
1239cdf0e10cSrcweir 		case psp::weight::Medium:	  return WEIGHT_MEDIUM;
1240cdf0e10cSrcweir 		case psp::weight::SemiBold:	  return WEIGHT_SEMIBOLD;
1241cdf0e10cSrcweir 		case psp::weight::Bold:		  return WEIGHT_BOLD;
1242cdf0e10cSrcweir 		case psp::weight::UltraBold:  return WEIGHT_ULTRABOLD;
1243cdf0e10cSrcweir 		case psp::weight::Black:	  return WEIGHT_BLACK;
1244cdf0e10cSrcweir 		case psp::weight::Unknown:	  return WEIGHT_DONTKNOW;
1245cdf0e10cSrcweir         default:
1246cdf0e10cSrcweir             DBG_ERROR( "unknown weight mapping" );
1247cdf0e10cSrcweir             break;
1248cdf0e10cSrcweir 	}
1249cdf0e10cSrcweir 	return WEIGHT_DONTKNOW;
1250cdf0e10cSrcweir }
1251cdf0e10cSrcweir 
ToFontPitch(psp::pitch::type ePitch)1252cdf0e10cSrcweir FontPitch PspGraphics::ToFontPitch (psp::pitch::type ePitch)
1253cdf0e10cSrcweir {
1254cdf0e10cSrcweir 	switch (ePitch)
1255cdf0e10cSrcweir 	{
1256cdf0e10cSrcweir 		case psp::pitch::Fixed:		return PITCH_FIXED;
1257cdf0e10cSrcweir 		case psp::pitch::Variable:	return PITCH_VARIABLE;
1258cdf0e10cSrcweir 		case psp::pitch::Unknown:	return PITCH_DONTKNOW;
1259cdf0e10cSrcweir         default:
1260cdf0e10cSrcweir             DBG_ERROR( "unknown pitch mapping" );
1261cdf0e10cSrcweir             break;
1262cdf0e10cSrcweir 	}
1263cdf0e10cSrcweir 	return PITCH_DONTKNOW;
1264cdf0e10cSrcweir }
1265cdf0e10cSrcweir 
ToFontItalic(psp::italic::type eItalic)1266cdf0e10cSrcweir FontItalic PspGraphics::ToFontItalic (psp::italic::type eItalic)
1267cdf0e10cSrcweir {
1268cdf0e10cSrcweir 	switch (eItalic)
1269cdf0e10cSrcweir 	{
1270cdf0e10cSrcweir 		case psp::italic::Upright:	return ITALIC_NONE;
1271cdf0e10cSrcweir 		case psp::italic::Oblique:	return ITALIC_OBLIQUE;
1272cdf0e10cSrcweir 		case psp::italic::Italic:	return ITALIC_NORMAL;
1273cdf0e10cSrcweir 		case psp::italic::Unknown:	return ITALIC_DONTKNOW;
1274cdf0e10cSrcweir         default:
1275cdf0e10cSrcweir             DBG_ERROR( "unknown italic mapping" );
1276cdf0e10cSrcweir             break;
1277cdf0e10cSrcweir 	}
1278cdf0e10cSrcweir 	return ITALIC_DONTKNOW;
1279cdf0e10cSrcweir }
1280cdf0e10cSrcweir 
ToFontFamily(psp::family::type eFamily)1281cdf0e10cSrcweir FontFamily PspGraphics::ToFontFamily (psp::family::type eFamily)
1282cdf0e10cSrcweir {
1283cdf0e10cSrcweir 	switch (eFamily)
1284cdf0e10cSrcweir 	{
1285cdf0e10cSrcweir 		case psp::family::Decorative: return FAMILY_DECORATIVE;
1286cdf0e10cSrcweir 		case psp::family::Modern:	  return FAMILY_MODERN;
1287cdf0e10cSrcweir 		case psp::family::Roman:	  return FAMILY_ROMAN;
1288cdf0e10cSrcweir 		case psp::family::Script:	  return FAMILY_SCRIPT;
1289cdf0e10cSrcweir 		case psp::family::Swiss:	  return FAMILY_SWISS;
1290cdf0e10cSrcweir 		case psp::family::System:	  return FAMILY_SYSTEM;
1291cdf0e10cSrcweir 		case psp::family::Unknown:	  return FAMILY_DONTKNOW;
1292cdf0e10cSrcweir         default:
1293cdf0e10cSrcweir             DBG_ERROR( "unknown family mapping" );
1294cdf0e10cSrcweir             break;
1295cdf0e10cSrcweir 	}
1296cdf0e10cSrcweir 	return FAMILY_DONTKNOW;
1297cdf0e10cSrcweir }
1298cdf0e10cSrcweir 
Info2DevFontAttributes(const psp::FastPrintFontInfo & rInfo)1299cdf0e10cSrcweir ImplDevFontAttributes PspGraphics::Info2DevFontAttributes( const psp::FastPrintFontInfo& rInfo )
1300cdf0e10cSrcweir {
1301cdf0e10cSrcweir     ImplDevFontAttributes aDFA;
1302cdf0e10cSrcweir     aDFA.maName         = rInfo.m_aFamilyName;
1303cdf0e10cSrcweir     aDFA.maStyleName    = rInfo.m_aStyleName;
1304cdf0e10cSrcweir     aDFA.meFamily       = ToFontFamily (rInfo.m_eFamilyStyle);
1305cdf0e10cSrcweir     aDFA.meWeight       = ToFontWeight (rInfo.m_eWeight);
1306cdf0e10cSrcweir     aDFA.meItalic       = ToFontItalic (rInfo.m_eItalic);
1307cdf0e10cSrcweir     aDFA.meWidthType    = ToFontWidth (rInfo.m_eWidth);
1308cdf0e10cSrcweir     aDFA.mePitch        = ToFontPitch (rInfo.m_ePitch);
1309cdf0e10cSrcweir     aDFA.mbSymbolFlag   = (rInfo.m_aEncoding == RTL_TEXTENCODING_SYMBOL);
1310cdf0e10cSrcweir     aDFA.mbSubsettable  = rInfo.m_bSubsettable;
1311cdf0e10cSrcweir     aDFA.mbEmbeddable   = rInfo.m_bEmbeddable;
1312cdf0e10cSrcweir 
1313cdf0e10cSrcweir     switch( rInfo.m_eType )
1314cdf0e10cSrcweir     {
1315cdf0e10cSrcweir         case psp::fonttype::Builtin:
1316cdf0e10cSrcweir             aDFA.mnQuality       = 1024;
1317cdf0e10cSrcweir             aDFA.mbDevice        = true;
1318cdf0e10cSrcweir             break;
1319cdf0e10cSrcweir         case psp::fonttype::TrueType:
1320cdf0e10cSrcweir             aDFA.mnQuality       = 512;
1321cdf0e10cSrcweir             aDFA.mbDevice        = false;
1322cdf0e10cSrcweir             break;
1323cdf0e10cSrcweir         case psp::fonttype::Type1:
1324cdf0e10cSrcweir             aDFA.mnQuality       = 0;
1325cdf0e10cSrcweir             aDFA.mbDevice        = false;
1326cdf0e10cSrcweir             break;
1327cdf0e10cSrcweir         default:
1328cdf0e10cSrcweir             aDFA.mnQuality       = 0;
1329cdf0e10cSrcweir             aDFA.mbDevice        = false;
1330cdf0e10cSrcweir             break;
1331cdf0e10cSrcweir     }
1332cdf0e10cSrcweir 
1333cdf0e10cSrcweir     aDFA.mbOrientation   = true;
1334cdf0e10cSrcweir 
1335cdf0e10cSrcweir     // add font family name aliases
1336cdf0e10cSrcweir     ::std::list< OUString >::const_iterator it = rInfo.m_aAliases.begin();
1337cdf0e10cSrcweir     bool bHasMapNames = false;
1338cdf0e10cSrcweir     for(; it != rInfo.m_aAliases.end(); ++it )
1339cdf0e10cSrcweir     {
1340cdf0e10cSrcweir         if( bHasMapNames )
1341cdf0e10cSrcweir             aDFA.maMapNames.Append( ';' );
1342cdf0e10cSrcweir         aDFA.maMapNames.Append( (*it).getStr() );
1343cdf0e10cSrcweir 	bHasMapNames = true;
1344cdf0e10cSrcweir     }
1345cdf0e10cSrcweir 
1346cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 2
1347cdf0e10cSrcweir     if( bHasMapNames )
1348cdf0e10cSrcweir     {
1349cdf0e10cSrcweir         ByteString aOrigName( aDFA.maName, osl_getThreadTextEncoding() );
1350cdf0e10cSrcweir         ByteString aAliasNames( aDFA.maMapNames, osl_getThreadTextEncoding() );
1351cdf0e10cSrcweir         fprintf( stderr, "using alias names \"%s\" for font family \"%s\"\n",
1352cdf0e10cSrcweir             aAliasNames.GetBuffer(), aOrigName.GetBuffer() );
1353cdf0e10cSrcweir     }
1354cdf0e10cSrcweir #endif
1355cdf0e10cSrcweir 
1356cdf0e10cSrcweir     return aDFA;
1357cdf0e10cSrcweir }
1358cdf0e10cSrcweir 
1359cdf0e10cSrcweir // -----------------------------------------------------------------------
1360cdf0e10cSrcweir 
AnnounceFonts(ImplDevFontList * pFontList,const psp::FastPrintFontInfo & aInfo)1361cdf0e10cSrcweir void PspGraphics::AnnounceFonts( ImplDevFontList* pFontList, const psp::FastPrintFontInfo& aInfo )
1362cdf0e10cSrcweir {
1363cdf0e10cSrcweir     int nQuality = 0;
1364cdf0e10cSrcweir 
1365cdf0e10cSrcweir     if( aInfo.m_eType == psp::fonttype::TrueType )
1366cdf0e10cSrcweir     {
1367cdf0e10cSrcweir         // asian type 1 fonts are not known
1368cdf0e10cSrcweir         psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
1369cdf0e10cSrcweir         ByteString aFileName( rMgr.getFontFileSysPath( aInfo.m_nID ) );
1370cdf0e10cSrcweir         int nPos = aFileName.SearchBackward( '_' );
1371cdf0e10cSrcweir         if( nPos == STRING_NOTFOUND || aFileName.GetChar( nPos+1 ) == '.' )
1372cdf0e10cSrcweir             nQuality += 5;
1373cdf0e10cSrcweir         else
1374cdf0e10cSrcweir         {
1375cdf0e10cSrcweir             static const char* pLangBoost = NULL;
1376cdf0e10cSrcweir             static bool bOnce = true;
1377cdf0e10cSrcweir             if( bOnce )
1378cdf0e10cSrcweir             {
1379cdf0e10cSrcweir                 bOnce = false;
1380cdf0e10cSrcweir                 const LanguageType aLang = Application::GetSettings().GetUILanguage();
1381cdf0e10cSrcweir                 switch( aLang )
1382cdf0e10cSrcweir                 {
1383cdf0e10cSrcweir                     case LANGUAGE_JAPANESE:
1384cdf0e10cSrcweir                         pLangBoost = "jan";
1385cdf0e10cSrcweir                         break;
1386cdf0e10cSrcweir                     case LANGUAGE_CHINESE:
1387cdf0e10cSrcweir                     case LANGUAGE_CHINESE_SIMPLIFIED:
1388cdf0e10cSrcweir                     case LANGUAGE_CHINESE_SINGAPORE:
1389cdf0e10cSrcweir                         pLangBoost = "zhs";
1390cdf0e10cSrcweir                         break;
1391cdf0e10cSrcweir                     case LANGUAGE_CHINESE_TRADITIONAL:
1392cdf0e10cSrcweir                     case LANGUAGE_CHINESE_HONGKONG:
1393cdf0e10cSrcweir                     case LANGUAGE_CHINESE_MACAU:
1394cdf0e10cSrcweir                         pLangBoost = "zht";
1395cdf0e10cSrcweir                         break;
1396cdf0e10cSrcweir                     case LANGUAGE_KOREAN:
1397cdf0e10cSrcweir                     case LANGUAGE_KOREAN_JOHAB:
1398cdf0e10cSrcweir                         pLangBoost = "kor";
1399cdf0e10cSrcweir                         break;
1400cdf0e10cSrcweir                 }
1401cdf0e10cSrcweir             }
1402cdf0e10cSrcweir 
1403cdf0e10cSrcweir             if( pLangBoost )
1404cdf0e10cSrcweir                 if( aFileName.Copy( nPos+1, 3 ).EqualsIgnoreCaseAscii( pLangBoost ) )
1405cdf0e10cSrcweir                     nQuality += 10;
1406cdf0e10cSrcweir         }
1407cdf0e10cSrcweir     }
1408cdf0e10cSrcweir 
1409cdf0e10cSrcweir     ImplPspFontData* pFD = new ImplPspFontData( aInfo );
1410cdf0e10cSrcweir     pFD->mnQuality += nQuality;
1411cdf0e10cSrcweir     pFontList->Add( pFD );
1412cdf0e10cSrcweir }
1413cdf0e10cSrcweir 
filterText(const String & rOrig,String & rNewText,xub_StrLen nIndex,xub_StrLen & rLen,xub_StrLen & rCutStart,xub_StrLen & rCutStop)1414cdf0e10cSrcweir bool PspGraphics::filterText( const String& rOrig, String& rNewText, xub_StrLen nIndex, xub_StrLen& rLen, xub_StrLen& rCutStart, xub_StrLen& rCutStop )
1415cdf0e10cSrcweir {
1416cdf0e10cSrcweir 	if( ! m_pPhoneNr )
1417cdf0e10cSrcweir 		return false;
1418cdf0e10cSrcweir 
1419cdf0e10cSrcweir     rCutStop = rCutStart = STRING_NOTFOUND;
1420cdf0e10cSrcweir 
1421cdf0e10cSrcweir #define FAX_PHONE_TOKEN          "@@#"
1422cdf0e10cSrcweir #define FAX_PHONE_TOKEN_LENGTH   3
1423cdf0e10cSrcweir #define FAX_END_TOKEN            "@@"
1424cdf0e10cSrcweir #define FAX_END_TOKEN_LENGTH     2
1425cdf0e10cSrcweir 
1426cdf0e10cSrcweir 	bool bRet = false;
1427cdf0e10cSrcweir 	bool bStarted = false;
1428cdf0e10cSrcweir 	bool bStopped = false;
1429cdf0e10cSrcweir 	sal_uInt16 nPos;
1430cdf0e10cSrcweir 	sal_uInt16 nStart = 0;
1431cdf0e10cSrcweir 	sal_uInt16 nStop = rLen;
1432cdf0e10cSrcweir 	String aPhone = rOrig.Copy( nIndex, rLen );
1433cdf0e10cSrcweir 
1434cdf0e10cSrcweir 	if( ! m_bPhoneCollectionActive )
1435cdf0e10cSrcweir 	{
1436cdf0e10cSrcweir 		if( ( nPos = aPhone.SearchAscii( FAX_PHONE_TOKEN ) ) != STRING_NOTFOUND )
1437cdf0e10cSrcweir 		{
1438cdf0e10cSrcweir 			nStart = nPos;
1439cdf0e10cSrcweir 			m_bPhoneCollectionActive = true;
1440cdf0e10cSrcweir 			m_aPhoneCollection.Erase();
1441cdf0e10cSrcweir 			bRet = true;
1442cdf0e10cSrcweir 			bStarted = true;
1443cdf0e10cSrcweir 		}
1444cdf0e10cSrcweir 	}
1445cdf0e10cSrcweir 	if( m_bPhoneCollectionActive )
1446cdf0e10cSrcweir 	{
1447cdf0e10cSrcweir 		bRet = true;
1448cdf0e10cSrcweir 		nPos = bStarted ? nStart + FAX_PHONE_TOKEN_LENGTH : 0;
1449cdf0e10cSrcweir 		if( ( nPos = aPhone.SearchAscii( FAX_END_TOKEN, nPos ) ) != STRING_NOTFOUND )
1450cdf0e10cSrcweir 		{
1451cdf0e10cSrcweir 			m_bPhoneCollectionActive = false;
1452cdf0e10cSrcweir 			nStop = nPos + FAX_END_TOKEN_LENGTH;
1453cdf0e10cSrcweir 			bStopped = true;
1454cdf0e10cSrcweir 		}
1455cdf0e10cSrcweir 		int nTokenStart = nStart + (bStarted ? FAX_PHONE_TOKEN_LENGTH : 0);
1456cdf0e10cSrcweir 		int nTokenStop = nStop - (bStopped ? FAX_END_TOKEN_LENGTH : 0);
1457cdf0e10cSrcweir 		m_aPhoneCollection += aPhone.Copy( nTokenStart, nTokenStop - nTokenStart );
1458cdf0e10cSrcweir 		if( ! m_bPhoneCollectionActive )
1459cdf0e10cSrcweir 		{
1460cdf0e10cSrcweir             m_pPhoneNr->AppendAscii( "<Fax#>" );
1461cdf0e10cSrcweir 			m_pPhoneNr->Append( m_aPhoneCollection );
1462cdf0e10cSrcweir             m_pPhoneNr->AppendAscii( "</Fax#>" );
1463cdf0e10cSrcweir 			m_aPhoneCollection.Erase();
1464cdf0e10cSrcweir 		}
1465cdf0e10cSrcweir 	}
1466cdf0e10cSrcweir 	if( m_aPhoneCollection.Len() > 1024 )
1467cdf0e10cSrcweir 	{
1468cdf0e10cSrcweir 		m_bPhoneCollectionActive = false;
1469cdf0e10cSrcweir 		m_aPhoneCollection.Erase();
1470cdf0e10cSrcweir 		bRet = false;
1471cdf0e10cSrcweir 	}
1472cdf0e10cSrcweir 
1473cdf0e10cSrcweir     if( bRet && m_bSwallowFaxNo )
1474cdf0e10cSrcweir     {
1475cdf0e10cSrcweir         rLen -= nStop - nStart;
1476cdf0e10cSrcweir         rCutStart = nStart+nIndex;
1477cdf0e10cSrcweir         rCutStop = nStop+nIndex;
1478cdf0e10cSrcweir         if( rCutStart )
1479cdf0e10cSrcweir             rNewText = rOrig.Copy( 0, rCutStart );
1480cdf0e10cSrcweir         rNewText += rOrig.Copy( rCutStop );
1481cdf0e10cSrcweir     }
1482cdf0e10cSrcweir 
1483cdf0e10cSrcweir     return bRet && m_bSwallowFaxNo;
1484cdf0e10cSrcweir }
1485cdf0e10cSrcweir 
drawAlphaBitmap(const SalTwoRect &,const SalBitmap &,const SalBitmap &)1486cdf0e10cSrcweir bool PspGraphics::drawAlphaBitmap( const SalTwoRect&,
1487cdf0e10cSrcweir                                    const SalBitmap&,
1488cdf0e10cSrcweir                                    const SalBitmap& )
1489cdf0e10cSrcweir {
1490cdf0e10cSrcweir     return false;
1491cdf0e10cSrcweir }
1492cdf0e10cSrcweir 
drawTransformedBitmap(const basegfx::B2DPoint & rNull,const basegfx::B2DPoint & rX,const basegfx::B2DPoint & rY,const SalBitmap & rSourceBitmap,const SalBitmap * pAlphaBitmap)14935f27b83cSArmin Le Grand bool PspGraphics::drawTransformedBitmap(
14945f27b83cSArmin Le Grand     const basegfx::B2DPoint& rNull,
14955f27b83cSArmin Le Grand     const basegfx::B2DPoint& rX,
14965f27b83cSArmin Le Grand     const basegfx::B2DPoint& rY,
14975f27b83cSArmin Le Grand     const SalBitmap& rSourceBitmap,
14985f27b83cSArmin Le Grand     const SalBitmap* pAlphaBitmap)
14995f27b83cSArmin Le Grand {
15005f27b83cSArmin Le Grand     // here direct support for transformed bitmaps can be impemented
15015f27b83cSArmin Le Grand     (void)rNull; (void)rX; (void)rY; (void)rSourceBitmap; (void)pAlphaBitmap;
15025f27b83cSArmin Le Grand     return false;
15035f27b83cSArmin Le Grand }
15045f27b83cSArmin Le Grand 
drawAlphaRect(long,long,long,long,sal_uInt8)1505cdf0e10cSrcweir bool PspGraphics::drawAlphaRect( long, long, long, long, sal_uInt8 )
1506cdf0e10cSrcweir {
1507cdf0e10cSrcweir     return false;
1508cdf0e10cSrcweir }
1509cdf0e10cSrcweir 
GetGraphicsData() const1510cdf0e10cSrcweir SystemGraphicsData PspGraphics::GetGraphicsData() const
1511cdf0e10cSrcweir {
1512cdf0e10cSrcweir     SystemGraphicsData aRes;
1513cdf0e10cSrcweir     aRes.nSize = sizeof(aRes);
1514cdf0e10cSrcweir         aRes.hDrawable = 0;
1515cdf0e10cSrcweir         aRes.pRenderFormat = 0;
1516cdf0e10cSrcweir     return aRes;
1517cdf0e10cSrcweir }
1518cdf0e10cSrcweir 
GetSysFontData(int nFallbacklevel) const1519cdf0e10cSrcweir SystemFontData PspGraphics::GetSysFontData( int nFallbacklevel ) const
1520cdf0e10cSrcweir {
1521cdf0e10cSrcweir     SystemFontData aSysFontData;
1522cdf0e10cSrcweir 
1523cdf0e10cSrcweir     if (nFallbacklevel >= MAX_FALLBACK) nFallbacklevel = MAX_FALLBACK - 1;
1524cdf0e10cSrcweir     if (nFallbacklevel < 0 ) nFallbacklevel = 0;
1525cdf0e10cSrcweir 
1526cdf0e10cSrcweir     aSysFontData.nSize = sizeof( SystemFontData );
1527cdf0e10cSrcweir     aSysFontData.nFontId = 0;
1528cdf0e10cSrcweir     aSysFontData.nFontFlags = 0;
1529cdf0e10cSrcweir     aSysFontData.bFakeBold = false;
1530cdf0e10cSrcweir     aSysFontData.bFakeItalic = false;
1531cdf0e10cSrcweir     aSysFontData.bAntialias = true;
1532cdf0e10cSrcweir     return aSysFontData;
1533cdf0e10cSrcweir }
1534cdf0e10cSrcweir 
supportsOperation(OutDevSupportType) const1535cdf0e10cSrcweir bool PspGraphics::supportsOperation( OutDevSupportType ) const
1536cdf0e10cSrcweir {
1537cdf0e10cSrcweir     return false;
1538cdf0e10cSrcweir }
1539