void VGradientEx::transform( const QTransform &m )
{
	double mx, my;
	mx = m.m11() * m_origin.x() + m.m21() * m_origin.y() + m.dx();
	my = m.m22() * m_origin.y() + m.m12() * m_origin.x() + m.dy();
	m_origin = FPoint(mx, my);
	mx = m.m11() * m_focalPoint.x() + m.m21() * m_focalPoint.y() + m.dx();
	my = m.m22() * m_focalPoint.y() + m.m12() * m_focalPoint.x() + m.dy();
	m_focalPoint = FPoint(mx, my);
	mx = m.m11() * m_vector.x() + m.m21() * m_vector.y() + m.dx();
	my = m.m22() * m_vector.y() + m.m12() * m_vector.x() + m.dy();
	m_vector = FPoint(mx, my);
}
static QLineF preciselyMap( const QTransform& transform, const QLineF& line )
{
    qreal fx1 = line.x1();
    qreal fy1 = line.y1();
    qreal fx2 = line.x2();
    qreal fy2 = line.y2();

    qreal x1 = transform.m11() * fx1 + transform.m21() * fy1 + transform.dx();
    qreal y1 = transform.m12() * fx1 + transform.m22() * fy1 + transform.dy();
    qreal x2 = transform.m11() * fx2 + transform.m21() * fy2 + transform.dx();
    qreal y2 = transform.m12() * fx2 + transform.m22() * fy2 + transform.dy();

    return QLineF( x1, y1, x2, y2 );
}
Exemple #3
0
/**
 * @brief NewSceneRect calculate scene rect what contains all items and doesn't less that size of scene view.
 * @param sc scene.
 * @param view view.
 */
