Frequently Asked Question
Export an Ink annotation and recreate it from path
Last Updated 11 months ago
If you want to export an Ink annotation and then re-create it from path, you can use the following as a guide:
private ArrayList exportInk(Page.Annotation annotation) { if (annotation != null && annotation.GetType() == 15) { Path inkPath = annotation.GetInkPath(); float pt1[] = new float[2]; float pt2[] = new float[2]; int index = 0; if (inkPath != null) { ArrayList inkPoints = new ArrayList(); int cnt = inkPath.GetNodeCount(); while (index < cnt) { int op = inkPath.GetNode(index, pt1); switch (op) { case 1: //line to inkPoints.add(new Point(op, pt1[0], pt1[1])); index++; break; case 2: //curve to inkPath.GetNode(index + 1, pt2); float pt3[] = new float[2]; inkPath.GetNode(index + 2, pt3); inkPoints.add(new Point(op, pt1[0], pt1[1], pt2[0], pt2[1], pt3[0], pt3[1])); index += 3; break; default: //move to inkPoints.add(new Point(op, pt1[0], pt1[1])); index++; break; } } inkPath.Destroy(); return inkPoints; } } return null; }
private void createInk(ArrayList inkPoints) { if(inkPoints != null) { Ink mInk = new Ink(Global.inkWidth / m_layout.vGetScale()); for(int i = 0 ; i < inkPoints.size() ; i++) { Point point = inkPoints.get(i); switch(point.type) { case 1: //line to mInk.OnMove(point.x, point.y); break; case 0: //move to mInk.OnDown(point.x, point.y); break; } } Page page = m_doc.GetPage(m_pageno); //TODO set pageno according to requirements if (page != null) { page.ObjsStart(); page.AddAnnotInk(mInk); page.Close(); } mInk.Destroy(); //m_layout.vRenderSync(m_layout.vGetPage(m_pageno)); } }
Point:
public class Point { private int type; private float x; private float x2; private float x3; private float y; private float y2; private float y3; public Point(int type, float x, float y) { this.type = type; this.x = x; this.y = y; } public Point(int type, float x, float y, float x2, float y2, float x3, float y3) { this.type = type; this.x = x; this.x2 = x2; this.x3 = x3; this.y = y; this.y2 = y2; this.y3 = y3; } public int getType() { return type; } public void setType(int type) { this.type = type; } public float getX() { return x; } public void setX(float x) { this.x = x; } public float getY() { return y; } public void setY(float y) { this.y = y; } }