Exemplo n.º 1
0
void EmfPaintEngine::drawLines ( const QLineF * lines, int lineCount )
{
   setClipping();

	HPEN wpen = convertPen(painter()->pen());
	SelectObject(metaDC, wpen);

	QMatrix m = painter()->worldMatrix();

	for (int i = 0; i < lineCount; i++) {
		POINT *pts = new POINT[2];

		QPointF p1 = m.map(lines[i].p1());
		QPointF p2 = m.map(lines[i].p2());

		pts[0].x = qRound(p1.x());
		pts[0].y = qRound(p1.y());
		pts[1].x = qRound(p2.x());
		pts[1].y = qRound(p2.y());
		Polyline(metaDC, pts, 2);
		delete [] pts;
	}

	resetClipping();
	DeleteObject(wpen);
}
Exemplo n.º 2
0
void EmfPaintEngine::drawImage(const QRectF & r, const QImage & image, const QRectF &, Qt::ImageConversionFlags flags)
{
	QMatrix m = painter()->worldMatrix();
	QPointF p = m.map(r.topLeft());
	int x = qRound(p.x());
	int y = qRound(p.y());
	int width = qRound(r.width());
	int height = qRound(r.height());

#ifdef Q_WS_WIN
	setClipping();
	QPixmap pix = QPixmap::fromImage (image.scaled(width, height), flags);

	HBITMAP hbtmp = pix.toWinHBITMAP();
	HDC hDC = CreateCompatibleDC(metaDC);
    SelectObject(hDC, hbtmp);
    BitBlt(metaDC, x, y, width, height, hDC, 0, 0, SRCCOPY);
    DeleteObject(hbtmp);
    DeleteDC(hDC);

	resetClipping();
#else
	QImage imag = image.scaled(width, height);
	for (int i = 0; i < width; i++){
		for (int j = 0; j < height; j++){
			QRgb rgb = imag.pixel(i, j);
			if (qAlpha(rgb) == 255)
				SetPixel(metaDC, x + i, y + j, RGB(qRed(rgb), qGreen(rgb), qBlue(rgb)));
		}
	}
#endif
}
Exemplo n.º 3
0
void EmfPaintEngine::drawPolygon ( const QPointF * points, int pointCount, PolygonDrawMode mode )
{
	setClipping();

	HPEN wpen = convertPen(painter()->pen());
	SelectObject(metaDC, wpen);
	HBRUSH wbrush = convertBrush(painter()->brush());
	SelectObject(metaDC, wbrush);

	POINT *pts = new POINT[pointCount];
	QMatrix m = painter()->worldMatrix();
	for (int i = 0; i < pointCount; i++){
		QPointF p = m.map (points[i]);
		pts[i].x = qRound(p.x());
		pts[i].y = qRound(p.y());
	}

	if (mode == QPaintEngine::PolylineMode)
		Polyline(metaDC, pts, pointCount);
	else if (mode == QPaintEngine::OddEvenMode)
		Polygon(metaDC, pts, pointCount);
	else
		qWarning("EmfEngine: drawPolygon with unsupported mode.\n");

	resetClipping();
	delete [] pts;
	DeleteObject(wpen);
	DeleteObject(wbrush);
}
Exemplo n.º 4
0
void EmfPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap & pix, const QPointF &)
{
	setClipping();

#ifdef Q_WS_WIN
	HBITMAP hBmp = pix.toWinHBITMAP();
	HBRUSH wbrush = CreatePatternBrush(hBmp);

	QMatrix m = painter()->worldMatrix();
	QRectF dr = m.mapRect(r);

	RECT rect;
	rect.left = qRound(dr.left());
	rect.top = qRound(dr.top());
	rect.right = qRound(dr.right());
	rect.bottom = qRound(dr.bottom());

	FillRect(metaDC, &rect, wbrush);

	DeleteObject(hBmp);
	DeleteObject(wbrush);
#else
	int width = qRound(r.width());
	int height = qRound(r.height());

	QPixmap pixmap(width, height);
	QPainter p(&pixmap);
	p.drawTiledPixmap(0, 0, width, height, pix);
	p.end();

	drawPixmap(r, pixmap, QRectF());
#endif

	resetClipping();
}
Exemplo n.º 5
0
void EmfPaintEngine::drawTextItem ( const QPointF & p, const QTextItem & textItem )
{
	setClipping();

	SetBkMode( metaDC, TRANSPARENT );

	QFont f = textItem.font();
	QFontMetrics fm(f);
	HFONT wfont = CreateFontA(fm.height() - 1, fm.averageCharWidth(), 0, 0,
				10*f.weight(), f.italic(), f.underline (), f.strikeOut(),
				DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
				DEFAULT_QUALITY, DEFAULT_PITCH, f.family().toAscii().data());
	SelectObject( metaDC, wfont);

	QColor colour = painter()->pen().color();
	SetTextColor( metaDC, RGB(colour.red(), colour.green(), colour.blue()));

	QString text = textItem.text();
	int size = text.size();

	QMatrix m = painter()->worldMatrix();

	XFORM xf;
	xf.eM11 = m.m11();
	xf.eM12 = m.m12();
	xf.eM21 = m.m21();
	xf.eM22 = m.m22();
	xf.eDx = m.dx();
	xf.eDy = m.dy();
	SetWorldTransform(metaDC, &xf);

#ifdef Q_WS_WIN
	wchar_t *wtext = (wchar_t *)malloc(size*sizeof(wchar_t));
	if (!wtext){
		qWarning("EmfEngine: Not enough memory in drawTextItem().");
		return;
	}
	
	size = text.toWCharArray(wtext);
	TextOutW(metaDC, qRound(p.x()), qRound(p.y() - 0.85*fm.height()), wtext, size);
	free(wtext);
#else
	TextOutA(metaDC, qRound(p.x()), qRound(p.y() - 0.85*fm.height()), text.toLocal8Bit().data(), size);
#endif

	xf.eM11 = 1.0;
	xf.eM12 = 0.0;
	xf.eM21 = 0.0;
	xf.eM22 = 1.0;
	xf.eDx = 0.0;
	xf.eDy = 0.0;
	SetWorldTransform(metaDC, &xf);

	resetClipping();
	DeleteObject(wfont);
}
Exemplo n.º 6
0
    void popState()
    {
    	ASSERT(m_graphicsState->previous);
    	if (!m_graphicsState->previous)
    	    return;

    	CustomGraphicsState* oldTop = m_graphicsState;
    	m_graphicsState = oldTop->previous;
    	delete oldTop;

        m_currentLayer->accumulatedOrigin -= view()->Origin();
        view()->PopState();
        resetClipping();
    }
