mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-03 00:02:25 -05:00
Merge pull request #34574 from mhugent/dxf_label_linebreaks
DXF export: handle line breaks in label text
This commit is contained in:
commit
ebfdc2c8b6
@ -2314,10 +2314,14 @@ void QgsDxfExport::drawLabel( const QString &layerId, QgsRenderContext &context,
|
||||
|
||||
if ( mFlags & FlagNoMText )
|
||||
{
|
||||
txt.replace( QChar( QChar::LineFeed ), ' ' );
|
||||
txt.replace( QChar( QChar::CarriageReturn ), ' ' );
|
||||
writeText( dxfLayer, txt, label, tmpLyr, context.expressionContext() );
|
||||
}
|
||||
else
|
||||
{
|
||||
txt.replace( QString( QChar( QChar::CarriageReturn ) ) + QString( QChar( QChar::LineFeed ) ), QStringLiteral( "\\P" ) );
|
||||
txt.replace( QChar( QChar::CarriageReturn ), QStringLiteral( "\\P" ) );
|
||||
txt = txt.replace( wrapchr, QLatin1String( "\\P" ) );
|
||||
txt.replace( " ", "\\~" );
|
||||
|
||||
|
@ -52,6 +52,7 @@ class TestQgsDxfExport : public QObject
|
||||
void testMtext();
|
||||
void testMtext_data();
|
||||
void testMTextEscapeSpaces();
|
||||
void testMTextEscapeLineBreaks();
|
||||
void testText();
|
||||
void testTextAngle();
|
||||
void testTextAlign();
|
||||
@ -398,6 +399,48 @@ void TestQgsDxfExport::testMTextEscapeSpaces()
|
||||
QVERIFY2( fileContainsText( file, "\\fQGIS Vera Sans|i0|b1;\\H3.81136;A\\~text\\~with\\~spaces", &debugInfo ), debugInfo.toUtf8().constData() );
|
||||
}
|
||||
|
||||
void TestQgsDxfExport::testMTextEscapeLineBreaks()
|
||||
{
|
||||
int field = mPointLayerNoSymbols->addExpressionField( QStringLiteral( "'A text with ' || char(13) || char(10) || 'line break'" ), QgsField( QStringLiteral( "linebreaktest" ), QVariant::String ) );
|
||||
|
||||
QgsPalLayerSettings settings;
|
||||
settings.fieldName = QStringLiteral( "linebreaktest" );
|
||||
QgsTextFormat format;
|
||||
format.setFont( QgsFontUtils::getStandardTestFont( QStringLiteral( "Bold" ) ).family() );
|
||||
format.setSize( 12 );
|
||||
format.setNamedStyle( QStringLiteral( "Bold" ) );
|
||||
format.setColor( QColor( 200, 0, 200 ) );
|
||||
settings.setFormat( format );
|
||||
mPointLayerNoSymbols->setLabeling( new QgsVectorLayerSimpleLabeling( settings ) );
|
||||
mPointLayerNoSymbols->setLabelsEnabled( true );
|
||||
|
||||
QgsDxfExport d;
|
||||
d.addLayers( QList< QgsDxfExport::DxfLayer >() << QgsDxfExport::DxfLayer( mPointLayerNoSymbols ) );
|
||||
|
||||
QgsMapSettings mapSettings;
|
||||
QSize size( 640, 480 );
|
||||
mapSettings.setOutputSize( size );
|
||||
mapSettings.setExtent( mPointLayerNoSymbols->extent() );
|
||||
mapSettings.setLayers( QList<QgsMapLayer *>() << mPointLayerNoSymbols );
|
||||
mapSettings.setOutputDpi( 96 );
|
||||
mapSettings.setDestinationCrs( mPointLayerNoSymbols->crs() );
|
||||
|
||||
d.setMapSettings( mapSettings );
|
||||
d.setSymbologyScale( 1000 );
|
||||
d.setSymbologyExport( QgsDxfExport::FeatureSymbology );
|
||||
|
||||
QString file = getTempFileName( "mtext_escape_linebreaks" );
|
||||
QFile dxfFile( file );
|
||||
QCOMPARE( d.writeToFile( &dxfFile, QStringLiteral( "CP1252" ) ), QgsDxfExport::ExportResult::Success );
|
||||
dxfFile.close();
|
||||
|
||||
dxfFile.open( QIODevice::ReadOnly );
|
||||
QString fileContent = QTextStream( &dxfFile ).readAll();
|
||||
dxfFile.close();
|
||||
QVERIFY( fileContent.contains( "A\\~text\\~with\\~\\Pline\\~break" ) );
|
||||
mPointLayerNoSymbols->removeExpressionField( field );
|
||||
}
|
||||
|
||||
void TestQgsDxfExport::testText()
|
||||
{
|
||||
QgsPalLayerSettings settings;
|
||||
|
Loading…
x
Reference in New Issue
Block a user