aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Victorovich <yuri@FreeBSD.org>2023-01-20 16:09:03 +0000
committerYuri Victorovich <yuri@FreeBSD.org>2023-01-20 18:43:32 +0000
commit4d86c9e4eed18955d057c752ebd1c444fc0a64a8 (patch)
tree42ddfca1ceca6f6a24e0fcd76723ea48e7855446
parent62fd95493e22bd6cb7dc9884e92a479cd76ea8d6 (diff)
downloadports-4d86c9e4eed18955d057c752ebd1c444fc0a64a8.tar.gz
ports-4d86c9e4eed18955d057c752ebd1c444fc0a64a8.zip
graphics/py-ManimPango: New port: Bindings for Pango for use with Manim
-rw-r--r--graphics/Makefile1
-rw-r--r--graphics/py-ManimPango/Makefile27
-rw-r--r--graphics/py-ManimPango/distinfo3
-rw-r--r--graphics/py-ManimPango/files/isoline_demo.py133
-rw-r--r--graphics/py-ManimPango/pkg-descr2
5 files changed, 166 insertions, 0 deletions
diff --git a/graphics/Makefile b/graphics/Makefile
index 92f03b93da2f..bb42c7d2230f 100644
--- a/graphics/Makefile
+++ b/graphics/Makefile
@@ -833,6 +833,7 @@
SUBDIR += proj-data
SUBDIR += pstoedit
SUBDIR += ptex
+ SUBDIR += py-ManimPango
SUBDIR += py-OWSLib
SUBDIR += py-PyOpenGL
SUBDIR += py-PyOpenGL-accelerate
diff --git a/graphics/py-ManimPango/Makefile b/graphics/py-ManimPango/Makefile
new file mode 100644
index 000000000000..9fbd35f2c906
--- /dev/null
+++ b/graphics/py-ManimPango/Makefile
@@ -0,0 +1,27 @@
+PORTNAME= ManimPango
+DISTVERSION= 0.4.3
+CATEGORIES= graphics
+MASTER_SITES= PYPI
+PKGNAMEPREFIX= ${PYTHON_PKGNAMEPREFIX}
+
+MAINTAINER= yuri@FreeBSD.org
+COMMENT= Bindings for Pango for use with Manim
+WWW= https://manimpango.manim.community/en/latest/
+
+LICENSE= MIT
+
+LIB_DEPENDS= libfontconfig.so:x11-fonts/fontconfig \
+ libfreetype.so:print/freetype2 \
+ libharfbuzz.so:print/harfbuzz
+
+USES= gettext-runtime gnome pkgconfig python
+USE_PYTHON= distutils cython autoplist pytest # tests fail to import manimpango, see https://github.com/ManimCommunity/ManimPango/issues/99
+USE_GNOME= cairo glib20 pango
+
+TEST_ENV= ${MAKE_ENV} PYTHONPATH=${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}
+TEST_WRKSRC= ${WRKSRC}/tests
+
+post-install:
+ @${STRIP_CMD} ${STAGEDIR}${PYTHON_SITELIBDIR}/manimpango/*${PYTHON_EXT_SUFFIX}.so
+
+.include <bsd.port.mk>
diff --git a/graphics/py-ManimPango/distinfo b/graphics/py-ManimPango/distinfo
new file mode 100644
index 000000000000..f0c0432a95d9
--- /dev/null
+++ b/graphics/py-ManimPango/distinfo
@@ -0,0 +1,3 @@
+TIMESTAMP = 1674237306
+SHA256 (ManimPango-0.4.3.tar.gz) = 732f1cb98bcc122c0dee93bb54966aa595f90730e5096ad6d86602cf4ba1a103
+SIZE (ManimPango-0.4.3.tar.gz) = 4076306
diff --git a/graphics/py-ManimPango/files/isoline_demo.py b/graphics/py-ManimPango/files/isoline_demo.py
new file mode 100644
index 000000000000..53bd1a51da61
--- /dev/null
+++ b/graphics/py-ManimPango/files/isoline_demo.py
@@ -0,0 +1,133 @@
+# from examples/isoline_demo.py
+
+""" Code for demo-ing and experimentation. Prepare for a mess """
+from isosurfaces import plot_isoline
+from isosurfaces.isoline import (
+ Cell,
+ build_tree,
+ Triangulator,
+ CurveTracer,
+)
+import numpy as np
+import cairo
+
+min_depth = 5
+pmin = np.array([-8, -6])
+pmax = np.array([8, 6])
+
+
+def f(x, y):
+ return y * (x - y) ** 2 - 4 * x - 8
+
+
+# Here we directly use plot_implicit internals in order to see the quadtree
+fn = lambda u: f(u[0], u[1])
+tol = (pmax - pmin) / 1000
+quadtree = build_tree(2, fn, pmin, pmax, min_depth, 5000, tol)
+triangles = Triangulator(quadtree, fn).triangulate()
+curves = CurveTracer(triangles, fn, tol).trace()
+
+
+def g(x, y):
+ return x ** 3 - x - y ** 2
+
+
+# Typical usage
+curves1 = plot_isoline(
+ lambda u: g(u[0], u[1]),
+ pmin,
+ pmax,
+ min_depth=4,
+ max_quads=1000,
+)
+
+
+def h(x, y):
+ return x ** 4 + y ** 4 - np.sin(x) - np.sin(4 * y)
+
+
+curves2 = plot_isoline(lambda u: h(u[0], u[1]), pmin, pmax, 4, 1000)
+
+
+WIDTH = 640
+HEIGHT = 480
+
+
+def setup_context(c):
+ # reflection to change math units to screen units
+ scale = min(WIDTH / (pmax[0] - pmin[0]), HEIGHT / (pmax[1] - pmin[1]))
+ c.scale(scale, -scale)
+ c.translate(WIDTH / scale / 2, -HEIGHT / scale / 2)
+ c.set_line_join(cairo.LINE_JOIN_BEVEL)
+
+
+def draw_axes(c):
+ c.save()
+ c.set_line_width(0.1)
+ c.move_to(0, -100)
+ c.line_to(0, 100)
+ c.stroke()
+ c.move_to(-100, 0)
+ c.line_to(100, 0)
+ c.stroke()
+ c.restore()
+
+
+def draw_quad(c, quad: Cell):
+ width = 0
+ if quad.depth <= min_depth:
+ width = 0.02
+ elif quad.depth == min_depth + 1:
+ width = 0.01
+ else:
+ width = 0.005
+ c.set_line_width(0.5 * width)
+
+ if quad.children:
+ c.move_to(*((quad.vertices[0].pos + quad.vertices[1].pos) / 2))
+ c.line_to(*((quad.vertices[2].pos + quad.vertices[3].pos) / 2))
+ c.move_to(*((quad.vertices[0].pos + quad.vertices[2].pos) / 2))
+ c.line_to(*((quad.vertices[1].pos + quad.vertices[3].pos) / 2))
+ c.stroke()
+ for child in quad.children:
+ draw_quad(c, child)
+
+
+def draw_quads(c):
+ c.save()
+ draw_quad(c, quadtree)
+ c.restore()
+
+
+def draw_bg(c):
+ c.save()
+ c.set_source_rgb(1, 1, 1)
+ c.paint()
+ c.restore()
+
+
+def draw_curves(c, curves_list, rgb):
+ print(
+ "drawing", sum(map(len, curves_list)), "segments in", len(curves_list), "curves"
+ )
+ c.set_source_rgb(*rgb)
+ # draw curves
+ c.save()
+ c.set_line_width(0.03)
+ for curve in curves_list:
+ c.move_to(*curve[0])
+ for v in curve:
+ c.line_to(*v)
+ c.stroke()
+ c.restore()
+
+
+with cairo.SVGSurface("demo.svg", WIDTH, HEIGHT) as surface:
+ c = cairo.Context(surface)
+ setup_context(c)
+ draw_bg(c)
+ draw_axes(c)
+ # draw_quads(c)
+ draw_curves(c, curves, [0.1, 0.1, 0.8])
+ draw_curves(c, curves1, [0.8, 0.1, 0.1])
+ draw_curves(c, curves2, [0.1, 0.6, 0.1])
diff --git a/graphics/py-ManimPango/pkg-descr b/graphics/py-ManimPango/pkg-descr
new file mode 100644
index 000000000000..13c88e438469
--- /dev/null
+++ b/graphics/py-ManimPango/pkg-descr
@@ -0,0 +1,2 @@
+ManimPango is a C binding for Pango using Cython, which is internally used in
+Manim to render (non-LaTeX) text.