void VAbstractTool::NewSceneRect(QGraphicsScene *sc, QGraphicsView *view)
{
    QRectF rect = sc->itemsBoundingRect();

    QRect  rec0 = view->rect();
    rec0 = QRect(0, 0, rec0.width()-2, rec0.height()-2);

    QTransform t = view->transform();

    QRectF rec1;
    if (t.m11() < 1)
    {
        qreal width = rec0.width()/t.m11();
        qreal height = rec0.height()/t.m22();
        rec1 = QRect(0, 0, static_cast<qint32>(width), static_cast<qint32>(height));

        rec1.translate(rec0.center().x()-rec1.center().x(), rec0.center().y()-rec1.center().y());
        QPolygonF polygone =  view->mapToScene(rec1.toRect());
        rec1 = polygone.boundingRect();
    }
    else
    {
        rec1 = rec0;
    }
    rec1 = rec1.united(rect.toRect());
    sc->setSceneRect(rec1);
}
void MGLES2Renderer::draw(const QList<QRect>& targets, const QList<QRect>& sources)
{
    GLuint num = d_ptr->setupVertices(d_ptr->m_boundTexSize, sources, targets);


    QTransform transform;
    GLfloat o = 1.0;
    if (d_ptr->m_activePainter) {
        transform = d_ptr->m_activePainter->combinedTransform();
        o = d_ptr->m_activePainter->opacity();
    }

    d_ptr->m_matWorld[0][0] = transform.m11();
    d_ptr->m_matWorld[0][1] = transform.m12();
    d_ptr->m_matWorld[0][3] = transform.m13();
    d_ptr->m_matWorld[1][0] = transform.m21();
    d_ptr->m_matWorld[1][1] = transform.m22();
    d_ptr->m_matWorld[1][3] = transform.m23();
    d_ptr->m_matWorld[3][0] = transform.dx();
    d_ptr->m_matWorld[3][1] = transform.dy();
    d_ptr->m_matWorld[3][3] = transform.m33();
    d_ptr->m_activeProgram->setUniformValue("matWorld", d_ptr->m_matWorld);
    d_ptr->m_activeProgram->setUniformValue("opacity", o);

    glDrawElements(GL_TRIANGLES, num, GL_UNSIGNED_SHORT, d_ptr->m_indices.data());
}
void MGLES2Renderer::draw(const QRect &rectangle)
{
    GLfloat *vertices = d_ptr->m_vertices.data();
    vertices[0] = rectangle.left();  vertices[1] = rectangle.top();
    vertices[2] = rectangle.left();  vertices[3] = rectangle.top() + rectangle.height();
    vertices[4] = rectangle.left() + rectangle.width(); vertices[5] = rectangle.top() + rectangle.height();
    vertices[6] = rectangle.left() + rectangle.width(); vertices[7] = rectangle.top();

    QTransform transform;
    GLfloat o = 1.0;
    if (d_ptr->m_activePainter) {
        transform = d_ptr->m_activePainter->combinedTransform();
        o = d_ptr->m_activePainter->opacity();
    }
    d_ptr->m_matWorld[0][0] = transform.m11();
    d_ptr->m_matWorld[0][1] = transform.m12();
    d_ptr->m_matWorld[0][3] = transform.m13();
    d_ptr->m_matWorld[1][0] = transform.m21();
    d_ptr->m_matWorld[1][1] = transform.m22();
    d_ptr->m_matWorld[1][3] = transform.m23();
    d_ptr->m_matWorld[3][0] = transform.dx();
    d_ptr->m_matWorld[3][1] = transform.dy();
    d_ptr->m_matWorld[3][3] = transform.m33();
    d_ptr->m_activeProgram->setUniformValue("matWorld", d_ptr->m_matWorld);
    d_ptr->m_activeProgram->setUniformValue("opacity", o);

    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
Exemple #6
0
void ellipse::rotate(qreal angle)
{

    this->transformationRotate = this->transformationRotate.rotate(angle);

    QPointF translatePoint(this->transformationTranslate.dx(),this->transformationTranslate.dy());

    QTransform tempRotate(1, 0, 0, 1, 0, 0);
    tempRotate.rotate(angle);
    QPointF rotatedPoint = tempRotate.map(translatePoint);
    this->transformationTranslate = QTransform(1, 0, 0, 1, rotatedPoint.x(), rotatedPoint.y());

    this->transformationMatrix = this->transformationScale* this->transformationRotate * this->transformationTranslate;

	if(!this->transformationMatrix.isInvertible())
	{
        //qDebug() << "Notinvertible";
	}
    QTransform inverted = this->transformationMatrix.inverted();
    data.scaleX = (cl_float) inverted.m11();
    data.scaleY = (cl_float) inverted.m22();
    data.angleX = (cl_float) inverted.m21();
    data.angleY = (cl_float) inverted.m12();
    data.dx = (cl_float) inverted.dx();
    data.dy = (cl_float) inverted.dy();
}
void QgsComposerRuler::setSceneTransform( const QTransform& transform )
{
  QString debug = QString::number( transform.dx() ) + "," + QString::number( transform.dy() ) + ","
                  + QString::number( transform.m11() ) + "," + QString::number( transform.m22() );
  mTransform = transform;
  update();
}
void QNanoPainter::transform(const QTransform &transform)
{
    nvgTransform(nvgCtx()
                 , transform.m11(), transform.m12()
                 , transform.m21(), transform.m22()
                 , transform.m31(), transform.m32());
}
Exemple #9
0
void Selection::transform(QTransform transform, int pageNum)
{
  m_selectionPolygon = transform.map(m_selectionPolygon);

  qreal sx = transform.m11();
  qreal sy = transform.m22();
  qreal s = (sx + sy) / 2.0;

  for (int i = 0; i < m_strokes.size(); ++i)
  {
    m_strokes[i].points = transform.map(m_strokes[i].points);
    /*
    'if (!transform.isRotating())' doesn't work, since rotation of 180 and 360 degrees is treated as a scaling transformation. Same goes for
    'if (transform.isScaling())'
    */
    if (transform.determinant() != 1)
    {
      m_strokes[i].penWidth = m_strokes[i].penWidth * s;
    }
  }
  if (transform.determinant() != 1)
  {
    m_x_padding *= sx;
    m_y_padding *= sy;
  }
  if (transform.isRotating())
  {
    m_x_padding = m_padding;
    m_y_padding = m_padding;
  }

  m_angle = 0.0;

  setPageNum(pageNum);
}
Exemple #10
0
OutputImageParams::PartialXform::PartialXform(QTransform const& xform)
:	m_11(xform.m11()),
	m_12(xform.m12()),
	m_21(xform.m21()),
	m_22(xform.m22())
{
}
Exemple #11
0
void RasterImage::draw(QPainter* painter) const
{
    painter->save();
    QSizeF s;
    if (_sizeIsSpatium)
        s = _size * spatium();
    else
        s = _size * MScore::DPMM;
    if (score()->printing()) {
        // use original image size for printing
        painter->scale(s.width() / doc.width(), s.height() / doc.height());
        painter->drawPixmap(QPointF(0, 0), QPixmap::fromImage(doc));
    }
    else {
        QTransform t = painter->transform();
        QSize ss = QSizeF(s.width() * t.m11(), s.height() * t.m22()).toSize();
        t.setMatrix(1.0, t.m12(), t.m13(), t.m21(), 1.0, t.m23(), t.m31(), t.m32(), t.m33());
        painter->setWorldTransform(t);
        if ((buffer.size() != ss || _dirty) && !doc.isNull()) {
            buffer = QPixmap::fromImage(doc.scaled(ss, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
            _dirty = false;
        }
        Image::draw(painter, ss);
    }
    painter->restore();
}
void TransformEditDialog::init(QTransform aTransform, const PropertyAttributes *aAttributes)
{
    ui->setupUi(this);

    setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);

    ui->m11SpinBox->setValue(aTransform.m11());
    ui->m12SpinBox->setValue(aTransform.m12());
    ui->m13SpinBox->setValue(aTransform.m13());
    ui->m21SpinBox->setValue(aTransform.m21());
    ui->m22SpinBox->setValue(aTransform.m22());
    ui->m23SpinBox->setValue(aTransform.m23());
    ui->m31SpinBox->setValue(aTransform.m31());
    ui->m32SpinBox->setValue(aTransform.m32());
    ui->m33SpinBox->setValue(aTransform.m33());

    if (aAttributes)
    {
        aAttributes->applyToDoubleSpinBox(ui->m11SpinBox);
        aAttributes->applyToDoubleSpinBox(ui->m12SpinBox);
        aAttributes->applyToDoubleSpinBox(ui->m13SpinBox);
        aAttributes->applyToDoubleSpinBox(ui->m21SpinBox);
        aAttributes->applyToDoubleSpinBox(ui->m22SpinBox);
        aAttributes->applyToDoubleSpinBox(ui->m23SpinBox);
        aAttributes->applyToDoubleSpinBox(ui->m31SpinBox);
        aAttributes->applyToDoubleSpinBox(ui->m32SpinBox);
        aAttributes->applyToDoubleSpinBox(ui->m33SpinBox);
    }
}
QT_BEGIN_NAMESPACE

static inline bool qtransform_equals_no_translate(const QTransform &a, const QTransform &b)
{
    if (a.type() <= QTransform::TxTranslate && b.type() <= QTransform::TxTranslate) {
        return true;
    } else {
        // We always use paths for perspective text anyway, so no
        // point in checking the full matrix...
        Q_ASSERT(a.type() < QTransform::TxProject);
        Q_ASSERT(b.type() < QTransform::TxProject);

        return a.m11() == b.m11()
            && a.m12() == b.m12()
            && a.m21() == b.m21()
            && a.m22() == b.m22();
    }
}
inline QString toOctaveFormat(const QTransform &t)
{
    QString s("T = [%1 %2 %3; %4 %5 %6; %7 %8 %9]");
    s = s
        .arg(t.m11()).arg(t.m12()).arg(t.m13())
        .arg(t.m21()).arg(t.m22()).arg(t.m23())
        .arg(t.m31()).arg(t.m32()).arg(t.m33());

    return s;
}
void qTransformToTemplateTransform(const QTransform& in, TemplateTransform* out)
{
	out->template_x = qRound(1000 * in.m31());
	out->template_y = qRound(1000 * in.m32());
	
	out->template_rotation = qAtan2(-in.m21(), in.m11());
	
	out->template_scale_x = in.m11() / qCos(out->template_rotation);
	out->template_scale_y = in.m22() / qCos(out->template_rotation);
}
void QMLProfile::paint(QPainter *painter)
{
	// let's look at the intended size of the content and scale our scene accordingly
	QRect painterRect = painter->viewport();
	QRect profileRect = m_profileWidget->viewport()->rect();
	// qDebug() << "profile viewport and painter viewport" << profileRect << painterRect;
	qreal sceneSize = 104; // that should give us 2% margin all around (100x100 scene)
	qreal dprComp =  devicePixelRatio() * painterRect.width() / profileRect.width();
	qreal sx = painterRect.width() / sceneSize / dprComp;
	qreal sy = painterRect.height() / sceneSize / dprComp;

	// next figure out the weird magic by which we need to shift the painter so the profile is shown
	int dpr = rint(devicePixelRatio());
	qreal magicShiftFactor = (dpr == 2 ? 0.25 : (dpr == 3 ? 0.33 : 0.0));

	// now set up the transformations scale the profile and
	// shift the painter (taking its existing transformation into account)
	QTransform profileTransform = QTransform();
	profileTransform.scale(sx, sy);
	QTransform painterTransform = painter->transform();
	painterTransform.translate(-painterRect.width() * magicShiftFactor ,-painterRect.height() * magicShiftFactor);

#if PROFILE_SCALING_DEBUG
	// some debugging messages to help adjust this in case the magic above is insufficient
	QMLManager::instance()->appendTextToLog(QString("dpr %1 profile viewport %2 %3 painter viewport %4 %5").arg(dpr).arg(profileRect.width()).arg(profileRect.height())
						.arg(painterRect.width()).arg(painterRect.height()));
	QMLManager::instance()->appendTextToLog(QString("profile matrix %1 %2 %3 %4 %5 %6 %7 %8 %9").arg(profileTransform.m11()).arg(profileTransform.m12()).arg(profileTransform.m13())
						.arg(profileTransform.m21()).arg(profileTransform.m22()).arg(profileTransform.m23())
						.arg(profileTransform.m31()).arg(profileTransform.m32()).arg(profileTransform.m33()));
	QMLManager::instance()->appendTextToLog(QString("painter matrix %1 %2 %3 %4 %5 %6 %7 %8 %9").arg(painterTransform.m11()).arg(painterTransform.m12()).arg(painterTransform.m13())
						.arg(painterTransform.m21()).arg(painterTransform.m22()).arg(painterTransform.m23())
						.arg(painterTransform.m31()).arg(painterTransform.m32()).arg(painterTransform.m33()));
	qDebug() << "profile scaled by" << profileTransform.m11() << profileTransform.m22() << "and translated by" << profileTransform.m31() << profileTransform.m32();
	qDebug() << "exist profile transform" << m_profileWidget->transform() << "painter transform" << painter->transform();
#endif
	// apply the transformation
	painter->setTransform(painterTransform);
	m_profileWidget->setTransform(profileTransform);

	// finally, render the profile
	m_profileWidget->render(painter);
}
Exemple #17
0
void Image::draw(QPainter* painter) const
      {
      bool emptyImage = false;
      if (imageType == ImageType::SVG) {
            if (!svgDoc)
                  emptyImage = true;
            else
                  svgDoc->render(painter, bbox());
            }
      else if (imageType == ImageType::RASTER) {
            if (rasterDoc == nullptr)
                  emptyImage = true;
            else {
                  painter->save();
                  QSizeF s;
                  if (_sizeIsSpatium)
                        s = _size * spatium();
                  else
                        s = _size * MScore::DPMM;
                  if (score()->printing()) {
                        // use original image size for printing
                        painter->scale(s.width() / rasterDoc->width(), s.height() / rasterDoc->height());
                        painter->drawPixmap(QPointF(0, 0), QPixmap::fromImage(*rasterDoc));
                        }
                  else {
                        QTransform t = painter->transform();
                        QSize ss = QSizeF(s.width() * t.m11(), s.height() * t.m22()).toSize();
                        t.setMatrix(1.0, t.m12(), t.m13(), t.m21(), 1.0, t.m23(), t.m31(), t.m32(), t.m33());
                        painter->setWorldTransform(t);
                        if ((buffer.size() != ss || _dirty) && rasterDoc && !rasterDoc->isNull()) {
                              buffer = QPixmap::fromImage(rasterDoc->scaled(ss, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
                              _dirty = false;
                              }
                        if (buffer.isNull())
                              emptyImage = true;
                        else
                              painter->drawPixmap(QPointF(0.0, 0.0), buffer);
                        }
                  painter->restore();
                  }
            }
      if (emptyImage) {
            painter->setBrush(Qt::NoBrush);
            painter->setPen(Qt::black);
            painter->drawRect(bbox());
            painter->drawLine(0.0, 0.0, bbox().width(), bbox().height());
            painter->drawLine(bbox().width(), 0.0, 0.0, bbox().height());
            }
      if (selected() && !(score() && score()->printing())) {
            painter->setBrush(Qt::NoBrush);
            painter->setPen(MScore::selectColor[0]);
            painter->drawRect(bbox());
            }
      }
 void updateVertices(const QTransform &t) 
 {
     worldMatrix[0][0] = t.m11();
     worldMatrix[0][1] = t.m12();
     worldMatrix[0][3] = t.m13();
     worldMatrix[1][0] = t.m21();
     worldMatrix[1][1] = t.m22();
     worldMatrix[1][3] = t.m23();
     worldMatrix[3][0] = t.dx();
     worldMatrix[3][1] = t.dy();
     worldMatrix[3][3] = t.m33();
 }
Exemple #19
0
void
qDebug(QTransform transform)
{
    QString string;
    string =  "m11:" + QString::number(transform.m11()) + "\n";
    string += "m12:" + QString::number(transform.m12()) + "\n";
    string += "m13:" + QString::number(transform.m13()) + "\n";
    string += "m21:" + QString::number(transform.m21()) + "\n";
    string += "m22:" + QString::number(transform.m22()) + "\n";
    string += "m23::" + QString::number(transform.m23()) + "\n";
    qDebug(string);
}
glyph_metrics_t QFontEngineDirectWrite::alphaMapBoundingBox(glyph_t glyph, QFixed subPixelPosition,
                                                            const QTransform &matrix,
                                                            GlyphFormat /*format*/)
{
    glyph_metrics_t bbox = QFontEngine::boundingBox(glyph, matrix); // To get transformed advance

    UINT16 glyphIndex = glyph;
    FLOAT glyphAdvance = 0;

    DWRITE_GLYPH_OFFSET glyphOffset;
    glyphOffset.advanceOffset = 0;
    glyphOffset.ascenderOffset = 0;

    DWRITE_GLYPH_RUN glyphRun;
    glyphRun.fontFace = m_directWriteFontFace;
    glyphRun.fontEmSize = fontDef.pixelSize;
    glyphRun.glyphCount = 1;
    glyphRun.glyphIndices = &glyphIndex;
    glyphRun.glyphAdvances = &glyphAdvance;
    glyphRun.isSideways = false;
    glyphRun.bidiLevel = 0;
    glyphRun.glyphOffsets = &glyphOffset;

    DWRITE_MATRIX transform;
    transform.dx = subPixelPosition.toReal();
    transform.dy = 0;
    transform.m11 = matrix.m11();
    transform.m12 = matrix.m12();
    transform.m21 = matrix.m21();
    transform.m22 = matrix.m22();

    IDWriteGlyphRunAnalysis *glyphAnalysis = NULL;
    HRESULT hr = m_directWriteFactory->CreateGlyphRunAnalysis(
                &glyphRun,
                1.0f,
                &transform,
                DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC,
                DWRITE_MEASURING_MODE_NATURAL,
                0.0, 0.0,
                &glyphAnalysis
                );

    if (SUCCEEDED(hr)) {
        RECT rect;
        glyphAnalysis->GetAlphaTextureBounds(DWRITE_TEXTURE_CLEARTYPE_3x1, &rect);
        glyphAnalysis->Release();

        return glyph_metrics_t(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
                               bbox.xoff, bbox.yoff);
    } else {
        return glyph_metrics_t();
    }
}
Exemple #21
0
SEXP to_sexp(QTransform tform) {
  SEXP ans = allocMatrix(REALSXP, 3, 3);; 
  REAL(ans)[0] = tform.m11();
  REAL(ans)[1] = tform.m21();
  REAL(ans)[2] = tform.m31();
  REAL(ans)[3] = tform.m12();
  REAL(ans)[4] = tform.m22();
  REAL(ans)[5] = tform.m32();
  REAL(ans)[6] = tform.m13();
  REAL(ans)[7] = tform.m23();
  REAL(ans)[8] = tform.m33();
  return ans;
}
void QJsonPaintEngine::updateMatrix(const QTransform &matrix)
{
	Q_D(QJsonPaintEngine);
#ifdef QT_PICTURE_DEBUG
	qDebug() << " -> updateMatrix():" << matrix;
#endif
	d->s << QString("\t{\"m\": {\"m11\": %1, \"m12\": %2, \"m21\": %3, \"m22\": %4, \"dx\": %5, \"dy\": %6}},\r\n")
			.arg(matrix.m11())
			.arg(matrix.m12())
			.arg(matrix.m21())
			.arg(matrix.m22())
			.arg(matrix.dx())
			.arg(matrix.dy());
}
Exemple #23
0
void RasterImage::draw(Painter*) const
{
#if 0
    QTransform t = p.worldTransform();
    QSize s      = QSizeF(sz.width() * t.m11(), sz.height() * t.m22()).toSize();
    t.setMatrix(1.0, t.m12(), t.m13(), t.m21(), 1.0, t.m23(), t.m31(), t.m32(), t.m33());
    p.setWorldTransform(t);
    if (buffer.size() != s || _dirty) {
        buffer = QPixmap::fromImage(doc.scaled(s, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
        _dirty = false;
    }
    Image::draw(p, v);
#endif
}
void GraphicsUtils::saveTransform(QXmlStreamWriter & streamWriter, const QTransform & transform) {
	if (transform.isIdentity()) return;

	streamWriter.writeStartElement("transform");
	streamWriter.writeAttribute("m11", QString::number(transform.m11()));
	streamWriter.writeAttribute("m12", QString::number(transform.m12()));
	streamWriter.writeAttribute("m13", QString::number(transform.m13()));
	streamWriter.writeAttribute("m21", QString::number(transform.m21()));
	streamWriter.writeAttribute("m22", QString::number(transform.m22()));
	streamWriter.writeAttribute("m23", QString::number(transform.m23()));
	streamWriter.writeAttribute("m31", QString::number(transform.m31()));
	streamWriter.writeAttribute("m32", QString::number(transform.m32()));
	streamWriter.writeAttribute("m33", QString::number(transform.m33()));
	streamWriter.writeEndElement();
}
    void paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget* widget)
    {
        if (!m_layer)
            return;

        GraphicsContext gc(painter);
        const QTransform transform = painter->transform();
        TransformationMatrix matrix(
                transform.m11(), transform.m12(), 0, transform.m13(),
                transform.m21(), transform.m22(), 0, transform.m23(),
                0, 0, 1, 0,
                transform.m31(), transform.m32(), 0, transform.m33()
            );
        painter->beginNativePainting();
        m_layer->paint(&gc, widget->size(), options->rect, options->exposedRect.toAlignedRect(), matrix, painter->opacity());
        painter->endNativePainting();
    }
QVector3D Conversions::xyz2enu(const QVector3D &xyz, qreal reflat, qreal reflon, qreal refalt)
{
    QVector3D refxyz = Conversions::lla2xyz(reflat,reflon,refalt);
    QVector3D diffxyz = xyz - refxyz;

    QTransform R1 = Conversions::rot(90.0 + reflon,3);
    QTransform R2 = Conversions::rot(90.0-reflat,1);
    QTransform R = R2*R1;

    //MAKE THIS MATRIX MULTIPLY
    qreal x = R.m11()*diffxyz.x() + R.m12()*diffxyz.y() + R.m13()*diffxyz.z();
    qreal y = R.m21()*diffxyz.x() + R.m22()*diffxyz.y() + R.m23()*diffxyz.z();
    qreal z = R.m31()*diffxyz.x() + R.m32()*diffxyz.y() + R.m33()*diffxyz.z();

    QVector3D enu(x,y,z);

    return enu;
}
void TextureMapperLayerClientQt::renderCompositedLayers(GraphicsContext* context, const IntRect& clip)
{
    if (!m_rootTextureMapperLayer || !m_textureMapper)
        return;

    m_textureMapper->setGraphicsContext(context);
    // GraphicsContext::imageInterpolationQuality is always InterpolationDefault here,
    // but 'default' may be interpreted differently due to a different backend QPainter,
    // so we need to set an explicit imageInterpolationQuality.
    if (context->platformContext()->renderHints() & QPainter::SmoothPixmapTransform)
        m_textureMapper->setImageInterpolationQuality(WebCore::InterpolationMedium);
    else
        m_textureMapper->setImageInterpolationQuality(WebCore::InterpolationNone);

    m_textureMapper->setTextDrawingMode(context->textDrawingMode());
    QPainter* painter = context->platformContext();
    QTransform transform;
    if (m_textureMapper->accelerationMode() == TextureMapper::OpenGLMode) {
        // TextureMapperGL needs to duplicate the entire transform QPainter would do,
        // including the transforms QPainter would normally do behind the scenes.
        transform = painter->deviceTransform();
    } else {
        // TextureMapperImageBuffer needs a transform that can be used
        // with QPainter::setWorldTransform.
        transform = painter->worldTransform();
    }
    const TransformationMatrix matrix(
        transform.m11(), transform.m12(), 0, transform.m13(),
        transform.m21(), transform.m22(), 0, transform.m23(),
        0, 0, 1, 0,
        transform.m31(), transform.m32(), 0, transform.m33()
        );
    if (m_rootGraphicsLayer->opacity() != painter->opacity() || m_rootGraphicsLayer->transform() != matrix) {
        m_rootGraphicsLayer->setOpacity(painter->opacity());
        m_rootGraphicsLayer->setTransform(matrix);
        m_rootGraphicsLayer->flushCompositingStateForThisLayerOnly();
    }
    m_textureMapper->beginPainting();
    m_textureMapper->beginClip(matrix, clip);
    m_rootTextureMapperLayer->paint();
    m_fpsCounter.updateFPSAndDisplay(m_textureMapper.get(), IntPoint::zero(), matrix);
    m_textureMapper->endClip();
    m_textureMapper->endPainting();
}
Exemple #28
0
void svg_renderer::update_drawing (const QTransform &transform, const QRectF &rect_to_update, int cache_object_type)
{
  m_cache->lock ();
  DO_ON_EXIT (m_cache->unlock ());

  double cache_zoom_x = m_cache->zoom_x ();
  double cache_zoom_y = m_cache->zoom_y ();
  double cur_zoom_x = transform.m11 ();
  double cur_zoom_y = transform.m22 ();
  QRectF rect_to_draw = rect_to_update;
  QTransform real_transform = transform;

  SkBitmap bitmap;
  bitmap.setConfig (SkBitmap::kARGB_8888_Config, rect_to_draw.width (), rect_to_draw.height ());
  bitmap.allocPixels ();
  SkBitmapDevice device (bitmap);
  SkCanvas canvas (&device);

  if (!are_equal (cache_zoom_x, cur_zoom_x) || !are_equal (cache_zoom_y, cur_zoom_y))
    {
      QTransform scale_transform = QTransform::fromScale (cache_zoom_x / cur_zoom_x, cache_zoom_y / cur_zoom_y);
      real_transform = real_transform * scale_transform;
      canvas.setMatrix (qt2skia::matrix (scale_transform.inverted ()));
      rect_to_draw = scale_transform.mapRect (rect_to_draw);
    }

  canvas.drawColor (SK_ColorTRANSPARENT, SkXfermode::kSrc_Mode);

  pair<render_cache_id, render_cache_id> it_pair = render_cache_id::get_id_for_pixel_rect (real_transform, rect_to_draw, cache_object_type);

  for (int x = it_pair.first.x (); x <= it_pair.second.x (); x++)
    for (int y = it_pair.first.y (); y <= it_pair.second.y (); y++)
      {
        render_cache_id cur_id (x, y, cache_object_type);
        SkBitmap bitmap = m_cache->bitmap (cur_id);
        if (bitmap.empty ())
          continue;

        QRectF pixel_rect = cur_id.pixel_rect (real_transform);
        canvas.drawBitmap (bitmap, SkFloatToScalar (pixel_rect.x ()), SkFloatToScalar (pixel_rect.y ()));
      }

  m_cache->set_current_screen (bitmap, cache_object_type);
}
Exemple #29
0
/*!
    Returns an inverted copy of this matrix.

    If the matrix is singular (not invertible), the returned matrix is
    the identity matrix. If \a invertible is valid (i.e. not 0), its
    value is set to true if the matrix is invertible, otherwise it is
    set to false.

    \sa isInvertible()
*/
QTransform QTransform::inverted(bool *invertible) const
{
    qreal det = determinant();
    if (qFuzzyCompare(det, qreal(0.0))) {
        if (invertible)
            *invertible = false;
        return QTransform();
    }
    if (invertible)
        *invertible = true;
    QTransform adjA = adjoint();
    QTransform invert = adjA / det;
    invert = QTransform(invert.m11()/invert.m33(), invert.m12()/invert.m33(), invert.m13()/invert.m33(),
                        invert.m21()/invert.m33(), invert.m22()/invert.m33(), invert.m23()/invert.m33(),
                        invert.m31()/invert.m33(), invert.m32()/invert.m33(), 1);
    // inverting doesn't change the type
    invert.m_type = m_type;
    invert.m_dirty = m_dirty;
    return invert;
}
Exemple #30
0
void saveValue(QDomElement *parent, const QString &tag, const QTransform &t)
{
    QDomDocument doc = parent->ownerDocument();
    QDomElement e = doc.createElement(tag);
    parent->appendChild(e);

    e.setAttribute("type", "transform");

    e.setAttribute("m11", toString(t.m11()));
    e.setAttribute("m12", toString(t.m12()));
    e.setAttribute("m13", toString(t.m13()));

    e.setAttribute("m21", toString(t.m21()));
    e.setAttribute("m22", toString(t.m22()));
    e.setAttribute("m23", toString(t.m23()));

    e.setAttribute("m31", toString(t.m31()));
    e.setAttribute("m32", toString(t.m32()));
    e.setAttribute("m33", toString(t.m33()));
}