unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob 579c2302d853b4b56e70ea6fd118d8075cf5f9ef 5650 bytes (raw)
name: gnu/packages/patches/python-manimpango-remove-manim-dep.patch 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
 
Fix dependency on manim for tests

This fixes a circular dependency between manim and manimpango.

Extracted from upstream:
https://github.com/ManimCommunity/ManimPango/commit/7e2b17aa14b10bd58af0598cc2de51a406682797

diff --git a/tests/_manim.py b/tests/_manim.py
index 3ea4676..b11d3e9 100644
--- a/tests/_manim.py
+++ b/tests/_manim.py
@@ -2,11 +2,12 @@
 """This file contains helpers for the tests copied and modified
 from Manim.
 """
-
+import copy
 import os
+import re
 from pathlib import Path

-from manimpango import Alignment, MarkupUtils
+from manimpango import Alignment, MarkupUtils, TextSetting, text2svg


 class MarkupText:
@@ -104,3 +105,115 @@ class MarkupText:

     def __repr__(self):
         return f"MarkupText({repr(self.original_text)})"
+
+
+class Text:
+    def __init__(
+        self,
+        text: str,
+        fill_opacity: float = 1.0,
+        stroke_width: int = 0,
+        size: int = 1,
+        line_spacing: int = -1,
+        font: str = "",
+        slant: str = "NORMAL",
+        weight: str = "NORMAL",
+        gradient: tuple = None,
+        tab_width: int = 4,
+        disable_ligatures: bool = False,
+        filename: str = "text.svg",
+        **kwargs,
+    ) -> None:
+        self.size = size
+        self.filename = filename
+        self.line_spacing = line_spacing
+        self.font = font
+        self.slant = slant
+        self.weight = weight
+        self.gradient = gradient
+        self.tab_width = tab_width
+        self.original_text = text
+        self.disable_ligatures = disable_ligatures
+        text_without_tabs = text
+        self.t2f = self.t2s = self.t2w = {}
+        if text.find("\t") != -1:
+            text_without_tabs = text.replace("\t", " " * self.tab_width)
+        self.text = text_without_tabs
+        if self.line_spacing == -1:
+            self.line_spacing = self.size + self.size * 0.3
+        else:
+            self.line_spacing = self.size + self.size * self.line_spacing
+        self.text2svg()
+
+    def text2settings(self):
+        """Internally used function. Converts the texts and styles
+        to a setting for parsing."""
+        settings = []
+        t2x = [self.t2f, self.t2s, self.t2w]
+        for i in range(len(t2x)):
+            fsw = [self.font, self.slant, self.weight]
+            if t2x[i]:
+                for word, x in list(t2x[i].items()):
+                    for start, end in self.find_indexes(word, self.text):
+                        fsw[i] = x
+                        settings.append(TextSetting(start, end, *fsw))
+        # Set all text settings (default font, slant, weight)
+        fsw = [self.font, self.slant, self.weight]
+        settings.sort(key=lambda setting: setting.start)
+        temp_settings = settings.copy()
+        start = 0
+        for setting in settings:
+            if setting.start != start:
+                temp_settings.append(TextSetting(start, setting.start, *fsw))
+            start = setting.end
+        if start != len(self.text):
+            temp_settings.append(TextSetting(start, len(self.text), *fsw))
+        settings = sorted(temp_settings, key=lambda setting: setting.start)
+
+        if re.search(r"\n", self.text):
+            line_num = 0
+            for start, end in self.find_indexes("\n", self.text):
+                for setting in settings:
+                    if setting.line_num == -1:
+                        setting.line_num = line_num
+                    if start < setting.end:
+                        line_num += 1
+                        new_setting = copy.copy(setting)
+                        setting.end = end
+                        new_setting.start = end
+                        new_setting.line_num = line_num
+                        settings.append(new_setting)
+                        settings.sort(key=lambda setting: setting.start)
+                        break
+        for setting in settings:
+            if setting.line_num == -1:
+                setting.line_num = 0
+        return settings
+
+    def text2svg(self):
+        """Internally used function.
+        Convert the text to SVG using Pango
+        """
+        size = self.size * 10
+        line_spacing = self.line_spacing * 10
+        dir_name = Path(self.filename).parent
+        disable_liga = self.disable_ligatures
+        if not os.path.exists(dir_name):
+            os.makedirs(dir_name)
+        file_name = self.filename
+        settings = self.text2settings()
+        width = 600
+        height = 400
+
+        return text2svg(
+            settings,
+            size,
+            line_spacing,
+            disable_liga,
+            file_name,
+            30,
+            30,
+            width,
+            height,
+            self.text,
+        )
diff --git a/tests/test_fonts.py b/tests/test_fonts.py
index 51e7eb4..da42895 100644
--- a/tests/test_fonts.py
+++ b/tests/test_fonts.py
@@ -3,13 +3,12 @@ import sys
 from pathlib import Path
 from shutil import copyfile

-import manim
 import pytest

 import manimpango

 from . import FONT_DIR
-from ._manim import MarkupText
+from ._manim import MarkupText, Text

 font_lists = {
     (FONT_DIR / "AdobeVFPrototype.ttf").absolute(): "Adobe Variable Font Prototype",
@@ -38,7 +37,7 @@ def test_register_font(font_name):
 @pytest.mark.parametrize("font_name", font_lists.values())
 def test_warning(capfd, font_name):
     print(font_name)
-    manim.Text("Testing", font=font_name)
+    Text("Testing", font=font_name)
     captured = capfd.readouterr()
     assert "Pango-WARNING **" not in captured.err, "Looks like pango raised a warning?"

--
2.32.0

debug log:

solving 579c2302d8 ...
found 579c2302d8 in https://yhetil.org/guix-patches/20210910112502.6466-10-daniel.meissner-i4k@ruhr-uni-bochum.de/ ||
	https://yhetil.org/guix-patches/20210915152519.25572-11-daniel.meissner-i4k@ruhr-uni-bochum.de/ ||
	https://yhetil.org/guix-patches/20220101235155.5754-10-daniel.meissner-i4k@ruhr-uni-bochum.de/

applying [1/1] https://yhetil.org/guix-patches/20210910112502.6466-10-daniel.meissner-i4k@ruhr-uni-bochum.de/
diff --git a/gnu/packages/patches/python-manimpango-remove-manim-dep.patch b/gnu/packages/patches/python-manimpango-remove-manim-dep.patch
new file mode 100644
index 0000000000..579c2302d8

Checking patch gnu/packages/patches/python-manimpango-remove-manim-dep.patch...
Applied patch gnu/packages/patches/python-manimpango-remove-manim-dep.patch cleanly.

skipping https://yhetil.org/guix-patches/20210915152519.25572-11-daniel.meissner-i4k@ruhr-uni-bochum.de/ for 579c2302d8
skipping https://yhetil.org/guix-patches/20220101235155.5754-10-daniel.meissner-i4k@ruhr-uni-bochum.de/ for 579c2302d8
index at:
100644 579c2302d853b4b56e70ea6fd118d8075cf5f9ef	gnu/packages/patches/python-manimpango-remove-manim-dep.patch

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).