pretty code

2026年5月10日 星期日

ScreenBar Halo 2 入手

我最近的人生終於有光明了XD

問了幾家附近的 3 C 買場都沒有賣此掛燈,上網購買又得避開晚上送貨,不知為啥也不能選擇常去的便利商店取貨?

今天雖然推 Code 不順,還是抽空去了三創一趟,既然好不容易上去台北,還是每層樓都走馬看花一下,很多店家動線貌似都有重新調整,逛起來舒服多了。

來到現場,看不出來這款掛燈特殊之處,可能是展場燈光本來就很亮的緣故。

反正我就是要買,故也沒多做考慮,一個放家裡,一個放公司。

回家剛裝上時,還覺得是不是裝錯了,感覺一點用處都沒有,後來才發現原來燈管可以旋轉調角度,調整過後果然好多了。

可惜現在老了不在書桌看書寫字了,不然我這鍵盤處的一小塊天地,真的是充滿光明。

明天去公司時應該就能點光明燈了XD

官修正史董狐筆

吾善養吾浩然正氣。

風簷展書讀,古道照顏色。

雖說百無一用是書生,但至少讀書人有風骨。

我的修為還是太淺了些,希望在今年生日前能夠進入無界力量XD


誰說武道止於十境?這個作者的眼界也太小了點!

就像《碧血劍》中描述的華山派內功一樣,雖說由外功練起,但最後也是殊途同歸,由外而內。

這部小說,我喜歡的有齊聖人,當然還有主角陳平安。

沒有這本書,我現在應該翻桌了,每個星期推 Code 都要搞人,髒話都罵了三千字了XD

2026年5月9日 星期六

Fix make build

果不其然,今天要推 Code 時又 Gone 了,明明昨天早上還檢查過(後記:push 時跑的驗證跟第一次檢查環境跑的不是同一個!)。

為了這個,也是搞得我心煩意亂,害我 Debug 時不能靜心,浪費了快兩個小時。

凡事要靠自己,我又不像陳平安有齊聖人照看XD

檢討一下,下次不要再犯錯了!

1. 雖然看出 UVM 有錯誤,但還是懶得問 AI,畢竟要自己打字也是心累。

我的 Debug 方向是對的,因為心煩所以想岔了路,一直想要將缺少的 interface 檔案,透過 BUILD_OPTION 傳進去,也就是想要餵給 XRUN,所以我透過 Makefile 修改問題,有符合我的解題思路。

但因為 Verilog 本質上比較像 C 語言,所以找不到的 interface 檔案,應該要放在同檔案上方用 include 解決。

2. 不要在未確定客戶後續是否還有 commit 未 pull,就先執行 make build。

誠如上次我猜的那樣,客戶的 Makefile 相依性有問題,明明執行完 make build,後續還有 commit 且 commit 中有包含 DV 相關的 testbench 裡的檔案,但因為 git push 判斷 make build 已成功,故並未重新執行 make build。

3. 同前,既然無法確定客戶後續是否還有 commit ,我應該要嚴格執行之前訂定的 SOP。

不過此番看來,PM 4:00 過後還是太趕,改成 PM 8:00?


希望下一次推 Code 可以順利一些﹍

2026/05/10 更新

還好今天母親節聚餐延後,不然我還真的沒辦法繼續了。

昨天晚上好不容易解決掉 make build 問題,你他媽的跑驗證又有問題,重點還不只 1 個問題。

但這次嚴守紀律,不為了這個熬夜,還是準時在 12 前上床。

現在再來盡最後一次的努力。

首先,我以下的理解應該無誤:

- 客戶透過 .git/hooks/pre-push 強制我跑驗證才能 push。
- 驗證跑的 test 跟平常跑的不一樣,至少跟第一次驗證環境的不一樣。
- 驗證要跑的東西是放在真正跑驗證那層的 testfiles 資料夾內,由 Makefile 決定是哪個。
- 跑驗證時,是透過跑驗證那層的上一層裡的 bin 資料夾裡的 perl 程式來 dispatch。
- 跑驗證的 log 在哪我還找不到,但有錯的 log 是放在驗證那層所有 fail 開頭的檔案。

但奇怪的點是我兩個錯誤的測試,其中一個在 test list 裡卻是註解狀態,理論上不應該被 random 挑選到才對?

還有就是在目前這個時間點,星期日早上 7 點,看起來都還有人 commit。

前幾次不知道,我想那個人內心一定很幹,怎麼有人放假在推 Code!如果我的速度比他快,他就會遇到我之前平日推 Code 遇到的死結一樣,因為我比他先 push,導致他推 Code 會失敗。

重點他的 commit 還有持續 fix 驗證問題,難道驗證失敗是因為他的問題?

