Fix failing tests
@ -61,12 +61,15 @@ def colorDiff(c1, c2):
|
|||||||
|
|
||||||
|
|
||||||
def imageFromPath(path):
|
def imageFromPath(path):
|
||||||
if (path[:7] == 'https://' or path[:7] == 'file://'):
|
print(path)
|
||||||
|
if (path[:8] == 'https://' or path[:7] == 'file://'):
|
||||||
# fetch remote image
|
# fetch remote image
|
||||||
|
print('fetching remote!')
|
||||||
data = urllib.request.urlopen(path).read()
|
data = urllib.request.urlopen(path).read()
|
||||||
image = QImage()
|
image = QImage()
|
||||||
image.loadFromData(data)
|
image.loadFromData(data)
|
||||||
else:
|
else:
|
||||||
|
print('using local!')
|
||||||
image = QImage(path)
|
image = QImage(path)
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|||||||
@ -83,7 +83,9 @@ void QgsComposerShape::setShapeStyleSymbol( QgsFillSymbol* symbol )
|
|||||||
|
|
||||||
void QgsComposerShape::refreshSymbol()
|
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();
|
updateBoundingRect();
|
||||||
|
|
||||||
update();
|
update();
|
||||||
@ -102,7 +104,9 @@ void QgsComposerShape::createDefaultShapeStyleSymbol()
|
|||||||
properties.insert( QStringLiteral( "joinstyle" ), QStringLiteral( "miter" ) );
|
properties.insert( QStringLiteral( "joinstyle" ), QStringLiteral( "miter" ) );
|
||||||
mShapeStyleSymbol = QgsFillSymbol::createSimple( properties );
|
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();
|
updateBoundingRect();
|
||||||
|
|
||||||
emit frameChanged();
|
emit frameChanged();
|
||||||
|
|||||||
@ -488,15 +488,32 @@ void QgsComposerUtils::drawText( QPainter *painter, const QRectF &rect, const QS
|
|||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsRenderContext QgsComposerUtils::createRenderContextForMap( QgsComposerMap* map, QPainter* painter )
|
QgsRenderContext QgsComposerUtils::createRenderContextForMap( QgsComposerMap* map, QPainter* painter, double dpi )
|
||||||
{
|
{
|
||||||
if ( !map )
|
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
|
// 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;
|
double dotsPerMM = dpi / 25.4;
|
||||||
|
|
||||||
// get map settings from reference map
|
// get map settings from reference map
|
||||||
|
|||||||
@ -252,7 +252,7 @@ class CORE_EXPORT QgsComposerUtils
|
|||||||
* @note added in QGIS 3.0
|
* @note added in QGIS 3.0
|
||||||
* @see createRenderContextForComposition()
|
* @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.
|
* 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()
|
void QgsPaperItem::calculatePageMargin()
|
||||||
{
|
{
|
||||||
//get max bleed from symbol
|
//get max bleed from symbol
|
||||||
double maxBleed = QgsSymbolLayerUtils::estimateMaxSymbolBleed( mComposition->pageStyleSymbol(),
|
QgsRenderContext rc = QgsComposerUtils::createRenderContextForMap( mComposition->referenceMap(), nullptr, mComposition->printResolution() );
|
||||||
QgsComposerUtils::createRenderContextForComposition( mComposition, nullptr ) );
|
double maxBleedPixels = QgsSymbolLayerUtils::estimateMaxSymbolBleed( mComposition->pageStyleSymbol(), rc );
|
||||||
|
|
||||||
//Now subtract 1 pixel to prevent semi-transparent borders at edge of solid page caused by
|
//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,
|
//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
|
//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
|
bool QgsPaperItem::writeXml( QDomElement& elem, QDomDocument & doc ) const
|
||||||
|
|||||||
@ -21,6 +21,7 @@ from qgis.core import (QgsTextAnnotation,
|
|||||||
QgsRenderContext,
|
QgsRenderContext,
|
||||||
QgsCoordinateReferenceSystem,
|
QgsCoordinateReferenceSystem,
|
||||||
QgsRectangle,
|
QgsRectangle,
|
||||||
|
QgsMultiRenderChecker,
|
||||||
QgsRenderChecker,
|
QgsRenderChecker,
|
||||||
QgsPoint,
|
QgsPoint,
|
||||||
QgsVectorLayer,
|
QgsVectorLayer,
|
||||||
@ -160,12 +161,12 @@ class TestQgsAnnotation(unittest.TestCase):
|
|||||||
temp_dir = QDir.tempPath() + '/'
|
temp_dir = QDir.tempPath() + '/'
|
||||||
file_name = temp_dir + 'annotation_' + name + ".png"
|
file_name = temp_dir + 'annotation_' + name + ".png"
|
||||||
image.save(file_name, "PNG")
|
image.save(file_name, "PNG")
|
||||||
checker = QgsRenderChecker()
|
checker = QgsMultiRenderChecker()
|
||||||
checker.setControlPathPrefix("annotations")
|
checker.setControlPathPrefix("annotations")
|
||||||
checker.setControlName("expected_" + reference_image)
|
checker.setControlName("expected_" + reference_image)
|
||||||
checker.setRenderedImage(file_name)
|
checker.setRenderedImage(file_name)
|
||||||
checker.setColorTolerance(2)
|
checker.setColorTolerance(2)
|
||||||
result = checker.compareImages(name, 20)
|
result = checker.runTest(name, 20)
|
||||||
self.report += checker.report()
|
self.report += checker.report()
|
||||||
print((self.report))
|
print((self.report))
|
||||||
return result
|
return result
|
||||||
|
|||||||
@ -21,7 +21,8 @@ from qgis.core import (QgsTextAnnotation,
|
|||||||
QgsPoint,
|
QgsPoint,
|
||||||
QgsVectorLayer,
|
QgsVectorLayer,
|
||||||
QgsFeature,
|
QgsFeature,
|
||||||
QgsGeometry)
|
QgsGeometry,
|
||||||
|
QgsFillSymbol)
|
||||||
from qgis.gui import (QgsMapCanvas,
|
from qgis.gui import (QgsMapCanvas,
|
||||||
QgsMapCanvasAnnotationItem)
|
QgsMapCanvasAnnotationItem)
|
||||||
|
|
||||||
@ -86,7 +87,7 @@ class TestQgsMapCanvasAnnotationItem(unittest.TestCase):
|
|||||||
a = QgsTextAnnotation()
|
a = QgsTextAnnotation()
|
||||||
a.setFrameSize(QSizeF(300, 200))
|
a.setFrameSize(QSizeF(300, 200))
|
||||||
a.setHasFixedMapPosition(False)
|
a.setHasFixedMapPosition(False)
|
||||||
a.setFrameBorderWidth(0)
|
a.setFillSymbol(QgsFillSymbol.createSimple({'color': 'blue', 'width_border': '0'}))
|
||||||
|
|
||||||
canvas = QgsMapCanvas()
|
canvas = QgsMapCanvas()
|
||||||
canvas.setDestinationCrs(QgsCoordinateReferenceSystem(4326))
|
canvas.setDestinationCrs(QgsCoordinateReferenceSystem(4326))
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 7.2 KiB |
BIN
tests/testdata/control_images/annotations/expected_html_nofeature/travis/expected_html_nofeature.png
vendored
Normal file
|
After Width: | Height: | Size: 7.8 KiB |
BIN
tests/testdata/control_images/annotations/expected_svg_annotation/expected_svg_annotation_mask.png
vendored
Normal file
|
After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 8.7 KiB |