fonts3d.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import os
  4. from vedo import printc, Text2D, Text3D, show, Plotter
  5. from vedo import fonts, fonts_path, settings
  6. import numpy as np
  7. ################################################################################## 2D
  8. inred = Text2D(
  9. "°monospaced fonts are marked in red", c="r5", pos="bottom-center", font="VictorMono"
  10. )
  11. acts2d = [inred]
  12. txt = "The quick fox jumps over the lazy dog. 1234567890 αβγδεθλμνπστφψω"
  13. for i, f in enumerate(fonts):
  14. bg = None
  15. if f in ["Calco", "Glasgo", "SmartCouric", "VictorMono"]:
  16. bg = "red5"
  17. t = Text2D(f"{f}: {txt}", pos=(0.015, 1 - (i + 3) * 0.06), font=f, s=1.3, c="k", bg=bg)
  18. acts2d.append(t)
  19. acts2d.append(Text2D("List of built-in fonts", pos="top-center", bg="k", s=1.3))
  20. plt0a = show(acts2d, bg2="cornsilk", size=(1300, 800), interactive=False)
  21. ## online fonts:
  22. acts2d = []
  23. i = 0
  24. for key, props in sorted(settings.font_parameters.items()):
  25. if props["islocal"]:
  26. continue
  27. if key in ("Justino2", "Justino3"):
  28. continue
  29. bg = None
  30. if props["mono"]:
  31. bg = "red5"
  32. t = Text2D(f"{key}: {txt}", pos=(0.015, 1 - (i + 2) * 0.03), font=key, c="k", bg=bg)
  33. acts2d.append(t)
  34. i += 1
  35. plt0b = show(
  36. acts2d,
  37. Text2D("Additional fonts (https://vedo.embl.es/fonts)", pos="top-center", bg="k"),
  38. bg2="lb",
  39. size=(1300, 1350),
  40. pos=(1200, 0),
  41. new=True,
  42. )
  43. ################################################################################ printout
  44. for font in fonts:
  45. printc(font + " - available characters:", " " * 25, bold=1, invert=1)
  46. fontfile = os.path.join(fonts_path, font + ".npz")
  47. font_meshes = np.load(fontfile, allow_pickle=True)["font"][0]
  48. for k in font_meshes.keys():
  49. printc(k, end=" ")
  50. print()
  51. printc("\n(use the above to copy&paste any char into your python script!)", italic=1)
  52. printc("Symbols ~ ^ _ are reserved modifiers:", italic=1)
  53. printc(" use ~ to add a short space, 1/4 of the default size,", italic=1)
  54. printc(" use ^ and _ to start up/sub scripting, space terminates them.\n", italic=1)
  55. ################################################################################## 3D
  56. # Symbols ~ ^ _ are reserved modifiers:
  57. # use ~ to add a short space, 1/4 of the default size,
  58. # use ^ and _ to start up/sub scripting, a space terminates them.
  59. txt = """The quick fox jumps over the lazy dog.
  60. Symbols: !@#$%&*()+=-{}[]:;|<>?/:euro1234567890
  61. Units: :delta=0.25E-03 ~μm, T_sea ~=~5.3~±0.7~:circC
  62. LaTeX: :nabla:dotE=~4:pi~:rho, :nabla:timesE=~-1/c~~:partialB/:partialt
  63. ih~:partial/:partialt~:Psi = [-h^2 /2m:nabla^2 + V(r,t)]~:Psi(r,t)
  64. :DeltaE~=~h:nu, y = :Sigma_n ~A_n cos(:omega_n t+:delta_n ) sin(k_n x)
  65. :intx:dot~dx = :onehalf x:^2 + const.
  66. d^2 x^:mu + :Gamma^:mu_:alpha:beta ~dx^:alpha ~dx^:beta = 0
  67. -∇:^2u(x) = f(x) in Ω, u(x)~=~u_D (x) in :partial:Omega
  68. """
  69. plt = Plotter(N=4, pos=(300, 0), size=(1600, 950))
  70. cam = dict(
  71. pos=(3.99e5, 8.51e3, 6.47e5),
  72. focal_point=(2.46e5, 1.16e5, -9.24e3),
  73. viewup=(-0.0591, 0.983, 0.175),
  74. distance=6.82e5,
  75. clipping_range=(5.26e5, 8.92e5),
  76. )
  77. for i, fnt in enumerate(["Kanopus", "Normografo", "Theemim", "VictorMono"]):
  78. t = Text3D(txt, font=fnt, italic=0).c("darkblue").scale(12300)
  79. plt.at(i)
  80. plt.show(
  81. t,
  82. Text2D("Font: " + fnt, font=fnt, bg="r"),
  83. axes=dict(
  84. xtitle="my units for L_x (:mum)",
  85. ytitle="my Y-axis with:na long description",
  86. title_font=fnt,
  87. label_font=fnt,
  88. digits=2,
  89. ),
  90. camera=cam,
  91. resetcam=not bool(i),
  92. )
  93. plt.interactive().close()
  94. plt0b.close()
  95. plt0a.close()