Exemplo n.º 7
0
void EmfPaintEngine::drawEllipse ( const QRectF & rect )
{
	setClipping();

	HPEN wpen = convertPen(painter()->pen());
	SelectObject(metaDC, wpen);
	HBRUSH wbrush = convertBrush(painter()->brush());
	SelectObject(metaDC, wbrush);

	QRectF r = painter()->worldMatrix().mapRect(rect);
	Ellipse(metaDC, qRound(r.left()), qRound(r.top()), qRound(r.right()), qRound(r.bottom()));

	resetClipping();
	DeleteObject(wpen);
	DeleteObject(wbrush);
}
Exemplo n.º 8
0
void EmfPaintEngine::drawRects ( const QRectF * rects, int rectCount )
{
	setClipping();

	HPEN wpen = convertPen(painter()->pen());
	SelectObject(metaDC, wpen);
	HBRUSH wbrush = convertBrush(painter()->brush());
	SelectObject(metaDC, wbrush);

	QMatrix m = painter()->worldMatrix();
	for (int i = 0; i < rectCount; i++){
		QRectF r = m.mapRect(rects[i]);
		Rectangle(metaDC, qRound(r.left()), qRound(r.top()), qRound(r.right()), qRound(r.bottom()));
	}

	resetClipping();
	DeleteObject(wpen);
	DeleteObject(wbrush);
}
Exemplo n.º 9
0
void EmfPaintEngine::drawPoints ( const QPointF * points, int pointCount )
{
	setClipping();

	QColor color = painter()->pen().color();
	HBRUSH wbrush = CreateSolidBrush(RGB(color.red(), color.green(), color.blue()));
	SelectObject(metaDC, wbrush);

	int lw = painter()->pen().width();
	QMatrix m = painter()->worldMatrix();
	for (int i = 0; i < pointCount; i++){
		QPointF p = m.map(points[i]);
		int x = qRound(p.x());
		int y = qRound(p.y());
		Rectangle(metaDC, x, y, x + lw, y + lw);
	}

	resetClipping();
	DeleteObject(wbrush);
}
Exemplo n.º 10
0
void EmfPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &)
{
	setClipping();

	QMatrix m = painter()->worldMatrix();
	QPointF p = m.map(r.topLeft());
	int x = qRound(p.x());
	int y = qRound(p.y());
	int width = qRound(r.width());
	int height = qRound(r.height());

#ifdef Q_WS_WIN
	HBITMAP hbtmp = NULL;
	DWORD op = SRCCOPY;
	if (pm.hasAlpha()){
		QImage image = pm.scaled(width, height).toImage();
		image.invertPixels();
		hbtmp = QPixmap::fromImage (image).toWinHBITMAP();
		op = SRCINVERT;
	} else
		hbtmp = pm.scaled(width, height).toWinHBITMAP();

	HDC hDC = CreateCompatibleDC(metaDC);
    SelectObject(hDC, hbtmp);

    BitBlt(metaDC, x, y, width, height, hDC, 0, 0, op);
    DeleteObject(hbtmp);
    DeleteDC(hDC);
#else
	QImage image = pm.scaled(width, height).toImage();
	for (int i = 0; i < width; i++){
		for (int j = 0; j < height; j++){
			QRgb rgb = image.pixel(i, j);
			if (qAlpha(rgb) == 255)
				SetPixel(metaDC, x + i, y + j, RGB(qRed(rgb), qGreen(rgb), qBlue(rgb)));
		}
	}
#endif
	resetClipping();
}
Exemplo n.º 11
0
 void pushState()
 {
 	m_graphicsState = new CustomGraphicsState(m_graphicsState);
     view()->PushState();
     resetClipping();
 }
