Skip to content
Permalink
Browse files

Applied font bug workaround to the composer scalebar and cleaned up a

couple of debugging statements.


git-svn-id: http://svn.osgeo.org/qgis/trunk@7637 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
StevenB StevenB
StevenB authored and StevenB committed Nov 21, 2007
1 parent 852421f commit 722498b3603135133d272483d5baef1bc297e0de
Showing with 16 additions and 6 deletions.
  1. +16 −6 src/app/composer/qgscomposerscalebar.cpp
@@ -166,9 +166,12 @@ QgsComposerScalebar::~QgsComposerScalebar()
QGraphicsItem::hide();
}

#define FONT_WORKAROUND_SCALE 10
QRectF QgsComposerScalebar::render(QPainter * p)
{
std::cout << "QgsComposerScalebar::render p = " << p << std::endl;
#ifdef QGISDEBUG
std::cout << "QgsComposerScalebar::render() "<< std::endl;
#endif

// Painter can be 0, create dummy to avoid many if below
QPainter *painter;
@@ -181,8 +184,9 @@ QRectF QgsComposerScalebar::render(QPainter * p)
pixmap = new QPixmap(1, 1);
painter = new QPainter(pixmap);
}

#ifdef QGISDEBUG
std::cout << "mComposition->scale() = " << mComposition->scale() << std::endl;
#endif

QgsComposerMap *map = mComposition->map(mMap); //Get the topmost map from the composition

@@ -242,10 +246,11 @@ QRectF QgsComposerScalebar::render(QPainter * p)
font.setPointSizeFloat(size);
QFontMetrics metrics(font);

font.setPointSizeFloat(size * FONT_WORKAROUND_SCALE); //hack to work around Qt font bug

if (plotStyle() == QgsComposition::Postscript)
{
font.setPointSizeF(metrics.ascent() * 72.0 / mComposition->resolution());
std::cout << "scalebar using PS font size!" << std::endl;
font.setPointSizeF(metrics.ascent() * 72.0 / mComposition->resolution() * FONT_WORKAROUND_SCALE);
}

painter->setFont(font);
@@ -271,7 +276,11 @@ std::cout << "scalebar using PS font size!" << std::endl;

double x = barLx + (i * segwidth) - shift; //figure out the bottom left corner and draw the text
double y = -tickSize - offset - metrics.descent();
painter->drawText(QPointF(x, y), txt);

painter->save();
painter->scale(1./FONT_WORKAROUND_SCALE, 1./FONT_WORKAROUND_SCALE);
painter->drawText(QPointF(x * FONT_WORKAROUND_SCALE, y * FONT_WORKAROUND_SCALE), txt);
painter->restore();

}//end of label drawing

@@ -289,8 +298,9 @@ return QRectF(barLx - (mPen.widthF()/2), -totalHeight, width + textRightOverhang

void QgsComposerScalebar::paint(QPainter * painter, const QStyleOptionGraphicsItem * itemStyle, QWidget * pWidget)
{
#ifdef QGISDEBUG
std::cout << "draw mPlotStyle = " << plotStyle() << std::endl;

#endif
mBoundingRect = render(painter);

// Show selected / Highlight

0 comments on commit 722498b

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