Class { kSVGItem, kDisplayListPageItemBoss, { IID_ISHAPE, kSVGShapeImpl, IID_IINKRESOURCES, kAllProcessInkResourcesImpl, IID_IFLATTENERUSAGE, kSVGItemFlattenerUsageImpl, IID_IVISITORHELPER, kEPSItemVisitorHelperImpl, IID_ISCRIPT, kSVGItemScriptImpl, } },
Class
{
kSVGPlaceProviderBoss,
kInvalidClass,
{
IID_IK2SERVICEPROVIDER, kImportServiceImpl,
IID_IIMPORTPROVIDER, kSVGPlaceProviderImpl,
IID_IIMPORTPREVIEW, kSVGImportPreviewImpl,
}
},
/**
* Class for reading from InDesign IPMStream
*/
public class PMInputStream extends InputStream
{
/**
* Creates PMInputStream object and attaches it to IPMStream* already
* opened by InDesign.
* @param iPMStreamPtr IPMStream* to attach to
* @throws IOException The stream has no ability to read.
*/
public PMInputStream(long iPMStreamPtr) throws IOException {
this.ownedStreamPtr = iPMStreamPtr;
this.retain();
}
@Override
public int read() throws IOException {
return readByte();
}
@Override
public int read(byte b[], int off, int len) throws IOException {
if (len == 0) return 0;
return readBytes(b, off, len);
}
@Override
public long skip(long n) throws IOException {
return performSeek(n, SeekFromCurrent);
}
public long seek(long numberOfBytes, int fromHere) throws IOException {
return performSeek(numberOfBytes, fromHere);
}
@Override
public int available() {
return availableBytes();
}
// native functions below
...
/**
* 'Cause IPMStream is a COM-like object we gotta call AddRef() for it
* if we wanna save pointer in our class.
*/
private native void retain();
/**
* Once we called AddRef() we shouldn't forget calling corresponding
* Release(). Let's do it!
*/
private native void release();
protected native int readByte();
protected native int readBytes(byte b[], int off, int len);
protected native long performSeek(long numberOfBytes, int fromHere);
protected native int availableBytes();
protected native String getFileName();
protected native long getLastModifiedTime();
class IPMStream; class PMInputStream
{
private:
IPMStream* fStream;
public:
PMInputStream(IPMStream* stream);
~PMInputStream() { close(); }
void close();
int read() {
unsigned char result;
return read(&result, 1) == 1? result: -1;
}
int read(unsigned char* buffer, int len){ return fStream->XferByte(buffer, len); }
XInt64 seek(XInt64 numberOfBytes, SeekFrom fromHere) {
return fStream->Seek((int32)numberOfBytes, fromHere);
}
public:
enum SeekFrom { SeekFromStart = kSeekFromStart,
SeekFromCurrent = kSeekFromCurrent,
SeekFromEnd = kSeekFromEnd
};
};
Paint getPaint(){ return paint; }
Paint getPaint(){ return paint; }
we will lower.
public void setXORMode(Color c1){ throw new RuntimeException("setXORMode: N/A"); }
public void fillRect(int x, int y, int w, int h) { fill(new Rectangle(x, y, w, h)); }
public void draw(Shape s);
public void fill(Shape s);
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer);
public void drawString(String str, float x, float y);
public void drawString(AttributedCharacterIterator iterator, float x, float y);
private native void newpath();
private native void moveto(float x, float y);
private native void lineto(float x, float y);
private native void curveto(float x1, float y1, float x2, float y2, float x3, float y3);
private native void curvetov(float x2, float y2, float x3, float y3);
private native void closepath();
private native void gsave();
private native void grestore();
private native void setlinewidth(float width);
private native void setdash(int len, float[] dashArray, float offset);
private native void setopacity(float opacity, boolean bIsAlphaShape); // from 0 to 1.0
private native void setrgbcolor(float r, float g, float b);
private native void fill();
private native void eofill();
private native void stroke();
private native void image(int[] buffer, int x, int y, int width, int height, double[] transformMatrix);
private native void clip();
private native void eoclip();
private void applyPath(PathIterator pi, int kind) {
float[] coord = new float[6];
int retSeg;
newpath();
while(!pi.isDone()) {
retSeg = pi.currentSegment(coord);
switch (retSeg) {
case SEG_LINETO:
lineto(coord[0], coord[1]);
break;
case SEG_CUBICTO:
curveto(coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]);
break;
case SEG_MOVETO:
moveto(coord[0], coord[1]);
break;
case SEG_QUADTO:
curvetov(coord[0], coord[1], coord[2], coord[3]);
break;
case SEG_CLOSE:
closepath();
break;
}
pi.next();
}
if(kind == PATH_FILL) {
if(pi.getWindingRule() == PathIterator.WIND_EVEN_ODD) eofill();
else fill();
}
else if(kind == PATH_STROKE) stroke();
else if(kind == PATH_CLIP) {
if(pi.getWindingRule() == PathIterator.WIND_EVEN_ODD) eoclip();
else clip();
}
}
public void draw(Shape s) {
PathIterator pi = s.getPathIterator(getTransform());
applyClip(getClip());
applyStroke(s);
applyStyles();
applyPath(pi, PATH_STROKE);
restoreClip();
}
private void applyClip(Shape xclip) {
gsave();
if(xclip != null) {
PathIterator pi = xclip.getPathIterator(getTransform());
applyPath(pi, PATH_CLIP);
}
}
Source: https://habr.com/ru/post/122746/