ManimPango 0.6.1__cp311-cp311-macosx_10_13_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.
- manimpango/__init__.py +35 -0
- manimpango/_register_font.cpython-311-darwin.so +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.cpython-311-darwin.so +0 -0
- manimpango/cmanimpango.pxd +3 -0
- manimpango/cmanimpango.pyx +321 -0
- manimpango/enums.cpython-311-darwin.so +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
- manimpango-0.6.1.dist-info/METADATA +219 -0
- manimpango-0.6.1.dist-info/RECORD +21 -0
- manimpango-0.6.1.dist-info/WHEEL +6 -0
- manimpango-0.6.1.dist-info/licenses/LICENSE +21 -0
- manimpango-0.6.1.dist-info/licenses/LICENSE.bin +3208 -0
- manimpango-0.6.1.dist-info/top_level.txt +1 -0
manimpango/enums.pyx
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
from pango cimport *
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Style(Enum):
|
|
7
|
+
"""
|
|
8
|
+
An enumeration specifying the various slant styles possible for a font.
|
|
9
|
+
|
|
10
|
+
Attributes
|
|
11
|
+
----------
|
|
12
|
+
|
|
13
|
+
NORMAL :
|
|
14
|
+
the font is upright.
|
|
15
|
+
|
|
16
|
+
ITALIC :
|
|
17
|
+
the font is slanted, but in a roman style.
|
|
18
|
+
|
|
19
|
+
OBLIQUE:
|
|
20
|
+
the font is slanted in an italic style.
|
|
21
|
+
"""
|
|
22
|
+
NORMAL = PANGO_STYLE_NORMAL
|
|
23
|
+
ITALIC = PANGO_STYLE_ITALIC
|
|
24
|
+
OBLIQUE = PANGO_STYLE_OBLIQUE
|
|
25
|
+
|
|
26
|
+
class Weight(Enum):
|
|
27
|
+
"""
|
|
28
|
+
An enumeration specifying the weight (boldness) of a font.
|
|
29
|
+
This is a numerical value ranging from 100 to 1000, but there are some predefined values
|
|
30
|
+
Using numerical value other then that defined here is not supported.
|
|
31
|
+
|
|
32
|
+
Attributes
|
|
33
|
+
----------
|
|
34
|
+
|
|
35
|
+
NORMAL :
|
|
36
|
+
the default weight (= 400)
|
|
37
|
+
|
|
38
|
+
BOLD :
|
|
39
|
+
the bold weight( = 700)
|
|
40
|
+
|
|
41
|
+
THIN :
|
|
42
|
+
the thin weight( = 100; Since: 1.24)
|
|
43
|
+
|
|
44
|
+
ULTRALIGHT :
|
|
45
|
+
the ultralight weight( = 200)
|
|
46
|
+
|
|
47
|
+
LIGHT :
|
|
48
|
+
the light weight( = 300)
|
|
49
|
+
|
|
50
|
+
BOOK :
|
|
51
|
+
the book weight( = 380; Since: 1.24)
|
|
52
|
+
|
|
53
|
+
MEDIUM :
|
|
54
|
+
the normal weight( = 500; Since: 1.24)
|
|
55
|
+
|
|
56
|
+
SEMIBOLD :
|
|
57
|
+
the semibold weight( = 600)
|
|
58
|
+
|
|
59
|
+
ULTRABOLD :
|
|
60
|
+
the ultrabold weight( = 800)
|
|
61
|
+
|
|
62
|
+
HEAVY :
|
|
63
|
+
the heavy weight( = 900)
|
|
64
|
+
|
|
65
|
+
ULTRAHEAVY :
|
|
66
|
+
the ultraheavy weight( = 1000; Since: 1.24)
|
|
67
|
+
"""
|
|
68
|
+
NORMAL = PANGO_WEIGHT_NORMAL
|
|
69
|
+
BOLD = PANGO_WEIGHT_BOLD
|
|
70
|
+
THIN = PANGO_WEIGHT_THIN
|
|
71
|
+
ULTRALIGHT = PANGO_WEIGHT_ULTRALIGHT
|
|
72
|
+
LIGHT = PANGO_WEIGHT_LIGHT
|
|
73
|
+
BOOK = PANGO_WEIGHT_BOOK
|
|
74
|
+
MEDIUM = PANGO_WEIGHT_MEDIUM
|
|
75
|
+
SEMIBOLD = PANGO_WEIGHT_SEMIBOLD
|
|
76
|
+
ULTRABOLD = PANGO_WEIGHT_ULTRABOLD
|
|
77
|
+
HEAVY = PANGO_WEIGHT_HEAVY
|
|
78
|
+
ULTRAHEAVY = PANGO_WEIGHT_ULTRAHEAVY
|
|
79
|
+
|
|
80
|
+
class Variant(Enum):
|
|
81
|
+
"""
|
|
82
|
+
An enumeration specifying capitalization variant of the font.
|
|
83
|
+
|
|
84
|
+
Attributes
|
|
85
|
+
----------
|
|
86
|
+
|
|
87
|
+
NORMAL :
|
|
88
|
+
A normal font.
|
|
89
|
+
|
|
90
|
+
SMALL_CAPS :
|
|
91
|
+
A font with the lower case characters replaced by smaller variants
|
|
92
|
+
of the capital characters.
|
|
93
|
+
"""
|
|
94
|
+
NORMAL = PANGO_VARIANT_NORMAL
|
|
95
|
+
SMALL_CAPS = PANGO_VARIANT_SMALL_CAPS
|
|
96
|
+
|
|
97
|
+
class Alignment(Enum):
|
|
98
|
+
"""
|
|
99
|
+
An enumeration specifying alignment.
|
|
100
|
+
|
|
101
|
+
Attributes
|
|
102
|
+
----------
|
|
103
|
+
|
|
104
|
+
NORMAL :
|
|
105
|
+
A normal font.
|
|
106
|
+
|
|
107
|
+
SMALL_CAPS :
|
|
108
|
+
A font with the lower case characters replaced by smaller variants
|
|
109
|
+
of the capital characters.
|
|
110
|
+
"""
|
|
111
|
+
LEFT = PANGO_ALIGN_LEFT
|
|
112
|
+
CENTER = PANGO_ALIGN_CENTER
|
|
113
|
+
RIGHT = PANGO_ALIGN_RIGHT
|
manimpango/glib.pxd
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
cdef extern from "glib.h":
|
|
2
|
+
ctypedef void* gpointer
|
|
3
|
+
ctypedef int gint
|
|
4
|
+
ctypedef unsigned int guint
|
|
5
|
+
ctypedef gint gboolean
|
|
6
|
+
ctypedef unsigned short guint16
|
|
7
|
+
ctypedef char gchar
|
|
8
|
+
ctypedef struct GError:
|
|
9
|
+
gint code
|
|
10
|
+
gchar *message
|
|
11
|
+
void g_error_free (GError *error)
|
|
12
|
+
void g_object_unref(gpointer object)
|
|
13
|
+
void g_free(gpointer mem)
|
manimpango/pango.pxd
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
from cairo cimport *
|
|
2
|
+
from glib cimport *
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
cdef extern from "pango/pangocairo.h":
|
|
6
|
+
int PANGO_SCALE
|
|
7
|
+
int pango_units_from_double(double d)
|
|
8
|
+
double pango_units_to_double (int i)
|
|
9
|
+
ctypedef struct PangoLayout:
|
|
10
|
+
pass
|
|
11
|
+
ctypedef struct PangoContext:
|
|
12
|
+
pass
|
|
13
|
+
ctypedef struct PangoFontMap:
|
|
14
|
+
pass
|
|
15
|
+
ctypedef struct PangoFontDescription:
|
|
16
|
+
pass
|
|
17
|
+
ctypedef struct PangoFontFamily:
|
|
18
|
+
pass
|
|
19
|
+
ctypedef enum PangoStyle:
|
|
20
|
+
PANGO_STYLE_NORMAL
|
|
21
|
+
PANGO_STYLE_OBLIQUE
|
|
22
|
+
PANGO_STYLE_ITALIC
|
|
23
|
+
ctypedef enum PangoWeight:
|
|
24
|
+
PANGO_WEIGHT_THIN
|
|
25
|
+
PANGO_WEIGHT_ULTRALIGHT
|
|
26
|
+
PANGO_WEIGHT_LIGHT
|
|
27
|
+
PANGO_WEIGHT_BOOK
|
|
28
|
+
PANGO_WEIGHT_NORMAL
|
|
29
|
+
PANGO_WEIGHT_MEDIUM
|
|
30
|
+
PANGO_WEIGHT_SEMIBOLD
|
|
31
|
+
PANGO_WEIGHT_BOLD
|
|
32
|
+
PANGO_WEIGHT_ULTRABOLD
|
|
33
|
+
PANGO_WEIGHT_HEAVY
|
|
34
|
+
PANGO_WEIGHT_ULTRAHEAVY
|
|
35
|
+
ctypedef enum PangoVariant:
|
|
36
|
+
PANGO_VARIANT_NORMAL
|
|
37
|
+
PANGO_VARIANT_SMALL_CAPS
|
|
38
|
+
ctypedef enum PangoWrapMode:
|
|
39
|
+
PANGO_WRAP_WORD
|
|
40
|
+
PANGO_WRAP_CHAR
|
|
41
|
+
PANGO_WRAP_WORD_CHAR
|
|
42
|
+
ctypedef enum PangoAlignment:
|
|
43
|
+
PANGO_ALIGN_LEFT
|
|
44
|
+
PANGO_ALIGN_CENTER
|
|
45
|
+
PANGO_ALIGN_RIGHT
|
|
46
|
+
PangoLayout* pango_cairo_create_layout(cairo_t* cr)
|
|
47
|
+
void pango_cairo_show_layout(
|
|
48
|
+
cairo_t* cr,
|
|
49
|
+
PangoLayout* layout
|
|
50
|
+
)
|
|
51
|
+
void pango_cairo_update_layout(
|
|
52
|
+
cairo_t* cr,
|
|
53
|
+
PangoLayout* layout
|
|
54
|
+
)
|
|
55
|
+
PangoFontDescription* pango_font_description_new()
|
|
56
|
+
void pango_font_description_set_size(
|
|
57
|
+
PangoFontDescription* desc,
|
|
58
|
+
gint size
|
|
59
|
+
)
|
|
60
|
+
void pango_font_description_set_family(
|
|
61
|
+
PangoFontDescription* desc,
|
|
62
|
+
const char* family
|
|
63
|
+
)
|
|
64
|
+
void pango_font_description_set_style(
|
|
65
|
+
PangoFontDescription* desc,
|
|
66
|
+
PangoStyle style
|
|
67
|
+
)
|
|
68
|
+
void pango_font_description_set_weight(
|
|
69
|
+
PangoFontDescription* desc,
|
|
70
|
+
PangoWeight weight
|
|
71
|
+
)
|
|
72
|
+
void pango_font_description_set_variant(
|
|
73
|
+
PangoFontDescription* desc,
|
|
74
|
+
PangoVariant variant
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
void pango_layout_set_width(
|
|
78
|
+
PangoLayout* layout,
|
|
79
|
+
int width
|
|
80
|
+
)
|
|
81
|
+
void pango_layout_set_font_description(
|
|
82
|
+
PangoLayout* layout,
|
|
83
|
+
const PangoFontDescription* desc
|
|
84
|
+
)
|
|
85
|
+
void pango_layout_set_text(
|
|
86
|
+
PangoLayout* layout,
|
|
87
|
+
const char* text,
|
|
88
|
+
int length
|
|
89
|
+
)
|
|
90
|
+
void pango_layout_set_wrap(
|
|
91
|
+
PangoLayout *layout,
|
|
92
|
+
PangoWrapMode wrap
|
|
93
|
+
)
|
|
94
|
+
void pango_layout_set_markup(
|
|
95
|
+
PangoLayout *layout,
|
|
96
|
+
const char *markup,
|
|
97
|
+
int length
|
|
98
|
+
)
|
|
99
|
+
void pango_layout_get_size(
|
|
100
|
+
PangoLayout* layout,
|
|
101
|
+
int* width,
|
|
102
|
+
int* height
|
|
103
|
+
)
|
|
104
|
+
const char* pango_version_string()
|
|
105
|
+
void pango_font_description_free(
|
|
106
|
+
PangoFontDescription *desc
|
|
107
|
+
)
|
|
108
|
+
gboolean pango_parse_markup(
|
|
109
|
+
const char *markup_text,
|
|
110
|
+
int length,
|
|
111
|
+
unsigned int accel_marker,
|
|
112
|
+
void* attr_list,
|
|
113
|
+
void* text,
|
|
114
|
+
void* accel_char,
|
|
115
|
+
void* error
|
|
116
|
+
)
|
|
117
|
+
PangoFontMap* pango_cairo_font_map_new()
|
|
118
|
+
void pango_font_map_list_families(
|
|
119
|
+
PangoFontMap *fontmap,
|
|
120
|
+
PangoFontFamily ***families,
|
|
121
|
+
int *n_families
|
|
122
|
+
)
|
|
123
|
+
PangoFontFamily* pango_font_map_get_family(
|
|
124
|
+
PangoFontMap *fontmap,
|
|
125
|
+
const char *name
|
|
126
|
+
)
|
|
127
|
+
const char* pango_font_family_get_name(
|
|
128
|
+
PangoFontFamily *family
|
|
129
|
+
)
|
|
130
|
+
void pango_layout_set_justify(
|
|
131
|
+
PangoLayout *layout,
|
|
132
|
+
gboolean justify
|
|
133
|
+
)
|
|
134
|
+
void pango_layout_set_indent(
|
|
135
|
+
PangoLayout *layout,
|
|
136
|
+
int indent
|
|
137
|
+
)
|
|
138
|
+
void pango_layout_set_alignment(
|
|
139
|
+
PangoLayout *layout,
|
|
140
|
+
PangoAlignment alignment
|
|
141
|
+
)
|
|
142
|
+
PangoFontMap* pango_context_get_font_map(
|
|
143
|
+
PangoContext* context
|
|
144
|
+
)
|
|
145
|
+
PangoContext* pango_layout_get_context(
|
|
146
|
+
PangoLayout* layout
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
cdef extern from *:
|
|
152
|
+
"""
|
|
153
|
+
#if _WIN32
|
|
154
|
+
#include <pango/pangowin32.h>
|
|
155
|
+
#endif
|
|
156
|
+
#if PANGO_VERSION_CHECK(1,44,0)
|
|
157
|
+
int set_line_width(PangoLayout *layout,float spacing)
|
|
158
|
+
{
|
|
159
|
+
pango_layout_set_line_spacing(layout, spacing);
|
|
160
|
+
return 1;
|
|
161
|
+
}
|
|
162
|
+
#else
|
|
163
|
+
int set_line_width(PangoLayout *layout,float spacing){return 0;}
|
|
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
|
+
|
|
182
|
+
"""
|
|
183
|
+
# The above docs string is C which is used to
|
|
184
|
+
# check for the Pango Version there at run time.
|
|
185
|
+
# pango_layout_set_line_spacing is only avaiable only for
|
|
186
|
+
# pango>=1.44.0 but we support pango>=1.30.0 that why this
|
|
187
|
+
# conditionals.
|
|
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
|
+
)
|
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)
|