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