diff --git a/docs/fonts.py b/docs/fonts.py index 477b69b27..c3250c668 100644 --- a/docs/fonts.py +++ b/docs/fonts.py @@ -61,32 +61,60 @@ # :rcraw:`font.fantasy` = ``'TeX Gyre Adventor'``. # # After importing proplot, the default matplotlib font will be -# `TeX Gyre Heros `__, -# which emulates the more conventional and (in our opinion) aesthetically pleasing -# font `Helvetica `__. The new default font +# `TeX Gyre Heros `__, which +# emulates the more conventional and (in our opinion) aesthetically pleasing +# font `Helvetica `__. The default font # family lists are shown in the :ref:`default proplotrc file `. -# # To compare different fonts, use the `~proplot.demos.show_fonts` command with the # `family` keyword (default behavior is ``family='sans-serif'``). Tables of the TeX -# Gyre and sans-serif fonts packaged with proplot are shown below. In order to show how -# the fonts perform as math text, the demo is rendered with :rcraw:`mathtext.default` -# = ``'regular'``, :rcraw:`mathtext.fontset` = ``'custom'``, and -# :rcraw:`mathtext.fallback` = ``None``. This uses the global :rcraw:`font.family` -# for the math text and shows a dummy glyph "¤" is shown where math characters -# are unavailable (see the matplotlib `math text guide -# `__ -# for details). In practice, proplot uses a standard non-italicized math -# text everywhere by setting :rc:`mathtext.fontset` = ``'stixsans'`` and -# :rcraw:`mathtext.default = 'rm'` (see the :ref:`proplotrc file ` -# for details). +# Gyre and sans-serif fonts packaged with proplot are shown below. # %% import proplot as pplt -fig, axs = pplt.show_fonts(family='tex-gyre') +fig, axs = pplt.show_fonts(family='tex-gyre', show_math=False) + +# %% +import proplot as pplt +fig, axs = pplt.show_fonts(family='sans-serif', show_math=False) + +# %% [raw] raw_mimetype="text/restructuredtext" +# .. _ug_fonts_math: +# +# Math fonts +# ---------- +# +# Proplot changes the default :rcraw:`mathtext.fontset` from ``'dejavusans'`` to +# ``'custom'``. This means that LaTeX-generated math text in a given string (i.e., +# text surrounded by ``'$dollar signs$'``) uses the same font +# family as non-math text (see the matplotlib `math text guide +# `__ for +# details). This improves the consistency of figure text when switching between +# different fonts. However if you are rendering very complex equations, +# you may want to change the default font to the matplotlib-packaged +# font ``'DejaVu Sans'`` or the proplot-packaged font ``'Fira Math'`` (see +# `this page `__ for more on Fira Math). +# Tables of the TeX Gyre and sans-serif fonts packaged with proplot are +# shown below. A dummy glyph "¤" is shown where math characters are unavailable +# for a particular font (in practice, the fallback font :rc:`mathtext.fallback` +# is used whenever a math character is unavailable, but the demo function +# disables the fallback font to highlight which characters are unavailable). +# +# .. note:: +# +# Proplot modifies the matplotlib math text internals so that the ``'custom'`` +# font set can be applied with modifications to the currently active non-math +# font rather than only a global font family. This works by changing the default +# values of :rcraw:`mathtext.bf`, :rcraw:`mathtext.it`, :rcraw:`mathtext.rm`, +# :rcraw:`mathtext.sf` from the global default font family ``'sans'`` to the local +# font family ``'regular'``, where ``'regular'`` is a dummy name permitted by +# proplot (see the :ref:`proplotrc file ` for details). This means +# that if :rcraw:`mathtext.fontset` is ``'custom'`` and the font family is changed +# for an arbitrary `~matplotlib.text.Text` instance, then any LaTeX-generated math +# in the text string will also use this font family. # %% import proplot as pplt -fig, axs = pplt.show_fonts(family='sans-serif') +fig, axs = pplt.show_fonts(family='sans-serif', show_math=True) # %% [raw] raw_mimetype="text/restructuredtext" # .. _ug_fonts_user: diff --git a/proplot/demos.py b/proplot/demos.py index 4c273dc14..efd3a7522 100644 --- a/proplot/demos.py +++ b/proplot/demos.py @@ -795,7 +795,7 @@ def show_colors(*, nhues=17, minsat=10, unknown='User', include=None, ignore=Non def show_fonts( - *args, family=None, text=None, + *args, family=None, text=None, show_math=True, size=12, weight='normal', style='normal', stretch='normal', ): """ @@ -841,8 +841,8 @@ def show_fonts( show_cycles show_colors """ - # Select fonts for plotting. Default is to show sans-serif fonts. Otherwise - # fonts can be specified as input arguments or with the family keyword + # Select fonts for plotting. Default is to show sans-serif and user fonts. + # Otherwise fonts can be specified as input arguments or with the family keyword if not args and family is None: args = sorted( { @@ -881,23 +881,28 @@ def show_fonts( # The default sample text if text is None: - text = ( - 'the quick brown fox jumps over a lazy dog' '\n' - 'THE QUICK BROWN FOX JUMPS OVER A LAZY DOG' '\n' - '(0) + {1\N{DEGREE SIGN}} \N{MINUS SIGN} [2*] - <3> / 4,0 ' - r'$\geq\gg$ 5.0 $\leq\ll$ ~6 $\times$ 7 ' - r'$\equiv$ 8 $\approx$ 9 $\propto$' '\n' - r'$\alpha\beta$ $\Gamma\gamma$ $\Delta\delta$ ' - r'$\epsilon\zeta\eta$ $\Theta\theta$ $\kappa\mu\nu$ ' - r'$\Lambda\lambda$ $\Pi\pi$ $\xi\rho\tau\chi$ $\Sigma\sigma$ ' - r'$\Phi\phi$ $\Psi\psi$ $\Omega\omega$ !?&#%' - ) + if not show_math: + text = ( + 'the quick brown fox jumps over a lazy dog . , + -' + '\n' + 'THE QUICK BROWN FOX JUMPS OVER A LAZY DOG ! ? & # %' + ) + else: + text = ( + r'$\alpha\beta$ $\Gamma\gamma$ $\Delta\delta$ ' + r'$\epsilon\zeta\eta$ $\Theta\theta$ $\kappa\mu\nu$ ' + r'$\Lambda\lambda$ $\Pi\pi$ $\xi\rho\tau\chi$ $\Sigma\sigma$ ' + r'$\Phi\phi$ $\Psi\psi$ $\Omega\omega$ ' + r'$\ll { }^k \gg [ ]_l \propto ( )^m \cdot \left<\right>_n$' + '\n' + r'$0^a + 1_b - 2^c \times 3_d = ' + r'4.0^e \equiv 5.0_f \approx 6.0^g \sim 7_h \leq 8^i \geq 9_j' + r'\sum X \ll \int Y \gg \oint Z \propto \prod Q$' + '\n' + ) # Settings for rendering math text - ctx = { - 'mathtext.default': 'regular', - 'mathtext.fontset': 'custom', - } + ctx = {'mathtext.fontset': 'custom'} if _version_mpl < 3.4: ctx['mathtext.fallback_to_cm'] = False else: diff --git a/proplot/fonts/FiraSans-Black.ttf b/proplot/fonts/FiraSans-Black.ttf new file mode 100644 index 000000000..3087a31bc Binary files /dev/null and b/proplot/fonts/FiraSans-Black.ttf differ diff --git a/proplot/fonts/FiraSans-BlackItalic.ttf b/proplot/fonts/FiraSans-BlackItalic.ttf new file mode 100644 index 000000000..9a9ef5e84 Binary files /dev/null and b/proplot/fonts/FiraSans-BlackItalic.ttf differ diff --git a/proplot/fonts/FiraSans-Bold.ttf b/proplot/fonts/FiraSans-Bold.ttf new file mode 100644 index 000000000..0fb896aec Binary files /dev/null and b/proplot/fonts/FiraSans-Bold.ttf differ diff --git a/proplot/fonts/FiraSans-BoldItalic.ttf b/proplot/fonts/FiraSans-BoldItalic.ttf new file mode 100644 index 000000000..e7e936f7b Binary files /dev/null and b/proplot/fonts/FiraSans-BoldItalic.ttf differ diff --git a/proplot/fonts/FiraSans-ExtraBold.ttf b/proplot/fonts/FiraSans-ExtraBold.ttf new file mode 100644 index 000000000..4b29d6f8a Binary files /dev/null and b/proplot/fonts/FiraSans-ExtraBold.ttf differ diff --git a/proplot/fonts/FiraSans-ExtraBoldItalic.ttf b/proplot/fonts/FiraSans-ExtraBoldItalic.ttf new file mode 100644 index 000000000..de3b83b48 Binary files /dev/null and b/proplot/fonts/FiraSans-ExtraBoldItalic.ttf differ diff --git a/proplot/fonts/FiraSans-ExtraLight.ttf b/proplot/fonts/FiraSans-ExtraLight.ttf new file mode 100644 index 000000000..e5755da8d Binary files /dev/null and b/proplot/fonts/FiraSans-ExtraLight.ttf differ diff --git a/proplot/fonts/FiraSans-ExtraLightItalic.ttf b/proplot/fonts/FiraSans-ExtraLightItalic.ttf new file mode 100644 index 000000000..890524e9f Binary files /dev/null and b/proplot/fonts/FiraSans-ExtraLightItalic.ttf differ diff --git a/proplot/fonts/FiraSans-Italic.ttf b/proplot/fonts/FiraSans-Italic.ttf new file mode 100644 index 000000000..36efca2a7 Binary files /dev/null and b/proplot/fonts/FiraSans-Italic.ttf differ diff --git a/proplot/fonts/FiraSans-Light.ttf b/proplot/fonts/FiraSans-Light.ttf new file mode 100644 index 000000000..fac4edf54 Binary files /dev/null and b/proplot/fonts/FiraSans-Light.ttf differ diff --git a/proplot/fonts/FiraSans-LightItalic.ttf b/proplot/fonts/FiraSans-LightItalic.ttf new file mode 100644 index 000000000..1daa0bcce Binary files /dev/null and b/proplot/fonts/FiraSans-LightItalic.ttf differ diff --git a/proplot/fonts/FiraSans-Medium.ttf b/proplot/fonts/FiraSans-Medium.ttf new file mode 100644 index 000000000..eeb8f8f0b Binary files /dev/null and b/proplot/fonts/FiraSans-Medium.ttf differ diff --git a/proplot/fonts/FiraSans-MediumItalic.ttf b/proplot/fonts/FiraSans-MediumItalic.ttf new file mode 100644 index 000000000..328b53b2c Binary files /dev/null and b/proplot/fonts/FiraSans-MediumItalic.ttf differ diff --git a/proplot/fonts/FiraSans-Regular.ttf b/proplot/fonts/FiraSans-Regular.ttf new file mode 100644 index 000000000..c4cfa5975 Binary files /dev/null and b/proplot/fonts/FiraSans-Regular.ttf differ diff --git a/proplot/fonts/FiraSans-SemiBold.ttf b/proplot/fonts/FiraSans-SemiBold.ttf new file mode 100644 index 000000000..954a2cab8 Binary files /dev/null and b/proplot/fonts/FiraSans-SemiBold.ttf differ diff --git a/proplot/fonts/FiraSans-SemiBoldItalic.ttf b/proplot/fonts/FiraSans-SemiBoldItalic.ttf new file mode 100644 index 000000000..55e812c66 Binary files /dev/null and b/proplot/fonts/FiraSans-SemiBoldItalic.ttf differ diff --git a/proplot/fonts/LICENSE_FIRASANS.txt b/proplot/fonts/LICENSE_FIRASANS.txt new file mode 100644 index 000000000..70e4f161e --- /dev/null +++ b/proplot/fonts/LICENSE_FIRASANS.txt @@ -0,0 +1,97 @@ +Copyright (c) , (), +with Reserved Font Name . +Copyright (c) , (), +with Reserved Font Name . +Copyright (c) , (). + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/proplot/fonts/LICENSE_NOTOSERIF.txt b/proplot/fonts/LICENSE_NOTOSERIF.txt new file mode 100644 index 000000000..fce27fb35 --- /dev/null +++ b/proplot/fonts/LICENSE_NOTOSERIF.txt @@ -0,0 +1,93 @@ +Copyright 2012 Google Inc. All Rights Reserved. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/proplot/fonts/LICENSE_SOURCESERIF.txt b/proplot/fonts/LICENSE_SOURCESERIF.txt new file mode 100644 index 000000000..e6efdaf8e --- /dev/null +++ b/proplot/fonts/LICENSE_SOURCESERIF.txt @@ -0,0 +1,93 @@ +Copyright 2014 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/proplot/fonts/NotoSerif-Bold.ttf b/proplot/fonts/NotoSerif-Bold.ttf new file mode 100644 index 000000000..156cfcbe0 Binary files /dev/null and b/proplot/fonts/NotoSerif-Bold.ttf differ diff --git a/proplot/fonts/NotoSerif-BoldItalic.ttf b/proplot/fonts/NotoSerif-BoldItalic.ttf new file mode 100644 index 000000000..d82186466 Binary files /dev/null and b/proplot/fonts/NotoSerif-BoldItalic.ttf differ diff --git a/proplot/fonts/NotoSerif-Italic.ttf b/proplot/fonts/NotoSerif-Italic.ttf new file mode 100644 index 000000000..101bb8c2d Binary files /dev/null and b/proplot/fonts/NotoSerif-Italic.ttf differ diff --git a/proplot/fonts/NotoSerif-Regular.ttf b/proplot/fonts/NotoSerif-Regular.ttf new file mode 100644 index 000000000..e5587fc7a Binary files /dev/null and b/proplot/fonts/NotoSerif-Regular.ttf differ diff --git a/proplot/fonts/SourceSerifPro-Black.ttf b/proplot/fonts/SourceSerifPro-Black.ttf new file mode 100644 index 000000000..4562a7ff3 Binary files /dev/null and b/proplot/fonts/SourceSerifPro-Black.ttf differ diff --git a/proplot/fonts/SourceSerifPro-BlackItalic.ttf b/proplot/fonts/SourceSerifPro-BlackItalic.ttf new file mode 100644 index 000000000..ff6397a71 Binary files /dev/null and b/proplot/fonts/SourceSerifPro-BlackItalic.ttf differ diff --git a/proplot/fonts/SourceSerifPro-Bold.ttf b/proplot/fonts/SourceSerifPro-Bold.ttf new file mode 100644 index 000000000..bf782fb56 Binary files /dev/null and b/proplot/fonts/SourceSerifPro-Bold.ttf differ diff --git a/proplot/fonts/SourceSerifPro-BoldItalic.ttf b/proplot/fonts/SourceSerifPro-BoldItalic.ttf new file mode 100644 index 000000000..1461f4a45 Binary files /dev/null and b/proplot/fonts/SourceSerifPro-BoldItalic.ttf differ diff --git a/proplot/fonts/SourceSerifPro-ExtraLight.ttf b/proplot/fonts/SourceSerifPro-ExtraLight.ttf new file mode 100644 index 000000000..f1cca5513 Binary files /dev/null and b/proplot/fonts/SourceSerifPro-ExtraLight.ttf differ diff --git a/proplot/fonts/SourceSerifPro-ExtraLightItalic.ttf b/proplot/fonts/SourceSerifPro-ExtraLightItalic.ttf new file mode 100644 index 000000000..d1bde716d Binary files /dev/null and b/proplot/fonts/SourceSerifPro-ExtraLightItalic.ttf differ diff --git a/proplot/fonts/SourceSerifPro-Italic.ttf b/proplot/fonts/SourceSerifPro-Italic.ttf new file mode 100644 index 000000000..4baaf1d0d Binary files /dev/null and b/proplot/fonts/SourceSerifPro-Italic.ttf differ diff --git a/proplot/fonts/SourceSerifPro-Light.ttf b/proplot/fonts/SourceSerifPro-Light.ttf new file mode 100644 index 000000000..ff60489b9 Binary files /dev/null and b/proplot/fonts/SourceSerifPro-Light.ttf differ diff --git a/proplot/fonts/SourceSerifPro-LightItalic.ttf b/proplot/fonts/SourceSerifPro-LightItalic.ttf new file mode 100644 index 000000000..b202bd5f6 Binary files /dev/null and b/proplot/fonts/SourceSerifPro-LightItalic.ttf differ diff --git a/proplot/fonts/SourceSerifPro-Regular.ttf b/proplot/fonts/SourceSerifPro-Regular.ttf new file mode 100644 index 000000000..e6c5dff97 Binary files /dev/null and b/proplot/fonts/SourceSerifPro-Regular.ttf differ diff --git a/proplot/fonts/SourceSerifPro-SemiBold.ttf b/proplot/fonts/SourceSerifPro-SemiBold.ttf new file mode 100644 index 000000000..b0f8edc60 Binary files /dev/null and b/proplot/fonts/SourceSerifPro-SemiBold.ttf differ diff --git a/proplot/fonts/SourceSerifPro-SemiBoldItalic.ttf b/proplot/fonts/SourceSerifPro-SemiBoldItalic.ttf new file mode 100644 index 000000000..040e7fc7a Binary files /dev/null and b/proplot/fonts/SourceSerifPro-SemiBoldItalic.ttf differ diff --git a/proplot/internals/__init__.py b/proplot/internals/__init__.py index cd8cae9e4..62ce40482 100644 --- a/proplot/internals/__init__.py +++ b/proplot/internals/__init__.py @@ -48,6 +48,7 @@ def _not_none(*args, default=None, **kwargs): benchmarks, context, docstring, + fonts, guides, inputs, labels, diff --git a/proplot/internals/fonts.py b/proplot/internals/fonts.py new file mode 100644 index 000000000..9608de6ba --- /dev/null +++ b/proplot/internals/fonts.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +""" +Overrides related to math fonts +""" +import matplotlib as mpl +from matplotlib.font_manager import findfont, ttfFontProperty +from matplotlib.mathtext import MathTextParser + +from . import warnings + +try: # newer versions + from matplotlib._mathtext import UnicodeFonts +except ImportError: # older versions + from matplotlib.mathtext import UnicodeFonts + + +class _UnicodeFonts(UnicodeFonts): + """ + A simple `~matplotlib._mathtext.UnicodeFonts` subclass that + interprets ``rc['mathtext.default'] != 'regular'`` in the presence of + ``rc['mathtext.fontset'] == 'custom'`` as possibly modifying the active font. + + Works by permitting the ``rc['mathtext.rm']``, ``rc['mathtext.it']``, + etc. settings to have the dummy value ``'current'`` instead of a valid family + name, e.g. ``rc['mathtext.it'] == 'current:italic'`` (permitted through an + override of the `~matplotlib.rcsetup.validate_font_properties` validator). + When this dummy value is detected then the font properties passed to + `~matplotlib._mathtext.TrueTypeFont` are taken by replacing ``'current'`` + in the "math" fontset with the active font name. + """ + def __init__(self, *args, **kwargs): + # Initialize font + # NOTE: Could also capture the 'default_font_prop' passed as positional + # argument but want to guard against keyword changes. This entire API is + # private and it is easier to do graceful fallback with _fonts dictionary. + ctx = {} # rc context + regular = {} # styles + for texfont in ('cal', 'rm', 'tt', 'it', 'bf', 'sf'): + key = 'mathtext.' + texfont + prop = mpl.rcParams[key] + if prop.startswith('regular'): + ctx[key] = prop.replace('regular', 'sans', 1) + regular[texfont] = prop + with mpl.rc_context(ctx): + super().__init__(*args, **kwargs) + # Apply current font replacements + if ( + not hasattr(self, 'fontmap') + or not hasattr(self, '_fonts') + or 'regular' not in self._fonts + ): + warnings._warn_proplot('Failed to update math text parser.') + else: + font = self._fonts['regular'] # an ft2font.FT2Font instance + font = ttfFontProperty(font) + for texfont, prop in regular.items(): + prop = prop.replace('regular', font.name) + self.fontmap[texfont] = findfont(prop, fallback_to_default=False) + + +# Replace the parser +try: + mapping = MathTextParser._font_type_mapping + if mapping['custom'] is UnicodeFonts: + mapping['custom'] = _UnicodeFonts +except (KeyError, AttributeError): + warnings._warn_proplot('Failed to update math text parser.') diff --git a/proplot/internals/rcsetup.py b/proplot/internals/rcsetup.py index 42fc2e959..052fa9fe2 100644 --- a/proplot/internals/rcsetup.py +++ b/proplot/internals/rcsetup.py @@ -14,6 +14,7 @@ from matplotlib import rcParamsDefault as _rc_matplotlib_native from matplotlib.colors import Colormap from matplotlib.font_manager import font_scalings +from matplotlib.fontconfig_pattern import parse_fontconfig_pattern from . import ic # noqa: F401 from . import warnings @@ -263,6 +264,19 @@ def _validate_color(value, alternative=None): raise error +def _validate_fontprops(s): + """ + Parse font property with support for ``'regular'`` placeholder. + """ + b = s.startswith('regular') + if b: + s = s.replace('regular', 'sans', 1) + parse_fontconfig_pattern(s) + if b: + s = s.replace('sans', 'regular', 1) + return s + + def _validate_fontsize(value): """ Validate font size with new scalings and permitting other units. @@ -507,13 +521,15 @@ def copy(self): _validate['image.cmap'] = _validate_cmap('continuous') _validate['legend.loc'] = _validate_options(*LEGEND_LOCS) for _key, _validator in _validate.items(): - if _validator is msetup.validate_fontsize: + if _validator is getattr(msetup, 'validate_fontsize', None): # should exist FONT_KEYS.add(_key) _validate[_key] = _validate_fontsize if _validator is getattr(msetup, 'validate_fontsize_None', None): FONT_KEYS.add(_key) _validate[_key] = _validate_or_none(_validate_fontsize) - if _validator is msetup.validate_color: + if _validator is getattr(msetup, 'validate_font_properties', None): + _validate[_key] = _validate_fontprops + if _validator is getattr(msetup, 'validate_color', None): # should exist _validate[_key] = _validate_color if _validator is getattr(msetup, 'validate_color_or_auto', None): _validate[_key] = functools.partial(_validate_color, alternative='auto') @@ -571,7 +587,9 @@ def copy(self): 'ITC Bookman', 'New Century Schoolbook', 'Nimbus Roman No9 L', + 'Noto Serif', 'Palatino', + 'Source Serif Pro', 'Times New Roman', 'Times', 'Utopia', @@ -585,6 +603,7 @@ def copy(self): 'Arial', 'Avenir', 'Fira Math', + 'Fira Sans', 'Frutiger', 'Geneva', 'Gill Sans', @@ -660,8 +679,14 @@ def copy(self): 'legend.fontsize': SMALLSIZE, 'legend.framealpha': FRAMEALPHA, 'legend.handletextpad': 0.5, - 'mathtext.default': 'rm', - 'mathtext.fontset': 'stixsans', + 'mathtext.default': 'it', + 'mathtext.fontset': 'custom', + 'mathtext.bf': 'regular:bold', # custom settings implemented above + 'mathtext.cal': 'cursive', + 'mathtext.it': 'regular:italic', + 'mathtext.rm': 'regular', + 'mathtext.sf': 'regular', + 'mathtext.tt': 'monospace', 'patch.linewidth': LINEWIDTH, 'savefig.bbox': None, # use custom tight layout 'savefig.directory': '', # current directory