ManimPango 0.4.3__cp38-cp38-win32.whl → 1.0.0a2__cp38-cp38-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.
Files changed (83) hide show
  1. {ManimPango-0.4.3.dist-info → ManimPango-1.0.0a2.dist-info}/METADATA +2 -2
  2. ManimPango-1.0.0a2.dist-info/RECORD +85 -0
  3. {ManimPango-0.4.3.dist-info → ManimPango-1.0.0a2.dist-info}/WHEEL +1 -1
  4. manimpango/__init__.py +5 -7
  5. manimpango/_distributor_init.py +36 -0
  6. manimpango/_version.py +1 -1
  7. manimpango/attributes/__init__.py +324 -0
  8. manimpango/attributes/attributes.pxi +219 -0
  9. manimpango/buffer.pxi +15 -0
  10. manimpango/cmanimpango.c +10025 -0
  11. manimpango/cmanimpango.cp38-win32.pyd +0 -0
  12. manimpango/enums.c +3721 -0
  13. manimpango/enums.cp38-win32.pyd +0 -0
  14. manimpango/enums.pyx +1 -10
  15. manimpango/exceptions.py +5 -0
  16. manimpango/fonts/__init__.py +153 -0
  17. manimpango/fonts/_font_desc.c +7576 -0
  18. manimpango/fonts/_font_desc.cp38-win32.pyd +0 -0
  19. manimpango/fonts/_font_desc.pxd +5 -0
  20. manimpango/fonts/_font_desc.pyi +25 -0
  21. manimpango/fonts/_font_desc.pyx +114 -0
  22. manimpango/fonts/enums.c +3628 -0
  23. manimpango/fonts/enums.cp38-win32.pyd +0 -0
  24. manimpango/fonts/enums.pyi +23 -0
  25. manimpango/fonts/enums.pyx +84 -0
  26. manimpango/{cairo.pxd → include/cairo.pxd} +21 -0
  27. manimpango/include/glib.pxd +36 -0
  28. manimpango/{pango.pxd → include/pango.pxd} +61 -0
  29. manimpango/include/pango_attributes.pxd +184 -0
  30. manimpango/layout/__init__.py +266 -0
  31. manimpango/layout/_layout.c +8630 -0
  32. manimpango/layout/_layout.cp38-win32.pyd +0 -0
  33. manimpango/layout/_layout.pyx +60 -0
  34. manimpango/layout/layout.pxi +52 -0
  35. manimpango/register_font.c +5016 -0
  36. manimpango/register_font.cp38-win32.pyd +0 -0
  37. manimpango/renderer/__init__.py +5 -0
  38. manimpango/renderer/cairo_utils.pxi +72 -0
  39. manimpango/renderer/image_renderer.c +12319 -0
  40. manimpango/renderer/image_renderer.cp38-win32.pyd +0 -0
  41. manimpango/renderer/image_renderer.pxd +23 -0
  42. manimpango/renderer/image_renderer.pyi +21 -0
  43. manimpango/renderer/image_renderer.pyx +219 -0
  44. manimpango/renderer/svg_renderer.c +10671 -0
  45. manimpango/renderer/svg_renderer.cp38-win32.pyd +0 -0
  46. manimpango/renderer/svg_renderer.pxd +23 -0
  47. manimpango/renderer/svg_renderer.pyi +17 -0
  48. manimpango/renderer/svg_renderer.pyx +174 -0
  49. manimpango/utils/__init__.py +3 -0
  50. manimpango/utils/_utils.cp38-win32.pyd +0 -0
  51. manimpango/utils/_utils.pyi +2 -0
  52. manimpango/utils/utils.c +3533 -0
  53. manimpango/{utils.py → utils/utils.py} +3 -1
  54. manimpango/utils/utils.pyx +27 -0
  55. ManimPango-0.4.3.dist-info/RECORD +0 -44
  56. manimpango/glib.pxd +0 -13
  57. {ManimPango-0.4.3.dist-info → ManimPango-1.0.0a2.dist-info}/LICENSE +0 -0
  58. {ManimPango-0.4.3.dist-info → ManimPango-1.0.0a2.dist-info}/LICENSE.win32 +0 -0
  59. {ManimPango-0.4.3.dist-info → ManimPango-1.0.0a2.dist-info}/top_level.txt +0 -0
  60. /manimpango/{CORE_MANIM_cairo-2.dll → .libs/CORE_MANIM_cairo-2.dll} +0 -0
  61. /manimpango/{CORE_MANIM_cairo-gobject-2.dll → .libs/CORE_MANIM_cairo-gobject-2.dll} +0 -0
  62. /manimpango/{CORE_MANIM_cairo-script-interpreter-2.dll → .libs/CORE_MANIM_cairo-script-interpreter-2.dll} +0 -0
  63. /manimpango/{CORE_MANIM_expat.dll → .libs/CORE_MANIM_expat.dll} +0 -0
  64. /manimpango/{CORE_MANIM_ffi-7.dll → .libs/CORE_MANIM_ffi-7.dll} +0 -0
  65. /manimpango/{CORE_MANIM_fontconfig-1.dll → .libs/CORE_MANIM_fontconfig-1.dll} +0 -0
  66. /manimpango/{CORE_MANIM_freetype-6.dll → .libs/CORE_MANIM_freetype-6.dll} +0 -0
  67. /manimpango/{CORE_MANIM_fribidi-0.dll → .libs/CORE_MANIM_fribidi-0.dll} +0 -0
  68. /manimpango/{CORE_MANIM_gio-2.0-0.dll → .libs/CORE_MANIM_gio-2.0-0.dll} +0 -0
  69. /manimpango/{CORE_MANIM_glib-2.0-0.dll → .libs/CORE_MANIM_glib-2.0-0.dll} +0 -0
  70. /manimpango/{CORE_MANIM_gmodule-2.0-0.dll → .libs/CORE_MANIM_gmodule-2.0-0.dll} +0 -0
  71. /manimpango/{CORE_MANIM_gobject-2.0-0.dll → .libs/CORE_MANIM_gobject-2.0-0.dll} +0 -0
  72. /manimpango/{CORE_MANIM_gthread-2.0-0.dll → .libs/CORE_MANIM_gthread-2.0-0.dll} +0 -0
  73. /manimpango/{CORE_MANIM_harfbuzz-gobject.dll → .libs/CORE_MANIM_harfbuzz-gobject.dll} +0 -0
  74. /manimpango/{CORE_MANIM_harfbuzz-subset.dll → .libs/CORE_MANIM_harfbuzz-subset.dll} +0 -0
  75. /manimpango/{CORE_MANIM_harfbuzz.dll → .libs/CORE_MANIM_harfbuzz.dll} +0 -0
  76. /manimpango/{CORE_MANIM_intl-8.dll → .libs/CORE_MANIM_intl-8.dll} +0 -0
  77. /manimpango/{CORE_MANIM_pango-1.0-0.dll → .libs/CORE_MANIM_pango-1.0-0.dll} +0 -0
  78. /manimpango/{CORE_MANIM_pangocairo-1.0-0.dll → .libs/CORE_MANIM_pangocairo-1.0-0.dll} +0 -0
  79. /manimpango/{CORE_MANIM_pangoft2-1.0-0.dll → .libs/CORE_MANIM_pangoft2-1.0-0.dll} +0 -0
  80. /manimpango/{CORE_MANIM_pangowin32-1.0-0.dll → .libs/CORE_MANIM_pangowin32-1.0-0.dll} +0 -0
  81. /manimpango/{CORE_MANIM_pixman-1-0.dll → .libs/CORE_MANIM_pixman-1-0.dll} +0 -0
  82. /manimpango/{CORE_MANIM_png16-16.dll → .libs/CORE_MANIM_png16-16.dll} +0 -0
  83. /manimpango/{CORE_MANIM_z.dll → .libs/CORE_MANIM_z.dll} +0 -0
