René's URL Explorer Experiment


Title: Various issues with FontProperties · Issue #10249 · matplotlib/matplotlib · GitHub

Open Graph Title: Various issues with FontProperties · Issue #10249 · matplotlib/matplotlib

X Title: Various issues with FontProperties · Issue #10249 · matplotlib/matplotlib

Description: FontProperties (henceforth "FP") is used by Matplotlib for font selection. Instances can be passed e.g. to text() (as the fontproperties kwarg) or legend() (as the prop kwarg); they behave essentially as a mapping with fields such as fam...

Open Graph Description: FontProperties (henceforth "FP") is used by Matplotlib for font selection. Instances can be passed e.g. to text() (as the fontproperties kwarg) or legend() (as the prop kwarg); they behave essentia...

X Description: FontProperties (henceforth "FP") is used by Matplotlib for font selection. Instances can be passed e.g. to text() (as the fontproperties kwarg) or legend() (as the prop kwarg); they behav...

Opengraph URL: https://github.com/matplotlib/matplotlib/issues/10249

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Various issues with FontProperties","articleBody":"FontProperties (henceforth \"FP\") is used by Matplotlib for font selection.  Instances can be passed e.g. to `text()` (as the `fontproperties` kwarg) or `legend()` (as the `prop` kwarg); they behave essentially as a mapping with fields such as `family` (DejaVu Sans, etc), `weight` (a CSS/OpenType numeric value, per https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight, with a mapping for names such as \"bold\", etc.), etc., that are matched against the list of system fonts (in the infamous fontList.json), with font_manager.py, using a custom-designed distance function.\r\n\r\nFPs can be constructed either by passing kwargs to the constructor (`FP(family=..., weight=..., ...)`) or a fontconfig-style pattern string (`FP(\"DejaVu Sans:bold:...\")`, https://www.freedesktop.org/software/fontconfig/fontconfig-user.html).\r\n\r\nA few issues with FPs are listed below.  Note that this discussion is not directly related to the font cache (misguessing of font weights, etc.) issues (although the font cache is used to match FPs).\r\n\r\n- [ ] The user API is not uniform: `text(..., fontproperties=...)` accepts a FP instance or a fontconfig pattern string (but not a dict) vs `legend(..., prop=...)` which uses a different kwarg and accepts a FP instance or a dict (but not a fontconfig pattern string).  While this issue should be relatively easy to fix, I am reluctant to encourage usage of fontconfig pattern strings until the next issue is fixed.\r\n\r\n- [ ] The fontconfig-style strings use CSS/OpenType weights, which are very different from fontconfig weights (https://lists.freedesktop.org/archives/fontconfig/2011-September/003646.html).  For example, `text(.5, .5, \"foo\", fontproperties=\":weight=200\")` will use a thin font (CSS 200 = \"Extra/Ultra Light\") but `fc-list :weight=200` at the terminal will return bold fonts (FC 200 = \"Bold\").  It would seem more reasonable e.g. to use CSS-style strings (https://developer.mozilla.org/en-US/docs/Web/CSS/font), although these *require* a font size to be included (but it doesn't seem too bad to allow ignoring it).  Note that if we really want to do so, it seems possible to support both fc-style and CSS-style strings (with optional weight) because they can be differentiated (namely, a fc-string (other than a bare family name, which looks the same in both cases up to quoting) contains colons whereas css-strings do not).  Not sure it's really worth it though...\r\n\r\n- [ ] The FP matching algorithm is custom-made, while we could actually follow a standard algorithm (e.g. https://www.w3.org/TR/css-fonts-4/#font-matching-algorithm, or whatever fontconfig uses (which seems a bit underspecified though, and probably technically depends on the user's fonts.conf...)).  Arguably this is less an issue as long as the current algorithm does something \"reasonable\".\r\n\r\n- [ ] The FP constructor is a bit a mess because it overloads the first argument to be either the family or a fontconfig pattern (the latter needs to be escaped, but not the former), so the syntax for requesting a sans-serif font depends on whether one requests additional properties or not:\r\n```\r\n[ins] In [1]: matplotlib.font_manager.FontProperties(\"sans-serif\").get_family()\r\n\u003cdeep pyparsing traceback, then ValueError: Could not parse font string: 'sans-serif'\u003e\r\n\r\n[ins] In [2]: matplotlib.font_manager.FontProperties(\"sans-serif\", weight=\"bold\").get_family()  \r\nOut[2]: ['sans-serif']\r\n\r\n[ins] In [3]: matplotlib.font_manager.FontProperties(\"sans\\-serif\").get_family()                \r\nOut[3]: ['sans-serif']\r\n\r\n[ins] In [4]: matplotlib.font_manager.FontProperties(\"sans\\-serif\", weight=\"bold\").get_family() \r\nOut[4]: ['sans\\\\-serif']\r\n```\r\n(i.e. one needs to write `sans-serif` if the weight is given, but `sans\\-serif` if not).\r\n\r\n- [ ] Edit: it may be necessary to distinguish an unset property in a FP and one which has already resolved its fallback-to-default, due to the issue demonstrated in https://github.com/matplotlib/matplotlib/issues/16389#issuecomment-585110776.\r\n\r\n---\r\n\r\nI think the end-result should be something as follows:\r\n\r\n- Deprecate the `fontproperties` kwarg for Text, `prop` for `legend`, etc., in favor of a new `font` kwarg for every one; deprecate `FP` as a public class.\r\n- The `font` kwarg takes one of\r\n  * a Path object (explicit font path; raises if the files embeds multiple font faces)\r\n  * a (Path, index) pair (to handle files with multiple font faces embedded)\r\n  * a CSS font string, with the following allowances:\r\n    * \"bare\" font names do not need to be quoted\r\n    * the font size can be ignored (defaulting to the rcparam)\r\n    * the font family can be ignored (defaulting to the rcparam)\r\n  * a CSS font mapping (`{\"family\": ..., \"size\": ...}` corresponding to the CSS `font-family: ...; font-size: ...`)\r\n  * possibly (though unclear if needed), a fontconfig font string (using *fontconfig* weights) or fontconfig mapping (as above), although the latter definitely needs to be marked in some way to distinguish it from CSS font mappings.\r\n\r\n---\r\n\r\nSome other potentially relevant CSS options (it's not so much that I deeply love CSS, just that it has the benefit of being a spec that already exists...), just treating this as a list of ideas:\r\n- line-height (i.e. linespacing for us)\r\n\r\n---\r\n\r\nSome more notes:\r\nUnfortunately even tokenizing CSS seems not so trivial; the only Python libs that I found for that task are https://github.com/Kozea/tinycss (no commit for more than a year), https://github.com/Kozea/tinycss2 (essentially abandoned, per https://github.com/Kozea/tinycss2/issues/4#issuecomment-301393942), and https://bitbucket.org/cthedot/cssutils (LGPL, and no commit for more than a year).  (And parsing still needs to go on top of that.)\r\nMoreover, having read the CSS font spec a few times, I just don't understand how the \"font\" shorthand resolves whether \"normal\" refers to \"font-weight\", \"font-stetch\", or \"font-style\".\r\nIf there's any specialist of CSS syntax I'm all ears.\r\nHowever the plan of just taking a mapping kwarg remains.","author":{"url":"https://github.com/anntzer","@type":"Person","name":"anntzer"},"datePublished":"2018-01-14T09:15:12.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/10249/matplotlib/issues/10249"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:56080153-0d6c-ea52-8af9-b9c3f96bb61d
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCCEE:2D3512:155AD50:1C5884F:6A52B597
html-safe-nonce1916a88b7d6dabb64faed90f99a8f06497ddce138b21279386997b9f547303e5
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQ0VFOjJEMzUxMjoxNTVBRDUwOjFDNTg4NEY6NkE1MkI1OTciLCJ2aXNpdG9yX2lkIjoiMjE2Nzc5NDc1NjI4NTAxOTU0MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacad733845991b184fbae8a1e7d4791123a7964abcd4ce7d1274e0de90f785db94
hovercard-subject-tagissue:288394098
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/10249/issue_layout
twitter:imagehttps://opengraph.githubassets.com/6e0a98f38d64405a163974570c5360cd45d470dfb7a1fa2c98a161fafea80eb3/matplotlib/matplotlib/issues/10249
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/6e0a98f38d64405a163974570c5360cd45d470dfb7a1fa2c98a161fafea80eb3/matplotlib/matplotlib/issues/10249
og:image:altFontProperties (henceforth "FP") is used by Matplotlib for font selection. Instances can be passed e.g. to text() (as the fontproperties kwarg) or legend() (as the prop kwarg); they behave essentia...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameanntzer
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
go-importgithub.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git
octolytics-dimension-user_id215947
octolytics-dimension-user_loginmatplotlib
octolytics-dimension-repository_id1385122
octolytics-dimension-repository_nwomatplotlib/matplotlib
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1385122
octolytics-dimension-repository_network_root_nwomatplotlib/matplotlib
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release07a982c1d40157c619b364352b704c3ce66bb332
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/matplotlib/matplotlib/issues/10249#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F10249
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F10249
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=matplotlib%2Fmatplotlib
Reloadhttps://github.com/matplotlib/matplotlib/issues/10249
Reloadhttps://github.com/matplotlib/matplotlib/issues/10249
Reloadhttps://github.com/matplotlib/matplotlib/issues/10249
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/10249
matplotlib https://github.com/matplotlib
matplotlibhttps://github.com/matplotlib/matplotlib
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/10249
Notifications https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Fork 8.4k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Star 23k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Code https://github.com/matplotlib/matplotlib
Issues 1.1k https://github.com/matplotlib/matplotlib/issues
Pull requests 408 https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality 0 https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
Code https://github.com/matplotlib/matplotlib
Issues https://github.com/matplotlib/matplotlib/issues
Pull requests https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
Various issues with FontPropertieshttps://github.com/matplotlib/matplotlib/issues/10249#top
keepItems to be ignored by the “Stale” Github Actionhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22keep%22
topic: text/fontshttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22topic%3A%20text%2Ffonts%22
future releaseshttps://github.com/matplotlib/matplotlib/milestone/25
https://github.com/anntzer
anntzerhttps://github.com/anntzer
on Jan 14, 2018https://github.com/matplotlib/matplotlib/issues/10249#issue-288394098
https://developer.mozilla.org/en-US/docs/Web/CSS/font-weighthttps://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
https://www.freedesktop.org/software/fontconfig/fontconfig-user.htmlhttps://www.freedesktop.org/software/fontconfig/fontconfig-user.html
https://lists.freedesktop.org/archives/fontconfig/2011-September/003646.htmlhttps://lists.freedesktop.org/archives/fontconfig/2011-September/003646.html
https://developer.mozilla.org/en-US/docs/Web/CSS/fonthttps://developer.mozilla.org/en-US/docs/Web/CSS/font
https://www.w3.org/TR/css-fonts-4/#font-matching-algorithmhttps://www.w3.org/TR/css-fonts-4/#font-matching-algorithm
“Size” ignored if placed before fontproperties  #16389 (comment)https://github.com/matplotlib/matplotlib/issues/16389#issuecomment-585110776
https://github.com/Kozea/tinycsshttps://github.com/Kozea/tinycss
https://github.com/Kozea/tinycss2https://github.com/Kozea/tinycss2
Kozea/tinycss2#4 (comment)https://github.com/Kozea/tinycss2/issues/4#issuecomment-301393942
https://bitbucket.org/cthedot/cssutilshttps://bitbucket.org/cthedot/cssutils
keepItems to be ignored by the “Stale” Github Actionhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22keep%22
topic: text/fontshttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22topic%3A%20text%2Ffonts%22
future releasesNo due datehttps://github.com/matplotlib/matplotlib/milestone/25
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.