单位与换算 8 条
document units and conversion
换机器必做的单位探测:
已知探测结果后,写
def probe_unit(doc): doc.Unit = 6 # 试毫米 if doc.Unit == 6: return "mm" doc.Unit = 2 # 试英寸 if doc.Unit == 2: return "inch" return f"other({doc.Unit})"已知探测结果后,写
def mm(v): return v/25.4 if unit=="inch" else v 包一层,全篇用 mm,最省心。本类条目
- doc.Unit当前文档单位(cdrUnit 枚举)。所有几何 API 都跟随它:页面宽高、Shape 坐标尺寸、Outline.Width、矩形圆角半径。
- doc.Unit = cdrMillimeter把单位改成毫米,之后代码里就能直接写毫米数,不用处处除 25.4。改完回读确认一次。
- 字号 = 磅(pt)唯一不跟 doc.Unit 的量:CreateArtisticText 的 size 参数、TextRange.Size 都是磅。172pt ≈ 60.7mm。
- 1 inch = 25.4 mm = 72 pt = 96 px换算基准。你代码里 1490/25.4 = 1490mm 转英寸,说明本机 doc.Unit 是英寸。
- page.SizeWidth * page.SizeHeight页面面积(平方单位)。做「元素占页面比例」时用它当分母。
- shape.GetBoundingBox() → w*h包围盒面积,用于「两个 G 是否重叠」这类判定:重叠面积 / min(面积A, 面积B) >= 0.85 就认为是同一处 —— 你代码里的去重逻辑。
- shape.Curve.Area / shape.Curve.Length真实面积 / 周长,仅曲线对象有。
- RectIntersect 面积两矩形重叠面积 = max(0, min(x1+w1, x2+w2) - max(x1, x2)) * max(0, min(y1+h1, y2+h2) - max(y1, y2)