ManimPango 0.5.0__cp312-cp312-macosx_10_9_x86_64.whl → 0.6.0__cp312-cp312-macosx_10_9_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.
Files changed (37) hide show
  1. {ManimPango-0.5.0.dist-info → ManimPango-0.6.0.dist-info}/METADATA +5 -12
  2. ManimPango-0.6.0.dist-info/RECORD +21 -0
  3. {ManimPango-0.5.0.dist-info → ManimPango-0.6.0.dist-info}/WHEEL +1 -1
  4. manimpango/__init__.py +1 -1
  5. manimpango/_register_font.cpython-312-darwin.so +0 -0
  6. manimpango/{register_font.pxd → _register_font.pxd} +8 -1
  7. manimpango/_register_font.pyx +160 -0
  8. manimpango/_version.py +1 -1
  9. manimpango/cmanimpango.cpython-312-darwin.so +0 -0
  10. manimpango/cmanimpango.pyx +15 -0
  11. manimpango/enums.cpython-312-darwin.so +0 -0
  12. manimpango/pango.pxd +33 -0
  13. manimpango/register_font.py +156 -0
  14. ManimPango-0.5.0.dist-info/RECORD +0 -38
  15. manimpango/.dylibs/libcairo.2.dylib +0 -0
  16. manimpango/.dylibs/libffi.7.dylib +0 -0
  17. manimpango/.dylibs/libfontconfig.1.dylib +0 -0
  18. manimpango/.dylibs/libfreetype.6.dylib +0 -0
  19. manimpango/.dylibs/libfribidi.0.dylib +0 -0
  20. manimpango/.dylibs/libgio-2.0.0.dylib +0 -0
  21. manimpango/.dylibs/libglib-2.0.0.dylib +0 -0
  22. manimpango/.dylibs/libgmodule-2.0.0.dylib +0 -0
  23. manimpango/.dylibs/libgobject-2.0.0.dylib +0 -0
  24. manimpango/.dylibs/libharfbuzz.0.dylib +0 -0
  25. manimpango/.dylibs/libintl.8.dylib +0 -0
  26. manimpango/.dylibs/libpango-1.0.0.dylib +0 -0
  27. manimpango/.dylibs/libpangocairo-1.0.0.dylib +0 -0
  28. manimpango/.dylibs/libpangoft2-1.0.0.dylib +0 -0
  29. manimpango/.dylibs/libpcre2-8.0.dylib +0 -0
  30. manimpango/.dylibs/libpixman-1.0.dylib +0 -0
  31. manimpango/.dylibs/libpng16.16.dylib +0 -0
  32. manimpango/.dylibs/libz.dylib +0 -0
  33. manimpango/register_font.cpython-312-darwin.so +0 -0
  34. manimpango/register_font.pyx +0 -241
  35. {ManimPango-0.5.0.dist-info → ManimPango-0.6.0.dist-info}/LICENSE +0 -0
  36. {ManimPango-0.5.0.dist-info → ManimPango-0.6.0.dist-info}/LICENSE.bin +0 -0
  37. {ManimPango-0.5.0.dist-info → ManimPango-0.6.0.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ManimPango
3
- Version: 0.5.0
3
+ Version: 0.6.0
4
4
  Summary: Bindings for Pango for using with Manim.
5
5
  Home-page: https://manimpango.manim.community/
6
6
  Author: Naveen M K
@@ -20,10 +20,10 @@ Classifier: Programming Language :: Python :: 3.9
20
20
  Classifier: Programming Language :: Python :: 3.10
21
21
  Classifier: Programming Language :: Python :: 3.11
22
22
  Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
23
24
  Classifier: Development Status :: 4 - Beta
24
25
  Classifier: Programming Language :: Python :: 3 :: Only
25
26
  Classifier: License :: OSI Approved :: MIT License
26
- Classifier: Operating System :: OS Independent
27
27
  Classifier: Programming Language :: Cython
28
28
  Requires-Python: >=3.8
29
29
  Description-Content-Type: text/markdown
@@ -76,7 +76,7 @@ For building **ManimPango**, you need
76
76
  * [`pkg-config`](https://www.freedesktop.org/wiki/Software/pkg-config/)
77
77
  * [Pango](https://pango.gnome.org) along with its development headers and its dependencies.
78
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, but their version of **Pango** is old and will probably not be updated in the near future.
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
80
 
81
81
  ```sh
82
82
  brew install pango pkg-config
@@ -177,9 +177,9 @@ pacman -S mingw-w64-x86_64-ffmpeg
177
177
 
178
178
  #### Visual Studio
179
179
 
180
- First, install Visual Studio as specified in https://wiki.python.org/moin/WindowsCompilers. Possibly Visual Studio Build Tools 2019 with Windows10 SDK.
180
+ First, install Visual Studio as specified in https://wiki.python.org/moin/WindowsCompilers. Possibly Visual Studio Build Tools 2022 with Windows10 SDK.
181
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` and `C:\cibw\vendor\pkg-config\bin` to PATH.
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
183
 
184
184
  **Note:** You can change the install location by editing line 24 of the file `packing/download_dlls.py`.
185
185
 
@@ -197,13 +197,6 @@ Finally, you can install your local **ManimPango** clone just like any other pyt
197
197
  pip install .
198
198
  ```
199
199
 
200
- **Important**: You have to to use https://docs.python.org/3/library/os.html#os.add_dll_directory before running **ManimPango**. Alternatively, you need to copy the `dll` at `C:\cibw\vendor\bin` to the folder where **ManimPango** is compiled. This is applicable for Python 3.8 and above.
201
-
202
- ```python
203
- import os
204
- os.add_dll_directory('C:\cibw\vendor\bin')
205
- ```
206
-
207
200
  ## Code of Conduct
208
201
 
209
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).
@@ -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=Gslco0u-UdyhQslriEMCnIh5wENI6Dd1FlwyhvZM_HQ,110
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/_register_font.cpython-312-darwin.so,sha256=6pAl62Kio78YnGdLakYSs0iEc-VxMCkkE0A1zChAtPY,7001480
8
+ manimpango/cmanimpango.pxd,sha256=qmQydFpNgEPYcDtfDhcaiAhu6-WyvQA0Tth09fO0sl4,62
9
+ manimpango/_version.py,sha256=tBvPR0sOsOC0mL_wGk5l2NiZwbLwYUDP1D3S3jG7zOA,46
10
+ manimpango/_register_font.pxd,sha256=0xKRYafsvYhOT2LdNuh9XfvfNQRYs4XDTCgYJTLFZ8E,2028
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/utils.py,sha256=khEmMGksIdblHNbM-Rlv4r3Cj2QmP0Jf3Eb6xP1imnc,1621
16
+ manimpango/enums.cpython-312-darwin.so,sha256=ijfHcGnkGXdGB3yKQSqE_xs93RUYgw9hBa2WOM9vsxE,3976248
17
+ manimpango/pango.pxd,sha256=yKu5nJUj_WP--KXshX_5i868Bc8NmdbYWoAWjaEPNBg,5344
18
+ manimpango/_register_font.pyx,sha256=gQGvAVMMwdEqEsz148lLzODsX-E5VRPzjObwpmpYqTM,5135
19
+ manimpango/cmanimpango.cpython-312-darwin.so,sha256=Dgb8sqhJ_nWJw0-_5ynrSmg30ejdptnOzcxRLbGXJcs,7223352
20
+ manimpango/cmanimpango.pyx,sha256=7X4q6SZGg7WpDGR23THbqqNQaPoYBxejQuG7M6fMxgk,11046
21
+ manimpango/glib.pxd,sha256=-Ua7DTGh1FCHZc7fnOUGuCsYfl5WlW7LFpGXAq6VUNM,374
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.41.2)
2
+ Generator: setuptools (74.1.2)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp312-cp312-macosx_10_9_x86_64
5
5
 
manimpango/__init__.py CHANGED
@@ -11,9 +11,9 @@ if os.name == "nt": # pragma: no cover
11
11
  f"{os.environ['PATH']}"
12
12
  )
13
13
  try:
14
+ from .register_font import * # isort:skip # noqa: F403,F401
14
15
  from .cmanimpango import * # noqa: F403,F401
15
16
  from .enums import * # noqa: F403,F401
16
- from .register_font import * # noqa: F403,F401
17
17
  except ImportError as ie: # pragma: no cover
18
18
  py_ver = ".".join(map(str, sys.version_info[:3]))
19
19
  msg = f"""
@@ -1,5 +1,5 @@
1
-
2
1
  from libc.stddef cimport wchar_t
2
+ from pango cimport *
3
3
 
4
4
 
5
5
  cdef extern from "Python.h":
@@ -35,6 +35,13 @@ IF UNAME_SYSNAME == "Windows":
35
35
  DWORD fl,
36
36
  unsigned int pdv
37
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
+
38
45
  ELIF UNAME_SYSNAME == "Darwin":
39
46
  cdef extern from "Carbon/Carbon.h":
40
47
  ctypedef struct CFURLRef:
@@ -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 CHANGED
@@ -1,2 +1,2 @@
1
1
  # -*- coding: utf-8 -*-
2
- __version__ = "0.5.0"
2
+ __version__ = "0.6.0"
@@ -2,9 +2,11 @@ import typing
2
2
  import warnings
3
3
  from xml.sax.saxutils import escape
4
4
 
5
+ from . import registered_fonts
5
6
  from .enums import Alignment
6
7
  from .utils import *
7
8
 
9
+ include "utils.pxi"
8
10
 
9
11
  class TextSetting:
10
12
  """Formatting for slices of a :class:`manim.mobject.svg.text_mobject.Text` object."""
@@ -48,6 +50,7 @@ def text2svg(
48
50
  cdef double font_size_c = size
49
51
  cdef cairo_status_t status
50
52
  cdef int temp_width
53
+ cdef PangoFontMap* fontmap
51
54
 
52
55
  file_name_bytes = file_name.encode("utf-8")
53
56
  surface = cairo_svg_surface_create(file_name_bytes,width,height)
@@ -72,6 +75,11 @@ def text2svg(
72
75
  last_line_num = 0
73
76
 
74
77
  layout = pango_cairo_create_layout(cr)
78
+ fontmap = pango_context_get_font_map (pango_layout_get_context (layout));
79
+
80
+ for font_item in registered_fonts:
81
+ if font_item.type == 'win32':
82
+ add_to_fontmap(fontmap, font_item.path)
75
83
 
76
84
  if layout == NULL:
77
85
  cairo_destroy(cr)
@@ -206,6 +214,7 @@ class MarkupUtils:
206
214
  cdef cairo_status_t status
207
215
  cdef double font_size = size
208
216
  cdef int temp_int # a temporary C integer for conversion
217
+ cdef PangoFontMap* fontmap
209
218
 
210
219
  file_name_bytes = file_name.encode("utf-8")
211
220
 
@@ -235,6 +244,12 @@ class MarkupUtils:
235
244
  cairo_surface_destroy(surface)
236
245
  raise MemoryError("Pango.Layout can't be created from Cairo Context.")
237
246
 
247
+ fontmap = pango_context_get_font_map (pango_layout_get_context (layout));
248
+
249
+ for font_item in registered_fonts:
250
+ if font_item.type == 'win32':
251
+ add_to_fontmap(fontmap, font_item.path)
252
+
238
253
  if pango_width is None:
239
254
  pango_layout_set_width(layout, pango_units_from_double(width))
240
255
  else:
Binary file
manimpango/pango.pxd CHANGED
@@ -139,9 +139,20 @@ cdef extern from "pango/pangocairo.h":
139
139
  PangoLayout *layout,
140
140
  PangoAlignment alignment
141
141
  )
142
+ PangoFontMap* pango_context_get_font_map(
143
+ PangoContext* context
144
+ )
145
+ PangoContext* pango_layout_get_context(
146
+ PangoLayout* layout
147
+ )
148
+
149
+
142
150
 
143
151
  cdef extern from *:
144
152
  """
153
+ #if _WIN32
154
+ #include <pango/pangowin32.h>
155
+ #endif
145
156
  #if PANGO_VERSION_CHECK(1,44,0)
146
157
  int set_line_width(PangoLayout *layout,float spacing)
147
158
  {
@@ -151,6 +162,23 @@ cdef extern from *:
151
162
  #else
152
163
  int set_line_width(PangoLayout *layout,float spacing){return 0;}
153
164
  #endif
165
+
166
+ #if _WIN32 && PANGO_VERSION_CHECK(1,52,0)
167
+ gboolean font_map_add_font_file(PangoFontMap *font_map,
168
+ const char *font_file_path,
169
+ GError **error)
170
+ {
171
+ return pango_win32_font_map_add_font_file(font_map, font_file_path, error);
172
+ }
173
+ #else
174
+ gboolean font_map_add_font_file(PangoFontMap *font_map,
175
+ const char *font_file_path,
176
+ GError **error)
177
+ {
178
+ return 1;
179
+ }
180
+ #endif
181
+
154
182
  """
155
183
  # The above docs string is C which is used to
156
184
  # check for the Pango Version there at run time.
@@ -158,3 +186,8 @@ cdef extern from *:
158
186
  # pango>=1.44.0 but we support pango>=1.30.0 that why this
159
187
  # conditionals.
160
188
  bint set_line_width(PangoLayout *layout,float spacing)
189
+
190
+ # only for windows and 1.52.0+
191
+ gboolean font_map_add_font_file(PangoFontMap *font_map,
192
+ const char *font_file_path,
193
+ GError **error)
@@ -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
+ )
@@ -1,38 +0,0 @@
1
- ManimPango-0.5.0.dist-info/RECORD,,
2
- ManimPango-0.5.0.dist-info/LICENSE,sha256=PkzdSXTMd8X-B3IFjUlsGc9eDGAM9x7DAt8iBgLj7sg,1067
3
- ManimPango-0.5.0.dist-info/WHEEL,sha256=keHNpQgVCtZmnassXI38bYehVkiZ8Lrud_k-zLyqsEg,111
4
- ManimPango-0.5.0.dist-info/top_level.txt,sha256=_7RXNU2cbck8IbstWHzYv6YV58wtKUDBX-pmUjE6SKs,11
5
- ManimPango-0.5.0.dist-info/LICENSE.bin,sha256=qM2kte-MyVxokaHNRdgyYS0aH1yP2uLXfOwzqkLPtlA,160378
6
- ManimPango-0.5.0.dist-info/METADATA,sha256=wX-RWoF5xwQ_9LjmSUOtB5Dpwt6rJ1wnWBMO4lrcGmw,8436
7
- manimpango/cmanimpango.pxd,sha256=qmQydFpNgEPYcDtfDhcaiAhu6-WyvQA0Tth09fO0sl4,62
8
- manimpango/_version.py,sha256=P_qFbmVpJJdLNM4Gz7C55-YeTd7OBAohQks3uq0HGtE,46
9
- manimpango/__init__.py,sha256=RFEgAmrwsyNo-ARQL9YCj22mZXUwp8_JIwQqf27dh9o,1084
10
- manimpango/cairo.pxd,sha256=qI50gJGUuAJy9A6hRZbMMwMWqfCmG5H6Tz-EWkqmvTo,771
11
- manimpango/enums.pyx,sha256=ltZjDhviuWzi8pRDDkbRp3rYiZIassSpezOEOx0x3xw,2461
12
- manimpango/register_font.pxd,sha256=kgz5X5wUc-WxjEHogdtdi7Y5e8IZAETUqLU-bD3M25Y,1726
13
- manimpango/register_font.pyx,sha256=QXmGcqflkaSyrvIwlv8ksx0XgkENwwwi6C7J3kQyV-E,7453
14
- manimpango/utils.py,sha256=khEmMGksIdblHNbM-Rlv4r3Cj2QmP0Jf3Eb6xP1imnc,1621
15
- manimpango/enums.cpython-312-darwin.so,sha256=AaGJ4gY3pXtHWjUVPJrx6gNMSeiLRWBEADFar3tV4Uc,79392
16
- manimpango/pango.pxd,sha256=6rPGDbHiXr-MLCN4ZukyDvKfclTz4G-IH-VT4qcTeMc,4308
17
- manimpango/register_font.cpython-312-darwin.so,sha256=zYNnWXR-9D7y6GoRlcu59T5S-1efmLLYYsejfJFs3UQ,106768
18
- manimpango/cmanimpango.cpython-312-darwin.so,sha256=AMoJhdNKpffkTS_sZEGPxL0u6PZeS0pudVJ80eBNOmM,149568
19
- manimpango/cmanimpango.pyx,sha256=h1pT40dD1JGXmhqVTKeDiegLYa3GjUHIHWUMvwzR_LA,10496
20
- manimpango/glib.pxd,sha256=-Ua7DTGh1FCHZc7fnOUGuCsYfl5WlW7LFpGXAq6VUNM,374
21
- manimpango/.dylibs/libpango-1.0.0.dylib,sha256=mg4Jtk8fMkuXqoxR3yJulksD5w_OPOMCnuEGA10hmpY,445424
22
- manimpango/.dylibs/libz.dylib,sha256=iUO8HvyLQqyUiAHKn3ZKzTNyPzzwwGqqzvb8sMfBVgo,141632
23
- manimpango/.dylibs/libpangoft2-1.0.0.dylib,sha256=wn-0D3EjBETeLHzG9tVngY0p4HOAcl7Vt1Y7TM621Ps,139696
24
- manimpango/.dylibs/libpcre2-8.0.dylib,sha256=aVJ32fhooK9vUMgwDd5_tFmOTl6SA9hk9O5Kf-BZkZw,627968
25
- manimpango/.dylibs/libcairo.2.dylib,sha256=9mz9aD3qVNZ6Fx7VGm3lbZH8Lb4XIHa362BONFS5AOQ,1195344
26
- manimpango/.dylibs/libglib-2.0.0.dylib,sha256=IEvZ9c2APkN6mzpoWfunsjiWGSjTie10j8sa3hO3O6E,1280512
27
- manimpango/.dylibs/libpng16.16.dylib,sha256=KyDJtRwFpWzdcTb57lb2MP34MeWrVe_CejuJmTd9lCc,279056
28
- manimpango/.dylibs/libpangocairo-1.0.0.dylib,sha256=rU1rlrM2FkygtFfaRzafXTkl4G9_ARQJkA9OBUvqU2g,139280
29
- manimpango/.dylibs/libgobject-2.0.0.dylib,sha256=w1ch1K3ffQIcctsoGMR-veZhrQEz3bRbWUoYtLi094s,371392
30
- manimpango/.dylibs/libfreetype.6.dylib,sha256=9fbuul18tC9YC6PJs-4vv7TtR010V1TsZzebqWegOHQ,808288
31
- manimpango/.dylibs/libharfbuzz.0.dylib,sha256=LfwgW4F1pZIyBF_2G_znsjsDISzuxMXE-oaP6JCP6iM,1230640
32
- manimpango/.dylibs/libgmodule-2.0.0.dylib,sha256=BGV-7-gGsYkAlsiFWNfOLdBdj0rSPmW99q3zAQXzCak,54896
33
- manimpango/.dylibs/libintl.8.dylib,sha256=YAeq6Y4sz2UAaiRaEO4ep_egDfWhP3OaFel4Gt_vQYA,52544
34
- manimpango/.dylibs/libfribidi.0.dylib,sha256=9vf45ij87Mz4m8elO1CVvSi9TR5dwgesp7a7EL-fHeU,155824
35
- manimpango/.dylibs/libfontconfig.1.dylib,sha256=o4KsB_j6lp2Ew5wWG8DCgOb4W_T9eNaxlT9GulY1L6M,339136
36
- manimpango/.dylibs/libffi.7.dylib,sha256=bWEx32zS9IZl-OwHLsh93-NcdBpA8rbLWnGHfcTsem8,73632
37
- manimpango/.dylibs/libpixman-1.0.dylib,sha256=xGja7LbgmLxqyF-fP9Ul1OY4_B1Bd9HSVE6iWcZucRM,816880
38
- manimpango/.dylibs/libgio-2.0.0.dylib,sha256=UWYbPYIrYECmEQLAJVxuax-tle1O4S4De77T8U5yJHw,1919136
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,241 +0,0 @@
1
- from pathlib import Path
2
-
3
- from pango cimport *
4
-
5
- import os
6
-
7
-
8
- cpdef bint fc_register_font(str font_path):
9
- """This function registers the font file using ``fontconfig`` so that
10
- it is available for use by Pango. On Linux it is aliased to
11
- :func:`register_font` and on Windows and macOS this would work only when
12
- using ``fontconfig`` backend.
13
-
14
- Parameters
15
- ==========
16
- font_path : :class:`str`
17
- Relative or absolute path to font file.
18
- Returns
19
- =======
20
- :class:`bool`
21
- True means it worked without any error.
22
- False means there was an unknown error
23
- Examples
24
- --------
25
- >>> register_font("/home/roboto.tff")
26
- True
27
-
28
- Raises
29
- ------
30
- AssertionError
31
- Font is missing.
32
- """
33
- a = Path(font_path)
34
- assert a.exists(), f"font doesn't exist at {a.absolute()}"
35
- font_path = os.fspath(a.absolute())
36
- font_path_bytes=font_path.encode('utf-8')
37
- cdef const unsigned char* fontPath = font_path_bytes
38
- fontAddStatus = FcConfigAppFontAddFile(FcConfigGetCurrent(), fontPath)
39
- if fontAddStatus:
40
- return True
41
- else:
42
- return False
43
-
44
-
45
- cpdef bint fc_unregister_font(str font_path):
46
- """This function unregisters(removes) the font file using
47
- ``fontconfig``. It is mostly optional to call this.
48
- Mainly used in tests. On Linux it is aliased to
49
- :func:`unregister_font` and on Windows and macOS this
50
- would work only when using ``fontconfig`` backend.
51
-
52
- Parameters
53
- ==========
54
-
55
- font_path: :class:`str`
56
- For compatibility with the windows function.
57
-
58
- Returns
59
- =======
60
- :class:`bool`
61
- True means it worked without any error.
62
- False means there was an unknown error
63
-
64
- """
65
- FcConfigAppFontClear(NULL)
66
- return True
67
-
68
-
69
- IF UNAME_SYSNAME == "Linux":
70
- register_font = fc_register_font
71
- unregister_font = fc_unregister_font
72
-
73
-
74
- ELIF UNAME_SYSNAME == "Windows":
75
- cpdef bint register_font(str font_path):
76
- """This function registers the font file using native windows API
77
- so that it is available for use by Pango.
78
-
79
- Parameters
80
- ==========
81
- font_path : :class:`str`
82
- Relative or absolute path to font file.
83
- Returns
84
- =======
85
- :class:`bool`
86
- True means it worked without any error.
87
- False means there was an unknown error
88
- Examples
89
- --------
90
- >>> register_font("C:/home/roboto.tff")
91
- True
92
- Raises
93
- ------
94
- AssertionError
95
- Font is missing.
96
- """
97
- a=Path(font_path)
98
- assert a.exists(), f"font doesn't exist at {a.absolute()}"
99
- font_path = os.fspath(a.absolute())
100
- cdef LPCWSTR wchar_path = PyUnicode_AsWideCharString(font_path, NULL)
101
- fontAddStatus = AddFontResourceExW(
102
- wchar_path,
103
- FR_PRIVATE,
104
- 0
105
- )
106
- if fontAddStatus > 0:
107
- return True
108
- else:
109
- return False
110
-
111
-
112
- cpdef bint unregister_font(str font_path):
113
- """This function unregisters(removes) the font file using
114
- native Windows API. It is mostly optional to call this.
115
- Mainly used in tests.
116
- Parameters
117
- ==========
118
- font_path : :class:`str`
119
- Relative or absolute path to font file.
120
- Returns
121
- =======
122
- :class:`bool`
123
- True means it worked without any error.
124
- False means there was an unknown error
125
- Raises
126
- ------
127
- AssertionError
128
- Font is missing.
129
- """
130
- a=Path(font_path)
131
- assert a.exists(), f"font doesn't exist at {a.absolute()}"
132
- font_path = os.fspath(a.absolute())
133
- cdef LPCWSTR wchar_path = PyUnicode_AsWideCharString(font_path, NULL)
134
- return RemoveFontResourceExW(
135
- wchar_path,
136
- FR_PRIVATE,
137
- 0
138
- )
139
-
140
-
141
- ELIF UNAME_SYSNAME == "Darwin":
142
- cpdef bint register_font(str font_path):
143
- """This function registers the font file using ``CoreText`` API so that
144
- it is available for use by Pango.
145
- Parameters
146
- ==========
147
- font_path : :class:`str`
148
- Relative or absolute path to font file.
149
- Returns
150
- =======
151
- :class:`bool`
152
- True means it worked without any error.
153
- False means there was an unknown error
154
- Examples
155
- --------
156
- >>> register_font("/home/roboto.tff")
157
- True
158
- Raises
159
- ------
160
- AssertionError
161
- Font is missing.
162
- """
163
- a = Path(font_path)
164
- assert a.exists(), f"font doesn't exist at {a.absolute()}"
165
- font_path_bytes_py = str(a.absolute().as_uri()).encode('utf-8')
166
- cdef unsigned char* font_path_bytes = <bytes>font_path_bytes_py
167
- b = len(a.absolute().as_uri())
168
- cdef CFURLRef cf_url = CFURLCreateWithBytes(NULL, font_path_bytes, b, 0x08000100, NULL)
169
- return CTFontManagerRegisterFontsForURL(
170
- cf_url,
171
- kCTFontManagerScopeProcess,
172
- NULL
173
- )
174
-
175
-
176
- cpdef bint unregister_font(str font_path):
177
- """This function unregisters(removes) the font file using
178
- native ``CoreText`` API. It is mostly optional to call this.
179
- Mainly used in tests.
180
- Parameters
181
- ==========
182
- font_path : :class:`str`
183
- Relative or absolute path to font file.
184
- Returns
185
- =======
186
- :class:`bool`
187
- True means it worked without any error.
188
- False means there was an unknown error
189
- Raises
190
- ------
191
- AssertionError
192
- Font is missing.
193
- """
194
- a = Path(font_path)
195
- assert a.exists(), f"font doesn't exist at {a.absolute()}"
196
- font_path_bytes_py = str(a.absolute().as_uri()).encode('utf-8')
197
- cdef unsigned char* font_path_bytes = <bytes>font_path_bytes_py
198
- b = len(a.absolute().as_uri())
199
- cdef CFURLRef cf_url = CFURLCreateWithBytes(NULL, font_path_bytes, b, 0x08000100, NULL)
200
- return CTFontManagerUnregisterFontsForURL(
201
- cf_url,
202
- kCTFontManagerScopeProcess,
203
- NULL
204
- )
205
-
206
-
207
- cpdef list list_fonts():
208
- """Lists the fonts available to Pango.
209
- This is usually same as system fonts but it also
210
- includes the fonts added through :func:`register_font`.
211
-
212
- Returns
213
- -------
214
-
215
- :class:`list` :
216
- List of fonts sorted alphabetically.
217
- """
218
- cdef PangoFontMap* fontmap = pango_cairo_font_map_new()
219
- if fontmap == NULL:
220
- raise MemoryError("Pango.FontMap can't be created.")
221
- cdef int n_families=0
222
- cdef PangoFontFamily** families=NULL
223
- pango_font_map_list_families(
224
- fontmap,
225
- &families,
226
- &n_families
227
- )
228
- if families is NULL or n_families == 0:
229
- raise MemoryError("Pango returned unexpected length on families.")
230
- family_list = []
231
- for i in range(n_families):
232
- name = pango_font_family_get_name(families[i])
233
- # according to pango's docs, the `char *` returned from
234
- # `pango_font_family_get_name`is owned by pango, and python
235
- # shouldn't interfere with it. I hope Cython handles it.
236
- # https://cython.readthedocs.io/en/stable/src/tutorial/strings.html#dealing-with-const
237
- family_list.append(name.decode())
238
- g_free(families)
239
- g_object_unref(fontmap)
240
- family_list.sort()
241
- return family_list