ManimPango 0.6.0__cp313-cp313-win32.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.win32 +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.cp313-win32.pyd +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.cp313-win32.pyd +0 -0
- manimpango/cmanimpango.pxd +3 -0
- manimpango/cmanimpango.pyx +321 -0
- manimpango/enums.cp313-win32.pyd +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,156 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from functools import lru_cache
|
|
5
|
+
|
|
6
|
+
from ._register_font import (
|
|
7
|
+
RegisteredFont,
|
|
8
|
+
_fc_register_font,
|
|
9
|
+
_fc_unregister_font,
|
|
10
|
+
_list_fonts,
|
|
11
|
+
_register_font,
|
|
12
|
+
_unregister_font,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"fc_register_font",
|
|
17
|
+
"fc_unregister_font",
|
|
18
|
+
"list_fonts",
|
|
19
|
+
"register_font",
|
|
20
|
+
"unregister_font",
|
|
21
|
+
"registered_fonts",
|
|
22
|
+
"RegisteredFont",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
# An set of all registered font paths
|
|
26
|
+
registered_fonts: set[RegisteredFont] = set()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def fc_register_font(font_path: str) -> None:
|
|
30
|
+
"""This function registers the font file using ``fontconfig`` so that
|
|
31
|
+
it is available for use by Pango. On Linux it is aliased to
|
|
32
|
+
:func:`register_font` and on Windows and macOS this would work only when
|
|
33
|
+
using ``fontconfig`` backend.
|
|
34
|
+
|
|
35
|
+
Parameters
|
|
36
|
+
==========
|
|
37
|
+
font_path : :class:`str`
|
|
38
|
+
Relative or absolute path to font file.
|
|
39
|
+
|
|
40
|
+
Returns
|
|
41
|
+
=======
|
|
42
|
+
:class:`bool`
|
|
43
|
+
True means it worked without any error.
|
|
44
|
+
False means there was an unknown error
|
|
45
|
+
|
|
46
|
+
Examples
|
|
47
|
+
========
|
|
48
|
+
>>> register_font("/home/roboto.tff")
|
|
49
|
+
True
|
|
50
|
+
|
|
51
|
+
Raises
|
|
52
|
+
======
|
|
53
|
+
AssertionError
|
|
54
|
+
The :param:`font_path` specified doesn't exist.
|
|
55
|
+
"""
|
|
56
|
+
return _fc_register_font(registered_fonts, font_path)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def fc_unregister_font(font_path: str) -> None:
|
|
60
|
+
"""This function unregister (removes) the font file using
|
|
61
|
+
``fontconfig``. It is mostly optional to call this.
|
|
62
|
+
Mainly used in tests. On Linux it is aliased to
|
|
63
|
+
:func:`unregister_font` and on Windows and macOS this
|
|
64
|
+
would work only when using ``fontconfig`` backend.
|
|
65
|
+
|
|
66
|
+
Parameters
|
|
67
|
+
==========
|
|
68
|
+
font_path: :class:`str`
|
|
69
|
+
For compatibility with the windows function.
|
|
70
|
+
|
|
71
|
+
Returns
|
|
72
|
+
=======
|
|
73
|
+
:class:`bool`
|
|
74
|
+
True means it worked without any error.
|
|
75
|
+
False means there was an unknown error
|
|
76
|
+
|
|
77
|
+
"""
|
|
78
|
+
return _fc_unregister_font(registered_fonts, font_path)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def register_font(font_path: str) -> None:
|
|
82
|
+
"""This function registers the font file using native OS API
|
|
83
|
+
to make the font available for use by Pango. On Linux it is
|
|
84
|
+
aliased to :func:`fc_register_font` and on Windows and macOS
|
|
85
|
+
it uses the native API.
|
|
86
|
+
|
|
87
|
+
Parameters
|
|
88
|
+
==========
|
|
89
|
+
font_path: :class:`str`
|
|
90
|
+
Relative or absolute path to font file.
|
|
91
|
+
|
|
92
|
+
Returns
|
|
93
|
+
=======
|
|
94
|
+
:class:`bool`
|
|
95
|
+
True means it worked without any error.
|
|
96
|
+
False means there was an unknown error
|
|
97
|
+
|
|
98
|
+
Examples
|
|
99
|
+
========
|
|
100
|
+
>>> register_font("C:/home/roboto.tff")
|
|
101
|
+
True
|
|
102
|
+
|
|
103
|
+
Raises
|
|
104
|
+
======
|
|
105
|
+
AssertionError
|
|
106
|
+
The :param:`font_path` specified doesn't exist.
|
|
107
|
+
"""
|
|
108
|
+
return _register_font(registered_fonts, font_path)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def unregister_font(font_path: str) -> None:
|
|
112
|
+
"""This function unregister (removes) the font file using native OS API.
|
|
113
|
+
It is mostly optional to call this. Mainly used in tests. On Linux it is
|
|
114
|
+
aliased to :func:`fc_unregister_font` and on Windows and macOS it uses
|
|
115
|
+
the native API.
|
|
116
|
+
|
|
117
|
+
Parameters
|
|
118
|
+
==========
|
|
119
|
+
font_path: :class:`str`
|
|
120
|
+
Relative or absolute path to font file.
|
|
121
|
+
|
|
122
|
+
Returns
|
|
123
|
+
=======
|
|
124
|
+
:class:`bool`
|
|
125
|
+
True means it worked without any error.
|
|
126
|
+
False means there was an unknown error
|
|
127
|
+
|
|
128
|
+
Examples
|
|
129
|
+
========
|
|
130
|
+
>>> unregister_font("C:/home/roboto.tff")
|
|
131
|
+
True
|
|
132
|
+
|
|
133
|
+
Raises
|
|
134
|
+
======
|
|
135
|
+
AssertionError
|
|
136
|
+
The :param:`font_path` specified doesn't exist.
|
|
137
|
+
|
|
138
|
+
"""
|
|
139
|
+
return _unregister_font(registered_fonts, font_path)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def list_fonts() -> list:
|
|
143
|
+
"""Lists the fonts available to Pango.
|
|
144
|
+
This is usually same as system fonts but it also
|
|
145
|
+
includes the fonts added through :func:`register_font`
|
|
146
|
+
or :func:`fc_register_font`.
|
|
147
|
+
|
|
148
|
+
Returns
|
|
149
|
+
-------
|
|
150
|
+
|
|
151
|
+
:class:`list` :
|
|
152
|
+
List of fonts sorted alphabetically.
|
|
153
|
+
"""
|
|
154
|
+
return lru_cache(maxsize=None)(_list_fonts)(
|
|
155
|
+
tuple(sorted(registered_fonts, key=lambda x: x.path))
|
|
156
|
+
)
|
manimpango/utils.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
from .enums import Style, Weight
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class PangoUtils:
|
|
8
|
+
@staticmethod
|
|
9
|
+
def str2style(string: str) -> Style:
|
|
10
|
+
"""Internally used function. Converts text to Pango Understandable Styles."""
|
|
11
|
+
styles = {
|
|
12
|
+
"NORMAL": Style.NORMAL,
|
|
13
|
+
"ITALIC": Style.ITALIC,
|
|
14
|
+
"OBLIQUE": Style.OBLIQUE,
|
|
15
|
+
}
|
|
16
|
+
try:
|
|
17
|
+
return styles[string]
|
|
18
|
+
except KeyError:
|
|
19
|
+
raise AttributeError("There is no Style Called %s" % string)
|
|
20
|
+
|
|
21
|
+
@staticmethod
|
|
22
|
+
def str2weight(string: str) -> Weight:
|
|
23
|
+
"""Internally used function. Convert text to Pango Understandable Weight"""
|
|
24
|
+
weights = {
|
|
25
|
+
"NORMAL": Weight.NORMAL,
|
|
26
|
+
"BOLD": Weight.BOLD,
|
|
27
|
+
"THIN": Weight.THIN,
|
|
28
|
+
"ULTRALIGHT": Weight.ULTRALIGHT,
|
|
29
|
+
"LIGHT": Weight.LIGHT,
|
|
30
|
+
"BOOK": Weight.BOOK,
|
|
31
|
+
"MEDIUM": Weight.MEDIUM,
|
|
32
|
+
"SEMIBOLD": Weight.SEMIBOLD,
|
|
33
|
+
"ULTRABOLD": Weight.ULTRABOLD,
|
|
34
|
+
"HEAVY": Weight.HEAVY,
|
|
35
|
+
"ULTRAHEAVY": Weight.ULTRAHEAVY,
|
|
36
|
+
}
|
|
37
|
+
try:
|
|
38
|
+
return weights[string]
|
|
39
|
+
except KeyError:
|
|
40
|
+
raise AttributeError("There is no Font Weight Called %s" % string)
|
|
41
|
+
|
|
42
|
+
@staticmethod
|
|
43
|
+
def remove_last_M(file_name: str) -> None:
|
|
44
|
+
"""Remove element from the SVG file in order to allow comparison."""
|
|
45
|
+
with open(file_name, "r") as fpr:
|
|
46
|
+
content = fpr.read()
|
|
47
|
+
content = re.sub(r'Z M [^A-Za-z]*? "\/>', 'Z "/>', content)
|
|
48
|
+
with open(file_name, "w") as fpw:
|
|
49
|
+
fpw.write(content)
|