Skip to content

Commit

Permalink
Use tightBoundingRect to calculate size of dxf text. Otherwise, the t…
Browse files Browse the repository at this point in the history
…ext will be too big in the dxf
  • Loading branch information
mhugent committed Jun 19, 2018
1 parent 6d3199f commit e3d0305
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -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 );
}


Expand Down

0 comments on commit e3d0305

Please sign in to comment.