From 3c3662b3ba9ae8cd36a42aa0bcf43016fc21e9fb Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 12 Jun 2020 16:06:39 +0200 Subject: [PATCH] Add option to disable X axis font's pre-scaling If used pre-scaling along X null the effect of the font's hinting. --- lib/font_renderer/font_renderer.cpp | 13 +++++++------ lib/font_renderer/font_renderer.h | 7 ++++--- lib/font_renderer/font_renderer_alpha.h | 10 ++++++---- src/renderer.c | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/font_renderer/font_renderer.cpp b/lib/font_renderer/font_renderer.cpp index 1db68600..de08313d 100644 --- a/lib/font_renderer/font_renderer.cpp +++ b/lib/font_renderer/font_renderer.cpp @@ -20,8 +20,8 @@ public: // Conventional LUT values: (1./3., 2./9., 1./9.) // The values below are fine tuned as in the Elementary Plot library. - FR_Impl(bool hinting, bool kerning, bool subpixel, float gamma_value) : - m_renderer(hinting, kerning, subpixel), + FR_Impl(bool hinting, bool kerning, bool subpixel, bool prescale_x, float gamma_value) : + m_renderer(hinting, kerning, subpixel, prescale_x), m_gamma_lut(double(gamma_value)), m_lcd_lut(0.448, 0.184, 0.092), m_subpixel(subpixel) @@ -40,10 +40,11 @@ private: }; FR_Renderer *FR_Renderer_New(unsigned int flags, float gamma) { - bool hinting = ((flags & FR_HINTING) != 0); - bool kerning = ((flags & FR_KERNING) != 0); - bool subpixel = ((flags & FR_SUBPIXEL) != 0); - return new FR_Impl(hinting, kerning, subpixel, gamma); + bool hinting = ((flags & FR_HINTING) != 0); + bool kerning = ((flags & FR_KERNING) != 0); + bool subpixel = ((flags & FR_SUBPIXEL) != 0); + bool prescale_x = ((flags & FR_PRESCALE_X) != 0); + return new FR_Impl(hinting, kerning, subpixel, prescale_x, gamma); } FR_Bitmap* FR_Bitmap_New(FR_Renderer *font_renderer, int width, int height) { diff --git a/lib/font_renderer/font_renderer.h b/lib/font_renderer/font_renderer.h index 8f05ee97..a72911de 100644 --- a/lib/font_renderer/font_renderer.h +++ b/lib/font_renderer/font_renderer.h @@ -18,9 +18,10 @@ struct FR_Impl; typedef struct FR_Impl FR_Renderer; enum { - FR_HINTING = 1 << 0, - FR_KERNING = 1 << 2, - FR_SUBPIXEL = 1 << 3, + FR_HINTING = 1 << 0, + FR_KERNING = 1 << 1, + FR_SUBPIXEL = 1 << 2, + FR_PRESCALE_X = 1 << 3, }; typedef struct { diff --git a/lib/font_renderer/font_renderer_alpha.h b/lib/font_renderer/font_renderer_alpha.h index c61b5990..5dcf5e37 100644 --- a/lib/font_renderer/font_renderer_alpha.h +++ b/lib/font_renderer/font_renderer_alpha.h @@ -27,6 +27,7 @@ class font_renderer_alpha bool m_hinting; bool m_kerning; bool m_subpixel; + bool m_prescale_x; bool m_font_loaded; @@ -37,12 +38,13 @@ class font_renderer_alpha public: typedef agg::pixfmt_alpha8::color_type color_type; - font_renderer_alpha(bool hinting, bool kerning, bool subpixel): + font_renderer_alpha(bool hinting, bool kerning, bool subpixel, bool prescale_x): m_feng(), m_fman(m_feng), m_hinting(hinting), m_kerning(kerning), m_subpixel(subpixel), + m_prescale_x(prescale_x), m_font_loaded(false), m_curves(m_fman.path_adaptor()), m_trans(m_curves, m_mtx) @@ -77,7 +79,7 @@ public: } void set_font_height(double height) { - const double scale_x = 100.0; + const double scale_x = (m_prescale_x ? 100.0 : 1.0); m_feng.height(height); if (m_subpixel) { const int subpixel_scale = 3; @@ -88,11 +90,11 @@ public: } template - void draw_codepoint(Rasterizer& ras, Scanline& sl, + void draw_codepoint(Rasterizer& ras, Scanline& sl, RenSolid& ren_solid, const color_type color, int codepoint, double& x, double& y, int subpixel_scale) { - const double scale_x = 100; + const double scale_x = (m_prescale_x ? 100.0 : 1.0); // Represent the delta in x scaled by scale_x. double x_delta = 0; diff --git a/src/renderer.c b/src/renderer.c index f34d782d..f5f5854d 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -149,7 +149,7 @@ RenFont* ren_load_font(const char *filename, float size) { font->size = size; const float gamma = 1.5; - font->renderer = FR_Renderer_New(FR_HINTING | FR_SUBPIXEL, gamma); + font->renderer = FR_Renderer_New(FR_HINTING | FR_SUBPIXEL | FR_PRESCALE_X, gamma); if (FR_Load_Font(font->renderer, filename)) { free(font); return NULL;