File: fonts3d.py

package info (click to toggle)
vedo 2025.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,404 kB
  • sloc: python: 64,792; javascript: 1,932; xml: 437; sh: 139; makefile: 6
file content (107 lines) | stat: -rw-r--r-- 3,719 bytes parent folder | download
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
from vedo import printc, Text2D, Text3D, show, Plotter
from vedo import fonts, fonts_path, settings
import numpy as np

################################################################################## 2D
inred = Text2D(
    "°monospaced fonts are marked in red", c="r5", pos="bottom-center", font="VictorMono"
)
acts2d = [inred]

txt = "The quick fox jumps over the lazy dog. 1234567890 αβγδεθλμνπστφψω"
for i, f in enumerate(fonts):
    bg = None
    if f in ["Calco", "Glasgo", "SmartCouric", "VictorMono"]:
        bg = "red5"
    t = Text2D(f"{f}: {txt}", pos=(0.015, 1 - (i + 3) * 0.06), font=f, s=1.3, c="k", bg=bg)
    acts2d.append(t)

acts2d.append(Text2D("List of built-in fonts", pos="top-center", bg="k", s=1.3))
plt0a = show(acts2d, bg2="cornsilk", size=(1300, 800), interactive=False)

## online fonts:
acts2d = []
i = 0
for key, props in sorted(settings.font_parameters.items()):
    if props["islocal"]:
        continue
    if key in ("Justino2", "Justino3"):
        continue
    bg = None
    if props["mono"]:
        bg = "red5"
    t = Text2D(f"{key}: {txt}", pos=(0.015, 1 - (i + 2) * 0.03), font=key, c="k", bg=bg)
    acts2d.append(t)
    i += 1
plt0b = show(
    acts2d,
    Text2D("Additional fonts (https://vedo.embl.es/fonts)", pos="top-center", bg="k"),
    bg2="lb",
    size=(1300, 1350),
    pos=(1200, 0),
    new=True,
)

################################################################################ printout
for font in fonts:
    printc(font + " - available characters:", " " * 25, bold=1, invert=1)
    fontfile = os.path.join(fonts_path, font + ".npz")
    font_meshes = np.load(fontfile, allow_pickle=True)["font"][0]
    for k in font_meshes.keys():
        printc(k, end=" ")
    print()

printc("\n(use the above to copy&paste any char into your python script!)", italic=1)
printc("Symbols ~ ^ _ are reserved modifiers:", italic=1)
printc(" use ~ to add a short space, 1/4 of the default size,", italic=1)
printc(" use ^ and _ to start up/sub scripting, space terminates them.\n", italic=1)


################################################################################## 3D
# Symbols ~ ^ _ are reserved modifiers:
#  use ~ to add a short space, 1/4 of the default size,
#  use ^ and _ to start up/sub scripting, a space terminates them.
txt = """The quick fox jumps over the lazy dog.
Symbols: !@#$%&*()+=-{}[]:;|<>?/:euro1234567890
Units:  :delta=0.25E-03 ~μm, T_sea ~=~5.3~±0.7~:circC
LaTeX: :nabla:dotE=~4:pi~:rho, :nabla:timesE=~-1/c~~:partialB/:partialt
       ih~:partial/:partialt~:Psi = [-h^2 /2m:nabla^2  + V(r,t)]~:Psi(r,t)
       :DeltaE~=~h:nu, y = :Sigma_n ~A_n cos(:omega_n t+:delta_n ) sin(k_n x)
       :intx:dot~dx = :onehalf x:^2 + const.
       d^2 x^:mu  + :Gamma^:mu_:alpha:beta ~dx^:alpha ~dx^:beta  = 0
       -∇:^2u(x) = f(x) in Ω, u(x)~=~u_D (x) in :partial:Omega
"""

plt = Plotter(N=4, pos=(300, 0), size=(1600, 950))

cam = dict(
    pos=(3.99e5, 8.51e3, 6.47e5),
    focal_point=(2.46e5, 1.16e5, -9.24e3),
    viewup=(-0.0591, 0.983, 0.175),
    distance=6.82e5,
    clipping_range=(5.26e5, 8.92e5),
)

for i, fnt in enumerate(["Kanopus", "Normografo", "Theemim", "VictorMono"]):
    t = Text3D(txt, font=fnt, italic=0).c("darkblue").scale(12300)
    plt.at(i)
    plt.show(
        t,
        Text2D("Font: " + fnt, font=fnt, bg="r"),
        axes=dict(
            xtitle="my units for L_x  (:mum)",
            ytitle="my Y-axis with:na long description",
            title_font=fnt,
            label_font=fnt,
            digits=2,
        ),
        camera=cam,
        resetcam=not bool(i),
    )
plt.interactive().close()

plt0b.close()
plt0a.close()