1{ 2 "cells": [ 3 { 4 "cell_type": "markdown", 5 "metadata": {}, 6 "source": [ 7 "## name-viewer.ipynb\n", 8 "\n", 9 "### Usage\n", 10 "\n", 11 "1. Install `jupyter`, `plotly`, `fonttools` dependencies with pip\n", 12 "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", 13 "3. Execute the block of Python source by selecting the code block below and clicking the \"Run\" button above\n", 14 "4. Repeat from step 2 with modified font paths to view tables in other fonts\n" 15 ] 16 }, 17 { 18 "cell_type": "code", 19 "execution_count": null, 20 "metadata": {}, 21 "outputs": [], 22 "source": [ 23 "import plotly as py\n", 24 "import plotly.graph_objs as go\n", 25 "\n", 26 "from fontTools.ttLib import TTFont\n", 27 "\n", 28 "py.offline.init_notebook_mode(connected=True)\n", 29 "\n", 30 "# EDIT HERE ------------------------------------------------------\n", 31 "#\n", 32 "# Path to font file\n", 33 "FONT_PATH = \"path/to/font.ttf\"\n", 34 "#\n", 35 "# Table height\n", 36 "# - adjust for the length of output from the font file\n", 37 "HEIGHT = 700\n", 38 "#\n", 39 "# END EDIT -------------------------------------------------------\n", 40 "\n", 41 "record_list = []\n", 42 "nameID_list = []\n", 43 "ppelangID_list = []\n", 44 "value_list = []\n", 45 "\n", 46 "tt = TTFont(FONT_PATH)\n", 47 "namerecord_list = tt[\"name\"].names\n", 48 "\n", 49 "for record in namerecord_list:\n", 50 " nameID_list.append(record.nameID)\n", 51 " ppelangID_list.append(\"{} {} {}\".format(record.platformID, \n", 52 " record.platEncID, \n", 53 " record.langID))\n", 54 " value_list.append(\"{}\".format(record.string.decode('utf-8').strip()))\n", 55 " \n", 56 "\n", 57 "record_list.append(nameID_list)\n", 58 "record_list.append(ppelangID_list)\n", 59 "record_list.append(value_list)\n", 60 "\n", 61 "\n", 62 "trace0 = go.Table(\n", 63 " columnorder = [1,2,3],\n", 64 " columnwidth = [80,80,400],\n", 65 " header = dict(\n", 66 " values = [['<b>nameID</b>'],\n", 67 " ['<b>p-pE-lang</b>'],\n", 68 " ['<b>Value</b>']\n", 69 " ],\n", 70 " line = dict(color = '#506784'),\n", 71 " fill = dict(color = '#FFDE00'),\n", 72 " align = ['center','center', 'center'],\n", 73 " font = dict(color = 'black', size = 16),\n", 74 " ),\n", 75 " cells = dict(\n", 76 " values = record_list,\n", 77 " line = dict(color = '#506784'),\n", 78 " fill = dict(color = ['#000000', 'white']),\n", 79 " align = ['center', 'center', 'left'],\n", 80 " font = dict(color = ['#F8F8F5', '#000000', '#000000'], size = 14),\n", 81 " height = 30,\n", 82 " ))\n", 83 "\n", 84 "data1 = [trace0]\n", 85 "\n", 86 "layout1 = go.Layout(\n", 87 " autosize=True,\n", 88 " height=HEIGHT,\n", 89 ")\n", 90 "\n", 91 "fig1 = dict(data=data1, layout=layout1)\n", 92 "py.offline.iplot(fig1)" 93 ] 94 } 95 ], 96 "metadata": { 97 "kernelspec": { 98 "display_name": "Python 3", 99 "language": "python", 100 "name": "python3" 101 }, 102 "language_info": { 103 "codemirror_mode": { 104 "name": "ipython", 105 "version": 3 106 }, 107 "file_extension": ".py", 108 "mimetype": "text/x-python", 109 "name": "python", 110 "nbconvert_exporter": "python", 111 "pygments_lexer": "ipython3", 112 "version": "3.7.2" 113 } 114 }, 115 "nbformat": 4, 116 "nbformat_minor": 2 117} 118