@@ -930,7 +930,7 @@ void QgsDxfExport::writeBlocks()
930
930
writeGroup ( 1 , QLatin1String ( " " ) );
931
931
932
932
// maplayer 0 -> block receives layer from INSERT statement
933
- ml->writeDxf ( *this , mapUnitScaleFactor ( mSymbologyScale , ml->sizeUnit (), mMapUnits ), QStringLiteral ( " 0" ), ctx );
933
+ ml->writeDxf ( *this , mapUnitScaleFactor ( mSymbologyScale , ml->sizeUnit (), mMapUnits , ctx. renderContext (). mapToPixel (). mapUnitsPerPixel () ), QStringLiteral ( " 0" ), ctx );
934
934
935
935
writeGroup ( 0 , QStringLiteral ( " ENDBLK" ) );
936
936
writeHandle ();
@@ -966,6 +966,9 @@ void QgsDxfExport::writeEntities()
966
966
ctx.setMapToPixel ( QgsMapToPixel ( 1.0 / mFactor , mExtent .center ().x (), mExtent .center ().y (), mExtent .width () * mFactor ,
967
967
mExtent .height () * mFactor , 0 ) );
968
968
969
+ ctx.expressionContext ().appendScope ( QgsExpressionContextUtils::projectScope ( QgsProject::instance () ) );
970
+ ctx.expressionContext ().appendScope ( QgsExpressionContextUtils::globalScope () );
971
+
969
972
// label engine
970
973
QgsLabelingEngine engine;
971
974
engine.setMapSettings ( mMapSettings );
@@ -3435,7 +3438,7 @@ void QgsDxfExport::writePoint( const QgsPoint &pt, const QString &layer, const Q
3435
3438
const QgsMarkerSymbolLayer *msl = dynamic_cast < const QgsMarkerSymbolLayer * >( symbolLayer );
3436
3439
if ( msl && symbol )
3437
3440
{
3438
- if ( symbolLayer->writeDxf ( *this , mapUnitScaleFactor ( mSymbologyScale , msl->sizeUnit (), mMapUnits ), layer, ctx, QPointF ( pt.x (), pt.y () ) ) )
3441
+ if ( symbolLayer->writeDxf ( *this , mapUnitScaleFactor ( mSymbologyScale , msl->sizeUnit (), mMapUnits , ctx. renderContext (). mapToPixel (). mapUnitsPerPixel () ), layer, ctx, QPointF ( pt.x (), pt.y () ) ) )
3439
3442
{
3440
3443
return ;
3441
3444
}
@@ -3982,14 +3985,53 @@ QgsRenderContext QgsDxfExport::renderContext() const
3982
3985
return context;
3983
3986
}
3984
3987
3985
- double QgsDxfExport::mapUnitScaleFactor ( double scale , QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits )
3988
+ double QgsDxfExport::mapUnitScaleFactor ( double scaleDenominator , QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits, double mapUnitsPerPixel )
3986
3989
{
3987
3990
if ( symbolUnits == QgsUnitTypes::RenderMapUnits )
3988
3991
{
3989
3992
return 1.0 ;
3990
3993
}
3991
- // MM symbol unit
3992
- return scale * QgsUnitTypes::fromUnitToUnitFactor ( QgsUnitTypes::DistanceMeters, mapUnits ) / 1000.0 ;
3994
+ else if ( symbolUnits == QgsUnitTypes::RenderMillimeters )
3995
+ {
3996
+ return ( scaleDenominator * QgsUnitTypes::fromUnitToUnitFactor ( QgsUnitTypes::DistanceMeters, mapUnits ) / 1000.0 );
3997
+ }
3998
+ else if ( symbolUnits == QgsUnitTypes::RenderPixels )
3999
+ {
4000
+ return mapUnitsPerPixel;
4001
+ }
4002
+ return 1.0 ;
4003
+ }
4004
+
4005
+ void QgsDxfExport::clipValueToMapUnitScale ( double &value, const QgsMapUnitScale &scale, double pixelToMMFactor ) const
4006
+ {
4007
+ if ( !scale.minSizeMMEnabled && !scale.maxSizeMMEnabled )
4008
+ {
4009
+ return ;
4010
+ }
4011
+
4012
+ double mapUnitsPerPixel = mMapSettings .mapToPixel ().mapUnitsPerPixel ();
4013
+
4014
+ double minSizeMU = -DBL_MAX;
4015
+ if ( scale.minSizeMMEnabled )
4016
+ {
4017
+ minSizeMU = scale.minSizeMM * pixelToMMFactor * mapUnitsPerPixel;
4018
+ }
4019
+ if ( !qgsDoubleNear ( scale.minScale , 0.0 ) )
4020
+ {
4021
+ minSizeMU = qMax ( minSizeMU, value );
4022
+ }
4023
+ value = qMax ( value, minSizeMU );
4024
+
4025
+ double maxSizeMU = DBL_MAX;
4026
+ if ( scale.maxSizeMMEnabled )
4027
+ {
4028
+ maxSizeMU = scale.maxSizeMM * pixelToMMFactor * mapUnitsPerPixel;
4029
+ }
4030
+ if ( !qgsDoubleNear ( scale.maxScale , 0.0 ) )
4031
+ {
4032
+ maxSizeMU = qMin ( maxSizeMU, value );
4033
+ }
4034
+ value = qMin ( value, maxSizeMU );
3993
4035
}
3994
4036
3995
4037
QList< QPair< QgsSymbolLayer *, QgsSymbol * > > QgsDxfExport::symbolLayers ( QgsRenderContext &context )
@@ -4122,7 +4164,7 @@ void QgsDxfExport::writeLinetype( const QString &styleName, const QVector<qreal>
4122
4164
QVector<qreal>::const_iterator dashIt = pattern.constBegin ();
4123
4165
for ( ; dashIt != pattern.constEnd (); ++dashIt )
4124
4166
{
4125
- length += ( *dashIt * mapUnitScaleFactor ( mSymbologyScale , u, mMapUnits ) );
4167
+ length += ( *dashIt * mapUnitScaleFactor ( mSymbologyScale , u, mMapUnits , mMapSettings . mapToPixel (). mapUnitsPerPixel () ) );
4126
4168
}
4127
4169
4128
4170
writeGroup ( 0 , QStringLiteral ( " LTYPE" ) );
@@ -4143,7 +4185,7 @@ void QgsDxfExport::writeLinetype( const QString &styleName, const QVector<qreal>
4143
4185
{
4144
4186
// map units or mm?
4145
4187
double segmentLength = ( isGap ? -*dashIt : *dashIt );
4146
- segmentLength *= mapUnitScaleFactor ( mSymbologyScale , u, mMapUnits );
4188
+ segmentLength *= mapUnitScaleFactor ( mSymbologyScale , u, mMapUnits , mMapSettings . mapToPixel (). mapUnitsPerPixel () );
4147
4189
writeGroup ( 49 , segmentLength );
4148
4190
writeGroup ( 74 , 0 );
4149
4191
isGap = !isGap;
0 commit comments