[gtk/glyphy2: 29/32] Update to boldness api changes in glyphy
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/glyphy2: 29/32] Update to boldness api changes in glyphy
- Date: Wed, 6 Apr 2022 21:23:27 +0000 (UTC)
commit 312d7b26606bd64bc7c6466ff2447a7084421c03
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Apr 4 20:38:04 2022 -0400
Update to boldness api changes in glyphy
With this, synthetic bold fonts work as well
as the do with freetype.
gsk/gl/gskglglyphylibrary.c | 32 ++++++++++++++++++++------------
gsk/gl/gskglrenderjob.c | 6 +++++-
gsk/gl/resources/glyphy.fs.glsl | 4 ++--
3 files changed, 27 insertions(+), 15 deletions(-)
---
diff --git a/gsk/gl/gskglglyphylibrary.c b/gsk/gl/gskglglyphylibrary.c
index fd5d1d503a..3a0ec8b3a1 100644
--- a/gsk/gl/gskglglyphylibrary.c
+++ b/gsk/gl/gskglglyphylibrary.c
@@ -54,7 +54,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 */
#define ITEM_W 64
#define ITEM_H_QUANTUM 8
@@ -349,6 +352,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;
@@ -380,17 +386,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);
diff --git a/gsk/gl/gskglrenderjob.c b/gsk/gl/gskglrenderjob.c
index 6f6f45772e..4fe13b2791 100644
--- a/gsk/gl/gskglrenderjob.c
+++ b/gsk/gl/gskglrenderjob.c
@@ -3164,6 +3164,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)))
@@ -3237,9 +3239,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,
diff --git a/gsk/gl/resources/glyphy.fs.glsl b/gsk/gl/resources/glyphy.fs.glsl
index 66860734df..a42aa9df54 100644
--- a/gsk/gl/resources/glyphy.fs.glsl
+++ b/gsk/gl/resources/glyphy.fs.glsl
@@ -47,6 +47,7 @@ main()
float m = length (vec2 (length (dpdx), length (dpdy))) * SQRT2_2;
float gsdist = glyphy_sdf (p, gi.nominal_size GLYPHY_DEMO_EXTRA_ARGS);
+ gsdist -= u_boldness;
float sdist = gsdist / m * u_contrast;
#if 0
@@ -70,14 +71,13 @@ main()
glyphy_arc_list_t arc_list = glyphy_arc_list (p, gi.nominal_size GLYPHY_DEMO_EXTRA_ARGS);
// Color the number of endpoints per cell blue
- color += vec4 (0,0,1,.1) * float(arc_list.num_endpoints) * 32./255.;
+ color += vec4 (0,0,1,.4) * float(arc_list.num_endpoints) * 32./255.;
gskSetOutputColor(color);
}
else
#endif
{
- sdist -= u_boldness * 10.;
if (u_outline)
sdist = abs (sdist) - u_outline_thickness * .5;
if (sdist > 1.)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]