Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <config_graphite.h>
21 :
22 : #include <vector>
23 : #include <queue>
24 : #include <set>
25 :
26 : #include <prex.h>
27 : #include <X11/Xproto.h>
28 : #include <postx.h>
29 :
30 : #include "tools/debug.hxx"
31 :
32 : #include "basegfx/polygon/b2dpolygon.hxx"
33 : #include "basegfx/polygon/b2dpolypolygon.hxx"
34 : #include "basegfx/polygon/b2dpolypolygontools.hxx"
35 : #include "basegfx/polygon/b2dpolygontools.hxx"
36 : #include "basegfx/polygon/b2dpolygonclipper.hxx"
37 : #include "basegfx/polygon/b2dlinegeometry.hxx"
38 : #include "basegfx/matrix/b2dhommatrix.hxx"
39 : #include "basegfx/matrix/b2dhommatrixtools.hxx"
40 : #include "basegfx/polygon/b2dpolypolygoncutter.hxx"
41 : #include "basegfx/polygon/b2dtrapezoid.hxx"
42 :
43 : #include "vcl/jobdata.hxx"
44 :
45 : #include "unx/salunx.h"
46 : #include "unx/saldata.hxx"
47 : #include "unx/saldisp.hxx"
48 : #include "unx/salgdi.h"
49 : #include "unx/salframe.h"
50 : #include "unx/salvd.h"
51 : #include <unx/x11/xlimits.hxx>
52 :
53 : #include "generic/printergfx.hxx"
54 : #include "xrender_peer.hxx"
55 :
56 : #define STATIC_POINTS 64
57 :
58 : class SalPolyLine
59 : {
60 : XPoint Points_[STATIC_POINTS];
61 : XPoint *pFirst_;
62 : public:
63 : inline SalPolyLine( sal_uLong nPoints );
64 : inline SalPolyLine( sal_uLong nPoints, const SalPoint *p );
65 : inline ~SalPolyLine();
66 0 : inline XPoint &operator [] ( sal_uLong n ) const
67 0 : { return pFirst_[n]; }
68 : };
69 :
70 : inline SalPolyLine::SalPolyLine( sal_uLong nPoints )
71 : : pFirst_( nPoints+1 > STATIC_POINTS ? new XPoint[nPoints+1] : Points_ )
72 : {}
73 :
74 0 : inline SalPolyLine::SalPolyLine( sal_uLong nPoints, const SalPoint *p )
75 0 : : pFirst_( nPoints+1 > STATIC_POINTS ? new XPoint[nPoints+1] : Points_ )
76 : {
77 0 : for( sal_uLong i = 0; i < nPoints; i++ )
78 : {
79 0 : pFirst_[i].x = (short)p[i].mnX;
80 0 : pFirst_[i].y = (short)p[i].mnY;
81 : }
82 0 : pFirst_[nPoints] = pFirst_[0]; // close polyline
83 0 : }
84 :
85 0 : inline SalPolyLine::~SalPolyLine()
86 0 : { if( pFirst_ != Points_ ) delete [] pFirst_; }
87 :
88 : #undef STATIC_POINTS
89 :
90 0 : X11SalGraphics::X11SalGraphics()
91 0 : : m_nXScreen( 0 )
92 : {
93 0 : m_pFrame = NULL;
94 0 : m_pVDev = NULL;
95 0 : m_pDeleteColormap = NULL;
96 0 : hDrawable_ = None;
97 0 : m_aXRenderPicture = 0;
98 0 : m_pXRenderFormat = NULL;
99 :
100 0 : mpClipRegion = NULL;
101 0 : pPaintRegion_ = NULL;
102 :
103 0 : pPenGC_ = NULL;
104 0 : nPenPixel_ = 0;
105 0 : nPenColor_ = MAKE_SALCOLOR( 0x00, 0x00, 0x00 ); // Black
106 :
107 0 : pFontGC_ = NULL;
108 0 : for( int i = 0; i < MAX_FALLBACK; ++i )
109 0 : mpServerFont[i] = NULL;
110 :
111 0 : nTextPixel_ = 0;
112 0 : nTextColor_ = MAKE_SALCOLOR( 0x00, 0x00, 0x00 ); // Black
113 :
114 : #if ENABLE_GRAPHITE
115 : // check if graphite fonts have been disabled
116 0 : static const char* pDisableGraphiteStr = getenv( "SAL_DISABLE_GRAPHITE" );
117 0 : bDisableGraphite_ = pDisableGraphiteStr ? (pDisableGraphiteStr[0]!='0') : sal_False;
118 : #endif
119 :
120 0 : pBrushGC_ = NULL;
121 0 : nBrushPixel_ = 0;
122 0 : nBrushColor_ = MAKE_SALCOLOR( 0xFF, 0xFF, 0xFF ); // White
123 0 : hBrush_ = None;
124 :
125 0 : pMonoGC_ = NULL;
126 0 : pCopyGC_ = NULL;
127 0 : pMaskGC_ = NULL;
128 0 : pInvertGC_ = NULL;
129 0 : pInvert50GC_ = NULL;
130 0 : pStippleGC_ = NULL;
131 0 : pTrackingGC_ = NULL;
132 :
133 0 : bWindow_ = sal_False;
134 0 : bPrinter_ = sal_False;
135 0 : bVirDev_ = sal_False;
136 0 : bPenGC_ = sal_False;
137 0 : bFontGC_ = sal_False;
138 0 : bBrushGC_ = sal_False;
139 0 : bMonoGC_ = sal_False;
140 0 : bCopyGC_ = sal_False;
141 0 : bInvertGC_ = sal_False;
142 0 : bInvert50GC_ = sal_False;
143 0 : bStippleGC_ = sal_False;
144 0 : bTrackingGC_ = sal_False;
145 0 : bXORMode_ = sal_False;
146 0 : bDitherBrush_ = sal_False;
147 0 : }
148 :
149 0 : X11SalGraphics::~X11SalGraphics()
150 : {
151 0 : ReleaseFonts();
152 0 : freeResources();
153 0 : }
154 :
155 0 : void X11SalGraphics::freeResources()
156 : {
157 0 : Display *pDisplay = GetXDisplay();
158 :
159 : DBG_ASSERT( !pPaintRegion_, "pPaintRegion_" );
160 0 : if( mpClipRegion ) XDestroyRegion( mpClipRegion ), mpClipRegion = None;
161 :
162 0 : if( hBrush_ ) XFreePixmap( pDisplay, hBrush_ ), hBrush_ = None;
163 0 : if( pPenGC_ ) XFreeGC( pDisplay, pPenGC_ ), pPenGC_ = None;
164 0 : if( pFontGC_ ) XFreeGC( pDisplay, pFontGC_ ), pFontGC_ = None;
165 0 : if( pBrushGC_ ) XFreeGC( pDisplay, pBrushGC_ ), pBrushGC_ = None;
166 0 : if( pMonoGC_ ) XFreeGC( pDisplay, pMonoGC_ ), pMonoGC_ = None;
167 0 : if( pCopyGC_ ) XFreeGC( pDisplay, pCopyGC_ ), pCopyGC_ = None;
168 0 : if( pMaskGC_ ) XFreeGC( pDisplay, pMaskGC_ ), pMaskGC_ = None;
169 0 : if( pInvertGC_ ) XFreeGC( pDisplay, pInvertGC_ ), pInvertGC_ = None;
170 0 : if( pInvert50GC_ ) XFreeGC( pDisplay, pInvert50GC_ ), pInvert50GC_ = None;
171 0 : if( pStippleGC_ ) XFreeGC( pDisplay, pStippleGC_ ), pStippleGC_ = None;
172 0 : if( pTrackingGC_ ) XFreeGC( pDisplay, pTrackingGC_ ), pTrackingGC_ = None;
173 0 : if( m_pDeleteColormap )
174 0 : delete m_pDeleteColormap, m_pColormap = m_pDeleteColormap = NULL;
175 :
176 0 : if( m_aXRenderPicture )
177 0 : XRenderPeer::GetInstance().FreePicture( m_aXRenderPicture ), m_aXRenderPicture = 0;
178 :
179 0 : bPenGC_ = bFontGC_ = bBrushGC_ = bMonoGC_ = bCopyGC_ = bInvertGC_ = bInvert50GC_ = bStippleGC_ = bTrackingGC_ = false;
180 0 : }
181 :
182 0 : void X11SalGraphics::SetDrawable( Drawable aDrawable, SalX11Screen nXScreen )
183 : {
184 : // shortcut if nothing changed
185 0 : if( hDrawable_ == aDrawable )
186 0 : return;
187 :
188 : // free screen specific resources if needed
189 0 : if( nXScreen != m_nXScreen )
190 : {
191 0 : freeResources();
192 0 : m_pColormap = &GetGenericData()->GetSalDisplay()->GetColormap( nXScreen );
193 0 : m_nXScreen = nXScreen;
194 : }
195 :
196 0 : hDrawable_ = aDrawable;
197 0 : SetXRenderFormat( NULL );
198 0 : if( m_aXRenderPicture )
199 : {
200 0 : XRenderPeer::GetInstance().FreePicture( m_aXRenderPicture );
201 0 : m_aXRenderPicture = 0;
202 : }
203 :
204 0 : if( hDrawable_ )
205 : {
206 0 : nPenPixel_ = GetPixel( nPenColor_ );
207 0 : nTextPixel_ = GetPixel( nTextColor_ );
208 0 : nBrushPixel_ = GetPixel( nBrushColor_ );
209 : }
210 : }
211 :
212 0 : void X11SalGraphics::Init( SalFrame *pFrame, Drawable aTarget,
213 : SalX11Screen nXScreen )
214 : {
215 0 : m_pColormap = &GetGenericData()->GetSalDisplay()->GetColormap(nXScreen);
216 0 : m_nXScreen = nXScreen;
217 0 : SetDrawable( aTarget, nXScreen );
218 :
219 0 : bWindow_ = sal_True;
220 0 : m_pFrame = pFrame;
221 0 : m_pVDev = NULL;
222 0 : }
223 :
224 0 : void X11SalGraphics::DeInit()
225 : {
226 0 : SetDrawable( None, m_nXScreen );
227 0 : }
228 :
229 0 : void X11SalGraphics::SetClipRegion( GC pGC, XLIB_Region pXReg ) const
230 : {
231 0 : Display *pDisplay = GetXDisplay();
232 :
233 0 : int n = 0;
234 : XLIB_Region Regions[3];
235 :
236 0 : if( mpClipRegion )
237 0 : Regions[n++] = mpClipRegion;
238 :
239 0 : if( pXReg && !XEmptyRegion( pXReg ) )
240 0 : Regions[n++] = pXReg;
241 :
242 0 : if( 0 == n )
243 0 : XSetClipMask( pDisplay, pGC, None );
244 0 : else if( 1 == n )
245 0 : XSetRegion( pDisplay, pGC, Regions[0] );
246 : else
247 : {
248 0 : XLIB_Region pTmpRegion = XCreateRegion();
249 0 : XIntersectRegion( Regions[0], Regions[1], pTmpRegion );
250 :
251 0 : XSetRegion( pDisplay, pGC, pTmpRegion );
252 0 : XDestroyRegion( pTmpRegion );
253 : }
254 0 : }
255 :
256 0 : GC X11SalGraphics::SelectPen()
257 : {
258 0 : Display *pDisplay = GetXDisplay();
259 :
260 0 : if( !pPenGC_ )
261 : {
262 : XGCValues values;
263 0 : values.subwindow_mode = ClipByChildren;
264 0 : values.fill_rule = EvenOddRule; // Pict import/ Gradient
265 0 : values.graphics_exposures = False;
266 :
267 : pPenGC_ = XCreateGC( pDisplay, hDrawable_,
268 : GCSubwindowMode | GCFillRule | GCGraphicsExposures,
269 0 : &values );
270 : }
271 :
272 0 : if( !bPenGC_ )
273 : {
274 0 : if( nPenColor_ != SALCOLOR_NONE )
275 0 : XSetForeground( pDisplay, pPenGC_, nPenPixel_ );
276 0 : XSetFunction ( pDisplay, pPenGC_, bXORMode_ ? GXxor : GXcopy );
277 0 : SetClipRegion( pPenGC_ );
278 0 : bPenGC_ = sal_True;
279 : }
280 :
281 0 : return pPenGC_;
282 : }
283 :
284 0 : GC X11SalGraphics::SelectBrush()
285 : {
286 0 : Display *pDisplay = GetXDisplay();
287 :
288 : DBG_ASSERT( nBrushColor_ != SALCOLOR_NONE, "Brush Transparent" );
289 :
290 0 : if( !pBrushGC_ )
291 : {
292 : XGCValues values;
293 0 : values.subwindow_mode = ClipByChildren;
294 0 : values.fill_rule = EvenOddRule; // Pict import/ Gradient
295 0 : values.graphics_exposures = False;
296 :
297 : pBrushGC_ = XCreateGC( pDisplay, hDrawable_,
298 : GCSubwindowMode | GCFillRule | GCGraphicsExposures,
299 0 : &values );
300 : }
301 :
302 0 : if( !bBrushGC_ )
303 : {
304 0 : if( !bDitherBrush_ )
305 : {
306 0 : XSetFillStyle ( pDisplay, pBrushGC_, FillSolid );
307 0 : XSetForeground( pDisplay, pBrushGC_, nBrushPixel_ );
308 0 : if( bPrinter_ )
309 0 : XSetTile( pDisplay, pBrushGC_, None );
310 : }
311 : else
312 : {
313 : // Bug in Sun Solaris 2.5.1, XFillPolygon doesn't always reflect
314 : // changes of the tile. PROPERTY_BUG_Tile doesn't fix this !
315 0 : if (GetDisplay()->GetProperties() & PROPERTY_BUG_FillPolygon_Tile)
316 0 : XSetFillStyle ( pDisplay, pBrushGC_, FillSolid );
317 :
318 0 : XSetFillStyle ( pDisplay, pBrushGC_, FillTiled );
319 0 : XSetTile ( pDisplay, pBrushGC_, hBrush_ );
320 : }
321 0 : XSetFunction ( pDisplay, pBrushGC_, bXORMode_ ? GXxor : GXcopy );
322 0 : SetClipRegion( pBrushGC_ );
323 :
324 0 : bBrushGC_ = sal_True;
325 : }
326 :
327 0 : return pBrushGC_;
328 : }
329 :
330 0 : GC X11SalGraphics::GetTrackingGC()
331 : {
332 0 : const char dash_list[2] = {2, 2};
333 :
334 0 : if( !pTrackingGC_ )
335 : {
336 : XGCValues values;
337 :
338 0 : values.graphics_exposures = False;
339 0 : values.foreground = m_pColormap->GetBlackPixel()
340 0 : ^ m_pColormap->GetWhitePixel();
341 0 : values.function = GXxor;
342 0 : values.line_width = 1;
343 0 : values.line_style = LineOnOffDash;
344 :
345 : pTrackingGC_ = XCreateGC( GetXDisplay(), GetDrawable(),
346 : GCGraphicsExposures | GCForeground | GCFunction
347 : | GCLineWidth | GCLineStyle,
348 0 : &values );
349 0 : XSetDashes( GetXDisplay(), pTrackingGC_, 0, dash_list, 2 );
350 : }
351 :
352 0 : if( !bTrackingGC_ )
353 : {
354 0 : SetClipRegion( pTrackingGC_ );
355 0 : bTrackingGC_ = sal_True;
356 : }
357 :
358 0 : return pTrackingGC_;
359 : }
360 :
361 0 : void X11SalGraphics::DrawLines( sal_uLong nPoints,
362 : const SalPolyLine &rPoints,
363 : GC pGC,
364 : bool bClose
365 : )
366 : {
367 : // calculate how many lines XWindow can draw in one go
368 0 : sal_uLong nMaxLines = (GetDisplay()->GetMaxRequestSize() - sizeof(xPolyPointReq))
369 0 : / sizeof(xPoint);
370 0 : if( nMaxLines > nPoints ) nMaxLines = nPoints;
371 :
372 : // print all lines that XWindows can draw
373 : sal_uLong n;
374 0 : for( n = 0; nPoints - n > nMaxLines; n += nMaxLines - 1 )
375 : XDrawLines( GetXDisplay(),
376 : GetDrawable(),
377 : pGC,
378 0 : &rPoints[n],
379 : nMaxLines,
380 0 : CoordModeOrigin );
381 :
382 0 : if( n < nPoints )
383 : XDrawLines( GetXDisplay(),
384 : GetDrawable(),
385 : pGC,
386 0 : &rPoints[n],
387 0 : nPoints - n,
388 0 : CoordModeOrigin );
389 0 : if( bClose )
390 : {
391 0 : if( rPoints[nPoints-1].x != rPoints[0].x || rPoints[nPoints-1].y != rPoints[0].y )
392 0 : drawLine( rPoints[nPoints-1].x, rPoints[nPoints-1].y, rPoints[0].x, rPoints[0].y );
393 : }
394 0 : }
395 :
396 : // Calculate a dither-pixmap and make a brush of it
397 : #define P_DELTA 51
398 : #define DMAP( v, m ) ((v % P_DELTA) > m ? (v / P_DELTA) + 1 : (v / P_DELTA))
399 :
400 0 : BOOL X11SalGraphics::GetDitherPixmap( SalColor nSalColor )
401 : {
402 : static const short nOrdDither8Bit[ 8 ][ 8 ] =
403 : {
404 : { 0, 38, 9, 48, 2, 40, 12, 50},
405 : {25, 12, 35, 22, 28, 15, 37, 24},
406 : { 6, 44, 3, 41, 8, 47, 5, 44},
407 : {32, 19, 28, 16, 34, 21, 31, 18},
408 : { 1, 40, 11, 49, 0, 39, 10, 48},
409 : {27, 14, 36, 24, 26, 13, 36, 23},
410 : { 8, 46, 4, 43, 7, 45, 4, 42},
411 : {33, 20, 30, 17, 32, 20, 29, 16}
412 : };
413 :
414 : // test for correct depth (8bit)
415 0 : if( GetColormap().GetVisual().GetDepth() != 8 )
416 0 : return sal_False;
417 :
418 : char pBits[64];
419 0 : char *pBitsPtr = pBits;
420 :
421 : // Set the pallette-entries for the dithering tile
422 0 : sal_uInt8 nSalColorRed = SALCOLOR_RED ( nSalColor );
423 0 : sal_uInt8 nSalColorGreen = SALCOLOR_GREEN ( nSalColor );
424 0 : sal_uInt8 nSalColorBlue = SALCOLOR_BLUE ( nSalColor );
425 :
426 0 : for( int nY = 0; nY < 8; nY++ )
427 : {
428 0 : for( int nX = 0; nX < 8; nX++ )
429 : {
430 0 : short nMagic = nOrdDither8Bit[nY][nX];
431 0 : sal_uInt8 nR = P_DELTA * DMAP( nSalColorRed, nMagic );
432 0 : sal_uInt8 nG = P_DELTA * DMAP( nSalColorGreen, nMagic );
433 0 : sal_uInt8 nB = P_DELTA * DMAP( nSalColorBlue, nMagic );
434 :
435 0 : *pBitsPtr++ = GetColormap().GetPixel( MAKE_SALCOLOR( nR, nG, nB ) );
436 : }
437 : }
438 :
439 : // create the tile as ximage and an according pixmap -> caching
440 : XImage *pImage = XCreateImage( GetXDisplay(),
441 0 : GetColormap().GetXVisual(),
442 : 8,
443 : ZPixmap,
444 : 0, // offset
445 : pBits, // data
446 : 8, 8, // width & height
447 : 8, // bitmap_pad
448 0 : 0 ); // (default) bytes_per_line
449 :
450 0 : if ( GetDisplay()->GetProperties() & PROPERTY_BUG_Tile )
451 : {
452 0 : if (hBrush_)
453 0 : XFreePixmap (GetXDisplay(), hBrush_);
454 0 : hBrush_ = limitXCreatePixmap( GetXDisplay(), GetDrawable(), 8, 8, 8 );
455 : }
456 0 : else if( !hBrush_ )
457 0 : hBrush_ = limitXCreatePixmap( GetXDisplay(), GetDrawable(), 8, 8, 8 );
458 :
459 : // put the ximage to the pixmap
460 : XPutImage( GetXDisplay(),
461 : hBrush_,
462 : GetDisplay()->GetCopyGC( m_nXScreen ),
463 : pImage,
464 : 0, 0, // Source
465 : 0, 0, // Destination
466 0 : 8, 8 ); // width & height
467 :
468 : // destroy image-frame but not palette-data
469 0 : pImage->data = NULL;
470 0 : XDestroyImage( pImage );
471 :
472 0 : return sal_True;
473 : }
474 :
475 0 : void X11SalGraphics::GetResolution( sal_Int32 &rDPIX, sal_Int32 &rDPIY ) // const
476 : {
477 0 : const SalDisplay *pDisplay = GetDisplay();
478 0 : if (!pDisplay)
479 : {
480 : OSL_TRACE("Null display");
481 0 : rDPIX = rDPIY = 96;
482 0 : return;
483 : }
484 :
485 0 : rDPIX = pDisplay->GetResolution().A();
486 0 : rDPIY = pDisplay->GetResolution().B();
487 0 : if( !pDisplay->GetExactResolution() && rDPIY < 96 )
488 : {
489 0 : rDPIX = Divide( rDPIX * 96, rDPIY );
490 0 : rDPIY = 96;
491 : }
492 0 : else if ( rDPIY > 200 )
493 : {
494 0 : rDPIX = Divide( rDPIX * 200, rDPIY );
495 0 : rDPIY = 200;
496 : }
497 :
498 : // #i12705# equalize x- and y-resolution if they are close enough
499 0 : if( rDPIX != rDPIY )
500 : {
501 : // different x- and y- resolutions are usually artifacts of
502 : // a wrongly calculated screen size.
503 : #ifdef DEBUG
504 : printf("Forcing Resolution from %" SAL_PRIdINT32 "x%" SAL_PRIdINT32 " to %" SAL_PRIdINT32 "x%" SAL_PRIdINT32 "\n",
505 : rDPIX,rDPIY,rDPIY,rDPIY);
506 : #endif
507 0 : rDPIX = rDPIY; // y-resolution is more trustworthy
508 : }
509 : }
510 :
511 0 : sal_uInt16 X11SalGraphics::GetBitCount() const
512 : {
513 0 : return GetVisual().GetDepth();
514 : }
515 :
516 0 : long X11SalGraphics::GetGraphicsWidth() const
517 : {
518 0 : if( m_pFrame )
519 0 : return m_pFrame->maGeometry.nWidth;
520 0 : else if( m_pVDev )
521 0 : return m_pVDev->GetWidth();
522 : else
523 0 : return 0;
524 : }
525 :
526 0 : long X11SalGraphics::GetGraphicsHeight() const
527 : {
528 0 : if( m_pFrame )
529 0 : return m_pFrame->maGeometry.nHeight;
530 0 : else if( m_pVDev )
531 0 : return m_pVDev->GetHeight();
532 : else
533 0 : return 0;
534 : }
535 :
536 0 : void X11SalGraphics::ResetClipRegion()
537 : {
538 0 : if( mpClipRegion )
539 : {
540 0 : bPenGC_ = sal_False;
541 0 : bFontGC_ = sal_False;
542 0 : bBrushGC_ = sal_False;
543 0 : bMonoGC_ = sal_False;
544 0 : bCopyGC_ = sal_False;
545 0 : bInvertGC_ = sal_False;
546 0 : bInvert50GC_ = sal_False;
547 0 : bStippleGC_ = sal_False;
548 0 : bTrackingGC_ = sal_False;
549 :
550 0 : XDestroyRegion( mpClipRegion );
551 0 : mpClipRegion = NULL;
552 : }
553 0 : }
554 :
555 0 : bool X11SalGraphics::setClipRegion( const Region& i_rClip )
556 : {
557 0 : if( mpClipRegion )
558 0 : XDestroyRegion( mpClipRegion );
559 0 : mpClipRegion = XCreateRegion();
560 :
561 0 : RectangleVector aRectangles;
562 0 : i_rClip.GetRegionRectangles(aRectangles);
563 :
564 0 : for(RectangleVector::const_iterator aRectIter(aRectangles.begin()); aRectIter != aRectangles.end(); ++aRectIter)
565 : {
566 0 : const long nW(aRectIter->GetWidth());
567 :
568 0 : if(nW)
569 : {
570 0 : const long nH(aRectIter->GetHeight());
571 :
572 0 : if(nH)
573 : {
574 : XRectangle aRect;
575 :
576 0 : aRect.x = (short)aRectIter->Left();
577 0 : aRect.y = (short)aRectIter->Top();
578 0 : aRect.width = (unsigned short)nW;
579 0 : aRect.height = (unsigned short)nH;
580 0 : XUnionRectWithRegion(&aRect, mpClipRegion, mpClipRegion);
581 : }
582 : }
583 : }
584 :
585 : //ImplRegionInfo aInfo;
586 : //long nX, nY, nW, nH;
587 : //bool bRegionRect = i_rClip.ImplGetFirstRect(aInfo, nX, nY, nW, nH );
588 : //while( bRegionRect )
589 : //{
590 : // if ( nW && nH )
591 : // {
592 : // XRectangle aRect;
593 : // aRect.x = (short)nX;
594 : // aRect.y = (short)nY;
595 : // aRect.width = (unsigned short)nW;
596 : // aRect.height = (unsigned short)nH;
597 : //
598 : // XUnionRectWithRegion( &aRect, mpClipRegion, mpClipRegion );
599 : // }
600 : // bRegionRect = i_rClip.ImplGetNextRect( aInfo, nX, nY, nW, nH );
601 : //}
602 :
603 : // done, invalidate GCs
604 0 : bPenGC_ = sal_False;
605 0 : bFontGC_ = sal_False;
606 0 : bBrushGC_ = sal_False;
607 0 : bMonoGC_ = sal_False;
608 0 : bCopyGC_ = sal_False;
609 0 : bInvertGC_ = sal_False;
610 0 : bInvert50GC_ = sal_False;
611 0 : bStippleGC_ = sal_False;
612 0 : bTrackingGC_ = sal_False;
613 :
614 0 : if( XEmptyRegion( mpClipRegion ) )
615 : {
616 0 : XDestroyRegion( mpClipRegion );
617 0 : mpClipRegion= NULL;
618 : }
619 0 : return true;
620 : }
621 :
622 0 : void X11SalGraphics::SetLineColor()
623 : {
624 0 : if( nPenColor_ != SALCOLOR_NONE )
625 : {
626 0 : nPenColor_ = SALCOLOR_NONE;
627 0 : bPenGC_ = sal_False;
628 : }
629 0 : }
630 :
631 0 : void X11SalGraphics::SetLineColor( SalColor nSalColor )
632 : {
633 0 : if( nPenColor_ != nSalColor )
634 : {
635 0 : nPenColor_ = nSalColor;
636 0 : nPenPixel_ = GetPixel( nSalColor );
637 0 : bPenGC_ = sal_False;
638 : }
639 0 : }
640 :
641 0 : void X11SalGraphics::SetFillColor()
642 : {
643 0 : if( nBrushColor_ != SALCOLOR_NONE )
644 : {
645 0 : bDitherBrush_ = sal_False;
646 0 : nBrushColor_ = SALCOLOR_NONE;
647 0 : bBrushGC_ = sal_False;
648 : }
649 0 : }
650 :
651 0 : void X11SalGraphics::SetFillColor( SalColor nSalColor )
652 : {
653 0 : if( nBrushColor_ != nSalColor )
654 : {
655 0 : bDitherBrush_ = sal_False;
656 0 : nBrushColor_ = nSalColor;
657 0 : nBrushPixel_ = GetPixel( nSalColor );
658 0 : if( TrueColor != GetColormap().GetVisual().GetClass()
659 0 : && GetColormap().GetColor( nBrushPixel_ ) != nBrushColor_
660 0 : && nSalColor != MAKE_SALCOLOR( 0x00, 0x00, 0x00 ) // black
661 0 : && nSalColor != MAKE_SALCOLOR( 0x00, 0x00, 0x80 ) // blue
662 0 : && nSalColor != MAKE_SALCOLOR( 0x00, 0x80, 0x00 ) // green
663 0 : && nSalColor != MAKE_SALCOLOR( 0x00, 0x80, 0x80 ) // cyan
664 0 : && nSalColor != MAKE_SALCOLOR( 0x80, 0x00, 0x00 ) // red
665 0 : && nSalColor != MAKE_SALCOLOR( 0x80, 0x00, 0x80 ) // magenta
666 0 : && nSalColor != MAKE_SALCOLOR( 0x80, 0x80, 0x00 ) // brown
667 0 : && nSalColor != MAKE_SALCOLOR( 0x80, 0x80, 0x80 ) // gray
668 0 : && nSalColor != MAKE_SALCOLOR( 0xC0, 0xC0, 0xC0 ) // light gray
669 0 : && nSalColor != MAKE_SALCOLOR( 0x00, 0x00, 0xFF ) // light blue
670 0 : && nSalColor != MAKE_SALCOLOR( 0x00, 0xFF, 0x00 ) // light green
671 0 : && nSalColor != MAKE_SALCOLOR( 0x00, 0xFF, 0xFF ) // light cyan
672 0 : && nSalColor != MAKE_SALCOLOR( 0xFF, 0x00, 0x00 ) // light red
673 0 : && nSalColor != MAKE_SALCOLOR( 0xFF, 0x00, 0xFF ) // light magenta
674 0 : && nSalColor != MAKE_SALCOLOR( 0xFF, 0xFF, 0x00 ) // light brown
675 0 : && nSalColor != MAKE_SALCOLOR( 0xFF, 0xFF, 0xFF ) )
676 0 : bDitherBrush_ = GetDitherPixmap(nSalColor);
677 0 : bBrushGC_ = sal_False;
678 : }
679 0 : }
680 :
681 0 : void X11SalGraphics::SetROPLineColor( SalROPColor nROPColor )
682 : {
683 0 : switch( nROPColor )
684 : {
685 : case SAL_ROP_0 : // 0
686 0 : nPenPixel_ = (Pixel)0;
687 0 : break;
688 : case SAL_ROP_1 : // 1
689 0 : nPenPixel_ = (Pixel)(1 << GetVisual().GetDepth()) - 1;
690 0 : break;
691 : case SAL_ROP_INVERT : // 2
692 0 : nPenPixel_ = (Pixel)(1 << GetVisual().GetDepth()) - 1;
693 0 : break;
694 : }
695 0 : nPenColor_ = GetColormap().GetColor( nPenPixel_ );
696 0 : bPenGC_ = sal_False;
697 0 : }
698 :
699 0 : void X11SalGraphics::SetROPFillColor( SalROPColor nROPColor )
700 : {
701 0 : switch( nROPColor )
702 : {
703 : case SAL_ROP_0 : // 0
704 0 : nBrushPixel_ = (Pixel)0;
705 0 : break;
706 : case SAL_ROP_1 : // 1
707 0 : nBrushPixel_ = (Pixel)(1 << GetVisual().GetDepth()) - 1;
708 0 : break;
709 : case SAL_ROP_INVERT : // 2
710 0 : nBrushPixel_ = (Pixel)(1 << GetVisual().GetDepth()) - 1;
711 0 : break;
712 : }
713 0 : bDitherBrush_ = sal_False;
714 0 : nBrushColor_ = GetColormap().GetColor( nBrushPixel_ );
715 0 : bBrushGC_ = sal_False;
716 0 : }
717 :
718 0 : void X11SalGraphics::SetXORMode( bool bSet, bool )
719 : {
720 0 : if( !bXORMode_ == bSet )
721 : {
722 0 : bXORMode_ = bSet;
723 0 : bPenGC_ = sal_False;
724 0 : bFontGC_ = sal_False;
725 0 : bBrushGC_ = sal_False;
726 0 : bMonoGC_ = sal_False;
727 0 : bCopyGC_ = sal_False;
728 0 : bInvertGC_ = sal_False;
729 0 : bInvert50GC_ = sal_False;
730 0 : bStippleGC_ = sal_False;
731 0 : bTrackingGC_ = sal_False;
732 : }
733 0 : }
734 :
735 0 : void X11SalGraphics::drawPixel( long nX, long nY )
736 : {
737 0 : if( nPenColor_ != SALCOLOR_NONE )
738 0 : XDrawPoint( GetXDisplay(), GetDrawable(), SelectPen(), nX, nY );
739 0 : }
740 :
741 0 : void X11SalGraphics::drawPixel( long nX, long nY, SalColor nSalColor )
742 : {
743 0 : if( nSalColor != SALCOLOR_NONE )
744 : {
745 0 : Display *pDisplay = GetXDisplay();
746 :
747 0 : if( (nPenColor_ == SALCOLOR_NONE) && !bPenGC_ )
748 : {
749 0 : SetLineColor( nSalColor );
750 0 : XDrawPoint( pDisplay, GetDrawable(), SelectPen(), nX, nY );
751 0 : nPenColor_ = SALCOLOR_NONE;
752 0 : bPenGC_ = False;
753 : }
754 : else
755 : {
756 0 : GC pGC = SelectPen();
757 :
758 0 : if( nSalColor != nPenColor_ )
759 0 : XSetForeground( pDisplay, pGC, GetPixel( nSalColor ) );
760 :
761 0 : XDrawPoint( pDisplay, GetDrawable(), pGC, nX, nY );
762 :
763 0 : if( nSalColor != nPenColor_ )
764 0 : XSetForeground( pDisplay, pGC, nPenPixel_ );
765 : }
766 : }
767 0 : }
768 :
769 0 : void X11SalGraphics::drawLine( long nX1, long nY1, long nX2, long nY2 )
770 : {
771 0 : if( nPenColor_ != SALCOLOR_NONE )
772 : {
773 0 : if ( GetDisplay()->GetProperties() & PROPERTY_BUG_DrawLine )
774 : {
775 0 : GC aGC = SelectPen();
776 0 : XDrawPoint (GetXDisplay(), GetDrawable(), aGC, (int)nX1, (int)nY1);
777 0 : XDrawPoint (GetXDisplay(), GetDrawable(), aGC, (int)nX2, (int)nY2);
778 0 : XDrawLine (GetXDisplay(), GetDrawable(), aGC, nX1, nY1, nX2, nY2 );
779 : }
780 : else
781 : XDrawLine( GetXDisplay(), GetDrawable(),SelectPen(),
782 0 : nX1, nY1, nX2, nY2 );
783 : }
784 0 : }
785 :
786 0 : void X11SalGraphics::drawRect( long nX, long nY, long nDX, long nDY )
787 : {
788 0 : if( nBrushColor_ != SALCOLOR_NONE )
789 : {
790 : XFillRectangle( GetXDisplay(),
791 : GetDrawable(),
792 : SelectBrush(),
793 0 : nX, nY, nDX, nDY );
794 : }
795 : // description DrawRect is wrong; thus -1
796 0 : if( nPenColor_ != SALCOLOR_NONE )
797 : XDrawRectangle( GetXDisplay(),
798 : GetDrawable(),
799 : SelectPen(),
800 0 : nX, nY, nDX-1, nDY-1 );
801 0 : }
802 :
803 0 : void X11SalGraphics::drawPolyLine( sal_uLong nPoints, const SalPoint *pPtAry )
804 : {
805 0 : drawPolyLine( nPoints, pPtAry, false );
806 0 : }
807 :
808 0 : void X11SalGraphics::drawPolyLine( sal_uLong nPoints, const SalPoint *pPtAry, bool bClose )
809 : {
810 0 : if( nPenColor_ != SALCOLOR_NONE )
811 : {
812 0 : SalPolyLine Points( nPoints, pPtAry );
813 :
814 0 : DrawLines( nPoints, Points, SelectPen(), bClose );
815 : }
816 0 : }
817 :
818 0 : void X11SalGraphics::drawPolygon( sal_uLong nPoints, const SalPoint* pPtAry )
819 : {
820 0 : if( nPoints == 0 )
821 0 : return;
822 :
823 0 : if( nPoints < 3 )
824 : {
825 0 : if( !bXORMode_ )
826 : {
827 0 : if( 1 == nPoints )
828 0 : drawPixel( pPtAry[0].mnX, pPtAry[0].mnY );
829 : else
830 : drawLine( pPtAry[0].mnX, pPtAry[0].mnY,
831 0 : pPtAry[1].mnX, pPtAry[1].mnY );
832 : }
833 0 : return;
834 : }
835 :
836 0 : SalPolyLine Points( nPoints, pPtAry );
837 :
838 0 : nPoints++;
839 :
840 : /* WORKAROUND: some Xservers (Xorg, VIA chipset in this case)
841 : * do not draw the visible part of a polygon
842 : * if it overlaps to the left of screen 0,y.
843 : * This happens to be the case in the gradient drawn in the
844 : * menubar background. workaround for the special case of
845 : * of a rectangle overlapping to the left.
846 : */
847 0 : if( nPoints == 5 &&
848 0 : Points[ 0 ].x == Points[ 1 ].x &&
849 0 : Points[ 1 ].y == Points[ 2 ].y &&
850 0 : Points[ 2 ].x == Points[ 3 ].x &&
851 0 : Points[ 0 ].x == Points[ 4 ].x && Points[ 0 ].y == Points[ 4 ].y
852 : )
853 : {
854 0 : bool bLeft = false;
855 0 : bool bRight = false;
856 0 : for(unsigned int i = 0; i < nPoints; i++ )
857 : {
858 0 : if( Points[i].x < 0 )
859 0 : bLeft = true;
860 : else
861 0 : bRight= true;
862 : }
863 0 : if( bLeft && ! bRight )
864 0 : return;
865 0 : if( bLeft && bRight )
866 : {
867 0 : for( unsigned int i = 0; i < nPoints; i++ )
868 0 : if( Points[i].x < 0 )
869 0 : Points[i].x = 0;
870 : }
871 : }
872 :
873 0 : if( nBrushColor_ != SALCOLOR_NONE )
874 : XFillPolygon( GetXDisplay(),
875 : GetDrawable(),
876 : SelectBrush(),
877 0 : &Points[0], nPoints,
878 0 : Complex, CoordModeOrigin );
879 :
880 0 : if( nPenColor_ != SALCOLOR_NONE )
881 0 : DrawLines( nPoints, Points, SelectPen(), true );
882 : }
883 :
884 0 : void X11SalGraphics::drawPolyPolygon( sal_uInt32 nPoly,
885 : const sal_uInt32 *pPoints,
886 : PCONSTSALPOINT *pPtAry )
887 : {
888 0 : if( nBrushColor_ != SALCOLOR_NONE )
889 : {
890 : sal_uInt32 i, n;
891 0 : XLIB_Region pXRegA = NULL;
892 :
893 0 : for( i = 0; i < nPoly; i++ ) {
894 0 : n = pPoints[i];
895 0 : SalPolyLine Points( n, pPtAry[i] );
896 0 : if( n > 2 )
897 : {
898 0 : XLIB_Region pXRegB = XPolygonRegion( &Points[0], n+1, WindingRule );
899 0 : if( !pXRegA )
900 0 : pXRegA = pXRegB;
901 : else
902 : {
903 0 : XXorRegion( pXRegA, pXRegB, pXRegA );
904 0 : XDestroyRegion( pXRegB );
905 : }
906 : }
907 0 : }
908 :
909 0 : if( pXRegA )
910 : {
911 : XRectangle aXRect;
912 0 : XClipBox( pXRegA, &aXRect );
913 :
914 0 : GC pGC = SelectBrush();
915 0 : SetClipRegion( pGC, pXRegA ); // ??? twice
916 0 : XDestroyRegion( pXRegA );
917 0 : bBrushGC_ = sal_False;
918 :
919 : XFillRectangle( GetXDisplay(),
920 : GetDrawable(),
921 : pGC,
922 0 : aXRect.x, aXRect.y, aXRect.width, aXRect.height );
923 : }
924 : }
925 :
926 0 : if( nPenColor_ != SALCOLOR_NONE )
927 0 : for( sal_uInt32 i = 0; i < nPoly; i++ )
928 0 : drawPolyLine( pPoints[i], pPtAry[i], true );
929 0 : }
930 :
931 0 : sal_Bool X11SalGraphics::drawPolyLineBezier( sal_uLong, const SalPoint*, const BYTE* )
932 : {
933 0 : return sal_False;
934 : }
935 :
936 0 : sal_Bool X11SalGraphics::drawPolygonBezier( sal_uLong, const SalPoint*, const BYTE* )
937 : {
938 0 : return sal_False;
939 : }
940 :
941 0 : sal_Bool X11SalGraphics::drawPolyPolygonBezier( sal_uInt32, const sal_uInt32*,
942 : const SalPoint* const*, const BYTE* const* )
943 : {
944 0 : return sal_False;
945 : }
946 :
947 0 : void X11SalGraphics::invert( sal_uLong nPoints,
948 : const SalPoint* pPtAry,
949 : SalInvert nFlags )
950 : {
951 0 : SalPolyLine Points ( nPoints, pPtAry );
952 :
953 : GC pGC;
954 0 : if( SAL_INVERT_50 & nFlags )
955 0 : pGC = GetInvert50GC();
956 : else
957 0 : if ( SAL_INVERT_TRACKFRAME & nFlags )
958 0 : pGC = GetTrackingGC();
959 : else
960 0 : pGC = GetInvertGC();
961 :
962 0 : if( SAL_INVERT_TRACKFRAME & nFlags )
963 0 : DrawLines ( nPoints, Points, pGC, true );
964 : else
965 : XFillPolygon( GetXDisplay(),
966 : GetDrawable(),
967 : pGC,
968 0 : &Points[0], nPoints,
969 0 : Complex, CoordModeOrigin );
970 0 : }
971 :
972 0 : BOOL X11SalGraphics::drawEPS( long,long,long,long,void*,sal_uLong )
973 : {
974 0 : return sal_False;
975 : }
976 :
977 0 : XID X11SalGraphics::GetXRenderPicture()
978 : {
979 0 : XRenderPeer& rRenderPeer = XRenderPeer::GetInstance();
980 :
981 0 : if( !m_aXRenderPicture )
982 : {
983 : // check xrender support for matching visual
984 0 : XRenderPictFormat* pXRenderFormat = GetXRenderFormat();
985 0 : if( !pXRenderFormat )
986 0 : return 0;
987 : // get the matching xrender target for drawable
988 0 : m_aXRenderPicture = rRenderPeer.CreatePicture( hDrawable_, pXRenderFormat, 0, NULL );
989 : }
990 :
991 : {
992 : // reset clip region
993 : // TODO: avoid clip reset if already done
994 : XRenderPictureAttributes aAttr;
995 0 : aAttr.clip_mask = None;
996 0 : rRenderPeer.ChangePicture( m_aXRenderPicture, CPClipMask, &aAttr );
997 : }
998 :
999 0 : return m_aXRenderPicture;
1000 : }
1001 :
1002 0 : XRenderPictFormat* X11SalGraphics::GetXRenderFormat() const
1003 : {
1004 0 : if( m_pXRenderFormat == NULL )
1005 0 : m_pXRenderFormat = XRenderPeer::GetInstance().FindVisualFormat( GetVisual().visual );
1006 0 : return m_pXRenderFormat;
1007 : }
1008 :
1009 0 : SystemGraphicsData X11SalGraphics::GetGraphicsData() const
1010 : {
1011 0 : SystemGraphicsData aRes;
1012 :
1013 0 : aRes.nSize = sizeof(aRes);
1014 0 : aRes.pDisplay = GetXDisplay();
1015 0 : aRes.hDrawable = hDrawable_;
1016 0 : aRes.pVisual = GetVisual().visual;
1017 0 : aRes.nScreen = m_nXScreen.getXScreen();
1018 0 : aRes.nDepth = GetBitCount();
1019 0 : aRes.aColormap = GetColormap().GetXColormap();
1020 0 : aRes.pXRenderFormat = m_pXRenderFormat;
1021 0 : return aRes;
1022 : }
1023 :
1024 : // draw a poly-polygon
1025 0 : bool X11SalGraphics::drawPolyPolygon( const ::basegfx::B2DPolyPolygon& rOrigPolyPoly, double fTransparency )
1026 : {
1027 : // nothing to do for empty polypolygons
1028 0 : const int nOrigPolyCount = rOrigPolyPoly.count();
1029 0 : if( nOrigPolyCount <= 0 )
1030 0 : return sal_True;
1031 :
1032 : // nothing to do if everything is transparent
1033 0 : if( (nBrushColor_ == SALCOLOR_NONE)
1034 0 : && (nPenColor_ == SALCOLOR_NONE) )
1035 0 : return sal_True;
1036 :
1037 : // cannot handle pencolor!=brushcolor yet
1038 0 : if( (nPenColor_ != SALCOLOR_NONE)
1039 0 : && (nPenColor_ != nBrushColor_) )
1040 0 : return sal_False;
1041 :
1042 : // TODO: remove the env-variable when no longer needed
1043 0 : static const char* pRenderEnv = getenv( "SAL_DISABLE_RENDER_POLY" );
1044 0 : if( pRenderEnv )
1045 0 : return sal_False;
1046 :
1047 : // snap to raster if requested
1048 0 : basegfx::B2DPolyPolygon aPolyPoly = rOrigPolyPoly;
1049 0 : const bool bSnapToRaster = !getAntiAliasB2DDraw();
1050 0 : if( bSnapToRaster )
1051 0 : aPolyPoly = basegfx::tools::snapPointsOfHorizontalOrVerticalEdges( aPolyPoly );
1052 :
1053 : // don't bother with polygons outside of visible area
1054 0 : const basegfx::B2DRange aViewRange( 0, 0, GetGraphicsWidth(), GetGraphicsHeight() );
1055 0 : aPolyPoly = basegfx::tools::clipPolyPolygonOnRange( aPolyPoly, aViewRange, true, false );
1056 0 : if( !aPolyPoly.count() )
1057 0 : return true;
1058 :
1059 : // tesselate the polypolygon into trapezoids
1060 0 : basegfx::B2DTrapezoidVector aB2DTrapVector;
1061 0 : basegfx::tools::trapezoidSubdivide( aB2DTrapVector, aPolyPoly );
1062 0 : const int nTrapCount = aB2DTrapVector.size();
1063 0 : if( !nTrapCount )
1064 0 : return true;
1065 0 : const bool bDrawn = drawFilledTrapezoids( &aB2DTrapVector[0], nTrapCount, fTransparency );
1066 0 : return bDrawn;
1067 : }
1068 :
1069 0 : bool X11SalGraphics::drawFilledTrapezoids( const ::basegfx::B2DTrapezoid* pB2DTraps, int nTrapCount, double fTransparency )
1070 : {
1071 0 : if( nTrapCount <= 0 )
1072 0 : return true;
1073 :
1074 0 : Picture aDstPic = GetXRenderPicture();
1075 : // check xrender support for this drawable
1076 0 : if( !aDstPic )
1077 0 : return false;
1078 :
1079 : // convert the B2DTrapezoids into XRender-Trapezoids
1080 : typedef std::vector<XTrapezoid> TrapezoidVector;
1081 0 : TrapezoidVector aTrapVector( nTrapCount );
1082 0 : const basegfx::B2DTrapezoid* pB2DTrap = pB2DTraps;
1083 0 : for( int i = 0; i < nTrapCount; ++pB2DTrap, ++i )
1084 : {
1085 0 : XTrapezoid& rTrap = aTrapVector[ i ] ;
1086 :
1087 : // set y-coordinates
1088 0 : const double fY1 = pB2DTrap->getTopY();
1089 0 : rTrap.left.p1.y = rTrap.right.p1.y = rTrap.top = XDoubleToFixed( fY1 );
1090 0 : const double fY2 = pB2DTrap->getBottomY();
1091 0 : rTrap.left.p2.y = rTrap.right.p2.y = rTrap.bottom = XDoubleToFixed( fY2 );
1092 :
1093 : // set x-coordinates
1094 0 : const double fXL1 = pB2DTrap->getTopXLeft();
1095 0 : rTrap.left.p1.x = XDoubleToFixed( fXL1 );
1096 0 : const double fXR1 = pB2DTrap->getTopXRight();
1097 0 : rTrap.right.p1.x = XDoubleToFixed( fXR1 );
1098 0 : const double fXL2 = pB2DTrap->getBottomXLeft();
1099 0 : rTrap.left.p2.x = XDoubleToFixed( fXL2 );
1100 0 : const double fXR2 = pB2DTrap->getBottomXRight();
1101 0 : rTrap.right.p2.x = XDoubleToFixed( fXR2 );
1102 : }
1103 :
1104 : // get xrender Picture for polygon foreground
1105 : // TODO: cache it like the target picture which uses GetXRenderPicture()
1106 0 : XRenderPeer& rRenderPeer = XRenderPeer::GetInstance();
1107 0 : SalDisplay::RenderEntry& rEntry = GetDisplay()->GetRenderEntries( m_nXScreen )[ 32 ];
1108 0 : if( !rEntry.m_aPicture )
1109 : {
1110 0 : Display* pXDisplay = GetXDisplay();
1111 :
1112 0 : rEntry.m_aPixmap = limitXCreatePixmap( pXDisplay, hDrawable_, 1, 1, 32 );
1113 : XRenderPictureAttributes aAttr;
1114 0 : aAttr.repeat = true;
1115 :
1116 0 : XRenderPictFormat* pXRPF = rRenderPeer.FindStandardFormat( PictStandardARGB32 );
1117 0 : rEntry.m_aPicture = rRenderPeer.CreatePicture( rEntry.m_aPixmap, pXRPF, CPRepeat, &aAttr );
1118 : }
1119 :
1120 : // set polygon foreground color and opacity
1121 0 : XRenderColor aRenderColor = GetXRenderColor( nBrushColor_ , fTransparency );
1122 0 : rRenderPeer.FillRectangle( PictOpSrc, rEntry.m_aPicture, &aRenderColor, 0, 0, 1, 1 );
1123 :
1124 : // set clipping
1125 : // TODO: move into GetXRenderPicture?
1126 0 : if( mpClipRegion && !XEmptyRegion( mpClipRegion ) )
1127 0 : rRenderPeer.SetPictureClipRegion( aDstPic, mpClipRegion );
1128 :
1129 : // render the trapezoids
1130 0 : const XRenderPictFormat* pMaskFormat = rRenderPeer.GetStandardFormatA8();
1131 : rRenderPeer.CompositeTrapezoids( PictOpOver,
1132 0 : rEntry.m_aPicture, aDstPic, pMaskFormat, 0, 0, &aTrapVector[0], aTrapVector.size() );
1133 :
1134 0 : return true;
1135 : }
1136 :
1137 0 : bool X11SalGraphics::drawPolyLine(
1138 : const ::basegfx::B2DPolygon& rPolygon,
1139 : double fTransparency,
1140 : const ::basegfx::B2DVector& rLineWidth,
1141 : basegfx::B2DLineJoin eLineJoin,
1142 : com::sun::star::drawing::LineCap eLineCap)
1143 : {
1144 0 : const bool bIsHairline = (rLineWidth.getX() == rLineWidth.getY()) && (rLineWidth.getX() <= 1.2);
1145 :
1146 : // #i101491#
1147 0 : if( !bIsHairline && (rPolygon.count() > 1000) )
1148 : {
1149 : // the used basegfx::tools::createAreaGeometry is simply too
1150 : // expensive with very big polygons; fallback to caller (who
1151 : // should use ImplLineConverter normally)
1152 : // AW: ImplLineConverter had to be removed since it does not even
1153 : // know LineJoins, so the fallback will now prepare the line geometry
1154 : // the same way.
1155 0 : return false;
1156 : }
1157 :
1158 : // temporarily adjust brush color to pen color
1159 : // since the line is drawn as an area-polygon
1160 0 : const SalColor aKeepBrushColor = nBrushColor_;
1161 0 : nBrushColor_ = nPenColor_;
1162 :
1163 : // #i11575#desc5#b adjust B2D tesselation result to raster positions
1164 0 : basegfx::B2DPolygon aPolygon = rPolygon;
1165 0 : const double fHalfWidth = 0.5 * rLineWidth.getX();
1166 :
1167 : // #i122456# This is probably thought to happen to align hairlines to pixel positions, so
1168 : // it should be a 0.5 translation, not more. It will definitely go wrong with fat lines
1169 0 : aPolygon.transform( basegfx::tools::createTranslateB2DHomMatrix(0.5, 0.5) );
1170 :
1171 : // shortcut for hairline drawing to improve performance
1172 0 : bool bDrawnOk = true;
1173 0 : if( bIsHairline )
1174 : {
1175 : // hairlines can benefit from a simplified tesselation
1176 : // e.g. for hairlines the linejoin style can be ignored
1177 0 : basegfx::B2DTrapezoidVector aB2DTrapVector;
1178 0 : basegfx::tools::createLineTrapezoidFromB2DPolygon( aB2DTrapVector, aPolygon, rLineWidth.getX() );
1179 :
1180 : // draw tesselation result
1181 0 : const int nTrapCount = aB2DTrapVector.size();
1182 0 : if( nTrapCount > 0 )
1183 0 : bDrawnOk = drawFilledTrapezoids( &aB2DTrapVector[0], nTrapCount, fTransparency );
1184 :
1185 : // restore the original brush GC
1186 0 : nBrushColor_ = aKeepBrushColor;
1187 0 : return bDrawnOk;
1188 : }
1189 :
1190 : // get the area polygon for the line polygon
1191 0 : if( (rLineWidth.getX() != rLineWidth.getY())
1192 0 : && !basegfx::fTools::equalZero( rLineWidth.getY() ) )
1193 : {
1194 : // prepare for createAreaGeometry() with anisotropic linewidth
1195 0 : aPolygon.transform( basegfx::tools::createScaleB2DHomMatrix(1.0, rLineWidth.getX() / rLineWidth.getY()));
1196 : }
1197 :
1198 : // create the area-polygon for the line
1199 0 : const basegfx::B2DPolyPolygon aAreaPolyPoly( basegfx::tools::createAreaGeometry(aPolygon, fHalfWidth, eLineJoin, eLineCap) );
1200 :
1201 0 : if( (rLineWidth.getX() != rLineWidth.getY())
1202 0 : && !basegfx::fTools::equalZero( rLineWidth.getX() ) )
1203 : {
1204 : // postprocess createAreaGeometry() for anisotropic linewidth
1205 0 : aPolygon.transform(basegfx::tools::createScaleB2DHomMatrix(1.0, rLineWidth.getY() / rLineWidth.getX()));
1206 : }
1207 :
1208 : // draw each area polypolygon component individually
1209 : // to emulate the polypolygon winding rule "non-zero"
1210 0 : const int nPolyCount = aAreaPolyPoly.count();
1211 0 : for( int nPolyIdx = 0; nPolyIdx < nPolyCount; ++nPolyIdx )
1212 : {
1213 0 : const ::basegfx::B2DPolyPolygon aOnePoly( aAreaPolyPoly.getB2DPolygon( nPolyIdx ) );
1214 0 : bDrawnOk = drawPolyPolygon( aOnePoly, fTransparency );
1215 0 : if( !bDrawnOk )
1216 0 : break;
1217 0 : }
1218 :
1219 : // restore the original brush GC
1220 0 : nBrushColor_ = aKeepBrushColor;
1221 0 : return bDrawnOk;
1222 0 : }
1223 :
1224 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|