Skip to content

Commit

Permalink
修訂填寫注音及製作網頁的處理邏輯問題。
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanJui committed Sep 6, 2024
1 parent 5092fa7 commit c4a616f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 15 deletions.
Binary file modified Tai_Gi_Zu_Im_Bun.xlsx
Binary file not shown.
91 changes: 91 additions & 0 deletions docs/天易見,見君難_漢字注音.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

<!DOCTYPE html>
<html lang="zh-TW">
<head>
<title>《天易見,見君難》【漢字注音】</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="assets/styles/styles.css">
</head>
<body>
《天易見,見君難》【漢字注音】
<div class='separator' style='clear: both'>
<a href='圖片' style='display: block; padding: 1em 0; text-align: center'>
<img alt='天易見,見君難' border='0' width='400' data-original-height='630' data-original-width='1200'
src='https://i1.kknews.cc/z5JiPfLkV6qU-v2XS9sdDsjMfPL9ohuAAlOAYBfk45I/0.jpg' />
</a>
</div>

<div class='Siang_Pai'><p>
<span></span>
<ruby><rb></rb><rt>thiⁿ¹</rt><rtc>ㄊㆪˉ</rtc></ruby>
<ruby><rb></rb><rt>i⁷</rt><rtc>ㄧ˫</rtc></ruby>
<ruby><rb></rb><rt>kiⁿ³</rt><rtc>ㄍㆪ˪</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>kiⁿ³</rt><rtc>ㄍㆪ˪</rtc></ruby>
<ruby><rb></rb><rt>kun¹</rt><rtc>ㄍㄨㄣˉ</rtc></ruby>
<ruby><rb></rb><rt>lan⁵</rt><rtc>ㄌㄢˊ</rtc></ruby>
<span></span>
</p><p>
<ruby><rb></rb><rt>ban⁷</rt><rtc>ㆠㄢ˫</rtc></ruby>
<ruby><rb></rb><rt>to⁷</rt><rtc>ㄉㆦ˫</rtc></ruby>
<ruby><rb></rb><rt>te³</rt><rtc>ㄉㆤ˪</rtc></ruby>
<ruby><rb></rb><rt>sing⁵</rt><rtc>ㄒㄧㄥˊ</rtc></ruby>
<ruby><rb></rb><rt>thiⁿ¹</rt><rtc>ㄊㆪˉ</rtc></ruby>
<ruby><rb></rb><rt>iong⁷</rt><rtc>ㄧㆲ˫</rtc></ruby>
<ruby><rb></rb><rt>uan²</rt><rtc>ㄨㄢˋ</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>thiⁿ¹</rt><rtc>ㄊㆪˉ</rtc></ruby>
<ruby><rb></rb><rt>i⁷</rt><rtc>ㄧ˫</rtc></ruby>
<ruby><rb></rb><rt>kiⁿ³</rt><rtc>ㄍㆪ˪</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>kiⁿ³</rt><rtc>ㄍㆪ˪</rtc></ruby>
<ruby><rb></rb><rt>kun¹</rt><rtc>ㄍㄨㄣˉ</rtc></ruby>
<ruby><rb></rb><rt>lan⁵</rt><rtc>ㄌㄢˊ</rtc></ruby>
<span></span>
</p><p>
<ruby><rb></rb><rt>ue⁷</rt><rtc>ㄨㄝ˫</rtc></ruby>
<ruby><rb></rb><rt>tong⁵</rt><rtc>ㄉㆲˊ</rtc></ruby>
<ruby><rb></rb><rt>sin¹</rt><rtc>ㄒㄧㄣˉ</rtc></ruby>
<ruby><rb></rb><rt>koo³</rt><rtc>ㄍㆦ˪</rtc></ruby>
<ruby><rb></rb><rt>kin⁷</rt><rtc>ㄍㄧㄣ˫</rtc></ruby>
<ruby><rb></rb><rt>koo¹</rt><rtc>ㄍㆦˉ</rtc></ruby>
<ruby><rb></rb><rt>san¹</rt><rtc>ㄙㄢˉ</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>khik⁴</rt><rtc>ㄎㄧㆶ</rtc></ruby>
<ruby><rb></rb><rt>lan⁵</rt><rtc>ㄌㄢˊ</rtc></ruby>
<ruby><rb></rb><rt>kan¹</rt><rtc>ㄍㄢˉ</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>ui⁵</rt><rtc>ㄨㄧˊ</rtc></ruby>
<ruby><rb></rb><rt>sui⁵</rt><rtc>ㄙㄨㄧˊ</rtc></ruby>
<ruby><rb></rb><rt>an¹</rt><rtc>ㄢˉ</rtc></ruby>
<span></span>
</p><p>
<ruby><rb></rb><rt>beh⁴</rt><rtc>ㆠㆤㆷ</rtc></ruby>
<ruby><rb></rb><rt>tiau⁷</rt><rtc>ㄉㄧㄠ˫</rtc></ruby>
<ruby><rb></rb><rt>sio²</rt><rtc>ㄒㄧㄜˋ</rtc></ruby>
<ruby><rb></rb><rt>ziu¹</rt><rtc>ㄐㄧㄨˉ</rtc></ruby>
<ruby><rb></rb><rt>cue⁷</rt><rtc>ㄘㄨㄝ˫</rtc></ruby>
<ruby><rb></rb><rt>ku⁷</rt><rtc>ㄍㄨ˫</rtc></ruby>
<ruby><rb></rb><rt>su⁷</rt><rtc>ㄙㄨ˫</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>bo⁵</rt><rtc>ㆠㆦˊ</rtc></ruby>
<ruby><rb></rb><rt>cu²</rt><rtc>ㄘㄨˋ</rtc></ruby>
<ruby><rb></rb><rt>mng⁷</rt><rtc>ㄇㄫ˫</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>zui²</rt><rtc>ㄗㄨㄧˋ</rtc></ruby>
<ruby><rb></rb><rt>lian⁵</rt><rtc>ㄌㄧㄢˊ</rtc></ruby>
<ruby><rb></rb><rt>thiⁿ¹</rt><rtc>ㄊㆪˉ</rtc></ruby>
<span></span>
</p></div>
<div>
<p>
為能正確顯示「注音符號」,請點擊以下連結,下載注音符號專用字型:
<a href="https://github.com/cmex-30/Bopomofo_on_Web/tree/master/font/BopomofoRuby1909-v1-Regular.ttf">
BopomofoRuby1909-v1-Regular.ttf
</a>
,並於使用之電腦端安裝此字型。
</p>
</div>
</body>
</html>

