Skip to content

Commit

Permalink
Merge pull request #7273 from mhugent/dxf_fontsize_fix
Browse files Browse the repository at this point in the history
Use tightBoundingRect to calculate size of dxf text. Otherwise, the t…
  • Loading branch information
mhugent committed Jun 19, 2018
2 parents 10dd428 + e3d0305 commit 6a84baf
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 6a84baf

Please sign in to comment.