總之,是否要為此調整 SOP?

另外,屋漏偏逢連夜雨,所有的 Server 目前都已停擺,工作無法 dispatch,就不知道是真的掛點還是接近 +0 時區的午夜,Server 正在重開機或是執行什麼任務?

如果最後真的是因為 Server 無法推 Code,那我也真的沒轍了!

我可以改 Verilog、Makefile、Script,甚至是 Perl 檔案,只為了讓整個 flow 打通,但是遇到 IT 問題我就沒辦法了,畢竟孤臣無力可回天呀!

2026/05/10 下午更新

Server 還是斷斷續續的工作,整個進度非常緩慢。

全部 4 台只有一台恢復正常,至少剛剛檢查情況是這樣。

另外,驗證清單確實是放在 testfiles,只是要注意裡面還有 INCLUDE 其他 test 檔案。

這樣一來我的疑惑完全打通了。

2026年5月5日 星期二

萬惡的 X - 事後總檢討

同樣的招式不能對聖鬥士使用兩次!

昨天無意間在 HTML 格式的文件,看到我解了快四天的關鍵訊號

今天又在另一份 PDF 格式的文件最後兩頁,看到關於那個訊號的提醒。

最扯的是,我在 2 月多的郵件,就有提到這個訊號,但我居然一點印象都沒有?

檢討了一下,應該是從 3 月底就陸續在忙,故到今天才有時間好好閱讀文件。

先是忙一個不應該我下去做的功能,然後是為了推 Code 有兩個週末假期都在跟客戶不合理的流程奮戰。

中間又有代理某樣工作,甚至還花了點時間閱讀某個不是我這個專案 IP 的文件。

還幫客戶解了一個不屬於我工作的 tool 問題。

最後則是開發了幾個新功能。

除了工作,家務事也是同樣精彩,找清運回收沙發及升降桌,購買新沙發及升降桌,東西到貨後的清潔工作,還有放假煮了好幾次飯。

中間雖然有一天因為家裡有事臨時請假,但感覺好久沒放假了?

總之,下次遇到同樣的問題,如果是還沒閱讀文件的情況,第一件事一定要先把文件看完,然後是回顧同樣主題的郵件,最後才是閱讀 IP Verilog。

如果可以的話,閱讀 Simulator 的文件,也許像 AI 說的,有更好 Debug 的手段也說不一定?

2026年5月4日 星期一

越來越喜歡 AI 了

現在都直接用自然語言寫 code 了,起手式就先將需求寫在 spec.txt,開啟 Claude 後,直接跟 AI 說一聲。

Please read the spec.txt and work for me.

不過,偶爾還是要自己動手寫不然會變笨。

所以嘿嘿我自己來,但是雜事就交給 AI。

就在剛剛,終於圓滿了我的嘿嘿小工具XD



之後要嘿嘿就知道書名了,懶得從 Python parss 資料給批次檔了,反正在 Windows 上,反白 ID 後,按滑鼠右鍵就可以貼上了。

這似乎是 Windows 新終端機才有的功能? 

呼山不來去就山

既然沒人能幫助我避開這件事,我只好想個 SOP 來遵循。

只要不滿足我的前置條件,我才懶得管能不能推 Code 成功。


假日應該開始有時間做自己的事吧?

2026年5月3日 星期日

Swift to Python

差點忘了這件事,上個星期六晚上無聊,請 Claude Code 直接幫我 porting 一個我在電子書討論區看到的小工具。

由於該工具是用 Swift 寫的,本人雖然使用過很多程式語言,但我不喜歡蘋果,故我也不會想去學蘋果體系的東西。

所以我只是簡單下個指示。

There is a tool in the folder of original_tool. It is wriiten by Swift.
Please rewrite the tool by Python.
Please use git to record your porting.
Please put all codes in python_tool folder.

一開始還以為 token 會爆掉,沒想到也是不到 20 分鐘就 porting 完畢。



當然從圖片看不出 bug,目前 porting 的版本有兩個 bug:

