Skip to content
Permalink
Browse files

Fix failing tests

  • Loading branch information
nyalldawson committed Jan 30, 2017
1 parent 1c1dae3 commit 6bffa17cc26c017c49dea714407f9a2bea42b24a
@@ -61,12 +61,15 @@ def colorDiff(c1, c2):


def imageFromPath(path):
if (path[:7] == 'https://' or path[:7] == 'file://'):
print(path)
if (path[:8] == 'https://' or path[:7] == 'file://'):
# fetch remote image
print('fetching remote!')
data = urllib.request.urlopen(path).read()
image = QImage()
image.loadFromData(data)
else:
print('using local!')
image = QImage(path)
return image

@@ -83,7 +83,9 @@ void QgsComposerShape::setShapeStyleSymbol( QgsFillSymbol* symbol )

void QgsComposerShape::refreshSymbol()
{
mMaxSymbolBleed = QgsSymbolLayerUtils::estimateMaxSymbolBleed( mShapeStyleSymbol, QgsComposerUtils::createRenderContextForComposition( mComposition, nullptr ) );
QgsRenderContext rc = QgsComposerUtils::createRenderContextForMap( mComposition->referenceMap(), nullptr, mComposition->printResolution() );
mMaxSymbolBleed = ( 25.4 / mComposition->printResolution() ) * QgsSymbolLayerUtils::estimateMaxSymbolBleed( mShapeStyleSymbol, rc );

updateBoundingRect();

update();
@@ -102,7 +104,9 @@ void QgsComposerShape::createDefaultShapeStyleSymbol()
properties.insert( QStringLiteral( "joinstyle" ), QStringLiteral( "miter" ) );
mShapeStyleSymbol = QgsFillSymbol::createSimple( properties );

mMaxSymbolBleed = QgsSymbolLayerUtils::estimateMaxSymbolBleed( mShapeStyleSymbol, QgsComposerUtils::createRenderContextForComposition( mComposition, nullptr ) );
QgsRenderContext rc = QgsComposerUtils::createRenderContextForMap( mComposition->referenceMap(), nullptr, mComposition->printResolution() );
mMaxSymbolBleed = ( 25.4 / mComposition->printResolution() ) * QgsSymbolLayerUtils::estimateMaxSymbolBleed( mShapeStyleSymbol, rc );

updateBoundingRect();

emit frameChanged();
@@ -488,15 +488,32 @@ void QgsComposerUtils::drawText( QPainter *painter, const QRectF &rect, const QS
painter->restore();
}

QgsRenderContext QgsComposerUtils::createRenderContextForMap( QgsComposerMap* map, QPainter* painter )
QgsRenderContext QgsComposerUtils::createRenderContextForMap( QgsComposerMap* map, QPainter* painter, double dpi )
{
if ( !map )
{
return QgsRenderContext::fromQPainter( painter );
QgsRenderContext context;
context.setPainter( painter );
if ( dpi < 0 && painter && painter->device() )
{
context.setScaleFactor( painter->device()->logicalDpiX() / 25.4 );
}
else if ( dpi > 0 )
{
context.setScaleFactor( dpi / 25.4 );
}
else
{
context.setScaleFactor( 3.465 ); //assume 88 dpi as standard value
}
return context;
}

// default to 88 dpi if no painter specified
int dpi = ( painter && painter->device() ) ? painter->device()->logicalDpiX() : 88;
if ( dpi < 0 )
{
dpi = ( painter && painter->device() ) ? painter->device()->logicalDpiX() : 88;
}
double dotsPerMM = dpi / 25.4;

// get map settings from reference map
@@ -252,7 +252,7 @@ class CORE_EXPORT QgsComposerUtils
* @note added in QGIS 3.0
* @see createRenderContextForComposition()
*/
static QgsRenderContext createRenderContextForMap( QgsComposerMap* map, QPainter* painter );
static QgsRenderContext createRenderContextForMap( QgsComposerMap* map, QPainter* painter, double dpi = -1 );

/**
* Creates a render context suitable for the specified composition and QPainter destination.
@@ -201,13 +201,16 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
void QgsPaperItem::calculatePageMargin()
{
//get max bleed from symbol
double maxBleed = QgsSymbolLayerUtils::estimateMaxSymbolBleed( mComposition->pageStyleSymbol(),
QgsComposerUtils::createRenderContextForComposition( mComposition, nullptr ) );
QgsRenderContext rc = QgsComposerUtils::createRenderContextForMap( mComposition->referenceMap(), nullptr, mComposition->printResolution() );
double maxBleedPixels = QgsSymbolLayerUtils::estimateMaxSymbolBleed( mComposition->pageStyleSymbol(), rc );

//Now subtract 1 pixel to prevent semi-transparent borders at edge of solid page caused by
//anti-aliased painting. This may cause a pixel to be cropped from certain edge lines/symbols,
//but that can be counteracted by adding a dummy transparent line symbol layer with a wider line width
mPageMargin = maxBleed - ( 25.4 / mComposition->printResolution() );
maxBleedPixels--;

double maxBleedMm = ( 25.4 / mComposition->printResolution() ) * maxBleedPixels;
mPageMargin = maxBleedMm;
}

bool QgsPaperItem::writeXml( QDomElement& elem, QDomDocument & doc ) const
@@ -21,6 +21,7 @@
QgsRenderContext,
QgsCoordinateReferenceSystem,
QgsRectangle,
QgsMultiRenderChecker,
QgsRenderChecker,
QgsPoint,
QgsVectorLayer,
@@ -160,12 +161,12 @@ def imageCheck(self, name, reference_image, image):
temp_dir = QDir.tempPath() + '/'
file_name = temp_dir + 'annotation_' + name + ".png"
image.save(file_name, "PNG")
checker = QgsRenderChecker()
checker = QgsMultiRenderChecker()
checker.setControlPathPrefix("annotations")
checker.setControlName("expected_" + reference_image)
checker.setRenderedImage(file_name)
checker.setColorTolerance(2)
result = checker.compareImages(name, 20)
result = checker.runTest(name, 20)
self.report += checker.report()
print((self.report))
return result
@@ -21,7 +21,8 @@
QgsPoint,
QgsVectorLayer,
QgsFeature,
QgsGeometry)
QgsGeometry,
QgsFillSymbol)
from qgis.gui import (QgsMapCanvas,
QgsMapCanvasAnnotationItem)

@@ -86,7 +87,7 @@ def testSize(self):
a = QgsTextAnnotation()
a.setFrameSize(QSizeF(300, 200))
a.setHasFixedMapPosition(False)
a.setFrameBorderWidth(0)
a.setFillSymbol(QgsFillSymbol.createSimple({'color': 'blue', 'width_border': '0'}))

canvas = QgsMapCanvas()
canvas.setDestinationCrs(QgsCoordinateReferenceSystem(4326))
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 6bffa17

Please sign in to comment.
You can’t perform that action at this time.