xref: /AOO41X/main/vcl/os2/source/gdi/salgdi.cxx (revision 9f62ea84a806e17e6f2bbff75724a7257a0eb5d9)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <string.h>
25cdf0e10cSrcweir #include <svpm.h>
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #define _SV_SALGDI_CXX
28cdf0e10cSrcweir #include <tools/debug.hxx>
29cdf0e10cSrcweir #include <saldata.hxx>
30cdf0e10cSrcweir #include <salgdi.h>
31cdf0e10cSrcweir #include <tools/debug.hxx>
32cdf0e10cSrcweir #include <salframe.h>
33cdf0e10cSrcweir #include <tools/poly.hxx>
34cdf0e10cSrcweir #ifndef _RTL_STRINGBUF_HXX
35cdf0e10cSrcweir #include <rtl/strbuf.hxx>
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir #include "vcl/region.h"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #ifndef __H_FT2LIB
40cdf0e10cSrcweir #include <wingdi.h>
41cdf0e10cSrcweir #include <ft2lib.h>
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir 
44cdf0e10cSrcweir // -----------
45cdf0e10cSrcweir // - Defines -
46cdf0e10cSrcweir // -----------
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // ClipRegions funktionieren immer noch nicht auf allen getesteten Druckern
49cdf0e10cSrcweir #define SAL_PRINTER_CLIPPATH	1
50cdf0e10cSrcweir // #define SAL_PRINTER_POLYPATH 1
51cdf0e10cSrcweir 
52cdf0e10cSrcweir // =======================================================================
53cdf0e10cSrcweir 
54cdf0e10cSrcweir void ImplInitSalGDI()
55cdf0e10cSrcweir {
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir // -----------------------------------------------------------------------
59cdf0e10cSrcweir 
60cdf0e10cSrcweir void ImplFreeSalGDI()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	SalData*	pSalData = GetSalData();
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     // delete icon cache
65cdf0e10cSrcweir     SalIcon* pIcon = pSalData->mpFirstIcon;
66cdf0e10cSrcweir     while( pIcon )
67cdf0e10cSrcweir     {
68cdf0e10cSrcweir         SalIcon* pTmp = pIcon->pNext;
69cdf0e10cSrcweir         WinDestroyPointer( pIcon->hIcon );
70cdf0e10cSrcweir         delete pIcon;
71cdf0e10cSrcweir         pIcon = pTmp;
72cdf0e10cSrcweir     }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir // =======================================================================
77cdf0e10cSrcweir 
78cdf0e10cSrcweir void ImplSalInitGraphics( Os2SalGraphics* pData )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	GpiCreateLogColorTable( pData->mhPS, LCOL_RESET, LCOLF_RGB, 0, 0, NULL );
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir // -----------------------------------------------------------------------
84cdf0e10cSrcweir 
85cdf0e10cSrcweir void ImplSalDeInitGraphics( Os2SalGraphics* pData )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir // =======================================================================
90cdf0e10cSrcweir 
91cdf0e10cSrcweir Os2SalGraphics::Os2SalGraphics()
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     for( int i = 0; i < MAX_FALLBACK; ++i )
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         mhFonts[ i ] = 0;
96cdf0e10cSrcweir         mpOs2FontData[ i ]  = NULL;
97cdf0e10cSrcweir         mpOs2FontEntry[ i ] = NULL;
98cdf0e10cSrcweir     }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     mfFontScale = 1.0;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 	mhPS 			= 0;
103cdf0e10cSrcweir 	mhDC 			= 0;
104cdf0e10cSrcweir 	mbLine				= FALSE;
105cdf0e10cSrcweir 	mbFill				= FALSE;
106cdf0e10cSrcweir 	mbXORMode			= FALSE;
107cdf0e10cSrcweir 	mnFontMetricCount	= 0;
108cdf0e10cSrcweir 	mpFontMetrics		= NULL;
109cdf0e10cSrcweir 	mpClipRectlAry		= NULL;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 	mhDefFont			= 0;
112cdf0e10cSrcweir 	mpFontKernPairs		= NULL;
113cdf0e10cSrcweir 	mnFontKernPairCount	= 0;
114cdf0e10cSrcweir 	mbFontKernInit		= FALSE;
115cdf0e10cSrcweir 
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir // -----------------------------------------------------------------------
119cdf0e10cSrcweir 
120cdf0e10cSrcweir Os2SalGraphics::~Os2SalGraphics()
121cdf0e10cSrcweir {
122cdf0e10cSrcweir 	Ft2DeleteSetId( mhPS, LCID_BASE);
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 	if ( mpFontMetrics )
125cdf0e10cSrcweir 		delete mpFontMetrics;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	if ( mpFontKernPairs )
128cdf0e10cSrcweir 		delete mpFontKernPairs;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir // -----------------------------------------------------------------------
133cdf0e10cSrcweir 
134cdf0e10cSrcweir static SalColor ImplGetROPSalColor( SalROPColor nROPColor )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir 	SalColor nSalColor;
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 	switch( nROPColor )
139cdf0e10cSrcweir 	{
140cdf0e10cSrcweir 		case SAL_ROP_0:
141cdf0e10cSrcweir 			nSalColor = MAKE_SALCOLOR( 0, 0, 0 );
142cdf0e10cSrcweir 		break;
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 		case SAL_ROP_1:
145cdf0e10cSrcweir 		case SAL_ROP_INVERT:
146cdf0e10cSrcweir 			nSalColor = MAKE_SALCOLOR( 255, 255, 255 );
147cdf0e10cSrcweir 		break;
148cdf0e10cSrcweir 	}
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 	return nSalColor;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir // -----------------------------------------------------------------------
154cdf0e10cSrcweir 
155cdf0e10cSrcweir void Os2SalGraphics::GetResolution( long& rDPIX, long& rDPIY )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir 	// since OOo asks for DPI, I will query FONT_RES, which seems to be
158cdf0e10cSrcweir 	// more correct than _RESOLUTION fields (on my wide screen lcd)
159cdf0e10cSrcweir 	// and does not require conversion
160cdf0e10cSrcweir 	DevQueryCaps( mhDC, CAPS_HORIZONTAL_FONT_RES, 1, &rDPIX );
161cdf0e10cSrcweir 	DevQueryCaps( mhDC, CAPS_VERTICAL_FONT_RES, 1, &rDPIY );
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir // -----------------------------------------------------------------------
165cdf0e10cSrcweir 
166cdf0e10cSrcweir USHORT Os2SalGraphics::GetBitCount()
167cdf0e10cSrcweir {
168cdf0e10cSrcweir 	LONG nBitCount;
169cdf0e10cSrcweir 	DevQueryCaps( mhDC, CAPS_COLOR_BITCOUNT, 1, &nBitCount );
170cdf0e10cSrcweir 	return (USHORT)nBitCount;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir // -----------------------------------------------------------------------
174cdf0e10cSrcweir 
175cdf0e10cSrcweir long Os2SalGraphics::GetGraphicsWidth() const
176cdf0e10cSrcweir {
177cdf0e10cSrcweir     if( mhWnd )
178cdf0e10cSrcweir     {
179cdf0e10cSrcweir         Os2SalFrame* pFrame = (Os2SalFrame*)GetWindowPtr( mhWnd );
180cdf0e10cSrcweir         if( pFrame )
181cdf0e10cSrcweir         {
182cdf0e10cSrcweir             if( pFrame->maGeometry.nWidth )
183cdf0e10cSrcweir                 return pFrame->maGeometry.nWidth;
184cdf0e10cSrcweir             else
185cdf0e10cSrcweir             {
186cdf0e10cSrcweir                 // TODO: perhaps not needed, maGeometry should always be up-to-date
187cdf0e10cSrcweir                 RECTL aRect;
188cdf0e10cSrcweir                 WinQueryWindowRect( mhWnd, &aRect );
189cdf0e10cSrcweir                 return aRect.xRight;
190cdf0e10cSrcweir             }
191cdf0e10cSrcweir         }
192cdf0e10cSrcweir     }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     return 0;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir // -----------------------------------------------------------------------
198cdf0e10cSrcweir 
199cdf0e10cSrcweir void Os2SalGraphics::ResetClipRegion()
200cdf0e10cSrcweir {
201cdf0e10cSrcweir #ifdef SAL_PRINTER_CLIPPATH
202cdf0e10cSrcweir 	if ( mbPrinter )
203cdf0e10cSrcweir 		GpiSetClipPath( mhPS, 0, SCP_RESET );
204cdf0e10cSrcweir 	else
205cdf0e10cSrcweir #endif
206cdf0e10cSrcweir 	{
207cdf0e10cSrcweir 		HRGN hOldRegion;
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 		GpiSetClipRegion( mhPS, NULL, &hOldRegion );
210cdf0e10cSrcweir 		if ( hOldRegion )
211cdf0e10cSrcweir 			GpiDestroyRegion( mhPS, hOldRegion );
212cdf0e10cSrcweir 	}
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir // -----------------------------------------------------------------------
216cdf0e10cSrcweir 
217cdf0e10cSrcweir bool Os2SalGraphics::setClipRegion( const Region& i_rClip )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir     ULONG nCount = i_rClip.GetRectCount();
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 	mpClipRectlAry	  = new RECTL[ nCount ];
222cdf0e10cSrcweir 	mnClipElementCount = 0;
223cdf0e10cSrcweir 
224cdf0e10cSrcweir     ImplRegionInfo aInfo;
225cdf0e10cSrcweir     long nX, nY, nW, nH;
226cdf0e10cSrcweir     bool bRegionRect = i_rClip.ImplGetFirstRect(aInfo, nX, nY, nW, nH );
227cdf0e10cSrcweir     while( bRegionRect )
228cdf0e10cSrcweir     {
229cdf0e10cSrcweir         if ( nW && nH )
230cdf0e10cSrcweir         {
231cdf0e10cSrcweir             RECTL* pClipRect = &mpClipRectlAry[ mnClipElementCount ];
232cdf0e10cSrcweir             pClipRect->xLeft   = nX;
233cdf0e10cSrcweir             pClipRect->yTop    = mnHeight - nY;
234cdf0e10cSrcweir             pClipRect->xRight  = nX + nW;
235cdf0e10cSrcweir             pClipRect->yBottom = mnHeight - (nY + nH);
236cdf0e10cSrcweir             mnClipElementCount++;
237cdf0e10cSrcweir         }
238cdf0e10cSrcweir         bRegionRect = i_rClip.ImplGetNextRect( aInfo, nX, nY, nW, nH );
239cdf0e10cSrcweir     }
240cdf0e10cSrcweir #ifdef SAL_PRINTER_CLIPPATH
241cdf0e10cSrcweir 	if ( mbPrinter )
242cdf0e10cSrcweir 	{
243cdf0e10cSrcweir 		GpiSetClipPath( mhPS, 0, SCP_RESET );
244cdf0e10cSrcweir 		GpiBeginPath( mhPS, 1L );
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 		for( int i = 0; i < mnClipElementCount; i++ )
247cdf0e10cSrcweir 		{
248cdf0e10cSrcweir 			POINTL aPt;
249cdf0e10cSrcweir 			RECTL* pClipRect = &mpClipRectlAry[ i ];
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 			aPt.x = pClipRect->xLeft;
252cdf0e10cSrcweir 			aPt.y = pClipRect->yTop-1;
253cdf0e10cSrcweir 			Ft2Move( mhPS, &aPt );
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 			aPt.x = pClipRect->xRight-1;
256cdf0e10cSrcweir 			aPt.y = pClipRect->yBottom;
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 			Ft2Box( mhPS, DRO_OUTLINE, &aPt, 0, 0 );
259cdf0e10cSrcweir 		}
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 		GpiEndPath( mhPS );
262cdf0e10cSrcweir 		GpiSetClipPath( mhPS, 1L, SCP_ALTERNATE | SCP_AND );
263cdf0e10cSrcweir 	}
264cdf0e10cSrcweir 	else
265cdf0e10cSrcweir #endif
266cdf0e10cSrcweir 	{
267cdf0e10cSrcweir 		HRGN hClipRegion = GpiCreateRegion( mhPS,
268cdf0e10cSrcweir 											mnClipElementCount,
269cdf0e10cSrcweir 											mpClipRectlAry );
270cdf0e10cSrcweir 		HRGN hOldRegion;
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 		GpiSetClipRegion( mhPS, hClipRegion, &hOldRegion );
273cdf0e10cSrcweir 		if( hOldRegion )
274cdf0e10cSrcweir 			GpiDestroyRegion( mhPS, hOldRegion );
275cdf0e10cSrcweir 	}
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 	delete [] mpClipRectlAry;
278cdf0e10cSrcweir 
279cdf0e10cSrcweir     return true;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir // -----------------------------------------------------------------------
283cdf0e10cSrcweir 
284cdf0e10cSrcweir void Os2SalGraphics::SetLineColor()
285cdf0e10cSrcweir {
286cdf0e10cSrcweir 	// don't draw line!
287cdf0e10cSrcweir 	mbLine = FALSE;
288cdf0e10cSrcweir }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir // -----------------------------------------------------------------------
291cdf0e10cSrcweir 
292cdf0e10cSrcweir void Os2SalGraphics::SetLineColor( SalColor nSalColor )
293cdf0e10cSrcweir {
294cdf0e10cSrcweir 	LINEBUNDLE lb;
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 	// set color
297cdf0e10cSrcweir 	lb.lColor = RGBCOLOR( SALCOLOR_RED( nSalColor ),
298cdf0e10cSrcweir 						  SALCOLOR_GREEN( nSalColor ),
299cdf0e10cSrcweir 						  SALCOLOR_BLUE( nSalColor ) );
300cdf0e10cSrcweir 
301cdf0e10cSrcweir 	Ft2SetAttrs( mhPS,
302cdf0e10cSrcweir 				 PRIM_LINE,
303cdf0e10cSrcweir 				 LBB_COLOR,
304cdf0e10cSrcweir 				 0,
305cdf0e10cSrcweir 				 &lb );
306cdf0e10cSrcweir 
307cdf0e10cSrcweir 	// draw line!
308cdf0e10cSrcweir 	mbLine = TRUE;
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
311cdf0e10cSrcweir // -----------------------------------------------------------------------
312cdf0e10cSrcweir 
313cdf0e10cSrcweir void Os2SalGraphics::SetFillColor()
314cdf0e10cSrcweir {
315cdf0e10cSrcweir 	// don't fill area!
316cdf0e10cSrcweir 	mbFill = FALSE;
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir // -----------------------------------------------------------------------
320cdf0e10cSrcweir 
321cdf0e10cSrcweir void Os2SalGraphics::SetFillColor( SalColor nSalColor )
322cdf0e10cSrcweir {
323cdf0e10cSrcweir 	AREABUNDLE ab;
324cdf0e10cSrcweir 
325cdf0e10cSrcweir 	// set color
326cdf0e10cSrcweir 	ab.lColor = RGBCOLOR( SALCOLOR_RED( nSalColor ),
327cdf0e10cSrcweir 						  SALCOLOR_GREEN( nSalColor ),
328cdf0e10cSrcweir 						  SALCOLOR_BLUE( nSalColor ) );
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 	Ft2SetAttrs( mhPS,
331cdf0e10cSrcweir 				 PRIM_AREA,
332cdf0e10cSrcweir 				 ABB_COLOR,
333cdf0e10cSrcweir 				 0,
334cdf0e10cSrcweir 				 &ab );
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 	// fill area!
337cdf0e10cSrcweir 	mbFill = TRUE;
338cdf0e10cSrcweir }
339cdf0e10cSrcweir 
340cdf0e10cSrcweir // -----------------------------------------------------------------------
341cdf0e10cSrcweir 
342cdf0e10cSrcweir void Os2SalGraphics::SetXORMode( bool bSet, bool )
343cdf0e10cSrcweir {
344cdf0e10cSrcweir 	mbXORMode = bSet;
345cdf0e10cSrcweir 	LONG nMixMode = bSet ? FM_XOR : FM_OVERPAINT;
346cdf0e10cSrcweir 
347cdf0e10cSrcweir 	// set mix mode for lines
348cdf0e10cSrcweir 	LINEBUNDLE lb;
349cdf0e10cSrcweir 	lb.usMixMode = nMixMode;
350cdf0e10cSrcweir 	Ft2SetAttrs( mhPS,
351cdf0e10cSrcweir 				 PRIM_LINE,
352cdf0e10cSrcweir 				 LBB_MIX_MODE,
353cdf0e10cSrcweir 				 0,
354cdf0e10cSrcweir 				 &lb );
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 	// set mix mode for areas
357cdf0e10cSrcweir 	AREABUNDLE ab;
358cdf0e10cSrcweir 	ab.usMixMode = nMixMode;
359cdf0e10cSrcweir 	Ft2SetAttrs( mhPS,
360cdf0e10cSrcweir 				 PRIM_AREA,
361cdf0e10cSrcweir 				 ABB_MIX_MODE,
362cdf0e10cSrcweir 				 0,
363cdf0e10cSrcweir 				 &ab );
364cdf0e10cSrcweir 
365cdf0e10cSrcweir 	// set mix mode for text
366cdf0e10cSrcweir 	CHARBUNDLE cb;
367cdf0e10cSrcweir 	cb.usMixMode = nMixMode;
368cdf0e10cSrcweir 	Ft2SetAttrs( mhPS,
369cdf0e10cSrcweir 				 PRIM_CHAR,
370cdf0e10cSrcweir 				 CBB_MIX_MODE,
371cdf0e10cSrcweir 				 0,
372cdf0e10cSrcweir 				 &cb );
373cdf0e10cSrcweir }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir // -----------------------------------------------------------------------
376cdf0e10cSrcweir 
377cdf0e10cSrcweir void Os2SalGraphics::SetROPLineColor( SalROPColor nROPColor )
378cdf0e10cSrcweir {
379cdf0e10cSrcweir 	SetLineColor( ImplGetROPSalColor( nROPColor ) );
380cdf0e10cSrcweir }
381cdf0e10cSrcweir 
382cdf0e10cSrcweir // -----------------------------------------------------------------------
383cdf0e10cSrcweir 
384cdf0e10cSrcweir void Os2SalGraphics::SetROPFillColor( SalROPColor nROPColor )
385cdf0e10cSrcweir {
386cdf0e10cSrcweir 	SetFillColor( ImplGetROPSalColor( nROPColor ) );
387cdf0e10cSrcweir }
388cdf0e10cSrcweir 
389cdf0e10cSrcweir // -----------------------------------------------------------------------
390cdf0e10cSrcweir 
391cdf0e10cSrcweir void Os2SalGraphics::drawPixel( long nX, long nY )
392cdf0e10cSrcweir {
393cdf0e10cSrcweir 	POINTL aPt;
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 	aPt.x = nX;
396cdf0e10cSrcweir 	aPt.y = TY( nY );
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 	// set color
399cdf0e10cSrcweir 	Ft2SetPel( mhPS, &aPt );
400cdf0e10cSrcweir }
401cdf0e10cSrcweir 
402cdf0e10cSrcweir // -----------------------------------------------------------------------
403cdf0e10cSrcweir 
404cdf0e10cSrcweir void Os2SalGraphics::drawPixel( long nX, long nY, SalColor nSalColor )
405cdf0e10cSrcweir {
406cdf0e10cSrcweir 	// save old color
407cdf0e10cSrcweir 	LINEBUNDLE oldLb;
408cdf0e10cSrcweir 	GpiQueryAttrs( mhPS,
409cdf0e10cSrcweir 				   PRIM_LINE,
410cdf0e10cSrcweir 				   LBB_COLOR,
411cdf0e10cSrcweir 				   &oldLb );
412cdf0e10cSrcweir 
413cdf0e10cSrcweir 	// set new color
414cdf0e10cSrcweir 	LINEBUNDLE lb;
415cdf0e10cSrcweir 	lb.lColor = RGBCOLOR( SALCOLOR_RED( nSalColor ),
416cdf0e10cSrcweir 						  SALCOLOR_GREEN( nSalColor ),
417cdf0e10cSrcweir 						  SALCOLOR_BLUE( nSalColor ) );
418cdf0e10cSrcweir 	Ft2SetAttrs( mhPS,
419cdf0e10cSrcweir 				 PRIM_LINE,
420cdf0e10cSrcweir 				 LBB_COLOR,
421cdf0e10cSrcweir 				 0,
422cdf0e10cSrcweir 				 &lb );
423cdf0e10cSrcweir 
424cdf0e10cSrcweir 	// set color of pixel
425cdf0e10cSrcweir 	POINTL aPt;
426cdf0e10cSrcweir 	aPt.x = nX;
427cdf0e10cSrcweir 	aPt.y = TY( nY );
428cdf0e10cSrcweir 	Ft2SetPel( mhPS, &aPt );
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 	// restore old color
431cdf0e10cSrcweir 	Ft2SetAttrs( mhPS,
432cdf0e10cSrcweir 				 PRIM_LINE,
433cdf0e10cSrcweir 				 LBB_COLOR,
434cdf0e10cSrcweir 				 0,
435cdf0e10cSrcweir 				 &oldLb );
436cdf0e10cSrcweir }
437cdf0e10cSrcweir 
438cdf0e10cSrcweir // -----------------------------------------------------------------------
439cdf0e10cSrcweir 
440cdf0e10cSrcweir void Os2SalGraphics::drawLine( long nX1, long nY1, long nX2, long nY2 )
441cdf0e10cSrcweir {
442cdf0e10cSrcweir 	// OS2 zeichnet den Endpunkt mit
443cdf0e10cSrcweir 	POINTL aPt;
444cdf0e10cSrcweir 	aPt.x = nX1;
445cdf0e10cSrcweir 	aPt.y = TY( nY1 );
446cdf0e10cSrcweir 	Ft2Move( mhPS, &aPt );
447cdf0e10cSrcweir 	aPt.x = nX2;
448cdf0e10cSrcweir 	aPt.y = TY( nY2 );
449cdf0e10cSrcweir 	GpiLine( mhPS, &aPt );
450cdf0e10cSrcweir }
451cdf0e10cSrcweir 
452cdf0e10cSrcweir // -----------------------------------------------------------------------
453cdf0e10cSrcweir 
454cdf0e10cSrcweir void Os2SalGraphics::drawRect( long nX, long nY, long nWidth, long nHeight )
455cdf0e10cSrcweir {
456cdf0e10cSrcweir 	POINTL aPt;
457cdf0e10cSrcweir 	long lControl;
458cdf0e10cSrcweir 
459cdf0e10cSrcweir 	if ( mbFill )
460cdf0e10cSrcweir 	{
461cdf0e10cSrcweir 		if ( mbLine )
462cdf0e10cSrcweir 			lControl = DRO_OUTLINEFILL;
463cdf0e10cSrcweir 		else
464cdf0e10cSrcweir 			lControl = DRO_FILL;
465cdf0e10cSrcweir 	}
466cdf0e10cSrcweir 	else
467cdf0e10cSrcweir 	{
468cdf0e10cSrcweir 		if ( mbLine )
469cdf0e10cSrcweir 			lControl = DRO_OUTLINE;
470cdf0e10cSrcweir 		else
471cdf0e10cSrcweir 			return;
472cdf0e10cSrcweir 	}
473cdf0e10cSrcweir 
474cdf0e10cSrcweir 	aPt.x = nX;
475cdf0e10cSrcweir 	aPt.y = TY( nY );
476cdf0e10cSrcweir 	Ft2Move( mhPS, &aPt );
477cdf0e10cSrcweir 	aPt.x = nX + nWidth - 1;
478cdf0e10cSrcweir 	aPt.y = TY( nY + nHeight - 1 );
479cdf0e10cSrcweir 	Ft2Box( mhPS, lControl, &aPt, 0, 0 );
480cdf0e10cSrcweir }
481cdf0e10cSrcweir 
482cdf0e10cSrcweir // -----------------------------------------------------------------------
483cdf0e10cSrcweir 
484cdf0e10cSrcweir void Os2SalGraphics::drawPolyLine( ULONG nPoints, const SalPoint* pPtAry )
485cdf0e10cSrcweir {
486cdf0e10cSrcweir 	// convert all points to sys orientation
487cdf0e10cSrcweir 	POINTL* 			pOS2PtAry = new POINTL[ nPoints ];
488cdf0e10cSrcweir 	POINTL* 			pTempOS2PtAry = pOS2PtAry;
489cdf0e10cSrcweir 	const SalPoint* 	pTempPtAry = pPtAry;
490cdf0e10cSrcweir 	ULONG				nTempPoints = nPoints;
491cdf0e10cSrcweir 	long				nHeight = mnHeight - 1;
492cdf0e10cSrcweir 
493cdf0e10cSrcweir 	while( nTempPoints-- )
494cdf0e10cSrcweir 	{
495cdf0e10cSrcweir 		(*pTempOS2PtAry).x = (*pTempPtAry).mnX;
496cdf0e10cSrcweir 		(*pTempOS2PtAry).y = nHeight - (*pTempPtAry).mnY;
497cdf0e10cSrcweir 		pTempOS2PtAry++;
498cdf0e10cSrcweir 		pTempPtAry++;
499cdf0e10cSrcweir 	}
500cdf0e10cSrcweir 
501cdf0e10cSrcweir 	Ft2Move( mhPS, pOS2PtAry );
502cdf0e10cSrcweir 	GpiPolyLine( mhPS, nPoints, pOS2PtAry );
503cdf0e10cSrcweir 	delete [] pOS2PtAry;
504cdf0e10cSrcweir }
505cdf0e10cSrcweir 
506cdf0e10cSrcweir // -----------------------------------------------------------------------
507cdf0e10cSrcweir 
508cdf0e10cSrcweir void Os2SalGraphics::drawPolygon( ULONG nPoints, const SalPoint* pPtAry )
509cdf0e10cSrcweir {
510cdf0e10cSrcweir 	PM_POLYGON aPolygon;
511cdf0e10cSrcweir 
512cdf0e10cSrcweir 	// create polygon
513cdf0e10cSrcweir 	aPolygon.aPointl = new POINTL[ nPoints ];
514cdf0e10cSrcweir 	aPolygon.ulPoints = nPoints;
515cdf0e10cSrcweir 
516cdf0e10cSrcweir 	// convert all points to sys orientation
517cdf0e10cSrcweir 	POINTL* 			pTempOS2PtAry = aPolygon.aPointl;
518cdf0e10cSrcweir 	const SalPoint* 	pTempPtAry = pPtAry;
519cdf0e10cSrcweir 	ULONG				nTempPoints = nPoints;
520cdf0e10cSrcweir 	long				nHeight = mnHeight - 1;
521cdf0e10cSrcweir 
522cdf0e10cSrcweir 	while( nTempPoints-- )
523cdf0e10cSrcweir 	{
524cdf0e10cSrcweir 		(*pTempOS2PtAry).x = (*pTempPtAry).mnX;
525cdf0e10cSrcweir 		(*pTempOS2PtAry).y = nHeight - (*pTempPtAry).mnY;
526cdf0e10cSrcweir 		pTempOS2PtAry++;
527cdf0e10cSrcweir 		pTempPtAry++;
528cdf0e10cSrcweir 	}
529cdf0e10cSrcweir 
530cdf0e10cSrcweir 	// Innenleben zeichnen
531cdf0e10cSrcweir 	if ( mbFill )
532cdf0e10cSrcweir 	{
533cdf0e10cSrcweir #ifdef SAL_PRINTER_POLYPATH
534cdf0e10cSrcweir 		if ( mbPrinter )
535cdf0e10cSrcweir 		{
536cdf0e10cSrcweir 			Ft2BeginPath( mhPS, 1 );
537cdf0e10cSrcweir 			Ft2Move( mhPS, aPolygon.aPointl );
538cdf0e10cSrcweir 			Ft2PolyLine( mhPS, aPolygon.ulPoints, aPolygon.aPointl );
539cdf0e10cSrcweir 			Ft2EndPath( mhPS );
540cdf0e10cSrcweir 			Ft2FillPath( mhPS, 1, 0 );
541cdf0e10cSrcweir 
542cdf0e10cSrcweir 			if ( mbLine )
543cdf0e10cSrcweir 			{
544cdf0e10cSrcweir 				Ft2Move( mhPS, aPolygon.aPointl );
545cdf0e10cSrcweir 				Ft2PolyLine( mhPS, aPolygon.ulPoints, aPolygon.aPointl );
546cdf0e10cSrcweir 			}
547cdf0e10cSrcweir 		}
548cdf0e10cSrcweir 		else
549cdf0e10cSrcweir #endif
550cdf0e10cSrcweir 		{
551cdf0e10cSrcweir 			ULONG nOptions = POLYGON_ALTERNATE;
552cdf0e10cSrcweir 
553cdf0e10cSrcweir 			if ( mbLine )
554cdf0e10cSrcweir 				nOptions |= POLYGON_BOUNDARY;
555cdf0e10cSrcweir 			else
556cdf0e10cSrcweir 				nOptions |= POLYGON_NOBOUNDARY;
557cdf0e10cSrcweir 
558cdf0e10cSrcweir 			Ft2Move( mhPS, aPolygon.aPointl );
559cdf0e10cSrcweir 			GpiPolygons( mhPS, 1, &aPolygon, nOptions, POLYGON_EXCL );
560cdf0e10cSrcweir 		}
561cdf0e10cSrcweir 	}
562cdf0e10cSrcweir 	else
563cdf0e10cSrcweir 	{
564cdf0e10cSrcweir 		if ( mbLine )
565cdf0e10cSrcweir 		{
566cdf0e10cSrcweir 			Ft2Move( mhPS, aPolygon.aPointl );
567cdf0e10cSrcweir 			GpiPolyLine( mhPS, nPoints, aPolygon.aPointl );
568cdf0e10cSrcweir 		}
569cdf0e10cSrcweir 	}
570cdf0e10cSrcweir 
571cdf0e10cSrcweir 	delete [] aPolygon.aPointl;
572cdf0e10cSrcweir }
573cdf0e10cSrcweir 
574cdf0e10cSrcweir // -----------------------------------------------------------------------
575cdf0e10cSrcweir 
576cdf0e10cSrcweir void Os2SalGraphics::drawPolyPolygon( ULONG nPoly, const ULONG* pPoints,
577cdf0e10cSrcweir 								   PCONSTSALPOINT* pPtAry )
578cdf0e10cSrcweir {
579cdf0e10cSrcweir 	ULONG		i;
580cdf0e10cSrcweir 	long		nHeight = mnHeight - 1;
581cdf0e10cSrcweir 	PM_POLYGON*	aPolygonAry = new PM_POLYGON[ nPoly ];
582cdf0e10cSrcweir 
583cdf0e10cSrcweir 	for( i = 0; i < nPoly; i++ )
584cdf0e10cSrcweir 	{
585cdf0e10cSrcweir 		const SalPoint * pTempPtAry = (const SalPoint*)pPtAry[ i ];
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 		// create polygon
588cdf0e10cSrcweir 		ULONG nTempPoints = pPoints[ i ];
589cdf0e10cSrcweir 		POINTL * pTempOS2PtAry = new POINTL[ nTempPoints ];
590cdf0e10cSrcweir 
591cdf0e10cSrcweir 		// convert all points to sys orientation
592cdf0e10cSrcweir 		aPolygonAry[ i ].ulPoints = nTempPoints;
593cdf0e10cSrcweir 		aPolygonAry[ i ].aPointl = pTempOS2PtAry;
594cdf0e10cSrcweir 
595cdf0e10cSrcweir 		while( nTempPoints-- )
596cdf0e10cSrcweir 		{
597cdf0e10cSrcweir 			(*pTempOS2PtAry).x = (*pTempPtAry).mnX;
598cdf0e10cSrcweir 			(*pTempOS2PtAry).y = nHeight - (*pTempPtAry).mnY;
599cdf0e10cSrcweir 			pTempOS2PtAry++;
600cdf0e10cSrcweir 			pTempPtAry++;
601cdf0e10cSrcweir 		}
602cdf0e10cSrcweir 	}
603cdf0e10cSrcweir 
604cdf0e10cSrcweir 	// Innenleben zeichnen
605cdf0e10cSrcweir 	if ( mbFill )
606cdf0e10cSrcweir 	{
607cdf0e10cSrcweir #ifdef SAL_PRINTER_POLYPATH
608cdf0e10cSrcweir 		if ( mbPrinter )
609cdf0e10cSrcweir 		{
610cdf0e10cSrcweir 			Ft2BeginPath( mhPS, 1 );
611cdf0e10cSrcweir 			for ( i = 0; i < nPoly; i++ )
612cdf0e10cSrcweir 			{
613cdf0e10cSrcweir 				Ft2Move( mhPS, aPolygonAry[i].aPointl );
614cdf0e10cSrcweir 				Ft2PolyLine( mhPS, aPolygonAry[i].ulPoints, aPolygonAry[i].aPointl );
615cdf0e10cSrcweir 			}
616cdf0e10cSrcweir 			Ft2EndPath( mhPS );
617cdf0e10cSrcweir 			Ft2FillPath( mhPS, 1, 0 );
618cdf0e10cSrcweir 		}
619cdf0e10cSrcweir 		else
620cdf0e10cSrcweir #endif
621cdf0e10cSrcweir 		{
622cdf0e10cSrcweir 			ULONG nOptions = POLYGON_ALTERNATE;
623cdf0e10cSrcweir 
624cdf0e10cSrcweir 			if ( mbLine )
625cdf0e10cSrcweir 				nOptions |= POLYGON_BOUNDARY;
626cdf0e10cSrcweir 			else
627cdf0e10cSrcweir 				nOptions |= POLYGON_NOBOUNDARY;
628cdf0e10cSrcweir 
629cdf0e10cSrcweir 			Ft2Move( mhPS, aPolygonAry[ 0 ].aPointl );
630cdf0e10cSrcweir 			GpiPolygons( mhPS, nPoly, aPolygonAry, nOptions, POLYGON_EXCL );
631cdf0e10cSrcweir 		}
632cdf0e10cSrcweir 	}
633cdf0e10cSrcweir 	else
634cdf0e10cSrcweir 	{
635cdf0e10cSrcweir 		if ( mbLine )
636cdf0e10cSrcweir 		{
637cdf0e10cSrcweir 			for( i = 0; i < nPoly; i++ )
638cdf0e10cSrcweir 			{
639cdf0e10cSrcweir 				Ft2Move( mhPS, aPolygonAry[ i ].aPointl );
640cdf0e10cSrcweir 				GpiPolyLine( mhPS, aPolygonAry[ i ].ulPoints, aPolygonAry[ i ].aPointl );
641cdf0e10cSrcweir 			}
642cdf0e10cSrcweir 		}
643cdf0e10cSrcweir 	}
644cdf0e10cSrcweir 
645cdf0e10cSrcweir 	// cleanup
646cdf0e10cSrcweir 	for( i = 0; i < nPoly; i++ )
647cdf0e10cSrcweir 		delete [] aPolygonAry[ i ].aPointl;
648cdf0e10cSrcweir 	delete [] aPolygonAry;
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir // -----------------------------------------------------------------------
652cdf0e10cSrcweir 
653cdf0e10cSrcweir bool Os2SalGraphics::drawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double /*fTransparency*/ )
654cdf0e10cSrcweir {
655cdf0e10cSrcweir 	// TODO: implement and advertise OutDevSupport_B2DDraw support
656cdf0e10cSrcweir 	return false;
657cdf0e10cSrcweir }
658cdf0e10cSrcweir 
659cdf0e10cSrcweir // -----------------------------------------------------------------------
660cdf0e10cSrcweir 
661cdf0e10cSrcweir bool Os2SalGraphics::drawPolyLine(
662cdf0e10cSrcweir     const basegfx::B2DPolygon& /*rPolygon*/,
663cdf0e10cSrcweir     double /*fTransparency*/,
664cdf0e10cSrcweir     const basegfx::B2DVector& /*rLineWidths*/,
665cdf0e10cSrcweir     basegfx::B2DLineJoin /*eLineJoin*/)
666cdf0e10cSrcweir {
667cdf0e10cSrcweir     // TODO: implement
668cdf0e10cSrcweir     return false;
669cdf0e10cSrcweir }
670cdf0e10cSrcweir 
671cdf0e10cSrcweir // -----------------------------------------------------------------------
672cdf0e10cSrcweir 
673cdf0e10cSrcweir sal_Bool Os2SalGraphics::drawPolyLineBezier( ULONG nPoints, const SalPoint* pPtAry, const BYTE* pFlgAry )
674cdf0e10cSrcweir {
675cdf0e10cSrcweir     return sal_False;
676cdf0e10cSrcweir }
677cdf0e10cSrcweir 
678cdf0e10cSrcweir // -----------------------------------------------------------------------
679cdf0e10cSrcweir 
680cdf0e10cSrcweir sal_Bool Os2SalGraphics::drawPolygonBezier( ULONG nPoints, const SalPoint* pPtAry, const BYTE* pFlgAry )
681cdf0e10cSrcweir {
682cdf0e10cSrcweir     return sal_False;
683cdf0e10cSrcweir }
684cdf0e10cSrcweir 
685cdf0e10cSrcweir // -----------------------------------------------------------------------
686cdf0e10cSrcweir 
687cdf0e10cSrcweir sal_Bool Os2SalGraphics::drawPolyPolygonBezier( ULONG nPoly, const ULONG* pPoints,
688cdf0e10cSrcweir                                              const SalPoint* const* pPtAry, const BYTE* const* pFlgAry )
689cdf0e10cSrcweir {
690cdf0e10cSrcweir     return sal_False;
691cdf0e10cSrcweir }
692cdf0e10cSrcweir 
693cdf0e10cSrcweir // =======================================================================
694cdf0e10cSrcweir 
695cdf0e10cSrcweir // MAXIMUM BUFSIZE EQ 0xFFFF
696cdf0e10cSrcweir #define POSTSCRIPT_BUFSIZE			0x4000
697cdf0e10cSrcweir // we only try to get the BoundingBox in the first 4096 bytes
698cdf0e10cSrcweir #define POSTSCRIPT_BOUNDINGSEARCH	0x1000
699cdf0e10cSrcweir 
700cdf0e10cSrcweir static BYTE* ImplSearchEntry( BYTE* pSource, BYTE* pDest, ULONG nComp, ULONG nSize )
701cdf0e10cSrcweir {
702cdf0e10cSrcweir 	while ( nComp-- >= nSize )
703cdf0e10cSrcweir 	{
704cdf0e10cSrcweir 		ULONG	i;
705cdf0e10cSrcweir 		for ( i = 0; i < nSize; i++ )
706cdf0e10cSrcweir 		{
707cdf0e10cSrcweir 			if ( ( pSource[i]&~0x20 ) != ( pDest[i]&~0x20 ) )
708cdf0e10cSrcweir 				break;
709cdf0e10cSrcweir 		}
710cdf0e10cSrcweir 		if ( i == nSize )
711cdf0e10cSrcweir 			return pSource;
712cdf0e10cSrcweir 		pSource++;
713cdf0e10cSrcweir 	}
714cdf0e10cSrcweir 	return NULL;
715cdf0e10cSrcweir }
716cdf0e10cSrcweir 
717cdf0e10cSrcweir 
718cdf0e10cSrcweir static BOOL ImplGetBoundingBox( double* nNumb, BYTE* pSource, ULONG nSize )
719cdf0e10cSrcweir {
720cdf0e10cSrcweir 	BOOL	bRetValue = FALSE;
721cdf0e10cSrcweir 	BYTE* pDest = ImplSearchEntry( pSource, (BYTE*)"%%BoundingBox:", nSize, 14 );
722cdf0e10cSrcweir 	if ( pDest )
723cdf0e10cSrcweir 	{
724cdf0e10cSrcweir 		nNumb[0] = nNumb[1] = nNumb[2] = nNumb[3] = 0;
725cdf0e10cSrcweir 		pDest += 14;
726cdf0e10cSrcweir 
727cdf0e10cSrcweir 		int nSizeLeft = nSize - ( pDest - pSource );
728cdf0e10cSrcweir 		if ( nSizeLeft > 100 )
729cdf0e10cSrcweir 			nSizeLeft = 100;	// only 100 bytes following the bounding box will be checked
730cdf0e10cSrcweir 
731cdf0e10cSrcweir 		int i;
732cdf0e10cSrcweir 		for ( i = 0; ( i < 4 ) && nSizeLeft; i++ )
733cdf0e10cSrcweir 		{
734cdf0e10cSrcweir 			int 	nDivision = 1;
735cdf0e10cSrcweir 			BOOL	bDivision = FALSE;
736cdf0e10cSrcweir 			BOOL	bNegative = FALSE;
737cdf0e10cSrcweir 			BOOL	bValid = TRUE;
738cdf0e10cSrcweir 
739cdf0e10cSrcweir 			while ( ( --nSizeLeft ) && ( *pDest == ' ' ) || ( *pDest == 0x9 ) ) pDest++;
740cdf0e10cSrcweir 			BYTE nByte = *pDest;
741cdf0e10cSrcweir 			while ( nSizeLeft && ( nByte != ' ' ) && ( nByte != 0x9 ) && ( nByte != 0xd ) && ( nByte != 0xa ) )
742cdf0e10cSrcweir 			{
743cdf0e10cSrcweir 				switch ( nByte )
744cdf0e10cSrcweir 				{
745cdf0e10cSrcweir 					case '.' :
746cdf0e10cSrcweir 						if ( bDivision )
747cdf0e10cSrcweir 							bValid = FALSE;
748cdf0e10cSrcweir 						else
749cdf0e10cSrcweir 							bDivision = TRUE;
750cdf0e10cSrcweir 						break;
751cdf0e10cSrcweir 					case '-' :
752cdf0e10cSrcweir 						bNegative = TRUE;
753cdf0e10cSrcweir 						break;
754cdf0e10cSrcweir 					default :
755cdf0e10cSrcweir 						if ( ( nByte < '0' ) || ( nByte > '9' ) )
756cdf0e10cSrcweir 							nSizeLeft = 1; 	// error parsing the bounding box values
757cdf0e10cSrcweir 						else if ( bValid )
758cdf0e10cSrcweir 						{
759cdf0e10cSrcweir 							if ( bDivision )
760cdf0e10cSrcweir 								nDivision*=10;
761cdf0e10cSrcweir 							nNumb[i] *= 10;
762cdf0e10cSrcweir 							nNumb[i] += nByte - '0';
763cdf0e10cSrcweir 						}
764cdf0e10cSrcweir 						break;
765cdf0e10cSrcweir 				}
766cdf0e10cSrcweir 				nSizeLeft--;
767cdf0e10cSrcweir 				nByte = *(++pDest);
768cdf0e10cSrcweir 			}
769cdf0e10cSrcweir 			if ( bNegative )
770cdf0e10cSrcweir 				nNumb[i] = -nNumb[i];
771cdf0e10cSrcweir 			if ( bDivision && ( nDivision != 1 ) )
772cdf0e10cSrcweir 				nNumb[i] /= nDivision;
773cdf0e10cSrcweir 		}
774cdf0e10cSrcweir 		if ( i == 4 )
775cdf0e10cSrcweir 			bRetValue = TRUE;
776cdf0e10cSrcweir 	}
777cdf0e10cSrcweir 	return bRetValue;
778cdf0e10cSrcweir }
779cdf0e10cSrcweir 
780cdf0e10cSrcweir #if 0
781cdf0e10cSrcweir static void ImplWriteDouble( BYTE** pBuf, double nNumber )
782cdf0e10cSrcweir {
783cdf0e10cSrcweir //	*pBuf += sprintf( (char*)*pBuf, "%f", nNumber );
784cdf0e10cSrcweir 
785cdf0e10cSrcweir 	if ( nNumber < 0 )
786cdf0e10cSrcweir 	{
787cdf0e10cSrcweir 		*(*pBuf)++ = (BYTE)'-';
788cdf0e10cSrcweir 		nNumber = -nNumber;
789cdf0e10cSrcweir 	}
790cdf0e10cSrcweir 	ULONG nTemp = (ULONG)nNumber;
791cdf0e10cSrcweir 	const String aNumber1( nTemp );
792cdf0e10cSrcweir 	ULONG nLen = aNumber1.Len();
793cdf0e10cSrcweir 
794cdf0e10cSrcweir 	for ( USHORT n = 0; n < nLen; n++ )
795cdf0e10cSrcweir 		*(*pBuf)++ = aNumber1[ n ];
796cdf0e10cSrcweir 
797cdf0e10cSrcweir 	nTemp = (ULONG)( ( nNumber - nTemp ) * 100000 );
798cdf0e10cSrcweir 	if ( nTemp )
799cdf0e10cSrcweir 	{
800cdf0e10cSrcweir 		*(*pBuf)++ = (BYTE)'.';
801cdf0e10cSrcweir 		const String aNumber2( nTemp );
802cdf0e10cSrcweir 
803cdf0e10cSrcweir 		ULONG nLen = aNumber2.Len();
804cdf0e10cSrcweir 		if ( nLen < 8 )
805cdf0e10cSrcweir 		{
806cdf0e10cSrcweir 			for ( n = 0; n < ( 5 - nLen ); n++ )
807cdf0e10cSrcweir 			{
808cdf0e10cSrcweir 				*(*pBuf)++ = (BYTE)'0';
809cdf0e10cSrcweir 			}
810cdf0e10cSrcweir 		}
811cdf0e10cSrcweir 		for ( USHORT n = 0; n < nLen; n++ )
812cdf0e10cSrcweir 		{
813cdf0e10cSrcweir 			*(*pBuf)++ = aNumber2[ n ];
814cdf0e10cSrcweir 		}
815cdf0e10cSrcweir 	}
816cdf0e10cSrcweir 	*(*pBuf)++ = ' ';
817cdf0e10cSrcweir }
818cdf0e10cSrcweir #endif
819cdf0e10cSrcweir 
820cdf0e10cSrcweir inline void ImplWriteString( BYTE** pBuf, const char* sString )
821cdf0e10cSrcweir {
822cdf0e10cSrcweir 	strcpy( (char*)*pBuf, sString );
823cdf0e10cSrcweir 	*pBuf += strlen( sString );
824cdf0e10cSrcweir }
825cdf0e10cSrcweir 
826cdf0e10cSrcweir BOOL Os2SalGraphics::drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, ULONG nSize )
827cdf0e10cSrcweir {
828cdf0e10cSrcweir 	if ( !mbPrinter )
829cdf0e10cSrcweir 		return FALSE;
830cdf0e10cSrcweir 
831cdf0e10cSrcweir 	BOOL	bRet  = FALSE;
832cdf0e10cSrcweir 	LONG	nLong = 0;
833cdf0e10cSrcweir 	if ( !(DevQueryCaps( mhDC, CAPS_TECHNOLOGY, 1, &nLong ) &&
834cdf0e10cSrcweir 		   (CAPS_TECH_POSTSCRIPT == nLong)) )
835cdf0e10cSrcweir 		return FALSE;
836cdf0e10cSrcweir 
837cdf0e10cSrcweir 	BYTE*	pBuf = new BYTE[ POSTSCRIPT_BUFSIZE ];
838cdf0e10cSrcweir 	double	nBoundingBox[4];
839cdf0e10cSrcweir 
840cdf0e10cSrcweir 	if ( pBuf && ImplGetBoundingBox( nBoundingBox, (BYTE*)pPtr, nSize ) )
841cdf0e10cSrcweir 	{
842cdf0e10cSrcweir 		LONG pOS2DXAry[4];		  // hack -> print always 2 white space
843cdf0e10cSrcweir 		POINTL aPt;
844cdf0e10cSrcweir 		aPt.x = 0;
845cdf0e10cSrcweir 		aPt.y = 0;
846cdf0e10cSrcweir 		PCH pStr = (PCH) "  ";
847cdf0e10cSrcweir 		for( long i = 0; i < 4; i++ )
848cdf0e10cSrcweir 			pOS2DXAry[i] = i;
849cdf0e10cSrcweir 		Ft2CharStringPosAt( mhPS, &aPt, NULL, 0, 2, (PCH)pStr,(PLONG)&pOS2DXAry[0] );
850cdf0e10cSrcweir 
851cdf0e10cSrcweir 		OStringBuffer aBuf( POSTSCRIPT_BUFSIZE );
852cdf0e10cSrcweir 
853cdf0e10cSrcweir                 // reserve place for a USHORT
854cdf0e10cSrcweir                 aBuf.append( "aa" );
855cdf0e10cSrcweir 
856cdf0e10cSrcweir                 // #107797# Write out EPS encapsulation header
857cdf0e10cSrcweir                 // ----------------------------------------------------------------------------------
858cdf0e10cSrcweir 
859cdf0e10cSrcweir                 // directly taken from the PLRM 3.0, p. 726. Note:
860cdf0e10cSrcweir                 // this will definitely cause problems when
861cdf0e10cSrcweir                 // recursively creating and embedding PostScript files
862cdf0e10cSrcweir                 // in OOo, since we use statically-named variables
863cdf0e10cSrcweir                 // here (namely, b4_Inc_state_salWin, dict_count_salWin and
864cdf0e10cSrcweir                 // op_count_salWin). Currently, I have no idea on how to
865cdf0e10cSrcweir                 // work around that, except from scanning and
866cdf0e10cSrcweir                 // interpreting the EPS for unused identifiers.
867cdf0e10cSrcweir 
868cdf0e10cSrcweir                 // append the real text
869cdf0e10cSrcweir                 aBuf.append( "\n\n/b4_Inc_state_salWin save def\n"
870cdf0e10cSrcweir                              "/dict_count_salWin countdictstack def\n"
871cdf0e10cSrcweir                              "/op_count_salWin count 1 sub def\n"
872cdf0e10cSrcweir                              "userdict begin\n"
873cdf0e10cSrcweir                              "/showpage {} def\n"
874cdf0e10cSrcweir                              "0 setgray 0 setlinecap\n"
875cdf0e10cSrcweir                              "1 setlinewidth 0 setlinejoin\n"
876cdf0e10cSrcweir                              "10 setmiterlimit [] 0 setdash newpath\n"
877cdf0e10cSrcweir                              "/languagelevel where\n"
878cdf0e10cSrcweir                              "{\n"
879cdf0e10cSrcweir                              "  pop languagelevel\n"
880cdf0e10cSrcweir                              "  1 ne\n"
881cdf0e10cSrcweir                              "  {\n"
882cdf0e10cSrcweir                              "    false setstrokeadjust false setoverprint\n"
883cdf0e10cSrcweir                              "  } if\n"
884cdf0e10cSrcweir                              "} if\n\n" );
885cdf0e10cSrcweir 
886cdf0e10cSrcweir #if 0
887cdf0e10cSrcweir                 // #i10737# Apply clipping manually
888cdf0e10cSrcweir                 // ----------------------------------------------------------------------------------
889cdf0e10cSrcweir 
890cdf0e10cSrcweir                 // Windows seems to ignore any clipping at the HDC,
891cdf0e10cSrcweir                 // when followed by a POSTSCRIPT_PASSTHROUGH
892cdf0e10cSrcweir 
893cdf0e10cSrcweir                 // Check whether we've got a clipping, consisting of
894cdf0e10cSrcweir                 // exactly one rect (other cases should be, but aren't
895cdf0e10cSrcweir                 // handled currently)
896cdf0e10cSrcweir 
897cdf0e10cSrcweir                 // TODO: Handle more than one rectangle here (take
898cdf0e10cSrcweir                 // care, the buffer can handle only POSTSCRIPT_BUFSIZE
899cdf0e10cSrcweir                 // characters!)
900cdf0e10cSrcweir                 if ( mhRegion != 0 &&
901cdf0e10cSrcweir                      mpStdClipRgnData != NULL &&
902cdf0e10cSrcweir                      mpClipRgnData == mpStdClipRgnData &&
903cdf0e10cSrcweir                      mpClipRgnData->rdh.nCount == 1 )
904cdf0e10cSrcweir                 {
905cdf0e10cSrcweir                     RECT* pRect = &(mpClipRgnData->rdh.rcBound);
906cdf0e10cSrcweir 
907cdf0e10cSrcweir                     aBuf.append( "\nnewpath\n" );
908cdf0e10cSrcweir                     aBuf.append( pRect->left );
909cdf0e10cSrcweir                     aBuf.append( " " );
910cdf0e10cSrcweir                     aBuf.append( pRect->top );
911cdf0e10cSrcweir                     aBuf.append( " moveto\n" );
912cdf0e10cSrcweir                     aBuf.append( pRect->right );
913cdf0e10cSrcweir                     aBuf.append( " " );
914cdf0e10cSrcweir                     aBuf.append( pRect->top );
915cdf0e10cSrcweir                     aBuf.append( " lineto\n" );
916cdf0e10cSrcweir                     aBuf.append( pRect->right );
917cdf0e10cSrcweir                     aBuf.append( " " );
918cdf0e10cSrcweir                     aBuf.append( pRect->bottom );
919cdf0e10cSrcweir                     aBuf.append( " lineto\n" );
920cdf0e10cSrcweir                     aBuf.append( pRect->left );
921cdf0e10cSrcweir                     aBuf.append( " " );
922cdf0e10cSrcweir                     aBuf.append( pRect->bottom );
923cdf0e10cSrcweir                     aBuf.append( " lineto\n"
924cdf0e10cSrcweir                                  "closepath\n"
925cdf0e10cSrcweir                                  "clip\n"
926cdf0e10cSrcweir                                  "newpath\n" );
927cdf0e10cSrcweir                 }
928cdf0e10cSrcweir #endif
929cdf0e10cSrcweir 
930cdf0e10cSrcweir                 // #107797# Write out buffer
931cdf0e10cSrcweir                 // ----------------------------------------------------------------------------------
932cdf0e10cSrcweir 				*((USHORT*)aBuf.getStr()) = (USHORT)( aBuf.getLength() - 2 );
933cdf0e10cSrcweir 				//Escape ( mhDC, nEscape, aBuf.getLength(), (LPTSTR)aBuf.getStr(), 0 );
934cdf0e10cSrcweir 				DevEscape( mhDC, DEVESC_RAWDATA, aBuf.getLength(),
935cdf0e10cSrcweir 						(PBYTE)aBuf.getStr(), 0, NULL );
936cdf0e10cSrcweir 
937cdf0e10cSrcweir 		double dM11 = nWidth / ( nBoundingBox[2] - nBoundingBox[0] );
938cdf0e10cSrcweir 		double dM22 = - ( nHeight / (nBoundingBox[1] - nBoundingBox[3] ) );
939cdf0e10cSrcweir 
940cdf0e10cSrcweir                 // reserve a USHORT again
941cdf0e10cSrcweir                 aBuf.setLength( 2 );
942cdf0e10cSrcweir                 aBuf.append( "\n\n[" );
943cdf0e10cSrcweir                 aBuf.append( dM11 );
944cdf0e10cSrcweir                 aBuf.append( " 0 0 " );
945cdf0e10cSrcweir                 aBuf.append( dM22 );
946cdf0e10cSrcweir                 aBuf.append( ' ' );
947cdf0e10cSrcweir                 aBuf.append( nX - ( dM11 * nBoundingBox[0] ) );
948cdf0e10cSrcweir                 aBuf.append( ' ' );
949cdf0e10cSrcweir                 aBuf.append( nY - ( dM22 * nBoundingBox[3] ) );
950cdf0e10cSrcweir                 aBuf.append( "] concat\n"
951cdf0e10cSrcweir                              "%%BeginDocument:\n" );
952cdf0e10cSrcweir 				*((USHORT*)aBuf.getStr()) = (USHORT)( aBuf.getLength() - 2 );
953cdf0e10cSrcweir 				DevEscape( mhDC, DEVESC_RAWDATA, aBuf.getLength(),
954cdf0e10cSrcweir 						(PBYTE)aBuf.getStr(), 0, NULL );
955cdf0e10cSrcweir #if 0
956cdf0e10cSrcweir 		BYTE* pTemp = pBuf;
957cdf0e10cSrcweir 		ImplWriteString( &pTemp, "save\n[ " );
958cdf0e10cSrcweir 		ImplWriteDouble( &pTemp, dM11 );
959cdf0e10cSrcweir 		ImplWriteDouble( &pTemp, 0 );
960cdf0e10cSrcweir 		ImplWriteDouble( &pTemp, 0 );
961cdf0e10cSrcweir 		ImplWriteDouble( &pTemp, dM22 );
962cdf0e10cSrcweir 		ImplWriteDouble( &pTemp, nX - ( dM11 * nBoundingBox[0] ) );
963cdf0e10cSrcweir 		ImplWriteDouble( &pTemp, mnHeight - nY - ( dM22 * nBoundingBox[3] ) );
964cdf0e10cSrcweir 		ImplWriteString( &pTemp, "] concat /showpage {} def\n" );
965cdf0e10cSrcweir 
966cdf0e10cSrcweir 		if ( DevEscape( mhDC, DEVESC_RAWDATA, pTemp - pBuf,
967cdf0e10cSrcweir 			(PBYTE)pBuf, 0, NULL ) == DEV_OK )
968cdf0e10cSrcweir #endif //
969cdf0e10cSrcweir 		{
970cdf0e10cSrcweir 			UINT32 nToDo = nSize;
971cdf0e10cSrcweir 			UINT32 nDoNow;
972cdf0e10cSrcweir 			bRet = TRUE;
973cdf0e10cSrcweir 			while( nToDo && bRet )
974cdf0e10cSrcweir 			{
975cdf0e10cSrcweir 				nDoNow = 0x4000;
976cdf0e10cSrcweir 				if ( nToDo < nDoNow )
977cdf0e10cSrcweir 					nDoNow = nToDo;
978cdf0e10cSrcweir 
979cdf0e10cSrcweir 				if ( DevEscape( mhDC, DEVESC_RAWDATA, nDoNow, (PBYTE)pPtr + nSize - nToDo,
980cdf0e10cSrcweir 				   0, NULL ) == -1 )
981cdf0e10cSrcweir 					bRet = FALSE;
982cdf0e10cSrcweir 				nToDo -= nDoNow;
983cdf0e10cSrcweir 			}
984cdf0e10cSrcweir 
985cdf0e10cSrcweir 			if ( bRet )
986cdf0e10cSrcweir 			{
987cdf0e10cSrcweir 				strcpy ( (char*)pBuf, "\nrestore\n" );
988cdf0e10cSrcweir 				if ( DevEscape( mhDC, DEVESC_RAWDATA, 9, (PBYTE)pBuf,
989cdf0e10cSrcweir 					0, NULL ) == DEV_OK ) bRet = TRUE;
990cdf0e10cSrcweir 			}
991cdf0e10cSrcweir 
992cdf0e10cSrcweir                 // #107797# Write out EPS encapsulation footer
993cdf0e10cSrcweir                 // ----------------------------------------------------------------------------------
994cdf0e10cSrcweir                 // reserve a USHORT again
995cdf0e10cSrcweir                 aBuf.setLength( 2 );
996cdf0e10cSrcweir                 aBuf.append( "%%EndDocument\n"
997cdf0e10cSrcweir                              "count op_count_salWin sub {pop} repeat\n"
998cdf0e10cSrcweir                              "countdictstack dict_count_salWin sub {end} repeat\n"
999cdf0e10cSrcweir                              "b4_Inc_state_salWin restore\n\n" );
1000cdf0e10cSrcweir 				*((USHORT*)aBuf.getStr()) = (USHORT)( aBuf.getLength() - 2 );
1001cdf0e10cSrcweir 				DevEscape( mhDC, DEVESC_RAWDATA, aBuf.getLength(),
1002cdf0e10cSrcweir 						(PBYTE)aBuf.getStr(), 0, NULL );
1003cdf0e10cSrcweir 				bRet = TRUE;
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir 		}
1006cdf0e10cSrcweir 	}
1007cdf0e10cSrcweir 	delete [] pBuf;
1008cdf0e10cSrcweir 	return bRet;
1009cdf0e10cSrcweir }
1010cdf0e10cSrcweir 
1011cdf0e10cSrcweir /*
1012cdf0e10cSrcweir  * IsNativeControlSupported()
1013cdf0e10cSrcweir  *
1014cdf0e10cSrcweir  *  Returns TRUE if the platform supports native
1015cdf0e10cSrcweir  *  drawing of the control defined by nPart
1016cdf0e10cSrcweir  */
1017cdf0e10cSrcweir BOOL Os2SalGraphics::IsNativeControlSupported( ControlType nType, ControlPart nPart )
1018cdf0e10cSrcweir {
1019cdf0e10cSrcweir 	return( FALSE );
1020cdf0e10cSrcweir }
1021cdf0e10cSrcweir 
1022cdf0e10cSrcweir // -----------------------------------------------------------------------
1023cdf0e10cSrcweir 
1024cdf0e10cSrcweir SystemGraphicsData Os2SalGraphics::GetGraphicsData() const
1025cdf0e10cSrcweir {
1026cdf0e10cSrcweir     SystemGraphicsData aRes;
1027cdf0e10cSrcweir     aRes.nSize = sizeof(aRes);
1028cdf0e10cSrcweir #if 0
1029cdf0e10cSrcweir     aRes.hDC = mhDC;
1030cdf0e10cSrcweir #endif
1031cdf0e10cSrcweir     return aRes;
1032cdf0e10cSrcweir }
1033cdf0e10cSrcweir 
1034cdf0e10cSrcweir // -----------------------------------------------------------------------
1035