Skip to content

Commit 5d4dfcf

Browse files
authored
Merge pull request #471 from naveen521kk/pango-text
Add Pango Renderer
2 parents 07343cc + 4f09716 commit 5d4dfcf

File tree

12 files changed

+705
-13
lines changed

12 files changed

+705
-13
lines changed

.github/manimdependency.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"windows": {
3-
"ffmpeg": "https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-4.3.1-2020-09-21-full_build.zip"
3+
"ffmpeg": "https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-4.3.1-2020-09-21-full_build.zip",
4+
"pango": "v0.1.0"
45
}
5-
}
6+
}

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ jobs:
6060
brew cask install basictex
6161
eval "$(/usr/libexec/path_helper -s)"
6262
sudo tlmgr update --self
63+
brew install pkg-config
64+
brew install libffi
65+
brew install pango
66+
brew install glib
6367
sudo tlmgr install standalone preview doublestroke relsize fundus-calligra wasysym physics dvisvgm.x86_64-darwin dvisvgm rsfs wasy cm-super
6468
echo "::add-path::$HOME/.poetry/bin"
6569
echo "::set-env name=PATH::$PATH"
@@ -76,6 +80,7 @@ jobs:
7680
if: runner.os == 'Windows' && steps.cache-windows.outputs.cache-hit != 'true'
7781
run: |
7882
$ffmpegUrl = python -c "import json;print(json.load(open('.github/manimdependency.json'))['windows']['ffmpeg'])"
83+
$pangoVersion = python -c "import json;print(json.load(open('.github/manimdependency.json'))['windows']['pango'])"
7984
$OriPath = $env:PATH
8085
echo "Install Tinytex"
8186
Invoke-WebRequest "https://ci.appveyor.com/api/projects/yihui/tinytex/artifacts/TinyTeX.zip?job=image:%20Visual%20Studio%202019" -O "$($env:TMP)\TinyTex.zip"
@@ -88,12 +93,16 @@ jobs:
8893
Invoke-WebRequest "$ffmpegUrl" -O "$($env:TMP)\ffmpeg.zip"
8994
7z x "$($env:TMP)\ffmpeg.zip" -o"$($PWD)\ManimCache"
9095
Move-Item "ManimCache\ffmpeg-*" "ManimCache\FFmpeg"
96+
Invoke-WebRequest "https://github.com/ManimCommunity/manim-windows/releases/download/$($pangoVersion)/pango-windows-binaires-x64.zip" -O "$($env:TMP)\Pango.zip"
97+
mkdir "$($PWD)\ManimCache\Pango"
98+
7z x "$($env:TMP)\Pango.zip" -o"$($PWD)\ManimCache\Pango"
9199
92100
- name: Add Windows dependecies to path
93101
if: runner.os == 'Windows'
94102
run: |
95103
$env:Path += ";" + "$($PWD)\ManimCache\FFmpeg\bin"
96104
$env:Path += ";" + "$($PWD)\ManimCache\LatexWindows\TinyTeX\bin\win32"
105+
$env:Path += ";" + "$($PWD)\ManimCache\Pango\pango"
97106
$env:Path = "$env:USERPROFILE\.poetry\bin;$($env:PATH)"
98107
echo "::set-env name=Path::$env:Path"
99108

docs/source/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Mobjects, Scenes, and Animations
6666
#. :code:`VGroup` now supports printing the class names of contained mobjects and :code:`VDict` supports printing the internal dict of mobjects
6767
#. :code:`Scene` now renders when :code:`Scene.render()` is called rather than upon instantiation.
6868
#. :code:`ValueTracker` now supports increment using the `+=` operator (in addition to the already existing `increment_value` method)
69+
#. Add :class:`PangoText` for rendering texts using Pango.
6970

7071

7172
Documentation

docs/source/conf.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212

1313
import os
14+
import subprocess
1415
import sys
1516
from distutils.sysconfig import get_python_lib
1617

@@ -19,8 +20,12 @@
1920

2021

