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.
This commit is contained in:
Chase Geigle 2017-01-24 20:52:52 -06:00 committed by Michael Carlberg
parent e7dc6b8bbb
commit 6364bb4385
1 changed files with 18 additions and 7 deletions

View File

@ -123,17 +123,28 @@ renderer::renderer(
{ {
double dpi_x = 96, dpi_y = 96; double dpi_x = 96, dpi_y = 96;
if (m_conf.has(m_conf.section(), "dpi")) { if (m_conf.has(m_conf.section(), "dpi")) {
try { dpi_x = dpi_y = m_conf.get<double>("dpi");
// dpi specified directly as a value } else {
dpi_x = dpi_y = m_conf.get<double>("dpi"); if (m_conf.has(m_conf.section(), "dpi-x")) {
} catch (const value_error&) { dpi_x = m_conf.get<double>("dpi-x");
// dpi to be comptued }
auto screen = m_connection.screen(); if (m_conf.has(m_conf.section(), "dpi-y")) {
dpi_y = m_conf.get<double>("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; 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; 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<string>(m_conf.section(), "font", {}); auto fonts = m_conf.get_list<string>(m_conf.section(), "font", {});
if (fonts.empty()) { if (fonts.empty()) {