r17790 by fschmid - Display sharp lines for frame.
scribus-commit
scribus-commit at lists.scribus.net
Sun Oct 7 09:36:30 UTC 2012
Author: fschmid
Date: Sun Oct 7 09:36:29 2012
New Revision: 17790
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17790
Log:
Display sharp lines for frame.
Modified:
trunk/Scribus/scribus/pageitem.cpp
trunk/Scribus/scribus/pageitem_textframe.cpp
trunk/Scribus/scribus/scpainter.cpp
trunk/Scribus/scribus/scpainter.h
Modified: trunk/Scribus/scribus/pageitem.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17790&path=/trunk/Scribus/scribus/pageitem.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem.cpp (original)
+++ trunk/Scribus/scribus/pageitem.cpp Sun Oct 7 09:36:29 2012
@@ -1140,14 +1140,14 @@
p->save();
- p->setPen(color, 0.5 / p->zoomFactor(), Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
+ p->setPen(color, 0, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
p->setPenOpacity(1.0);
p->setBrush(Qt::white);
p->setBrushOpacity(1.0);
p->setFillMode(ScPainter::Solid);
- p->drawRect(left, top, sideLength, sideLength);
- p->drawLine(QPointF(left, top), QPointF(right, bottom));
- p->drawLine(QPointF(left, bottom), QPointF(right, top));
+ p->drawSharpRect(left, top, sideLength, sideLength);
+ p->drawSharpLine(QPointF(left, top), QPointF(right, bottom));
+ p->drawSharpLine(QPointF(left, bottom), QPointF(right, top));
p->restore();
}
@@ -1952,12 +1952,9 @@
if (!isEmbedded)
p->translate(Xpos, Ypos);
p->rotate(Rot);
-// p->setAntialiasing(false);
if ((!isEmbedded) && (!m_Doc->RePos))
{
- double aestheticFactor(5.0);
- double scpInv = 1.0 / (qMax(p->zoomFactor(), 1.0) * aestheticFactor);
- // double scpInv = 0;
+ double scpInv = 0;
if (!isGroup())
{
if ((Frame) && (m_Doc->guidesPrefs().framesShown) && ((itemType() == ImageFrame) || (itemType() == LatexFrame) || (itemType() == OSGFrame) || (itemType() == PathText)))
@@ -1992,21 +1989,21 @@
else
// Ugly Hack to fix rendering problems with cairo >=1.5.10 && <1.8.0 follows
#if ((CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 5, 10)) && (CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 8, 0)))
- p->setupPolygon(&PoLine, false);
+ p->setupSharpPolygon(&PoLine, false);
#else
- p->setupPolygon(&PoLine);
+ p->setupSharpPolygon(&PoLine);
#endif
p->strokePath();
}
}
if ((m_Doc->guidesPrefs().framesShown) && textFlowUsesContourLine() && (ContourLine.size() != 0))
{
- p->setPen(Qt::darkGray, 1.0 / qMax(p->zoomFactor(), 1.0), Qt::DotLine, Qt::FlatCap, Qt::MiterJoin);
+ p->setPen(Qt::darkGray, 0, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin);
// Ugly Hack to fix rendering problems with cairo >=1.5.10 && <1.8.0 follows
#if ((CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 5, 10)) && (CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 8, 0)))
- p->setupPolygon(&ContourLine, false);
+ p->setupSharpPolygon(&ContourLine, false);
#else
- p->setupPolygon(&ContourLine);
+ p->setupSharpPolygon(&ContourLine);
#endif
p->strokePath();
}
@@ -2032,7 +2029,7 @@
}
if ((m_Doc->guidesPrefs().layerMarkersShown) && (m_Doc->layerCount() > 1) && (!m_Doc->layerOutline(LayerID)) && (isGroup()) && (!m_Doc->drawAsPreview))
{
- p->setPen(Qt::black, 0.5/ p->zoomFactor(), Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
+ p->setPen(Qt::black, 0, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
p->setPenOpacity(1.0);
p->setBrush(m_Doc->layerMarker(LayerID));
p->setBrushOpacity(1.0);
@@ -2040,7 +2037,7 @@
double ofwh = 10;
double ofx = Width - ofwh/2;
double ofy = Height - ofwh*3;
- p->drawRect(ofx, ofy, ofwh, ofwh);
+ p->drawSharpRect(ofx, ofy, ofwh, ofwh);
}
if (no_fill && no_stroke && m_Doc->guidesPrefs().framesShown)
{
@@ -2048,7 +2045,7 @@
if (m_Locked)
p->setPen(PrefsManager::instance()->appPrefs.displayPrefs.frameLockColor, scpInv, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
p->setFillMode(ScPainter::None);
- p->drawRect(0, 0, Width, Height);
+ p->drawSharpRect(0, 0, Width, Height);
no_fill = false;
no_stroke = false;
}
@@ -2056,9 +2053,7 @@
//if (m_Doc->m_Selection->findItem(this)!=-1)
// drawLockedMarker(p);
}
-// Tinput = false;
FrameOnly = false;
-// p->setAntialiasing(true);
p->restore();
}
@@ -4727,6 +4722,7 @@
bool useRasterBackup = m_Doc->useRaster;
bool SnapGuidesBackup = m_Doc->SnapGuides;
bool SnapElementBackup = m_Doc->SnapElement;
+ int dummy = 0;
m_Doc->SnapElement = false;
m_Doc->useRaster = false;
m_Doc->SnapGuides = false;
@@ -4743,7 +4739,7 @@
{
bool actionFound = checkGradientUndoRedo(ss, isUndo);
if (actionFound)
- int dummy = 0;
+ dummy = 0;
else if (ss->contains("ARC"))
restoreArc(ss, isUndo);
else if (ss->contains("MASKTYPE"))
Modified: trunk/Scribus/scribus/pageitem_textframe.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17790&path=/trunk/Scribus/scribus/pageitem_textframe.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_textframe.cpp (original)
+++ trunk/Scribus/scribus/pageitem_textframe.cpp Sun Oct 7 09:36:29 2012
@@ -317,7 +317,7 @@
currentShadow = newShadow;
}
}
-
+/*
static void debugLineLayout(const StoryText& itemText, const LineSpec& line)
{
QFile debugFile(QDir::homePath() + "/Desktop/debug_line.csv");
@@ -350,7 +350,7 @@
debugFile.close();
}
-
+*/
static void dumpIt(const ParagraphStyle& pstyle, QString indent = QString("->"))
{
QString db = QString("%6%1/%2 @ %3: %4--%5 linespa%6: %7 align%8")
@@ -3544,13 +3544,9 @@
if (!isEmbedded)
p->translate(Xpos, Ypos);
p->rotate(Rot);
-// p->setAntialiasing(false);
if ((!isEmbedded) && (!m_Doc->RePos))
{
- // added to prevent fat frame outline due to antialiasing and considering you canât pass a cosmetic pen to scpainter - pm
- double aestheticFactor(5.0);
- double scpInv = 1.0 / (qMax(p->zoomFactor(), 1.0) * aestheticFactor);
-// double scpInv = 0.0;
+ double scpInv = 0.0;
if ((Frame) && (m_Doc->guidesPrefs().framesShown))
{
p->setPen(PrefsManager::instance()->appPrefs.displayPrefs.frameNormColor, scpInv, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
@@ -3564,9 +3560,9 @@
p->setFillMode(0);
// Ugly Hack to fix rendering problems with cairo >=1.5.10 && <1.8.0 follows
#if ((CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 5, 10)) && (CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 8, 0)))
- p->setupPolygon(&PoLine, false);
+ p->setupSharpPolygon(&PoLine, false);
#else
- p->setupPolygon(&PoLine);
+ p->setupSharpPolygon(&PoLine);
#endif
p->strokePath();
}
@@ -3575,9 +3571,9 @@
p->setPen(Qt::lightGray, scpInv, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
// Ugly Hack to fix rendering problems with cairo >=1.5.10 && <1.8.0 follows
#if ((CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 5, 10)) && (CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 8, 0)))
- p->setupPolygon(&ContourLine, false);
+ p->setupSharpPolygon(&ContourLine, false);
#else
- p->setupPolygon(&ContourLine);
+ p->setupSharpPolygon(&ContourLine);
#endif
p->strokePath();
}
@@ -3592,7 +3588,7 @@
drawColumnBorders(p);
if ((m_Doc->guidesPrefs().layerMarkersShown) && (m_Doc->layerCount() > 1) && (!m_Doc->layerOutline(LayerID)) && (!m_Doc->drawAsPreview))
{
- p->setPen(Qt::black, 0.5/ p->zoomFactor(), Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
+ p->setPen(Qt::black, 0, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
p->setPenOpacity(1.0);
p->setBrush(m_Doc->layerMarker(LayerID));
p->setBrushOpacity(1.0);
@@ -3600,14 +3596,12 @@
double ofwh = 10;
double ofx = Width - ofwh/2;
double ofy = Height - ofwh*3;
- p->drawRect(ofx, ofy, ofwh, ofwh);
+ p->drawSharpRect(ofx, ofy, ofwh, ofwh);
}
//if (m_Doc->selection->findItem(this)!=-1)
// drawLockedMarker(p);
}
-// Tinput = false;
FrameOnly = false;
-// p->setAntialiasing(true);
p->restore();
}
@@ -4548,7 +4542,7 @@
void PageItem_TextFrame::drawColumnBorders(ScPainter *p)
{
- p->setPen(Qt::black, 0.5/ p->zoomFactor(), Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
+ p->setPen(Qt::black, 0, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
p->setPenOpacity(1.0);
p->setBrush(Qt::white);
p->setBrushOpacity(1.0);
@@ -4562,16 +4556,16 @@
if (lineColor() != CommonStrings::None)
lineCorr = m_lineWidth / 2.0;
if (TExtra + lineCorr!=0.0)
- p->drawLine(FPoint(0, TExtra + lineCorr), FPoint(Width, TExtra + lineCorr));
+ p->drawSharpLine(FPoint(0, TExtra + lineCorr), FPoint(Width, TExtra + lineCorr));
if (BExtra + lineCorr!=0.0)
- p->drawLine(FPoint(0, Height - BExtra - lineCorr), FPoint(Width, Height - BExtra - lineCorr));
+ p->drawSharpLine(FPoint(0, Height - BExtra - lineCorr), FPoint(Width, Height - BExtra - lineCorr));
while(curCol < Cols)
{
colLeft=(colWidth + ColGap) * curCol + Extra + lineCorr;
if (colLeft != 0.0)
- p->drawLine(FPoint(colLeft, 0), FPoint(colLeft, 0+Height));
+ p->drawSharpLine(FPoint(colLeft, 0), FPoint(colLeft, 0+Height));
if (colLeft + colWidth != Width)
- p->drawLine(FPoint(colLeft+colWidth, 0), FPoint(colLeft+colWidth, 0+Height));
+ p->drawSharpLine(FPoint(colLeft+colWidth, 0), FPoint(colLeft+colWidth, 0+Height));
++curCol;
}
Modified: trunk/Scribus/scribus/scpainter.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17790&path=/trunk/Scribus/scribus/scpainter.cpp
==============================================================================
--- trunk/Scribus/scribus/scpainter.cpp (original)
+++ trunk/Scribus/scribus/scpainter.cpp Sun Oct 7 09:36:29 2012
@@ -2015,6 +2015,77 @@
cairo_close_path( m_cr );
}
+void ScPainter::setupSharpPolygon(FPointArray *points, bool closed)
+{
+ bool nPath = true;
+ bool first = true;
+ FPoint np, np1, np2, np3, np4, firstP;
+
+ if (points->size() <= 3)
+ return;
+
+ newPath();
+ for (uint poi=0; poi<points->size()-3; poi += 4)
+ {
+ if (points->point(poi).x() > 900000)
+ {
+ nPath = true;
+ continue;
+ }
+ if (nPath)
+ {
+ np = points->point(poi);
+ if ((!first) && (closed) && (np4 == firstP))
+ cairo_close_path( m_cr );
+ sharpLineHelper(np);
+ cairo_move_to( m_cr, np.x(), np.y());
+ first = nPath = false;
+ firstP = np4 = np;
+ }
+ np = points->point(poi);
+ np1 = points->point(poi + 1);
+ np2 = points->point(poi + 3);
+ np3 = points->point(poi + 2);
+ if (np4 == np3)
+ continue;
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 9, 6)
+ if ((np == np1) && (np2 == np3))
+ {
+ sharpLineHelper(np3);
+ cairo_line_to( m_cr, np3.x(), np3.y());
+ }
+ else
+#endif
+ cairo_curve_to(m_cr, np1.x(), np1.y(), np2.x(), np2.y(), np3.x(), np3.y());
+ np4 = np3;
+ }
+ if (closed)
+ cairo_close_path( m_cr );
+}
+
+void ScPainter::sharpLineHelper(FPoint &pp)
+{
+ double x1 = pp.x();
+ double y1 = pp.y();
+ cairo_user_to_device (m_cr, &x1, &y1);
+ x1 = floor(x1) + 0.5;
+ y1 = floor(y1) + 0.5;
+ cairo_device_to_user (m_cr, &x1, &y1);
+ pp.setXY(x1, y1);
+}
+
+void ScPainter::sharpLineHelper(QPointF &pp)
+{
+ double x1 = pp.x();
+ double y1 = pp.y();
+ cairo_user_to_device (m_cr, &x1, &y1);
+ x1 = floor(x1) + 0.5;
+ y1 = floor(y1) + 0.5;
+ cairo_device_to_user (m_cr, &x1, &y1);
+ pp.setX(x1);
+ pp.setY(y1);
+}
+
void ScPainter::drawPolygon()
{
fillPath();
@@ -2041,16 +2112,51 @@
strokePath();
}
+void ScPainter::drawSharpLine(FPoint start, FPoint end)
+{
+ newPath();
+ sharpLineHelper(start);
+ sharpLineHelper(end);
+ moveTo(start.x(), start.y());
+ lineTo(end.x(), end.y());
+ strokePath();
+}
+
+void ScPainter::drawSharpLine(QPointF start, QPointF end)
+{
+ newPath();
+ sharpLineHelper(start);
+ sharpLineHelper(end);
+ moveTo(start.x(), start.y());
+ lineTo(end.x(), end.y());
+ strokePath();
+}
+
void ScPainter::drawRect(double x, double y, double w, double h)
{
newPath();
cairo_rectangle(m_cr, x, y, w, h);
-// moveTo( x, y );
-// lineTo( x+w, y );
-// lineTo( x+w, y+h );
-// lineTo( x, y+h );
-// lineTo( x, y );
-// cairo_close_path( m_cr );
+ fillPath();
+ strokePath();
+}
+
+void ScPainter::drawSharpRect(double x, double y, double w, double h)
+{
+ newPath();
+ double x1 = x;
+ double y1 = y;
+ double w1 = w;
+ double h1 = h;
+ // see http://www.cairographics.org/FAQ/#sharp_lines
+ cairo_user_to_device (m_cr, &x1, &y1);
+ cairo_user_to_device (m_cr, &w1, &h1);
+ x1 = floor(x1) + 0.5;
+ y1 = floor(y1) + 0.5;
+ w1 = floor(w1) + 0.5;
+ h1 = floor(h1) + 0.5;
+ cairo_device_to_user (m_cr, &x1, &y1);
+ cairo_device_to_user (m_cr, &w1, &h1);
+ cairo_rectangle(m_cr, x1, y1, w1, h1);
fillPath();
strokePath();
}
Modified: trunk/Scribus/scribus/scpainter.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17790&path=/trunk/Scribus/scribus/scpainter.h
==============================================================================
--- trunk/Scribus/scribus/scpainter.h (original)
+++ trunk/Scribus/scribus/scpainter.h Sun Oct 7 09:36:29 2012
@@ -82,11 +82,17 @@
virtual void drawImage( QImage *image);
virtual void setupPolygon(FPointArray *points, bool closed = true);
+ virtual void setupSharpPolygon(FPointArray *points, bool closed = true);
+ virtual void sharpLineHelper(FPoint &pp);
+ virtual void sharpLineHelper(QPointF &pp);
virtual void drawPolygon();
virtual void drawPolyLine();
virtual void drawLine(FPoint start, FPoint end);
virtual void drawLine(const QPointF& start, const QPointF& end);
+ virtual void drawSharpLine(FPoint start, FPoint end);
+ virtual void drawSharpLine(QPointF start, QPointF end);
virtual void drawRect(double, double, double, double);
+ virtual void drawSharpRect(double x, double y, double w, double h);
virtual void drawText(QRectF area, QString text, bool filled = true, int align = 0);
virtual void drawShadePanel(const QRect &r, const QPalette &pal, bool sunken, int lineWidth);
More information about the scribus-commit
mailing list