r14265 by fschmid - Xara Importer: added support for simple linear and circular gradients.
scribus-commit
scribus-commit at lists.scribus.net
Sat Nov 7 23:00:29 CET 2009
Revision: 14265
Author: fschmid
Date: 2009-11-07T16:07:57.793561Z
Commit message: Xara Importer: added support for simple linear and circular gradients.
Changeset:
M /trunk/Scribus/scribus/scpainter.cpp
M /trunk/Scribus/scribus/plugins/xarimplugin/importxar.h
M /trunk/Scribus/scribus/ui/cpalette.cpp
M /trunk/Scribus/scribus/plugins/xarimplugin/importxar.cpp
Diffs:
Index: scribus/scpainter.cpp
===================================================================
--- scribus/scpainter.cpp (revision 14264)
+++ scribus/scpainter.cpp (revision 14265)
@@ -956,12 +956,53 @@
{
double r, g, b;
m_fill.getRgbF(&r, &g, &b);
+/*
+ Experimental Code for testing gradient masks, sadly this feature
+ is only possible with cairo.
+ if (fill_trans != 1.0)
+ {
+ cairo_set_source_rgb( m_cr, r, g, b );
+ cairo_set_operator(m_cr, CAIRO_OPERATOR_OVER);
+ cairo_pattern_t *pat;
+ double x1 = fill_gradient.origin().x();
+ double y1 = fill_gradient.origin().y();
+ double x2 = fill_gradient.vector().x();
+ double y2 = fill_gradient.vector().y();
+ if (fill_gradient.type() == VGradient::linear)
+ pat = cairo_pattern_create_linear (x1, y1, x2, y2);
+ else
+ pat = cairo_pattern_create_radial (x1, y1, 0, x1, y1, sqrt(pow(x2 - x1, 2) + pow(y2 - y1,2)));
+ QList<VColorStop*> colorStops = fill_gradient.colorStops();
+ QColor qStopColor;
+ for( int offset = 0 ; offset < colorStops.count() ; offset++ )
+ {
+ qStopColor = colorStops[ offset ]->color;
+ int h, s, v, sneu, vneu;
+ int shad = colorStops[offset]->shade;
+ qStopColor.getHsv(&h, &s, &v);
+ sneu = s * shad / 100;
+ vneu = 255 - ((255 - v) * shad / 100);
+ qStopColor.setHsv(h, sneu, vneu);
+ double a = colorStops[offset]->opacity;
+ double r, g, b;
+ qStopColor.getRgbF(&r, &g, &b);
+ cairo_pattern_add_color_stop_rgba (pat, colorStops[ offset ]->rampPoint, r, g, b, a);
+ }
+ cairo_clip_preserve (m_cr);
+ cairo_mask(m_cr, pat);
+ cairo_pattern_destroy (pat);
+ }
+ else
+ {
+*/
cairo_set_source_rgba( m_cr, r, g, b, fill_trans );
-// if (fill_trans != 1.0)
- cairo_set_operator(m_cr, CAIRO_OPERATOR_OVER);
+ cairo_set_operator(m_cr, CAIRO_OPERATOR_OVER);
+ cairo_fill_preserve(m_cr);
+// }
+// cairo_set_operator(m_cr, CAIRO_OPERATOR_OVER);
// else
// cairo_set_operator(m_cr, CAIRO_OPERATOR_SOURCE);
- cairo_fill_preserve( m_cr );
+// cairo_fill_preserve( m_cr );
}
else if (fillMode == 2)
{
@@ -1294,6 +1335,41 @@
cairo_surface_destroy (image2);
cairo_surface_destroy (image3);
cairo_pop_group_to_source (m_cr);
+/*
+ Experimental Code for testing gradient masks, sadly this feature
+ is only possible with cairo.
+ if (fill_trans != 1.0)
+ {
+ cairo_pattern_t *pat;
+ double x1 = fill_gradient.origin().x();
+ double y1 = fill_gradient.origin().y();
+ double x2 = fill_gradient.vector().x();
+ double y2 = fill_gradient.vector().y();
+ if (fill_gradient.type() == VGradient::linear)
+ pat = cairo_pattern_create_linear (x1, y1, x2, y2);
+ else
+ pat = cairo_pattern_create_radial (x1, y1, 0, x1, y1, sqrt(pow(x2 - x1, 2) + pow(y2 - y1,2)));
+ QList<VColorStop*> colorStops = fill_gradient.colorStops();
+ QColor qStopColor;
+ for( int offset = 0 ; offset < colorStops.count() ; offset++ )
+ {
+ qStopColor = colorStops[ offset ]->color;
+ int h, s, v, sneu, vneu;
+ int shad = colorStops[offset]->shade;
+ qStopColor.getHsv(&h, &s, &v);
+ sneu = s * shad / 100;
+ vneu = 255 - ((255 - v) * shad / 100);
+ qStopColor.setHsv(h, sneu, vneu);
+ double a = colorStops[offset]->opacity;
+ double r, g, b;
+ qStopColor.getRgbF(&r, &g, &b);
+ cairo_pattern_add_color_stop_rgba (pat, colorStops[ offset ]->rampPoint, r, g, b, a);
+ }
+ cairo_mask(m_cr, pat);
+ cairo_pattern_destroy (pat);
+ }
+ else
+*/
cairo_paint_with_alpha (m_cr, fill_trans);
#else
/* Working code, sadly we need to create an additional mask image with the same size as the image to be painted */
Index: scribus/ui/cpalette.cpp
===================================================================
--- scribus/ui/cpalette.cpp (revision 14264)
+++ scribus/ui/cpalette.cpp (revision 14265)
@@ -171,12 +171,12 @@
groupScaleLayout->setAlignment( Qt::AlignTop );
textLabel5 = new QLabel( groupScale );
groupScaleLayout->addWidget( textLabel5, 0, 0 );
- spinXscaling = new ScrSpinBox( 1, 500, groupScale, 0);
+ spinXscaling = new ScrSpinBox( 0.01, 500, groupScale, 0);
spinXscaling->setValue( 100 );
groupScaleLayout->addWidget( spinXscaling, 0, 1 );
textLabel6 = new QLabel( groupScale );
groupScaleLayout->addWidget( textLabel6, 1, 0 );
- spinYscaling = new ScrSpinBox( 1, 500, groupScale, 0 );
+ spinYscaling = new ScrSpinBox( 0.01, 500, groupScale, 0 );
spinYscaling->setValue( 100 );
groupScaleLayout->addWidget( spinYscaling, 1, 1 );
keepScaleRatio = new LinkButton( groupScale );
@@ -389,6 +389,12 @@
return;
if (!currentDoc)
return;
+ disconnect(namedGradient, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradient(const QString &)));
+ disconnect(namedGradientStroke, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradientStroke(const QString &)));
+ disconnect(tabWidgetStroke, SIGNAL(currentChanged(int)), this, SLOT(slotGradStroke(int)));
+ disconnect(gradientTypeStroke, SIGNAL(activated(int)), this, SLOT(slotGradTypeStroke(int)));
+ disconnect(gradEdit, SIGNAL(gradientChanged()), this, SIGNAL(gradientChanged()));
+ disconnect(gradEditStroke, SIGNAL(gradientChanged()), this, SIGNAL(strokeGradientChanged()));
updateCList();
setActTrans(currentItem->fillTransparency(), currentItem->lineTransparency());
setActBlend(currentItem->fillBlendmode(), currentItem->lineBlendmode());
@@ -400,10 +406,6 @@
ChooseGrad(currentItem->GrType);
gradEdit->setGradient(currentItem->fill_gradient);
gradEditStroke->setGradient(currentItem->stroke_gradient);
- disconnect(namedGradient, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradient(const QString &)));
- disconnect(namedGradientStroke, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradientStroke(const QString &)));
- disconnect(tabWidgetStroke, SIGNAL(currentChanged(int)), this, SLOT(slotGradStroke(int)));
- disconnect(gradientTypeStroke, SIGNAL(activated(int)), this, SLOT(slotGradTypeStroke(int)));
if (!currentItem->gradient().isEmpty())
{
setCurrentComboItem(namedGradient, currentItem->gradient());
@@ -451,6 +453,8 @@
connect(namedGradientStroke, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradientStroke(const QString &)));
connect(tabWidgetStroke, SIGNAL(currentChanged(int)), this, SLOT(slotGradStroke(int)));
connect(gradientTypeStroke, SIGNAL(activated(int)), this, SLOT(slotGradTypeStroke(int)));
+ connect(gradEdit, SIGNAL(gradientChanged()), this, SIGNAL(gradientChanged()));
+ connect(gradEditStroke, SIGNAL(gradientChanged()), this, SIGNAL(strokeGradientChanged()));
}
void Cpalette::updateCList()
Index: scribus/plugins/xarimplugin/importxar.cpp
===================================================================
--- scribus/plugins/xarimplugin/importxar.cpp (revision 14264)
+++ scribus/plugins/xarimplugin/importxar.cpp (revision 14265)
@@ -532,6 +532,10 @@
handleLineColor(ts);
else if (tag == 152)
handleLineWidth(ts);
+ else if (tag == 153)
+ handleSimpleGradient(ts, dataLen, true);
+ else if (tag == 154)
+ handleSimpleGradient(ts, dataLen, false);
else if (tag == 157)
handleBitmapFill(ts, dataLen);
else if (tag == 190)
@@ -553,6 +557,36 @@
}
}
+void XarPlug::handleSimpleGradient(QDataStream &ts, quint32 dataLen, bool linear)
+{
+ XarStyle *gc = m_gc.top();
+ quint32 blx, bly, brx, bry, colRef1, colRef2;
+ ts >> blx >> bly >> brx >> bry >> colRef1 >> colRef2;
+ if (dataLen == 40)
+ {
+ double p, p1;
+ ts >> p >> p1;
+ }
+ QString gCol1 = XarColorMap[colRef1].name;
+ QString gCol2 = XarColorMap[colRef2].name;
+ gc->FillGradient = VGradient(VGradient::linear);
+ gc->FillGradient.clearStops();
+ const ScColor& gradC1 = m_Doc->PageColors[gCol1];
+ const ScColor& gradC2 = m_Doc->PageColors[gCol2];
+ QColor c1 = ScColorEngine::getRGBColor(gradC1, m_Doc);
+ QColor c2 = ScColorEngine::getRGBColor(gradC2, m_Doc);
+ gc->FillGradient.addStop( c1, 0.0, 0.5, 1.0, gCol1, 100 );
+ gc->FillGradient.addStop( c2, 1.0, 0.5, 1.0, gCol2, 100 );
+ if (linear)
+ gc->FillGradientType = 6;
+ else
+ gc->FillGradientType = 7;
+ gc->GradFillX1 = (blx / 1000.0) + baseX + m_Doc->currentPage()->xOffset();
+ gc->GradFillY1 = (docHeight - (bly / 1000.0)) + baseY + m_Doc->currentPage()->yOffset();
+ gc->GradFillX2 = (brx / 1000.0) + baseX + m_Doc->currentPage()->xOffset();
+ gc->GradFillY2 = (docHeight - (bry / 1000.0)) + baseY + m_Doc->currentPage()->yOffset();
+}
+
void XarPlug::handleBitmapFill(QDataStream &ts, quint32 dataLen)
{
XarStyle *gc = m_gc.top();
@@ -1123,16 +1157,23 @@
{
for (int a = 0; a < gc->Elements.count(); a++)
{
- gc->Elements.at(a)->setFillColor(gc->FillCol);
- gc->Elements.at(a)->setLineWidth(gc->LWidth);
- gc->Elements.at(a)->setLineColor(gc->StrokeCol);
+ PageItem *item = gc->Elements.at(a);
if (!gc->fillPattern.isEmpty())
{
- gc->Elements.at(a)->setPattern(gc->fillPattern);
- gc->Elements.at(a)->setPatternTransform(gc->patternScaleX, gc->patternScaleY, gc->patternOffsetX, gc->patternOffsetY,
+ item->setPattern(gc->fillPattern);
+ item->setPatternTransform(gc->patternScaleX, gc->patternScaleY, gc->patternOffsetX, gc->patternOffsetY,
gc->patternRotation, gc->patternSkewX, gc->patternSkewY);
- gc->Elements.at(a)->GrType = 8;
+ item->GrType = 8;
}
+ if ((gc->FillGradientType == 6) || (gc->FillGradientType == 7))
+ {
+ item->GrType = gc->FillGradientType;
+ item->fill_gradient = gc->FillGradient;
+ item->setGradientVector(gc->GradFillX1 - item->xPos(), gc->GradFillY1 - item->yPos(), gc->GradFillX2 - item->xPos(), gc->GradFillY2 - item->yPos());
+ }
+ item->setFillColor(gc->FillCol);
+ item->setLineWidth(gc->LWidth);
+ item->setLineColor(gc->StrokeCol);
}
}
delete gc;
Index: scribus/plugins/xarimplugin/importxar.h
===================================================================
--- scribus/plugins/xarimplugin/importxar.h (revision 14264)
+++ scribus/plugins/xarimplugin/importxar.h (revision 14265)
@@ -145,6 +145,7 @@
bool convert(QString fn);
void parseXar(QDataStream &ts);
void handleTags(quint32 tag, quint32 dataLen, QDataStream &ts);
+ void handleSimpleGradient(QDataStream &ts, quint32 dataLen, bool linear);
void handleBitmapFill(QDataStream &ts, quint32 dataLen);
void defineBitmap(QDataStream &ts, quint32 dataLen, quint32 tag);
void handleLineColor(QDataStream &ts);
More information about the scribus-commit
mailing list