
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/misc/font_indexing.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_misc_font_indexing.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_misc_font_indexing.py:


=============
Font indexing
=============

This example shows how the font tables relate to one another.

.. GENERATED FROM PYTHON SOURCE LINES 8-37




.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    (6, 0, 519, 576)
    36 57 65 86
    AV -48
    AV -49
    AV -16
    AT -19






|

.. code-block:: Python


    import os

    import matplotlib
    from matplotlib.ft2font import FT2Font, Kerning

    font = FT2Font(
        os.path.join(matplotlib.get_data_path(), 'fonts/ttf/DejaVuSans.ttf'))
    font.set_charmap(0)

    codes = font.get_charmap().items()

    # make a charname to charcode and glyphind dictionary
    coded = {}
    glyphd = {}
    for ccode, glyphind in codes:
        name = font.get_glyph_name(glyphind)
        coded[name] = ccode
        glyphd[name] = glyphind
        # print(glyphind, ccode, hex(int(ccode)), name)

    code = coded['A']
    glyph = font.load_char(code)
    print(glyph.bbox)
    print(glyphd['A'], glyphd['V'], coded['A'], coded['V'])
    print('AV', font.get_kerning(glyphd['A'], glyphd['V'], Kerning.DEFAULT))
    print('AV', font.get_kerning(glyphd['A'], glyphd['V'], Kerning.UNFITTED))
    print('AV', font.get_kerning(glyphd['A'], glyphd['V'], Kerning.UNSCALED))
    print('AT', font.get_kerning(glyphd['A'], glyphd['T'], Kerning.UNSCALED))


.. _sphx_glr_download_gallery_misc_font_indexing.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: font_indexing.ipynb <font_indexing.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: font_indexing.py <font_indexing.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: font_indexing.zip <font_indexing.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
