manimpango 0.2.1__tar.gz → 0.2.3__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ManimPango
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Bindings for Pango for using with Manim.
5
5
  Home-page: https://manimpango.manim.community/
6
6
  Author: Naveen M K
@@ -11,6 +11,5 @@ ManimPango.egg-info/not-zip-safe
11
11
  ManimPango.egg-info/top_level.txt
12
12
  manimpango/__init__.py
13
13
  manimpango/_version.py
14
- manimpango/cmanimpango.c
15
14
  manimpango/cmanimpango.pxd
16
15
  manimpango/cmanimpango.pyx
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ManimPango
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Bindings for Pango for using with Manim.
5
5
  Home-page: https://manimpango.manim.community/
6
6
  Author: Naveen M K
@@ -1,2 +1,2 @@
1
1
  # -*- coding: utf-8 -*-
2
- __version__ = "0.2.1"
2
+ __version__ = "0.2.3"
@@ -183,3 +183,30 @@ ELIF UNAME_SYSNAME == "Windows":
183
183
  DWORD fl,
184
184
  unsigned int pdv
185
185
  )
186
+ ELIF UNAME_SYSNAME == "Darwin":
187
+ cdef extern from "Carbon/Carbon.h":
188
+ ctypedef struct CFURLRef:
189
+ pass
190
+ ctypedef enum CTFontManagerScope:
191
+ kCTFontManagerScopeProcess
192
+ ctypedef unsigned int UInt8
193
+ ctypedef long CFIndex
194
+ ctypedef unsigned int UInt32
195
+ ctypedef UInt32 CFStringEncoding
196
+ CFURLRef CFURLCreateWithBytes(
197
+ void*,
198
+ unsigned char *URLBytes,
199
+ CFIndex length,
200
+ CFStringEncoding encoding,
201
+ void*
202
+ )
203
+ bint CTFontManagerRegisterFontsForURL(
204
+ CFURLRef fontURL,
205
+ CTFontManagerScope scope,
206
+ void* error
207
+ )
208
+ bint CTFontManagerUnregisterFontsForURL(
209
+ CFURLRef fontURL,
210
+ CTFontManagerScope scope,
211
+ void* error
212
+ )
@@ -269,9 +269,8 @@ def text2svg(
269
269
  class MarkupUtils:
270
270
  @staticmethod
271
271
  def validate(text: str) -> bool:
272
- length = len(text)
273
272
  text_bytes = text.encode("utf-8")
274
- return pango_parse_markup(text_bytes, <int>length, 0, NULL, NULL, NULL, NULL)
273
+ return pango_parse_markup(text_bytes, -1, 0, NULL, NULL, NULL, NULL)
275
274
 
276
275
  @staticmethod
277
276
  def text2svg(
@@ -333,7 +332,7 @@ class MarkupUtils:
333
332
  g_object_unref(layout)
334
333
  raise MemoryError("Pango.FontDesc can't be created.")
335
334
  pango_font_description_set_size(font_desc, pango_units_from_double(font_size))
336
- if font:
335
+ if font is not None and len(font) != 0:
337
336
  pango_font_description_set_family(font_desc, font.encode("utf-8"))
338
337
  pango_font_description_set_style(font_desc, PangoUtils.str2style(slant).value)
339
338
  pango_font_description_set_weight(font_desc, PangoUtils.str2weight(weight).value)
@@ -519,3 +518,65 @@ IF UNAME_SYSNAME == "Windows":
519
518
  FR_PRIVATE,
520
519
  0
521
520
  )
521
+ ELIF UNAME_SYSNAME == "Darwin":
522
+ cpdef bint register_font(str font_path):
523
+ """This function registers the font file using ``CoreText`` API so that
524
+ it is available for use by Pango.
525
+ Parameters
526
+ ==========
527
+ font_path : :class:`str`
528
+ Relative or absolute path to font file.
529
+ Returns
530
+ =======
531
+ :class:`bool`
532
+ True means it worked without any error.
533
+ False means there was an unknown error
534
+ Examples
535
+ --------
536
+ >>> register_font("/home/roboto.tff")
537
+ 1
538
+ Raises
539
+ ------
540
+ AssertionError
541
+ Font is missing.
542
+ """
543
+ a = Path(font_path)
544
+ assert a.exists(), f"font doesn't exist at {a.absolute()}"
545
+ font_path_bytes_py = str(a.absolute().as_uri()).encode('utf-8')
546
+ cdef unsigned char* font_path_bytes = <bytes>font_path_bytes_py
547
+ b = len(a.absolute().as_uri())
548
+ cdef CFURLRef cf_url = CFURLCreateWithBytes(NULL, font_path_bytes, b, 0x08000100, NULL)
549
+ return CTFontManagerRegisterFontsForURL(
550
+ cf_url,
551
+ kCTFontManagerScopeProcess,
552
+ NULL
553
+ )
554
+ cpdef bint unregister_font(str font_path):
555
+ """This function unregisters(removes) the font file using
556
+ native ``CoreText`` API. It is mostly optional to call this.
557
+ Mainly used in tests.
558
+ Parameters
559
+ ==========
560
+ font_path : :class:`str`
561
+ Relative or absolute path to font file.
562
+ Returns
563
+ =======
564
+ :class:`bool`
565
+ True means it worked without any error.
566
+ False means there was an unknown error
567
+ Raises
568
+ ------
569
+ AssertionError
570
+ Font is missing.
571
+ """
572
+ a = Path(font_path)
573
+ assert a.exists(), f"font doesn't exist at {a.absolute()}"
574
+ font_path_bytes_py = str(a.absolute().as_uri()).encode('utf-8')
575
+ cdef unsigned char* font_path_bytes = <bytes>font_path_bytes_py
576
+ b = len(a.absolute().as_uri())
577
+ cdef CFURLRef cf_url = CFURLCreateWithBytes(NULL, font_path_bytes, b, 0x08000100, NULL)
578
+ return CTFontManagerUnregisterFontsForURL(
579
+ cf_url,
580
+ kCTFontManagerScopeProcess,
581
+ NULL
582
+ )