When supporting the spec just isn’t enough

Recently I have been working on our annotation code, adding greater support for ink annotations. So I perform the same steps I always do. This time I thought I would give you a quick run down of these steps and what I encountered as I continued.

Read the Specification.

First thing is to read the specification so I have an idea of what it is I have to achieve. In this case I find ink annotations specify an array of arrays specifying points that are used to form the complete line of the ink. These points either are connected by strait or curved lines in an implementation dependent way. If the annotations contains an appearance we use that in place of the array of coordinates. Chasing the implementation notes I find the following. “93. Acrobat viewers always use straight lines to connect the points along each path.” That is going to make life incredibly easy, or so I thought.

Check existing code.

I began to check our existing code. We already have support for appearance streams, we currently needed the coordinates to be drawn. This is beginning to look even easier. I just need to set a color, loop through the coordinates for the ink list within the ink annotation and make a call to a draw line method.

Compare output with adobe reader.

So now I open an example file in adobe reader to confirm what the final output should be. Wait. No. This is wrong. The spec explicitly states all adobe viewers use straight lines. Why are there curves here. Could the ink have an appearance applied to it? No. Four points defining the shape of a “Z”. Hmmm, other viewers display a Z shape built of straight lines, just as the spec states. Right, lets not get too distracted by this. Lets follow the spec and see where to go from there.

Implement changes, to match output as closely as possibly.

Already having access to the four points and drawing a straight line between each point in order, this has been the easiest part yet. Except, many users compare output. If I don’t want this to comeback and haunt me I need to match adobes viewer as closely as I can. But how to add the curve. After a lengthy investigation that I won’t bore you with I came to the conclusion that the curves were bézier curves with control points calculated based on the lines around it. With time and effort I managed to find the best values that can be used to calculate these points.

It turns out that adobe viewer doesn’t always follow it’s own specification. For instance when a file containing an ink annotation with no appearance the viewer builds a shape using curves starting and ending at the points specified in the ink list. It also turns out that should you save the file after modifications or you just use the save as option within adobe reader, the generated curved shape is saved as an appearance for the ink annotation, to be used in place of the points. I should point out that the saving of this shape as an appearance stream is something we do not support.

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (Twitter, Facebook and Google+) or the  Blog RSS.

The following two tabs change content below.
Kieran France is a programmer for IDRSolutions. He enjoys tinkering with most things including gadgets, code and electronics. He often has no idea what to write in his blog posts but tries his hardest to make them interesting and entertaining, he also makes no excuses for his odd sense of humor.

Related Posts:

KieranF

About Kieran France

Kieran France is a programmer for IDRSolutions. He enjoys tinkering with most things including gadgets, code and electronics. He often has no idea what to write in his blog posts but tries his hardest to make them interesting and entertaining, he also makes no excuses for his odd sense of humor.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>