GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Bug]: Cairo backends don't render italic text · Issue #28452 · matplotlib/matplotlib

[Bug]: Cairo backends don't render italic text #28452

New issue
Copy link
New issue
Copy link
Open
Open
[Bug]: Cairo backends don't render italic text#28452
Copy link
Labels
backend: cairo

Description

@QuLogic
QuLogic
opened on Jun 25, 2024
Issue body actions

Bug summary

The anatomy example uses italic text for its annotations. When running with TkCairo (or any other Cairo-based backend), this text is just upright.

Code for reproduction

MPLBACKEND=TkCairo python galleries/examples/showcase/anatomy.py

Actual outcome

Figure_1

Expected outcome

Figure_1

Additional information

No response

Operating system

Fedora 40

Matplotlib Version

d7d1bba

Matplotlib Backend

TkAgg/TkCairo

Python version

3.12.3

Jupyter version

n/a

Installation

git checkout

Activity

  1. anntzer commented on Jun 25, 2024

    @anntzer
    anntzer
    on Jun 25, 2024
    Contributor
    More actions

    From a quick look, the relevant functions for cairo's "toy" font APIs are cairo{ft,quartz,win32}_font_face_create_for_toy, which do appear to have some (extremely limited) support for style/weight. Now we just need to figure out the right arguments to pass to these (if any...).

  2. QuLogic commented on Jun 25, 2024

    @QuLogic
    QuLogic
    on Jun 25, 2024
    MemberAuthor
    More actions

    Well, we do attempt to set the slant and the weight, but I guess that is not sufficient? Or maybe the family name is too specific?

    matplotlib/lib/matplotlib/backends/backend_cairo.py

    Lines 62 to 79 in e353367

    def _cairo_font_args_from_font_prop(prop):
    """
    Convert a `.FontProperties` or a `.FontEntry` to arguments that can be
    passed to `.Context.select_font_face`.
    """
    def attr(field):
    try:
    return getattr(prop, f"get_{field}")()
    except AttributeError:
    return getattr(prop, field)
    name = attr("name")
    slant = getattr(cairo, f"FONT_SLANT_{attr('style').upper()}")
    weight = attr("weight")
    weight = (cairo.FONT_WEIGHT_NORMAL
    if font_manager.weight_dict.get(weight, weight) < 550
    else cairo.FONT_WEIGHT_BOLD)
    return name, slant, weight

  3. anntzer commented on Jun 25, 2024

    @anntzer
    anntzer
    on Jun 25, 2024
    Contributor
    More actions

    I think the family name is too specific (from what I remember looking at the cairo code; haven't re-checked).
    OTOH as the cairo docs say themselves, trying to render text without actually going through freetype (or win32 or quartz) is only implemented as a "toy" in cairo.
    Although pycairo says it can be integrated with freetype-py (https://pycairo.readthedocs.io/en/latest/tutorial/other.html#freetype-py-cairo), from a quick skim at the examples they seem to just extract the bitmap using freetype and blit it (essentially like we do in FT2Font and FT2Image) rather than rendering as glyphs (text on vector output), so that doesn't really help.
    Also cairo's actual freetype integration seems not implented in pycairo (https://pycairo.readthedocs.io/en/latest/reference/text.html#class-freetypefontface-fontface).
    I suspect (though I would be happy to be proven wrong) that fixing this is quickly going to reach mplcairo territory ;-)

  4. anntzer
    added
    backend: cairo
    on Apr 22, 2025
  5. QuLogic
    added a parent issue on Sep 1, 2026
    • [MNT]: Deprecate internal Cairo backends #32276
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend: cairo

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.