refactor: unify HTML preview rendering units to pt#22
Merged
Conversation
Replace mixed CSS units (px, cm) with pt (points) as the standard rendering unit for Word, PowerPoint, and Excel HTML previews. Key changes: - Add shared Units utility class (Core/Units.cs) with TwipsToPt and EmuToPt conversions that leverage exact integer ratios (1pt = 20 twips, 1pt = 12700 EMU) for zero-precision-loss conversions - Word: replace TwipsToPx (twips/1440*96, lossy) with TwipsToPt (twips/20, exact) across 17 call sites - PowerPoint HTML: replace EmuToCm (EMU/360000, irrational) with EmuToPt (EMU/12700, exact) across 36 call sites - Excel: convert column widths, row heights, and frozen pane offsets from px to pt for unit consistency - PPT SVG module intentionally unchanged (viewBox is unitless) - Add UnitsTests with precision validation for all conversions https://claude.ai/code/session_019rKwH4ZHPkkykhRauA7wP7
goworm
added a commit
that referenced
this pull request
Mar 29, 2026
…gBBYH refactor: unify HTML preview rendering units to pt
goworm
added a commit
that referenced
this pull request
Apr 2, 2026
…gBBYH refactor: unify HTML preview rendering units to pt
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.
Summary
Units工具类(Core/Units.cs),利用精确整数比(1pt = 20 twips, 1pt = 12700 EMU)实现零损失转换TwipsToPx(twips/1440×96, 有舍入)→Units.TwipsToPt(twips/20, 精确),涉及 17 处EmuToCm(EMU/360000, 无理数)→Units.EmuToPt(EMU/12700, 精确),涉及 36 处UnitsTests单元测试验证转换精度改动背景
之前三个模块各自使用不同的 CSS 单位:
twips/1440*96, Round 1位)twips/20, 精确)EMU/360000, Round 3位)EMU/12700, 精确整除)width*7.5+5, 魔数)width*5.625+3.75)涉及文件(12个)
新增:
src/officecli/Core/Units.cstests/.../UnitsTests.cs修改:
WordHandler.HtmlPreview.Css.cs,WordHandler.HtmlPreview.Tables.csPowerPointHandler.HtmlPreview.cs,.Shapes.cs,.Tables.cs,.Charts.cs,.Text.cs,.Css.csExcelHandler.HtmlPreview.cs,ExcelHandler.HtmlPreview.Charts.csTest plan
view html截图,确认无 >2px 布局偏移Relates to
Closes #21
https://claude.ai/code/session_019rKwH4ZHPkkykhRauA7wP7