# HG changeset patch # User Chris Cannam # Date 1485465439 0 # Node ID dc6457ac4d077c73c2851113c934d494bf2a4d2f # Parent a8e126fe6a53eba79125962a42d84daab6b6ffe5 Add method to scale pen widths for hi-res screens diff -r a8e126fe6a53 -r dc6457ac4d07 layer/PaintAssistant.cpp --- a/layer/PaintAssistant.cpp Thu Jan 26 21:16:46 2017 +0000 +++ b/layer/PaintAssistant.cpp Thu Jan 26 21:17:19 2017 +0000 @@ -19,6 +19,7 @@ #include "base/AudioLevel.h" #include "base/Strings.h" +#include "base/Debug.h" #include #include @@ -262,3 +263,42 @@ std::cerr << "ERROR: PaintAssistant::drawVisibleText: Boxed style not yet implemented!" << std::endl; } } + +double +PaintAssistant::scalePenWidth(double width) +{ + static double ratio = 0.0; + if (ratio == 0.0) { + double baseEm; +#ifdef Q_OS_MAC + baseEm = 17.0; +#else + baseEm = 15.0; +#endif + double em = QFontMetrics(QFont()).height(); + ratio = em / baseEm; + + SVDEBUG << "PaintAssistant::scalePenWidth: ratio is " << ratio + << " (em = " << em << ")" << endl; + } + + if (ratio <= 1.0) { + // we only ever scale up in this method + return width; + } + + if (width <= 0) { + // zero-width pen, produce a scaled one-pixel pen + return ratio; + } + + return width * ratio; +} + +QPen +PaintAssistant::scalePen(QPen pen) +{ + return QPen(pen.color(), scalePenWidth(pen.width())); +} + + diff -r a8e126fe6a53 -r dc6457ac4d07 layer/PaintAssistant.h --- a/layer/PaintAssistant.h Thu Jan 26 21:16:46 2017 +0000 +++ b/layer/PaintAssistant.h Thu Jan 26 21:17:19 2017 +0000 @@ -13,10 +13,11 @@ COPYING included with this distribution for more information. */ -#ifndef PAINT_ASSISTANT_H -#define PAINT_ASSISTANT_H +#ifndef SV_PAINT_ASSISTANT_H +#define SV_PAINT_ASSISTANT_H #include +#include #include class QPainter; @@ -46,6 +47,18 @@ static void drawVisibleText(const LayerGeometryProvider *, QPainter &p, int x, int y, QString text, TextStyle style); + + /** + * Scale up pen width for a hi-dpi display without pixel doubling. + * Very similar to ViewManager::scalePixelSize, but a bit more + * conservative. + */ + static double scalePenWidth(double width); + + /** + * Apply scalePenWidth to a pen. + */ + static QPen scalePen(QPen pen); }; #endif