2122
if os.environ.get("READTHEDOCS") == "True":
22-
# we need to add ffmpeg to the path
2323
site_path = get_python_lib()
24+
# bindings for pangocffi, cairocffi, pangocairocffi need to be generated
25+
subprocess.run(["python", "pangocffi/ffi_build.py"], cwd=site_path)
26+
subprocess.run(["python", "cairocffi/ffi_build.py"], cwd=site_path)
27+
subprocess.run(["python", "pangocairocffi/ffi_build.py"], cwd=site_path)
28+
# we need to add ffmpeg to the path
2429
ffmpeg_path = os.path.join(site_path, "imageio_ffmpeg", "binaries")
2530
# the included binary is named ffmpeg-linux..., create a symlink
2631
[ffmpeg_bin] = [

docs/source/installation/mac.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ To install cairo:
1515
1616
brew install cairo
1717
18+
To install Pango and it dependencies:
19+
20+
.. code-block:: bash
21+
22+
brew install pkg-config
23+
brew install libffi
24+
brew install pango
25+
brew install glib
26+
27+
1828
To install ffmpeg:
1929

2030
.. code-block:: bash

docs/source/installation/win.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,32 @@ You can install manim very easily using chocolatey, by typing the following comm
1818
1919
And then you can skip all the other steps and move to installing :ref:`latex-installation`.
2020

21+
Pango Installation
22+
******************
23+
24+
These steps would get you `libpango-1.0-0.dll` to your ``PATH`` along
25+
with other dependencies. You may probably have them before itself if
26+
you have installed `GTK <https://www.gtk.org/>`_ or any ``GTK``
27+
based app like emacs. If you have it you can just add it to your
28+
path and skip these steps.
29+
30+
1. Go to `Release Page
31+
<https://github.com/ManimCommunity/manim-windows/releases/latest>`_
32+
and download the one according to your PC architechture.
33+
34+
.. important:: Please download the ``zip`` file for architechture of python installed.
35+
It is possible to have installed ``x86`` python installed on ``x64`` PC.
36+
37+
2. Extract the zip file using File Explorer or 7z to the loaction you want to install.
38+
39+
.. code-block:: bash
40+
41+
7z x pango-windows-binaires-x64.zip -oC:\Pango
42+
43+
3. Finally, add it `PATH variable
44+
<https://www.computerhope.com/issues/ch000549.htm>`_.
45+
46+
2147
FFmpeg installation
2248
*******************
2349

example_scenes/pangoText.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from manim import *
2+
3+
4+
class PangoRendering(Scene):
5+
CONFIG = {"font": "sans-serif"}
6+
7+
def construct(self):
8+
morning = PangoText("வணக்கம்", font="sans-serif")
9+
self.play(Write(morning))
10+
self.wait(3)
11+
self.clear()
12+
chin = PangoText(
13+
"見 角 言 谷 辛 辰 辵 邑 酉 釆 里!", t2c={"見 角 言": BLUE}
14+
) # works same as ``Text``.
15+
self.play(Write(chin))
16+
self.wait(2)
17+
mess = PangoText("Multi-Language", style=BOLD)
18+
self.play(Transform(chin, mess))
19+
self.wait(2)
20+
self.clear()
21+
russ = PangoText("Здравствуйте मस नम म ", font="sans-serif")
22+
self.play(Write(russ))
23+
self.wait(2)
24+
self.clear()
25+
hin = PangoText("नमस्ते", font="sans-serif")
26+
self.play(Write(hin))
27+
self.wait(2)
28+
self.clear()
29+
arb = PangoText("صباح الخير ", font="sans-serif")
30+
self.play(Write(arb))
31+
self.wait(3)
32+
self.clear()
33+
arb = PangoText(
34+
"صباح الخير \n تشرفت بمقابلتك", font="sans-serif"
35+
) # don't mix RTL and LTR languages nothing shows up then ;-)
36+
self.play(Write(arb))
37+
self.wait(3)
38+
self.clear()
39+
jap = PangoText("臂猿「黛比」帶著孩子", font="sans-serif")
40+
self.play(Write(jap))
41+
self.wait(3)

manim/constants.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,23 @@ class MyText(Text):
2929
There are no scenes inside that module
3030
"""
3131

32-
# Cairo stuff
32+
# Cairo and Pango stuff
3333
NORMAL = "NORMAL"
3434
ITALIC = "ITALIC"
3535
OBLIQUE = "OBLIQUE"
3636
BOLD = "BOLD"
37+
# Only for Pango from below
38+
THIN = "THIN"
39+
ULTRALIGHT = "ULTRALIGHT"
40+
LIGHT = "LIGHT"
41+
SEMILIGHT = "SEMILIGHT"
42+
BOOK = "BOOK"
43+
MEDIUM = "MEDIUM"
44+
SEMIBOLD = "SEMIBOLD"
45+
ULTRABOLD = "ULTRABOLD"
46+
HEAVY = "HEAVY"
47+
ULTRAHEAVY = "ULTRAHEAVY"
48+
3749

3850
# Geometry: directions
3951
ORIGIN = np.array((0.0, 0.0, 0.0))

0 commit comments

Comments
 (0)