Skip to content
Permalink
Browse files

Use tightBoundingRect to calculate size of dxf text. Otherwise, the t…

…ext will be too big in the dxf
  • Loading branch information
mhugent committed Jun 19, 2018
1 parent 6d3199f commit e3d03056e3edf358b43fd25b2064c7635835d0cc
Showing with 18 additions and 2 deletions.
  1. +18 −2 src/core/dxf/qgsdxfexport.cpp
@@ -4598,13 +4598,29 @@ void QgsDxfExport::drawLabel( QString layerId, QgsRenderContext& context, pal::L
txt.prepend( "\\K" ).append( "\\k" );
}

QFontMetricsF* fm = lf->labelFontMetrics();
if ( !fm )
{
return;
}

QRectF textBoundingRect = fm->tightBoundingRect( txt );

double maxAscent = -textBoundingRect.y();
double maxDescent = textBoundingRect.height() - maxAscent;

txt.prepend( QString( "\\f%1|i%2|b%3;\\H%4;" )
.arg( tmpLyr.textFont.family() )
.arg( tmpLyr.textFont.italic() ? 1 : 0 )
.arg( tmpLyr.textFont.bold() ? 1 : 0 )
.arg( label->getHeight() / ( 1 + txt.count( "\\P" ) ) * 0.75 ) );
.arg(( maxAscent ) * context.mapToPixel().mapUnitsPerPixel() ) );

double labelY = label->getY();

int nLines = txt.count( "\\P" ) + 1;
labelY += ( label->getHeight() - ( maxAscent + maxDescent + fm->lineSpacing() * ( nLines - 1 ) ) * context.mapToPixel().mapUnitsPerPixel() ) / 2.0;

writeMText( dxfLayer, txt, QgsPointV2( label->getX(), label->getY() ), label->getWidth(), label->getAlpha() * 180.0 / M_PI, tmpLyr.textColor );
writeMText( dxfLayer, txt, QgsPointV2( label->getX(), labelY ), label->getWidth(), label->getAlpha() * 180.0 / M_PI, tmpLyr.textColor );
}


0 comments on commit e3d0305

Please sign in to comment.
You can’t perform that action at this time.