Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix for problems with floating point outline width for hard markers
git-svn-id: http://svn.osgeo.org/qgis/trunk@8447 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 17, 2008
1 parent f67d600 commit 0cfd8b3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
24 changes: 12 additions & 12 deletions src/core/symbology/qgsmarkercatalogue.cpp
Expand Up @@ -91,7 +91,7 @@ QgsMarkerCatalogue *QgsMarkerCatalogue::instance()
return QgsMarkerCatalogue::mMarkerCatalogue;
}

QImage QgsMarkerCatalogue::imageMarker ( QString fullName, int size, QPen pen, QBrush brush, bool qtBug )
QImage QgsMarkerCatalogue::imageMarker ( QString fullName, double size, QPen pen, QBrush brush, bool qtBug )
{

//
Expand All @@ -100,15 +100,15 @@ QImage QgsMarkerCatalogue::imageMarker ( QString fullName, int size, QPen pen, Q
QImage myImage;
if ( fullName.left(5) == "hard:" )
{
myImage = QImage (size, size, QImage::Format_ARGB32_Premultiplied);
myImage = QImage (size + 1, size + 1, QImage::Format_ARGB32_Premultiplied);
}
else
{
// TODO Change this logic so width is size and height is same
// proportion of scale factor as in oritignal SVG TS XXX
if (size < 1) size=1;
//QPixmap myPixmap = QPixmap(width,height);
myImage = QImage(size,size, QImage::Format_ARGB32_Premultiplied);
myImage = QImage(size ,size , QImage::Format_ARGB32_Premultiplied);
}

// starting with transparent QImage
Expand Down Expand Up @@ -141,7 +141,7 @@ QImage QgsMarkerCatalogue::imageMarker ( QString fullName, int size, QPen pen, Q
return QImage(); // empty
}

QPicture QgsMarkerCatalogue::pictureMarker ( QString fullName, int size, QPen pen, QBrush brush, bool qtBug )
QPicture QgsMarkerCatalogue::pictureMarker ( QString fullName, double size, QPen pen, QBrush brush, bool qtBug )
{

//
Expand Down Expand Up @@ -182,42 +182,42 @@ QPicture QgsMarkerCatalogue::pictureMarker ( QString fullName, int size, QPen pe
return QPicture(); // empty
}

void QgsMarkerCatalogue::svgMarker ( QPainter * thepPainter, QString filename, int scaleFactor)
void QgsMarkerCatalogue::svgMarker ( QPainter * thepPainter, QString filename, double scaleFactor)
{
QSvgRenderer mySVG;
mySVG.load(filename);
mySVG.render(thepPainter);
}

void QgsMarkerCatalogue::hardMarker (QPainter * thepPainter, QString name, int s, QPen pen, QBrush brush, bool qtBug )
void QgsMarkerCatalogue::hardMarker (QPainter * thepPainter, QString name, double s, QPen pen, QBrush brush, bool qtBug )
{
// Size of polygon symbols is calculated so that the boundingbox is circumscribed
// around a circle with diameter mPointSize

int half = s/2; // number of points from center
double half = s/2; // number of points from center

QgsDebugMsg(QString("Hard marker size %1").arg(s));

// Find out center coordinates.
int x_c = s/2;
int y_c = x_c;
double x_c = s/2;
double y_c = x_c;

// Picture
QPicture picture;
thepPainter->begin(&picture);
thepPainter->setRenderHint(QPainter::Antialiasing);

// Also width must be odd otherwise there are discrepancies visible in canvas!
int lw = (int)(2*floor((double)pen.width()/2)+1); // -> lw > 0
pen.setWidth(lw);
double lw = pen.widthF();//(int)(2*floor((double)pen.widthF()/2)+1); // -> lw > 0
pen.setWidthF(lw);
thepPainter->setPen ( pen );
thepPainter->setBrush( brush);
QRect box;

// Circle radius, is used for other figures also, when compensating for line
// width is necessary.

int r = (s-2*lw)/2-1;
double r = (s-2*lw)/2-1;
QgsDebugMsg(QString("Hard marker radius %1").arg(r));

if ( name == "circle" )
Expand Down
8 changes: 4 additions & 4 deletions src/core/symbology/qgsmarkercatalogue.h
Expand Up @@ -43,16 +43,16 @@ class CORE_EXPORT QgsMarkerCatalogue
/** Returns pixmap of the marker
* \param fullName full name, e.g. hard:circle, svg:/home/usr1/marker1.svg
*/
QImage imageMarker (QString fullName, int size, QPen pen, QBrush brush, bool qtBug = true );
QImage imageMarker (QString fullName, double size, QPen pen, QBrush brush, bool qtBug = true );

/** Returns qpicture of the marker
* \param fullName full name, e.g. hard:circle, svg:/home/usr1/marker1.svg
*/
QPicture pictureMarker (QString fullName, int size, QPen pen, QBrush brush, bool qtBug = true );
QPicture pictureMarker (QString fullName, double size, QPen pen, QBrush brush, bool qtBug = true );

/** Returns a pixmap given a filename of a svg marker
* NOTE: this method needs to be public static for QgsMarkerDialog::visualizeMarkers */
static void svgMarker (QPainter * thepPainter, QString name, int size );
static void svgMarker (QPainter * thepPainter, QString name, double size );
private:

/**Constructor*/
Expand All @@ -64,7 +64,7 @@ class CORE_EXPORT QgsMarkerCatalogue
QStringList mList;

/** Hard coded */
void hardMarker (QPainter * thepPainter, QString name, int size, QPen pen, QBrush brush, bool qtBug = true );
void hardMarker (QPainter * thepPainter, QString name, double size, QPen pen, QBrush brush, bool qtBug = true );

};

Expand Down
3 changes: 1 addition & 2 deletions src/core/symbology/qgssymbol.cpp
Expand Up @@ -384,8 +384,7 @@ void QgsSymbol::cache2( double widthScale, QColor selectionColor )
//std::cerr << "QgsSymbol::cache2 widthScale = " << widthScale << std::endl;

QPen pen = mPen;
pen.setWidth ( (int) ( widthScale * pen.width() ) );

pen.setWidthF(widthScale * pen.widthF());

mPointSymbolImage2 = QgsMarkerCatalogue::instance()->imageMarker ( mPointSymbolName, mPointSize * widthScale,
pen, mBrush, false );
Expand Down

0 comments on commit 0cfd8b3

Please sign in to comment.