Exemplo n.º 12
0
void EmfPaintEngine::drawPath ( const QPainterPath & path )
{
	setClipping();

	int points = path.elementCount();
	POINT *pts = new POINT[points];
	BYTE *types = new BYTE[points];

	POINT *bzs = new POINT[3];
	int bez = 0;

	BeginPath(metaDC);

	QMatrix m = painter()->worldMatrix();
	for (int i = 0; i < points; i++){
		QPainterPath::Element el = path.elementAt(i);
		QPointF p = m.map(QPointF(el.x, el.y));
		int x = qRound(p.x());
		int y = qRound(p.y());
		pts[i].x = x;
		pts[i].y = y;

		switch(el.type){
			case QPainterPath::MoveToElement:
				types[i] = PT_MOVETO;
			#ifndef Q_WS_WIN
				MoveToEx (metaDC, x, y, 0);
			#endif
			break;

			case QPainterPath::LineToElement:
				types[i] = PT_LINETO;
			#ifndef Q_WS_WIN
				LineTo(metaDC, x, y);
			#endif
			break;

			case QPainterPath::CurveToElement:
				types[i] = PT_BEZIERTO;
			#ifndef Q_WS_WIN
				bzs[bez] = pts[i];
				bez++;
			#endif
			break;

			case QPainterPath::CurveToDataElement:
				types[i] = PT_BEZIERTO;
			#ifndef Q_WS_WIN
				bzs[bez] = pts[i];
				if (bez == 2){
					PolyBezierTo(metaDC, bzs, 3);
					bez = 0;
				} else
					bez++;
			#endif
			break;
		}
	}

	HPEN wpen = convertPen(painter()->pen());
	SelectObject(metaDC, wpen);
#ifdef Q_WS_WIN
	PolyDraw(metaDC, pts, types, points);
#else
	StrokePath(metaDC);
#endif

	HBRUSH wbrush = convertBrush(painter()->brush());
	SelectObject(metaDC, wbrush);

	EndPath(metaDC);

	if(QPoint(pts[0].x, pts[0].y) == QPoint(pts[points - 1].x, pts[points - 1].y))
		StrokeAndFillPath(metaDC);
	else {
		FillPath(metaDC);
	#ifdef Q_WS_WIN
		PolyDraw(metaDC, pts, types, points);
	#else
		StrokePath(metaDC);
	#endif
	}

	resetClipping();
	DeleteObject(wbrush);
	DeleteObject(wpen);
	delete [] pts;
	delete [] types;
}