1. render 區會一直閃爍,我猜程式寫得不好,變成一直 loop 更新。
2. 雖說可以區分哪些字體無法用在直式閱讀,但直式顯示畫面標點符號並沒有變成直式格式。(我猜是報告中提到的限制?

下面是請 AI 整理的報告

================================================================
  DEVELOPMENT REPORT: Chinese Vertical Font Viewer (Python Port)
================================================================
Date     : 2026-04-25
Author   : tylpk  (assisted by Claude Sonnet 4.6)
Project  : c_font_tool
Repo     : C:\Users\tylpk\Desktop\AI\c_font_tool


----------------------------------------------------------------
1. PROJECT OVERVIEW
----------------------------------------------------------------

Goal
  Port the macOS Swift app "Chinese-Vertical-font-reading-test"
  (found in original_tool/) to Python so it can run on Windows
  and other platforms without Xcode or macOS.

Original tool
  - Language  : Swift 5 / SwiftUI
  - Platform  : macOS 13.0+, built with Xcode 15+
  - Source    : original_tool/Chinese-Vertical-font-reading-test/
  - Key files :
      ChineseVerticalApp.swift   -- app entry point
      ContentView.swift          -- main UI, font loading, EPUB handling,
                                    font analysis logic
      VerticalTextView.swift     -- CoreText-based vertical text rendering
      FontDetailView.swift       -- details panel sub-view

Python tool output
  - Language  : Python 3.10+
  - Platform  : Windows / macOS / Linux (anywhere Python + tkinter run)
  - Source    : python_tool/
  - Entry     : python_tool/main.py


----------------------------------------------------------------
2. FILE STRUCTURE
----------------------------------------------------------------

python_tool/
  main.py              (  23 lines)  Entry point; launches TkinterDnD
                                     or plain tkinter root window.
  app.py               ( 522 lines)  Main GUI application class.
  font_analyzer.py     ( 321 lines)  Font metadata extraction and
                                     vertical-support analysis.
  vertical_renderer.py ( 124 lines)  Pillow-based vertical text renderer.
  epub_reader.py       ( 132 lines)  EPUB / TXT text extraction.
  requirements.txt     (   3 lines)  Python package dependencies.

Total Python source: 1,122 lines


----------------------------------------------------------------
3. DEPENDENCIES
----------------------------------------------------------------

Package          Version  Purpose
---------------  -------  --------------------------------------
fonttools        >=4.40   Parse font binary tables (cmap, name,
                          GSUB, OS/2) for metadata and glyph
                          coverage analysis.
Pillow           >=10.0   Render TrueType/OpenType glyphs onto
                          an in-memory image for the vertical
                          text display canvas.
tkinterdnd2      >=0.3    Enable drag-and-drop of font/book files
                          onto the tkinter window. Gracefully
                          absent — file dialogs work as fallback.

All three were already installed or installed successfully via:
  pip install -r python_tool/requirements.txt


----------------------------------------------------------------
4. FEATURE MAPPING (Swift → Python)
----------------------------------------------------------------

4.1 Font Loading
  Swift  : CTFontManagerCreateFontDescriptorsFromURL + CTFontCreate
  Python : fonttools TTFont / TTCollection
  Notes  : TTC collections are fully supported; all sub-fonts are
           exposed as separate entries (Font Name [0], [1], …).

4.2 Font Metadata (details panel)
  Fields ported:
    Full Name, Family, Chinese Name, Chinese Family,
    PostScript Name, Style, File Size, File Path,
    Glyph Count, Ascent / Descent,
    CJK Punctuation (24 chars), Vertical Forms (20 forms),
    Rotation correctness summary.

  Chinese name extraction
    Swift  : Parse raw 'name' table bytes manually.
    Python : fonttools NameRecord.toUnicode(); filter by
             Windows platform Chinese language IDs
             (0x0804 zh-CN, 0x0404 zh-TW, 0x0C04 zh-HK, …)
             and Mac platform IDs (33 zh-Hans, 19 zh-Hant).

4.3 CJK Punctuation Coverage
  Checks 24 standard CJK punctuation code points against the
  font's cmap.  Missing glyphs are listed by character and
  flagged as warnings.  Their code points are passed to the
  renderer which replaces them with □ drawn in red.

4.4 Vertical Forms Coverage (U+FE10–FE44)
  Checks 20 vertical presentation form code points against cmap.
  Reports: ✓ complete / △ incomplete / ✗ none.

4.5 Rotation Check (CLREQ compliance)
  The most technically involved analysis:

  Swift  : Shape each character in both a horizontal and a
           vertical CTFrame, compare resulting glyph IDs via
           CoreText.  A changed glyph ID means GSUB 'vert'
           substituted it.
  Python : Traverse the GSUB table with fonttools; collect all
           glyph-name → glyph-name mappings from lookups
           referenced by 'vert' and 'vrt2' features.
           Compare base glyph name to the substitution target.

  Rules applied (matching Swift logic exactly):
    shouldRotate = True  (brackets, em-dash, ellipsis):
      GSUB substitutes base → correct
      base cmap == vert-form cmap (already vertical) → correct
      no substitution, not already vertical → WRONG (highlighted)
    shouldRotate = False (fullwidth colon, semicolon):
      GSUB substitutes base → WRONG (font incorrectly rotates)
      base cmap == vert-form cmap → WRONG (glyph is vertical form)
      no substitution → correct

  Checked characters (20 total):
    :;()《》「」『』〈〉【】〔〕〖〗—…

4.6 Vertical Text Rendering
  Swift  : CoreText CTFramesetter + CTFrameDraw into NSView,
           right-to-left CTFrameProgression, verticalGlyphForm=true.
  Python : Pillow ImageDraw.text() draws each character one at a
           time into an RGB image:
             • Columns progress right → left
             • Characters within a column progress top → bottom
             • Cell size derived from font bbox of a reference
               CJK character ("字")
             • Missing-glyph code points replaced with □ in red
             • Wrong-rotation code points drawn in red

  Limitation: Pillow does not apply OpenType GSUB features, so
  glyphs are not automatically substituted to their vertical forms
  during rendering.  The rendered preview is useful for glyph
  presence and layout; the analysis panel provides the authoritative
  vertical-support verdict.

4.7 EPUB / TXT Reading Mode
  Swift  : Manual ZIP parsing with raw byte offsets + Apple
           Compression framework for DEFLATE.
  Python : stdlib zipfile module (handles both STORE and DEFLATE).
           OPF spine order preserved via regex parsing of
           <item> / <itemref> elements.
           HTML stripped with a custom html.parser subclass that
           inserts newlines at block-level tags and decodes
           common HTML entities.
           TXT: tried utf-8, utf-8-sig, gbk, big5 in order.

4.8 GUI
  Swift  : SwiftUI (macOS only), declarative two-mode layout.
  Python : tkinter + ttk, imperative class-based layout.

  Comparison mode:
    • Top area: one Canvas column per loaded font, positioned with
      place() so they divide the width equally.
    • Font name label above each column; click to select.
    • Right-click context menu: "Remove <name>".
    • Bottom panel (fixed 300 px): toolbar + scrollable key-value
      details list.
    • Toolbar: font name display, Remove Font, Open Font…,
      Open Book…, Edit Text, font size Spinbox.

  Reading mode:
    • Top bar: Back button, font name, page N/M counter.
    • Full-area Canvas showing one page of vertical text.
    • Navigation:
        Click left half  → next page  (vertical-RL: earlier content
        Click right half → prev page   is on the right)
        ← / → arrow keys, Space bar.

  Drag-and-drop (tkinterdnd2):
    • .ttf / .otf / .ttc / .dfont → load font, add column
    • .epub / .txt → enter reading mode
    • Falls back to "Open Font…" / "Open Book…" dialogs if
      tkinterdnd2 is not available.

  Font size: Spinbox (12–200 pt); triggers full re-render.
  Window resize: debounced 150 ms, then re-renders all columns
  or the current reading page.


----------------------------------------------------------------
5. GIT HISTORY
----------------------------------------------------------------

Commit  22c0b07  Port: app.py + main.py — tkinter GUI
Commit  8b623a0  Port: vertical_renderer.py — Pillow rendering
Commit  fd0abb6  Port: epub_reader.py — EPUB/TXT extraction
Commit  1cd5dd1  Port: font_analyzer.py — analysis logic
Commit  6373068  Port: add requirements.txt
Commit  134a91e  Add original Swift tool and spec


----------------------------------------------------------------
6. HOW TO RUN
----------------------------------------------------------------

  # Install dependencies (one-time)
  pip install -r python_tool/requirements.txt

  # Launch
  python python_tool/main.py

Tested on: Windows 11 Home 10.0.26200, Python 3.14
Runtime output on first launch: one benign fonttools warning
  "114685 extra bytes in post.stringData array"
  (non-conforming post table in a system font; not an error)


----------------------------------------------------------------
7. KNOWN DIFFERENCES FROM THE SWIFT ORIGINAL
----------------------------------------------------------------

1. No real GSUB shaping in the renderer.
   The Swift app uses CoreText which applies GSUB features
   (including 'vert') during glyph layout.  The Python renderer
   draws Unicode code points directly with Pillow; vertical form
   substitution is not applied visually.  The analysis panel
   correctly identifies which fonts support it.

2. No pinch-to-zoom.
   The Swift app supports trackpad pinch gestures.  Python/tkinter
   has no cross-platform pinch support.  Font size is controlled
   via the Spinbox in the toolbar instead.

3. Column drop target highlight.
   The Swift app highlights the specific column being hovered
   during a drag.  tkinterdnd2 provides only window-level drop
   events, so per-column hover highlight is not implemented.

4. .dfont support.
   fonttools can open .dfont files on macOS.  On Windows this
   format is unlikely to be encountered; the code accepts the
   extension but fonttools may raise an error for some .dfont files.

================================================================