.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/validation/validate_text_size.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__gallery_validation_validate_text_size.py: Text size ========= This example shows text with different sizes. * On the left the text is in screen space. The size must match a reference, e.g. from text with the same font in a browser. * On the right the text is in world space. The text must sit snugly with its baseline on the bottom line. .. GENERATED FROM PYTHON SOURCE LINES 12-114 .. image-sg:: /_gallery/validation/images/sphx_glr_validate_text_size_001.webp :alt: validate text size :srcset: /_gallery/validation/images/sphx_glr_validate_text_size_001.webp :class: sphx-glr-single-img .. code-block:: Python from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx import pylinalg as la renderer = gfx.renderers.WgpuRenderer(RenderCanvas()) scene = gfx.Scene() scene.add(gfx.Background.from_color("#000")) obj0 = gfx.Text( text="Screen | World", font_size=80, screen_space=True, anchor="bottom-center", material=gfx.TextMaterial( color="#aea", weight_offset=100, outline_color="#484", outline_thickness=0.2, aa=False, ), ) obj0.local.position = (0, 50, 0) obj1 = gfx.Text( text="Lorem ipsum 40!", font_size=40, anchor="baseline-right", screen_space=True, material=gfx.TextMaterial(color="#0ff", aa=False), ) obj1.local.position = (-10, 0, 0) obj2 = gfx.Text( text="Lorem ipsum 40!", font_size=40, anchor="baseline-left", screen_space=False, material=gfx.TextMaterial(color="#0ff", aa=False), ) obj2.local.position = (10, 0, 0) obj3 = gfx.Text( text="Lorem ipsum 20 !", font_size=40, anchor="baseline-right", screen_space=True, material=gfx.TextMaterial(color="#0ff", aa=False), ) obj3.local.position = (-10, -50, 0) obj3.local.scale = (0.5, 0.5, 0.5) obj4 = gfx.Text( text="Lorem ipsum 20!", font_size=40, anchor="baseline-left", screen_space=False, material=gfx.TextMaterial(color="#0ff", aa=False), ) obj4.local.position = (10, -50, 0) obj4.local.scale = (0.5, 0.5, 0.5) obj5 = gfx.Text( text="Rotated", font_size=20, anchor="baseline-right", screen_space=True, material=gfx.TextMaterial(color="#0ff", aa=False), ) obj5.local.position = (-10, -100, 0) obj5.local.rotation = la.quat_from_axis_angle((0, 0, 1), 0.2) obj6 = gfx.Text( text="Rotated", font_size=20, anchor="baseline-left", screen_space=False, material=gfx.TextMaterial(color="#0ff", aa=False), ) obj6.local.position = (10, -100, 0) obj6.local.rotation = la.quat_from_axis_angle((0, 0, 1), -0.2) line = gfx.Line( gfx.Geometry(positions=[(0, 0, 0), (900, 0, 0), (0, 40, 0), (900, 40, 0)]), gfx.LineSegmentMaterial(color="green", aa=False), ) scene.add(line, obj0, obj1, obj2, obj3, obj4, obj5, obj6) camera = gfx.OrthographicCamera() camera.show_rect(-325, 325, -200, 200) controller = gfx.OrbitController(camera, register_events=renderer) renderer.request_draw(lambda: renderer.render(scene, camera)) if __name__ == "__main__": print(__doc__) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.224 seconds) .. _sphx_glr_download__gallery_validation_validate_text_size.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: validate_text_size.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: validate_text_size.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: validate_text_size.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_ .. only:: html Interactive example ------------------- Try this example in your browser using Pyodide. Might not work with all examples and all devices. Check the output and your browser's console for details. .. raw:: html