Skip to content

Commit

Permalink
Merge pull request #1783 from Kozea/fix-font-face
Browse files Browse the repository at this point in the history
Use partial font instead of font face to create font cache keys
  • Loading branch information
liZe authored Dec 23, 2022
2 parents deabe55 + b8b9e8c commit 274ba54
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
5 changes: 2 additions & 3 deletions docs/first_steps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ Ubuntu_, Fedora_, Archlinux_, Gentoo_…

If WeasyPrint is not available on your distribution, or if you want to use a
more recent version of WeasyPrint, you have to be sure that Python_ (at least
version 3.7.0) and Pango_ (at least version 1.44.0, 1.46.0 or newer is
preferred to get smaller documents) are installed on your system. You can
verify this by launching::
version 3.7.0) and Pango_ (at least version 1.44.0) are installed on your
system. You can verify this by launching::

python3 --version
pango-view --version
Expand Down
11 changes: 6 additions & 5 deletions weasyprint/pdf/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,12 @@ def set_blend_mode(self, mode):

@lru_cache()
def add_font(self, pango_font):
if pango.pango_version() > 14600:
pango_face = pango.pango_font_get_face(pango_font)
description = pango.pango_font_face_describe(pango_face)
else:
description = pango.pango_font_describe(pango_font)
description = pango.pango_font_describe(pango_font)
mask = (
pango.PANGO_FONT_MASK_SIZE +
pango.PANGO_FONT_MASK_GRAVITY +
pango.PANGO_FONT_MASK_VARIATIONS)
pango.pango_font_description_unset_fields(description, mask)
key = pango.pango_font_description_hash(description)
pango.pango_font_description_free(description)
if key not in self._fonts:
Expand Down
12 changes: 9 additions & 3 deletions weasyprint/text/ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
typedef ... PangoAttrList;
typedef ... PangoAttrClass;
typedef ... PangoFont;
typedef ... PangoFontFace;
typedef guint PangoGlyph;
typedef gint PangoGlyphUnit;
Expand All @@ -72,6 +71,12 @@
PANGO_WEIGHT_ULTRAHEAVY = 1000
} PangoWeight;
typedef enum {
PANGO_FONT_MASK_SIZE = 1 << 5,
PANGO_FONT_MASK_GRAVITY = 1 << 6,
PANGO_FONT_MASK_VARIATIONS = 1 << 7
} PangoFontMask;
typedef enum {
PANGO_STRETCH_ULTRA_CONDENSED,
PANGO_STRETCH_EXTRA_CONDENSED,
Expand Down Expand Up @@ -249,6 +254,9 @@
const PangoFontDescription* desc);
int pango_font_description_get_size (PangoFontDescription *desc);
void pango_font_description_unset_fields (
PangoFontDescription* desc, PangoFontMask to_unset);
int pango_glyph_string_get_width (PangoGlyphString *glyphs);
char * pango_font_description_to_string (
const PangoFontDescription *desc);
Expand Down Expand Up @@ -280,8 +288,6 @@
void pango_font_get_glyph_extents (
PangoFont *font, PangoGlyph glyph, PangoRectangle *ink_rect,
PangoRectangle *logical_rect);
PangoFontFace* pango_font_get_face (PangoFont* font);
PangoFontDescription* pango_font_face_describe (PangoFontFace* face);
void pango_context_set_round_glyph_positions (
PangoContext *context, gboolean round_positions);
Expand Down

0 comments on commit 274ba54

Please sign in to comment.