@@ -0,0 +1,23 @@
1
+ from cairo cimport *
2
+ from glib cimport *
3
+ from pango cimport *
4
+
5
+ from ..fonts import FontDescription
6
+ from ..layout import Layout
7
+
8
+
9
+ cdef class ImageRenderer:
10
+ cdef cairo_surface_t* cairo_surface
11
+ cdef cairo_t* cairo_context
12
+ cdef PangoLayout* pango_layout
13
+ cdef PangoFontDescription* pango_font_desc
14
+ cdef PangoAttrList* pango_attr_list
15
+
16
+ cdef str _file_name
17
+ cdef int _width
18
+ cdef int _height
19
+ cdef object py_layout
20
+ cdef object py_font_desc
21
+
22
+ cdef bint start_renderering(self)
23
+ cpdef bint render(self)
@@ -0,0 +1,21 @@
1
+ from ..layout import Layout
2
+
3
+ class ImageRenderer:
4
+ def __init__(
5
+ self,
6
+ width: int,
7
+ height: int,
8
+ layout: Layout,
9
+ file_name: str,
10
+ ): ...
11
+ @property
12
+ def file_name(self) -> str: ...
13
+ @property
14
+ def width(self) -> int: ...
15
+ @property
16
+ def height(self) -> int: ...
17
+ @property
18
+ def stride(self) -> int: ...
19
+ def render(self) -> None: ...
20
+ def save(self, file_name: str = None) -> str: ...
21
+ def get_buffer(self) -> object: ...
@@ -0,0 +1,219 @@
1
+ import typing as T
2
+
3
+ from ..layout import Layout
4
+
5
+ include "cairo_utils.pxi"
6
+ include "../buffer.pxi"
7
+
8
+ cdef class ImageRenderer:
9
+ """:class:`ImageRenderer` is a renderer which renders the
10
+ :class:`~.Layout` to an image buffer. You can directly use
11
+ the buffer or else you can save it to a file, as a png file,
12
+ using the :meth:`save` method.
13
+
14
+ The :attr:`file_name` is optional, if you don't provide it
15
+ then you can use the :meth:`get_buffer` method to get the
16
+ buffer.
17
+
18
+ Parameters
19
+ ==========
20
+ width: :class:`float`
21
+ The width of the PNG.
22
+ height: :class:`float`
23
+ The height of the PNG.
24
+ layout: :class:`Layout`
25
+ The :class:`~.Layout` that needs to be rendered.
26
+ file_name: :class:`str`
27
+ The path to render the PNG file to.
28
+
29
+ Example
30
+ =======
31
+ >>> import manimpango as mp
32
+ >>> a = mp.ImageRenderer(100, 100, mp.Layout('hello'), 'test.png')
33
+ >>> a
34
+ <ImageRenderer file_name='test.png' width=100.0 height=100.0 layout=<Layout text='hello' markup=None>
35
+ >>> a.render()
36
+ True
37
+ >>> a.save()
38
+ 'test.png'
39
+
40
+ Raises
41
+ ======
42
+ Exception
43
+ Any error reported by cairo.
44
+ """
45
+ def __cinit__(
46
+ self,
47
+ width: int,
48
+ height: int,
49
+ layout: Layout,
50
+ file_name: T.Optional[str] = None
51
+ ):
52
+ surface = cairo_image_surface_create(
53
+ CAIRO_FORMAT_ARGB32,
54
+ width,
55
+ height
56
+ )
57
+ if surface == NULL:
58
+ raise MemoryError("Cairo.ImageSurface can't be created.")
59
+ self.cairo_surface = surface
60
+ self.cairo_context = create_cairo_context_from_surface(surface)
61
+ self.pango_layout = create_pango_layout(self.cairo_context)
62
+ self.pango_font_desc = create_font_desc()
63
+ self.pango_attr_list = create_attr_list()
64
+
65
+ def __init__(
66
+ self,
67
+ width: int,
68
+ height: int,
69
+ layout: Layout,
70
+ file_name: T.Optional[str] = None
71
+ ):
72
+ self._file_name = file_name
73
+ self._width = width
74
+ self._height = height
75
+ self.py_layout = layout
76
+ self.py_font_desc = layout.font_desc
77
+
78
+ cdef bint start_renderering(self):
79
+ pylayout_to_pango_layout(
80
+ self.pango_layout,
81
+ self.py_layout,
82
+ self.pango_attr_list
83
+ )
84
+ pyfontdesc_to_pango_font_desc(self.pango_font_desc, self.py_font_desc)
85
+ pango_layout_set_font_description(
86
+ self.pango_layout,
87
+ self.pango_font_desc
88
+ )
89
+ # Check if the context is fine
90
+ _err = is_context_fine(self.cairo_context)
91
+ if _err != "":
92
+ raise Exception(_err)
93
+
94
+ # Assign the font description to the layout
95
+ pango_layout_set_font_description(self.pango_layout,
96
+ self.pango_font_desc)
97
+
98
+ # Render the actual layout into the cairo context
99
+ pango_cairo_show_layout(self.cairo_context,
100
+ self.pango_layout)
101
+
102
+ # Check if the context is fine again
103
+ _err = is_context_fine(self.cairo_context)
104
+ if _err != "":
105
+ raise Exception(_err)
106
+
107
+ return 1
108
+
109
+ cpdef bint render(self):
110
+ """:meth:`render` actually does the rendering.
111
+ Any error reported by Cairo is reported as an exception.
112
+ If this method suceeds you can expect an valid image in the
113
+ buffer.
114
+
115
+ Returns
116
+ =======
117
+ bool
118
+ ``True`` if the function worked, else ``False``.
119
+ """
120
+ return self.start_renderering()
121
+
122
+ def save(self, file_name: T.Optional[str] = None) -> str:
123
+ """This method is to save the image to an PNG image.
124
+ Note that only PNG image are supported, if you need other
125
+ formats, use external libraries such as Pillow.
126
+
127
+ Parameters
128
+ ==========
129
+ file_name:
130
+ The file_name to write the image to.
131
+
132
+ Raises
133
+ ======
134
+ ValueError
135
+ Raised when the file_name parameter is ``None``.
136
+
137
+ Returns
138
+ =======
139
+ str
140
+ The filepath to the saved file.
141
+ """
142
+ if file_name is None:
143
+ file_name = self.file_name
144
+
145
+ if not file_name:
146
+ raise ValueError("Need a filename to save.")
147
+
148
+ cdef cairo_status_t _status = cairo_surface_write_to_png(self.cairo_surface,
149
+ file_name.encode('utf-8'))
150
+
151
+ if _status == CAIRO_STATUS_NO_MEMORY:
152
+ raise MemoryError("Cairo didn't find memory")
153
+ elif _status != CAIRO_STATUS_SUCCESS:
154
+ temp_bytes = <bytes>cairo_status_to_string(_status)
155
+ raise Exception(temp_bytes.decode('utf-8'))
156
+
157
+ return self.file_name
158
+
159
+ def __repr__(self) -> str:
160
+ return (f"<ImageRenderer file_name={repr(self.file_name)}"
161
+ f" width={repr(self.width)}"
162
+ f" height={repr(self.height)}"
163
+ f" layout={repr(self.layout)}")
164
+
165
+ def __dealloc__(self):
166
+ if self.pango_attr_list:
167
+ pango_attr_list_unref(self.pango_attr_list)
168
+ if self.pango_layout:
169
+ g_object_unref(self.pango_layout)
170
+ if self.cairo_context:
171
+ cairo_destroy(self.cairo_context)
172
+ if self.cairo_surface:
173
+ cairo_surface_destroy(self.cairo_surface)
174
+ if self.pango_font_desc:
175
+ pango_font_description_free(self.pango_font_desc)
176
+
177
+ @property
178
+ def file_name(self) -> str:
179
+ """The file_name where the file is rendered onto"""
180
+ return self._file_name
181
+
182
+ @property
183
+ def width(self) -> int:
184
+ """The width of the PNG."""
185
+ return self._width
186
+
187
+ @property
188
+ def height(self) -> int:
189
+ """The height of the PNG."""
190
+ return self._height
191
+
192
+ @property
193
+ def stride(self) -> int:
194
+ """The stride of the PNG."""
195
+ return cairo_image_surface_get_stride(self.cairo_surface)
196
+
197
+ @property
198
+ def layout(self) -> Layout:
199
+ """The :class:`~.Layout` which is being rendered.
200
+ """
201
+ return self.py_layout
202
+
203
+ def get_buffer(self) -> object:
204
+ """This method returns the buffer of the image.
205
+ This contains the image in the format of ``ARGB32``.
206
+
207
+ Returns
208
+ =======
209
+ bytes
210
+ The buffer of the image.
211
+ """
212
+ b = ImageBuffer()
213
+ b.data = cairo_image_surface_get_data(self.cairo_surface)
214
+ if b.data == NULL:
215
+ return None
216
+
217
+ b.height = cairo_image_surface_get_height(self.cairo_surface)
218
+ b.stride = cairo_image_surface_get_stride(self.cairo_surface)
219
+ return b