@@ -43,6 +43,7 @@ class TestQgsDxfExport : public QObject
43
43
void testPolygons ();
44
44
void testMtext ();
45
45
void testMTextNoSymbology (); // tests if label export works if layer has vector renderer type 'no symbols'
46
+ void testMTextEscapeSpaces ();
46
47
void testText ();
47
48
48
49
private:
@@ -82,6 +83,7 @@ void TestQgsDxfExport::init()
82
83
mPointLayerNoSymbols = new QgsVectorLayer ( filename, QStringLiteral ( " points" ), QStringLiteral ( " ogr" ) );
83
84
QVERIFY ( mPointLayerNoSymbols ->isValid () );
84
85
mPointLayerNoSymbols ->setRenderer ( new QgsNullSymbolRenderer () );
86
+ mPointLayerNoSymbols ->addExpressionField ( QStringLiteral ( " 'A text with spaces'" ), QgsField ( QStringLiteral ( " Spacestest" ), QVariant::String ) );
85
87
QgsProject::instance ()->addMapLayer ( mPointLayerNoSymbols );
86
88
filename = QStringLiteral ( TEST_DATA_DIR ) + " /lines.shp" ;
87
89
mLineLayer = new QgsVectorLayer ( filename, QStringLiteral ( " lines" ), QStringLiteral ( " ogr" ) );
@@ -193,6 +195,41 @@ void TestQgsDxfExport::testMTextNoSymbology()
193
195
QVERIFY ( testMtext ( mPointLayerNoSymbols , QStringLiteral ( " text_no_symbology_dxf" ) ) );
194
196
}
195
197
198
+ void TestQgsDxfExport::testMTextEscapeSpaces ()
199
+ {
200
+ QgsPalLayerSettings settings;
201
+ settings.fieldName = QStringLiteral ( " Spacestest" );
202
+ QgsTextFormat format;
203
+ format.setFont ( QgsFontUtils::getStandardTestFont ( QStringLiteral ( " Bold" ) ).family () );
204
+ format.setSize ( 12 );
205
+ format.setNamedStyle ( QStringLiteral ( " Bold" ) );
206
+ format.setColor ( QColor ( 200 , 0 , 200 ) );
207
+ settings.setFormat ( format );
208
+ mPointLayerNoSymbols ->setLabeling ( new QgsVectorLayerSimpleLabeling ( settings ) );
209
+ mPointLayerNoSymbols ->setLabelsEnabled ( true );
210
+
211
+ QgsDxfExport d;
212
+ d.addLayers ( QList< QgsDxfExport::DxfLayer >() << QgsDxfExport::DxfLayer ( mPointLayerNoSymbols ) );
213
+
214
+ QgsMapSettings mapSettings;
215
+ QSize size ( 640 , 480 );
216
+ mapSettings.setOutputSize ( size );
217
+ mapSettings.setExtent ( mPointLayerNoSymbols ->extent () );
218
+ mapSettings.setLayers ( QList<QgsMapLayer *>() << mPointLayerNoSymbols );
219
+ mapSettings.setOutputDpi ( 96 );
220
+ mapSettings.setDestinationCrs ( mPointLayerNoSymbols ->crs () );
221
+
222
+ d.setMapSettings ( mapSettings );
223
+ d.setSymbologyScale ( 1000 );
224
+ d.setSymbologyExport ( QgsDxfExport::FeatureSymbology );
225
+
226
+ QString file = getTempFileName ( " mtext_escape_spaces" );
227
+ QFile dxfFile ( file );
228
+ QCOMPARE ( d.writeToFile ( &dxfFile, QStringLiteral ( " CP1252" ) ), 0 );
229
+ dxfFile.close ();
230
+ QVERIFY ( fileContainsText ( file, " \\ fQGIS Vera Sans|i0|b1;\\ H3.81136;A\\ ~text\\ ~with\\ ~spaces" ) );
231
+ }
232
+
196
233
void TestQgsDxfExport::testText ()
197
234
{
198
235
QgsPalLayerSettings settings;
0 commit comments