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