manimpango 0.2.5__tar.gz → 0.2.6__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.
- {ManimPango-0.2.5 → ManimPango-0.2.6}/ManimPango.egg-info/PKG-INFO +34 -6
- {ManimPango-0.2.5 → ManimPango-0.2.6}/PKG-INFO +34 -6
- {ManimPango-0.2.5 → ManimPango-0.2.6}/README.md +33 -5
- ManimPango-0.2.6/manimpango/__init__.py +35 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/manimpango/_version.py +1 -1
- {ManimPango-0.2.5 → ManimPango-0.2.6}/manimpango/cmanimpango.pyx +16 -8
- ManimPango-0.2.6/manimpango/utils.py +49 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/tests/_manim.py +43 -18
- {ManimPango-0.2.5 → ManimPango-0.2.6}/tests/test_markup.py +11 -0
- ManimPango-0.2.5/manimpango/__init__.py +0 -17
- ManimPango-0.2.5/manimpango/utils.py +0 -55
- {ManimPango-0.2.5 → ManimPango-0.2.6}/.coveragerc +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/CODE_OF_CONDUCT.md +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/LICENSE +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/MANIFEST.in +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/ManimPango.egg-info/SOURCES.txt +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/ManimPango.egg-info/dependency_links.txt +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/ManimPango.egg-info/not-zip-safe +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/ManimPango.egg-info/top_level.txt +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/docs/RELEASE.rst +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/docs/_static/favicon.ico +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/docs/_templates/autosummary/class.rst +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/docs/_templates/autosummary/module.rst +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/docs/conf.py +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/docs/index.rst +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/docs/make.bat +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/docs/reference.rst +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/manimpango/cairo.pxd +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/manimpango/cmanimpango.pxd +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/manimpango/enums.pyx +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/manimpango/glib.pxd +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/manimpango/pango.pxd +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/manimpango/register_font.pxd +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/manimpango/register_font.pyx +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/pyproject.toml +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/requirements-dev.txt +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/setup.cfg +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/setup.py +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/tests/__init__.py +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/tests/conftest.py +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/tests/fonts/AdobeVFPrototype.ttf +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/tests/fonts/BungeeColor-Regular_colr_Windows.ttf +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/tests/fonts/BungeeOutline-Regular.ttf +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/tests/fonts/LICENSE.txt +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/tests/fonts/NotoNastaliqUrdu-Regular.ttf +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/tests/svg_tester.py +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/tests/test_fonts.py +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/tests/test_import.py +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/tests/test_list_fonts.py +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/tests/test_utils.py +0 -0
- {ManimPango-0.2.5 → ManimPango-0.2.6}/tests/test_version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ManimPango
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.6
|
|
4
4
|
Summary: Bindings for Pango for using with Manim.
|
|
5
5
|
Home-page: https://manimpango.manim.community/
|
|
6
6
|
Author: Naveen M K
|
|
@@ -37,6 +37,15 @@ Description: # ManimPango
|
|
|
37
37
|
|
|
38
38
|
For **Linux Users**, there are no Wheels. You must have a C compiler as well as **Pango** and its dependencies along with the **Pango** development headers. See [BUILDING](#BUILDING) for more information.
|
|
39
39
|
|
|
40
|
+
## WORKFLOW SETUP / CONTRIBUTING
|
|
41
|
+
|
|
42
|
+
To make it easier for developers to contribute, we have a pre-commit workflow that will check for `black` formatting and `flake` checking.
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
pip install pre-commit
|
|
46
|
+
pre-commit install
|
|
47
|
+
```
|
|
48
|
+
|
|
40
49
|
## BUILDING
|
|
41
50
|
|
|
42
51
|
### Linux/MacOS
|
|
@@ -65,7 +74,7 @@ Description: # ManimPango
|
|
|
65
74
|
|
|
66
75
|
Or similar in your system's package manager.
|
|
67
76
|
|
|
68
|
-
|
|
77
|
+
#### Using `tar` archives
|
|
69
78
|
|
|
70
79
|
If you don't want to contribute to this repository, you can use the tar archives published in PyPi, or just use `pip` to install using
|
|
71
80
|
|
|
@@ -75,7 +84,15 @@ Description: # ManimPango
|
|
|
75
84
|
|
|
76
85
|
**Note**: `pip` by default uses wheels, so make sure to pass the `--no-binary` parameter.
|
|
77
86
|
|
|
78
|
-
|
|
87
|
+
#### Using `git` clones / Contributing
|
|
88
|
+
|
|
89
|
+
Please remember to do this inside your virtual environment, if you want to use your **Manimpango** with **Manim**.
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
python -m venv ./venv
|
|
93
|
+
source venv/bin/activate # Linux/macOS
|
|
94
|
+
venv\Scripts\activate # Windows
|
|
95
|
+
```
|
|
79
96
|
|
|
80
97
|
If you are using a clone of this repository, you will need [Cython](https://cython.org) which can be easily installed using `pip`:
|
|
81
98
|
|
|
@@ -86,12 +103,23 @@ Description: # ManimPango
|
|
|
86
103
|
After that you can use `pip` to install the clone with the following command:
|
|
87
104
|
|
|
88
105
|
```sh
|
|
89
|
-
pip install .
|
|
106
|
+
pip install -e .
|
|
107
|
+
pip install -r requirements-dev.txt .
|
|
90
108
|
```
|
|
91
109
|
|
|
92
|
-
|
|
110
|
+
Next, run the setup script:
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
python setup.py build_ext -i
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
After installation is complete, you should be able to run pytest:
|
|
93
117
|
|
|
94
|
-
|
|
118
|
+
```sh
|
|
119
|
+
pytest
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
You will need to this way if you want to *contribute* to **ManimPango**.
|
|
95
123
|
|
|
96
124
|
### Contributing with Windows
|
|
97
125
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ManimPango
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.6
|
|
4
4
|
Summary: Bindings for Pango for using with Manim.
|
|
5
5
|
Home-page: https://manimpango.manim.community/
|
|
6
6
|
Author: Naveen M K
|
|
@@ -37,6 +37,15 @@ Description: # ManimPango
|
|
|
37
37
|
|
|
38
38
|
For **Linux Users**, there are no Wheels. You must have a C compiler as well as **Pango** and its dependencies along with the **Pango** development headers. See [BUILDING](#BUILDING) for more information.
|
|
39
39
|
|
|
40
|
+
## WORKFLOW SETUP / CONTRIBUTING
|
|
41
|
+
|
|
42
|
+
To make it easier for developers to contribute, we have a pre-commit workflow that will check for `black` formatting and `flake` checking.
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
pip install pre-commit
|
|
46
|
+
pre-commit install
|
|
47
|
+
```
|
|
48
|
+
|
|
40
49
|
## BUILDING
|
|
41
50
|
|
|
42
51
|
### Linux/MacOS
|
|
@@ -65,7 +74,7 @@ Description: # ManimPango
|
|
|
65
74
|
|
|
66
75
|
Or similar in your system's package manager.
|
|
67
76
|
|
|
68
|
-
|
|
77
|
+
#### Using `tar` archives
|
|
69
78
|
|
|
70
79
|
If you don't want to contribute to this repository, you can use the tar archives published in PyPi, or just use `pip` to install using
|
|
71
80
|
|
|
@@ -75,7 +84,15 @@ Description: # ManimPango
|
|
|
75
84
|
|
|
76
85
|
**Note**: `pip` by default uses wheels, so make sure to pass the `--no-binary` parameter.
|
|
77
86
|
|
|
78
|
-
|
|
87
|
+
#### Using `git` clones / Contributing
|
|
88
|
+
|
|
89
|
+
Please remember to do this inside your virtual environment, if you want to use your **Manimpango** with **Manim**.
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
python -m venv ./venv
|
|
93
|
+
source venv/bin/activate # Linux/macOS
|
|
94
|
+
venv\Scripts\activate # Windows
|
|
95
|
+
```
|
|
79
96
|
|
|
80
97
|
If you are using a clone of this repository, you will need [Cython](https://cython.org) which can be easily installed using `pip`:
|
|
81
98
|
|
|
@@ -86,12 +103,23 @@ Description: # ManimPango
|
|
|
86
103
|
After that you can use `pip` to install the clone with the following command:
|
|
87
104
|
|
|
88
105
|
```sh
|
|
89
|
-
pip install .
|
|
106
|
+
pip install -e .
|
|
107
|
+
pip install -r requirements-dev.txt .
|
|
90
108
|
```
|
|
91
109
|
|
|
92
|
-
|
|
110
|
+
Next, run the setup script:
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
python setup.py build_ext -i
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
After installation is complete, you should be able to run pytest:
|
|
93
117
|
|
|
94
|
-
|
|
118
|
+
```sh
|
|
119
|
+
pytest
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
You will need to this way if you want to *contribute* to **ManimPango**.
|
|
95
123
|
|
|
96
124
|
### Contributing with Windows
|
|
97
125
|
|
|
@@ -25,6 +25,15 @@ pip install manimpango
|
|
|
25
25
|
|
|
26
26
|
For **Linux Users**, there are no Wheels. You must have a C compiler as well as **Pango** and its dependencies along with the **Pango** development headers. See [BUILDING](#BUILDING) for more information.
|
|
27
27
|
|
|
28
|
+
## WORKFLOW SETUP / CONTRIBUTING
|
|
29
|
+
|
|
30
|
+
To make it easier for developers to contribute, we have a pre-commit workflow that will check for `black` formatting and `flake` checking.
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
pip install pre-commit
|
|
34
|
+
pre-commit install
|
|
35
|
+
```
|
|
36
|
+
|
|
28
37
|
## BUILDING
|
|
29
38
|
|
|
30
39
|
### Linux/MacOS
|
|
@@ -53,7 +62,7 @@ apt install libpango1.0-dev pkg-config python3-dev
|
|
|
53
62
|
|
|
54
63
|
Or similar in your system's package manager.
|
|
55
64
|
|
|
56
|
-
|
|
65
|
+
#### Using `tar` archives
|
|
57
66
|
|
|
58
67
|
If you don't want to contribute to this repository, you can use the tar archives published in PyPi, or just use `pip` to install using
|
|
59
68
|
|
|
@@ -63,7 +72,15 @@ pip install manimpango --no-binary :all:
|
|
|
63
72
|
|
|
64
73
|
**Note**: `pip` by default uses wheels, so make sure to pass the `--no-binary` parameter.
|
|
65
74
|
|
|
66
|
-
|
|
75
|
+
#### Using `git` clones / Contributing
|
|
76
|
+
|
|
77
|
+
Please remember to do this inside your virtual environment, if you want to use your **Manimpango** with **Manim**.
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
python -m venv ./venv
|
|
81
|
+
source venv/bin/activate # Linux/macOS
|
|
82
|
+
venv\Scripts\activate # Windows
|
|
83
|
+
```
|
|
67
84
|
|
|
68
85
|
If you are using a clone of this repository, you will need [Cython](https://cython.org) which can be easily installed using `pip`:
|
|
69
86
|
|
|
@@ -74,12 +91,23 @@ pip install Cython
|
|
|
74
91
|
After that you can use `pip` to install the clone with the following command:
|
|
75
92
|
|
|
76
93
|
```sh
|
|
77
|
-
pip install .
|
|
94
|
+
pip install -e .
|
|
95
|
+
pip install -r requirements-dev.txt .
|
|
78
96
|
```
|
|
79
97
|
|
|
80
|
-
|
|
98
|
+
Next, run the setup script:
|
|
99
|
+
|
|
100
|
+
```sh
|
|
101
|
+
python setup.py build_ext -i
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
After installation is complete, you should be able to run pytest:
|
|
81
105
|
|
|
82
|
-
|
|
106
|
+
```sh
|
|
107
|
+
pytest
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
You will need to this way if you want to *contribute* to **ManimPango**.
|
|
83
111
|
|
|
84
112
|
### Contributing with Windows
|
|
85
113
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from ._version import __version__ # noqa: F403,F401
|
|
6
|
+
|
|
7
|
+
if os.name == "nt": # pragma: no cover
|
|
8
|
+
os.environ["PATH"] = (
|
|
9
|
+
f"{os.path.abspath(os.path.dirname(__file__))}"
|
|
10
|
+
f"{os.pathsep}"
|
|
11
|
+
f"{os.environ['PATH']}"
|
|
12
|
+
)
|
|
13
|
+
try:
|
|
14
|
+
from .cmanimpango import * # noqa: F403,F401
|
|
15
|
+
from .enums import * # noqa: F403,F401
|
|
16
|
+
from .register_font import * # noqa: F403,F401
|
|
17
|
+
except ImportError as ie: # pragma: no cover
|
|
18
|
+
py_ver = ".".join(map(str, sys.version_info[:3]))
|
|
19
|
+
msg = f"""
|
|
20
|
+
|
|
21
|
+
ManimPango could not import and load the necessary shared libraries.
|
|
22
|
+
This error may occur when ManimPango and its dependencies are improperly set up.
|
|
23
|
+
Please make sure the following versions are what you expect:
|
|
24
|
+
|
|
25
|
+
* ManimPango v{__version__}, Python v{py_ver}
|
|
26
|
+
|
|
27
|
+
If you believe there is a greater problem,
|
|
28
|
+
feel free to contact us or create an issue on GitHub:
|
|
29
|
+
|
|
30
|
+
* Discord: https://discord.gg/mMRrZQW
|
|
31
|
+
* GitHub: https://github.com/ManimCommunity/ManimPango/issues
|
|
32
|
+
|
|
33
|
+
Original error: {ie}
|
|
34
|
+
"""
|
|
35
|
+
raise ImportError(msg)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
__version__ = "0.2.
|
|
2
|
+
__version__ = "0.2.6"
|
|
@@ -2,6 +2,7 @@ from xml.sax.saxutils import escape
|
|
|
2
2
|
from .utils import *
|
|
3
3
|
from .enums import Alignment
|
|
4
4
|
import warnings
|
|
5
|
+
import typing
|
|
5
6
|
|
|
6
7
|
class TextSetting:
|
|
7
8
|
"""Formatting for slices of a :class:`manim.mobject.svg.text_mobject.Text` object."""
|
|
@@ -31,14 +32,14 @@ def text2svg(
|
|
|
31
32
|
START_Y:int,
|
|
32
33
|
width:int,
|
|
33
34
|
height:int,
|
|
34
|
-
orig_text:str
|
|
35
|
+
orig_text:str,
|
|
36
|
+
pango_width: typing.Union[int, None] = None,
|
|
35
37
|
) -> int:
|
|
36
38
|
"""Render an SVG file from a :class:`manim.mobject.svg.text_mobject.Text` object."""
|
|
37
39
|
cdef cairo_surface_t* surface
|
|
38
40
|
cdef cairo_t* cr
|
|
39
41
|
cdef PangoFontDescription* font_desc
|
|
40
42
|
cdef PangoLayout* layout
|
|
41
|
-
cdef double width_layout = width
|
|
42
43
|
cdef double font_size_c = size
|
|
43
44
|
cdef cairo_status_t status
|
|
44
45
|
cdef int temp_width
|
|
@@ -67,12 +68,16 @@ def text2svg(
|
|
|
67
68
|
|
|
68
69
|
layout = pango_cairo_create_layout(cr)
|
|
69
70
|
|
|
70
|
-
if layout==NULL:
|
|
71
|
+
if layout == NULL:
|
|
71
72
|
cairo_destroy(cr)
|
|
72
73
|
cairo_surface_destroy(surface)
|
|
73
74
|
raise MemoryError("Pango.Layout can't be created from Cairo Context.")
|
|
74
75
|
|
|
75
|
-
|
|
76
|
+
if pango_width is None:
|
|
77
|
+
pango_layout_set_width(layout, pango_units_from_double(width))
|
|
78
|
+
else:
|
|
79
|
+
pango_layout_set_width(layout, pango_units_from_double(pango_width))
|
|
80
|
+
|
|
76
81
|
for setting in settings:
|
|
77
82
|
family = setting.font
|
|
78
83
|
style = PangoUtils.str2style(setting.slant)
|
|
@@ -151,7 +156,8 @@ class MarkupUtils:
|
|
|
151
156
|
justify: bool = None,
|
|
152
157
|
indent: float = None,
|
|
153
158
|
line_spacing: float = None,
|
|
154
|
-
alignment: Alignment = None
|
|
159
|
+
alignment: Alignment = None,
|
|
160
|
+
pango_width: typing.Union[int, None] = None,
|
|
155
161
|
) -> int:
|
|
156
162
|
"""Render an SVG file from a :class:`manim.mobject.svg.text_mobject.MarkupText` object."""
|
|
157
163
|
cdef cairo_surface_t* surface
|
|
@@ -159,7 +165,6 @@ class MarkupUtils:
|
|
|
159
165
|
cdef PangoFontDescription* font_desc
|
|
160
166
|
cdef PangoLayout* layout
|
|
161
167
|
cdef cairo_status_t status
|
|
162
|
-
cdef double width_layout = width - 50
|
|
163
168
|
cdef double font_size = size
|
|
164
169
|
cdef int temp_int # a temporary C integer for conversion
|
|
165
170
|
|
|
@@ -186,12 +191,15 @@ class MarkupUtils:
|
|
|
186
191
|
|
|
187
192
|
cairo_move_to(context,START_X,START_Y)
|
|
188
193
|
layout = pango_cairo_create_layout(context)
|
|
189
|
-
if layout==NULL:
|
|
194
|
+
if layout == NULL:
|
|
190
195
|
cairo_destroy(context)
|
|
191
196
|
cairo_surface_destroy(surface)
|
|
192
197
|
raise MemoryError("Pango.Layout can't be created from Cairo Context.")
|
|
193
198
|
|
|
194
|
-
|
|
199
|
+
if pango_width is None:
|
|
200
|
+
pango_layout_set_width(layout, pango_units_from_double(width))
|
|
201
|
+
else:
|
|
202
|
+
pango_layout_set_width(layout, pango_units_from_double(pango_width))
|
|
195
203
|
|
|
196
204
|
if justify:
|
|
197
205
|
pango_layout_set_justify(layout, justify)
|
|
@@ -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)
|
|
@@ -26,6 +26,7 @@ class MarkupText:
|
|
|
26
26
|
alignment: Alignment = None,
|
|
27
27
|
# for the tests
|
|
28
28
|
filename: str = "test.svg",
|
|
29
|
+
wrap_text: bool = True,
|
|
29
30
|
**kwargs,
|
|
30
31
|
):
|
|
31
32
|
self.text = text
|
|
@@ -42,6 +43,7 @@ class MarkupText:
|
|
|
42
43
|
self.justify = justify
|
|
43
44
|
self.indent = indent
|
|
44
45
|
self.alignment = alignment
|
|
46
|
+
self.wrap_text = wrap_text
|
|
45
47
|
if not MarkupUtils.validate(self.text):
|
|
46
48
|
raise ValueError(
|
|
47
49
|
f"Pango cannot parse your markup in {self.text}. "
|
|
@@ -58,24 +60,47 @@ class MarkupText:
|
|
|
58
60
|
if not os.path.exists(dir_name):
|
|
59
61
|
os.makedirs(dir_name)
|
|
60
62
|
file_name = self.filename
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
63
|
+
if self.wrap_text:
|
|
64
|
+
return MarkupUtils.text2svg(
|
|
65
|
+
f"{self.text}",
|
|
66
|
+
self.font,
|
|
67
|
+
self.slant,
|
|
68
|
+
self.weight,
|
|
69
|
+
size,
|
|
70
|
+
True, # stray positional argument
|
|
71
|
+
disable_liga,
|
|
72
|
+
file_name,
|
|
73
|
+
20,
|
|
74
|
+
20,
|
|
75
|
+
600, # width
|
|
76
|
+
400, # height
|
|
77
|
+
justify=self.justify,
|
|
78
|
+
indent=self.indent,
|
|
79
|
+
line_spacing=self.line_spacing,
|
|
80
|
+
alignment=self.alignment,
|
|
81
|
+
)
|
|
82
|
+
else:
|
|
83
|
+
return MarkupUtils.text2svg(
|
|
84
|
+
f"{self.text}",
|
|
85
|
+
self.font,
|
|
86
|
+
self.slant,
|
|
87
|
+
self.weight,
|
|
88
|
+
size,
|
|
89
|
+
True, # stray positional argument
|
|
90
|
+
disable_liga,
|
|
91
|
+
file_name,
|
|
92
|
+
20,
|
|
93
|
+
20,
|
|
94
|
+
600, # width
|
|
95
|
+
400, # height
|
|
96
|
+
justify=self.justify,
|
|
97
|
+
indent=self.indent,
|
|
98
|
+
line_spacing=self.line_spacing,
|
|
99
|
+
alignment=self.alignment,
|
|
100
|
+
pango_width=-1,
|
|
101
|
+
)
|
|
102
|
+
# -1 for no wrapping
|
|
103
|
+
# default is full width and then wrap.
|
|
79
104
|
|
|
80
105
|
def __repr__(self):
|
|
81
106
|
return f"MarkupText({repr(self.original_text)})"
|
|
@@ -97,3 +97,14 @@ def test_markup_style(tmpdir):
|
|
|
97
97
|
s = SVGStyleTester(gotSVG=expected, expectedSVG=test_case)
|
|
98
98
|
assert len(s.got_svg_style) == len(s.expected_svg_style)
|
|
99
99
|
assert s.got_svg_style == s.expected_svg_style
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def test_wrap_text(tmpdir):
|
|
103
|
+
tmpdir = Path(tmpdir)
|
|
104
|
+
wrapped = tmpdir / "wrap.svg"
|
|
105
|
+
nowrap = tmpdir / "nowarap.svg"
|
|
106
|
+
|
|
107
|
+
MarkupText(ipsum_text, wrap_text=False, filename=str(nowrap))
|
|
108
|
+
MarkupText(ipsum_text, filename=str(wrapped))
|
|
109
|
+
|
|
110
|
+
assert wrapped.read_text() != nowrap.read_text()
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
import os
|
|
3
|
-
|
|
4
|
-
from ._version import __version__ # noqa: F403,F401
|
|
5
|
-
|
|
6
|
-
if os.name == "nt": # pragma: no cover
|
|
7
|
-
os.environ["PATH"] = (
|
|
8
|
-
f"{os.path.abspath(os.path.dirname(__file__))}"
|
|
9
|
-
f"{os.pathsep}"
|
|
10
|
-
f"{os.environ['PATH']}"
|
|
11
|
-
)
|
|
12
|
-
try:
|
|
13
|
-
from .cmanimpango import * # noqa: F403,F401
|
|
14
|
-
from .enums import * # noqa: F403,F401
|
|
15
|
-
from .register_font import * # noqa: F403,F401
|
|
16
|
-
except ImportError: # pragma: no cover
|
|
17
|
-
raise ImportError("Couldn't load the necessary Shared Libraries.")
|
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
if string == "NORMAL":
|
|
12
|
-
return Style.NORMAL
|
|
13
|
-
elif string == "ITALIC":
|
|
14
|
-
return Style.ITALIC
|
|
15
|
-
elif string == "OBLIQUE":
|
|
16
|
-
return Style.OBLIQUE
|
|
17
|
-
else:
|
|
18
|
-
raise AttributeError("There is no Style Called %s" % string)
|
|
19
|
-
|
|
20
|
-
@staticmethod
|
|
21
|
-
def str2weight(string: str) -> Weight:
|
|
22
|
-
"""Internally used function. Convert text to Pango Understandable Weight"""
|
|
23
|
-
if string == "NORMAL":
|
|
24
|
-
return Weight.NORMAL
|
|
25
|
-
elif string == "BOLD":
|
|
26
|
-
return Weight.BOLD
|
|
27
|
-
elif string == "THIN":
|
|
28
|
-
return Weight.THIN
|
|
29
|
-
elif string == "ULTRALIGHT":
|
|
30
|
-
return Weight.ULTRALIGHT
|
|
31
|
-
elif string == "LIGHT":
|
|
32
|
-
return Weight.LIGHT
|
|
33
|
-
elif string == "BOOK":
|
|
34
|
-
return Weight.BOOK
|
|
35
|
-
elif string == "MEDIUM":
|
|
36
|
-
return Weight.MEDIUM
|
|
37
|
-
elif string == "SEMIBOLD":
|
|
38
|
-
return Weight.SEMIBOLD
|
|
39
|
-
elif string == "ULTRABOLD":
|
|
40
|
-
return Weight.ULTRABOLD
|
|
41
|
-
elif string == "HEAVY":
|
|
42
|
-
return Weight.HEAVY
|
|
43
|
-
elif string == "ULTRAHEAVY":
|
|
44
|
-
return Weight.ULTRAHEAVY
|
|
45
|
-
else:
|
|
46
|
-
raise AttributeError("There is no Font Weight Called %s" % string)
|
|
47
|
-
|
|
48
|
-
@staticmethod
|
|
49
|
-
def remove_last_M(file_name: str) -> None:
|
|
50
|
-
"""Remove element from the SVG file in order to allow comparison."""
|
|
51
|
-
with open(file_name, "r") as fpr:
|
|
52
|
-
content = fpr.read()
|
|
53
|
-
content = re.sub(r'Z M [^A-Za-z]*? "\/>', 'Z "/>', content)
|
|
54
|
-
with open(file_name, "w") as fpw:
|
|
55
|
-
fpw.write(content)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|