16 changes: 7 additions & 9 deletions p720_Thiam_Zu_Im.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
import math

import xlwings as xw


def thiam_zu_im(wb, sheet_name='漢字注音', cell='V3'):
# 顯示「已輸入之拼音字母及注音符號」
named_range = wb.names['顯示注音輸入'] # 選擇名為 "顯示注音輸入" 的命名範圍# 選擇名為 "顯示注音輸入" 的命名範圍
named_range.refers_to_range.value = True

# 選擇工作表
sheet = wb.sheets[sheet_name]

# 取得 V3 儲存格的字串
v3_value = sheet.range(cell).value

# 顯示「已輸入之拼音字母及注音符號」
named_range = wb.names['顯示注音輸入'] # 選擇名為 "顯示注音輸入" 的命名範圍# 選擇名為 "顯示注音輸入" 的命名範圍
named_range.refers_to_range.value = True

# 確認 V3 不為空
if v3_value:
# 計算字串的總長度
total_length = len(v3_value)

# 每列最多處理 15 個字元,計算總共需要多少列
chars_per_row = 15
total_rows_needed = math.ceil(total_length / chars_per_row) # 無條件進位

# 清空 Row: 5, 9, 13, ... 漢字所在儲存格,上方的台語音標儲存格,及下方的台語注音符號儲存格
row = 5
index = 0 # 漢字處理指標
for i in range(total_rows_needed+1):
# 逐字處理字串
while index < total_length: # 使用 while 而非 for,確保處理完整個字串
for col in range(4, 19): # 【D欄=4】到【R欄=18】
# 確認是否還有字元可以處理
if index < total_length:
Expand Down Expand Up @@ -55,7 +53,7 @@ def thiam_zu_im(wb, sheet_name='漢字注音', cell='V3'):
# 逐行處理資料,從 Row 3 開始,每列處理 15 個字元
row = 3
index = 0 # 漢字處理指標
for i in range(total_rows_needed+1):
while index < total_length: # 使用 while 而非 for,確保處理完整個字串
for col in range(4, 19): # 【D欄=4】到【R欄=18】
# 確認是否還有字元可以處理
if index < total_length:
Expand Down
12 changes: 6 additions & 6 deletions p730_Tng_Sing_Bang_Iah.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,18 @@ def build_web_page(wb, sheet, source_chars, total_length):
while index < total_length:
for col in range(4, 19): # 【D欄=4】到【R欄=18】
if index < total_length:
ruby_tag = ""
src_char = source_chars[index] # 取得目前欲處理的【漢字】
if src_char == "\n":
# 若遇到換行字元,退出迴圈
write_buffer += ("</p><p>\n")
index += 1
break;
else:
han_ji = sheet.range((row, col)).value # 取得漢字
# 當 han_ji 是標點符號時,不需要注音
if is_punctuation(han_ji):
ruby_tag = f"<span>{han_ji}</span>"
ruby_tag = f"<span>{han_ji}</span>\n"
else:
lo_ma_im_piau = sheet.range((row - 1, col)).value # 取得漢字的台語音標
zu_im_hu_ho = sheet.range((row + 1, col)).value # 取得漢字的台語注音符號
Expand All @@ -133,16 +135,14 @@ def build_web_page(wb, sheet, source_chars, total_length):
# <rp>)</rp>
# </ruby>
# """
# ruby_tag = f"<ruby><rb>{han_ji}</rb><rt>{lo_ma_im_piau}</rt><rtc>{zu_im_hu_ho}</rtc></ruby>"
ruby_tag = f"<ruby><rb>{han_ji}</rb><rt>{lo_ma_im_piau}</rt><rtc>{zu_im_hu_ho}</rtc></ruby>"

write_buffer += (ruby_tag + "\n")
ruby_tag = f"<ruby><rb>{han_ji}</rb><rt>{lo_ma_im_piau}</rt><rtc>{zu_im_hu_ho}</rtc></ruby>\n"
write_buffer += ruby_tag
index += 1
else:
break # 若已處理完畢,退出欄位迴圈

# 每處理一行後,換到下一行
write_buffer += "<br>\n"
# write_buffer += "<br>\n"
row += 4

# =========================================================
Expand Down

0 comments on commit c4a616f

Please sign in to comment.