ManimPango 0.6.0__cp313-cp313-macosx_10_13_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ManimPango-0.6.0.dist-info/LICENSE +21 -0
- ManimPango-0.6.0.dist-info/LICENSE.bin +3208 -0
- ManimPango-0.6.0.dist-info/METADATA +206 -0
- ManimPango-0.6.0.dist-info/RECORD +21 -0
- ManimPango-0.6.0.dist-info/WHEEL +5 -0
- ManimPango-0.6.0.dist-info/top_level.txt +1 -0
- manimpango/__init__.py +35 -0
- manimpango/_register_font.cpython-313-darwin.so +0 -0
- manimpango/_register_font.pxd +71 -0
- manimpango/_register_font.pyx +160 -0
- manimpango/_version.py +2 -0
- manimpango/cairo.pxd +27 -0
- manimpango/cmanimpango.cpython-313-darwin.so +0 -0
- manimpango/cmanimpango.pxd +3 -0
- manimpango/cmanimpango.pyx +321 -0
- manimpango/enums.cpython-313-darwin.so +0 -0
- manimpango/enums.pyx +113 -0
- manimpango/glib.pxd +13 -0
- manimpango/pango.pxd +193 -0
- manimpango/register_font.py +156 -0
- manimpango/utils.py +49 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: ManimPango
|
|
3
|
+
Version: 0.6.0
|
|
4
|
+
Summary: Bindings for Pango for using with Manim.
|
|
5
|
+
Home-page: https://manimpango.manim.community/
|
|
6
|
+
Author: Naveen M K
|
|
7
|
+
Author-email: naveen@manim.community
|
|
8
|
+
Maintainer: The Manim Community Developers
|
|
9
|
+
License: MIT
|
|
10
|
+
Project-URL: Documentation, https://manimpango.manim.community/
|
|
11
|
+
Project-URL: Source, https://github.com/ManimCommunity/manimpango
|
|
12
|
+
Project-URL: Release notes, https://github.com/ManimCommunity/ManimPango/releases/
|
|
13
|
+
Keywords: cython,pango,cairo,manim
|
|
14
|
+
Platform: Linux
|
|
15
|
+
Platform: macOS
|
|
16
|
+
Platform: Windows
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Development Status :: 4 - Beta
|
|
25
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
26
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
27
|
+
Classifier: Programming Language :: Cython
|
|
28
|
+
Requires-Python: >=3.8
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
License-File: LICENSE.bin
|
|
32
|
+
|
|
33
|
+
# ManimPango
|
|
34
|
+
|
|
35
|
+
<p align="center">
|
|
36
|
+
<a href="https://pypi.org/project/manimpango/"><img src="https://img.shields.io/pypi/v/manimpango.svg?style=flat&logo=pypi" alt="PyPI Latest Release"></a>
|
|
37
|
+
<a href="https://pypi.org/project/manimpango/"><img alt="PyPI - Wheel" src="https://img.shields.io/pypi/wheel/manimpango"></a>
|
|
38
|
+
<a href="https://pypi.org/project/manimpango/"><img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/manimpango"></a>
|
|
39
|
+
<a href="https://choosealicense.com/licenses/mit/"><img alt="PyPI - License" src="https://img.shields.io/pypi/l/manimpango"></a>
|
|
40
|
+
<a href="https://pypi.org/project/manimpango/"><img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/ManimPango.svg?style=flat"></a>
|
|
41
|
+
<a href='https://manimpango.readthedocs.io/en/latest/?badge=latest'><img src='https://readthedocs.org/projects/manimpango/badge/?version=latest' alt='Documentation Status' /></a>
|
|
42
|
+
<br>
|
|
43
|
+
<img src="https://github.com/ManimCommunity/manimpango/workflows/Build%20Wheels/badge.svg">
|
|
44
|
+
</p>
|
|
45
|
+
|
|
46
|
+
**ManimPango** is a C binding for [Pango](https://pango.gnome.org/) using [Cython](https://cython.org/), which is internally used in [Manim](https://www.manim.community) to render (non-LaTeX) text.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## INSTALL
|
|
51
|
+
|
|
52
|
+
Installing **ManimPango** is super easy, just use `pip`. It is [`manimpango`](https://pypi.org/project/manimpango/) in PyPi.
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
pip install manimpango
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
For **Linux Users**, there are no Wheels. You must have a C compiler as well as **Pango** and its dependencies along with the **Pango** development headers. See [BUILDING](#BUILDING) for more information.
|
|
59
|
+
|
|
60
|
+
## WORKFLOW SETUP / CONTRIBUTING
|
|
61
|
+
|
|
62
|
+
To make it easier for developers to contribute, we have a pre-commit workflow that will check for `black` formatting and `flake` checking.
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
pip install pre-commit
|
|
66
|
+
pre-commit install
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## BUILDING
|
|
70
|
+
|
|
71
|
+
### Linux/MacOS
|
|
72
|
+
|
|
73
|
+
For building **ManimPango**, you need
|
|
74
|
+
* a C compiler
|
|
75
|
+
* Python's development headers
|
|
76
|
+
* [`pkg-config`](https://www.freedesktop.org/wiki/Software/pkg-config/)
|
|
77
|
+
* [Pango](https://pango.gnome.org) along with its development headers and its dependencies.
|
|
78
|
+
|
|
79
|
+
If you are on MacOS, you can use [brew](https://brew.sh) to install those. Using [MacPorts](https://www.macports.org) is also possible.
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
brew install pango pkg-config
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
If you are on Linux, you can use a system package manager to do so. For example, if you are on Debian based system, you can use `apt`
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
apt install libpango1.0-dev pkg-config python3-dev
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Arch Linux:** `pacman -S pango pkgconf`
|
|
92
|
+
|
|
93
|
+
**Fedora:** `dnf install pango-devel pkg-config python3-devel`
|
|
94
|
+
|
|
95
|
+
Or similar in your system's package manager.
|
|
96
|
+
|
|
97
|
+
#### Using `tar` archives
|
|
98
|
+
|
|
99
|
+
If you don't want to contribute to this repository, you can use the tar archives published in PyPi, or just use `pip` to install using
|
|
100
|
+
|
|
101
|
+
```sh
|
|
102
|
+
pip install manimpango --no-binary :all:
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Note**: `pip` by default uses wheels, so make sure to pass the `--no-binary` parameter.
|
|
106
|
+
|
|
107
|
+
#### Using `git` clones / Contributing
|
|
108
|
+
|
|
109
|
+
Please remember to do this inside your virtual environment, if you want to use your **Manimpango** with **Manim**.
|
|
110
|
+
|
|
111
|
+
```sh
|
|
112
|
+
python -m venv ./venv
|
|
113
|
+
source venv/bin/activate # Linux/macOS
|
|
114
|
+
venv\Scripts\activate # Windows
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
If you are using a clone of this repository, you will need [Cython](https://cython.org) which can be easily installed using `pip`:
|
|
118
|
+
|
|
119
|
+
```sh
|
|
120
|
+
pip install Cython
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
After that you can use `pip` to install the clone with the following command:
|
|
124
|
+
|
|
125
|
+
```sh
|
|
126
|
+
pip install -e .
|
|
127
|
+
pip install -r requirements-dev.txt .
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Next, run the setup script:
|
|
131
|
+
|
|
132
|
+
```sh
|
|
133
|
+
python setup.py build_ext -i
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
After installation is complete, you should be able to run pytest:
|
|
137
|
+
|
|
138
|
+
```sh
|
|
139
|
+
pytest
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
You will need to this way if you want to *contribute* to **ManimPango**.
|
|
143
|
+
|
|
144
|
+
### Contributing with Windows
|
|
145
|
+
|
|
146
|
+
*If you are a normal user, don't read this, you have wheels which you can just install directly using pip.*
|
|
147
|
+
|
|
148
|
+
If you want to contribute to **ManimPango** and you are on Windows, this section is for you.
|
|
149
|
+
|
|
150
|
+
As Windows does not include a C compiler by default, you will first need to install one. You have two choices:
|
|
151
|
+
|
|
152
|
+
1. MinGW/Msys2
|
|
153
|
+
|
|
154
|
+
2. Visual Studio
|
|
155
|
+
|
|
156
|
+
#### MinGW/Msys2
|
|
157
|
+
|
|
158
|
+
1. Download **MSYS2** from the download link provided on their page https://www.msys2.org/#installation and install it according to their instructions.
|
|
159
|
+
2. Once you have **MSYS2** installed, it offers you three different shells: the **MinGW32** shell, the **MinGW64** shell and **MSYS** shell. In order for the following steps to work, you have to open the **MSYS2 MinGW64** shell (you can search for this). Small hint: it has a blue color logo.
|
|
160
|
+
3. Run the following commands to install Python, Pango, Cython, Numpy, Scipy, Pillow, Pycairo and ffmpeg
|
|
161
|
+
```sh
|
|
162
|
+
pacman -S mingw-w64-x86_64-python
|
|
163
|
+
pacman -S mingw-w64-x86_64-python-pip
|
|
164
|
+
pacman -S mingw-w64-x86_64-pango
|
|
165
|
+
pacman -S mingw-w64-x86_64-cython
|
|
166
|
+
pacman -S mingw-w64-x86_64-python-numpy
|
|
167
|
+
pacman -S mingw-w64-x86_64-python-scipy
|
|
168
|
+
pacman -S mingw-w64-x86_64-python-pillow
|
|
169
|
+
pacman -S mingw-w64-x86_64-python-cairo
|
|
170
|
+
pacman -S mingw-w64-x86_64-ffmpeg
|
|
171
|
+
```
|
|
172
|
+
4. Still in the same shell, install **Manim** using `pip install manim`.
|
|
173
|
+
5. Finally, get your clone of **ManimPango**, `cd` into that directory and then run `pip install -e .`.
|
|
174
|
+
**Note** You can't use it with your regular Python version. It will cause weird errors if you do so. For working with **ManimPango**, you must be inside the `MSYS2 MINGW64 shell`.
|
|
175
|
+
6. You can then use `manim` inside that shell, to run **Manim**.
|
|
176
|
+
**Hint**: If you want to try out Python interactively, you can open `idle` using the command `python -m idlelib` inside that shell.
|
|
177
|
+
|
|
178
|
+
#### Visual Studio
|
|
179
|
+
|
|
180
|
+
First, install Visual Studio as specified in https://wiki.python.org/moin/WindowsCompilers. Possibly Visual Studio Build Tools 2022 with Windows10 SDK.
|
|
181
|
+
|
|
182
|
+
Then run the script at `packing/download_dlls.py`. This will get a **Pango** build along with `pkg-config` and install it at `C:\cibw\vendor`. Add `C:\cibw\vendor\bin` to PATH.
|
|
183
|
+
|
|
184
|
+
**Note:** You can change the install location by editing line 24 of the file `packing/download_dlls.py`.
|
|
185
|
+
|
|
186
|
+
Then set an environment variable `PKG_CONFIG_PATH`=`C:\cibw\vendor\lib\pkgconfig`.
|
|
187
|
+
|
|
188
|
+
Then you can install Cython using
|
|
189
|
+
|
|
190
|
+
```sh
|
|
191
|
+
pip install Cython
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Finally, you can install your local **ManimPango** clone just like any other python package by typing:
|
|
195
|
+
|
|
196
|
+
```sh
|
|
197
|
+
pip install .
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Code of Conduct
|
|
201
|
+
|
|
202
|
+
Our full code of conduct, and how we enforce it, can be read on [our website](https://docs.manim.community/en/latest/conduct.html).
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
This project is licensed under MIT License. The wheels distributed on PyPI contains compiled version of Pango and Cairo subject to terms of the GNU LGPL and other licenses. Consult the licenses of each library for more informations.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
ManimPango-0.6.0.dist-info/RECORD,,
|
|
2
|
+
ManimPango-0.6.0.dist-info/LICENSE,sha256=PkzdSXTMd8X-B3IFjUlsGc9eDGAM9x7DAt8iBgLj7sg,1067
|
|
3
|
+
ManimPango-0.6.0.dist-info/WHEEL,sha256=D4knibqS7go0mKn2AokLuLqlOVIDup2AjlFmMoS-Dks,111
|
|
4
|
+
ManimPango-0.6.0.dist-info/top_level.txt,sha256=_7RXNU2cbck8IbstWHzYv6YV58wtKUDBX-pmUjE6SKs,11
|
|
5
|
+
ManimPango-0.6.0.dist-info/LICENSE.bin,sha256=qM2kte-MyVxokaHNRdgyYS0aH1yP2uLXfOwzqkLPtlA,160378
|
|
6
|
+
ManimPango-0.6.0.dist-info/METADATA,sha256=OFxqPaRwxK9SJi8QCf5qTgN0UdWBJPRIxHo3c7DgcRU,7956
|
|
7
|
+
manimpango/cmanimpango.pxd,sha256=qmQydFpNgEPYcDtfDhcaiAhu6-WyvQA0Tth09fO0sl4,62
|
|
8
|
+
manimpango/_version.py,sha256=tBvPR0sOsOC0mL_wGk5l2NiZwbLwYUDP1D3S3jG7zOA,46
|
|
9
|
+
manimpango/_register_font.pxd,sha256=0xKRYafsvYhOT2LdNuh9XfvfNQRYs4XDTCgYJTLFZ8E,2028
|
|
10
|
+
manimpango/_register_font.cpython-313-darwin.so,sha256=VK9QHZChxAa0gdFECYJ5LP8bGfnGATjxCrCh8Ibb29U,7001040
|
|
11
|
+
manimpango/__init__.py,sha256=ga7wc-Qp5exvu1OJqt3VhySoWUpqUIWsZCE_Fh3-_jc,1097
|
|
12
|
+
manimpango/cairo.pxd,sha256=qI50gJGUuAJy9A6hRZbMMwMWqfCmG5H6Tz-EWkqmvTo,771
|
|
13
|
+
manimpango/enums.pyx,sha256=ltZjDhviuWzi8pRDDkbRp3rYiZIassSpezOEOx0x3xw,2461
|
|
14
|
+
manimpango/register_font.py,sha256=KMZwJlZK1liXFWl4TslOnV-2_8A_AViecQXjMdpX5UQ,3951
|
|
15
|
+
manimpango/cmanimpango.cpython-313-darwin.so,sha256=CY3zN1r-KaGJj6azcDF_8VTu-1RCU7NkvUZu_5F_DnE,7206424
|
|
16
|
+
manimpango/utils.py,sha256=khEmMGksIdblHNbM-Rlv4r3Cj2QmP0Jf3Eb6xP1imnc,1621
|
|
17
|
+
manimpango/pango.pxd,sha256=yKu5nJUj_WP--KXshX_5i868Bc8NmdbYWoAWjaEPNBg,5344
|
|
18
|
+
manimpango/_register_font.pyx,sha256=gQGvAVMMwdEqEsz148lLzODsX-E5VRPzjObwpmpYqTM,5135
|
|
19
|
+
manimpango/cmanimpango.pyx,sha256=7X4q6SZGg7WpDGR23THbqqNQaPoYBxejQuG7M6fMxgk,11046
|
|
20
|
+
manimpango/glib.pxd,sha256=-Ua7DTGh1FCHZc7fnOUGuCsYfl5WlW7LFpGXAq6VUNM,374
|
|
21
|
+
manimpango/enums.cpython-313-darwin.so,sha256=LJmDJ6cqtBwLpFKfJBu38anhHpFNZHuWyWYhzymEICg,3975680
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
manimpango
|
manimpango/__init__.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from ._version import __version__ # noqa: F403,F401
|
|
6
|
+
|
|
7
|
+
if os.name == "nt": # pragma: no cover
|
|
8
|
+
os.environ["PATH"] = (
|
|
9
|
+
f"{os.path.abspath(os.path.dirname(__file__))}"
|
|
10
|
+
f"{os.pathsep}"
|
|
11
|
+
f"{os.environ['PATH']}"
|
|
12
|
+
)
|
|
13
|
+
try:
|
|
14
|
+
from .register_font import * # isort:skip # noqa: F403,F401
|
|
15
|
+
from .cmanimpango import * # noqa: F403,F401
|
|
16
|
+
from .enums import * # noqa: F403,F401
|
|
17
|
+
except ImportError as ie: # pragma: no cover
|
|
18
|
+
py_ver = ".".join(map(str, sys.version_info[:3]))
|
|
19
|
+
msg = f"""
|
|
20
|
+
|
|
21
|
+
ManimPango could not import and load the necessary shared libraries.
|
|
22
|
+
This error may occur when ManimPango and its dependencies are improperly set up.
|
|
23
|
+
Please make sure the following versions are what you expect:
|
|
24
|
+
|
|
25
|
+
* ManimPango v{__version__}, Python v{py_ver}
|
|
26
|
+
|
|
27
|
+
If you believe there is a greater problem,
|
|
28
|
+
feel free to contact us or create an issue on GitHub:
|
|
29
|
+
|
|
30
|
+
* Discord: https://www.manim.community/discord/
|
|
31
|
+
* GitHub: https://github.com/ManimCommunity/ManimPango/issues
|
|
32
|
+
|
|
33
|
+
Original error: {ie}
|
|
34
|
+
"""
|
|
35
|
+
raise ImportError(msg)
|
|
Binary file
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from libc.stddef cimport wchar_t
|
|
2
|
+
from pango cimport *
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
cdef extern from "Python.h":
|
|
6
|
+
wchar_t* PyUnicode_AsWideCharString(
|
|
7
|
+
object unicode,
|
|
8
|
+
Py_ssize_t* size
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
cdef extern from "fontconfig/fontconfig.h":
|
|
12
|
+
ctypedef int FcBool
|
|
13
|
+
ctypedef struct FcConfig:
|
|
14
|
+
pass
|
|
15
|
+
FcBool FcConfigAppFontAddFile(
|
|
16
|
+
FcConfig* config,
|
|
17
|
+
const unsigned char* file_name
|
|
18
|
+
)
|
|
19
|
+
FcConfig* FcConfigGetCurrent()
|
|
20
|
+
void FcConfigAppFontClear(void *)
|
|
21
|
+
|
|
22
|
+
# Windows and macOS specific API's
|
|
23
|
+
IF UNAME_SYSNAME == "Windows":
|
|
24
|
+
cdef extern from "windows.h":
|
|
25
|
+
ctypedef const wchar_t* LPCWSTR
|
|
26
|
+
ctypedef enum DWORD:
|
|
27
|
+
FR_PRIVATE
|
|
28
|
+
int AddFontResourceExW(
|
|
29
|
+
LPCWSTR name,
|
|
30
|
+
DWORD fl,
|
|
31
|
+
unsigned int res
|
|
32
|
+
)
|
|
33
|
+
bint RemoveFontResourceExW(
|
|
34
|
+
LPCWSTR name,
|
|
35
|
+
DWORD fl,
|
|
36
|
+
unsigned int pdv
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
ctypedef void* HANDLE
|
|
40
|
+
HANDLE CreateMutexA(void* lpMutexAttributes, int bInitialOwner, const char* lpName)
|
|
41
|
+
int ReleaseMutex(HANDLE hMutex)
|
|
42
|
+
int WaitForSingleObject(HANDLE hHandle, unsigned long dwMilliseconds)
|
|
43
|
+
int CloseHandle(HANDLE hObject)
|
|
44
|
+
|
|
45
|
+
ELIF UNAME_SYSNAME == "Darwin":
|
|
46
|
+
cdef extern from "Carbon/Carbon.h":
|
|
47
|
+
ctypedef struct CFURLRef:
|
|
48
|
+
pass
|
|
49
|
+
ctypedef enum CTFontManagerScope:
|
|
50
|
+
kCTFontManagerScopeProcess
|
|
51
|
+
ctypedef unsigned int UInt8
|
|
52
|
+
ctypedef long CFIndex
|
|
53
|
+
ctypedef unsigned int UInt32
|
|
54
|
+
ctypedef UInt32 CFStringEncoding
|
|
55
|
+
CFURLRef CFURLCreateWithBytes(
|
|
56
|
+
void*,
|
|
57
|
+
unsigned char *URLBytes,
|
|
58
|
+
CFIndex length,
|
|
59
|
+
CFStringEncoding encoding,
|
|
60
|
+
void*
|
|
61
|
+
)
|
|
62
|
+
bint CTFontManagerRegisterFontsForURL(
|
|
63
|
+
CFURLRef fontURL,
|
|
64
|
+
CTFontManagerScope scope,
|
|
65
|
+
void* error
|
|
66
|
+
)
|
|
67
|
+
bint CTFontManagerUnregisterFontsForURL(
|
|
68
|
+
CFURLRef fontURL,
|
|
69
|
+
CTFontManagerScope scope,
|
|
70
|
+
void* error
|
|
71
|
+
)
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from pango cimport *
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
include "utils.pxi"
|
|
8
|
+
|
|
9
|
+
@dataclass(frozen=True)
|
|
10
|
+
class RegisteredFont:
|
|
11
|
+
"""A class to represent a font file.
|
|
12
|
+
|
|
13
|
+
Attributes
|
|
14
|
+
----------
|
|
15
|
+
path : :class:`str`
|
|
16
|
+
The path to the font file.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
path: str
|
|
20
|
+
type: "fontconfig" | "win32" | "macos"
|
|
21
|
+
|
|
22
|
+
cpdef bint _fc_register_font(set registered_fonts, str font_path):
|
|
23
|
+
a = Path(font_path)
|
|
24
|
+
assert a.exists(), f"font doesn't exist at {a.absolute()}"
|
|
25
|
+
font_path = os.fspath(a.absolute())
|
|
26
|
+
font_path_bytes = font_path.encode('utf-8')
|
|
27
|
+
cdef const unsigned char* fontPath = font_path_bytes
|
|
28
|
+
fontAddStatus = FcConfigAppFontAddFile(FcConfigGetCurrent(), fontPath)
|
|
29
|
+
if fontAddStatus:
|
|
30
|
+
registered_fonts.add(RegisteredFont(font_path, "fontconfig"))
|
|
31
|
+
return True
|
|
32
|
+
else:
|
|
33
|
+
return False
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
cpdef bint _fc_unregister_font(set registered_fonts, str font_path):
|
|
37
|
+
FcConfigAppFontClear(NULL)
|
|
38
|
+
# remove all type "fontconfig" files
|
|
39
|
+
copy = registered_fonts.copy()
|
|
40
|
+
for font in copy:
|
|
41
|
+
if font.type == 'fontconfig':
|
|
42
|
+
registered_fonts.remove(font)
|
|
43
|
+
|
|
44
|
+
return True
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
IF UNAME_SYSNAME == "Linux":
|
|
48
|
+
_register_font = _fc_register_font
|
|
49
|
+
_unregister_font = _fc_unregister_font
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
ELIF UNAME_SYSNAME == "Windows":
|
|
53
|
+
cpdef bint _register_font(set registered_fonts, str font_path):
|
|
54
|
+
a = Path(font_path)
|
|
55
|
+
assert a.exists(), f"font doesn't exist at {a.absolute()}"
|
|
56
|
+
font_path = os.fspath(a.absolute())
|
|
57
|
+
cdef LPCWSTR wchar_path = PyUnicode_AsWideCharString(font_path, NULL)
|
|
58
|
+
fontAddStatus = AddFontResourceExW(
|
|
59
|
+
wchar_path,
|
|
60
|
+
FR_PRIVATE,
|
|
61
|
+
0
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
if fontAddStatus > 0:
|
|
65
|
+
registered_fonts.add(RegisteredFont(font_path, "win32"))
|
|
66
|
+
return True
|
|
67
|
+
else:
|
|
68
|
+
return False
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
cpdef bint _unregister_font(set registered_fonts, str font_path):
|
|
72
|
+
a = Path(font_path)
|
|
73
|
+
assert a.exists(), f"font doesn't exist at {a.absolute()}"
|
|
74
|
+
font_path = os.fspath(a.absolute())
|
|
75
|
+
|
|
76
|
+
font = RegisteredFont(font_path, "win32")
|
|
77
|
+
if font in registered_fonts:
|
|
78
|
+
registered_fonts.remove(font)
|
|
79
|
+
|
|
80
|
+
cdef LPCWSTR wchar_path = PyUnicode_AsWideCharString(font_path, NULL)
|
|
81
|
+
return RemoveFontResourceExW(
|
|
82
|
+
wchar_path,
|
|
83
|
+
FR_PRIVATE,
|
|
84
|
+
0
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
ELIF UNAME_SYSNAME == "Darwin":
|
|
89
|
+
cpdef bint _register_font(set registered_fonts, str font_path):
|
|
90
|
+
a = Path(font_path)
|
|
91
|
+
assert a.exists(), f"font doesn't exist at {a.absolute()}"
|
|
92
|
+
font_path_bytes_py = str(a.absolute().as_uri()).encode('utf-8')
|
|
93
|
+
cdef unsigned char* font_path_bytes = <bytes>font_path_bytes_py
|
|
94
|
+
b = len(a.absolute().as_uri())
|
|
95
|
+
cdef CFURLRef cf_url = CFURLCreateWithBytes(NULL, font_path_bytes, b, 0x08000100, NULL)
|
|
96
|
+
res = CTFontManagerRegisterFontsForURL(
|
|
97
|
+
cf_url,
|
|
98
|
+
kCTFontManagerScopeProcess,
|
|
99
|
+
NULL
|
|
100
|
+
)
|
|
101
|
+
if res:
|
|
102
|
+
registered_fonts.add(RegisteredFont(os.fspath(a.absolute()), "macos"))
|
|
103
|
+
return True
|
|
104
|
+
else:
|
|
105
|
+
return False
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
cpdef bint _unregister_font(set registered_fonts, str font_path):
|
|
109
|
+
a = Path(font_path)
|
|
110
|
+
assert a.exists(), f"font doesn't exist at {a.absolute()}"
|
|
111
|
+
font_path_bytes_py = str(a.absolute().as_uri()).encode('utf-8')
|
|
112
|
+
cdef unsigned char* font_path_bytes = <bytes>font_path_bytes_py
|
|
113
|
+
b = len(a.absolute().as_uri())
|
|
114
|
+
cdef CFURLRef cf_url = CFURLCreateWithBytes(NULL, font_path_bytes, b, 0x08000100, NULL)
|
|
115
|
+
res = CTFontManagerUnregisterFontsForURL(
|
|
116
|
+
cf_url,
|
|
117
|
+
kCTFontManagerScopeProcess,
|
|
118
|
+
NULL
|
|
119
|
+
)
|
|
120
|
+
if res:
|
|
121
|
+
font = RegisteredFont(os.fspath(a.absolute()), "macos")
|
|
122
|
+
if font in registered_fonts:
|
|
123
|
+
registered_fonts.remove(font)
|
|
124
|
+
return True
|
|
125
|
+
else:
|
|
126
|
+
return False
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
cpdef list _list_fonts(tuple registered_fonts):
|
|
130
|
+
cdef PangoFontMap* fontmap = pango_cairo_font_map_new()
|
|
131
|
+
if fontmap == NULL:
|
|
132
|
+
raise MemoryError("Pango.FontMap can't be created.")
|
|
133
|
+
|
|
134
|
+
for font in registered_fonts:
|
|
135
|
+
if font.type == 'win32':
|
|
136
|
+
add_to_fontmap(fontmap, font.path)
|
|
137
|
+
|
|
138
|
+
cdef int n_families=0
|
|
139
|
+
cdef PangoFontFamily** families=NULL
|
|
140
|
+
pango_font_map_list_families(
|
|
141
|
+
fontmap,
|
|
142
|
+
&families,
|
|
143
|
+
&n_families
|
|
144
|
+
)
|
|
145
|
+
if families is NULL or n_families == 0:
|
|
146
|
+
raise MemoryError("Pango returned unexpected length on families.")
|
|
147
|
+
|
|
148
|
+
family_list = []
|
|
149
|
+
for i in range(n_families):
|
|
150
|
+
name = pango_font_family_get_name(families[i])
|
|
151
|
+
# according to pango's docs, the `char *` returned from
|
|
152
|
+
# `pango_font_family_get_name`is owned by pango, and python
|
|
153
|
+
# shouldn't interfere with it. I hope Cython handles it.
|
|
154
|
+
# https://cython.readthedocs.io/en/stable/src/tutorial/strings.html#dealing-with-const
|
|
155
|
+
family_list.append(name.decode())
|
|
156
|
+
|
|
157
|
+
g_free(families)
|
|
158
|
+
g_object_unref(fontmap)
|
|
159
|
+
family_list.sort()
|
|
160
|
+
return family_list
|
manimpango/_version.py
ADDED
manimpango/cairo.pxd
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
cdef extern from "cairo.h":
|
|
2
|
+
ctypedef struct cairo_surface_t:
|
|
3
|
+
pass
|
|
4
|
+
ctypedef struct cairo_t:
|
|
5
|
+
pass
|
|
6
|
+
ctypedef enum cairo_status_t:
|
|
7
|
+
CAIRO_STATUS_SUCCESS
|
|
8
|
+
CAIRO_STATUS_NO_MEMORY
|
|
9
|
+
cairo_t* cairo_create(cairo_surface_t* target)
|
|
10
|
+
void cairo_move_to(
|
|
11
|
+
cairo_t* cr,
|
|
12
|
+
double x,
|
|
13
|
+
double y
|
|
14
|
+
)
|
|
15
|
+
void cairo_destroy(cairo_t* cr)
|
|
16
|
+
void cairo_surface_destroy(cairo_surface_t* surface)
|
|
17
|
+
|
|
18
|
+
cairo_status_t cairo_status(cairo_t *cr)
|
|
19
|
+
const char* cairo_status_to_string(cairo_status_t status)
|
|
20
|
+
const char* cairo_version_string()
|
|
21
|
+
|
|
22
|
+
cdef extern from "cairo-svg.h":
|
|
23
|
+
cairo_surface_t* cairo_svg_surface_create(
|
|
24
|
+
const char* filename,
|
|
25
|
+
double width_in_points,
|
|
26
|
+
double height_in_points
|
|
27
|
+
)
|
|
Binary file
|