Skip to content

FPDFAnnotGetInkListPath and FPDFAnnotAddInkStroke is not working #26

@torfluor

Description

@torfluor

I apologize if it's just be being dumb, but to me it looks like adding and reading ink annotations is not working at all.
Both FPDFAnnotGetInkListPath and FPDFAnnotAddInkStroke should take a pointer to an array of FS_POINTF_ as the argument, but in the generated PDFiumCode.cs code the parameter is defined as global::PDFiumCore.FS_POINTF_ points and not a pointer. I manually modified the points parameter to IntPtr and after building the package both reading and adding ink annotation works.

I changed FPDFAnnotAddInkStroke from

public static int FPDFAnnotAddInkStroke(global::PDFiumCore.FpdfAnnotationT annot, global::PDFiumCore.FS_POINTF_ points, ulong point_count)
{
    var __arg0 = annot is null ? __IntPtr.Zero : annot.__Instance;
    var ____arg1 = points.__Instance;
    var __arg1 = new __IntPtr(&____arg1);
    var __ret = __Internal.FPDFAnnotAddInkStroke(__arg0, __arg1, point_count);
    return __ret;
}

to

public static int FPDFAnnotAddInkStroke(global::PDFiumCore.FpdfAnnotationT annot, IntPtr points, ulong point_count)
{
    var __arg0 = annot is null ? __IntPtr.Zero : annot.__Instance;
    var __arg1 = points;
    var __ret = __Internal.FPDFAnnotAddInkStroke(__arg0, __arg1, point_count);
    return __ret;
}

and FPDFAnnotGetInkListPath from

public static uint FPDFAnnotGetInkListPath(global::PDFiumCore.FpdfAnnotationT annot, uint path_index, global::PDFiumCore.FS_POINTF_ buffer, uint length)
{
    var __arg0 = annot is null ? __IntPtr.Zero : annot.__Instance;
    var ____arg2 = buffer.__Instance;
    var __arg2 = new __IntPtr(&____arg2);
    var __ret = __Internal.FPDFAnnotGetInkListPath(__arg0, path_index, __arg2, length);
    return __ret;
}

to

public static uint FPDFAnnotGetInkListPath(global::PDFiumCore.FpdfAnnotationT annot, uint path_index, IntPtr buffer, uint length)
{
    var __arg0 = annot is null ? __IntPtr.Zero : annot.__Instance;
    var __arg2 = buffer;
    var __ret = __Internal.FPDFAnnotGetInkListPath(__arg0, path_index, __arg2, length);
    return __ret;
}

I can then read and write ink paths from my client code

// Read ink path
FS_POINTF_[] fs_points = new FS_POINTF_[pathSize];
unsafe
{
    fixed (FS_POINTF_* pointer = fs_points)
    {
        var ptr = (IntPtr)pointer;

        var count = fpdf_annot.FPDFAnnotGetInkListPath(pdfiumAnnot, (uint)inkIndex, ptr, pathSize);
    }
}

// Write ink path
unsafe
{
    fixed (FS_POINTF_* pointer = fs_points)
    {
        var ptr = (IntPtr)pointer;

        var count = fpdf_annot.FPDFAnnotAddInkStroke(annot, ptr, (ulong)Points.Count);
    }
}

Please advice on how to best add these patches to the generator so I can create a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions