Skip to content
Permalink
Browse files
Consider also font descent and baseline in QgsComposerLabel::adjustSi…
…zeToText. Funded by Sourcepole QGIS Enterprise.
  • Loading branch information
manisandro authored and nyalldawson committed Jun 7, 2014
1 parent 912c950 commit 456adad745c19f1acc59d841de3c145fe38c2dfd
Showing with 23 additions and 4 deletions.
  1. +7 −1 python/core/composer/qgscomposeritem.sip
  2. +7 −0 src/core/composer/qgscomposeritem.cpp
  3. +7 −1 src/core/composer/qgscomposeritem.h
  4. +2 −2 src/core/composer/qgscomposerlabel.cpp
@@ -405,8 +405,14 @@ class QgsComposerItem : QObject, QGraphicsRectItem
/**Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
double fontAscentMillimeters( const QFont& font ) const;

/**Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
/**Returns the font descent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
double fontDescentMillimeters( const QFont& font ) const;

/**Returns the font height in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE.
* Font height equals the font ascent+descent+1 (for baseline).
* @note Added in version 2.4
*/
double fontHeightMillimeters( const QFont& font ) const;

/**Calculates font to from point size to pixel size*/
double pixelFontSize( double pointSize ) const;
@@ -749,6 +749,13 @@ double QgsComposerItem::fontDescentMillimeters( const QFont& font ) const
return ( fontMetrics.descent() / FONT_WORKAROUND_SCALE );
}

double QgsComposerItem::fontHeightMillimeters( const QFont& font ) const
{
QFont metricsFont = scaledFontPixelSize( font );
QFontMetricsF fontMetrics( metricsFont );
return ( fontMetrics.height() / FONT_WORKAROUND_SCALE );
}

double QgsComposerItem::pixelFontSize( double pointSize ) const
{
return ( pointSize * 0.3527 );
@@ -360,9 +360,15 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
/**Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
double fontAscentMillimeters( const QFont& font ) const;

/**Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
/**Returns the font descent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
double fontDescentMillimeters( const QFont& font ) const;

/**Returns the font height in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE.
* Font height equals the font ascent+descent+1 (for baseline).
* @note Added in version 2.4
*/
double fontHeightMillimeters( const QFont& font ) const;

/**Calculates font to from point size to pixel size*/
double pixelFontSize( double pointSize ) const;

@@ -254,10 +254,10 @@ void QgsComposerLabel::setFont( const QFont& f )
void QgsComposerLabel::adjustSizeToText()
{
double textWidth = textWidthMillimeters( mFont, displayText() );
double fontAscent = fontAscentMillimeters( mFont );
double fontHeight = fontHeightMillimeters( mFont );

double width = textWidth + 2 * mMargin + 2 * pen().widthF() + 1;
double height = fontAscent + 2 * mMargin + 2 * pen().widthF() + 1;
double height = fontHeight + 2 * mMargin + 2 * pen().widthF();

//keep alignment point constant
double xShift = 0;

0 comments on commit 456adad

Please sign in to comment.