From 0b906c8d8b7b89aa6152da61b650122fed530f2c Mon Sep 17 00:00:00 2001 From: irori Date: Sun, 11 Aug 2024 10:12:29 +0900 Subject: [PATCH] Add character catalog page --- .github/workflows/build.yml | 1 + .gitignore | 1 + site/catalog.js | 35 ++++++++ site/index.html | 3 +- src/catalog.py | 23 +++++ templates/catalog.html | 165 ++++++++++++++++++++++++++++++++++++ 6 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 site/catalog.js create mode 100644 src/catalog.py create mode 100644 templates/catalog.html diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c778385..a8daa51 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,6 +27,7 @@ jobs: ./build.sh otf woff2 cp dist/*.woff2 site/ pyftsubset dist/wapuro-mincho.woff2 --text-file=site/index.html --output-file=site/wapuro-mincho.subset.woff2 --flavor=woff2 + python src/catalog.py >site/catalog.html - name: Upload artifacts uses: actions/upload-artifact@v4 diff --git a/.gitignore b/.gitignore index 8faeb79..f5c3152 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .venv/ dist/*.otf dist/*.woff2 +site/catalog.html diff --git a/site/catalog.js b/site/catalog.js new file mode 100644 index 0000000..919889e --- /dev/null +++ b/site/catalog.js @@ -0,0 +1,35 @@ +const $ = document.querySelector.bind(document); + +const popup = $('#popup'); + +document.addEventListener('click', (event) => { + if (popup.classList.contains('show')) { + popup.classList.remove('show'); + } + const target = event.target; + if (target.tagName !== 'TD' || target.classList.contains('blank')) return; + const text = target.textContent; + const unicode = [...text].map((c) => + `U+${c.codePointAt(0).toString(16).padStart(4, 0).toUpperCase()}`).join(' '); + $('#popup-glyph').textContent = text; + document.getElementById('popup-info-jis').textContent = target.dataset.jis; + document.getElementById('popup-info-unicode').textContent = unicode; + popup.classList.add('show'); + popup.style.top = event.pageY - popup.offsetHeight / 2 + 'px'; + popup.style.left = event.pageX - popup.offsetWidth / 2 + 'px'; + $('#copy-icon').hidden = false; + $('#copied-icon').hidden = true; +}); + +document.addEventListener('keydown', (event) => { + if (event.key === 'Escape') { + popup.classList.remove('show'); + } +}); + +$('#copy-button').addEventListener('click', async (event) => { + event.stopPropagation(); + await navigator.clipboard.writeText($('#popup-glyph').textContent); + $('#copy-icon').hidden = true; + $('#copied-icon').hidden = false; +}); diff --git a/site/index.html b/site/index.html index f02a0d8..4ffc0c1 100644 --- a/site/index.html +++ b/site/index.html @@ -70,7 +70,8 @@

試し書き

収録文字

-

JIS X 0213:2004の第1〜第3水準漢字と非漢字 8,797字のうち、単一のUnicodeコードポイントで表せない25字を除いた計8,772字を収録しています。

+

JIS X 0213:2004が規定する第1〜第4水準漢字と非漢字、全11,233字を収録しています。

+

収録文字一覧

縦書きにも対応しています。また、当時のワープロ文書でよく使われていた縦倍角・横倍角バージョンも付属しています。

ライセンス

diff --git a/src/catalog.py b/src/catalog.py new file mode 100644 index 0000000..8ff5707 --- /dev/null +++ b/src/catalog.py @@ -0,0 +1,23 @@ +from jinja2 import Environment, FileSystemLoader +from jisx0213 import JISX0213 + +codeconv = JISX0213() +tables = [] +for plane in range(1, 3): + for row in range(1, 95): + # plane 2 has only characters in rows 1, 3–5, 8, 12–15, 78–94. + if plane == 2 and row not in (1, *range(3, 6), 8, *range(12, 16), *range(78, 95)): + continue + t = [None] * 100 + for cell in range(1, 95): + cp = (plane - 1) * 0x8080 | (row + 0x20) << 8 | (cell + 0x20) + u = codeconv.unicode(cp) + t[cell] = u + tables.append({ 'plane': plane, 'row': row, 'table': t }) + +env = Environment(loader=FileSystemLoader('templates')) +env.trim_blocks = True +env.lstrip_blocks = True +template = env.get_template('catalog.html') +content = template.render(char_table=tables) +print(content) diff --git a/templates/catalog.html b/templates/catalog.html new file mode 100644 index 0000000..105eb7c --- /dev/null +++ b/templates/catalog.html @@ -0,0 +1,165 @@ + + + + + + ワープロ明朝 収録文字一覧 + + + +

ワープロ明朝 収録文字一覧

+

トップページへ戻る

+ {% for tbl in char_table %} + + + + + + {% for i in range(10) %} + + {% endfor %} + + {% for y in range(10) %} + + {% if y == 0 %} + + + {% endif %} + + {% for x in range(10) %} + {% if tbl.table[y * 10 + x] is none %} + + {% else %} + + {% endif %} + {% endfor %} + + {% endfor %} +
{{ i }}
{{ tbl.plane }}{{ tbl.row }}{{ y }}0{{ tbl.table[y * 10 + x] }}
+ {% endfor %} + + + +