OpenXml 和 Word:如何计算 WrapPolygon 坐标?

发布于 2024-12-01 22:58:13 字数 525 浏览 1 评论 0原文

我正在使用 OpenXml 库创建 Microsoft Word 文档。我需要的大部分功能已经正常工作。然而,我一生都找不到以下信息。

我在锚点中显示图像,这会导致文本环绕图像。我使用了 WrapSquare,但这似乎影响了上一段的最后一行,如下图所示。图像锚定到第二段,但会导致第一段的最后一行也在图像周围缩进。

实验

​在 Word 中,我可以通过将换行更改为 WrapTight 来使文本按我想要的方式换行。但是,这需要一个具有多个坐标的 WrapPolygon。我找不到任何方法来确定多边形坐标,以便它们与图像的大小(以像素为单位)相匹配。

该文档似乎甚至没有表明这些坐标使用什么单位,更不用说如何从像素计算它们了。我只能假设计算会涉及 DPI 值,但我不知道当用户最终将文档加载到 Word 中时如何确定将使用什么 DPI。

如果有人能够解释为什么上述问题首先发生,我也会感到满意。我可以将图像向下移动,前面的段落不再受到影响。但为什么这是必要的呢? (左侧和顶部距文本的距离设置均为 0"。)

I am creating a Microsoft Word document using the OpenXml library. Most of what I need is already working correctly. However, I can't for the life of me find the following bit of information.

I'm displaying an image in an anchor, which causes text to wrap around the image. I used WrapSquare but this seems to affect the last line of the previous paragraph as shown in the image below. The image is anchored to the second paragraph but causes the last line of the first paragraph to also indent around the image.

Word Screenshot http://www.softcircuits.com/Client/Word.jpg

Experimenting within Word, I can make the text wrap how I want by changing the wrapping to WrapTight. However, this requires a WrapPolygon with several coordinates. And I can't find any way to determine the polygon coordinates so that they match the size of the image, which is in pixels.

The documentation doesn't even seem to indicate what units are used for these coordinates, let alone how to calculate them from pixels. I can only assume the calculation would involve a DPI value, but I have no idea how to determine what DPI will be used when the user eventually loads the document into Word.

I would also be satisfied if someone can explain why the issues described above is happening in the first place. I can shift the image down and the previous paragraph is no longer affected. But why is this necessary? (The Distance from text setting for both Left and Top is 0".)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦晓ヶ微光ヅ倾城 2024-12-08 22:58:13

WrapPolygon 元素有两个可能的子元素:LineToStartPoint,每个元素都采用 ax 和 y 坐标。根据2.1.1331 Part 1第20.4.2.9节,lineTo(包裹多边形线结束位置)2.1.1334 Part 1第20.4.2.14节,start(包裹多边形开始) > 在 [MS-OI29500:ISO/IEC 的 Microsoft Office 实施信息29500 标准合规性]:

该标准规定 x 和 y 属性表示为
动车组。 Office 以固定坐标解释 x 和 y 属性
空间为21600x21600。

至于将像素转换为 EMU(英制公制单位),请查看此 博客 文章作为示例。

The WrapPolygon element has two possible child elements of LineTo and StartPoint that each take a x and y coordinate. According to 2.1.1331 Part 1 Section 20.4.2.9, lineTo (Wrapping Polygon Line End Position) and 2.1.1334 Part 1 Section 20.4.2.14, start (Wrapping Polygon Start) found in the [MS-OI29500: Microsoft Office Implementation Information for ISO/IEC-29500 Standard Compliance]:

The standard states that the x and y attributes are represented in
EMUs. Office interprets the x and y attributes in a fixed coordinate
space of 21600x21600.

As far as converting pixels to EMUs (English Metric Units), take a look at this blog post for an example.

空名 2024-12-08 22:58:13

我终于解决了这个问题。不管标准如何规定,WrapPolygon 坐标不是 EMU(英制公制单位)。坐标相对于固定坐标空间(21600 x 21600,如 amurra 提供的引用中所述)。

更具体地说,这意味着 0,0 位于图像的左上角,21600,21600 位于图像的右下角。无论图像大小如何,情况都是如此。大于 21600 的坐标延伸到图像之外。

根据这篇文章,“ 21600 值是 Microsoft Office 早期版本绘图层的遗留工件。”

I finally resolved this. Despite what the standard says, the WrapPolygon coordinates are not EMUs (English Metric Units). The coordinates are relative to the fixed coordinate space (21600 x 21600, as mentioned in the quote provided by amurra).

More specifically, this means 0,0 is at the top, left corner of the image, and 21600,21600 is at the bottom, right corner of the image. This is the case no matter what the size of the image is. Coordinates greater than 21600 extend outside the image.

According to this article, "The 21600 value is a legacy artifact from the drawing layer of early versions of the Microsoft Office."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文