{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Font indexing\n\nThis example shows how the font tables relate to one another.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import os\n\nimport matplotlib\nfrom matplotlib.ft2font import FT2Font, Kerning\n\nfont = FT2Font(\n    os.path.join(matplotlib.get_data_path(), 'fonts/ttf/DejaVuSans.ttf'))\nfont.set_charmap(0)\n\ncodes = font.get_charmap().items()\n\n# make a charname to charcode and glyphind dictionary\ncoded = {}\nglyphd = {}\nfor ccode, glyphind in codes:\n    name = font.get_glyph_name(glyphind)\n    coded[name] = ccode\n    glyphd[name] = glyphind\n    # print(glyphind, ccode, hex(int(ccode)), name)\n\ncode = coded['A']\nglyph = font.load_char(code)\nprint(glyph.bbox)\nprint(glyphd['A'], glyphd['V'], coded['A'], coded['V'])\nprint('AV', font.get_kerning(glyphd['A'], glyphd['V'], Kerning.DEFAULT))\nprint('AV', font.get_kerning(glyphd['A'], glyphd['V'], Kerning.UNFITTED))\nprint('AV', font.get_kerning(glyphd['A'], glyphd['V'], Kerning.UNSCALED))\nprint('AT', font.get_kerning(glyphd['A'], glyphd['T'], Kerning.UNSCALED))"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.14.7"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}