Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use partial font instead of font face to create font cache keys #1783

Merged
merged 1 commit into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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