Points, inches and Emus: Measuring units in Office Open XML

本文详细介绍了Office Open XML中使用的各种测量单位,包括20分之一点(dxa)、半点、百分比的五十分之一及EMU(英语公制单位),并提供了具体的换算示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Points, inches and Emus: Measuring units in OfficeOpen XML

After I got confused with the OfficeOpen XML (OOXML) measuring units for a couple of hours, I thought I’d share what I found on it.

I order to avoid floating point calculations and still maintain high precision the format uses some odd measurement units. Don’t think you can get away with inches, centimeters or pixels!

UPDATE: I created a conversion tool for all those units, available here.

UPDATE 2: Just fixed the DNS, so the conversion tool should be available again quite soon 

Twentieths of a point (dxa)

The main unit in OOXML is a twentieth of a point. This is used for specifying page dimensions, margins, tabs, etc.

The international default letter size is ISO 216 A4 (210 x 297mm ~ 8.3 × 11.7in) and expressed as this:

// pageSize: with and height in 20th of a point
<w:pgSz w:w="11906" w:h="16838"/>

Calculations


dxa(20th of a Point)


Points

(dxa / 20)

Inches

(pt / 72)

Centimeters

(in * 2,54)

Width

11906

595.3

8,27…

21.00086…

Height

16838

841.9

11.69…

29.70036…

As you see it doesn’t really come out even, but even enough. As you can see here, word processes files at 72 dpi.

Half-points

Half-points are used to specify font sizes. A font-sizeof 12pt equals 24 half points:

// run properties
<w:rPr>
  // size value in half-points
  <w:sz w:val="24"/>
</w:rPr>
This is used for relative measurements in some places. It can for example be used for specifying tables total with, cell with and margins. Fiftieths of a Percent
<w:tbl>
    <w:tblPr>
      <!-- table width in 50th of a percent -->
      <w:tblW w:w="2500" w:type="pct"/>
    </w:tblPr>
    <w:tblGrid/>
    <w:tr>
        <w:tc>
            <w:p>
                <w:r>
                    <w:t>Hello, World!</w:t>
                </w:r>
            </w:p>
        </w:tc>
    </w:tr>
</w:tbl>
Calculation  This prints a table that takes 50% of the available with. If you want to specify the with in twentieth of points instead, you have to use specify w:type=”dxa”.

0.5 * 5000 = 2500pct

or

(50*50)%

EMUs (EnglishMetric Unit)

EMUs are used for coordinates in vector-based drawings and embedded pictures. The EMU is a virtual unit to bridge both centimeters and inches. One inch equates to 914400 EMUs and a centimeter is 360000. Actually I found out that the number 914400 is calculated by (the least common multiple of 100 and 254) times 72. As I understand it, this ensures that you can convert forth and back between integer 100th inches, millimeters and pixels with out any floating points. Is that correct, anybody?

Since OOXML is too verbose, the full markup would just confuse even more. Lets say we have a picture that we want to fit into a table cell.

The cell with is 4,25cm which equals to 2410 dxa.

<w:tcW w:w="2410" w:type="dxa"/>
When you try to draw this in word itself you’ll have a hard time to match the actual cell size. This version is set by manually calculating the target picture size. The original picture is 295x413 px at 72 dpi and is embedded using DrawingML. The target picture size in the document has to be specified twice. Once for the drawing canvas (extent) and a second time for the embedded picture itself.

<w:drawing>
    <wp:anchor ...>
        ...
        <!-- drawing canvas size -->
        <wp:extent cx="1530350" cy="2142490"/>
        ...
        <a:graphic>
            <a:graphicData>
                <pic:pic>
                    ...
                    <!-- shape properties -->
                    <pic:spPr bwMode="auto">
                        <!-- 2D transform -->
                        <a:xfrm>
                            ...
                            <!-- picture size -->
                            <a:ext cx="1530350" cy="2142490"/>
                        </a:xfrm>
                        ...
                    </pic:spPr>
                </pic:pic>
            </a:graphicData>
        </a:graphic>
    </wp:anchor>
</w:drawing>


20th of a Point


Points

(dxa/20)

Inches

(pt/72)

EMU

(in*914400)

Cell Width

2410

120.5

1,67361…

1530350


Calculations

Even though this is the most logical way to calculate it,it involves floating points. You can simply avoid those by calculating:

2410 * 914400 / 72 / 20 = 1530350

which can be simplified to:

2410 * 635 = 1530350

