0

docx files using docx4j, I am able to parse ovals and rectangles from the CTRect and CTOval object from docx4j. But when I get to the custom shapes docx4j give me objects in CTShape or CTShapetype. I have already read the VML Specification link.

The path value sometimes has the following values

  • m1,1 l1,200,200,200,200,1 xe
  • m100,1 l1,100,100,200,200,100 xe
  • m,l,21600r21600,xe
  • more combinations..., some using the adjusts values and some uses the formulas like path="wr@22,0@21@3,,0@21@4@.."

I want to parse those values to get the points or coordinates in the path. I am having problem parsing them and also for the fact that I am new to VML and I havent grasped it all. Do you have some suggested source codes, libraries, or existing opensource projects that I can use as reference or use or any resource that will help retreive the path coordinates?

FYI: I have tried looking up to LibreOffice source code but I didnt get much from the code, also I find it hard because it is on a different programming language.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
frey
  • 431
  • 1
  • 5
  • 21
  • You can have a look at http://vitali.web.cs.unibo.it/Progetti/VectorConverter – JasonPlutext Jun 07 '14 at 10:02
  • that is a very good resource, do you know any java counterpart? It is possible to try and convert it but I dont have much time for implementing the conversion. – frey Jun 09 '14 at 03:32

1 Answers1

2

I want to parse those values to get the points or coordinates in the path.

Use the VML Object Model Reference to parse the string.

Here is the breakdown of the first bulleted example:

m1,1: moveTo(1,1)

l1,200,200,200,200,1: polyline with points (1,200)(200,200)(200,1)

xe: close then end

And here is an explanation of the formulas:

A text representation of the commands that define the path. X or y-coordinate values can be a reference to a formula in the form "@#" where # is the formula's ordinal number, e.g., "@2". This attribute string is made up of a rich set of commands including the following:

Path Commands
ae (angleellipseto)

al (angleelipse)

ar (arc)

at (arcto)

c (curveto)

e (end)

l (lineto)

m (moveto)

nf (nofill)

ns (nostroke)

qb (quadraticbezier)

qx (ellipticalquadrantx)

qy (ellipticalquadranty)

r (rlineto)

t (rmoveto)

v (curveto)

wa (clockwisearcto)

wr (clockwisearc)

x (close)

The XSLTSL library method string-match can be used to parse with an XSLT 1.0 processor.

<xsl:template name="str:string-match">
  <xsl:param name="text"/>
  <xsl:param name="pattern"/>
</xsl:template>

<xsl:call-template name="str:string-match">
  <xsl:with-param name="text" select="$mytext"/>
  <xsl:with-param name="pattern" select="'m?,?'"/>
</xsl:call-template>

The XPath 2.0 method fn:matches can be used to parse with an XSLT 2.0 processor.

<xsl:if test="fn:matches($mytext, 'm.,.')"></xsl:if>

VML is an XML dialect, so use any Java XSLT processor:

Using Xalan alongside Saxon

can use VML stylesheets such as:

There is also a GWT project which produces VML:

And a good VML tutorial for reference:

References

Community
  • 1
  • 1
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265