From 6364bb43855516890b7a14ce8cca12834e1b6323 Mon Sep 17 00:00:00 2001 From: Chase Geigle Date: Tue, 24 Jan 2017 20:52:52 -0600 Subject: [PATCH] feature(renderer): Allow dpi-x and dpi-y configuration Negative values for any of the DPI settings are used to mean "auto", which will attempt to compute an appropriate DPI from monitor settings. --- src/components/renderer.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/components/renderer.cpp b/src/components/renderer.cpp index e66797cc..4590e25f 100644 --- a/src/components/renderer.cpp +++ b/src/components/renderer.cpp @@ -123,17 +123,28 @@ renderer::renderer( { double dpi_x = 96, dpi_y = 96; if (m_conf.has(m_conf.section(), "dpi")) { - try { - // dpi specified directly as a value - dpi_x = dpi_y = m_conf.get("dpi"); - } catch (const value_error&) { - // dpi to be comptued - auto screen = m_connection.screen(); + dpi_x = dpi_y = m_conf.get("dpi"); + } else { + if (m_conf.has(m_conf.section(), "dpi-x")) { + dpi_x = m_conf.get("dpi-x"); + } + if (m_conf.has(m_conf.section(), "dpi-y")) { + dpi_y = m_conf.get("dpi-y"); + } + } + + // dpi to be comptued + if (dpi_x <= 0 || dpi_y <= 0) { + auto screen = m_connection.screen(); + if (dpi_x <= 0) { dpi_x = screen->width_in_pixels * 25.4 / screen->width_in_millimeters; + } + if (dpi_y <= 0) { dpi_y = screen->height_in_pixels * 25.4 / screen->height_in_millimeters; } } - m_log.trace("renderer: DPI is %.1fx%.1f", dpi_x, dpi_y); + + m_log.info("renderer: DPI is %.1fx%.1f", dpi_x, dpi_y); auto fonts = m_conf.get_list(m_conf.section(), "font", {}); if (fonts.empty()) {