Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
before

after

改动说明
问题:注音(furigana / ruby)文本宽于其正文时,注音盒以正文盒中线为轴不改变整词前进宽度,
注音会溢出到正文框外,压到相邻注音上。混合存在单字注音与多字注音时,重叠可能发生在任意相邻单元
之间(单+单、多+单、多+多、以及同一个词内的逐字注音之间),表现为假名互相叠字。
这个 PR 做什么:新增一个可选、不依赖 DOM 的注音排布规范化能力,供宿主在送渲染前使用。
新增
normalizeRubyLayout(lines, measure):measure(text, fontRatio, language)),库本身保持零依赖,可在Node / 单测桩 / 浏览器 Canvas 下运行;
language用于取到与渲染层一致的字体。共用一条注音,空白注音条目按渲染器的过滤规则忽略)。
一个
ruby元素)与整行注音盒(applemusic-like-lyrics 每个词一行居中注音、不参与整词计宽),任一模型判定相撞即合并。
(前向与后向都覆盖);未相撞的注音保持原样,不做冗余合并。
不会产生半个词或自造的时间边界。
romanWord/obscene/emptyBeat在合并时聚合保留。入参数组本身,便于上层做响应式引用比较。
为什么放在
utils/而不是挂进normalizeLyricLines:注音是否显示、用什么字体量宽都属于宿主的显示层决策(渲染器的
--lp-ruby-font-size/.rubyWord字号、按行主语言选择的字族都在宿主侧)。作为解析管线的固定步骤会静默改变所有下游消费者的输出语义,因此这里只提供显式调用的能力。
是否包含破坏性变更
纯新增导出(
normalizeRubyLayout及type RubyWidthMeasurer),未改动任何既有函数签名与行为,normalizeLyricLines输出不变。关联 Issue
无(由 SPlayer 侧的注音压字问题触发,尚未在上游开 Issue)。
测试情况
新增
tests/ruby-layout.spec.ts共 18 例,覆盖:本地执行:
pnpm test(27 files / 247 passed)、pnpm typecheck、pnpm lint、pnpm build全部通过。真实渲染效果在浏览器端验证,见 SPlayer 侧 PR 的「测试情况」。
自查清单
pnpm format,pnpm typecheck、pnpm lint通过dev分支,默认分支为main,故向main提交