Since we want to maintain the aspect ratio of the original picture at 295:413 we have to calculate the height for the cell in dxas and for the pictures in EMUs.

The width-to-height-ratio for this picture is 1.4. So the height for the cell is 2410*1.4 = 3374 dxa and 3374*635 = 2142490 emu.

Thanks for reading! I hope this helps. 

https://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/


<think>嗯,用户想了解如何交互式放置提示标记,以及相关的单位换算和参数设置。首先,我需要理解这些概念在编程或设计工具中的具体应用。交互式放置提示标记可能指的是用户在图形界面中通过拖放或点击来设置标记,比如在地图应用中添加地点标记,或者在设计软件中放置参考线。单位换算可能涉及不同测量单位之间的转换,比如像素到厘米,或者在3D建模中的单位调整。参数设置可能包括调整标记的颜色、大小、坐标等属性。 接下来,我需要考虑用户可能的背景。可能是设计师、开发者,或者普通用户在使用工具时遇到操作问题。用户提到编程或设计工具,所以可能需要技术性的解答,比如API的使用,或者软件内的具体操作步骤。 然后,单位换算是关键部分。比如在CSS中,开发者需要处理px、em、rem等单位,或者3D建模软件中的米和毫米。参数设置可能涉及代码中的配置,比如标记的坐标、样式,或者通过GUI界面调整滑块、输入框等。 还要考虑用户提到的交互式放置,这可能涉及事件处理,比如鼠标点击、拖拽事件,以及如何将这些交互操作转化为程序中的坐标和参数。例如,在JavaScript中监听鼠标事件,获取位置,然后更新标记的位置。 需要检查是否有相关的库或框架推荐,比如在Web开发中使用D3.js或Fabric.js来处理交互式元素。或者在设计工具如Photoshop、Figma中如何操作。 另外,用户的问题中还提到了参数设置,可能需要解释如何通过代码或工具界面调整这些参数,比如使用JSON配置文件,或者在GUI中通过面板设置。 可能还需要考虑不同工具中的具体实现差异,比如在游戏引擎Unity中放置标记和在Adobe Illustrator中的方法不同,但核心概念相似。 最后,生成相关问题时要覆盖用户可能进一步想知道的内容,比如单位换算的最佳实践、常见参数错误处理,或者交互设计的性能优化。</think>### 交互式提示标记放置与参数设置 #### 1. 交互式提示标记的核心实现 交互式提示标记(Interactive Prompt Marker)通常通过以下步骤实现: - **事件监听**:捕捉用户输入事件(如鼠标点击、拖拽、触摸手势) - **坐标转换**:将屏幕坐标转换为应用逻辑坐标 例如在Web开发中: ```javascript canvas.addEventListener('click', (e) => { const rect = canvas.getBoundingClientRect(); const x = e.clientX - rect.left; // 转换为画布相对坐标 const y = e.clientY - rect.top; placeMarker(x, y); }); ``` - **标记渲染**:根据坐标更新UI元素位置 - **数据绑定**:将物理坐标与逻辑数据关联[^1] #### 2. 单位换算实现规范 常见单位转换公式: $$1\ \text{英寸} = 96\ \text{像素}\ (\text{基于标准DPI})$$ $$1\ \text{点} = \frac{1}{72}\ \text{英寸}$$ 在代码中建议封装转换函数: ```python def convert_units(value, from_unit, to_unit): conversion = { ('in', 'px'): lambda x: x * 96, ('px', 'in'): lambda x: x / 96, ('pt', 'in'): lambda x: x / 72, ('m', 'cm'): lambda x: x * 100 } return conversion[(from_unit, to_unit)](value) ``` #### 3. 参数设置最佳实践 | 参数类型 | 存储格式 | 校验规则 | |---------|---------|---------| | 坐标值 | 浮点数 | 0 ≤ x ≤ canvas_width | | 颜色值 | HEX字符串 | ^#([A-Fa-f0-9]{6})$ | | 单位类型 | 枚举值 | ['px','in','cm','mm'] | 推荐使用JSON Schema进行参数验证: ```json { "$schema": "http://json-schema.org/draft-07/schema#", "properties": { "position": { "type": "object", "properties": { "x": {"type": "number", "minimum": 0}, "y": {"type": "number", "minimum": 0} } }, "unit": {"enum": ["px", "in", "cm"]} } } ``` #### 4. 性能优化策略 - 使用空间分区算法优化标记检索: $$O(n) \rightarrow O(\log n)\ \text{通过四叉树索引}$$ - 实现增量式
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值