evas: Implement support for different H/V font DPI

This is modifying how a rarely used environment variable that sets the
DPI used for font sizing is parsed. The previous form remains valid, of
course. Note that EFL tends to use "scaling" instead of this DPI. The
font DPI is useful for me to open up a terminology window with almost
the same size as my IDE's code viewer.

Use case:

  export EVAS_FONT_DPI=95x94 terminology

Note:
I still don't get a 1:1 match with Qt's rendering, and in fact
94x95 works better than what 95x94 (which is reported by xdpyinfo).
Interesting though :)

@feature
This commit is contained in:
Jean-Philippe Andre 2017-10-12 15:15:34 +09:00
parent 47a4632398
commit ca581e00ba
3 changed files with 17 additions and 11 deletions

View File

@ -39,7 +39,7 @@ EAPI void evas_common_font_draw_do(const Cutout_Rects *reuse, const
EAPI Eina_Bool evas_common_font_draw_prepare_cutout(Cutout_Rects **reuse, RGBA_Image *dst, RGBA_Draw_Context *dc, RGBA_Gfx_Func *func);
/* load */
EAPI void evas_common_font_dpi_set (int dpi);
EAPI void evas_common_font_dpi_set (int dpi_h, int dpi_v);
EAPI RGBA_Font_Source *evas_common_font_source_memory_load (const char *name, const void *data, int data_size);
EAPI RGBA_Font_Source *evas_common_font_source_load (const char *name);
EAPI int evas_common_font_source_load_complete (RGBA_Font_Source *fs);

View File

@ -24,7 +24,8 @@ extern FT_Library evas_ft_lib;
static int font_cache_usage = 0;
static int font_cache = 0;
static int font_dpi = 75;
static int font_dpi_h = 75;
static int font_dpi_v = 75;
static Eina_Hash *fonts_src = NULL;
static Eina_Hash *fonts = NULL;
@ -131,9 +132,11 @@ evas_common_font_load_shutdown(void)
}
EAPI void
evas_common_font_dpi_set(int dpi)
evas_common_font_dpi_set(int dpi_h, int dpi_v)
{
font_dpi = dpi;
if (dpi_v <= 0) dpi_v = dpi_h;
font_dpi_h = dpi_h;
font_dpi_v = dpi_v;
}
EAPI RGBA_Font_Source *
@ -365,7 +368,7 @@ evas_common_font_int_memory_load(const char *source, const char *name, int size,
#ifdef EVAS_CSERVE2
if (evas_cserve2_use_get())
{
fi->cs2_handler = evas_cserve2_font_load(source, name, size, font_dpi,
fi->cs2_handler = evas_cserve2_font_load(source, name, size, font_dpi_h,
wanted_rend);
if (fi->cs2_handler)
{
@ -409,7 +412,7 @@ evas_common_font_int_load(const char *name, int size,
#ifdef EVAS_CSERVE2
if (evas_cserve2_use_get())
{
fi->cs2_handler = evas_cserve2_font_load(NULL, name, size, font_dpi,
fi->cs2_handler = evas_cserve2_font_load(NULL, name, size, font_dpi_h,
wanted_rend);
if (fi->cs2_handler)
{
@ -449,7 +452,7 @@ evas_common_font_int_load_complete(RGBA_Font_Int *fi)
}
fi->real_size = fi->size * 64;
fi->scale_factor = 1.0;
error = FT_Set_Char_Size(fi->src->ft.face, 0, fi->real_size, font_dpi, font_dpi);
error = FT_Set_Char_Size(fi->src->ft.face, 0, fi->real_size, font_dpi_h, font_dpi_v);
if (error)
error = FT_Set_Pixel_Sizes(fi->src->ft.face, 0, fi->real_size);
FTUNLOCK();
@ -503,12 +506,12 @@ evas_common_font_int_load_complete(RGBA_Font_Int *fi)
FTUNLOCK();
if (error)
{
error = FT_Set_Char_Size(fi->src->ft.face, 0, fi->real_size, font_dpi, font_dpi);
error = FT_Set_Char_Size(fi->src->ft.face, 0, fi->real_size, font_dpi_h, font_dpi_v);
if (error)
{
/* hack around broken fonts */
fi->real_size = (chosen_size2 / 64) * 60;
error = FT_Set_Char_Size(fi->src->ft.face, 0, fi->real_size, font_dpi, font_dpi);
error = FT_Set_Char_Size(fi->src->ft.face, 0, fi->real_size, font_dpi_h, font_dpi_v);
if (error)
{
/* couldn't choose the size anyway... what now? */

View File

@ -48,9 +48,12 @@ evas_common_font_init(void)
s = getenv("EVAS_FONT_DPI");
if (s)
{
int dpi = atoi(s);
int dpi_h = 75, dpi_v = 0;
if (dpi > 0) evas_common_font_dpi_set(dpi);
if (sscanf(s, "%dx%d", &dpi_h, &dpi_v) < 2)
dpi_h = dpi_v = atoi(s);
if (dpi_h > 0) evas_common_font_dpi_set(dpi_h, dpi_v);
}
LKI(lock_font_draw);
LKI(lock_bidi);