From d160d20b28b396f16fe81b4cb00d5fd4d183d9fd Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 10 Nov 2021 23:35:27 +0100 Subject: Store DPI in floating point instead of deci-integer + implement libfonts_get_output_dpi MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 3 ++- libfonts.h | 8 ++++---- libfonts_get_output_dpi.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 libfonts_get_output_dpi.c diff --git a/Makefile b/Makefile index 2ea54db..dae5d3a 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,8 @@ LIB_NAME = fonts OBJ =\ - libfonts_calculate_subpixel_order.o + libfonts_calculate_subpixel_order.o\ + libfonts_get_output_dpi.o HDR =\ libfonts.h diff --git a/libfonts.h b/libfonts.h index 7f14a48..a31a5e9 100644 --- a/libfonts.h +++ b/libfonts.h @@ -87,8 +87,8 @@ enum libfonts_orientation { }; struct libfonts_rendering_settings { - uint16_t deci_dpi_x; - uint16_t deci_dpi_y; + double dpi_x; /* actually pixels rather than dots */ + double dpi_y; enum libfonts_antialiasing horizontal_grey_text_antialiasing; enum libfonts_antialiasing vertical_grey_text_antialiasing; enum libfonts_antialiasing diagonal_grey_text_antialiasing; @@ -107,8 +107,8 @@ struct libfonts_output { int output_screen; enum libfonts_orientation physical_screen_orientation; enum libfonts_subpixel_order unrotated_subpixel_order; - uint16_t deci_dpi_x; - uint16_t deci_dpi_y; + double dpi_x; + double dpi_y; struct libfonts_rendering_settings *rendering_settings; }; diff --git a/libfonts_get_output_dpi.c b/libfonts_get_output_dpi.c new file mode 100644 index 0000000..259702a --- /dev/null +++ b/libfonts_get_output_dpi.c @@ -0,0 +1,40 @@ +/* See LICENSE file for copyright and license details. */ +#include "libfonts.h" +#include +#include +#include + + +int +libfonts_get_output_dpi(struct libfonts_output *output, const char *edid) +{ + int width, height; + char width1, width2, height1, height2; + + output->dpi_x = 0; + output->dpi_y = 0; + + if (strncasecmp(edid, "00""FF""FF""FF""FF""FF""FF""00", 2 * 8) || strlen(edid) < 256) + return 0; + + width1 = edid[21 * 2 + 0]; + width2 = edid[21 * 2 + 0]; + height1 = edid[22 * 2 + 0]; + height2 = edid[22 * 2 + 0]; + + if (!isxdigit(width1) || !isxdigit(width2) || !isxdigit(height1) || !isxdigit(height2)) + return 0; + + width = ((width1 & 15) + (width1 > '9' ? 9 : 0)) << 4; + width |= (width2 & 15) + (width2 > '9' ? 9 : 0); + height = ((height1 & 15) + (height1 > '9' ? 9 : 0)) << 4; + height |= (height2 & 15) + (height2 > '9' ? 9 : 0); + + if (!width || !height) + return 0; + + output->dpi_x = (double)output->output_width / (double)width * 2.54; + output->dpi_y = (double)output->output_height / (double)height * 2.54; + + return 1; +} -- cgit v1.2.3-70-g09d2