Skip to content

Commit

Permalink
Use faces as fonts dictionary keys
Browse files Browse the repository at this point in the history
Pango faces are just Pango fonts without the size information, it thus avoids
duplication for different sizes. Fortunately, it includes the variant
information.
  • Loading branch information
liZe committed Sep 30, 2022
1 parent 4f7c3cf commit dfccf1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
11 changes: 6 additions & 5 deletions weasyprint/pdf/stream.py
Expand Up @@ -311,11 +311,12 @@ def set_blend_mode(self, mode):
}))

def add_font(self, pango_font):
hb_font = pango.pango_font_get_hb_font(pango_font)
hb_face = harfbuzz.hb_font_get_face(hb_font)
if pango_font not in self._fonts:
self._fonts[pango_font] = Font(pango_font, hb_face)
return self._fonts[pango_font]
pango_face = pango.pango_font_get_face(pango_font)
if pango_face not in self._fonts:
hb_font = pango.pango_font_get_hb_font(pango_font)
hb_face = harfbuzz.hb_font_get_face(hb_font)
self._fonts[pango_face] = Font(pango_font, hb_face)
return self._fonts[pango_face]

def add_group(self, bounding_box):
states = pydyf.Dictionary()
Expand Down
13 changes: 6 additions & 7 deletions weasyprint/text/ffi.py
Expand Up @@ -44,6 +44,7 @@
typedef ... PangoAttrList;
typedef ... PangoAttrClass;
typedef ... PangoFont;
typedef ... PangoFontFace;
typedef guint PangoGlyph;
typedef gint PangoGlyphUnit;
Expand Down Expand Up @@ -257,6 +258,8 @@
PangoFontMetrics * pango_context_get_metrics (
PangoContext *context, const PangoFontDescription *desc,
PangoLanguage *language);
PangoFontMetrics * pango_font_get_metrics (
PangoFont *font, PangoLanguage *language);
void pango_font_metrics_unref (PangoFontMetrics *metrics);
int pango_font_metrics_get_ascent (PangoFontMetrics *metrics);
int pango_font_metrics_get_descent (PangoFontMetrics *metrics);
Expand All @@ -268,16 +271,12 @@
PangoFontMetrics *metrics);
int pango_font_metrics_get_strikethrough_position (
PangoFontMetrics *metrics);
void pango_context_set_round_glyph_positions (
PangoContext *context, gboolean round_positions);
PangoFontMetrics * pango_font_get_metrics (
PangoFont *font, PangoLanguage *language);
void pango_font_get_glyph_extents (
PangoFont *font, PangoGlyph glyph, PangoRectangle *ink_rect,
PangoRectangle *logical_rect);
PangoFontFace* pango_font_get_face (PangoFont* font);
void pango_context_set_round_glyph_positions (
PangoContext *context, gboolean round_positions);
PangoAttrList * pango_attr_list_new (void);
void pango_attr_list_unref (PangoAttrList *list);
Expand Down

0 comments on commit dfccf1b

Please sign in to comment.