Points, inches and Emus: Measuring units in Office Open XML
来源:互联网 发布:淘宝有没有hm旗舰店 编辑:程序博客网 时间:2024/06/16 00:19
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/
- Points, inches and Emus: Measuring units in Office Open XML
- Office Open XML Demo
- Office Open XML WordprocessingML
- Office Open XML SpreadsheetML
- Understanding and Using rem Units in CSS
- Units Problem: How to read text size as custom attr from xml and set it to TextView in java code
- Units Problem: How to read text size as custom attr from xml and set it to TextView in java code
- Office Open XML 创建超链接
- XML, Open Standards and How XFDL Fits In
- Creating a User in a Domain and Creating Organizational Units
- 汽车安全:Adventures in Automotive Networks and Control Units
- 如何操作 Office Open XML 格式文档
- Office Open XML的几个特点
- Office (2007) Open XML 文件格式简介【转载】
- 如何:修改 Office Open XML 文档【转载】
- Office Open XML 替换页眉页脚
- Office Open XML 打印Word文档目录
- ExcelPackage: Office Open XML Format file creation
- spring学习之路1
- ConcurrentHashMap
- 基于Hadoop/Mahout/Mllib的大数据挖掘培训开课
- DOM遍历元素节点时忽略空格文本节点的方法
- linux操作系统如何备份与还原
- Points, inches and Emus: Measuring units in Office Open XML
- [笔记]Java虚拟机垃圾回收的原理是“引用计数”吗?
- 办公常用linux命令
- OpenCV在AndroidStudio中的环境搭建
- Z buffer 和 W buffer 簡介
- Collection方法之五 对集合中元素进行遍历
- Leetcode 203 Remove Linked List Elements
- RegisterNatives注册失败,返回错误码-1
- Python 多线程使用总结