识别IDML中视觉元素的坐标 [英] Identify coordinates for a visual element in idml

查看:100
本文介绍了识别IDML中视觉元素的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要处理Indesign Idml文件,生成图像并将其他元素覆盖在html中的某些元素上。

I need to process Indesign Idml files, generate an image, and overlay other elements over certain elements in html.

给出一个Indesign Idml文件(这是一个软件包压缩的xml)并在该文件中提供了可视元素(通过xml中的标记)。有没有一种方法可以找到视觉元素在图像上的坐标?

Given an Indesign Idml file (which is a package of zipped xml) and given a visual element in that file (via a tag in the xml). Is there a way to find at what coordinates on the image that visual element falls?

推荐答案

图像容器的层次结构一个IDML文档如下:

The heirarchy of containers for an image in an IDML document is as follows:

文档[包含]> Spread> PageItem> PlacedImage。页面不用作容器,而PageItems则存储在展开坐标中,因此我们可以忽略Document和Page元素。如果您可以在展开坐标中找到一个放置的图像,并重新设置这些坐标的坐标,以便0,0位于屏幕的左上方,则可以像在InDesign文档中一样放置图像。

Document [Contains] > Spread > PageItem > PlacedImage. Pages aren't used as containers, and PageItems are stored in spread coordinates, so we can forget about the Document and Page elements. if you can find a Placed Image in Spread coordinates, and rebase those coords so 0,0 is at the top left of your screen, you can position an image as it was in the InDesign document.

页面项(包含图像)在IDML中没有几何边界。其边界存储为PathGeometry标记内的PathPointType对象数组,如下所示:

A page item (which contains an image) doesn't have geometric bounds in IDML. Its bounds are stored as an array of PathPointType objects within the PathGeometry tag, like this:

<Properties>
            <PathGeometry>
                <GeometryPathType PathOpen="false">
                    <PathPointArray>
                        <PathPointType Anchor="-32.04 -35.04" LeftDirection="-32.04 -35.04" RightDirection="-32.04 -35.04" />
                        <PathPointType Anchor="-32.04 35.04" LeftDirection="-32.04 35.04" RightDirection="-32.04 35.04" />
                        <PathPointType Anchor="32.04 35.04" LeftDirection="32.04 35.04" RightDirection="32.04 35.04" />
                        <PathPointType Anchor="32.04 -35.04" LeftDirection="32.04 -35.04" RightDirection="32.04 -35.04" />
                    </PathPointArray>
                </GeometryPathType>
            </PathGeometry>
        </Properties>

您可以通过获得最低/最高的点值,并假设边界周围,来简单地计算边界您的页面项目是一个矩形。然后,您需要项转换

You can calculate the bounds yourself simply enough by getting the lowest/greatest point values, assuming the border around your page item is a rectangle. Then you need the item transform,

ItemTransform="1 0 0 1 509.27559055100005 -123.76377952749999"

...,您需要考虑IDML认为0,0所在的位置(这是转换的起点)。

...and you need to allow for where IDML thinks 0,0 is (which is the origin of the transform).

在X轴上,装订位置为0(这是可变的-在单页文档中,通常是跨页的左边缘,但在两个页面文档,它可能是传播的中心)。这是您需要页面的地方。 BindingLocation以整数表示(0表示第一页之前,1表示第一页和第二页之间,依此类推)。您可以通过将前几页的ItemTransforms加起来找到相应的坐标。

In the X axis, 0 will be the binding location (which is variable - in a single page document it's usually the left hand edge of the spread, but in a two page document it may be the center of the spread). This is where you will need pages. BindingLocation is expressed as an integer (0 for before the first page, 1 for between first and second, etc). You find the coords of this by adding up the ItemTransforms of the preceding pages.

在Y轴上,由于Adobe最著名的原因,0是传播(不像您期望的那样顶部或底部)。

In the Y axis, for reasons best known to Adobe, 0 is the vertical center of the spread (not either the top or bottom, as you might expect).

IDML文档包含以下示例: http://www.photoshopelementsmac.com/devnet/indesign/documentation.html ,包括从一个坐标空间转换为另一个坐标空间。

The IDML docs have coord examples: http://www.photoshopelementsmac.com/devnet/indesign/documentation.html including translating from one coord space to another.

页面项(提供几何边界),放置的图像具有其自己的图形边界集(可以进一步抵消它),以及其自己的ItemTransform

Also, within a page item (which gives the geometric bounds), a placed image has its own set of graphic bounds, which can offset it further, as well as its own ItemTransform

要回答您的问题,您需要解压缩IDML zip文件,在XML中找到图像,然后执行以下操作:

So, to answer your question, you would need to unpack the IDML zip file, find the image in the XML, then do a sum something like:

// Pseudo-code:
// Calculate PageItem GeometricBounds First as noted above
X: (Spread.BindingLocation) + Spread.ItemTransform.tx + PageItem.itemTransform.tx + PageItem.GeometricBounds.Left + PlacedImage.ItemTransform.tx + PlacedImage.GraphicBounds.Left

Y: (Half Spread Height) + Spread.ItemTransform.ty + PageItem.itemTransform.ty + PageItem.GeometricBounds.Top+ PlacedImage.ItemTransform.ty + PlacedImage.GraphicBounds.Top

哦,还有一件事:所有IDML坐标均以磅为单位。如果要获得以像素为单位的结果,则需要将所有值除以72除以屏幕的PPI。

Oh, one more thing: all IDML coords are in points. You'll need to divide all values by 72 divided by the PPI of your screen if you want to get results in pixels.

这篇关于识别IDML中视觉元素的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