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