[pango/simple-fontmap: 31/35] pangocairo: handle PangoHbFont
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/simple-fontmap: 31/35] pangocairo: handle PangoHbFont
- Date: Thu, 21 Oct 2021 18:55:51 +0000 (UTC)
commit 529c5f9459bf5ae825b43cae88834f4da434c56c
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Aug 31 07:48:14 2021 -0400
pangocairo: handle PangoHbFont
Towards working rendering.
Basic rendering is working fine with this.
Missing:
- hexboxes
pango/pangocairo-fc.h | 3 ++
pango/pangocairo-fcfont.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++-
pango/pangocairo-font.c | 9 ++++-
3 files changed, 101 insertions(+), 2 deletions(-)
---
diff --git a/pango/pangocairo-fc.h b/pango/pangocairo-fc.h
index 36529569..9c1956d3 100644
--- a/pango/pangocairo-fc.h
+++ b/pango/pangocairo-fc.h
@@ -42,6 +42,9 @@ typedef struct _PangoCairoFcFontMap PangoCairoFcFontMap;
PANGO_AVAILABLE_IN_ALL
GType pango_cairo_fc_font_map_get_type (void) G_GNUC_CONST;
+PANGO_AVAILABLE_IN_1_50
+cairo_scaled_font_t * pango_cairo_hb_font_get_scaled_font (PangoFont *font);
+
G_END_DECLS
#endif /* __PANGOCAIRO_FC_H__ */
diff --git a/pango/pangocairo-fcfont.c b/pango/pangocairo-fcfont.c
index 85cc45c8..1545509e 100644
--- a/pango/pangocairo-fcfont.c
+++ b/pango/pangocairo-fcfont.c
@@ -32,8 +32,10 @@
#include "pangocairo-fc-private.h"
#include "pangofc-private.h"
#include "pango-impl-utils.h"
+#include "pango-hbfont-private.h"
+#include "pango-hbface-private.h"
-#include <hb-ot.h>
+#include <hb-ft.h>
#include <freetype/ftmm.h>
#define PANGO_TYPE_CAIRO_FC_FONT (pango_cairo_fc_font_get_type ())
@@ -276,3 +278,90 @@ _pango_cairo_fc_font_new (PangoCairoFcFontMap *cffontmap,
return (PangoFcFont *) cffont;
}
+
+static FT_Library ft_library;
+
+static cairo_scaled_font_t *
+create_scaled_font (PangoHbFont *font)
+{
+ unsigned int blob_length;
+ const char *blob_data;
+ FT_Face ft_face;
+ hb_font_t *hb_font;
+ unsigned int num_coords;
+ const int *coords;
+ cairo_font_face_t *cairo_face;
+ int size;
+ cairo_matrix_t ctm, font_matrix, gravity_matrix;
+ cairo_font_options_t *font_options;
+
+ if (!ft_library)
+ FT_Init_FreeType (&ft_library);
+
+ blob_data = hb_blob_get_data (font->face->blob, &blob_length);
+
+ if (FT_New_Memory_Face (ft_library,
+ (const FT_Byte *) blob_data,
+ blob_length,
+ font->face->index,
+ &ft_face))
+ g_error ("FT_New_Memory_Face failed");
+
+ hb_font = pango_font_get_hb_font (PANGO_FONT (font));
+ coords = hb_font_get_var_coords_normalized (hb_font, &num_coords);
+ if (num_coords > 0)
+ {
+ FT_Fixed *ft_coords = (FT_Fixed *) g_alloca (num_coords * sizeof (FT_Fixed));
+
+ for (unsigned int i = 0; i < num_coords; i++)
+ ft_coords[i] = coords[i] << 2;
+
+ FT_Set_Var_Blend_Coordinates (ft_face, num_coords, ft_coords);
+ }
+
+ cairo_face = cairo_ft_font_face_create_for_ft_face (ft_face, FT_LOAD_NO_HINTING | FT_LOAD_COLOR);
+
+ size = pango_font_description_get_size (font->description);
+
+ cairo_matrix_init_rotate (&gravity_matrix,
+ pango_gravity_to_rotation (font->gravity));
+
+ cairo_matrix_init_identity (&ctm);
+ cairo_matrix_init_scale (&font_matrix,
+ size * (font->dpi / 72.) / PANGO_SCALE,
+ size * (font->dpi / 72.) / PANGO_SCALE);
+ cairo_matrix_multiply (&font_matrix,
+ &font_matrix,
+ &gravity_matrix);
+ font_options = cairo_font_options_create ();
+ cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
+ cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
+
+ cairo_scaled_font_t *scaled_font = cairo_scaled_font_create (cairo_face,
+ &font_matrix,
+ &ctm,
+ font_options);
+ cairo_font_options_destroy (font_options);
+ cairo_font_face_destroy (cairo_face);
+
+ return scaled_font;
+}
+
+cairo_scaled_font_t *
+pango_cairo_hb_font_get_scaled_font (PangoFont *font)
+{
+ cairo_scaled_font_t *scaled_font;
+
+ scaled_font = g_object_get_data (G_OBJECT (font), "pango-cairo-scaled-font");
+ if (scaled_font)
+ goto done;
+
+ scaled_font = create_scaled_font (PANGO_HB_FONT (font));
+
+ g_object_set_data_full (G_OBJECT (font), "pango-cairo-scaled_font",
+ scaled_font, (GDestroyNotify)cairo_scaled_font_destroy);
+
+done:
+ return scaled_font;
+}
+
diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c
index 15c5be4a..bd23dac4 100644
--- a/pango/pangocairo-font.c
+++ b/pango/pangocairo-font.c
@@ -28,6 +28,8 @@
#include "pangocairo-private.h"
#include "pango-font-private.h"
#include "pango-impl-utils.h"
+#include "pango-hbfont.h"
+#include "pangocairo-fc.h"
#define PANGO_CAIRO_FONT_PRIVATE(font) \
((PangoCairoFontPrivate *) \
@@ -175,7 +177,12 @@ gboolean
_pango_cairo_font_install (PangoFont *font,
cairo_t *cr)
{
- cairo_scaled_font_t *scaled_font = pango_cairo_font_get_scaled_font ((PangoCairoFont *)font);
+ cairo_scaled_font_t *scaled_font;
+
+ if (PANGO_IS_HB_FONT (font))
+ scaled_font = pango_cairo_hb_font_get_scaled_font (font);
+ else
+ scaled_font = pango_cairo_font_get_scaled_font ((PangoCairoFont *)font);
if (G_UNLIKELY (scaled_font == NULL || cairo_scaled_font_status (scaled_font) != CAIRO_STATUS_SUCCESS))
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]