xref: /AOO41X/main/vcl/win/source/gdi/salgdi.cxx (revision 5f27b83cee6e25e8a00edc4ae51b88fe9d2801da)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <stdio.h>
28cdf0e10cSrcweir #include <string.h>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <rtl/strbuf.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <tools/svwin.h>
33cdf0e10cSrcweir #include <tools/debug.hxx>
34cdf0e10cSrcweir #include <tools/poly.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
37cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <win/wincomp.hxx>
40cdf0e10cSrcweir #include <win/saldata.hxx>
41cdf0e10cSrcweir #include <win/salgdi.h>
42cdf0e10cSrcweir #include <win/salframe.h>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using namespace rtl;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // =======================================================================
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // comment out to prevent use of beziers on GDI functions
49cdf0e10cSrcweir #define USE_GDI_BEZIERS
50cdf0e10cSrcweir 
51cdf0e10cSrcweir // =======================================================================
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #define DITHER_PAL_DELTA				51
54cdf0e10cSrcweir #define DITHER_PAL_STEPS				6
55cdf0e10cSrcweir #define DITHER_PAL_COUNT				(DITHER_PAL_STEPS*DITHER_PAL_STEPS*DITHER_PAL_STEPS)
56cdf0e10cSrcweir #define DITHER_MAX_SYSCOLOR 			16
57cdf0e10cSrcweir #define DITHER_EXTRA_COLORS 			1
58cdf0e10cSrcweir #define DMAP( _def_nVal, _def_nThres )	((pDitherDiff[_def_nVal]>(_def_nThres))?pDitherHigh[_def_nVal]:pDitherLow[_def_nVal])
59cdf0e10cSrcweir 
60cdf0e10cSrcweir // =======================================================================
61cdf0e10cSrcweir 
62cdf0e10cSrcweir struct SysColorEntry
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 	DWORD			nRGB;
65cdf0e10cSrcweir 	SysColorEntry*	pNext;
66cdf0e10cSrcweir };
67cdf0e10cSrcweir 
68cdf0e10cSrcweir // =======================================================================
69cdf0e10cSrcweir 
70cdf0e10cSrcweir static SysColorEntry* pFirstSysColor = NULL;
71cdf0e10cSrcweir static SysColorEntry* pActSysColor = NULL;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir // -----------------------------------------------------------------------------
74cdf0e10cSrcweir 
75cdf0e10cSrcweir // Blue7
76cdf0e10cSrcweir static PALETTEENTRY aImplExtraColor1 =
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	0, 184, 255, 0
79cdf0e10cSrcweir };
80cdf0e10cSrcweir 
81cdf0e10cSrcweir // -----------------------------------------------------------------------------
82cdf0e10cSrcweir 
83cdf0e10cSrcweir static PALETTEENTRY aImplSalSysPalEntryAry[ DITHER_MAX_SYSCOLOR ] =
84cdf0e10cSrcweir {
85cdf0e10cSrcweir {	 0,    0,	 0, 0 },
86cdf0e10cSrcweir {	 0,    0, 0x80, 0 },
87cdf0e10cSrcweir {	 0, 0x80,	 0, 0 },
88cdf0e10cSrcweir {	 0, 0x80, 0x80, 0 },
89cdf0e10cSrcweir { 0x80,    0,	 0, 0 },
90cdf0e10cSrcweir { 0x80,    0, 0x80, 0 },
91cdf0e10cSrcweir { 0x80, 0x80,	 0, 0 },
92cdf0e10cSrcweir { 0x80, 0x80, 0x80, 0 },
93cdf0e10cSrcweir { 0xC0, 0xC0, 0xC0, 0 },
94cdf0e10cSrcweir {	 0,    0, 0xFF, 0 },
95cdf0e10cSrcweir {	 0, 0xFF,	 0, 0 },
96cdf0e10cSrcweir {	 0, 0xFF, 0xFF, 0 },
97cdf0e10cSrcweir { 0xFF,    0,	 0, 0 },
98cdf0e10cSrcweir { 0xFF,    0, 0xFF, 0 },
99cdf0e10cSrcweir { 0xFF, 0xFF,	 0, 0 },
100cdf0e10cSrcweir { 0xFF, 0xFF, 0xFF, 0 }
101cdf0e10cSrcweir };
102cdf0e10cSrcweir 
103cdf0e10cSrcweir // -----------------------------------------------------------------------------
104cdf0e10cSrcweir 
105cdf0e10cSrcweir static BYTE aOrdDither8Bit[8][8] =
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	 0, 38,  9, 48,  2, 40, 12, 50,
108cdf0e10cSrcweir 	25, 12, 35, 22, 28, 15, 37, 24,
109cdf0e10cSrcweir 	 6, 44,  3, 41,  8, 47,  5, 44,
110cdf0e10cSrcweir 	32, 19, 28, 16, 34, 21, 31, 18,
111cdf0e10cSrcweir 	 1, 40, 11, 49,  0, 39, 10, 48,
112cdf0e10cSrcweir 	27, 14, 36, 24, 26, 13, 36, 23,
113cdf0e10cSrcweir 	 8, 46,  4, 43,  7, 45,  4, 42,
114cdf0e10cSrcweir 	33, 20, 30, 17, 32, 20, 29, 16
115cdf0e10cSrcweir };
116cdf0e10cSrcweir 
117cdf0e10cSrcweir // -----------------------------------------------------------------------------
118cdf0e10cSrcweir 
119cdf0e10cSrcweir static BYTE aOrdDither16Bit[8][8] =
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	0, 6, 1, 7, 0, 6, 1, 7,
122cdf0e10cSrcweir 	4, 2, 5, 3, 4, 2, 5, 3,
123cdf0e10cSrcweir 	1, 7, 0, 6, 1, 7, 0, 6,
124cdf0e10cSrcweir 	5, 3, 4, 2, 5, 3, 4, 2,
125cdf0e10cSrcweir 	0, 6, 1, 7, 0, 6, 1, 7,
126cdf0e10cSrcweir 	4, 2, 5, 3, 4, 2, 5, 3,
127cdf0e10cSrcweir 	1, 7, 0, 6, 1, 7, 0, 6,
128cdf0e10cSrcweir 	5, 3, 4, 2, 5, 3, 4, 2
129cdf0e10cSrcweir };
130cdf0e10cSrcweir 
131cdf0e10cSrcweir // =======================================================================
132cdf0e10cSrcweir 
133cdf0e10cSrcweir // Pens muessen wir mit 1 Pixel-Breite erzeugen, da ansonsten die S3-Karte
134cdf0e10cSrcweir // viele Paintprobleme hat, wenn Polygone/PolyLines gezeichnet werden und
135cdf0e10cSrcweir // eine komplexe ClipRegion gesetzt ist
136cdf0e10cSrcweir #define GSL_PEN_WIDTH					1
137cdf0e10cSrcweir 
138cdf0e10cSrcweir // =======================================================================
139cdf0e10cSrcweir 
140cdf0e10cSrcweir #define SAL_POLYPOLYCOUNT_STACKBUF			8
141cdf0e10cSrcweir #define SAL_POLYPOLYPOINTS_STACKBUF 		64
142cdf0e10cSrcweir 
143cdf0e10cSrcweir // =======================================================================
144cdf0e10cSrcweir 
145cdf0e10cSrcweir void ImplInitSalGDI()
146cdf0e10cSrcweir {
147cdf0e10cSrcweir 	SalData* pSalData = GetSalData();
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	// init stock brushes
150cdf0e10cSrcweir 	pSalData->maStockPenColorAry[0] 	= PALETTERGB( 0, 0, 0 );
151cdf0e10cSrcweir 	pSalData->maStockPenColorAry[1] 	= PALETTERGB( 0xFF, 0xFF, 0xFF );
152cdf0e10cSrcweir 	pSalData->maStockPenColorAry[2] 	= PALETTERGB( 0xC0, 0xC0, 0xC0 );
153cdf0e10cSrcweir 	pSalData->maStockPenColorAry[3] 	= PALETTERGB( 0x80, 0x80, 0x80 );
154cdf0e10cSrcweir 	pSalData->mhStockPenAry[0]			= CreatePen( PS_SOLID, GSL_PEN_WIDTH, pSalData->maStockPenColorAry[0] );
155cdf0e10cSrcweir 	pSalData->mhStockPenAry[1]			= CreatePen( PS_SOLID, GSL_PEN_WIDTH, pSalData->maStockPenColorAry[1] );
156cdf0e10cSrcweir 	pSalData->mhStockPenAry[2]			= CreatePen( PS_SOLID, GSL_PEN_WIDTH, pSalData->maStockPenColorAry[2] );
157cdf0e10cSrcweir 	pSalData->mhStockPenAry[3]			= CreatePen( PS_SOLID, GSL_PEN_WIDTH, pSalData->maStockPenColorAry[3] );
158cdf0e10cSrcweir 	pSalData->mnStockPenCount = 4;
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 	pSalData->maStockBrushColorAry[0]	= PALETTERGB( 0, 0, 0 );
161cdf0e10cSrcweir 	pSalData->maStockBrushColorAry[1]	= PALETTERGB( 0xFF, 0xFF, 0xFF );
162cdf0e10cSrcweir 	pSalData->maStockBrushColorAry[2]	= PALETTERGB( 0xC0, 0xC0, 0xC0 );
163cdf0e10cSrcweir 	pSalData->maStockBrushColorAry[3]	= PALETTERGB( 0x80, 0x80, 0x80 );
164cdf0e10cSrcweir 	pSalData->mhStockBrushAry[0]		= CreateSolidBrush( pSalData->maStockBrushColorAry[0] );
165cdf0e10cSrcweir 	pSalData->mhStockBrushAry[1]		= CreateSolidBrush( pSalData->maStockBrushColorAry[1] );
166cdf0e10cSrcweir 	pSalData->mhStockBrushAry[2]		= CreateSolidBrush( pSalData->maStockBrushColorAry[2] );
167cdf0e10cSrcweir 	pSalData->mhStockBrushAry[3]		= CreateSolidBrush( pSalData->maStockBrushColorAry[3] );
168cdf0e10cSrcweir 	pSalData->mnStockBrushCount = 4;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 	// initialize cache of device contexts
171cdf0e10cSrcweir 	pSalData->mpHDCCache = new HDCCache[ CACHESIZE_HDC ];
172cdf0e10cSrcweir 	memset( pSalData->mpHDCCache, 0, CACHESIZE_HDC * sizeof( HDCCache ) );
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     // initialize temporary font list
175cdf0e10cSrcweir     pSalData->mpTempFontItem = NULL;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 	// support palettes for 256 color displays
178cdf0e10cSrcweir 	HDC hDC = GetDC( 0 );
179cdf0e10cSrcweir 	int nBitsPixel = GetDeviceCaps( hDC, BITSPIXEL );
180cdf0e10cSrcweir 	int nPlanes = GetDeviceCaps( hDC, PLANES );
181cdf0e10cSrcweir 	int nRasterCaps = GetDeviceCaps( hDC, RASTERCAPS );
182cdf0e10cSrcweir 	int nBitCount = nBitsPixel * nPlanes;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	if ( (nBitCount > 8) && (nBitCount < 24) )
185cdf0e10cSrcweir 	{
186cdf0e10cSrcweir 		// test, if we have to dither
187cdf0e10cSrcweir 		HDC 		hMemDC = ::CreateCompatibleDC( hDC );
188cdf0e10cSrcweir 		HBITMAP 	hMemBmp = ::CreateCompatibleBitmap( hDC, 8, 8 );
189cdf0e10cSrcweir 		HBITMAP 	hBmpOld = (HBITMAP) ::SelectObject( hMemDC, hMemBmp );
190cdf0e10cSrcweir 		HBRUSH		hMemBrush = ::CreateSolidBrush( PALETTERGB( 175, 171, 169 ) );
191cdf0e10cSrcweir 		HBRUSH		hBrushOld = (HBRUSH) ::SelectObject( hMemDC, hMemBrush );
192cdf0e10cSrcweir 		sal_Bool		bDither16 = TRUE;
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 		::PatBlt( hMemDC, 0, 0, 8, 8, PATCOPY );
195cdf0e10cSrcweir 		const COLORREF aCol( ::GetPixel( hMemDC, 0, 0 ) );
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 		for( int nY = 0; ( nY < 8 ) && bDither16; nY++ )
198cdf0e10cSrcweir 			for( int nX = 0; ( nX < 8 ) && bDither16; nX++ )
199cdf0e10cSrcweir 				if( ::GetPixel( hMemDC, nX, nY ) != aCol )
200cdf0e10cSrcweir 					bDither16 = FALSE;
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 		::SelectObject( hMemDC, hBrushOld ), ::DeleteObject( hMemBrush );
203cdf0e10cSrcweir 		::SelectObject( hMemDC, hBmpOld ), ::DeleteObject( hMemBmp );
204cdf0e10cSrcweir 		::DeleteDC( hMemDC );
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 		if( bDither16 )
207cdf0e10cSrcweir 		{
208cdf0e10cSrcweir 			// create DIBPattern for 16Bit dithering
209cdf0e10cSrcweir 			long n;
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 			pSalData->mhDitherDIB = GlobalAlloc( GMEM_FIXED, sizeof( BITMAPINFOHEADER ) + 192 );
212cdf0e10cSrcweir 			pSalData->mpDitherDIB = (BYTE*) GlobalLock( pSalData->mhDitherDIB );
213cdf0e10cSrcweir 			pSalData->mpDitherDiff = new long[ 256 ];
214cdf0e10cSrcweir 			pSalData->mpDitherLow = new BYTE[ 256 ];
215cdf0e10cSrcweir 			pSalData->mpDitherHigh = new BYTE[ 256 ];
216cdf0e10cSrcweir 			pSalData->mpDitherDIBData = pSalData->mpDitherDIB + sizeof( BITMAPINFOHEADER );
217cdf0e10cSrcweir 			memset( pSalData->mpDitherDIB, 0, sizeof( BITMAPINFOHEADER ) );
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 			BITMAPINFOHEADER* pBIH = (BITMAPINFOHEADER*) pSalData->mpDitherDIB;
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 			pBIH->biSize = sizeof( BITMAPINFOHEADER );
222cdf0e10cSrcweir 			pBIH->biWidth = 8;
223cdf0e10cSrcweir 			pBIH->biHeight = 8;
224cdf0e10cSrcweir 			pBIH->biPlanes = 1;
225cdf0e10cSrcweir 			pBIH->biBitCount = 24;
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 			for( n = 0; n < 256L; n++ )
228cdf0e10cSrcweir 				pSalData->mpDitherDiff[ n ] = n - ( n & 248L );
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 			for( n = 0; n < 256L; n++ )
231cdf0e10cSrcweir 				pSalData->mpDitherLow[ n ] = (BYTE) ( n & 248 );
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 			for( n = 0; n < 256L; n++ )
234cdf0e10cSrcweir 				pSalData->mpDitherHigh[ n ] = (BYTE) Min( pSalData->mpDitherLow[ n ] + 8L, 255L );
235cdf0e10cSrcweir 		}
236cdf0e10cSrcweir 	}
237cdf0e10cSrcweir 	else if ( (nRasterCaps & RC_PALETTE) && (nBitCount == 8) )
238cdf0e10cSrcweir 	{
239cdf0e10cSrcweir 		BYTE			nRed, nGreen, nBlue;
240cdf0e10cSrcweir 		BYTE			nR, nG, nB;
241cdf0e10cSrcweir 		PALETTEENTRY*	pPalEntry;
242cdf0e10cSrcweir 		LOGPALETTE* 	pLogPal;
243cdf0e10cSrcweir 		const sal_uInt16	nDitherPalCount = DITHER_PAL_COUNT;
244cdf0e10cSrcweir 		sal_uLong			nTotalCount = DITHER_MAX_SYSCOLOR + nDitherPalCount + DITHER_EXTRA_COLORS;
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 		// create logical palette
247cdf0e10cSrcweir 		pLogPal = (LOGPALETTE*) new char[ sizeof( LOGPALETTE ) + ( nTotalCount * sizeof( PALETTEENTRY ) ) ];
248cdf0e10cSrcweir 		pLogPal->palVersion = 0x0300;
249cdf0e10cSrcweir 		pLogPal->palNumEntries = (sal_uInt16) nTotalCount;
250cdf0e10cSrcweir 		pPalEntry = pLogPal->palPalEntry;
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 		// Standard colors
253cdf0e10cSrcweir 		memcpy( pPalEntry, aImplSalSysPalEntryAry, DITHER_MAX_SYSCOLOR * sizeof( PALETTEENTRY ) );
254cdf0e10cSrcweir 		pPalEntry += DITHER_MAX_SYSCOLOR;
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 		// own palette (6/6/6)
257cdf0e10cSrcweir 		for( nB=0, nBlue=0; nB < DITHER_PAL_STEPS; nB++, nBlue += DITHER_PAL_DELTA )
258cdf0e10cSrcweir 		{
259cdf0e10cSrcweir 			for( nG=0, nGreen=0; nG < DITHER_PAL_STEPS; nG++, nGreen += DITHER_PAL_DELTA )
260cdf0e10cSrcweir 			{
261cdf0e10cSrcweir 				for( nR=0, nRed=0; nR < DITHER_PAL_STEPS; nR++, nRed += DITHER_PAL_DELTA )
262cdf0e10cSrcweir 				{
263cdf0e10cSrcweir 					pPalEntry->peRed   = nRed;
264cdf0e10cSrcweir 					pPalEntry->peGreen = nGreen;
265cdf0e10cSrcweir 					pPalEntry->peBlue  = nBlue;
266cdf0e10cSrcweir 					pPalEntry->peFlags = 0;
267cdf0e10cSrcweir 					pPalEntry++;
268cdf0e10cSrcweir 				}
269cdf0e10cSrcweir 			}
270cdf0e10cSrcweir 		}
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 		// insert special 'Blue' as standard drawing color
273cdf0e10cSrcweir 		*pPalEntry++ = aImplExtraColor1;
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 		// create palette
276cdf0e10cSrcweir 		pSalData->mhDitherPal = CreatePalette( pLogPal );
277cdf0e10cSrcweir 		delete[] (char*) pLogPal;
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 		if( pSalData->mhDitherPal )
280cdf0e10cSrcweir 		{
281cdf0e10cSrcweir 			// create DIBPattern for 8Bit dithering
282cdf0e10cSrcweir 			long nSize = sizeof( BITMAPINFOHEADER ) + ( 256 * sizeof( short ) ) + 64;
283cdf0e10cSrcweir 			long n;
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 			pSalData->mhDitherDIB = GlobalAlloc( GMEM_FIXED, nSize );
286cdf0e10cSrcweir 			pSalData->mpDitherDIB = (BYTE*) GlobalLock( pSalData->mhDitherDIB );
287cdf0e10cSrcweir 			pSalData->mpDitherDiff = new long[ 256 ];
288cdf0e10cSrcweir 			pSalData->mpDitherLow = new BYTE[ 256 ];
289cdf0e10cSrcweir 			pSalData->mpDitherHigh = new BYTE[ 256 ];
290cdf0e10cSrcweir 			pSalData->mpDitherDIBData = pSalData->mpDitherDIB + sizeof( BITMAPINFOHEADER ) + ( 256 * sizeof( short ) );
291cdf0e10cSrcweir 			memset( pSalData->mpDitherDIB, 0, sizeof( BITMAPINFOHEADER ) );
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 			BITMAPINFOHEADER*	pBIH = (BITMAPINFOHEADER*) pSalData->mpDitherDIB;
294cdf0e10cSrcweir 			short*				pColors = (short*) ( pSalData->mpDitherDIB + sizeof( BITMAPINFOHEADER ) );
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 			pBIH->biSize = sizeof( BITMAPINFOHEADER );
297cdf0e10cSrcweir 			pBIH->biWidth = 8;
298cdf0e10cSrcweir 			pBIH->biHeight = 8;
299cdf0e10cSrcweir 			pBIH->biPlanes = 1;
300cdf0e10cSrcweir 			pBIH->biBitCount = 8;
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 			for( n = 0; n < nDitherPalCount; n++ )
303cdf0e10cSrcweir 				pColors[ n ] = (short)( n + DITHER_MAX_SYSCOLOR );
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 			for( n = 0; n < 256L; n++ )
306cdf0e10cSrcweir 				pSalData->mpDitherDiff[ n ] = n % 51L;
307cdf0e10cSrcweir 
308cdf0e10cSrcweir 			for( n = 0; n < 256L; n++ )
309cdf0e10cSrcweir 				pSalData->mpDitherLow[ n ] = (BYTE) ( n / 51L );
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 			for( n = 0; n < 256L; n++ )
312cdf0e10cSrcweir 				pSalData->mpDitherHigh[ n ] = (BYTE)Min( pSalData->mpDitherLow[ n ] + 1, 5 );
313cdf0e10cSrcweir 		}
314cdf0e10cSrcweir 
315cdf0e10cSrcweir 		// get system color entries
316cdf0e10cSrcweir 		ImplUpdateSysColorEntries();
317cdf0e10cSrcweir 	}
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 	ReleaseDC( 0, hDC );
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir // -----------------------------------------------------------------------
323cdf0e10cSrcweir 
324cdf0e10cSrcweir void ImplFreeSalGDI()
325cdf0e10cSrcweir {
326cdf0e10cSrcweir 	SalData*	pSalData = GetSalData();
327cdf0e10cSrcweir 
328cdf0e10cSrcweir 	// destroy stock objects
329cdf0e10cSrcweir 	int	i;
330cdf0e10cSrcweir 	for ( i = 0; i < pSalData->mnStockPenCount; i++ )
331cdf0e10cSrcweir 		DeletePen( pSalData->mhStockPenAry[i] );
332cdf0e10cSrcweir 	for ( i = 0; i < pSalData->mnStockBrushCount; i++ )
333cdf0e10cSrcweir 		DeleteBrush( pSalData->mhStockBrushAry[i] );
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 	// 50% Brush loeschen
336cdf0e10cSrcweir 	if ( pSalData->mh50Brush )
337cdf0e10cSrcweir 	{
338cdf0e10cSrcweir 		DeleteBrush( pSalData->mh50Brush );
339cdf0e10cSrcweir 		pSalData->mh50Brush = 0;
340cdf0e10cSrcweir 	}
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 	// 50% Bitmap loeschen
343cdf0e10cSrcweir 	if ( pSalData->mh50Bmp )
344cdf0e10cSrcweir 	{
345cdf0e10cSrcweir 		DeleteBitmap( pSalData->mh50Bmp );
346cdf0e10cSrcweir 		pSalData->mh50Bmp = 0;
347cdf0e10cSrcweir 	}
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 	ImplClearHDCCache( pSalData );
350cdf0e10cSrcweir 	delete[] pSalData->mpHDCCache;
351cdf0e10cSrcweir 
352cdf0e10cSrcweir 	// Ditherpalette loeschen, wenn vorhanden
353cdf0e10cSrcweir 	if ( pSalData->mhDitherPal )
354cdf0e10cSrcweir 	{
355cdf0e10cSrcweir 		DeleteObject( pSalData->mhDitherPal );
356cdf0e10cSrcweir 		pSalData->mhDitherPal = 0;
357cdf0e10cSrcweir 	}
358cdf0e10cSrcweir 
359cdf0e10cSrcweir 	// delete buffers for dithering DIB patterns, if neccessary
360cdf0e10cSrcweir 	if ( pSalData->mhDitherDIB )
361cdf0e10cSrcweir 	{
362cdf0e10cSrcweir 		GlobalUnlock( pSalData->mhDitherDIB );
363cdf0e10cSrcweir 		GlobalFree( pSalData->mhDitherDIB );
364cdf0e10cSrcweir 		pSalData->mhDitherDIB = 0;
365cdf0e10cSrcweir 		delete[] pSalData->mpDitherDiff;
366cdf0e10cSrcweir 		delete[] pSalData->mpDitherLow;
367cdf0e10cSrcweir 		delete[] pSalData->mpDitherHigh;
368cdf0e10cSrcweir 	}
369cdf0e10cSrcweir 
370cdf0e10cSrcweir 	// delete SysColorList
371cdf0e10cSrcweir 	SysColorEntry* pEntry = pFirstSysColor;
372cdf0e10cSrcweir 	while( pEntry )
373cdf0e10cSrcweir 	{
374cdf0e10cSrcweir 		SysColorEntry* pTmp = pEntry->pNext;
375cdf0e10cSrcweir 		delete pEntry;
376cdf0e10cSrcweir 		pEntry = pTmp;
377cdf0e10cSrcweir 	}
378cdf0e10cSrcweir 	pFirstSysColor = NULL;
379cdf0e10cSrcweir 
380cdf0e10cSrcweir     // delete icon cache
381cdf0e10cSrcweir     SalIcon* pIcon = pSalData->mpFirstIcon;
382cdf0e10cSrcweir     pSalData->mpFirstIcon = NULL;
383cdf0e10cSrcweir     while( pIcon )
384cdf0e10cSrcweir     {
385cdf0e10cSrcweir         SalIcon* pTmp = pIcon->pNext;
386cdf0e10cSrcweir         DestroyIcon( pIcon->hIcon );
387cdf0e10cSrcweir         DestroyIcon( pIcon->hSmallIcon );
388cdf0e10cSrcweir         delete pIcon;
389cdf0e10cSrcweir         pIcon = pTmp;
390cdf0e10cSrcweir     }
391cdf0e10cSrcweir 
392cdf0e10cSrcweir     // delete temporary font list
393cdf0e10cSrcweir     ImplReleaseTempFonts( *pSalData );
394cdf0e10cSrcweir }
395cdf0e10cSrcweir 
396cdf0e10cSrcweir // -----------------------------------------------------------------------
397cdf0e10cSrcweir 
398cdf0e10cSrcweir static int ImplIsPaletteEntry( BYTE nRed, BYTE nGreen, BYTE nBlue )
399cdf0e10cSrcweir {
400cdf0e10cSrcweir 	// dither color?
401cdf0e10cSrcweir 	if ( !(nRed % DITHER_PAL_DELTA) && !(nGreen % DITHER_PAL_DELTA) && !(nBlue % DITHER_PAL_DELTA) )
402cdf0e10cSrcweir 		return TRUE;
403cdf0e10cSrcweir 
404cdf0e10cSrcweir 	PALETTEENTRY* pPalEntry = aImplSalSysPalEntryAry;
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 	// standard palette color?
407cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < DITHER_MAX_SYSCOLOR; i++, pPalEntry++ )
408cdf0e10cSrcweir 	{
409cdf0e10cSrcweir 		if( pPalEntry->peRed == nRed && pPalEntry->peGreen == nGreen && pPalEntry->peBlue == nBlue )
410cdf0e10cSrcweir 			return TRUE;
411cdf0e10cSrcweir 	}
412cdf0e10cSrcweir 
413cdf0e10cSrcweir 	// extra color?
414cdf0e10cSrcweir 	if ( aImplExtraColor1.peRed == nRed &&
415cdf0e10cSrcweir 		 aImplExtraColor1.peGreen == nGreen &&
416cdf0e10cSrcweir 		 aImplExtraColor1.peBlue == nBlue )
417cdf0e10cSrcweir 	{
418cdf0e10cSrcweir 		return TRUE;
419cdf0e10cSrcweir 	}
420cdf0e10cSrcweir 
421cdf0e10cSrcweir 	return FALSE;
422cdf0e10cSrcweir }
423cdf0e10cSrcweir 
424cdf0e10cSrcweir // =======================================================================
425cdf0e10cSrcweir 
426cdf0e10cSrcweir int ImplIsSysColorEntry( SalColor nSalColor )
427cdf0e10cSrcweir {
428cdf0e10cSrcweir 	SysColorEntry*	pEntry = pFirstSysColor;
429cdf0e10cSrcweir 	const DWORD 	nTestRGB = (DWORD)RGB( SALCOLOR_RED( nSalColor ),
430cdf0e10cSrcweir 										   SALCOLOR_GREEN( nSalColor ),
431cdf0e10cSrcweir 										   SALCOLOR_BLUE( nSalColor ) );
432cdf0e10cSrcweir 
433cdf0e10cSrcweir 	while ( pEntry )
434cdf0e10cSrcweir 	{
435cdf0e10cSrcweir 		if ( pEntry->nRGB == nTestRGB )
436cdf0e10cSrcweir 			return TRUE;
437cdf0e10cSrcweir 		pEntry = pEntry->pNext;
438cdf0e10cSrcweir 	}
439cdf0e10cSrcweir 
440cdf0e10cSrcweir 	return FALSE;
441cdf0e10cSrcweir }
442cdf0e10cSrcweir 
443cdf0e10cSrcweir // =======================================================================
444cdf0e10cSrcweir 
445cdf0e10cSrcweir static void ImplInsertSysColorEntry( int nSysIndex )
446cdf0e10cSrcweir {
447cdf0e10cSrcweir 	const DWORD nRGB = GetSysColor( nSysIndex );
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 	if ( !ImplIsPaletteEntry( GetRValue( nRGB ), GetGValue( nRGB ), GetBValue( nRGB ) ) )
450cdf0e10cSrcweir 	{
451cdf0e10cSrcweir 		if ( !pFirstSysColor )
452cdf0e10cSrcweir 		{
453cdf0e10cSrcweir 			pActSysColor = pFirstSysColor = new SysColorEntry;
454cdf0e10cSrcweir 			pFirstSysColor->nRGB = nRGB;
455cdf0e10cSrcweir 			pFirstSysColor->pNext = NULL;
456cdf0e10cSrcweir 		}
457cdf0e10cSrcweir 		else
458cdf0e10cSrcweir 		{
459cdf0e10cSrcweir 			pActSysColor = pActSysColor->pNext = new SysColorEntry;
460cdf0e10cSrcweir 			pActSysColor->nRGB = nRGB;
461cdf0e10cSrcweir 			pActSysColor->pNext = NULL;
462cdf0e10cSrcweir 		}
463cdf0e10cSrcweir 	}
464cdf0e10cSrcweir }
465cdf0e10cSrcweir 
466cdf0e10cSrcweir // =======================================================================
467cdf0e10cSrcweir 
468cdf0e10cSrcweir void ImplUpdateSysColorEntries()
469cdf0e10cSrcweir {
470cdf0e10cSrcweir 	// delete old SysColorList
471cdf0e10cSrcweir 	SysColorEntry* pEntry = pFirstSysColor;
472cdf0e10cSrcweir 	while( pEntry )
473cdf0e10cSrcweir 	{
474cdf0e10cSrcweir 		SysColorEntry* pTmp = pEntry->pNext;
475cdf0e10cSrcweir 		delete pEntry;
476cdf0e10cSrcweir 		pEntry = pTmp;
477cdf0e10cSrcweir 	}
478cdf0e10cSrcweir 	pActSysColor = pFirstSysColor = NULL;
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 	// create new sys color list
481cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_ACTIVEBORDER );
482cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_INACTIVEBORDER );
483cdf0e10cSrcweir 	if( aSalShlData.mnVersion >= 410 )
484cdf0e10cSrcweir 	{
485cdf0e10cSrcweir 		ImplInsertSysColorEntry( COLOR_GRADIENTACTIVECAPTION );
486cdf0e10cSrcweir 		ImplInsertSysColorEntry( COLOR_GRADIENTINACTIVECAPTION );
487cdf0e10cSrcweir 	}
488cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_3DFACE );
489cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_3DHILIGHT );
490cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_3DLIGHT );
491cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_3DSHADOW );
492cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_3DDKSHADOW );
493cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_INFOBK );
494cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_INFOTEXT );
495cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_BTNTEXT );
496cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_WINDOW );
497cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_WINDOWTEXT );
498cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_HIGHLIGHT );
499cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_HIGHLIGHTTEXT );
500cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_MENU );
501cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_MENUTEXT );
502cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_ACTIVECAPTION );
503cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_CAPTIONTEXT );
504cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_INACTIVECAPTION );
505cdf0e10cSrcweir 	ImplInsertSysColorEntry( COLOR_INACTIVECAPTIONTEXT );
506cdf0e10cSrcweir }
507cdf0e10cSrcweir 
508cdf0e10cSrcweir // -----------------------------------------------------------------------
509cdf0e10cSrcweir 
510cdf0e10cSrcweir static SalColor ImplGetROPSalColor( SalROPColor nROPColor )
511cdf0e10cSrcweir {
512cdf0e10cSrcweir 	SalColor nSalColor;
513cdf0e10cSrcweir 	if ( nROPColor == SAL_ROP_0 )
514cdf0e10cSrcweir 		nSalColor = MAKE_SALCOLOR( 0, 0, 0 );
515cdf0e10cSrcweir 	else
516cdf0e10cSrcweir 		nSalColor = MAKE_SALCOLOR( 255, 255, 255 );
517cdf0e10cSrcweir 	return nSalColor;
518cdf0e10cSrcweir }
519cdf0e10cSrcweir 
520cdf0e10cSrcweir // =======================================================================
521cdf0e10cSrcweir 
522cdf0e10cSrcweir void ImplSalInitGraphics( WinSalGraphics* pData )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir 	// Beim Printer berechnen wir die minimale Linienstaerke
525cdf0e10cSrcweir 	if ( pData->mbPrinter )
526cdf0e10cSrcweir 	{
527*5f27b83cSArmin Le Grand 		int nDPIX = GetDeviceCaps( pData->getHDC(), LOGPIXELSX );
528cdf0e10cSrcweir 		if ( nDPIX <= 300 )
529cdf0e10cSrcweir 			pData->mnPenWidth = 0;
530cdf0e10cSrcweir 		else
531cdf0e10cSrcweir 			pData->mnPenWidth = nDPIX/300;
532cdf0e10cSrcweir 	}
533cdf0e10cSrcweir 
534*5f27b83cSArmin Le Grand 	::SetTextAlign( pData->getHDC(), TA_BASELINE | TA_LEFT | TA_NOUPDATECP );
535*5f27b83cSArmin Le Grand 	::SetBkMode( pData->getHDC(), TRANSPARENT );
536*5f27b83cSArmin Le Grand 	::SetROP2( pData->getHDC(), R2_COPYPEN );
537cdf0e10cSrcweir }
538cdf0e10cSrcweir 
539cdf0e10cSrcweir // -----------------------------------------------------------------------
540cdf0e10cSrcweir 
541cdf0e10cSrcweir void ImplSalDeInitGraphics( WinSalGraphics* pData )
542cdf0e10cSrcweir {
543cdf0e10cSrcweir     // clear clip region
544*5f27b83cSArmin Le Grand 	SelectClipRgn( pData->getHDC(), 0 );
545cdf0e10cSrcweir 	// select default objects
546cdf0e10cSrcweir 	if ( pData->mhDefPen )
547*5f27b83cSArmin Le Grand 		SelectPen( pData->getHDC(), pData->mhDefPen );
548cdf0e10cSrcweir 	if ( pData->mhDefBrush )
549*5f27b83cSArmin Le Grand 		SelectBrush( pData->getHDC(), pData->mhDefBrush );
550cdf0e10cSrcweir 	if ( pData->mhDefFont )
551*5f27b83cSArmin Le Grand 		SelectFont( pData->getHDC(), pData->mhDefFont );
552cdf0e10cSrcweir }
553cdf0e10cSrcweir 
554cdf0e10cSrcweir // =======================================================================
555cdf0e10cSrcweir 
556cdf0e10cSrcweir HDC ImplGetCachedDC( sal_uLong nID, HBITMAP hBmp )
557cdf0e10cSrcweir {
558cdf0e10cSrcweir 	SalData*	pSalData = GetSalData();
559cdf0e10cSrcweir 	HDCCache*	pC = &pSalData->mpHDCCache[ nID ];
560cdf0e10cSrcweir 
561cdf0e10cSrcweir 	if( !pC->mhDC )
562cdf0e10cSrcweir 	{
563cdf0e10cSrcweir 		HDC hDC = GetDC( 0 );
564cdf0e10cSrcweir 
565cdf0e10cSrcweir 		// neuen DC mit DefaultBitmap anlegen
566cdf0e10cSrcweir 		pC->mhDC = CreateCompatibleDC( hDC );
567cdf0e10cSrcweir 
568cdf0e10cSrcweir 		if( pSalData->mhDitherPal )
569cdf0e10cSrcweir 		{
570cdf0e10cSrcweir 			pC->mhDefPal = SelectPalette( pC->mhDC, pSalData->mhDitherPal, TRUE );
571cdf0e10cSrcweir 			RealizePalette( pC->mhDC );
572cdf0e10cSrcweir 		}
573cdf0e10cSrcweir 
574cdf0e10cSrcweir 		pC->mhSelBmp = CreateCompatibleBitmap( hDC, CACHED_HDC_DEFEXT, CACHED_HDC_DEFEXT );
575cdf0e10cSrcweir 		pC->mhDefBmp = (HBITMAP) SelectObject( pC->mhDC, pC->mhSelBmp );
576cdf0e10cSrcweir 
577cdf0e10cSrcweir 		ReleaseDC( 0, hDC );
578cdf0e10cSrcweir 	}
579cdf0e10cSrcweir 
580cdf0e10cSrcweir 	if ( hBmp )
581cdf0e10cSrcweir 		SelectObject( pC->mhDC, pC->mhActBmp = hBmp );
582cdf0e10cSrcweir 	else
583cdf0e10cSrcweir 		pC->mhActBmp = 0;
584cdf0e10cSrcweir 
585cdf0e10cSrcweir 	return pC->mhDC;
586cdf0e10cSrcweir }
587cdf0e10cSrcweir 
588cdf0e10cSrcweir // =======================================================================
589cdf0e10cSrcweir 
590cdf0e10cSrcweir void ImplReleaseCachedDC( sal_uLong nID )
591cdf0e10cSrcweir {
592cdf0e10cSrcweir 	SalData*	pSalData = GetSalData();
593cdf0e10cSrcweir 	HDCCache*	pC = &pSalData->mpHDCCache[ nID ];
594cdf0e10cSrcweir 
595cdf0e10cSrcweir 	if ( pC->mhActBmp )
596cdf0e10cSrcweir 		SelectObject( pC->mhDC, pC->mhSelBmp );
597cdf0e10cSrcweir }
598cdf0e10cSrcweir 
599cdf0e10cSrcweir // =======================================================================
600cdf0e10cSrcweir 
601cdf0e10cSrcweir void ImplClearHDCCache( SalData* pData )
602cdf0e10cSrcweir {
603cdf0e10cSrcweir 	for( sal_uLong i = 0; i < CACHESIZE_HDC; i++ )
604cdf0e10cSrcweir 	{
605cdf0e10cSrcweir 		HDCCache* pC = &pData->mpHDCCache[ i ];
606cdf0e10cSrcweir 
607cdf0e10cSrcweir 		if( pC->mhDC )
608cdf0e10cSrcweir 		{
609cdf0e10cSrcweir 			SelectObject( pC->mhDC, pC->mhDefBmp );
610cdf0e10cSrcweir 
611cdf0e10cSrcweir 			if( pC->mhDefPal )
612cdf0e10cSrcweir 				SelectPalette( pC->mhDC, pC->mhDefPal, TRUE );
613cdf0e10cSrcweir 
614cdf0e10cSrcweir 			DeleteDC( pC->mhDC );
615cdf0e10cSrcweir 			DeleteObject( pC->mhSelBmp );
616cdf0e10cSrcweir 		}
617cdf0e10cSrcweir 	}
618cdf0e10cSrcweir }
619cdf0e10cSrcweir 
620cdf0e10cSrcweir // =======================================================================
621cdf0e10cSrcweir 
622cdf0e10cSrcweir // #100127# Fill point and flag memory from array of points which
623cdf0e10cSrcweir // might also contain bezier control points for the PolyDraw() GDI method
624cdf0e10cSrcweir // Make sure pWinPointAry and pWinFlagAry are big enough
625cdf0e10cSrcweir void ImplPreparePolyDraw( bool						bCloseFigures,
626cdf0e10cSrcweir                           sal_uLong 					nPoly,
627cdf0e10cSrcweir                           const sal_uLong* 				pPoints,
628cdf0e10cSrcweir                           const SalPoint* const* 	pPtAry,
629cdf0e10cSrcweir                           const BYTE* const* 		pFlgAry,
630cdf0e10cSrcweir                           POINT* 					pWinPointAry,
631cdf0e10cSrcweir                           BYTE* 					pWinFlagAry		)
632cdf0e10cSrcweir {
633cdf0e10cSrcweir     sal_uLong nCurrPoly;
634cdf0e10cSrcweir     for( nCurrPoly=0; nCurrPoly<nPoly; ++nCurrPoly )
635cdf0e10cSrcweir     {
636cdf0e10cSrcweir         const POINT* pCurrPoint = reinterpret_cast<const POINT*>( *pPtAry++ );
637cdf0e10cSrcweir         const BYTE* pCurrFlag = *pFlgAry++;
638cdf0e10cSrcweir         const sal_uLong nCurrPoints = *pPoints++;
639cdf0e10cSrcweir         const bool bHaveFlagArray( pCurrFlag );
640cdf0e10cSrcweir         sal_uLong nCurrPoint;
641cdf0e10cSrcweir 
642cdf0e10cSrcweir         if( nCurrPoints )
643cdf0e10cSrcweir         {
644cdf0e10cSrcweir             // start figure
645cdf0e10cSrcweir             *pWinPointAry++ = *pCurrPoint++;
646cdf0e10cSrcweir             *pWinFlagAry++  = PT_MOVETO;
647cdf0e10cSrcweir             ++pCurrFlag;
648cdf0e10cSrcweir 
649cdf0e10cSrcweir             for( nCurrPoint=1; nCurrPoint<nCurrPoints; )
650cdf0e10cSrcweir             {
651cdf0e10cSrcweir                 // #102067# Check existence of flag array
652cdf0e10cSrcweir                 if( bHaveFlagArray &&
653cdf0e10cSrcweir                     ( nCurrPoint + 2 ) < nCurrPoints )
654cdf0e10cSrcweir                 {
655cdf0e10cSrcweir                     BYTE P4( pCurrFlag[ 2 ] );
656cdf0e10cSrcweir 
657cdf0e10cSrcweir                     if( ( POLY_CONTROL == pCurrFlag[ 0 ] ) &&
658cdf0e10cSrcweir                         ( POLY_CONTROL == pCurrFlag[ 1 ] ) &&
659cdf0e10cSrcweir                         ( POLY_NORMAL == P4 || POLY_SMOOTH == P4 || POLY_SYMMTR == P4 ) )
660cdf0e10cSrcweir                     {
661cdf0e10cSrcweir                         // control point one
662cdf0e10cSrcweir                         *pWinPointAry++ = *pCurrPoint++;
663cdf0e10cSrcweir                         *pWinFlagAry++  = PT_BEZIERTO;
664cdf0e10cSrcweir 
665cdf0e10cSrcweir                         // control point two
666cdf0e10cSrcweir                         *pWinPointAry++ = *pCurrPoint++;
667cdf0e10cSrcweir                         *pWinFlagAry++  = PT_BEZIERTO;
668cdf0e10cSrcweir 
669cdf0e10cSrcweir                         // end point
670cdf0e10cSrcweir                         *pWinPointAry++ = *pCurrPoint++;
671cdf0e10cSrcweir                         *pWinFlagAry++  = PT_BEZIERTO;
672cdf0e10cSrcweir 
673cdf0e10cSrcweir                         nCurrPoint += 3;
674cdf0e10cSrcweir                         pCurrFlag += 3;
675cdf0e10cSrcweir                         continue;
676cdf0e10cSrcweir                     }
677cdf0e10cSrcweir                 }
678cdf0e10cSrcweir 
679cdf0e10cSrcweir                 // regular line point
680cdf0e10cSrcweir                 *pWinPointAry++ = *pCurrPoint++;
681cdf0e10cSrcweir                 *pWinFlagAry++  = PT_LINETO;
682cdf0e10cSrcweir                 ++pCurrFlag;
683cdf0e10cSrcweir                 ++nCurrPoint;
684cdf0e10cSrcweir             }
685cdf0e10cSrcweir 
686cdf0e10cSrcweir             // end figure?
687cdf0e10cSrcweir             if( bCloseFigures )
688cdf0e10cSrcweir                 pWinFlagAry[-1] |= PT_CLOSEFIGURE;
689cdf0e10cSrcweir         }
690cdf0e10cSrcweir     }
691cdf0e10cSrcweir }
692cdf0e10cSrcweir 
693cdf0e10cSrcweir // =======================================================================
694cdf0e10cSrcweir 
695cdf0e10cSrcweir // #100127# draw an array of points which might also contain bezier control points
696cdf0e10cSrcweir void ImplRenderPath( HDC hdc, sal_uLong nPoints, const SalPoint* pPtAry, const BYTE* pFlgAry )
697cdf0e10cSrcweir {
698cdf0e10cSrcweir     if( nPoints )
699cdf0e10cSrcweir     {
700cdf0e10cSrcweir         sal_uInt16 i;
701cdf0e10cSrcweir         // TODO: profile whether the following options are faster:
702cdf0e10cSrcweir         // a) look ahead and draw consecutive bezier or line segments by PolyBezierTo/PolyLineTo resp.
703cdf0e10cSrcweir         // b) convert our flag array to window's and use PolyDraw
704cdf0e10cSrcweir 
705cdf0e10cSrcweir         MoveToEx( hdc, pPtAry->mnX, pPtAry->mnY, NULL );
706cdf0e10cSrcweir         ++pPtAry; ++pFlgAry;
707cdf0e10cSrcweir 
708cdf0e10cSrcweir         for( i=1; i<nPoints; ++i, ++pPtAry, ++pFlgAry )
709cdf0e10cSrcweir         {
710cdf0e10cSrcweir             if( *pFlgAry != POLY_CONTROL )
711cdf0e10cSrcweir             {
712cdf0e10cSrcweir                 LineTo( hdc, pPtAry->mnX, pPtAry->mnY );
713cdf0e10cSrcweir             }
714cdf0e10cSrcweir             else if( nPoints - i > 2 )
715cdf0e10cSrcweir             {
716cdf0e10cSrcweir                 PolyBezierTo( hdc, reinterpret_cast<const POINT*>(pPtAry), 3 );
717cdf0e10cSrcweir                 i += 2; pPtAry += 2; pFlgAry += 2;
718cdf0e10cSrcweir             }
719cdf0e10cSrcweir         }
720cdf0e10cSrcweir     }
721cdf0e10cSrcweir }
722cdf0e10cSrcweir 
723cdf0e10cSrcweir // =======================================================================
724cdf0e10cSrcweir 
725cdf0e10cSrcweir WinSalGraphics::WinSalGraphics()
726cdf0e10cSrcweir {
727cdf0e10cSrcweir     for( int i = 0; i < MAX_FALLBACK; ++i )
728cdf0e10cSrcweir     {
729cdf0e10cSrcweir         mhFonts[ i ] = 0;
730cdf0e10cSrcweir         mpWinFontData[ i ]  = NULL;
731cdf0e10cSrcweir         mpWinFontEntry[ i ] = NULL;
732cdf0e10cSrcweir     }
733cdf0e10cSrcweir 
734cdf0e10cSrcweir     mfFontScale = 1.0;
735cdf0e10cSrcweir 
736*5f27b83cSArmin Le Grand 	mhLocalDC			= 0;
737cdf0e10cSrcweir 	mhPen				= 0;
738cdf0e10cSrcweir 	mhBrush				= 0;
739cdf0e10cSrcweir 	mhRegion 			= 0;
740cdf0e10cSrcweir 	mhDefPen 			= 0;
741cdf0e10cSrcweir 	mhDefBrush			= 0;
742cdf0e10cSrcweir 	mhDefFont			= 0;
743cdf0e10cSrcweir 	mhDefPal 			= 0;
744cdf0e10cSrcweir 	mpStdClipRgnData 	= NULL;
745cdf0e10cSrcweir 	mpLogFont			= NULL;
746cdf0e10cSrcweir 	mpFontCharSets		= NULL;
747cdf0e10cSrcweir 	mpFontAttrCache		= NULL;
748cdf0e10cSrcweir 	mnFontCharSetCount	= 0;
749cdf0e10cSrcweir 	mpFontKernPairs		= NULL;
750cdf0e10cSrcweir 	mnFontKernPairCount	= 0;
751cdf0e10cSrcweir 	mbFontKernInit		= FALSE;
752cdf0e10cSrcweir 	mbXORMode			= FALSE;
753cdf0e10cSrcweir 	mnPenWidth			= GSL_PEN_WIDTH;
754cdf0e10cSrcweir }
755cdf0e10cSrcweir 
756cdf0e10cSrcweir // -----------------------------------------------------------------------
757cdf0e10cSrcweir 
758cdf0e10cSrcweir WinSalGraphics::~WinSalGraphics()
759cdf0e10cSrcweir {
760cdf0e10cSrcweir 	// free obsolete GDI objekts
761cdf0e10cSrcweir         ReleaseFonts();
762cdf0e10cSrcweir 
763cdf0e10cSrcweir 	if ( mhPen )
764cdf0e10cSrcweir 	{
765cdf0e10cSrcweir 		if ( !mbStockPen )
766cdf0e10cSrcweir 			DeletePen( mhPen );
767cdf0e10cSrcweir 	}
768cdf0e10cSrcweir 	if ( mhBrush )
769cdf0e10cSrcweir 	{
770cdf0e10cSrcweir 		if ( !mbStockBrush )
771cdf0e10cSrcweir 			DeleteBrush( mhBrush );
772cdf0e10cSrcweir 	}
773cdf0e10cSrcweir 
774cdf0e10cSrcweir 	if ( mhRegion )
775cdf0e10cSrcweir 	{
776cdf0e10cSrcweir 		DeleteRegion( mhRegion );
777cdf0e10cSrcweir 		mhRegion = 0;
778cdf0e10cSrcweir 	}
779cdf0e10cSrcweir 
780cdf0e10cSrcweir 	// Cache-Daten zerstoeren
781cdf0e10cSrcweir 	if ( mpStdClipRgnData )
782cdf0e10cSrcweir 		delete [] mpStdClipRgnData;
783cdf0e10cSrcweir 
784cdf0e10cSrcweir 	if ( mpLogFont )
785cdf0e10cSrcweir 		delete mpLogFont;
786cdf0e10cSrcweir 
787cdf0e10cSrcweir 	if ( mpFontCharSets )
788cdf0e10cSrcweir 		delete mpFontCharSets;
789cdf0e10cSrcweir 
790cdf0e10cSrcweir 	if ( mpFontKernPairs )
791cdf0e10cSrcweir 		delete mpFontKernPairs;
792cdf0e10cSrcweir }
793cdf0e10cSrcweir 
794cdf0e10cSrcweir // -----------------------------------------------------------------------
795cdf0e10cSrcweir 
796cdf0e10cSrcweir void WinSalGraphics::GetResolution( long& rDPIX, long& rDPIY )
797cdf0e10cSrcweir {
798*5f27b83cSArmin Le Grand 	rDPIX = GetDeviceCaps( getHDC(), LOGPIXELSX );
799*5f27b83cSArmin Le Grand 	rDPIY = GetDeviceCaps( getHDC(), LOGPIXELSY );
800cdf0e10cSrcweir 
801cdf0e10cSrcweir     // #111139# this fixes the symptom of div by zero on startup
802cdf0e10cSrcweir     // however, printing will fail most likely as communication with
803cdf0e10cSrcweir     // the printer seems not to work in this case
804cdf0e10cSrcweir     if( !rDPIX || !rDPIY )
805cdf0e10cSrcweir         rDPIX = rDPIY = 600;
806cdf0e10cSrcweir }
807cdf0e10cSrcweir 
808cdf0e10cSrcweir // -----------------------------------------------------------------------
809cdf0e10cSrcweir 
810cdf0e10cSrcweir sal_uInt16 WinSalGraphics::GetBitCount()
811cdf0e10cSrcweir {
812*5f27b83cSArmin Le Grand 	return (sal_uInt16)GetDeviceCaps( getHDC(), BITSPIXEL );
813cdf0e10cSrcweir }
814cdf0e10cSrcweir 
815cdf0e10cSrcweir // -----------------------------------------------------------------------
816cdf0e10cSrcweir 
817cdf0e10cSrcweir long WinSalGraphics::GetGraphicsWidth() const
818cdf0e10cSrcweir {
819cdf0e10cSrcweir     if( mhWnd && IsWindow( mhWnd ) )
820cdf0e10cSrcweir     {
821cdf0e10cSrcweir         WinSalFrame* pFrame = GetWindowPtr( mhWnd );
822cdf0e10cSrcweir         if( pFrame )
823cdf0e10cSrcweir         {
824cdf0e10cSrcweir             if( pFrame->maGeometry.nWidth )
825cdf0e10cSrcweir                 return pFrame->maGeometry.nWidth;
826cdf0e10cSrcweir             else
827cdf0e10cSrcweir             {
828cdf0e10cSrcweir                 // TODO: perhaps not needed, maGeometry should always be up-to-date
829cdf0e10cSrcweir                 RECT aRect;
830cdf0e10cSrcweir                 GetClientRect( mhWnd, &aRect );
831cdf0e10cSrcweir                 return aRect.right;
832cdf0e10cSrcweir             }
833cdf0e10cSrcweir         }
834cdf0e10cSrcweir     }
835cdf0e10cSrcweir 
836cdf0e10cSrcweir     return 0;
837cdf0e10cSrcweir }
838cdf0e10cSrcweir 
839cdf0e10cSrcweir // -----------------------------------------------------------------------
840cdf0e10cSrcweir 
841cdf0e10cSrcweir void WinSalGraphics::ResetClipRegion()
842cdf0e10cSrcweir {
843cdf0e10cSrcweir 	if ( mhRegion )
844cdf0e10cSrcweir 	{
845cdf0e10cSrcweir 		DeleteRegion( mhRegion );
846cdf0e10cSrcweir 		mhRegion = 0;
847cdf0e10cSrcweir 	}
848cdf0e10cSrcweir 
849*5f27b83cSArmin Le Grand 	SelectClipRgn( getHDC(), 0 );
850cdf0e10cSrcweir }
851cdf0e10cSrcweir 
852cdf0e10cSrcweir // -----------------------------------------------------------------------
853cdf0e10cSrcweir 
854cdf0e10cSrcweir bool WinSalGraphics::setClipRegion( const Region& i_rClip )
855cdf0e10cSrcweir {
856cdf0e10cSrcweir 	if ( mhRegion )
857cdf0e10cSrcweir 	{
858cdf0e10cSrcweir 		DeleteRegion( mhRegion );
859cdf0e10cSrcweir 		mhRegion = 0;
860cdf0e10cSrcweir 	}
861cdf0e10cSrcweir 
862e6f63103SArmin Le Grand 	if( i_rClip.HasPolyPolygonOrB2DPolyPolygon() )
863cdf0e10cSrcweir 	{
864e6f63103SArmin Le Grand 	    const basegfx::B2DPolyPolygon aPolyPolygon( i_rClip.GetAsB2DPolyPolygon() );
865cdf0e10cSrcweir         const sal_uInt32 nCount(aPolyPolygon.count());
866cdf0e10cSrcweir 
867cdf0e10cSrcweir         if( nCount )
868cdf0e10cSrcweir         {
869cdf0e10cSrcweir             std::vector< POINT > aPolyPoints;
870cdf0e10cSrcweir             aPolyPoints.reserve( 1024 );
871cdf0e10cSrcweir             std::vector< INT > aPolyCounts( nCount, 0 );
872e6f63103SArmin Le Grand 
873cdf0e10cSrcweir             for(sal_uInt32 a(0); a < nCount; a++)
874cdf0e10cSrcweir             {
875cdf0e10cSrcweir                 basegfx::B2DPolygon aPoly(aPolyPolygon.getB2DPolygon(a));
876e6f63103SArmin Le Grand 
877cdf0e10cSrcweir                 aPoly = basegfx::tools::adaptiveSubdivideByDistance( aPoly, 1 );
878cdf0e10cSrcweir                 const sal_uInt32 nPoints = aPoly.count();
879cdf0e10cSrcweir                 aPolyCounts[a] = nPoints;
880e6f63103SArmin Le Grand 
881cdf0e10cSrcweir                 for( sal_uInt32 b = 0; b < nPoints; b++ )
882cdf0e10cSrcweir                 {
883cdf0e10cSrcweir                     basegfx::B2DPoint aPt( aPoly.getB2DPoint( b ) );
884cdf0e10cSrcweir                     POINT aPOINT;
885cdf0e10cSrcweir                     aPOINT.x = (LONG)aPt.getX();
886cdf0e10cSrcweir                     aPOINT.y = (LONG)aPt.getY();
887cdf0e10cSrcweir                     aPolyPoints.push_back( aPOINT );
888cdf0e10cSrcweir                 }
889cdf0e10cSrcweir             }
890e6f63103SArmin Le Grand 
891cdf0e10cSrcweir             mhRegion = CreatePolyPolygonRgn( &aPolyPoints[0], &aPolyCounts[0], nCount, ALTERNATE );
892cdf0e10cSrcweir         }
893cdf0e10cSrcweir 	}
894cdf0e10cSrcweir 	else
895cdf0e10cSrcweir 	{
896e6f63103SArmin Le Grand         RectangleVector aRectangles;
897e6f63103SArmin Le Grand         i_rClip.GetRegionRectangles(aRectangles);
898cdf0e10cSrcweir 
899e6f63103SArmin Le Grand         //ULONG nRectCount = i_rClip.GetRectCount();
900e6f63103SArmin Le Grand 	    ULONG nRectBufSize = sizeof(RECT)*aRectangles.size();
901e6f63103SArmin Le Grand         if ( aRectangles.size() < SAL_CLIPRECT_COUNT )
902cdf0e10cSrcweir         {
903cdf0e10cSrcweir             if ( !mpStdClipRgnData )
904cdf0e10cSrcweir                 mpStdClipRgnData = (RGNDATA*)new BYTE[sizeof(RGNDATA)-1+(SAL_CLIPRECT_COUNT*sizeof(RECT))];
905cdf0e10cSrcweir             mpClipRgnData = mpStdClipRgnData;
906cdf0e10cSrcweir         }
907cdf0e10cSrcweir         else
908cdf0e10cSrcweir             mpClipRgnData = (RGNDATA*)new BYTE[sizeof(RGNDATA)-1+nRectBufSize];
909cdf0e10cSrcweir         mpClipRgnData->rdh.dwSize	= sizeof( RGNDATAHEADER );
910cdf0e10cSrcweir         mpClipRgnData->rdh.iType 	= RDH_RECTANGLES;
911e6f63103SArmin Le Grand         mpClipRgnData->rdh.nCount	= aRectangles.size();
912cdf0e10cSrcweir         mpClipRgnData->rdh.nRgnSize	= nRectBufSize;
913cdf0e10cSrcweir         RECT*		pBoundRect = &(mpClipRgnData->rdh.rcBound);
914cdf0e10cSrcweir         SetRectEmpty( pBoundRect );
915cdf0e10cSrcweir         RECT* pNextClipRect         = (RECT*)(&(mpClipRgnData->Buffer));
916cdf0e10cSrcweir         bool bFirstClipRect         = true;
917cdf0e10cSrcweir 
918e6f63103SArmin Le Grand         for(RectangleVector::const_iterator aRectIter(aRectangles.begin()); aRectIter != aRectangles.end(); aRectIter++)
919cdf0e10cSrcweir         {
920e6f63103SArmin Le Grand             const long nW(aRectIter->GetWidth());
921e6f63103SArmin Le Grand             const long nH(aRectIter->GetHeight());
922e6f63103SArmin Le Grand 
923cdf0e10cSrcweir             if(nW && nH)
924cdf0e10cSrcweir             {
925e6f63103SArmin Le Grand                 const long nRight(aRectIter->Left() + nW);
926e6f63103SArmin Le Grand                 const long nBottom(aRectIter->Top() + nH);
927cdf0e10cSrcweir 
928cdf0e10cSrcweir                 if(bFirstClipRect)
929cdf0e10cSrcweir                 {
930e6f63103SArmin Le Grand                     pBoundRect->left = aRectIter->Left();
931e6f63103SArmin Le Grand                     pBoundRect->top = aRectIter->Top();
932cdf0e10cSrcweir                     pBoundRect->right = nRight;
933cdf0e10cSrcweir                     pBoundRect->bottom = nBottom;
934cdf0e10cSrcweir                     bFirstClipRect = false;
935cdf0e10cSrcweir                 }
936cdf0e10cSrcweir                 else
937cdf0e10cSrcweir                 {
938e6f63103SArmin Le Grand                     if(aRectIter->Left() < pBoundRect->left)
939e6f63103SArmin Le Grand                     {
940e6f63103SArmin Le Grand                         pBoundRect->left = (int)aRectIter->Left();
941cdf0e10cSrcweir                     }
942cdf0e10cSrcweir 
943e6f63103SArmin Le Grand                     if(aRectIter->Top() < pBoundRect->top)
944e6f63103SArmin Le Grand                     {
945e6f63103SArmin Le Grand                         pBoundRect->top = (int)aRectIter->Top();
946e6f63103SArmin Le Grand                     }
947e6f63103SArmin Le Grand 
948e6f63103SArmin Le Grand                     if(nRight > pBoundRect->right)
949e6f63103SArmin Le Grand                     {
950e6f63103SArmin Le Grand                         pBoundRect->right = (int)nRight;
951e6f63103SArmin Le Grand                     }
952e6f63103SArmin Le Grand 
953e6f63103SArmin Le Grand                     if(nBottom > pBoundRect->bottom)
954e6f63103SArmin Le Grand                     {
955e6f63103SArmin Le Grand                         pBoundRect->bottom = (int)nBottom;
956e6f63103SArmin Le Grand                     }
957e6f63103SArmin Le Grand                 }
958e6f63103SArmin Le Grand 
959e6f63103SArmin Le Grand                 pNextClipRect->left = (int)aRectIter->Left();
960e6f63103SArmin Le Grand                 pNextClipRect->top = (int)aRectIter->Top();
961cdf0e10cSrcweir                 pNextClipRect->right = (int)nRight;
962cdf0e10cSrcweir                 pNextClipRect->bottom = (int)nBottom;
963cdf0e10cSrcweir                 pNextClipRect++;
964cdf0e10cSrcweir             }
965cdf0e10cSrcweir             else
966cdf0e10cSrcweir             {
967cdf0e10cSrcweir                 mpClipRgnData->rdh.nCount--;
968cdf0e10cSrcweir                 mpClipRgnData->rdh.nRgnSize -= sizeof( RECT );
969cdf0e10cSrcweir             }
970cdf0e10cSrcweir         }
971e6f63103SArmin Le Grand 
972e6f63103SArmin Le Grand         //ImplRegionInfo aInfo;
973e6f63103SArmin Le Grand         //long nX, nY, nW, nH;
974e6f63103SArmin Le Grand         //bool bRegionRect = i_rClip.ImplGetFirstRect(aInfo, nX, nY, nW, nH );
975e6f63103SArmin Le Grand         //while( bRegionRect )
976e6f63103SArmin Le Grand         //{
977e6f63103SArmin Le Grand         //    if ( nW && nH )
978e6f63103SArmin Le Grand         //    {
979e6f63103SArmin Le Grand         //        long		nRight = nX + nW;
980e6f63103SArmin Le Grand         //        long		nBottom = nY + nH;
981e6f63103SArmin Le Grand         //
982e6f63103SArmin Le Grand         //        if ( bFirstClipRect )
983e6f63103SArmin Le Grand         //        {
984e6f63103SArmin Le Grand         //            pBoundRect->left	= nX;
985e6f63103SArmin Le Grand         //            pBoundRect->top 	= nY;
986e6f63103SArmin Le Grand         //            pBoundRect->right	= nRight;
987e6f63103SArmin Le Grand         //            pBoundRect->bottom	= nBottom;
988e6f63103SArmin Le Grand         //            bFirstClipRect = false;
989e6f63103SArmin Le Grand         //        }
990e6f63103SArmin Le Grand         //        else
991e6f63103SArmin Le Grand         //        {
992e6f63103SArmin Le Grand         //            if ( nX < pBoundRect->left )
993e6f63103SArmin Le Grand         //                pBoundRect->left = (int)nX;
994e6f63103SArmin Le Grand         //
995e6f63103SArmin Le Grand         //            if ( nY < pBoundRect->top )
996e6f63103SArmin Le Grand         //                pBoundRect->top = (int)nY;
997e6f63103SArmin Le Grand         //
998e6f63103SArmin Le Grand         //            if ( nRight > pBoundRect->right )
999e6f63103SArmin Le Grand         //                pBoundRect->right = (int)nRight;
1000e6f63103SArmin Le Grand         //
1001e6f63103SArmin Le Grand         //            if ( nBottom > pBoundRect->bottom )
1002e6f63103SArmin Le Grand         //                pBoundRect->bottom = (int)nBottom;
1003e6f63103SArmin Le Grand         //        }
1004e6f63103SArmin Le Grand         //
1005e6f63103SArmin Le Grand         //        pNextClipRect->left 	= (int)nX;
1006e6f63103SArmin Le Grand         //        pNextClipRect->top		= (int)nY;
1007e6f63103SArmin Le Grand         //        pNextClipRect->right	= (int)nRight;
1008e6f63103SArmin Le Grand         //        pNextClipRect->bottom	= (int)nBottom;
1009e6f63103SArmin Le Grand         //        pNextClipRect++;
1010e6f63103SArmin Le Grand         //    }
1011e6f63103SArmin Le Grand         //    else
1012e6f63103SArmin Le Grand         //    {
1013e6f63103SArmin Le Grand         //        mpClipRgnData->rdh.nCount--;
1014e6f63103SArmin Le Grand         //        mpClipRgnData->rdh.nRgnSize -= sizeof( RECT );
1015e6f63103SArmin Le Grand         //    }
1016e6f63103SArmin Le Grand         //    bRegionRect = i_rClip.ImplGetNextRect( aInfo, nX, nY, nW, nH );
1017e6f63103SArmin Le Grand         //}
1018e6f63103SArmin Le Grand 
1019cdf0e10cSrcweir         // create clip region from ClipRgnData
1020cdf0e10cSrcweir         if ( mpClipRgnData->rdh.nCount == 1 )
1021cdf0e10cSrcweir         {
1022cdf0e10cSrcweir             RECT* pRect = &(mpClipRgnData->rdh.rcBound);
1023cdf0e10cSrcweir             mhRegion = CreateRectRgn( pRect->left, pRect->top,
1024cdf0e10cSrcweir                                                      pRect->right, pRect->bottom );
1025cdf0e10cSrcweir         }
1026cdf0e10cSrcweir         else if( mpClipRgnData->rdh.nCount > 1 )
1027cdf0e10cSrcweir         {
1028cdf0e10cSrcweir             ULONG nSize = mpClipRgnData->rdh.nRgnSize+sizeof(RGNDATAHEADER);
1029cdf0e10cSrcweir             mhRegion = ExtCreateRegion( NULL, nSize, mpClipRgnData );
1030cdf0e10cSrcweir 
1031cdf0e10cSrcweir             // if ExtCreateRegion(...) is not supported
1032cdf0e10cSrcweir             if( !mhRegion )
1033cdf0e10cSrcweir             {
1034cdf0e10cSrcweir                 RGNDATAHEADER* pHeader = (RGNDATAHEADER*) mpClipRgnData;
1035cdf0e10cSrcweir 
1036cdf0e10cSrcweir                 if( pHeader->nCount )
1037cdf0e10cSrcweir                 {
1038cdf0e10cSrcweir                     RECT* pRect = (RECT*) mpClipRgnData->Buffer;
1039cdf0e10cSrcweir                     mhRegion = CreateRectRgn( pRect->left, pRect->top, pRect->right, pRect->bottom );
1040cdf0e10cSrcweir                     pRect++;
1041cdf0e10cSrcweir 
1042cdf0e10cSrcweir                     for( ULONG n = 1; n < pHeader->nCount; n++, pRect++ )
1043cdf0e10cSrcweir                     {
1044cdf0e10cSrcweir                         HRGN hRgn = CreateRectRgn( pRect->left, pRect->top, pRect->right, pRect->bottom );
1045cdf0e10cSrcweir                         CombineRgn( mhRegion, mhRegion, hRgn, RGN_OR );
1046cdf0e10cSrcweir                         DeleteRegion( hRgn );
1047cdf0e10cSrcweir                     }
1048cdf0e10cSrcweir                 }
1049cdf0e10cSrcweir             }
1050cdf0e10cSrcweir 
1051cdf0e10cSrcweir             if ( mpClipRgnData != mpStdClipRgnData )
1052cdf0e10cSrcweir                 delete [] mpClipRgnData;
1053cdf0e10cSrcweir         }
1054cdf0e10cSrcweir 	}
1055cdf0e10cSrcweir 
1056cdf0e10cSrcweir 	if( mhRegion )
1057*5f27b83cSArmin Le Grand 	    SelectClipRgn( getHDC(), mhRegion );
1058cdf0e10cSrcweir 	return mhRegion != 0;
1059cdf0e10cSrcweir }
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir // -----------------------------------------------------------------------
1062cdf0e10cSrcweir 
1063cdf0e10cSrcweir void WinSalGraphics::SetLineColor()
1064cdf0e10cSrcweir {
1065cdf0e10cSrcweir 	// create and select new pen
1066cdf0e10cSrcweir 	HPEN hNewPen = GetStockPen( NULL_PEN );
1067*5f27b83cSArmin Le Grand 	HPEN hOldPen = SelectPen( getHDC(), hNewPen );
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir 	// destory or save old pen
1070cdf0e10cSrcweir 	if ( mhPen )
1071cdf0e10cSrcweir 	{
1072cdf0e10cSrcweir 		if ( !mbStockPen )
1073cdf0e10cSrcweir 			DeletePen( mhPen );
1074cdf0e10cSrcweir 	}
1075cdf0e10cSrcweir 	else
1076cdf0e10cSrcweir 		mhDefPen = hOldPen;
1077cdf0e10cSrcweir 
1078cdf0e10cSrcweir 	// set new data
1079cdf0e10cSrcweir 	mhPen		= hNewPen;
1080cdf0e10cSrcweir 	mbPen		= FALSE;
1081cdf0e10cSrcweir 	mbStockPen	= TRUE;
1082cdf0e10cSrcweir }
1083cdf0e10cSrcweir 
1084cdf0e10cSrcweir // -----------------------------------------------------------------------
1085cdf0e10cSrcweir 
1086cdf0e10cSrcweir void WinSalGraphics::SetLineColor( SalColor nSalColor )
1087cdf0e10cSrcweir {
1088cdf0e10cSrcweir     maLineColor = nSalColor;
1089cdf0e10cSrcweir 	COLORREF	nPenColor = PALETTERGB( SALCOLOR_RED( nSalColor ),
1090cdf0e10cSrcweir 										SALCOLOR_GREEN( nSalColor ),
1091cdf0e10cSrcweir 										SALCOLOR_BLUE( nSalColor ) );
1092cdf0e10cSrcweir 	HPEN		hNewPen = 0;
1093cdf0e10cSrcweir 	sal_Bool		bStockPen = FALSE;
1094cdf0e10cSrcweir 
1095cdf0e10cSrcweir 	// search for stock pen (only screen, because printer have problems,
1096cdf0e10cSrcweir 	// when we use stock objects)
1097cdf0e10cSrcweir 	if ( !mbPrinter )
1098cdf0e10cSrcweir 	{
1099cdf0e10cSrcweir 		SalData* pSalData = GetSalData();
1100cdf0e10cSrcweir 		for ( sal_uInt16 i = 0; i < pSalData->mnStockPenCount; i++ )
1101cdf0e10cSrcweir 		{
1102cdf0e10cSrcweir 			if ( nPenColor == pSalData->maStockPenColorAry[i] )
1103cdf0e10cSrcweir 			{
1104cdf0e10cSrcweir 				hNewPen = pSalData->mhStockPenAry[i];
1105cdf0e10cSrcweir 				bStockPen = TRUE;
1106cdf0e10cSrcweir 				break;
1107cdf0e10cSrcweir 			}
1108cdf0e10cSrcweir 		}
1109cdf0e10cSrcweir 	}
1110cdf0e10cSrcweir 
1111cdf0e10cSrcweir 	// create new pen
1112cdf0e10cSrcweir 	if ( !hNewPen )
1113cdf0e10cSrcweir 	{
1114cdf0e10cSrcweir 		if ( !mbPrinter )
1115cdf0e10cSrcweir 		{
1116cdf0e10cSrcweir 			if ( GetSalData()->mhDitherPal && ImplIsSysColorEntry( nSalColor ) )
1117cdf0e10cSrcweir 				nPenColor = PALRGB_TO_RGB( nPenColor );
1118cdf0e10cSrcweir 		}
1119cdf0e10cSrcweir 
1120cdf0e10cSrcweir 		hNewPen = CreatePen( PS_SOLID, mnPenWidth, nPenColor );
1121cdf0e10cSrcweir 		bStockPen = FALSE;
1122cdf0e10cSrcweir 	}
1123cdf0e10cSrcweir 
1124cdf0e10cSrcweir 	// select new pen
1125*5f27b83cSArmin Le Grand 	HPEN hOldPen = SelectPen( getHDC(), hNewPen );
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir 	// destory or save old pen
1128cdf0e10cSrcweir 	if ( mhPen )
1129cdf0e10cSrcweir 	{
1130cdf0e10cSrcweir 		if ( !mbStockPen )
1131cdf0e10cSrcweir 			DeletePen( mhPen );
1132cdf0e10cSrcweir 	}
1133cdf0e10cSrcweir 	else
1134cdf0e10cSrcweir 		mhDefPen = hOldPen;
1135cdf0e10cSrcweir 
1136cdf0e10cSrcweir 	// set new data
1137cdf0e10cSrcweir 	mnPenColor	= nPenColor;
1138cdf0e10cSrcweir 	mhPen		= hNewPen;
1139cdf0e10cSrcweir 	mbPen		= TRUE;
1140cdf0e10cSrcweir 	mbStockPen	= bStockPen;
1141cdf0e10cSrcweir }
1142cdf0e10cSrcweir 
1143cdf0e10cSrcweir // -----------------------------------------------------------------------
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir void WinSalGraphics::SetFillColor()
1146cdf0e10cSrcweir {
1147cdf0e10cSrcweir 	// create and select new brush
1148cdf0e10cSrcweir 	HBRUSH hNewBrush = GetStockBrush( NULL_BRUSH );
1149*5f27b83cSArmin Le Grand 	HBRUSH hOldBrush = SelectBrush( getHDC(), hNewBrush );
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir 	// destory or save old brush
1152cdf0e10cSrcweir 	if ( mhBrush )
1153cdf0e10cSrcweir 	{
1154cdf0e10cSrcweir 		if ( !mbStockBrush )
1155cdf0e10cSrcweir 			DeleteBrush( mhBrush );
1156cdf0e10cSrcweir 	}
1157cdf0e10cSrcweir 	else
1158cdf0e10cSrcweir 		mhDefBrush = hOldBrush;
1159cdf0e10cSrcweir 
1160cdf0e10cSrcweir 	// set new data
1161cdf0e10cSrcweir 	mhBrush		= hNewBrush;
1162cdf0e10cSrcweir 	mbBrush		= FALSE;
1163cdf0e10cSrcweir 	mbStockBrush = TRUE;
1164cdf0e10cSrcweir }
1165cdf0e10cSrcweir 
1166cdf0e10cSrcweir // -----------------------------------------------------------------------
1167cdf0e10cSrcweir 
1168cdf0e10cSrcweir void WinSalGraphics::SetFillColor( SalColor nSalColor )
1169cdf0e10cSrcweir {
1170cdf0e10cSrcweir     maFillColor = nSalColor;
1171cdf0e10cSrcweir 	SalData*	pSalData	= GetSalData();
1172cdf0e10cSrcweir 	BYTE		nRed		= SALCOLOR_RED( nSalColor );
1173cdf0e10cSrcweir 	BYTE		nGreen		= SALCOLOR_GREEN( nSalColor );
1174cdf0e10cSrcweir 	BYTE		nBlue		= SALCOLOR_BLUE( nSalColor );
1175cdf0e10cSrcweir 	COLORREF	nBrushColor = PALETTERGB( nRed, nGreen, nBlue );
1176cdf0e10cSrcweir 	HBRUSH		hNewBrush	= 0;
1177cdf0e10cSrcweir 	sal_Bool		bStockBrush = FALSE;
1178cdf0e10cSrcweir 
1179cdf0e10cSrcweir 	// search for stock brush (only screen, because printer have problems,
1180cdf0e10cSrcweir 	// when we use stock objects)
1181cdf0e10cSrcweir 	if ( !mbPrinter )
1182cdf0e10cSrcweir 	{
1183cdf0e10cSrcweir 		for ( sal_uInt16 i = 0; i < pSalData->mnStockBrushCount; i++ )
1184cdf0e10cSrcweir 		{
1185cdf0e10cSrcweir 			if ( nBrushColor == pSalData->maStockBrushColorAry[ i ] )
1186cdf0e10cSrcweir 			{
1187cdf0e10cSrcweir 				hNewBrush = pSalData->mhStockBrushAry[i];
1188cdf0e10cSrcweir 				bStockBrush = TRUE;
1189cdf0e10cSrcweir 				break;
1190cdf0e10cSrcweir 			}
1191cdf0e10cSrcweir 		}
1192cdf0e10cSrcweir 	}
1193cdf0e10cSrcweir 
1194cdf0e10cSrcweir 	// create new brush
1195cdf0e10cSrcweir 	if ( !hNewBrush )
1196cdf0e10cSrcweir 	{
1197cdf0e10cSrcweir 		if ( mbPrinter || !pSalData->mhDitherDIB )
1198cdf0e10cSrcweir 			hNewBrush = CreateSolidBrush( nBrushColor );
1199cdf0e10cSrcweir 		else
1200cdf0e10cSrcweir 		{
1201cdf0e10cSrcweir 			if ( 24 == ((BITMAPINFOHEADER*)pSalData->mpDitherDIB)->biBitCount )
1202cdf0e10cSrcweir 			{
1203cdf0e10cSrcweir 				BYTE* pTmp = pSalData->mpDitherDIBData;
1204cdf0e10cSrcweir 				long* pDitherDiff = pSalData->mpDitherDiff;
1205cdf0e10cSrcweir 				BYTE* pDitherLow = pSalData->mpDitherLow;
1206cdf0e10cSrcweir 				BYTE* pDitherHigh = pSalData->mpDitherHigh;
1207cdf0e10cSrcweir 
1208cdf0e10cSrcweir 				for( long nY = 0L; nY < 8L; nY++ )
1209cdf0e10cSrcweir 				{
1210cdf0e10cSrcweir 					for( long nX = 0L; nX < 8L; nX++ )
1211cdf0e10cSrcweir 					{
1212cdf0e10cSrcweir 						const long nThres = aOrdDither16Bit[ nY ][ nX ];
1213cdf0e10cSrcweir 						*pTmp++ = DMAP( nBlue, nThres );
1214cdf0e10cSrcweir 						*pTmp++ = DMAP( nGreen, nThres );
1215cdf0e10cSrcweir 						*pTmp++ = DMAP( nRed, nThres );
1216cdf0e10cSrcweir 					}
1217cdf0e10cSrcweir 				}
1218cdf0e10cSrcweir 
1219cdf0e10cSrcweir 				hNewBrush = CreateDIBPatternBrush( pSalData->mhDitherDIB, DIB_RGB_COLORS );
1220cdf0e10cSrcweir 			}
1221cdf0e10cSrcweir 			else if ( ImplIsSysColorEntry( nSalColor ) )
1222cdf0e10cSrcweir 			{
1223cdf0e10cSrcweir 				nBrushColor = PALRGB_TO_RGB( nBrushColor );
1224cdf0e10cSrcweir 				hNewBrush = CreateSolidBrush( nBrushColor );
1225cdf0e10cSrcweir 			}
1226cdf0e10cSrcweir 			else if ( ImplIsPaletteEntry( nRed, nGreen, nBlue ) )
1227cdf0e10cSrcweir 				hNewBrush = CreateSolidBrush( nBrushColor );
1228cdf0e10cSrcweir 			else
1229cdf0e10cSrcweir 			{
1230cdf0e10cSrcweir 				BYTE* pTmp = pSalData->mpDitherDIBData;
1231cdf0e10cSrcweir 				long* pDitherDiff = pSalData->mpDitherDiff;
1232cdf0e10cSrcweir 				BYTE* pDitherLow = pSalData->mpDitherLow;
1233cdf0e10cSrcweir 				BYTE* pDitherHigh = pSalData->mpDitherHigh;
1234cdf0e10cSrcweir 
1235cdf0e10cSrcweir 				for ( long nY = 0L; nY < 8L; nY++ )
1236cdf0e10cSrcweir 				{
1237cdf0e10cSrcweir 					for ( long nX = 0L; nX < 8L; nX++ )
1238cdf0e10cSrcweir 					{
1239cdf0e10cSrcweir 						const long nThres = aOrdDither8Bit[ nY ][ nX ];
1240cdf0e10cSrcweir 						*pTmp = DMAP( nRed, nThres ) + DMAP( nGreen, nThres ) * 6 + DMAP( nBlue, nThres ) * 36;
1241cdf0e10cSrcweir 						pTmp++;
1242cdf0e10cSrcweir 					}
1243cdf0e10cSrcweir 				}
1244cdf0e10cSrcweir 
1245cdf0e10cSrcweir 				hNewBrush = CreateDIBPatternBrush( pSalData->mhDitherDIB, DIB_PAL_COLORS );
1246cdf0e10cSrcweir 			}
1247cdf0e10cSrcweir 		}
1248cdf0e10cSrcweir 
1249cdf0e10cSrcweir 		bStockBrush = FALSE;
1250cdf0e10cSrcweir 	}
1251cdf0e10cSrcweir 
1252cdf0e10cSrcweir 	// select new brush
1253*5f27b83cSArmin Le Grand 	HBRUSH hOldBrush = SelectBrush( getHDC(), hNewBrush );
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir 	// destory or save old brush
1256cdf0e10cSrcweir 	if ( mhBrush )
1257cdf0e10cSrcweir 	{
1258cdf0e10cSrcweir 		if ( !mbStockBrush )
1259cdf0e10cSrcweir 			DeleteBrush( mhBrush );
1260cdf0e10cSrcweir 	}
1261cdf0e10cSrcweir 	else
1262cdf0e10cSrcweir 		mhDefBrush = hOldBrush;
1263cdf0e10cSrcweir 
1264cdf0e10cSrcweir 	// set new data
1265cdf0e10cSrcweir 	mnBrushColor = nBrushColor;
1266cdf0e10cSrcweir 	mhBrush		= hNewBrush;
1267cdf0e10cSrcweir 	mbBrush		= TRUE;
1268cdf0e10cSrcweir 	mbStockBrush = bStockBrush;
1269cdf0e10cSrcweir }
1270cdf0e10cSrcweir 
1271cdf0e10cSrcweir // -----------------------------------------------------------------------
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir void WinSalGraphics::SetXORMode( bool bSet, bool )
1274cdf0e10cSrcweir {
1275cdf0e10cSrcweir 	mbXORMode = bSet;
1276*5f27b83cSArmin Le Grand 	::SetROP2( getHDC(), bSet ? R2_XORPEN : R2_COPYPEN );
1277cdf0e10cSrcweir }
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir // -----------------------------------------------------------------------
1280cdf0e10cSrcweir 
1281cdf0e10cSrcweir void WinSalGraphics::SetROPLineColor( SalROPColor nROPColor )
1282cdf0e10cSrcweir {
1283cdf0e10cSrcweir 	SetLineColor( ImplGetROPSalColor( nROPColor ) );
1284cdf0e10cSrcweir }
1285cdf0e10cSrcweir 
1286cdf0e10cSrcweir // -----------------------------------------------------------------------
1287cdf0e10cSrcweir 
1288cdf0e10cSrcweir void WinSalGraphics::SetROPFillColor( SalROPColor nROPColor )
1289cdf0e10cSrcweir {
1290cdf0e10cSrcweir 	SetFillColor( ImplGetROPSalColor( nROPColor ) );
1291cdf0e10cSrcweir }
1292cdf0e10cSrcweir 
1293cdf0e10cSrcweir // -----------------------------------------------------------------------
1294cdf0e10cSrcweir 
1295cdf0e10cSrcweir void WinSalGraphics::drawPixel( long nX, long nY )
1296cdf0e10cSrcweir {
1297cdf0e10cSrcweir 	if ( mbXORMode )
1298cdf0e10cSrcweir 	{
1299cdf0e10cSrcweir 		HBRUSH	hBrush = CreateSolidBrush( mnPenColor );
1300*5f27b83cSArmin Le Grand 		HBRUSH	hOldBrush = SelectBrush( getHDC(), hBrush );
1301*5f27b83cSArmin Le Grand 		PatBlt( getHDC(), (int)nX, (int)nY, (int)1, (int)1, PATINVERT );
1302*5f27b83cSArmin Le Grand 		SelectBrush( getHDC(), hOldBrush );
1303cdf0e10cSrcweir 		DeleteBrush( hBrush );
1304cdf0e10cSrcweir 	}
1305cdf0e10cSrcweir 	else
1306*5f27b83cSArmin Le Grand 		SetPixel( getHDC(), (int)nX, (int)nY, mnPenColor );
1307cdf0e10cSrcweir }
1308cdf0e10cSrcweir 
1309cdf0e10cSrcweir // -----------------------------------------------------------------------
1310cdf0e10cSrcweir 
1311cdf0e10cSrcweir void WinSalGraphics::drawPixel( long nX, long nY, SalColor nSalColor )
1312cdf0e10cSrcweir {
1313cdf0e10cSrcweir 	COLORREF nCol = PALETTERGB( SALCOLOR_RED( nSalColor ),
1314cdf0e10cSrcweir 								SALCOLOR_GREEN( nSalColor ),
1315cdf0e10cSrcweir 								SALCOLOR_BLUE( nSalColor ) );
1316cdf0e10cSrcweir 
1317cdf0e10cSrcweir 	if ( !mbPrinter &&
1318cdf0e10cSrcweir 		 GetSalData()->mhDitherPal &&
1319cdf0e10cSrcweir 		 ImplIsSysColorEntry( nSalColor ) )
1320cdf0e10cSrcweir 		nCol = PALRGB_TO_RGB( nCol );
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir 	if ( mbXORMode )
1323cdf0e10cSrcweir 	{
1324cdf0e10cSrcweir 		HBRUSH	hBrush = CreateSolidBrush( nCol );
1325*5f27b83cSArmin Le Grand 		HBRUSH	hOldBrush = SelectBrush( getHDC(), hBrush );
1326*5f27b83cSArmin Le Grand 		PatBlt( getHDC(), (int)nX, (int)nY, (int)1, (int)1, PATINVERT );
1327*5f27b83cSArmin Le Grand 		SelectBrush( getHDC(), hOldBrush );
1328cdf0e10cSrcweir 		DeleteBrush( hBrush );
1329cdf0e10cSrcweir 	}
1330cdf0e10cSrcweir 	else
1331*5f27b83cSArmin Le Grand 		::SetPixel( getHDC(), (int)nX, (int)nY, nCol );
1332cdf0e10cSrcweir }
1333cdf0e10cSrcweir 
1334cdf0e10cSrcweir // -----------------------------------------------------------------------
1335cdf0e10cSrcweir 
1336cdf0e10cSrcweir void WinSalGraphics::drawLine( long nX1, long nY1, long nX2, long nY2 )
1337cdf0e10cSrcweir {
1338*5f27b83cSArmin Le Grand 	MoveToEx( getHDC(), (int)nX1, (int)nY1, NULL );
1339cdf0e10cSrcweir 
1340cdf0e10cSrcweir 	// we must paint the endpoint
1341cdf0e10cSrcweir 	int bPaintEnd = TRUE;
1342cdf0e10cSrcweir 	if ( nX1 == nX2 )
1343cdf0e10cSrcweir 	{
1344cdf0e10cSrcweir 		bPaintEnd = FALSE;
1345cdf0e10cSrcweir 		if ( nY1 <= nY2 )
1346cdf0e10cSrcweir 			nY2++;
1347cdf0e10cSrcweir 		else
1348cdf0e10cSrcweir 			nY2--;
1349cdf0e10cSrcweir 	}
1350cdf0e10cSrcweir 	if ( nY1 == nY2 )
1351cdf0e10cSrcweir 	{
1352cdf0e10cSrcweir 		bPaintEnd = FALSE;
1353cdf0e10cSrcweir 		if ( nX1 <= nX2 )
1354cdf0e10cSrcweir 			nX2++;
1355cdf0e10cSrcweir 		else
1356cdf0e10cSrcweir 			nX2--;
1357cdf0e10cSrcweir 	}
1358cdf0e10cSrcweir 
1359*5f27b83cSArmin Le Grand 	LineTo( getHDC(), (int)nX2, (int)nY2 );
1360cdf0e10cSrcweir 
1361cdf0e10cSrcweir 	if ( bPaintEnd && !mbPrinter )
1362cdf0e10cSrcweir 	{
1363cdf0e10cSrcweir 		if ( mbXORMode )
1364cdf0e10cSrcweir 		{
1365cdf0e10cSrcweir 			HBRUSH	hBrush = CreateSolidBrush( mnPenColor );
1366*5f27b83cSArmin Le Grand 			HBRUSH	hOldBrush = SelectBrush( getHDC(), hBrush );
1367*5f27b83cSArmin Le Grand 			PatBlt( getHDC(), (int)nX2, (int)nY2, (int)1, (int)1, PATINVERT );
1368*5f27b83cSArmin Le Grand 			SelectBrush( getHDC(), hOldBrush );
1369cdf0e10cSrcweir 			DeleteBrush( hBrush );
1370cdf0e10cSrcweir 		}
1371cdf0e10cSrcweir 		else
1372*5f27b83cSArmin Le Grand 			SetPixel( getHDC(), (int)nX2, (int)nY2, mnPenColor );
1373cdf0e10cSrcweir 	}
1374cdf0e10cSrcweir }
1375cdf0e10cSrcweir 
1376cdf0e10cSrcweir // -----------------------------------------------------------------------
1377cdf0e10cSrcweir 
1378cdf0e10cSrcweir void WinSalGraphics::drawRect( long nX, long nY, long nWidth, long nHeight )
1379cdf0e10cSrcweir {
1380cdf0e10cSrcweir 	if ( !mbPen )
1381cdf0e10cSrcweir 	{
1382cdf0e10cSrcweir 		if ( !mbPrinter )
1383cdf0e10cSrcweir 		{
1384*5f27b83cSArmin Le Grand 			PatBlt( getHDC(), (int)nX, (int)nY, (int)nWidth, (int)nHeight,
1385cdf0e10cSrcweir 					mbXORMode ? PATINVERT : PATCOPY );
1386cdf0e10cSrcweir 		}
1387cdf0e10cSrcweir 		else
1388cdf0e10cSrcweir 		{
1389cdf0e10cSrcweir 			RECT aWinRect;
1390cdf0e10cSrcweir 			aWinRect.left	= nX;
1391cdf0e10cSrcweir 			aWinRect.top	= nY;
1392cdf0e10cSrcweir 			aWinRect.right	= nX+nWidth;
1393cdf0e10cSrcweir 			aWinRect.bottom = nY+nHeight;
1394*5f27b83cSArmin Le Grand 			::FillRect( getHDC(), &aWinRect, mhBrush );
1395cdf0e10cSrcweir 		}
1396cdf0e10cSrcweir 	}
1397cdf0e10cSrcweir 	else
1398*5f27b83cSArmin Le Grand 		WIN_Rectangle( getHDC(), (int)nX, (int)nY, (int)(nX+nWidth), (int)(nY+nHeight) );
1399cdf0e10cSrcweir }
1400cdf0e10cSrcweir 
1401cdf0e10cSrcweir // -----------------------------------------------------------------------
1402cdf0e10cSrcweir 
1403cdf0e10cSrcweir void WinSalGraphics::drawPolyLine( sal_uLong nPoints, const SalPoint* pPtAry )
1404cdf0e10cSrcweir {
1405cdf0e10cSrcweir 	// Unter NT koennen wir das Array direkt weiterreichen
1406cdf0e10cSrcweir 	DBG_ASSERT( sizeof( POINT ) == sizeof( SalPoint ),
1407cdf0e10cSrcweir 				"WinSalGraphics::DrawPolyLine(): POINT != SalPoint" );
1408cdf0e10cSrcweir 
1409cdf0e10cSrcweir 	POINT* pWinPtAry = (POINT*)pPtAry;
1410cdf0e10cSrcweir 	// Wegen Windows 95 und der Beschraenkung auf eine maximale Anzahl
1411cdf0e10cSrcweir 	// von Punkten
1412*5f27b83cSArmin Le Grand 	if ( !Polyline( getHDC(), pWinPtAry, (int)nPoints ) && (nPoints > MAX_64KSALPOINTS) )
1413*5f27b83cSArmin Le Grand 		Polyline( getHDC(), pWinPtAry, MAX_64KSALPOINTS );
1414cdf0e10cSrcweir }
1415cdf0e10cSrcweir 
1416cdf0e10cSrcweir // -----------------------------------------------------------------------
1417cdf0e10cSrcweir 
1418cdf0e10cSrcweir void WinSalGraphics::drawPolygon( sal_uLong nPoints, const SalPoint* pPtAry )
1419cdf0e10cSrcweir {
1420cdf0e10cSrcweir 	// Unter NT koennen wir das Array direkt weiterreichen
1421cdf0e10cSrcweir 	DBG_ASSERT( sizeof( POINT ) == sizeof( SalPoint ),
1422cdf0e10cSrcweir 				"WinSalGraphics::DrawPolygon(): POINT != SalPoint" );
1423cdf0e10cSrcweir 
1424cdf0e10cSrcweir 	POINT* pWinPtAry = (POINT*)pPtAry;
1425cdf0e10cSrcweir 	// Wegen Windows 95 und der Beschraenkung auf eine maximale Anzahl
1426cdf0e10cSrcweir 	// von Punkten
1427*5f27b83cSArmin Le Grand 	if ( !WIN_Polygon( getHDC(), pWinPtAry, (int)nPoints ) && (nPoints > MAX_64KSALPOINTS) )
1428*5f27b83cSArmin Le Grand 		WIN_Polygon( getHDC(), pWinPtAry, MAX_64KSALPOINTS );
1429cdf0e10cSrcweir }
1430cdf0e10cSrcweir 
1431cdf0e10cSrcweir // -----------------------------------------------------------------------
1432cdf0e10cSrcweir 
1433cdf0e10cSrcweir void WinSalGraphics::drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints,
1434cdf0e10cSrcweir 								   PCONSTSALPOINT* pPtAry )
1435cdf0e10cSrcweir {
1436cdf0e10cSrcweir 	UINT	aWinPointAry[SAL_POLYPOLYCOUNT_STACKBUF];
1437cdf0e10cSrcweir 	UINT*	pWinPointAry;
1438cdf0e10cSrcweir 	UINT	nPolyPolyPoints = 0;
1439cdf0e10cSrcweir 	UINT	nPoints;
1440cdf0e10cSrcweir 	UINT	i;
1441cdf0e10cSrcweir 
1442cdf0e10cSrcweir 	if ( nPoly <= SAL_POLYPOLYCOUNT_STACKBUF )
1443cdf0e10cSrcweir 		pWinPointAry = aWinPointAry;
1444cdf0e10cSrcweir 	else
1445cdf0e10cSrcweir 		pWinPointAry = new UINT[nPoly];
1446cdf0e10cSrcweir 
1447cdf0e10cSrcweir 	for ( i = 0; i < (UINT)nPoly; i++ )
1448cdf0e10cSrcweir 	{
1449cdf0e10cSrcweir 		nPoints = (UINT)pPoints[i]+1;
1450cdf0e10cSrcweir 		pWinPointAry[i] = nPoints;
1451cdf0e10cSrcweir 		nPolyPolyPoints += nPoints;
1452cdf0e10cSrcweir 	}
1453cdf0e10cSrcweir 
1454cdf0e10cSrcweir 	POINT  aWinPointAryAry[SAL_POLYPOLYPOINTS_STACKBUF];
1455cdf0e10cSrcweir 	POINT* pWinPointAryAry;
1456cdf0e10cSrcweir 	if ( nPolyPolyPoints <= SAL_POLYPOLYPOINTS_STACKBUF )
1457cdf0e10cSrcweir 		pWinPointAryAry = aWinPointAryAry;
1458cdf0e10cSrcweir 	else
1459cdf0e10cSrcweir 		pWinPointAryAry = new POINT[nPolyPolyPoints];
1460cdf0e10cSrcweir 	// Unter NT koennen wir das Array direkt weiterreichen
1461cdf0e10cSrcweir 	DBG_ASSERT( sizeof( POINT ) == sizeof( SalPoint ),
1462cdf0e10cSrcweir 				"WinSalGraphics::DrawPolyPolygon(): POINT != SalPoint" );
1463cdf0e10cSrcweir 	const SalPoint* pPolyAry;
1464cdf0e10cSrcweir 	UINT			n = 0;
1465cdf0e10cSrcweir 	for ( i = 0; i < (UINT)nPoly; i++ )
1466cdf0e10cSrcweir 	{
1467cdf0e10cSrcweir 		nPoints = pWinPointAry[i];
1468cdf0e10cSrcweir 		pPolyAry = pPtAry[i];
1469cdf0e10cSrcweir 		memcpy( pWinPointAryAry+n, pPolyAry, (nPoints-1)*sizeof(POINT) );
1470cdf0e10cSrcweir 		pWinPointAryAry[n+nPoints-1] = pWinPointAryAry[n];
1471cdf0e10cSrcweir 		n += nPoints;
1472cdf0e10cSrcweir 	}
1473cdf0e10cSrcweir 
1474*5f27b83cSArmin Le Grand 	if ( !WIN_PolyPolygon( getHDC(), pWinPointAryAry, (int*)pWinPointAry, (UINT)nPoly ) &&
1475cdf0e10cSrcweir 		 (nPolyPolyPoints > MAX_64KSALPOINTS) )
1476cdf0e10cSrcweir 	{
1477cdf0e10cSrcweir 		nPolyPolyPoints  = 0;
1478cdf0e10cSrcweir 		nPoly = 0;
1479cdf0e10cSrcweir 		do
1480cdf0e10cSrcweir 		{
1481cdf0e10cSrcweir 			nPolyPolyPoints += pWinPointAry[(UINT)nPoly];
1482cdf0e10cSrcweir 			nPoly++;
1483cdf0e10cSrcweir 		}
1484cdf0e10cSrcweir 		while ( nPolyPolyPoints < MAX_64KSALPOINTS );
1485cdf0e10cSrcweir 		nPoly--;
1486cdf0e10cSrcweir 		if ( pWinPointAry[(UINT)nPoly] > MAX_64KSALPOINTS )
1487cdf0e10cSrcweir 			pWinPointAry[(UINT)nPoly] = MAX_64KSALPOINTS;
1488cdf0e10cSrcweir 		if ( nPoly == 1 )
1489*5f27b83cSArmin Le Grand 			WIN_Polygon( getHDC(), pWinPointAryAry, *pWinPointAry );
1490cdf0e10cSrcweir 		else
1491*5f27b83cSArmin Le Grand 			WIN_PolyPolygon( getHDC(), pWinPointAryAry, (int*)pWinPointAry, nPoly );
1492cdf0e10cSrcweir 	}
1493cdf0e10cSrcweir 
1494cdf0e10cSrcweir 	if ( pWinPointAry != aWinPointAry )
1495cdf0e10cSrcweir 		delete [] pWinPointAry;
1496cdf0e10cSrcweir 	if ( pWinPointAryAry != aWinPointAryAry )
1497cdf0e10cSrcweir 		delete [] pWinPointAryAry;
1498cdf0e10cSrcweir }
1499cdf0e10cSrcweir 
1500cdf0e10cSrcweir // -----------------------------------------------------------------------
1501cdf0e10cSrcweir 
1502cdf0e10cSrcweir #define SAL_POLY_STACKBUF		32
1503cdf0e10cSrcweir 
1504cdf0e10cSrcweir // -----------------------------------------------------------------------
1505cdf0e10cSrcweir 
1506cdf0e10cSrcweir sal_Bool WinSalGraphics::drawPolyLineBezier( sal_uLong nPoints, const SalPoint* pPtAry, const BYTE* pFlgAry )
1507cdf0e10cSrcweir {
1508cdf0e10cSrcweir #ifdef USE_GDI_BEZIERS
1509cdf0e10cSrcweir 	// Unter NT koennen wir das Array direkt weiterreichen
1510cdf0e10cSrcweir 	DBG_ASSERT( sizeof( POINT ) == sizeof( SalPoint ),
1511cdf0e10cSrcweir 				"WinSalGraphics::DrawPolyLineBezier(): POINT != SalPoint" );
1512cdf0e10cSrcweir 
1513*5f27b83cSArmin Le Grand     ImplRenderPath( getHDC(), nPoints, pPtAry, pFlgAry );
1514cdf0e10cSrcweir 
1515cdf0e10cSrcweir     return sal_True;
1516cdf0e10cSrcweir #else
1517cdf0e10cSrcweir     return sal_False;
1518cdf0e10cSrcweir #endif
1519cdf0e10cSrcweir }
1520cdf0e10cSrcweir 
1521cdf0e10cSrcweir // -----------------------------------------------------------------------
1522cdf0e10cSrcweir 
1523cdf0e10cSrcweir sal_Bool WinSalGraphics::drawPolygonBezier( sal_uLong nPoints, const SalPoint* pPtAry, const BYTE* pFlgAry )
1524cdf0e10cSrcweir {
1525cdf0e10cSrcweir #ifdef USE_GDI_BEZIERS
1526cdf0e10cSrcweir 	// Unter NT koennen wir das Array direkt weiterreichen
1527cdf0e10cSrcweir 	DBG_ASSERT( sizeof( POINT ) == sizeof( SalPoint ),
1528cdf0e10cSrcweir 				"WinSalGraphics::DrawPolygonBezier(): POINT != SalPoint" );
1529cdf0e10cSrcweir 
1530cdf0e10cSrcweir     POINT	aStackAry1[SAL_POLY_STACKBUF];
1531cdf0e10cSrcweir     BYTE	aStackAry2[SAL_POLY_STACKBUF];
1532cdf0e10cSrcweir     POINT* 	pWinPointAry;
1533cdf0e10cSrcweir     BYTE* 	pWinFlagAry;
1534cdf0e10cSrcweir     if( nPoints > SAL_POLY_STACKBUF )
1535cdf0e10cSrcweir     {
1536cdf0e10cSrcweir         pWinPointAry = new POINT[ nPoints ];
1537cdf0e10cSrcweir         pWinFlagAry = new BYTE[ nPoints ];
1538cdf0e10cSrcweir     }
1539cdf0e10cSrcweir     else
1540cdf0e10cSrcweir     {
1541cdf0e10cSrcweir         pWinPointAry = aStackAry1;
1542cdf0e10cSrcweir         pWinFlagAry = aStackAry2;
1543cdf0e10cSrcweir     }
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir     ImplPreparePolyDraw(true, 1, &nPoints, &pPtAry, &pFlgAry, pWinPointAry, pWinFlagAry);
1546cdf0e10cSrcweir 
1547cdf0e10cSrcweir     sal_Bool bRet( sal_False );
1548cdf0e10cSrcweir 
1549*5f27b83cSArmin Le Grand     if( BeginPath( getHDC() ) )
1550cdf0e10cSrcweir     {
1551*5f27b83cSArmin Le Grand         PolyDraw(getHDC(), pWinPointAry, pWinFlagAry, nPoints);
1552cdf0e10cSrcweir 
1553*5f27b83cSArmin Le Grand         if( EndPath( getHDC() ) )
1554cdf0e10cSrcweir         {
1555*5f27b83cSArmin Le Grand             if( StrokeAndFillPath( getHDC() ) )
1556cdf0e10cSrcweir                 bRet = sal_True;
1557cdf0e10cSrcweir         }
1558cdf0e10cSrcweir     }
1559cdf0e10cSrcweir 
1560cdf0e10cSrcweir     if( pWinPointAry != aStackAry1 )
1561cdf0e10cSrcweir     {
1562cdf0e10cSrcweir         delete [] pWinPointAry;
1563cdf0e10cSrcweir         delete [] pWinFlagAry;
1564cdf0e10cSrcweir     }
1565cdf0e10cSrcweir 
1566cdf0e10cSrcweir     return bRet;
1567cdf0e10cSrcweir #else
1568cdf0e10cSrcweir     return sal_False;
1569cdf0e10cSrcweir #endif
1570cdf0e10cSrcweir }
1571cdf0e10cSrcweir 
1572cdf0e10cSrcweir // -----------------------------------------------------------------------
1573cdf0e10cSrcweir 
1574cdf0e10cSrcweir sal_Bool WinSalGraphics::drawPolyPolygonBezier( sal_uInt32 nPoly, const sal_uInt32* pPoints,
1575cdf0e10cSrcweir                                              const SalPoint* const* pPtAry, const BYTE* const* pFlgAry )
1576cdf0e10cSrcweir {
1577cdf0e10cSrcweir #ifdef USE_GDI_BEZIERS
1578cdf0e10cSrcweir 	// Unter NT koennen wir das Array direkt weiterreichen
1579cdf0e10cSrcweir 	DBG_ASSERT( sizeof( POINT ) == sizeof( SalPoint ),
1580cdf0e10cSrcweir 				"WinSalGraphics::DrawPolyPolygonBezier(): POINT != SalPoint" );
1581cdf0e10cSrcweir 
1582cdf0e10cSrcweir     sal_uLong nCurrPoly, nTotalPoints;
1583cdf0e10cSrcweir     const sal_uLong* pCurrPoints = pPoints;
1584cdf0e10cSrcweir     for( nCurrPoly=0, nTotalPoints=0; nCurrPoly<nPoly; ++nCurrPoly )
1585cdf0e10cSrcweir         nTotalPoints += *pCurrPoints++;
1586cdf0e10cSrcweir 
1587cdf0e10cSrcweir     POINT	aStackAry1[SAL_POLY_STACKBUF];
1588cdf0e10cSrcweir     BYTE	aStackAry2[SAL_POLY_STACKBUF];
1589cdf0e10cSrcweir     POINT* 	pWinPointAry;
1590cdf0e10cSrcweir     BYTE* 	pWinFlagAry;
1591cdf0e10cSrcweir     if( nTotalPoints > SAL_POLY_STACKBUF )
1592cdf0e10cSrcweir     {
1593cdf0e10cSrcweir         pWinPointAry = new POINT[ nTotalPoints ];
1594cdf0e10cSrcweir         pWinFlagAry = new BYTE[ nTotalPoints ];
1595cdf0e10cSrcweir     }
1596cdf0e10cSrcweir     else
1597cdf0e10cSrcweir     {
1598cdf0e10cSrcweir         pWinPointAry = aStackAry1;
1599cdf0e10cSrcweir         pWinFlagAry = aStackAry2;
1600cdf0e10cSrcweir     }
1601cdf0e10cSrcweir 
1602cdf0e10cSrcweir     ImplPreparePolyDraw(true, nPoly, pPoints, pPtAry, pFlgAry, pWinPointAry, pWinFlagAry);
1603cdf0e10cSrcweir 
1604cdf0e10cSrcweir     sal_Bool bRet( sal_False );
1605cdf0e10cSrcweir 
1606*5f27b83cSArmin Le Grand     if( BeginPath( getHDC() ) )
1607cdf0e10cSrcweir     {
1608*5f27b83cSArmin Le Grand         PolyDraw(getHDC(), pWinPointAry, pWinFlagAry, nTotalPoints);
1609cdf0e10cSrcweir 
1610*5f27b83cSArmin Le Grand         if( EndPath( getHDC() ) )
1611cdf0e10cSrcweir         {
1612*5f27b83cSArmin Le Grand             if( StrokeAndFillPath( getHDC() ) )
1613cdf0e10cSrcweir                 bRet = sal_True;
1614cdf0e10cSrcweir         }
1615cdf0e10cSrcweir     }
1616cdf0e10cSrcweir 
1617cdf0e10cSrcweir     if( pWinPointAry != aStackAry1 )
1618cdf0e10cSrcweir     {
1619cdf0e10cSrcweir         delete [] pWinPointAry;
1620cdf0e10cSrcweir         delete [] pWinFlagAry;
1621cdf0e10cSrcweir     }
1622cdf0e10cSrcweir 
1623cdf0e10cSrcweir     return bRet;
1624cdf0e10cSrcweir #else
1625cdf0e10cSrcweir     return sal_False;
1626cdf0e10cSrcweir #endif
1627cdf0e10cSrcweir }
1628cdf0e10cSrcweir 
1629cdf0e10cSrcweir // -----------------------------------------------------------------------
1630cdf0e10cSrcweir 
1631cdf0e10cSrcweir #define POSTSCRIPT_BUFSIZE 0x4000			// MAXIMUM BUFSIZE EQ 0xFFFF
1632cdf0e10cSrcweir #define POSTSCRIPT_BOUNDINGSEARCH 0x1000	// we only try to get the BoundingBox
1633cdf0e10cSrcweir 											// in the first 4096 bytes
1634cdf0e10cSrcweir 
1635cdf0e10cSrcweir static BYTE* ImplSearchEntry( BYTE* pSource, BYTE* pDest, sal_uLong nComp, sal_uLong nSize )
1636cdf0e10cSrcweir {
1637cdf0e10cSrcweir 	while ( nComp-- >= nSize )
1638cdf0e10cSrcweir 	{
1639cdf0e10cSrcweir 		sal_uLong i;
1640cdf0e10cSrcweir 		for ( i = 0; i < nSize; i++ )
1641cdf0e10cSrcweir 		{
1642cdf0e10cSrcweir 			if ( ( pSource[i]&~0x20 ) != ( pDest[i]&~0x20 ) )
1643cdf0e10cSrcweir 				break;
1644cdf0e10cSrcweir 		}
1645cdf0e10cSrcweir 		if ( i == nSize )
1646cdf0e10cSrcweir 			return pSource;
1647cdf0e10cSrcweir 		pSource++;
1648cdf0e10cSrcweir 	}
1649cdf0e10cSrcweir 	return NULL;
1650cdf0e10cSrcweir }
1651cdf0e10cSrcweir 
1652cdf0e10cSrcweir static sal_Bool ImplGetBoundingBox( double* nNumb, BYTE* pSource, sal_uLong nSize )
1653cdf0e10cSrcweir {
1654cdf0e10cSrcweir 	sal_Bool	bRetValue = FALSE;
1655cdf0e10cSrcweir 	BYTE* pDest = ImplSearchEntry( pSource, (BYTE*)"%%BoundingBox:", nSize, 14 );
1656cdf0e10cSrcweir 	if ( pDest )
1657cdf0e10cSrcweir 	{
1658cdf0e10cSrcweir 		nNumb[0] = nNumb[1] = nNumb[2] = nNumb[3] = 0;
1659cdf0e10cSrcweir 		pDest += 14;
1660cdf0e10cSrcweir 
1661cdf0e10cSrcweir 		int nSizeLeft = nSize - ( pDest - pSource );
1662cdf0e10cSrcweir 		if ( nSizeLeft > 100 )
1663cdf0e10cSrcweir 			nSizeLeft = 100;	// only 100 bytes following the bounding box will be checked
1664cdf0e10cSrcweir 
1665cdf0e10cSrcweir 		int i;
1666cdf0e10cSrcweir 		for ( i = 0; ( i < 4 ) && nSizeLeft; i++ )
1667cdf0e10cSrcweir 		{
1668cdf0e10cSrcweir 			int 	nDivision = 1;
1669cdf0e10cSrcweir 			sal_Bool	bDivision = FALSE;
1670cdf0e10cSrcweir 			sal_Bool	bNegative = FALSE;
1671cdf0e10cSrcweir 			sal_Bool	bValid = TRUE;
1672cdf0e10cSrcweir 
1673cdf0e10cSrcweir 			while ( ( --nSizeLeft ) && ( *pDest == ' ' ) || ( *pDest == 0x9 ) ) pDest++;
1674cdf0e10cSrcweir 			BYTE nByte = *pDest;
1675cdf0e10cSrcweir 			while ( nSizeLeft && ( nByte != ' ' ) && ( nByte != 0x9 ) && ( nByte != 0xd ) && ( nByte != 0xa ) )
1676cdf0e10cSrcweir 			{
1677cdf0e10cSrcweir 				switch ( nByte )
1678cdf0e10cSrcweir 				{
1679cdf0e10cSrcweir 					case '.' :
1680cdf0e10cSrcweir 						if ( bDivision )
1681cdf0e10cSrcweir 							bValid = FALSE;
1682cdf0e10cSrcweir 						else
1683cdf0e10cSrcweir 							bDivision = TRUE;
1684cdf0e10cSrcweir 						break;
1685cdf0e10cSrcweir 					case '-' :
1686cdf0e10cSrcweir 						bNegative = TRUE;
1687cdf0e10cSrcweir 						break;
1688cdf0e10cSrcweir 					default :
1689cdf0e10cSrcweir 						if ( ( nByte < '0' ) || ( nByte > '9' ) )
1690cdf0e10cSrcweir 							nSizeLeft = 1; 	// error parsing the bounding box values
1691cdf0e10cSrcweir 						else if ( bValid )
1692cdf0e10cSrcweir 						{
1693cdf0e10cSrcweir 							if ( bDivision )
1694cdf0e10cSrcweir 								nDivision*=10;
1695cdf0e10cSrcweir 							nNumb[i] *= 10;
1696cdf0e10cSrcweir 							nNumb[i] += nByte - '0';
1697cdf0e10cSrcweir 						}
1698cdf0e10cSrcweir 						break;
1699cdf0e10cSrcweir 				}
1700cdf0e10cSrcweir 				nSizeLeft--;
1701cdf0e10cSrcweir 				nByte = *(++pDest);
1702cdf0e10cSrcweir 			}
1703cdf0e10cSrcweir 			if ( bNegative )
1704cdf0e10cSrcweir 				nNumb[i] = -nNumb[i];
1705cdf0e10cSrcweir 			if ( bDivision && ( nDivision != 1 ) )
1706cdf0e10cSrcweir 				nNumb[i] /= nDivision;
1707cdf0e10cSrcweir 		}
1708cdf0e10cSrcweir 		if ( i == 4 )
1709cdf0e10cSrcweir 			bRetValue = TRUE;
1710cdf0e10cSrcweir 	}
1711cdf0e10cSrcweir 	return bRetValue;
1712cdf0e10cSrcweir }
1713cdf0e10cSrcweir 
1714cdf0e10cSrcweir sal_Bool WinSalGraphics::drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uLong nSize )
1715cdf0e10cSrcweir {
1716cdf0e10cSrcweir 	sal_Bool bRetValue = FALSE;
1717cdf0e10cSrcweir 
1718cdf0e10cSrcweir 	if ( mbPrinter )
1719cdf0e10cSrcweir 	{
1720cdf0e10cSrcweir 		int nEscape = POSTSCRIPT_PASSTHROUGH;
1721cdf0e10cSrcweir 
1722*5f27b83cSArmin Le Grand 		if ( Escape( getHDC(), QUERYESCSUPPORT, sizeof( int ), ( LPSTR )&nEscape, 0 ) )
1723cdf0e10cSrcweir 		{
1724cdf0e10cSrcweir 			double	nBoundingBox[4];
1725cdf0e10cSrcweir 
1726cdf0e10cSrcweir 			if ( ImplGetBoundingBox( nBoundingBox, (BYTE*)pPtr, nSize ) )
1727cdf0e10cSrcweir 			{
1728cdf0e10cSrcweir                 OStringBuffer aBuf( POSTSCRIPT_BUFSIZE );
1729cdf0e10cSrcweir 
1730cdf0e10cSrcweir                 // reserve place for a sal_uInt16
1731cdf0e10cSrcweir                 aBuf.append( "aa" );
1732cdf0e10cSrcweir 
1733cdf0e10cSrcweir                 // #107797# Write out EPS encapsulation header
1734cdf0e10cSrcweir                 // ----------------------------------------------------------------------------------
1735cdf0e10cSrcweir 
1736cdf0e10cSrcweir                 // directly taken from the PLRM 3.0, p. 726. Note:
1737cdf0e10cSrcweir                 // this will definitely cause problems when
1738cdf0e10cSrcweir                 // recursively creating and embedding PostScript files
1739cdf0e10cSrcweir                 // in OOo, since we use statically-named variables
1740cdf0e10cSrcweir                 // here (namely, b4_Inc_state_salWin, dict_count_salWin and
1741cdf0e10cSrcweir                 // op_count_salWin). Currently, I have no idea on how to
1742cdf0e10cSrcweir                 // work around that, except from scanning and
1743cdf0e10cSrcweir                 // interpreting the EPS for unused identifiers.
1744cdf0e10cSrcweir 
1745cdf0e10cSrcweir                 // append the real text
1746cdf0e10cSrcweir                 aBuf.append( "\n\n/b4_Inc_state_salWin save def\n"
1747cdf0e10cSrcweir                              "/dict_count_salWin countdictstack def\n"
1748cdf0e10cSrcweir                              "/op_count_salWin count 1 sub def\n"
1749cdf0e10cSrcweir                              "userdict begin\n"
1750cdf0e10cSrcweir                              "/showpage {} def\n"
1751cdf0e10cSrcweir                              "0 setgray 0 setlinecap\n"
1752cdf0e10cSrcweir                              "1 setlinewidth 0 setlinejoin\n"
1753cdf0e10cSrcweir                              "10 setmiterlimit [] 0 setdash newpath\n"
1754cdf0e10cSrcweir                              "/languagelevel where\n"
1755cdf0e10cSrcweir                              "{\n"
1756cdf0e10cSrcweir                              "  pop languagelevel\n"
1757cdf0e10cSrcweir                              "  1 ne\n"
1758cdf0e10cSrcweir                              "  {\n"
1759cdf0e10cSrcweir                              "    false setstrokeadjust false setoverprint\n"
1760cdf0e10cSrcweir                              "  } if\n"
1761cdf0e10cSrcweir                              "} if\n\n" );
1762cdf0e10cSrcweir 
1763cdf0e10cSrcweir 
1764cdf0e10cSrcweir                 // #i10737# Apply clipping manually
1765cdf0e10cSrcweir                 // ----------------------------------------------------------------------------------
1766cdf0e10cSrcweir 
1767cdf0e10cSrcweir                 // Windows seems to ignore any clipping at the HDC,
1768cdf0e10cSrcweir                 // when followed by a POSTSCRIPT_PASSTHROUGH
1769cdf0e10cSrcweir 
1770cdf0e10cSrcweir                 // Check whether we've got a clipping, consisting of
1771cdf0e10cSrcweir                 // exactly one rect (other cases should be, but aren't
1772cdf0e10cSrcweir                 // handled currently)
1773cdf0e10cSrcweir 
1774cdf0e10cSrcweir                 // TODO: Handle more than one rectangle here (take
1775cdf0e10cSrcweir                 // care, the buffer can handle only POSTSCRIPT_BUFSIZE
1776cdf0e10cSrcweir                 // characters!)
1777cdf0e10cSrcweir                 if ( mhRegion != 0 &&
1778cdf0e10cSrcweir                      mpStdClipRgnData != NULL &&
1779cdf0e10cSrcweir                      mpClipRgnData == mpStdClipRgnData &&
1780cdf0e10cSrcweir                      mpClipRgnData->rdh.nCount == 1 )
1781cdf0e10cSrcweir                 {
1782cdf0e10cSrcweir                     RECT* pRect = &(mpClipRgnData->rdh.rcBound);
1783cdf0e10cSrcweir 
1784cdf0e10cSrcweir                     aBuf.append( "\nnewpath\n" );
1785cdf0e10cSrcweir                     aBuf.append( pRect->left );
1786cdf0e10cSrcweir                     aBuf.append( " " );
1787cdf0e10cSrcweir                     aBuf.append( pRect->top );
1788cdf0e10cSrcweir                     aBuf.append( " moveto\n" );
1789cdf0e10cSrcweir                     aBuf.append( pRect->right );
1790cdf0e10cSrcweir                     aBuf.append( " " );
1791cdf0e10cSrcweir                     aBuf.append( pRect->top );
1792cdf0e10cSrcweir                     aBuf.append( " lineto\n" );
1793cdf0e10cSrcweir                     aBuf.append( pRect->right );
1794cdf0e10cSrcweir                     aBuf.append( " " );
1795cdf0e10cSrcweir                     aBuf.append( pRect->bottom );
1796cdf0e10cSrcweir                     aBuf.append( " lineto\n" );
1797cdf0e10cSrcweir                     aBuf.append( pRect->left );
1798cdf0e10cSrcweir                     aBuf.append( " " );
1799cdf0e10cSrcweir                     aBuf.append( pRect->bottom );
1800cdf0e10cSrcweir                     aBuf.append( " lineto\n"
1801cdf0e10cSrcweir                                  "closepath\n"
1802cdf0e10cSrcweir                                  "clip\n"
1803cdf0e10cSrcweir                                  "newpath\n" );
1804cdf0e10cSrcweir                 }
1805cdf0e10cSrcweir 
1806cdf0e10cSrcweir                 // #107797# Write out buffer
1807cdf0e10cSrcweir                 // ----------------------------------------------------------------------------------
1808cdf0e10cSrcweir 				*((sal_uInt16*)aBuf.getStr()) = (sal_uInt16)( aBuf.getLength() - 2 );
1809*5f27b83cSArmin Le Grand 				Escape ( getHDC(), nEscape, aBuf.getLength(), (LPTSTR)aBuf.getStr(), 0 );
1810cdf0e10cSrcweir 
1811cdf0e10cSrcweir 
1812cdf0e10cSrcweir                 // #107797# Write out EPS transformation code
1813cdf0e10cSrcweir                 // ----------------------------------------------------------------------------------
1814cdf0e10cSrcweir 				double	dM11 = nWidth / ( nBoundingBox[2] - nBoundingBox[0] );
1815cdf0e10cSrcweir 				double	dM22 = nHeight / (nBoundingBox[1] - nBoundingBox[3] );
1816cdf0e10cSrcweir                 // reserve a sal_uInt16 again
1817cdf0e10cSrcweir                 aBuf.setLength( 2 );
1818cdf0e10cSrcweir                 aBuf.append( "\n\n[" );
1819cdf0e10cSrcweir                 aBuf.append( dM11 );
1820cdf0e10cSrcweir                 aBuf.append( " 0 0 " );
1821cdf0e10cSrcweir                 aBuf.append( dM22 );
1822cdf0e10cSrcweir                 aBuf.append( ' ' );
1823cdf0e10cSrcweir                 aBuf.append( nX - ( dM11 * nBoundingBox[0] ) );
1824cdf0e10cSrcweir                 aBuf.append( ' ' );
1825cdf0e10cSrcweir                 aBuf.append( nY - ( dM22 * nBoundingBox[3] ) );
1826cdf0e10cSrcweir                 aBuf.append( "] concat\n"
1827cdf0e10cSrcweir                              "%%BeginDocument:\n" );
1828cdf0e10cSrcweir 				*((sal_uInt16*)aBuf.getStr()) = (sal_uInt16)( aBuf.getLength() - 2 );
1829*5f27b83cSArmin Le Grand 				Escape ( getHDC(), nEscape, aBuf.getLength(), (LPTSTR)aBuf.getStr(), 0 );
1830cdf0e10cSrcweir 
1831cdf0e10cSrcweir 
1832cdf0e10cSrcweir                 // #107797# Write out actual EPS content
1833cdf0e10cSrcweir                 // ----------------------------------------------------------------------------------
1834cdf0e10cSrcweir 				sal_uLong	nToDo = nSize;
1835cdf0e10cSrcweir 				sal_uLong	nDoNow;
1836cdf0e10cSrcweir 				while ( nToDo )
1837cdf0e10cSrcweir 				{
1838cdf0e10cSrcweir 					nDoNow = nToDo;
1839cdf0e10cSrcweir 					if ( nToDo > POSTSCRIPT_BUFSIZE - 2 )
1840cdf0e10cSrcweir 						nDoNow = POSTSCRIPT_BUFSIZE - 2;
1841cdf0e10cSrcweir                     // the following is based on the string buffer allocation
1842cdf0e10cSrcweir                     // of size POSTSCRIPT_BUFSIZE at construction time of aBuf
1843cdf0e10cSrcweir 					*((sal_uInt16*)aBuf.getStr()) = (sal_uInt16)nDoNow;
1844cdf0e10cSrcweir 					memcpy( (void*)(aBuf.getStr() + 2), (BYTE*)pPtr + nSize - nToDo, nDoNow );
1845*5f27b83cSArmin Le Grand 					sal_uLong nResult = Escape ( getHDC(), nEscape, nDoNow + 2, (LPTSTR)aBuf.getStr(), 0 );
1846cdf0e10cSrcweir 					if (!nResult )
1847cdf0e10cSrcweir 						break;
1848cdf0e10cSrcweir 					nToDo -= nResult;
1849cdf0e10cSrcweir 				}
1850cdf0e10cSrcweir 
1851cdf0e10cSrcweir 
1852cdf0e10cSrcweir                 // #107797# Write out EPS encapsulation footer
1853cdf0e10cSrcweir                 // ----------------------------------------------------------------------------------
1854cdf0e10cSrcweir                 // reserve a sal_uInt16 again
1855cdf0e10cSrcweir                 aBuf.setLength( 2 );
1856cdf0e10cSrcweir                 aBuf.append( "%%EndDocument\n"
1857cdf0e10cSrcweir                              "count op_count_salWin sub {pop} repeat\n"
1858cdf0e10cSrcweir                              "countdictstack dict_count_salWin sub {end} repeat\n"
1859cdf0e10cSrcweir                              "b4_Inc_state_salWin restore\n\n" );
1860cdf0e10cSrcweir 				*((sal_uInt16*)aBuf.getStr()) = (sal_uInt16)( aBuf.getLength() - 2 );
1861*5f27b83cSArmin Le Grand 				Escape ( getHDC(), nEscape, aBuf.getLength(), (LPTSTR)aBuf.getStr(), 0 );
1862cdf0e10cSrcweir 				bRetValue = TRUE;
1863cdf0e10cSrcweir 			}
1864cdf0e10cSrcweir 		}
1865cdf0e10cSrcweir 	}
1866cdf0e10cSrcweir 
1867cdf0e10cSrcweir 	return bRetValue;
1868cdf0e10cSrcweir }
1869cdf0e10cSrcweir 
1870cdf0e10cSrcweir // -----------------------------------------------------------------------
1871cdf0e10cSrcweir 
1872cdf0e10cSrcweir SystemGraphicsData WinSalGraphics::GetGraphicsData() const
1873cdf0e10cSrcweir {
1874cdf0e10cSrcweir     SystemGraphicsData aRes;
1875cdf0e10cSrcweir     aRes.nSize = sizeof(aRes);
1876*5f27b83cSArmin Le Grand     aRes.hDC = const_cast< WinSalGraphics* >(this)->getHDC();
1877cdf0e10cSrcweir     return aRes;
1878cdf0e10cSrcweir }
1879cdf0e10cSrcweir 
1880cdf0e10cSrcweir // -----------------------------------------------------------------------
1881