ManimPango 0.4.3__cp310-cp310-win32.whl → 1.0.0a2__cp310-cp310-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.cp310-win32.pyd +0 -0
  12. manimpango/enums.c +3721 -0
  13. manimpango/enums.cp310-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.cp310-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.cp310-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.cp310-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.cp310-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.cp310-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.cp310-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.cp310-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,219 @@
1
+ from pango cimport *
2
+ from pango_attributes cimport *
3
+
4
+ from manimpango.attributes import TextAttribute
5
+
6
+
7
+ cdef PangoAttribute* raise_on_null_attr(PangoAttribute* ptr):
8
+ if not ptr:
9
+ raise MemoryError("Could not allocate memory for attribute")
10
+ return ptr
11
+
12
+ cdef set_indexes(PangoAttribute* attr, start_index: int, end_index: int):
13
+ """Sets the start and end indexes of a PangoAttribute.
14
+
15
+ Parameters
16
+ ----------
17
+ attr
18
+ The PangoAttribute to set the indexes for.
19
+ start_index
20
+ The start index.
21
+ end_index
22
+ The end index.
23
+ """
24
+ if start_index is not None:
25
+ attr.start_index = start_index
26
+ if end_index != -1:
27
+ attr.end_index = end_index
28
+
29
+ cdef insert_into_queue(
30
+ GQueue* queue,
31
+ PangoAttribute* attr,
32
+ start_index: int,
33
+ end_index: int,
34
+ ):
35
+ """Inserts a PangoAttribute into a PangoAttrList.
36
+
37
+ Parameters
38
+ ----------
39
+ queue
40
+ The GQueue to insert the attribute into.
41
+ attr
42
+ The PangoAttribute to insert.
43
+ """
44
+ set_indexes(attr, start_index, end_index)
45
+ g_queue_push_tail(queue, attr)
46
+
47
+ cdef GQueue* create_attr_list_for_attribute (
48
+ attr: TextAttribute,
49
+ ):
50
+ """Creates a GQueue from a TextAttribute. The Queue will contain a list
51
+ of PangoAttributes.
52
+
53
+ Multiple PangoAttributes are to be created for a single TextAttribute. That's
54
+ because for a given `start` and `end` index value, the user can set various
55
+ attributes like `color`, `font`, `size`, etc. So, we need to create a
56
+ PangoAttribute for each of these attributes. Finally, we add all these
57
+ PangoAttributes to a Queue and return it.
58
+
59
+ Note: the caller is responsible for freeing the returned GQueue as well as
60
+ the created attributes.
61
+
62
+ Parameters
63
+ ----------
64
+ attr
65
+ The TextAttribute to convert.
66
+ """
67
+ cdef PangoAttribute* pango_attr = NULL
68
+ cdef GQueue* queue = g_queue_new()
69
+ if not queue:
70
+ raise MemoryError("Could not allocate memory for GQueue.")
71
+
72
+ # allow_breaks
73
+ if attr.allow_breaks is not None:
74
+ pango_attr = raise_on_null_attr(
75
+ pango_attr_allow_breaks_new(attr.allow_breaks))
76
+ insert_into_queue(
77
+ queue,
78
+ pango_attr,
79
+ attr.start_index,
80
+ attr.end_index,
81
+ )
82
+
83
+ # background_alpha
84
+ if attr.background_alpha is not None:
85
+ pango_attr = raise_on_null_attr(
86
+ pango_attr_background_alpha_new(attr.background_alpha))
87
+ insert_into_queue(
88
+ queue,
89
+ pango_attr,
90
+ attr.start_index,
91
+ attr.end_index,
92
+ )
93
+
94
+ # background_color
95
+ if attr.background_color is not None:
96
+ pango_attr = raise_on_null_attr(
97
+ pango_attr_background_new(
98
+ attr.background_color[0],
99
+ attr.background_color[1],
100
+ attr.background_color[2],
101
+ ),
102
+ )
103
+ insert_into_queue(
104
+ queue,
105
+ pango_attr,
106
+ attr.start_index,
107
+ attr.end_index,
108
+ )
109
+
110
+ # foreground_alpha
111
+ if attr.foreground_alpha is not None:
112
+ pango_attr = raise_on_null_attr(
113
+ pango_attr_foreground_alpha_new(attr.foreground_alpha))
114
+ insert_into_queue(
115
+ queue,
116
+ pango_attr,
117
+ attr.start_index,
118
+ attr.end_index,
119
+ )
120
+
121
+ # foreground_color
122
+ if attr.foreground_color is not None:
123
+ pango_attr = raise_on_null_attr(
124
+ pango_attr_foreground_new(
125
+ attr.foreground_color[0],
126
+ attr.foreground_color[1],
127
+ attr.foreground_color[2],
128
+ ),
129
+ )
130
+ insert_into_queue(
131
+ queue,
132
+ pango_attr,
133
+ attr.start_index,
134
+ attr.end_index,
135
+ )
136
+
137
+ # fallback
138
+ if attr.fallback is not None:
139
+ pango_attr = raise_on_null_attr(
140
+ pango_attr_fallback_new(attr.fallback))
141
+ insert_into_queue(
142
+ queue,
143
+ pango_attr,
144
+ attr.start_index,
145
+ attr.end_index,
146
+ )
147
+
148
+ # family
149
+ if attr.family is not None:
150
+ pango_attr = raise_on_null_attr(
151
+ pango_attr_family_new(
152
+ attr.family.encode("utf-8")
153
+ ))
154
+ insert_into_queue(
155
+ queue,
156
+ pango_attr,
157
+ attr.start_index,
158
+ attr.end_index,
159
+ )
160
+
161
+ # weight
162
+ if attr.weight is not None:
163
+ pango_attr = raise_on_null_attr(
164
+ pango_attr_weight_new(attr.weight.value))
165
+ insert_into_queue(
166
+ queue,
167
+ pango_attr,
168
+ attr.start_index,
169
+ attr.end_index,
170
+ )
171
+
172
+ # line height
173
+ if attr.line_height is not None:
174
+ pango_attr = raise_on_null_attr(
175
+ pango_attr_line_height_new(attr.line_height))
176
+ insert_into_queue(
177
+ queue,
178
+ pango_attr,
179
+ attr.start_index,
180
+ attr.end_index,
181
+ )
182
+
183
+ return queue
184
+
185
+
186
+ cdef convert_to_pango_attributes(
187
+ attrs: list[TextAttribute],
188
+ PangoAttrList* pango_attr_list
189
+ ):
190
+ """Converts a list of TextAttributes to a PangoAttribute.
191
+
192
+ Note: the caller owns pango_attrlist and is responsible for freeing it.
193
+
194
+ Parameters
195
+ ----------
196
+ attrs
197
+ The list of TextAttributes to convert.
198
+ pango_attrlist
199
+ The PangoAttrList to add the attributes to.
200
+ """
201
+ cdef GQueue* temp_queue = NULL;
202
+ cdef PangoAttribute* temp_attr = NULL;
203
+
204
+ if not pango_attr_list:
205
+ raise ValueError("pango_attr_list must not be NULL.")
206
+
207
+ # Use pango_attr_list_change() to add the attributes to the list.
208
+ for attr in attrs:
209
+ temp_queue = create_attr_list_for_attribute(attr)
210
+ if not temp_queue:
211
+ raise MemoryError("holy shit")
212
+ while not g_queue_is_empty(temp_queue):
213
+ temp_attr = <PangoAttribute*>g_queue_pop_head(temp_queue)
214
+ pango_attr_list_insert(
215
+ pango_attr_list,
216
+ temp_attr
217
+ )
218
+ # Don't free the attribute
219
+ g_queue_free (temp_queue)
manimpango/buffer.pxi ADDED
@@ -0,0 +1,15 @@
1
+ cdef class ImageBuffer:
2
+ cdef unsigned char * data
3
+ cdef int height
4
+ cdef int stride
5
+
6
+ def __getbuffer__(self, Py_buffer *buffer, int flags):
7
+ buffer.buf = self.data
8
+ buffer.format = 'B'
9
+ buffer.len = self.height * self.stride
10
+ buffer.obj = self
11
+ buffer.ndim = 1
12
+ buffer.readonly = 1
13
+
14
+ def __releasebuffer__(self, Py_buffer *buffer):
15
+ pass