@@ -467,7 +467,7 @@ void QgsDxfExport::writeTables()
467
467
{
468
468
writeGroup ( 0 , " LAYER" );
469
469
QString layerName = *layerIt ? ( *layerIt )->name () : " " ;
470
- writeGroup ( 2 , layerName );
470
+ writeGroup ( 2 , dxfLayerName ( layerName ) );
471
471
writeGroup ( 70 , 64 );
472
472
writeGroup ( 62 , 1 );
473
473
writeGroup ( 6 , " CONTINUOUS" );
@@ -577,7 +577,7 @@ void QgsDxfExport::writeEntities()
577
577
{
578
578
if ( mSymbologyExport == NoSymbology )
579
579
{
580
- addFeature ( fet, vl->name (), 0 , 0 ); // no symbology at all
580
+ addFeature ( fet, dxfLayerName ( vl->name () ), 0 , 0 ); // no symbology at all
581
581
}
582
582
else
583
583
{
@@ -597,7 +597,7 @@ void QgsDxfExport::writeEntities()
597
597
{
598
598
continue ;
599
599
}
600
- addFeature ( fet, vl->name (), s->symbolLayer ( 0 ), s );
600
+ addFeature ( fet, dxfLayerName ( vl->name () ), s->symbolLayer ( 0 ), s );
601
601
}
602
602
}
603
603
renderer->stopRender ( ctx );
@@ -1331,6 +1331,38 @@ QString QgsDxfExport::lineNameFromPenStyle( Qt::PenStyle style )
1331
1331
}
1332
1332
}
1333
1333
1334
+ QString QgsDxfExport::dxfLayerName ( const QString& name )
1335
+ {
1336
+ // dxf layers can be max 31 characters long
1337
+ QString layerName = name.left ( 31 );
1338
+
1339
+ // allowed characters are 0-9, A-Z, $, -, _
1340
+ for ( int i = 0 ; i < layerName.size (); ++i )
1341
+ {
1342
+ QChar c = layerName.at ( i );
1343
+ if ( c > 122 )
1344
+ {
1345
+ layerName[i] = ' _' ;
1346
+ continue ;
1347
+ }
1348
+
1349
+ if ( c.isNumber () )
1350
+ {
1351
+ continue ;
1352
+ }
1353
+ if ( c == ' $' || c == ' -' || c == ' _' )
1354
+ {
1355
+ continue ;
1356
+ }
1357
+
1358
+ if ( !c.isLetter () )
1359
+ {
1360
+ layerName[i] = ' _' ;
1361
+ }
1362
+ }
1363
+ return layerName;
1364
+ }
1365
+
1334
1366
/* *****************************************************Test with AC_1018 methods***************************************************************/
1335
1367
1336
1368
void QgsDxfExport::writeHeaderAC1018 ( QTextStream& stream )
0 commit comments