{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## name-viewer.ipynb\n",
    "\n",
    "### Usage\n",
    "\n",
    "1. Install `jupyter`, `plotly`, `fonttools` dependencies with pip\n",
    "2. Modify the `FONT_PATH` setting in the Python source block below by clicking next to it and typing a new path in your web browser window\n",
    "3. Execute the block of Python source by selecting the code block below and clicking the \"Run\" button above\n",
    "4. Repeat from step 2 with modified font paths to view tables in other fonts\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import plotly as py\n",
    "import plotly.graph_objs as go\n",
    "\n",
    "from fontTools.ttLib import TTFont\n",
    "\n",
    "py.offline.init_notebook_mode(connected=True)\n",
    "\n",
    "# EDIT HERE ------------------------------------------------------\n",
    "#\n",
    "# Path to font file\n",
    "FONT_PATH = \"path/to/font.ttf\"\n",
    "#\n",
    "# Table height\n",
    "#    - adjust for the length of output from the font file\n",
    "HEIGHT = 700\n",
    "#\n",
    "# END EDIT -------------------------------------------------------\n",
    "\n",
    "record_list = []\n",
    "nameID_list = []\n",
    "ppelangID_list = []\n",
    "value_list = []\n",
    "\n",
    "tt = TTFont(FONT_PATH)\n",
    "namerecord_list = tt[\"name\"].names\n",
    "\n",
    "for record in namerecord_list:\n",
    "    nameID_list.append(record.nameID)\n",
    "    ppelangID_list.append(\"{} {} {}\".format(record.platformID, \n",
    "                                            record.platEncID, \n",
    "                                            record.langID))\n",
    "    value_list.append(\"{}\".format(record.string.decode('utf-8').strip()))\n",
    "    \n",
    "\n",
    "record_list.append(nameID_list)\n",
    "record_list.append(ppelangID_list)\n",
    "record_list.append(value_list)\n",
    "\n",
    "\n",
    "trace0 = go.Table(\n",
    "  columnorder = [1,2,3],\n",
    "  columnwidth = [80,80,400],\n",
    "  header = dict(\n",
    "    values = [['<b>nameID</b>'],\n",
    "              ['<b>p-pE-lang</b>'],\n",
    "              ['<b>Value</b>']\n",
    "             ],\n",
    "    line = dict(color = '#506784'),\n",
    "    fill = dict(color = '#FFDE00'),\n",
    "    align = ['center','center', 'center'],\n",
    "    font = dict(color = 'black', size = 16),\n",
    "  ),\n",
    "  cells = dict(\n",
    "    values = record_list,\n",
    "    line = dict(color = '#506784'),\n",
    "    fill = dict(color = ['#000000', 'white']),\n",
    "    align = ['center', 'center', 'left'],\n",
    "    font = dict(color = ['#F8F8F5', '#000000', '#000000'], size = 14),\n",
    "    height = 30,\n",
    "    ))\n",
    "\n",
    "data1 = [trace0]\n",
    "\n",
    "layout1 = go.Layout(\n",
    "    autosize=True,\n",
    "    height=HEIGHT,\n",
    ")\n",
    "\n",
    "fig1 = dict(data=data1, layout=layout1)\n",
    "py.offline.iplot(fig1)"
   ]
  }
 ],
 "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.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}