comparison layer/PaintAssistant.cpp @ 1401:28075cc658c9

Scale pen for retina display on macOS as well as for hidpi display elsewhere
author Chris Cannam
date Thu, 15 Nov 2018 14:04:32 +0000
parents cca66ce390e0
children f2525e6cbdf1
comparison
equal deleted inserted replaced
1400:decb7741d036 1401:28075cc658c9
239 239
240 std::cerr << "ERROR: PaintAssistant::drawVisibleText: Boxed style not yet implemented!" << std::endl; 240 std::cerr << "ERROR: PaintAssistant::drawVisibleText: Boxed style not yet implemented!" << std::endl;
241 } 241 }
242 } 242 }
243 243
244 double 244
245 PaintAssistant::scaleSize(double size)
246 {
247 static double ratio = 0.0;
248 if (ratio == 0.0) {
249 double baseEm;
250 #ifdef Q_OS_MAC
251 baseEm = 17.0;
252 #else
253 baseEm = 15.0;
254 #endif
255 double em = QFontMetrics(QFont()).height();
256 ratio = em / baseEm;
257
258 SVDEBUG << "PaintAssistant::scaleSize: ratio is " << ratio
259 << " (em = " << em << ")" << endl;
260
261 if (ratio < 1.0) {
262 SVDEBUG << "PaintAssistant::scaleSize: rounding ratio up to 1.0"
263 << endl;
264 ratio = 1.0;
265 }
266 }
267
268 return size * ratio;
269 }
270
271 double
272 PaintAssistant::scalePenWidth(double width)
273 {
274 if (width <= 0) {
275 // zero-width pen, produce a scaled one-pixel pen
276 width = 1;
277 }
278
279 return scaleSize(width);
280 }
281
282 QPen
283 PaintAssistant::scalePen(QPen pen)
284 {
285 return QPen(pen.color(), scalePenWidth(pen.width()));
286 }
287
288