glyphy: Update for api changes in glyphy

With this, synthetic bold fonts work as well
as they do with freetype.
This commit is contained in:
Matthias Clasen
2022-04-04 20:38:04 -04:00
parent 5fb1a572c6
commit 8a438c46ae
3 changed files with 26 additions and 14 deletions

View File

@@ -55,7 +55,10 @@
#include <glyphy.h>
#define TOLERANCE (1/2048.)
#define MIN_FONT_SIZE 10
#define MIN_FONT_SIZE 14
#define GRID_SIZE 20 /* Per EM */
#define ENLIGHTEN_MAX .01 /* Per EM */
#define EMBOLDEN_MAX .024 /* Per EM */
/* We split the atlas into cells of size 64x8, so the minimum number of
* bytes we store per glyph is 2048, and an atlas of size 2048x1024 can
@@ -365,6 +368,9 @@ encode_glyph (GskGLGlyphyLibrary *self,
guint upem = hb_face_get_upem (face);
double tolerance = upem * tolerance_per_em;
double faraway = (double)upem / (MIN_FONT_SIZE * M_SQRT2);
double unit_size = (double) upem / GRID_SIZE;
double enlighten_max = (double) upem * ENLIGHTEN_MAX;
double embolden_max = (double) upem * EMBOLDEN_MAX;
double avg_fetch_achieved;
GskPathBuilder *builder;
GskPath *path, *simplified;
@@ -399,17 +405,19 @@ encode_glyph (GskGLGlyphyLibrary *self,
self->acc_endpoints->len,
FALSE);
if (!glyphy_arc_list_encode_blob ((gpointer)self->acc_endpoints->data,
self->acc_endpoints->len,
buffer,
buffer_len,
faraway,
4, /* UNUSED */
&avg_fetch_achieved,
output_len,
nominal_width,
nominal_height,
extents))
if (!glyphy_arc_list_encode_blob2 ((gpointer)self->acc_endpoints->data,
self->acc_endpoints->len,
buffer,
buffer_len,
faraway,
unit_size,
enlighten_max,
embolden_max,
&avg_fetch_achieved,
output_len,
nominal_width,
nominal_height,
extents))
return FALSE;
glyphy_extents_scale (extents, 1./upem, 1./upem);

View File

@@ -3200,6 +3200,8 @@ gsk_gl_render_job_visit_text_node_glyphy (GskGLRenderJob *job,
float font_scale;
gboolean synthetic_bold;
#define GRID_SIZE 20
g_assert (!gsk_text_node_has_color_glyphs (node));
if (!(num_glyphs = gsk_text_node_get_num_glyphs (node)))
@@ -3273,9 +3275,11 @@ gsk_gl_render_job_visit_text_node_glyphy (GskGLRenderJob *job,
gsk_gl_program_set_uniform1f (job->current_program,
UNIFORM_GLYPHY_CONTRAST, 0,
1.0);
/* 0.0208 is the value used by freetype for synthetic emboldening */
gsk_gl_program_set_uniform1f (job->current_program,
UNIFORM_GLYPHY_BOLDNESS, 0,
synthetic_bold ? 0.1 : 0.0);
synthetic_bold ? 0.0208 * GRID_SIZE : 0.0);
#if 0
gsk_gl_program_set_uniform1f (job->current_program,

View File

@@ -27,7 +27,6 @@ glyph_info_decode (vec4 v)
return gi;
}
float
antialias (float d)
{
@@ -46,6 +45,7 @@ main()
float m = length (vec2 (length (dpdx), length (dpdy))) * SQRT2_INV;
float gsdist = glyphy_sdf (p, gi.nominal_size GLYPHY_DEMO_EXTRA_ARGS);
gsdist -= u_boldness;
float sdist = gsdist / m * u_contrast;
if (u_outline)