Add option to disable X axis font's pre-scaling

If used pre-scaling along X null the effect of the font's hinting.
This commit is contained in:
Francesco Abbate 2020-06-12 16:06:39 +02:00
parent 4d3693479d
commit 3c3662b3ba
4 changed files with 18 additions and 14 deletions

View File

@ -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) {

View File

@ -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 {

View File

@ -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<class Rasterizer, class Scanline, class RenSolid>
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;

View File

@ -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;