source: trunk/src/kernel/qpainter_pm.cpp@ 59

Last change on this file since 59 was 59, checked in by dmik, 20 years ago

Implemented alpha blending for pixmaps.
Improved blitting of masked pixmaps.

  • Property svn:keywords set to Id
File size: 65.1 KB
Line 
1/****************************************************************************
2** $Id: qpainter_pm.cpp 59 2006-01-29 19:56:21Z dmik $
3**
4** Implementation of QPainter class for OS/2
5**
6** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
7** Copyright (C) 2004 Norman ASA. Initial OS/2 Port.
8** Copyright (C) 2005 netlabs.org. Further OS/2 Development.
9**
10** This file is part of the kernel module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#include "qpainter.h"
39#include "qpaintdevicemetrics.h"
40#include "qwidget.h"
41#include "qbitmap.h"
42#include "qpixmapcache.h"
43#include "qptrlist.h"
44//@@TODO (dmik): later
45//#include "qprinter.h"
46#include <stdlib.h>
47#include <math.h>
48#include "qapplication_p.h"
49#include "qfontdata_p.h"
50#include "qt_os2.h"
51#include "qtextlayout_p.h"
52#include "qtextengine_p.h"
53#include "qfontengine_p.h"
54
55//@@TODO (dmik): does OS/2 have this bug?
56///*
57// Workaround for win32 bug. When GM_ADVANCED graphicsmode is used with a non identity
58// matrix, subsequent calls to Ellipse, Chord and Pie will be inclusive. Also after
59// graphics mode is reset to GM_COMPATIBLE. This causes ellipses to grow in size
60// after a call to drawText when the painter is transformated.
61//
62// To work around this we register if a non identity transform is set in
63// QPainter::nativeXForm() and reduce the size by one if native xform has been used.
64//
65// Testcase for confirmation is checked in in:
66// //depot/manualtests/platformbugs/win32/ellipseafteradvgrmode.cpp
67//*/
68
69// QRgb has the same RGB format (0xaarrggbb) as OS/2 uses (ignoring the
70// highest alpha byte) so we just mask alpha to get the valid OS/2 color.
71#define COLOR_VALUE(c) ((flags & RGBColor) ? (c.rgb() & RGB_MASK) : c.pixel())
72
73//@@TODO (dmik): Innotek GCC 3.2.2 beta 4 CSD1 lacks this function in
74// its version of the toolkit header. This should be fixed soon.
75#if defined(Q_CC_GNU) && !defined(USE_OS2_TOOLKIT_HEADERS)
76extern "C" LONG APIENTRY GpiQueryNearestPaletteIndex(HPAL hpal, ULONG color);
77#endif
78
79// this function fixes a bug in OS/2 GPI: GpiSetBackColor() doesn't
80// change the background color attribute of line primitives.
81BOOL qt_GpiSetBackColor( HPS hps, LONG color )
82{
83 BOOL rc = FALSE;
84 rc = GpiSetBackColor( hps, color );
85 LINEBUNDLE lb;
86 lb.lBackColor = color;
87 rc &= GpiSetAttrs( hps, PRIM_LINE, LBB_BACK_COLOR, 0, (PBUNDLE) &lb );
88 return rc;
89}
90
91// this function fixes a bug in OS/2 GPI: GpiSetBackMix() doesn't
92// change the mix color attribute of line primitives. it also takes into
93// account the current pen style.
94BOOL qt_GpiSetBackMix( HPS hps, LONG mix, BOOL noPen )
95{
96 BOOL rc = FALSE;
97 rc = GpiSetBackMix( hps, mix );
98 LINEBUNDLE lb;
99 lb.usBackMixMode = noPen ? BM_LEAVEALONE : mix;
100 rc &= GpiSetAttrs( hps, PRIM_LINE, LBB_BACK_MIX_MODE, 0, (PBUNDLE) &lb );
101 return rc;
102}
103
104// helper function to select clip regions to the hps
105void qt_GpiSetClipRegion( HPS hps, HRGN hrgn, int devh, HRGN *hrgnOldRet )
106{
107 if ( hrgn ) {
108 // convert region y coordinates from Qt to GPI (see qregion_pm.cpp)
109 if ( devh ) {
110 POINTL ptl = { 0, devh };
111 GpiOffsetRegion( hps, hrgn, &ptl );
112 }
113 }
114 HRGN hrgnOld;
115 GpiSetClipRegion( hps, hrgn, &hrgnOld );
116 if ( hrgnOldRet )
117 *hrgnOldRet = hrgnOld;
118 else
119 GpiDestroyRegion( hps, hrgnOld );
120}
121
122// helpers to draw geometric width lines
123
124struct qt_geom_line_handle
125{
126 enum { AreaAttrs = ABB_COLOR | ABB_SET | ABB_SYMBOL | ABB_BACK_MIX_MODE };
127 LONG aa;
128 AREABUNDLE ab;
129};
130
131void qt_begin_geom_line( HPS hps, LONG color, BOOL noPen, qt_geom_line_handle *h )
132{
133 Q_ASSERT( h );
134 h->aa = 0;
135 GpiQueryAttrs( hps, PRIM_AREA, h->AreaAttrs, &h->ab );
136 AREABUNDLE ab;
137 if ( h->ab.lColor != color ) {
138 ab.lColor = color;
139 h->aa |= ABB_COLOR;
140 }
141 if ( h->ab.usSet != LCID_DEFAULT ) {
142 ab.usSet = LCID_DEFAULT;
143 h->aa |= ABB_SET;
144 }
145 ab.usSymbol = noPen ? PATSYM_BLANK : PATSYM_SOLID;
146 if ( h->ab.usSymbol != ab.usSymbol ) {
147 h->aa |= ABB_SYMBOL;
148 }
149 if ( noPen && h->ab.usBackMixMode != BM_LEAVEALONE ) {
150 ab.usBackMixMode = BM_LEAVEALONE;
151 h->aa |= ABB_BACK_MIX_MODE;
152 }
153 GpiSetAttrs( hps, PRIM_AREA, h->aa, 0, &ab );
154 GpiBeginPath( hps, 1 );
155}
156
157void qt_end_geom_line( HPS hps, qt_geom_line_handle *h )
158{
159 GpiEndPath( hps );
160 GpiStrokePath( hps, 1, 0 );
161 GpiSetAttrs( hps, PRIM_AREA, h->aa, 0, &h->ab );
162}
163
164/* These functions are implemented in qapplication_pm.cpp */
165extern void qt_fill_tile( QPixmap *, const QPixmap & );
166extern void qt_draw_tiled_pixmap( HPS, int, int, int, int,
167 const QPixmap *, int, int, int );
168
169void qt_erase_background(
170 HPS hps, int x, int y, int w, int h,
171 const QColor &bg_color,
172 const QPixmap *bg_pixmap, int off_x, int off_y, int devh
173)
174{
175 if ( bg_pixmap && bg_pixmap->isNull() ) // empty background
176 return;
177 HPAL oldPal = 0;
178 if ( QColor::hPal() ) {
179 oldPal = GpiSelectPalette( hps, QColor::hPal() );
180 } else {
181 // direct RGB mode
182 GpiCreateLogColorTable( hps, 0, LCOLF_RGB, 0, 0, NULL );
183 }
184 if ( bg_pixmap ) {
185//@@TODO (dmik): don't realize why the windows code doesn't do it...
186 // normalize pixmap offsets according to x and y
187 // to ensure that the offsets are always relative to
188 // the background origin point, regardless of what x and y are.
189 off_x = (off_x + x) % bg_pixmap->width();
190 off_y = (off_y + y) % bg_pixmap->height();
191 qt_draw_tiled_pixmap( hps, x, y, w, h, bg_pixmap, off_x, off_y, devh );
192 } else {
193 // flip y coordinate
194 if ( devh )
195 y = devh - (y + h);
196 // this function should be called only with window presentation space
197 // so simply use WinFillRect instead of GpiBox.
198 RECTL rcl = { x, y, x + w, y + h };
199 WinFillRect( hps, &rcl, bg_color.pixel() );
200 }
201 if ( QColor::hPal() ) {
202 GpiSelectPalette( hps, oldPal );
203 }
204}
205
206/*****************************************************************************
207 QPainter member functions
208 *****************************************************************************/
209
210void QPainter::initialize()
211{
212}
213
214void QPainter::cleanup()
215{
216}
217
218void QPainter::destroy()
219{
220
221}
222
223void QPainter::init()
224{
225 d = 0;
226//@@TODO (dmik): later
227// hasUsedNativeXForm = FALSE;
228// usingNativeXForm = FALSE;
229 flags = IsStartingUp;
230 pdev = 0;
231 bg_col = white; // default background color
232 bg_mode = TransparentMode; // default background mode
233 rop = CopyROP; // default ROP
234 tabstops = 0; // default tabbing
235 tabarray = 0;
236 tabarraylen = 0;
237 block_ext = FALSE;
238 txop = txinv = 0;
239 ps_stack = 0;
240 wm_stack = 0;
241 hps = 0;
242//@@TODO (dmik): remove?
243// hpen = 0;
244// hbrush = 0;
245// hfont = 0;
246 holdpal = 0;
247 holdrgn = 0;
248 hbrushbm = 0;
249 pixmapBrush = nocolBrush = FALSE;
250 devh = 0;
251 pfont = 0;
252}
253
254
255void QPainter::setFont( const QFont &font )
256{
257#if defined(QT_CHECK_STATE)
258 if ( !isActive() )
259 qWarning( "QPainter::setFont: Will be reset by begin()" );
260#endif
261 if ( cfont.d != font.d || testf(VolatileDC) ) {
262 cfont = font;
263 setf(DirtyFont);
264 }
265}
266
267
268void QPainter::updateFont()
269{
270 QFont *temp = 0;
271 clearf(DirtyFont);
272 if ( testf(ExtDev) ) {
273 QPDevCmdParam param[1];
274 param[0].font = &cfont;
275 if ( !pdev->cmd( QPaintDevice::PdcSetFont, this, param ) || !hps )
276 return;
277 }
278 if ( pdev->devType() == QInternal::Printer ) {
279 //int dw = pdev->metric( QPaintDeviceMetrics::PdmWidth );
280 //int dh = pdev->metric( QPaintDeviceMetrics::PdmHeight );
281 // ### fix compat mode
282 //bool vxfScale = testf(Qt2Compat) && testf(VxF)
283 // && ( dw != ww || dw != vw || dh != wh || dh != vh );
284
285 if ( pfont ) temp = pfont;
286 pfont = new QFont( cfont.d, pdev );
287 pfont->selectTo( hps );
288 } else {
289 if ( pfont ) {
290 temp = pfont;
291 pfont = 0;
292 }
293 cfont.selectTo( hps );
294 }
295 delete temp;
296}
297
298
299void QPainter::updatePen()
300{
301 if ( testf(ExtDev) ) {
302 QPDevCmdParam param[1];
303 param[0].pen = &cpen;
304 if ( !pdev->cmd(QPaintDevice::PdcSetPen,this,param) || !hps )
305 return;
306 }
307
308 ULONG LineAttrs = LBB_COLOR | LBB_TYPE | LBB_BACK_MIX_MODE;
309 LINEBUNDLE lb;
310 lb.lColor = COLOR_VALUE( cpen.color() );
311 lb.usBackMixMode = GpiQueryBackMix( hps );
312
313 switch ( cpen.style() ) {
314 case NoPen:
315 lb.usType = LINETYPE_INVISIBLE;
316 lb.usBackMixMode = BM_LEAVEALONE;
317 break;
318 case SolidLine:
319 lb.usType = LINETYPE_SOLID;
320 break;
321 case DashLine:
322 lb.usType = LINETYPE_LONGDASH;
323 break;
324 case DotLine:
325 lb.usType = LINETYPE_DOT;
326 break;
327 case DashDotLine:
328 lb.usType = LINETYPE_DASHDOT;
329 break;
330 case DashDotDotLine:
331 lb.usType = LINETYPE_DASHDOUBLEDOT;
332 break;
333 case MPenStyle:
334#if defined(QT_CHECK_STATE)
335 qWarning("QPainter::updatePen: MPenStyle used as a value. It is a mask!");
336#endif
337 break;
338 }
339
340 if ( cpen.width() > 1 ) {
341 LineAttrs |= LBB_END;
342 switch ( cpen.capStyle() ) {
343 case SquareCap:
344 lb.usEnd = LINEEND_SQUARE;
345 break;
346 case RoundCap:
347 lb.usEnd = LINEEND_ROUND;
348 break;
349 case FlatCap:
350 lb.usEnd = LINEEND_FLAT;
351 break;
352 case MPenCapStyle:
353 LineAttrs &= ~LBB_END;
354#if defined(QT_CHECK_STATE)
355 qWarning("QPainter::updatePen: MPenCapStyle used as a value. It is a mask!");
356#endif
357 break;
358 }
359 LineAttrs |= LBB_JOIN;
360 switch ( cpen.joinStyle() ) {
361 case BevelJoin:
362 lb.usJoin = LINEJOIN_BEVEL;
363 break;
364 case RoundJoin:
365 lb.usJoin = LINEJOIN_ROUND;
366 break;
367 case MiterJoin:
368 lb.usJoin = LINEJOIN_MITRE;
369 break;
370 case MPenJoinStyle:
371 LineAttrs &= ~LBB_JOIN;
372#if defined(QT_CHECK_STATE)
373 qWarning("QPainter::updatePen: MPenJoinStyle used as a value. It is a mask!");
374#endif
375 break;
376 }
377 LineAttrs |= LBB_GEOM_WIDTH;
378 lb.lGeomWidth = cpen.width();
379 }
380 GpiSetAttrs( hps, PRIM_LINE, LineAttrs, 0, (PBUNDLE) &lb );
381 // also set the image color attribute used to draw bitmaps
382 // and char color attribute for drawing text
383 GpiSetAttrs( hps, PRIM_IMAGE, IBB_COLOR, 0, (PBUNDLE) &lb );
384 GpiSetAttrs( hps, PRIM_CHAR, CBB_COLOR, 0, (PBUNDLE) &lb );
385}
386
387void QPainter::updateBrush()
388{
389 if ( testf(ExtDev) ) {
390 QPDevCmdParam param[1];
391 param[0].brush = &cbrush;
392 if ( !pdev->cmd(QPaintDevice::PdcSetBrush,this,param) || !hps )
393 return;
394 }
395
396 AREABUNDLE ab;
397 ab.lColor = COLOR_VALUE( cbrush.data->color );
398 GpiSetAttrs( hps, PRIM_AREA, ABB_COLOR, 0, &ab );
399
400 // pattern attrs make sence for area attrs only, so we use global
401 // GpiSetPattern*() calls below (it's necessary to set them separately).
402
403 // delete the brush LCID if any
404 if ( hbrushbm ) {
405 GpiSetPatternSet( hps, LCID_DEFAULT );
406 GpiDeleteSetId( hps, LCID_QTPixmapBrush );
407 }
408
409 //@@TODO (dmik): possibly pixmapBrush is not needed, hbrushbm and
410 // CustomPattern can substitute it.
411 pixmapBrush = nocolBrush = FALSE;
412 hbrushbm = 0;
413
414 int bs = cbrush.style();
415 if ( bs == CustomPattern ) {
416 HPS hbrushps = cbrush.pixmap()->hps;
417 hbrushbm = cbrush.pixmap()->hbm();
418 pixmapBrush = TRUE;
419 nocolBrush = cbrush.pixmap()->depth() == 1;
420 GpiSetBitmap( hbrushps, 0 );
421 GpiSetBitmapId( hps, hbrushbm, LCID_QTPixmapBrush );
422 GpiSetPatternSet( hps, LCID_QTPixmapBrush );
423 GpiSetBitmap( hbrushps, hbrushbm );
424 } else {
425 LONG pat;
426 if ( bs >= Dense1Pattern && bs <= Dense7Pattern ) {
427 pat = PATSYM_DENSE2 + (bs - Dense1Pattern);
428 } else {
429 switch ( bs ) {
430 case NoBrush:
431 pat = PATSYM_BLANK;
432 break;
433 case SolidPattern:
434 pat = PATSYM_SOLID;
435 break;
436 case HorPattern:
437 pat = PATSYM_HORIZ;
438 break;
439 case VerPattern:
440 pat = PATSYM_VERT;
441 break;
442 case CrossPattern:
443 pat = PATSYM_HATCH;
444 break;
445 case BDiagPattern:
446 pat = PATSYM_DIAG1;
447 break;
448 case FDiagPattern:
449 pat = PATSYM_DIAG3;
450 break;
451 case DiagCrossPattern:
452 pat = PATSYM_DIAGHATCH;
453 break;
454 default:
455 pat = PATSYM_HORIZ;
456 }
457 }
458 nocolBrush = TRUE;
459 GpiSetPatternSet( hps, LCID_DEFAULT );
460 GpiSetPattern( hps, pat );
461 }
462}
463
464
465bool QPainter::begin( const QPaintDevice *pd, bool unclipped )
466{
467 if ( isActive() ) { // already active painting
468#if defined(QT_CHECK_STATE)
469 qWarning( "QPainter::begin: Painter is already active."
470 "\n\tYou must end() the painter before a second begin()" );
471#endif
472 return FALSE;
473 }
474 if ( pd == 0 ) {
475#if defined(QT_CHECK_NULL)
476 qWarning( "QPainter::begin: Paint device cannot be null" );
477#endif
478 return FALSE;
479 }
480
481 const QWidget *copyFrom = 0;
482 pdev = redirect( (QPaintDevice*)pd );
483 if ( pdev ) { // redirected paint device?
484 if ( pd->devType() == QInternal::Widget )
485 copyFrom = (const QWidget *)pd; // copy widget settings
486 } else {
487 pdev = (QPaintDevice*)pd;
488 }
489
490 if ( pdev->isExtDev() && pdev->paintingActive() ) { // somebody else is already painting
491#if defined(QT_CHECK_STATE)
492 qWarning( "QPainter::begin: Another QPainter is already painting "
493 "this device;\n\tAn extended paint device can only be "
494 "painted by one QPainter at a time" );
495#endif
496 return FALSE;
497 }
498
499 bool reinit = flags != IsStartingUp; // 2nd, 3rd,.... time called
500 flags = 0x0; // init flags
501 int dt = pdev->devType(); // get the device type
502
503 if ( (pdev->devFlags & QInternal::ExternalDevice) != 0 )
504 setf(ExtDev); // this is an extended device
505 if ( (pdev->devFlags & QInternal::CompatibilityMode) != 0 )
506 setf(Qt2Compat);
507 else if ( dt == QInternal::Pixmap ) { // device is a pixmap
508 QPixmap *pm = (QPixmap*) pdev; // will modify it
509 pm->detach();
510 // Ensure the auxiliary masked bitmap created for masking is destroyed
511 // (to cause it to be recreated when the pixmap is blitted next time).
512 // Also ensure the alpha channel of the pixmap is unfolded -- any GPI
513 // call will clear the high byte that may be storing the alpha bits,
514 // so the pixmap will appear as fully transparent.
515 if ( pm->data->mask )
516 pm->prepareForMasking( FALSE, TRUE );
517 if ( pm->data->hasRealAlpha )
518 pm->unfoldAlphaChannel();
519 }
520
521 hps = 0;
522 holdpal = 0;
523 holdrgn = 0;
524 devh = 0;
525
526 QRegion *pRepaintRgn = 0;
527
528 if ( testf(ExtDev) ) { // external device
529 if ( !pdev->cmd(QPaintDevice::PdcBegin,this,0) ) {
530 pdev = 0; // could not begin
531 clearf( IsActive | DirtyFont | ExtDev );
532 return FALSE;
533 }
534 if ( tabstops ) // update tabstops for device
535 setTabStops( tabstops );
536 if ( tabarray ) // update tabarray for device
537 setTabArray( tabarray );
538 }
539
540 setf( IsActive );
541 pdev->painters++; // also tell paint device
542 bro = QPoint( 0, 0 );
543 if ( reinit ) {
544 bg_mode = TransparentMode; // default background mode
545 rop = CopyROP; // default ROP
546 wxmat.reset(); // reset world xform matrix
547 xmat.reset();
548 ixmat.reset();
549 txop = txinv = 0;
550 if ( dt != QInternal::Widget ) {
551 QFont defaultFont; // default drawing tools
552 QPen defaultPen;
553 QBrush defaultBrush;
554 cfont = defaultFont; // set these drawing tools
555 cpen = defaultPen;
556 cbrush = defaultBrush;
557 bg_col = white; // default background color
558 }
559 }
560 wx = wy = vx = vy = 0; // default view origins
561 ww = 0;
562
563 if ( dt == QInternal::Widget ) { // device is a widget
564 QWidget *w = (QWidget*)pdev;
565 cfont = w->font(); // use widget font
566 cpen = QPen( w->foregroundColor() ); // use widget fg color
567 if ( reinit ) {
568 QBrush defaultBrush;
569 cbrush = defaultBrush;
570 }
571 bg_col = w->backgroundColor(); // use widget bg color
572 ww = vw = w->width(); // default view size
573 wh = vh = w->height();
574 devh = wh; // for final y coord. flipping
575 if ( !w->isDesktop() )
576 pRepaintRgn = // clip rgn passed from repaint()
577 (QRegion *) WinQueryWindowULong( w->winId(), QWL_QTCLIPRGN );
578 if ( w->testWState(Qt::WState_InPaintEvent) ) {
579 hps = w->hps; // during paint event
580 } else {
581 if ( w->isDesktop() ) {
582 hps = WinGetScreenPS( HWND_DESKTOP );
583 } else {
584 if ( unclipped || w->testWFlags( WPaintUnclipped ) ) {
585 hps = WinGetClipPS( w->winId(), 0, PSF_PARENTCLIP );
586 } else {
587 hps = WinGetPS( w->winId() );
588 }
589 }
590 w->hps = hps;
591 }
592 } else if ( dt == QInternal::Pixmap ) { // device is a pixmap
593 QPixmap *pm = (QPixmap*)pdev;
594 if ( pm->isNull() ) {
595#if defined(QT_CHECK_NULL)
596 qWarning( "QPainter::begin: Cannot paint null pixmap" );
597#endif
598 end();
599 return FALSE;
600 }
601 hps = pm->hps;
602 ww = vw = pm->width(); // default view size
603 wh = vh = pm->height();
604 devh = wh; // for final y coord. flipping
605 if ( pm->depth() == 1 ) { // monochrome pixmap
606 setf( MonoDev );
607 bg_col = color0;
608 cpen.setColor( color1 );
609 }
610//@@TODO (dmik): later
611// } else if ( dt == QInternal::Printer ) { // device is a printer
612// if ( pdev->handle() )
613// hdc = pdev->handle();
614// flags |= (NoCache | RGBColor);
615// if ( qt_winver & WV_DOS_based )
616// flags |= VolatileDC;
617 } else if ( dt == QInternal::System ) { // system-dependent device
618 hps = pdev->handle();
619 if ( hps ) {
620 SIZEL sz;
621 GpiQueryPS( hps, &sz );
622 ww = vw = sz.cx;
623 wh = vh = sz.cy;
624 }
625 }
626 if ( testf(ExtDev) ) {
627 ww = vw = pdev->metric( QPaintDeviceMetrics::PdmWidth );
628 wh = vh = pdev->metric( QPaintDeviceMetrics::PdmHeight );
629 }
630 if ( ww == 0 )
631 ww = wh = vw = vh = 1024;
632 if ( copyFrom ) { // copy redirected widget
633 cfont = copyFrom->font();
634 cpen = QPen( copyFrom->foregroundColor() );
635 bg_col = copyFrom->backgroundColor();
636 pRepaintRgn =
637 (QRegion *) WinQueryWindowULong( copyFrom->winId(), QWL_QTCLIPRGN );
638 }
639 if ( testf(ExtDev) && hps == 0 ) { // external device
640 setBackgroundColor( bg_col ); // default background color
641 setBackgroundMode( TransparentMode ); // default background mode
642 setRasterOp( CopyROP ); // default raster operation
643 }
644 if ( hps ) { // initialize hps
645 if ( QColor::hPal() && dt != QInternal::Printer ) {
646 holdpal = GpiSelectPalette( hps, QColor::hPal() );
647 } else {
648 // direct RGB mode
649 GpiCreateLogColorTable( hps, 0, LCOLF_RGB, 0, 0, NULL );
650 }
651 qt_GpiSetBackColor( hps, COLOR_VALUE( bg_col ) );
652 GpiSetMix( hps, FM_OVERPAINT );
653 qt_GpiSetBackMix( hps, BM_LEAVEALONE, cpen.style() == NoPen );
654 GpiSetTextAlignment( hps, TA_NORMAL_HORIZ, TA_BASE );
655 }
656 updatePen();
657 updateBrush();
658 setBrushOrigin( 0, 0 );
659 if ( hps ) {
660 HRGN hrgn = 0;
661 if ( pRepaintRgn ) {
662 // make a shallow copy (for the case if the QWL_QTCLIPRGN pointer
663 // will become invalid -- it should not ever happen though)
664 repaintRgn = *pRepaintRgn;
665 QRegion rgn = repaintRgn;
666 // clip region in OS/2 cannot be used for anything else, make a deep copy
667 rgn.detach();
668 hrgn = rgn.handle();
669 // prevent QRegion's destructor from destroying the region handle
670 // (qt_GpiSetClipRegion does the job)
671 rgn.data->rgn = 0;
672 }
673 qt_GpiSetClipRegion( hps, hrgn, devh, &holdrgn );
674 } else {
675 holdrgn = HRGN_ERROR;
676 }
677 setf(DirtyFont);
678
679 return TRUE;
680}
681
682bool QPainter::end()
683{
684 if ( !isActive() ) {
685#if defined(QT_CHECK_STATE)
686 qWarning( "QPainter::end: Missing begin() or begin() failed" );
687#endif
688 return FALSE;
689 }
690
691 killPStack();
692
693 // delete the brush LCID if any
694 if ( hbrushbm ) {
695 GpiSetPatternSet( hps, LCID_DEFAULT );
696 GpiDeleteSetId( hps, LCID_QTPixmapBrush );
697 }
698//@@TODO (dmik): remove or set the LCID_DEFAULT font here?
699// if ( hfont ) {
700// SelectObject( hdc, stock_sysfont );
701// hfont = 0;
702// }
703 if ( holdrgn != HRGN_ERROR )
704 qt_GpiSetClipRegion( hps, holdrgn, 0, NULL );
705 if ( holdpal )
706 GpiSelectPalette( hps, holdpal );
707 if ( !pdev )
708 return FALSE;
709
710 if ( testf(ExtDev) )
711 pdev->cmd( QPaintDevice::PdcEnd, this, 0 );
712
713 if ( pdev->devType() == QInternal::Widget ) {
714 if ( !((QWidget*)pdev)->testWState(Qt::WState_InPaintEvent) ) {
715 QWidget *w = (QWidget*)pdev;
716 WinReleasePS( w->hps );
717 w->hps = 0;
718 }
719 }
720
721 if ( pfont ) {
722 delete pfont;
723 pfont = 0;
724 }
725 // cleanup printer font engines that could have been created by updateFont()
726 if( testf(ExtDev) )
727 QFontCache::instance->cleanupPrinterFonts();
728
729 flags = 0;
730 pdev->painters--;
731 pdev = 0;
732 hps = 0;
733 return TRUE;
734}
735
736void QPainter::flush(const QRegion &, CoordinateMode)
737{
738 flush();
739}
740
741void QPainter::flush()
742{
743//@@TODO (dmik): need something here?
744// GdiFlush();
745}
746
747
748void QPainter::setBackgroundColor( const QColor &c )
749{
750 if ( !isActive() ) {
751#if defined(QT_CHECK_STATE)
752 qWarning( "QPainter::setBackgroundColor: Call begin() first" );
753#endif
754 return;
755 }
756 bg_col = c;
757 if ( testf(ExtDev) ) {
758 QPDevCmdParam param[1];
759 param[0].color = &bg_col;
760 if ( !pdev->cmd(QPaintDevice::PdcSetBkColor,this,param) || !hps )
761 return;
762 }
763 // set the back color for all primitives
764 qt_GpiSetBackColor( hps, COLOR_VALUE(c) );
765}
766
767// background rop codes are the same as foreground according to os2tk45
768static const LONG qt_ropCodes[] = {
769 FM_OVERPAINT, // CopyROP
770 FM_OR, // OrROP
771 FM_XOR, // XorROP
772 FM_SUBTRACT, // NotAndROP
773 FM_NOTCOPYSRC, // NotCopyROP
774 FM_MERGENOTSRC, // NotOrROP
775 FM_NOTXORSRC, // NotXorROP ??
776 FM_AND, // AndROP
777 FM_INVERT, // NotROP
778 FM_ZERO, // ClearROP
779 FM_ONE, // SetROP
780 FM_LEAVEALONE, // NopROP
781 FM_MASKSRCNOT, // AndNotROP
782 FM_MERGESRCNOT, // OrNotROP
783 FM_NOTMASKSRC, // NandROP
784 FM_NOTMERGESRC // NorROP
785};
786
787void QPainter::setBackgroundMode( BGMode m )
788{
789 if ( !isActive() ) {
790#if defined(QT_CHECK_STATE)
791 qWarning( "QPainter::setBackgroundMode: Call begin() first" );
792#endif
793 return;
794 }
795 if ( m != TransparentMode && m != OpaqueMode ) {
796#if defined(QT_CHECK_RANGE)
797 qWarning( "QPainter::setBackgroundMode: Invalid mode" );
798#endif
799 return;
800 }
801 bg_mode = m;
802 if ( testf(ExtDev) ) {
803 QPDevCmdParam param[1];
804 param[0].ival = m;
805 if ( !pdev->cmd(QPaintDevice::PdcSetBkMode,this,param) || !hps )
806 return;
807 }
808 // set the back mix for all primitives
809 qt_GpiSetBackMix(
810 hps, m == TransparentMode ? BM_LEAVEALONE : qt_ropCodes[rop],
811 cpen.style() == NoPen
812 );
813}
814
815void QPainter::setRasterOp( RasterOp r )
816{
817 if ( !isActive() ) {
818#if defined(QT_CHECK_STATE)
819 qWarning( "QPainter::setRasterOp: Call begin() first" );
820#endif
821 return;
822 }
823 if ( (uint)r > LastROP ) {
824#if defined(QT_CHECK_RANGE)
825 qWarning( "QPainter::setRasterOp: Invalid ROP code" );
826#endif
827 return;
828 }
829 rop = r;
830 if ( testf(ExtDev) ) {
831 QPDevCmdParam param[1];
832 param[0].ival = r;
833 if ( !pdev->cmd(QPaintDevice::PdcSetROP,this,param) || !hps )
834 return;
835 }
836 // set the mixes for all primitives
837 GpiSetMix( hps, qt_ropCodes[r] );
838 if ( bg_mode != TransparentMode )
839 qt_GpiSetBackMix( hps, qt_ropCodes[r], cpen.style() == NoPen );
840}
841
842void QPainter::setBrushOrigin( int x, int y )
843{
844 if ( !isActive() ) {
845#if defined(QT_CHECK_STATE)
846 qWarning( "QPainter::setBrushOrigin: Call begin() first" );
847#endif
848 return;
849 }
850 bro = QPoint(x,y);
851 if ( testf(ExtDev) ) {
852 QPDevCmdParam param[1];
853 param[0].point = &bro;
854 if ( !pdev->cmd(QPaintDevice::PdcSetBrushOrigin,this,param) || !hps )
855 return;
856 }
857 POINTL ptl = { x, y };
858 // make y coordinate bottom-relative
859 if ( devh ) ptl.y = devh - ptl.y;
860 GpiSetPatternRefPoint( hps, &ptl );
861}
862
863/**
864 * Sets up a native transformation matrix on this painter.
865 * If the paint device has a defined height (i.e. it's QPixmap or
866 * QWidget), the matrix is adjusted to automatically flip the y axis
867 * (to make it increase downwards).
868 *
869 * @param assumeYNegation
870 * If true, it is assumed that all y coordinates are negated before
871 * passing them to GPI calls. This mode is useful for drawing text
872 * because font letters are already flipped by GPI when the text is drawn,
873 * so using full y axis flip would flip letters again (that is definitely
874 * unwanted).
875 */
876bool QPainter::setNativeXForm( bool assumeYNegation )
877{
878 QWMatrix mtx;
879
880 if ( testf(VxF) ) {
881 mtx.translate( vx, vy );
882 mtx.scale( 1.0*vw/ww, 1.0*vh/wh );
883 mtx.translate( -wx, -wy );
884 mtx = wxmat * mtx;
885 } else {
886 mtx = wxmat;
887 }
888
889 // Qt rotates clockwise (despite stated in QWMatrix::rotate() docs),
890 // while GPI rotates counterclockwise. Correct this by changing
891 // m12 and m21 signs and also apply optional y translation.
892
893 MATRIXLF m;
894 m.fxM11 = (FIXED) (mtx.m11() * 65536.0);
895 m.fxM12 = (FIXED) (-mtx.m12() * 65536.0);
896 m.fxM21 = (FIXED) (-mtx.m21() * 65536.0);
897 m.fxM22 = (FIXED) (mtx.m22() * 65536.0);
898 m.lM31 = (LONG) mtx.dx();
899 m.lM32 = devh && assumeYNegation ? ((LONG) -mtx.dy()) : (LONG) mtx.dy();
900 m.lM13 = m.lM23 = 0;
901
902 BOOL ok = GpiSetDefaultViewMatrix( hps, 8, &m, TRANSFORM_REPLACE );
903 if (ok && devh) {
904 // add a matrix to do automatic y flip or just to move negative
905 // y coordinates back to the viewable area
906 m.fxM11 = MAKEFIXED( 1, 0 );
907 m.fxM12 = 0;
908 m.fxM21 = 0;
909 m.fxM22 = assumeYNegation ? MAKEFIXED( 1, 0 ) : MAKEFIXED( -1, 0 );
910 m.lM31 = 0;
911 m.lM32 = devh - 1;
912 m.lM13 = m.lM23 = 0;
913 ok = GpiSetDefaultViewMatrix( hps, 8, &m, TRANSFORM_ADD );
914 }
915
916 return ok;
917}
918
919void QPainter::clearNativeXForm()
920{
921 // restore identity matrix
922 GpiSetDefaultViewMatrix( hps, 0, NULL, TRANSFORM_REPLACE );
923}
924
925void QPainter::setClipping( bool enable )
926{
927 if ( !isActive() ) {
928#if defined(QT_CHECK_STATE)
929 qWarning( "QPainter::setClipping: Will be reset by begin()" );
930#endif
931 return;
932 }
933
934 if ( !isActive() || enable == testf(ClipOn) )
935 return;
936
937 setf( ClipOn, enable );
938 if ( testf(ExtDev) ) {
939 if ( block_ext )
940 return;
941 QPDevCmdParam param[1];
942 param[0].ival = enable;
943 if ( !pdev->cmd(QPaintDevice::PdcSetClip,this,param) || !hps )
944 return;
945 }
946
947 HRGN hrgn = 0;
948 QRegion rgn;
949
950 if ( enable ) {
951 if ( !repaintRgn.isNull() )
952 rgn = crgn.intersect( repaintRgn );
953 else
954 rgn = crgn;
955#ifndef QT_NO_PRINTER
956//@@TODO (dmik): later
957// if ( pdev->devType() == QInternal::Printer ) {
958// double xscale = ((float)pdev->metric( QPaintDeviceMetrics::PdmPhysicalDpiX )) /
959// ((float)pdev->metric( QPaintDeviceMetrics::PdmDpiX ));
960// double yscale = ((float)pdev->metric( QPaintDeviceMetrics::PdmPhysicalDpiY )) /
961// ((float)pdev->metric( QPaintDeviceMetrics::PdmDpiY ));
962// double xoff = 0;
963// double yoff = 0;
964// QPrinter* printer = (QPrinter*)pdev;
965// if ( printer->fullPage() ) { // must adjust for margins
966// xoff = - GetDeviceCaps( printer->handle(), PHYSICALOFFSETX );
967// yoff = - GetDeviceCaps( printer->handle(), PHYSICALOFFSETY );
968// }
969// rgn = QWMatrix( xscale, 0, 0, yscale, xoff, yoff ) * rgn;
970// }
971#endif
972 } else {
973 if ( !repaintRgn.isNull() )
974 rgn = repaintRgn;
975 }
976
977 if ( !rgn.isNull() ) {
978 // clip region in OS/2 cannot be used for anything else, make a deep copy
979 rgn.detach();
980 hrgn = rgn.handle();
981 // prevent QRegion's destructor from destroying the region handle
982 // (qt_GpiSetClipRegion does the job)
983 rgn.data->rgn = 0;
984 }
985 qt_GpiSetClipRegion( hps, hrgn, devh, NULL );
986}
987
988
989void QPainter::setClipRect( const QRect &r, CoordinateMode m )
990{
991 QRegion rgn( r );
992 setClipRegion( rgn, m );
993}
994
995void QPainter::setClipRegion( const QRegion &rgn, CoordinateMode m )
996{
997#if defined(QT_CHECK_STATE)
998 if ( !isActive() )
999 qWarning( "QPainter::setClipRegion: Will be reset by begin()" );
1000#endif
1001 if ( m == CoordDevice )
1002 crgn = rgn;
1003 else
1004 crgn = xmat * rgn;
1005
1006 if ( testf(ExtDev) ) {
1007 if ( block_ext )
1008 return;
1009 QPDevCmdParam param[2];
1010 param[0].rgn = &rgn;
1011 param[1].ival = m;
1012 if ( !pdev->cmd(QPaintDevice::PdcSetClipRegion,this,param) || !hps )
1013 return;
1014 }
1015 clearf( ClipOn ); // be sure to update clip rgn
1016 setClipping( TRUE );
1017}
1018
1019// Note: this function does not check the array range!
1020void QPainter::drawPolyInternal(
1021 const QPointArray &a, bool close, bool winding, int index, int npoints,
1022 bool disjoint
1023)
1024{
1025 // QCOORD is a double word that is the same as POINTL members, and since
1026 // the order of xp and yp fields in the QPoint is also the same, we simply
1027 // cast QPointArray::data() to PPOINTL below.
1028
1029 if ( npoints < 0 )
1030 npoints = a.size() - index;
1031
1032 QPointArray pa = a;
1033 // flip y coordinates
1034 if ( devh ) {
1035 pa = QPointArray( npoints );
1036 for ( int i = 0; i < npoints; i++ ) {
1037 pa[i].setX( a[index+i].x() );
1038 pa[i].setY( devh - (a[index+i].y() + 1) );
1039 }
1040 index = 0;
1041 }
1042
1043 ULONG opts = winding ? BA_WINDING : BA_ALTERNATE;
1044 const PPOINTL ptls = ((PPOINTL) pa.data()) + index;
1045 if ( cpen.width() > 1 ) {
1046 if ( close ) {
1047 GpiBeginArea( hps, BA_NOBOUNDARY | opts );
1048 if ( disjoint ) {
1049 GpiPolyLineDisjoint( hps, npoints, ptls );
1050 } else {
1051 GpiMove( hps, ptls );
1052 GpiPolyLine( hps, npoints - 1, ptls + 1 );
1053 }
1054 GpiEndArea( hps );
1055 }
1056 qt_geom_line_handle gh;
1057 qt_begin_geom_line( hps, COLOR_VALUE(cpen.color()), cpen.style() == NoPen, &gh );
1058 if ( disjoint ) {
1059 GpiPolyLineDisjoint( hps, npoints, ptls );
1060 } else {
1061 GpiMove( hps, ptls );
1062 GpiPolyLine( hps, npoints - 1, ptls + 1 );
1063 }
1064 if ( close )
1065 GpiCloseFigure( hps );
1066 qt_end_geom_line( hps, &gh );
1067 } else {
1068 if ( close )
1069 GpiBeginArea( hps, BA_BOUNDARY | opts );
1070 else
1071 GpiBeginPath( hps, 1 );
1072 if ( disjoint ) {
1073 GpiPolyLineDisjoint( hps, npoints, ptls );
1074 } else {
1075 GpiMove( hps, ptls );
1076 GpiPolyLine( hps, npoints - 1, ptls + 1 );
1077 }
1078 if ( close )
1079 GpiEndArea( hps );
1080 else {
1081 GpiEndPath( hps );
1082 GpiOutlinePath( hps, 1, 0 );
1083 }
1084 }
1085}
1086
1087// angles in Qt are 1/16th of a degree, so the integer part of FIXED is
1088// angle/16 and the fixed part is (65536/16) * angle%16.
1089#define MAKEDEGREE(a16) MAKEFIXED((a16>>4), (a16<<12))
1090
1091static void doDrawArc( HPS hps, PPOINTL cptl, int first, int a, int alen )
1092{
1093 if ( first >= 0 ) {
1094 int sa, ea;
1095 for ( int i = first; i < 4; i++, cptl++ ) {
1096 sa = i * 90*16;
1097 ea = sa + 90*16;
1098 if (sa < a) sa = a;
1099 if (ea > a + alen) ea = a + alen;
1100 if (ea <= sa) break;
1101 ea -= sa;
1102 GpiPartialArc( hps, cptl, MAKEFIXED(1,0), MAKEDEGREE(sa), MAKEDEGREE(ea) );
1103 }
1104 } else {
1105 GpiPartialArc( hps, cptl, MAKEFIXED(1,0), MAKEDEGREE(a), MAKEDEGREE(alen) );
1106 }
1107}
1108
1109void QPainter::drawArcInternal(
1110 int x, int y, int w, int h, int a, int alen, ArcClose close
1111)
1112{
1113 if ( w <= 0 || h <= 0 ) {
1114 if ( w == 0 || h == 0 )
1115 return;
1116 fix_neg_rect( &x, &y, &w, &h );
1117 }
1118
1119 const int FullArc = 360*16;
1120 // correct angles
1121 if ( alen < 0 ) {
1122 a += alen;
1123 alen = -alen;
1124 }
1125 alen = QMIN( alen, FullArc );
1126 if ( a < 0 )
1127 a = FullArc - ((-a) % (FullArc));
1128 else
1129 a = a % FullArc;
1130
1131 int axr = (w - 1) / 2;
1132 int ayr = (h - 1) / 2;
1133 ARCPARAMS arcparams = { axr, ayr, 0, 0 };
1134 GpiSetArcParams( hps, &arcparams );
1135 int xc, yc;
1136 xc = x + axr;
1137 yc = y + ayr;
1138 // flip y coordinate
1139 if ( devh ) yc = devh - (yc + 1);
1140
1141 POINTL sptl = { xc, yc }, cptls [4];
1142 PPOINTL cptl = cptls;
1143 int first = -1;
1144
1145 // in order to draw arcs whose bounding reactangle has even width
1146 // and/or height we draw each quarter of the arc separately,
1147 // correspondingly moving its center point by one pixel.
1148 int extX = (w - 1) % 2;
1149 int extY = (h - 1) % 2;
1150 if ( extX != 0 || extY != 0 ) {
1151 for ( int i = 0, sa = 90*16; i < 4; i++, sa += 90*16, cptl++ ) {
1152 if ( first < 0 && sa > a )
1153 first = i;
1154 if ( first >= 0 ) {
1155 switch ( i ) {
1156 case 0: cptl->x = xc + extX; cptl->y = yc; break;
1157 case 1: cptl->x = xc; cptl->y = yc; break;
1158 case 2: cptl->x = xc; cptl->y = yc - extY; break;
1159 case 3: cptl->x = xc + extX; cptl->y = yc - extY; break;
1160 }
1161 }
1162 }
1163 cptl = cptls + first;
1164 } else {
1165 *cptl = sptl;
1166 }
1167
1168 if ( close != ClosePie ) {
1169 // set the current position to the start of the arc
1170 LONG oldMix = GpiQueryMix( hps );
1171 LONG oldType = GpiQueryLineType( hps );
1172 GpiSetMix( hps, FM_LEAVEALONE );
1173 GpiSetLineType( hps, LINETYPE_SOLID );
1174 GpiPartialArc( hps, cptl, MAKEFIXED(1,0), MAKEDEGREE(a), 0 );
1175 GpiSetLineType( hps, oldType );
1176 GpiSetMix( hps, oldMix );
1177 // cause the start point to be drawn (seems like a bug in OS/2 GPI)
1178 GpiQueryCurrentPosition( hps, &sptl );
1179 }
1180
1181 if ( cpen.width() > 1 ) {
1182 if ( close != CloseNone ) {
1183 GpiBeginArea( hps, BA_NOBOUNDARY | BA_ALTERNATE );
1184 GpiMove( hps, &sptl );
1185 doDrawArc( hps, cptl, first, a, alen );
1186 GpiEndArea( hps );
1187 }
1188 qt_geom_line_handle gh;
1189 qt_begin_geom_line( hps, COLOR_VALUE(cpen.color()), cpen.style() == NoPen, &gh );
1190
1191 GpiMove( hps, &sptl );
1192 doDrawArc( hps, cptl, first, a, alen );
1193
1194 if ( close != CloseNone )
1195 GpiCloseFigure( hps );
1196 qt_end_geom_line( hps, &gh );
1197 } else {
1198 if ( close != CloseNone )
1199 GpiBeginArea( hps, BA_BOUNDARY | BA_ALTERNATE );
1200 else
1201 GpiBeginPath( hps, 1 );
1202
1203 GpiMove( hps, &sptl );
1204 doDrawArc( hps, cptl, first, a, alen );
1205
1206 if ( close != CloseNone )
1207 GpiEndArea( hps );
1208 else {
1209 GpiEndPath( hps );
1210 GpiOutlinePath( hps, 1, 0 );
1211 }
1212 }
1213}
1214
1215void QPainter::drawPoint( int x, int y )
1216{
1217 if ( !isActive() )
1218 return;
1219 if ( testf(ExtDev|VxF|WxF) ) {
1220 if ( testf(ExtDev) ) {
1221 QPDevCmdParam param[1];
1222 QPoint p( x, y );
1223 param[0].point = &p;
1224 if ( !pdev->cmd(QPaintDevice::PdcDrawPoint,this,param) || !hps )
1225 return;
1226 }
1227 map( x, y, &x, &y );
1228 }
1229 POINTL ptl = { x, y };
1230 if ( devh ) ptl.y = devh - ( ptl.y + 1 );
1231 GpiSetPel( hps, &ptl );
1232}
1233
1234
1235void QPainter::drawPoints( const QPointArray& a, int index, int npoints )
1236{
1237 if ( npoints < 0 )
1238 npoints = a.size() - index;
1239 if ( index + npoints > (int)a.size() )
1240 npoints = a.size() - index;
1241 if ( !isActive() || npoints < 1 || index < 0 )
1242 return;
1243 QPointArray pa = a;
1244 if ( testf(ExtDev|VxF|WxF) ) {
1245 if ( testf(ExtDev) ) {
1246 QPDevCmdParam param[1];
1247 for (int i=0; i<npoints; i++) {
1248 QPoint p( pa[index+i].x(), pa[index+i].y() );
1249 param[0].point = &p;
1250 if ( !pdev->cmd(QPaintDevice::PdcDrawPoint,this,param))
1251 return;
1252 }
1253 if ( !hps ) return;
1254 }
1255 if ( txop != TxNone ) {
1256 pa = xForm( a, index, npoints );
1257 if ( pa.size() != a.size() ) {
1258 index = 0;
1259 npoints = pa.size();
1260 }
1261 }
1262 }
1263 for (int i=0; i<npoints; i++) {
1264 POINTL ptl = { pa[index+i].x(), pa[index+i].y() };
1265 if ( devh ) ptl.y = devh - ( ptl.y + 1 );
1266 GpiSetPel( hps, &ptl );
1267 }
1268}
1269
1270void QPainter::moveTo( int x, int y )
1271{
1272 if ( !isActive() )
1273 return;
1274 if ( testf(ExtDev|VxF|WxF) ) {
1275 if ( testf(ExtDev) ) {
1276 QPDevCmdParam param[1];
1277 QPoint p( x, y );
1278 param[0].point = &p;
1279 if ( !pdev->cmd(QPaintDevice::PdcMoveTo,this,param) || !hps )
1280 return;
1281 }
1282 map( x, y, &x, &y );
1283 }
1284 POINTL ptl = { x, y };
1285 if ( devh ) ptl.y = devh - ( ptl.y + 1 );
1286 GpiMove( hps, &ptl );
1287}
1288
1289
1290void QPainter::lineTo( int x, int y )
1291{
1292 if ( !isActive() )
1293 return;
1294 if ( testf(ExtDev|VxF|WxF) ) {
1295 if ( testf(ExtDev) ) {
1296 QPDevCmdParam param[1];
1297 QPoint p( x, y );
1298 param[0].point = &p;
1299 if ( !pdev->cmd(QPaintDevice::PdcLineTo,this,param) || !hps )
1300 return;
1301 }
1302 map( x, y, &x, &y );
1303 }
1304
1305 qt_geom_line_handle gh;
1306 if ( cpen.width() > 1 ) {
1307 qt_begin_geom_line( hps, COLOR_VALUE(cpen.color()), cpen.style() == NoPen, &gh );
1308 }
1309
1310 POINTL ptl = { x, y };
1311 if ( devh ) ptl.y = devh - ( ptl.y + 1 );
1312 GpiLine( hps, &ptl );
1313
1314 if ( cpen.width() > 1 ) {
1315 qt_end_geom_line( hps, &gh );
1316 }
1317//@@TODO (dmik): does OS/2 PM have the same bug?
1318// if ( (cpen.width() == 0) && (cpen.style() == SolidLine) )
1319// SetPixelV( hdc, x, y, COLOR_VALUE(cpen.color()) );
1320}
1321
1322
1323void QPainter::drawLine( int x1, int y1, int x2, int y2 )
1324{
1325 if ( !isActive() )
1326 return;
1327 if ( testf(ExtDev|VxF|WxF) ) {
1328 if ( testf(ExtDev) ) {
1329 QPDevCmdParam param[2];
1330 QPoint p1(x1, y1), p2(x2, y2);
1331 param[0].point = &p1;
1332 param[1].point = &p2;
1333 if ( !pdev->cmd(QPaintDevice::PdcDrawLine,this,param) || !hps )
1334 return;
1335 }
1336 map( x1, y1, &x1, &y1 );
1337 map( x2, y2, &x2, &y2 );
1338 }
1339
1340 qt_geom_line_handle gh;
1341 if ( cpen.width() > 1 ) {
1342 qt_begin_geom_line( hps, COLOR_VALUE(cpen.color()), cpen.style() == NoPen, &gh );
1343 }
1344
1345 POINTL ptl = { x1, y1 };
1346 if ( devh ) ptl.y = devh - (ptl.y + 1);
1347 GpiMove( hps, &ptl );
1348 ptl.x = x2;
1349 ptl.y = y2;
1350 if ( devh ) ptl.y = devh - (ptl.y + 1);
1351 GpiLine( hps, &ptl );
1352
1353 if ( cpen.width() > 1 ) {
1354 qt_end_geom_line( hps, &gh );
1355 }
1356}
1357
1358
1359void QPainter::drawRectInternal(
1360 int x, int y, int w, int h, int wRnd, int hRnd
1361) {
1362 if ( w <= 0 || h <= 0 ) {
1363 if ( w == 0 || h == 0 )
1364 return;
1365 fix_neg_rect( &x, &y, &w, &h );
1366 }
1367
1368 POINTL ptl1 = { x, y };
1369 if ( devh ) ptl1.y = devh - ( ptl1.y + h );
1370 POINTL ptl2 = { x + w - 1, ptl1.y + h - 1 };
1371
1372 if ( cpen.width() > 1 ) {
1373 GpiMove( hps, &ptl1 );
1374 GpiBox( hps, DRO_FILL, &ptl2, wRnd, hRnd );
1375 qt_geom_line_handle gh;
1376 qt_begin_geom_line( hps, COLOR_VALUE(cpen.color()), cpen.style() == NoPen, &gh );
1377 GpiMove( hps, &ptl1 );
1378 GpiBox( hps, DRO_OUTLINE, &ptl2, wRnd, hRnd );
1379 qt_end_geom_line( hps, &gh );
1380 } else {
1381 GpiMove( hps, &ptl1 );
1382 GpiBox( hps, DRO_FILL | DRO_OUTLINE, &ptl2, wRnd, hRnd );
1383 }
1384}
1385
1386void QPainter::drawRect( int x, int y, int w, int h )
1387{
1388 if ( !isActive() )
1389 return;
1390 if ( testf(ExtDev|VxF|WxF) ) {
1391 if ( testf(ExtDev) ) {
1392 QPDevCmdParam param[1];
1393 QRect r( x, y, w, h );
1394 param[0].rect = &r;
1395 if ( !pdev->cmd(QPaintDevice::PdcDrawRect,this,param) || !hps )
1396 return;
1397 }
1398 if ( txop == TxRotShear ) { // rotate/shear polygon
1399 QPointArray a( QRect(x,y,w,h) );
1400 drawPolyInternal( xForm(a) );
1401 return;
1402 }
1403 map( x, y, w, h, &x, &y, &w, &h );
1404 }
1405
1406 drawRectInternal( x, y, w, h, 0, 0 );
1407}
1408
1409void QPainter::drawWinFocusRectInternal(
1410 int x, int y, int w, int h, const QColor &bgCol, bool xormode
1411)
1412{
1413 if ( !isActive() || txop == TxRotShear )
1414 return;
1415
1416 if ( testf(ExtDev|VxF|WxF) ) {
1417 if ( testf(ExtDev) ) {
1418 QPDevCmdParam param[1];
1419 QRect r( x, y, w, h );
1420 param[0].rect = &r;
1421 if ( !pdev->cmd(QPaintDevice::PdcDrawRect,this,param) || !hps )
1422 return;
1423 }
1424 map( x, y, w, h, &x, &y, &w, &h );
1425 }
1426 if ( w <= 0 || h <= 0 ) {
1427 if ( w == 0 || h == 0 )
1428 return;
1429 fix_neg_rect( &x, &y, &w, &h );
1430 }
1431
1432 // flip y coordinate
1433 if ( devh ) y = devh - (y + h);
1434
1435 ULONG la =
1436 LBB_COLOR | LBB_MIX_MODE | LBB_BACK_MIX_MODE | LBB_TYPE;
1437 LINEBUNDLE oldLb, lb;
1438 GpiQueryAttrs( hps, PRIM_LINE, la, &oldLb );
1439 if ( !xormode ) { // black/white mode
1440 if( qGray( bgCol.rgb() ) <= 128 )
1441 lb.lColor = CLR_WHITE;
1442 else
1443 lb.lColor = CLR_BLACK;
1444 lb.usMixMode = FM_OVERPAINT;
1445 } else { // xor mode
1446 lb.lColor = CLR_TRUE;
1447 lb.usMixMode = FM_XOR;
1448 }
1449 lb.usBackMixMode = BM_LEAVEALONE;
1450 lb.usType = LINETYPE_ALTERNATE;
1451 GpiSetAttrs( hps, PRIM_LINE, la, 0, &lb );
1452
1453 POINTL ptl = { x, y };
1454 GpiMove( hps, &ptl );
1455 ptl.x += w - 1;
1456 ptl.y += h - 1;
1457 GpiBox( hps, DRO_OUTLINE, &ptl, 0, 0 );
1458
1459 GpiSetAttrs( hps, PRIM_LINE, la, 0, &oldLb );
1460}
1461
1462void QPainter::drawWinFocusRect( int x, int y, int w, int h, const QColor &bgCol )
1463{
1464 drawWinFocusRectInternal( x, y, w, h, bgCol, FALSE );
1465}
1466
1467void QPainter::drawWinFocusRect( int x, int y, int w, int h )
1468{
1469 if (
1470 pdev->devType() == QInternal::Widget &&
1471 GpiQueryClipRegion( hps )
1472 ) {
1473 // GPI bug: LINETYPE_ALTERNATE lines are drawn wrongly in XOR mode
1474 // when the clip region is set on the hps. we use doublebuffering
1475 // to avoid this.
1476 QSize ws = ((QWidget*) pdev)->size();
1477 POINTL ptls[] = { { 0, 0 }, { ws.width(), ws.height() }, { 0, 0 } };
1478 QPixmap pm( ws );
1479 GpiBitBlt( pm.hps, hps, 3, ptls, ROP_SRCCOPY, BBO_IGNORE );
1480 HPS thisHps = hps;
1481 hps = pm.hps;
1482 drawWinFocusRectInternal( x, y, w, h, bg_col, TRUE );
1483 hps = thisHps;
1484 GpiBitBlt( hps, pm.hps, 3, ptls, ROP_SRCCOPY, BBO_IGNORE );
1485 } else {
1486 drawWinFocusRectInternal( x, y, w, h, bg_col, TRUE );
1487 }
1488}
1489
1490
1491void QPainter::drawRoundRect( int x, int y, int w, int h, int xRnd, int yRnd )
1492{
1493 if ( !isActive() )
1494 return;
1495 if ( xRnd <= 0 || yRnd <= 0 ) {
1496 drawRect( x, y, w, h ); // draw normal rectangle
1497 return;
1498 }
1499 if ( xRnd >= 100 ) // fix ranges
1500 xRnd = 99;
1501 if ( yRnd >= 100 )
1502 yRnd = 99;
1503 if ( testf(ExtDev|VxF|WxF) ) {
1504 if ( testf(ExtDev) ) {
1505 QPDevCmdParam param[3];
1506 QRect r( x, y, w, h );
1507 param[0].rect = &r;
1508 param[1].ival = xRnd;
1509 param[2].ival = yRnd;
1510 if ( !pdev->cmd(QPaintDevice::PdcDrawRoundRect,this,param) || !hps)
1511 return;
1512 }
1513 if ( txop == TxRotShear ) { // rotate/shear polygon
1514 if ( w <= 0 || h <= 0 )
1515 fix_neg_rect( &x, &y, &w, &h );
1516 w--;
1517 h--;
1518 int rxx = w*xRnd/200;
1519 int ryy = h*yRnd/200;
1520 // were there overflows?
1521 if ( rxx < 0 )
1522 rxx = w/200*xRnd;
1523 if ( ryy < 0 )
1524 ryy = h/200*yRnd;
1525 int rxx2 = 2*rxx;
1526 int ryy2 = 2*ryy;
1527 QPointArray a[4];
1528 a[0].makeArc( x, y, rxx2, ryy2, 1*16*90, 16*90, xmat );
1529 a[1].makeArc( x, y+h-ryy2, rxx2, ryy2, 2*16*90, 16*90, xmat );
1530 a[2].makeArc( x+w-rxx2, y+h-ryy2, rxx2, ryy2, 3*16*90, 16*90, xmat );
1531 a[3].makeArc( x+w-rxx2, y, rxx2, ryy2, 0*16*90, 16*90, xmat );
1532 // ### is there a better way to join QPointArrays?
1533 QPointArray aa;
1534 aa.resize( a[0].size() + a[1].size() + a[2].size() + a[3].size() );
1535 uint j = 0;
1536 for ( int k=0; k<4; k++ ) {
1537 for ( uint i=0; i<a[k].size(); i++ ) {
1538 aa.setPoint( j, a[k].point(i) );
1539 j++;
1540 }
1541 }
1542 drawPolyInternal( aa );
1543 return;
1544 }
1545 map( x, y, w, h, &x, &y, &w, &h );
1546 }
1547
1548 drawRectInternal( x, y, w, h, w*xRnd/100, h*yRnd/100 );
1549}
1550
1551
1552void QPainter::drawEllipse( int x, int y, int w, int h )
1553{
1554 if ( !isActive() )
1555 return;
1556 if ( testf(ExtDev|VxF|WxF) ) {
1557 if ( testf(ExtDev) ) {
1558 QPDevCmdParam param[1];
1559 QRect r( x, y, w, h );
1560 param[0].rect = &r;
1561 if ( !pdev->cmd(QPaintDevice::PdcDrawEllipse,this,param) || !hps )
1562 return;
1563 }
1564 if ( txop == TxRotShear ) { // rotate/shear polygon
1565 QPointArray a;
1566 int increment = cpen.style() == NoPen ? 1 : 0;
1567 a.makeArc( x, y, w+increment, h+increment, 0, 360*16, xmat );
1568 drawPolyInternal( a );
1569 return;
1570 }
1571 map( x, y, w, h, &x, &y, &w, &h );
1572 }
1573
1574 drawArcInternal( x, y, w, h );
1575}
1576
1577
1578void QPainter::drawArc( int x, int y, int w, int h, int a, int alen )
1579{
1580 if ( !isActive() )
1581 return;
1582 if ( testf(ExtDev|VxF|WxF) ) {
1583 if ( testf(ExtDev) ) {
1584 QPDevCmdParam param[3];
1585 QRect r( x, y, w, h );
1586 param[0].rect = &r;
1587 param[1].ival = a;
1588 param[2].ival = alen;
1589 if ( !pdev->cmd(QPaintDevice::PdcDrawArc,this,param) || !hps )
1590 return;
1591 }
1592 if ( txop == TxRotShear ) { // rotate/shear
1593 QPointArray pa;
1594 pa.makeArc( x, y, w, h, a, alen, xmat ); // arc polyline
1595 drawPolyInternal( pa, FALSE );
1596 return;
1597 }
1598 map( x, y, w, h, &x, &y, &w, &h );
1599 }
1600
1601 drawArcInternal( x, y, w, h, a, alen, CloseNone );
1602}
1603
1604
1605void QPainter::drawPie( int x, int y, int w, int h, int a, int alen )
1606{
1607 if ( !isActive() )
1608 return;
1609 if ( testf(ExtDev|VxF|WxF) ) {
1610 if ( testf(ExtDev) ) {
1611 QPDevCmdParam param[3];
1612 QRect r( x, y, w, h );
1613 param[0].rect = &r;
1614 param[1].ival = a;
1615 param[2].ival = alen;
1616 if ( !pdev->cmd(QPaintDevice::PdcDrawPie,this,param) || !hps )
1617 return;
1618 }
1619 if ( txop == TxRotShear ) { // rotate/shear
1620 QPointArray pa;
1621 int increment = cpen.style() == NoPen ? 1 : 0;
1622 pa.makeArc( x, y, w+increment, h+increment, a, alen, xmat ); // arc polyline
1623 int n = pa.size();
1624 int cx, cy;
1625 xmat.map(x+w/2, y+h/2, &cx, &cy);
1626 pa.resize( n+1 );
1627 pa.setPoint( n, cx, cy ); // add legs
1628 drawPolyInternal( pa );
1629 return;
1630 }
1631 map( x, y, w, h, &x, &y, &w, &h );
1632 }
1633
1634 drawArcInternal( x, y, w, h, a, alen, ClosePie );
1635}
1636
1637
1638void QPainter::drawChord( int x, int y, int w, int h, int a, int alen )
1639{
1640 if ( !isActive() )
1641 return;
1642 if ( testf(ExtDev|VxF|WxF) ) {
1643 if ( testf(ExtDev) ) {
1644 QPDevCmdParam param[3];
1645 QRect r( x, y, w, h );
1646 param[0].rect = &r;
1647 param[1].ival = a;
1648 param[2].ival = alen;
1649 if ( !pdev->cmd(QPaintDevice::PdcDrawChord,this,param) || !hps )
1650 return;
1651 }
1652 if ( txop == TxRotShear ) { // rotate/shear
1653 QPointArray pa;
1654 int increment = cpen.style() == NoPen ? 1 : 0;
1655 pa.makeArc( x, y, w+increment, h+increment, a, alen, xmat ); // arc polygon
1656 int n = pa.size();
1657 pa.resize( n+1 );
1658 pa.setPoint( n, pa.at(0) ); // connect endpoints
1659 drawPolyInternal( pa );
1660 return;
1661 }
1662 map( x, y, w, h, &x, &y, &w, &h );
1663 }
1664
1665 drawArcInternal( x, y, w, h, a, alen, CloseChord );
1666}
1667
1668
1669void QPainter::drawLineSegments( const QPointArray &a, int index, int nlines )
1670{
1671 if ( nlines < 0 )
1672 nlines = a.size()/2 - index/2;
1673 if ( index + nlines*2 > (int)a.size() )
1674 nlines = (a.size() - index)/2;
1675 if ( !isActive() || nlines < 1 || index < 0 )
1676 return;
1677 QPointArray pa = a;
1678 if ( testf(ExtDev|VxF|WxF) ) {
1679 if ( testf(ExtDev) ) {
1680 if ( 2*nlines != (int)pa.size() ) {
1681 pa = QPointArray( nlines*2 );
1682 for ( int i=0; i<nlines*2; i++ )
1683 pa.setPoint( i, a.point(index+i) );
1684 index = 0;
1685 }
1686 QPDevCmdParam param[1];
1687 param[0].ptarr = (QPointArray*)&pa;
1688 if ( !pdev->cmd(QPaintDevice::PdcDrawLineSegments,this,param)
1689 || !hps )
1690 return;
1691 }
1692 if ( txop != TxNone ) {
1693 pa = xForm( a, index, nlines*2 );
1694 if ( pa.size() != a.size() ) {
1695 index = 0;
1696 nlines = pa.size()/2;
1697 }
1698 }
1699 }
1700 drawPolyInternal( pa, FALSE, FALSE, index, nlines*2, TRUE );
1701}
1702
1703
1704void QPainter::drawPolyline( const QPointArray &a, int index, int npoints )
1705{
1706 if ( npoints < 0 )
1707 npoints = a.size() - index;
1708 if ( index + npoints > (int)a.size() )
1709 npoints = a.size() - index;
1710 if ( !isActive() || npoints < 2 || index < 0 )
1711 return;
1712 QPointArray pa = a;
1713 if ( testf(ExtDev|VxF|WxF) ) {
1714 if ( testf(ExtDev) ) {
1715 if ( npoints != (int)pa.size() ) {
1716 pa = QPointArray( npoints );
1717 for ( int i=0; i<npoints; i++ )
1718 pa.setPoint( i, a.point(index+i) );
1719 index = 0;
1720 }
1721 QPDevCmdParam param[1];
1722 param[0].ptarr = (QPointArray*)&pa;
1723 if ( !pdev->cmd(QPaintDevice::PdcDrawPolyline,this,param) || !hps )
1724 return;
1725 }
1726 if ( txop != TxNone ) {
1727 pa = xForm( pa, index, npoints );
1728 if ( pa.size() != a.size() ) {
1729 index = 0;
1730 npoints = pa.size();
1731 }
1732 }
1733 }
1734 drawPolyInternal( pa, FALSE, FALSE, index, npoints );
1735}
1736
1737
1738void QPainter::drawConvexPolygon( const QPointArray &pa,
1739 int index, int npoints )
1740{
1741 // Any efficient way?
1742 drawPolygon(pa,FALSE,index,npoints);
1743}
1744
1745void QPainter::drawPolygon( const QPointArray &a, bool winding, int index,
1746 int npoints )
1747{
1748 if ( npoints < 0 )
1749 npoints = a.size() - index;
1750 if ( index + npoints > (int)a.size() )
1751 npoints = a.size() - index;
1752 if ( !isActive() || npoints < 2 || index < 0 )
1753 return;
1754 QPointArray pa = a;
1755 if ( testf(ExtDev|VxF|WxF) ) {
1756 if ( testf(ExtDev) ) {
1757 if ( npoints != (int)a.size() ) {
1758 pa = QPointArray( npoints );
1759 for ( int i=0; i<npoints; i++ )
1760 pa.setPoint( i, a.point(index+i) );
1761 }
1762 QPDevCmdParam param[2];
1763 param[0].ptarr = (QPointArray*)&pa;
1764 param[1].ival = winding;
1765 if ( !pdev->cmd(QPaintDevice::PdcDrawPolygon,this,param) || !hps )
1766 return;
1767 }
1768 if ( txop != TxNone ) {
1769 pa = xForm( a, index, npoints );
1770 if ( pa.size() != a.size() ) {
1771 index = 0;
1772 npoints = pa.size();
1773 }
1774 }
1775 }
1776 drawPolyInternal( pa, TRUE, winding, index, npoints );
1777}
1778
1779#ifndef QT_NO_BEZIER
1780void QPainter::drawCubicBezier( const QPointArray &a, int index )
1781{
1782 if ( !isActive() )
1783 return;
1784 if ( (int)a.size() - index < 4 ) {
1785#if defined(QT_CHECK_RANGE)
1786 qWarning( "QPainter::drawCubicBezier: Cubic Bezier needs 4 control "
1787 "points" );
1788#endif
1789 return;
1790 }
1791 QPointArray pa( a );
1792 if ( testf(ExtDev|VxF|WxF) ) {
1793 if ( index != 0 || a.size() > 4 ) {
1794 pa = QPointArray( 4 );
1795 for ( int i=0; i<4; i++ )
1796 pa.setPoint( i, a.point(index+i) );
1797 index = 0;
1798 }
1799 if ( testf(ExtDev) ) {
1800 QPDevCmdParam param[1];
1801 param[0].ptarr = (QPointArray*)&pa;
1802 if ( !pdev->cmd(QPaintDevice::PdcDrawCubicBezier,this,param)
1803 || !hps )
1804 return;
1805 }
1806 if ( txop != TxNone )
1807 pa = xForm( pa );
1808 }
1809
1810 // flip y coordinates
1811 if ( devh ) {
1812 for ( int i = index; i < 4; i++ )
1813 pa[i].setY( devh - (pa[i].y() + 1) );
1814 }
1815
1816 qt_geom_line_handle gh;
1817 if ( cpen.width() > 1 )
1818 qt_begin_geom_line( hps, COLOR_VALUE(cpen.color()), cpen.style() == NoPen, &gh );
1819 GpiMove( hps, (PPOINTL)(pa.data()+index) );
1820 GpiPolySpline( hps, 3, (PPOINTL)(pa.data()+index+1) );
1821 if ( cpen.width() > 1 )
1822 qt_end_geom_line( hps, &gh );
1823}
1824#endif // QT_NO_BEZIER
1825
1826//@@TODO (dmik): remove?
1827//extern uint qt_bitblt_foreground; // in qpaintdevice_pm.cpp
1828
1829void QPainter::drawPixmap( int x, int y, const QPixmap &pixmap,
1830 int sx, int sy, int sw, int sh )
1831{
1832 if ( !isActive() || pixmap.isNull() )
1833 return;
1834 if ( sw < 0 )
1835 sw = pixmap.width() - sx;
1836 if ( sh < 0 )
1837 sh = pixmap.height() - sy;
1838
1839 // Sanity-check clipping
1840 if ( sx < 0 ) {
1841 x -= sx;
1842 sw += sx;
1843 sx = 0;
1844 }
1845 if ( sw + sx > pixmap.width() )
1846 sw = pixmap.width() - sx;
1847 if ( sy < 0 ) {
1848 y -= sy;
1849 sh += sy;
1850 sy = 0;
1851 }
1852 if ( sh + sy > pixmap.height() )
1853 sh = pixmap.height() - sy;
1854
1855 if ( sw <= 0 || sh <= 0 )
1856 return;
1857
1858 if ( testf(ExtDev|VxF|WxF) ) {
1859 if ( testf(ExtDev) || (txop == TxScale && pixmap.mask()) ||
1860 txop == TxRotShear ) {
1861 if ( sx != 0 || sy != 0 ||
1862 sw != pixmap.width() || sh != pixmap.height() ) {
1863 QPixmap tmp( sw, sh, pixmap.depth(), QPixmap::NormalOptim );
1864 bitBlt( &tmp, 0, 0, &pixmap, sx, sy, sw, sh, CopyROP, TRUE );
1865 if ( pixmap.mask() ) {
1866 QBitmap mask( sw, sh );
1867 bitBlt( &mask, 0, 0, pixmap.mask(), sx, sy, sw, sh,
1868 CopyROP, TRUE );
1869 tmp.setMask( mask );
1870 }
1871 drawPixmap( x, y, tmp );
1872 return;
1873 }
1874 if ( testf(ExtDev) ) {
1875 QPDevCmdParam param[2];
1876 QRect r( x, y, pixmap.width(), pixmap.height() );
1877 param[0].rect = &r;
1878 param[1].pixmap = &pixmap;
1879 if ( !pdev->cmd(QPaintDevice::PdcDrawPixmap,this,param)
1880 || !hps )
1881 return;
1882 }
1883 }
1884 if ( txop == TxTranslate )
1885 map( x, y, &x, &y );
1886 }
1887
1888 if ( txop <= TxTranslate ) { // use optimized bitBlt
1889//@@TODO (dmik): remove?
1890// if ( pixmap.depth() == 1 )
1891// qt_bitblt_foreground = COLOR_VALUE(cpen.color());
1892 bitBlt( pdev, x, y, &pixmap, sx, sy, sw, sh, (RasterOp)rop );
1893 return;
1894 }
1895
1896 QPixmap *pm = (QPixmap*)&pixmap;
1897
1898/// @todo (dmik):
1899//
1900// For some unknown reason, the code below doesn't work for some selected
1901// target paint device width and scale factor combinations on my machine
1902// with ATI Radeon 9600 Pro and SNAP Version 2.9.2, build 446 -- GpiBitBlt
1903// simply does nothing (leaving the target hps untouched) but returns
1904// GPI_OK. This looks like a (video driver?) bug...
1905//
1906// An easy way to reproduce is to run the xform example, select the
1907// Image mode and set the scale factor to 360% (making sure the window
1908// size was not changed after starting the application).
1909//
1910#if 0
1911 if ( txop == TxScale && !pm->mask() ) {
1912 // Plain scaling and no mask, then GpiBitBlt is faster
1913 int w, h;
1914 map( x, y, sw, sh, &x, &y, &w, &h );
1915 // flip y coordinate
1916 if ( devh )
1917 y = devh - (y + h);
1918 POINTL ptls[] = {
1919 { x, y }, { x + w, y + h },
1920 { sx, sy }, { sw, sh }
1921 };
1922 GpiBitBlt( hps, pm->handle(), 4, ptls, ROP_SRCCOPY, BBO_IGNORE );
1923 } else
1924#endif
1925 {
1926#ifndef QT_NO_PIXMAP_TRANSFORMATION
1927 // We have a complex xform or scaling with mask, then xform the
1928 // pixmap (and possible mask) and bitBlt again.
1929 QWMatrix mat( m11(), m12(),
1930 m21(), m22(),
1931 dx(), dy() );
1932 mat = QPixmap::trueMatrix( mat, sw, sh );
1933 QPixmap pmx;
1934 if ( sx == 0 && sy == 0 &&
1935 sw == pixmap.width() && sh == pixmap.height() ) {
1936 pmx = pixmap; // xform the whole pixmap
1937 } else {
1938 pmx = QPixmap( sw, sh ); // xform subpixmap
1939 bitBlt( &pmx, 0, 0, pm, sx, sy, sw, sh );
1940 }
1941 pmx = pmx.xForm( mat );
1942 if ( pmx.isNull() ) // xformed into nothing
1943 return;
1944 if ( !pmx.mask() && txop == TxRotShear ) {
1945 QBitmap bm_clip( sw, sh, 1 ); // make full mask, xform it
1946 bm_clip.fill( color1 );
1947 pmx.setMask( bm_clip.xForm(mat) );
1948 }
1949 map( x, y, &x, &y ); //### already done above? // compute position of pixmap
1950 int dx, dy;
1951 mat.map( 0, 0, &dx, &dy );
1952 bitBlt( pdev, x - dx, y - dy, &pmx );
1953#endif
1954 }
1955}
1956
1957/* Internal, used by drawTiledPixmap */
1958
1959static void drawTile( QPainter *p, int x, int y, int w, int h,
1960 const QPixmap &pixmap, int xOffset, int yOffset )
1961{
1962 int yPos, xPos, drawH, drawW, yOff, xOff;
1963 yPos = y;
1964 yOff = yOffset;
1965 while( yPos < y + h ) {
1966 drawH = pixmap.height() - yOff; // Cropping first row
1967 if ( yPos + drawH > y + h ) // Cropping last row
1968 drawH = y + h - yPos;
1969 xPos = x;
1970 xOff = xOffset;
1971 while( xPos < x + w ) {
1972 drawW = pixmap.width() - xOff; // Cropping first column
1973 if ( xPos + drawW > x + w ) // Cropping last column
1974 drawW = x + w - xPos;
1975 p->drawPixmap( xPos, yPos, pixmap, xOff, yOff, drawW, drawH );
1976 xPos += drawW;
1977 xOff = 0;
1978 }
1979 yPos += drawH;
1980 yOff = 0;
1981 }
1982}
1983
1984void QPainter::drawTiledPixmap( int x, int y, int w, int h,
1985 const QPixmap &pixmap, int sx, int sy )
1986{
1987 int sw = pixmap.width();
1988 int sh = pixmap.height();
1989 if (!sw || !sh )
1990 return;
1991 if ( sx < 0 )
1992 sx = sw - -sx % sw;
1993 else
1994 sx = sx % sw;
1995 if ( sy < 0 )
1996 sy = sh - -sy % sh;
1997 else
1998 sy = sy % sh;
1999 /*
2000 Requirements for optimizing tiled pixmaps:
2001 - not an external device
2002 - not scale or rotshear
2003 - no mask
2004 */
2005 QBitmap *mask = (QBitmap *)pixmap.mask();
2006//@@TODO (dmik): is OS/2 buggy too?
2007//#if 0 // Windows is too buggy, so we just use our own code (which is faster).
2008 if ( !testf(ExtDev) && txop <= TxTranslate && mask == 0 ) {
2009 if ( txop == TxTranslate )
2010 map( x, y, &x, &y );
2011 qt_draw_tiled_pixmap( hps, x, y, w, h, &pixmap, sx, sy, devh );
2012 return;
2013 }
2014//#endif
2015 if ( sw*sh < 8192 && sw*sh < 16*w*h ) {
2016 int tw = sw, th = sh;
2017 while ( tw*th < 32678 && tw < w/2 )
2018 tw *= 2;
2019 while ( tw*th < 32678 && th < h/2 )
2020 th *= 2;
2021 QPixmap tile( tw, th, pixmap.depth(), QPixmap::BestOptim );
2022 qt_fill_tile( &tile, pixmap );
2023 if ( mask ) {
2024 QBitmap tilemask( tw, th, FALSE, QPixmap::NormalOptim );
2025 qt_fill_tile( &tilemask, *mask );
2026 tile.setMask( tilemask );
2027 }
2028 drawTile( this, x, y, w, h, tile, sx, sy );
2029 } else {
2030 drawTile( this, x, y, w, h, pixmap, sx, sy );
2031 }
2032}
2033
2034//@@TODO (dmik): need this at all?
2035#if 0
2036//
2037// Generate a string that describes a transformed bitmap. This string is used
2038// to insert and find bitmaps in the global pixmap cache.
2039//
2040
2041static QString gen_text_bitmap_key( const QWMatrix &m, const QFont &font,
2042 const QString &str, int pos, int len )
2043{
2044 QString fk = font.key();
2045 int sz = 4*2 + len*2 + fk.length()*2 + sizeof(double)*6;
2046 QByteArray buf(sz);
2047 uchar *p = (uchar *)buf.data();
2048 *((double*)p)=m.m11(); p+=sizeof(double);
2049 *((double*)p)=m.m12(); p+=sizeof(double);
2050 *((double*)p)=m.m21(); p+=sizeof(double);
2051 *((double*)p)=m.m22(); p+=sizeof(double);
2052 *((double*)p)=m.dx(); p+=sizeof(double);
2053 *((double*)p)=m.dy(); p+=sizeof(double);
2054 QChar h1( '$' );
2055 QChar h2( 'q' );
2056 QChar h3( 't' );
2057 QChar h4( '$' );
2058 *((QChar*)p)=h1; p+=2;
2059 *((QChar*)p)=h2; p+=2;
2060 *((QChar*)p)=h3; p+=2;
2061 *((QChar*)p)=h4; p+=2;
2062 memcpy( (char*)p, (char*)(str.unicode()+pos), len*2 ); p += len*2;
2063 memcpy( (char*)p, (char*)fk.unicode(), fk.length()*2 ); p += fk.length()*2;
2064 return QString( (QChar*)buf.data(), buf.size()/2 );
2065}
2066
2067static QBitmap *get_text_bitmap( const QString &key )
2068{
2069 return (QBitmap*)QPixmapCache::find( key );
2070}
2071
2072static void ins_text_bitmap( const QString &key, QBitmap *bm )
2073{
2074 if ( !QPixmapCache::insert(key,bm) ) // cannot insert pixmap
2075 delete bm;
2076}
2077#endif
2078
2079void QPainter::drawText( int x, int y, const QString &str, int len, QPainter::TextDirection dir )
2080{
2081 drawText( x, y, str, 0, len, dir );
2082}
2083
2084void QPainter::drawText( int x, int y, const QString &str, int pos, int len, QPainter::TextDirection dir)
2085{
2086 if ( !isActive() )
2087 return;
2088
2089 const int slen = str.length();
2090 if (len < 0)
2091 len = slen - pos;
2092 if ( len == 0 || pos >= slen ) // empty string
2093 return;
2094 if ( pos + len > slen )
2095 len = slen - pos;
2096
2097 if ( testf(DirtyFont) )
2098 updateFont();
2099
2100 if ( testf(ExtDev) ) {
2101 QPDevCmdParam param[3];
2102 QString string = str.mid( pos, len );
2103 QPoint p( x, y );
2104 param[0].point = &p;
2105 param[1].str = &string;
2106 param[2].ival = QFont::NoScript;
2107 if ( !pdev->cmd(QPaintDevice::PdcDrawText2,this,param) || !hps )
2108 return;
2109 }
2110
2111 // we can't take the complete string here as we would otherwise
2112 // get quadratic behaviour when drawing long strings in parts.
2113 // we do however need some chars around the part we paint to get arabic shaping correct.
2114 // ### maybe possible to remove after cursor restrictions work in QRT
2115 int start = QMAX( 0, pos - 8 );
2116 int end = QMIN( (int)str.length(), pos + len + 8 );
2117 QConstString cstr( str.unicode() + start, end - start );
2118 pos -= start;
2119
2120 QTextLayout layout( cstr.string(), this );
2121 layout.beginLayout( QTextLayout::SingleLine );
2122
2123 layout.setBoundary( pos );
2124 layout.setBoundary( pos + len );
2125
2126 QTextEngine *engine = layout.d;
2127 if ( dir != Auto ) {
2128 int level = (dir == RTL) ? 1 : 0;
2129 for ( int i = engine->items.size(); i >= 0; i-- )
2130 engine->items[i].analysis.bidiLevel = level;
2131 }
2132
2133 // small hack to force skipping of unneeded items
2134 start = 0;
2135 while ( engine->items[start].position < pos )
2136 ++start;
2137 engine->currentItem = start;
2138 layout.beginLine( 0xfffffff );
2139 end = start;
2140 while ( !layout.atEnd() && layout.currentItem().from() < pos + len ) {
2141 layout.addCurrentItem();
2142 end++;
2143 }
2144 int ascent = fontMetrics().ascent();
2145 layout.endLine( 0, 0, Qt::SingleLine|Qt::AlignLeft, &ascent, 0 );
2146
2147 // do _not_ call endLayout() here, as it would clean up the shaped items and we would do shaping another time
2148 // for painting.
2149
2150 for ( int i = start; i < end; i++ ) {
2151 QScriptItem *si = &engine->items[i];
2152
2153 QFontEngine *fe = si->fontEngine;
2154 Q_ASSERT( fe );
2155
2156 int xpos = x + si->x;
2157 int ypos = y + si->y - ascent;
2158
2159//@@TODO (dmik): remove
2160//#ifndef Q_OS_TEMP
2161// if ( rop != CopyROP ) {
2162// // Doesn't work for non-TrueType fonts, but we dealt with those
2163// // with the bitmap above.
2164// BeginPath(hdc);
2165// }
2166//#endif
2167
2168//@@TODO (dmik): do we really need this? we already have painter->handle()
2169// inside QFontEngine::draw(), and the font should have been selected into
2170// hps by updateFont()
2171// HPS oldPs = fe->hps;
2172// fe->hps = hps;
2173// fe->selectTo( hps );
2174
2175 int textFlags = 0;
2176 if ( cfont.d->underline ) textFlags |= Qt::Underline;
2177 if ( cfont.d->overline ) textFlags |= Qt::Overline;
2178 if ( cfont.d->strikeOut ) textFlags |= Qt::StrikeOut;
2179
2180 fe->draw( this, xpos, ypos, engine, si, textFlags );
2181//@@TODO (dmik): need?
2182// fe->hps = oldPs;
2183
2184//@@TODO (dmik): remove
2185// if ( rop != CopyROP ) {
2186//#ifndef Q_OS_TEMP
2187// EndPath(hdc);
2188//#endif
2189// uint pix = COLOR_VALUE(cpen.data->color);
2190// HBRUSH tbrush = CreateSolidBrush( pix );
2191// SelectObject( hdc, tbrush );
2192//#ifndef Q_OS_TEMP
2193// FillPath(hdc);
2194//#endif
2195// SelectObject( hdc, hbrush );
2196// DeleteObject( tbrush );
2197// }
2198 }
2199}
2200
2201
2202
2203void QPainter::drawTextItem( int x, int y, const QTextItem &ti, int textFlags )
2204{
2205 if ( testf(ExtDev) ) {
2206 QPDevCmdParam param[2];
2207 QPoint p(x, y);
2208 param[0].point = &p;
2209 param[1].textItem = &ti;
2210 bool retval = pdev->cmd(QPaintDevice::PdcDrawTextItem, this, param);
2211 if ( !retval || !hps )
2212 return;
2213 }
2214
2215 QTextEngine *engine = ti.engine;
2216 QScriptItem *si = &engine->items[ti.item];
2217
2218 engine->shape( ti.item );
2219 QFontEngine *fe = si->fontEngine;
2220 Q_ASSERT( fe );
2221
2222 x += si->x;
2223 y += si->y;
2224
2225//@@TODO (dmik): do we really need this? we already have painter->handle()
2226// inside QFontEngine::draw(), and the font should have been selected into
2227// hps by updateFont()
2228// HPS oldPs = fe->hps;
2229// fe->hps = hps;
2230// fe->selectTo( hps );
2231
2232 fe->draw( this, x, y, engine, si, textFlags );
2233//@@TODO (dmik): need?
2234// fe->hps = oldPs;
2235}
2236
2237
2238QPoint QPainter::pos() const
2239{
2240 QPoint p;
2241 if ( !isActive() || !hps )
2242 return p;
2243 POINTL ptl;
2244 GpiQueryCurrentPosition( hps, &ptl );
2245 if ( devh ) ptl.y = devh - ( ptl.y + 1 );
2246 p.rx() = ptl.x;
2247 p.ry() = ptl.y;
2248 return xFormDev( p );
2249}
2250
Note: See TracBrowser for help on using the repository browser.