Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pdfium to 6392, implement new methods #152

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
go: [ "1.20", "1.21", "1.22" ]
pdfium: [ "4849", "6281" ]
pdfium: [ "4849", "6392" ]
env:
PDFIUM_EXPERIMENTAL_VERSION: "6281"
PDFIUM_EXPERIMENTAL_VERSION: "6392"
PDFIUM_EXPERIMENTAL_GO_VERSION: "1.22"
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pdfium-windows.pc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ includedir=D:/opt/pdfium/include

Name: PDFium
Description: PDFium
Version: 6281
Version: 6392
Requires:

Libs: -L${libdir} -lpdfium
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pdfium.pc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ includedir=/opt/pdfium/include

Name: PDFium
Description: PDFium
Version: 6281
Version: 6392
Requires:

Libs: -L${libdir} -lpdfium
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ includedir={path}/include

Name: PDFium
Description: PDFium
Version: 6281
Version: 6392
Requires:

Libs: -L${libdir} -lpdfium
Expand Down
58 changes: 58 additions & 0 deletions internal/commons/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions internal/implementation_cgo/fpdf_annot.go
Original file line number Diff line number Diff line change
Expand Up @@ -1626,3 +1626,64 @@

return &responses.FPDFAnnot_SetURI{}, nil
}

// FPDFAnnot_GetFileAttachment get the attachment from the given annotation.
// Experimental API.
func (p *PdfiumImplementation) FPDFAnnot_GetFileAttachment(request *requests.FPDFAnnot_GetFileAttachment) (*responses.FPDFAnnot_GetFileAttachment, error) {
p.Lock()
defer p.Unlock()

documentHandle, err := p.getDocumentHandle(request.Document)
if err != nil {
return nil, err
}

annotationHandle, err := p.getAnnotationHandle(request.Annotation)
if err != nil {
return nil, err
}

handle := C.FPDFAnnot_GetFileAttachment(annotationHandle.handle)
if handle == nil {
return nil, errors.New("could not get attachment object")

Check warning on line 1648 in internal/implementation_cgo/fpdf_annot.go

View check run for this annotation

Codecov / codecov/patch

internal/implementation_cgo/fpdf_annot.go#L1648

Added line #L1648 was not covered by tests
}

attachmentHandle := p.registerAttachment(handle, documentHandle)

return &responses.FPDFAnnot_GetFileAttachment{
Attachment: attachmentHandle.nativeRef,
}, nil
}

// FPDFAnnot_AddFileAttachment Add an embedded file to the given annotation.
// Experimental API.
func (p *PdfiumImplementation) FPDFAnnot_AddFileAttachment(request *requests.FPDFAnnot_AddFileAttachment) (*responses.FPDFAnnot_AddFileAttachment, error) {
p.Lock()
defer p.Unlock()

documentHandle, err := p.getDocumentHandle(request.Document)
if err != nil {
return nil, err
}

annotationHandle, err := p.getAnnotationHandle(request.Annotation)
if err != nil {
return nil, err
}

transformedName, err := p.transformUTF8ToUTF16LE(request.Name)
if err != nil {
return nil, err

Check warning on line 1676 in internal/implementation_cgo/fpdf_annot.go

View check run for this annotation

Codecov / codecov/patch

internal/implementation_cgo/fpdf_annot.go#L1676

Added line #L1676 was not covered by tests
}

handle := C.FPDFAnnot_AddFileAttachment(annotationHandle.handle, (C.FPDF_WIDESTRING)(unsafe.Pointer(&transformedName[0])))
if handle == nil {
return nil, errors.New("could not get attachment object")

Check warning on line 1681 in internal/implementation_cgo/fpdf_annot.go

View check run for this annotation

Codecov / codecov/patch

internal/implementation_cgo/fpdf_annot.go#L1681

Added line #L1681 was not covered by tests
}

attachmentHandle := p.registerAttachment(handle, documentHandle)

return &responses.FPDFAnnot_AddFileAttachment{
Attachment: attachmentHandle.nativeRef,
}, nil
}
12 changes: 12 additions & 0 deletions internal/implementation_cgo/fpdf_annot_no_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,15 @@ func (p *PdfiumImplementation) FPDFAnnot_GetFormFieldExportValue(request *reques
func (p *PdfiumImplementation) FPDFAnnot_SetURI(request *requests.FPDFAnnot_SetURI) (*responses.FPDFAnnot_SetURI, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDFAnnot_GetFileAttachment get the attachment from the given annotation.
// Experimental API.
func (p *PdfiumImplementation) FPDFAnnot_GetFileAttachment(request *requests.FPDFAnnot_GetFileAttachment) (*responses.FPDFAnnot_GetFileAttachment, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDFAnnot_AddFileAttachment Add an embedded file to the given annotation.
// Experimental API.
func (p *PdfiumImplementation) FPDFAnnot_AddFileAttachment(request *requests.FPDFAnnot_AddFileAttachment) (*responses.FPDFAnnot_AddFileAttachment, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}
73 changes: 73 additions & 0 deletions internal/implementation_webassembly/fpdf_annot.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package implementation_webassembly

import "C"
import (
"errors"
"unsafe"
Expand Down Expand Up @@ -2193,3 +2194,75 @@

return &responses.FPDFAnnot_SetURI{}, nil
}

// FPDFAnnot_GetFileAttachment get the attachment from the given annotation.
// Experimental API.
func (p *PdfiumImplementation) FPDFAnnot_GetFileAttachment(request *requests.FPDFAnnot_GetFileAttachment) (*responses.FPDFAnnot_GetFileAttachment, error) {
p.Lock()
defer p.Unlock()

documentHandle, err := p.getDocumentHandle(request.Document)
if err != nil {
return nil, err
}

annotationHandle, err := p.getAnnotationHandle(request.Annotation)
if err != nil {
return nil, err
}

res, err := p.Module.ExportedFunction("FPDFAnnot_GetFileAttachment").Call(p.Context, *annotationHandle.handle)
if err != nil {
return nil, err

Check warning on line 2216 in internal/implementation_webassembly/fpdf_annot.go

View check run for this annotation

Codecov / codecov/patch

internal/implementation_webassembly/fpdf_annot.go#L2216

Added line #L2216 was not covered by tests
}

handle := res[0]
if handle == 0 {
return nil, errors.New("could not get attachment object")

Check warning on line 2221 in internal/implementation_webassembly/fpdf_annot.go

View check run for this annotation

Codecov / codecov/patch

internal/implementation_webassembly/fpdf_annot.go#L2221

Added line #L2221 was not covered by tests
}

attachmentHandle := p.registerAttachment(&handle, documentHandle)

return &responses.FPDFAnnot_GetFileAttachment{
Attachment: attachmentHandle.nativeRef,
}, nil
}

// FPDFAnnot_AddFileAttachment Add an embedded file to the given annotation.
// Experimental API.
func (p *PdfiumImplementation) FPDFAnnot_AddFileAttachment(request *requests.FPDFAnnot_AddFileAttachment) (*responses.FPDFAnnot_AddFileAttachment, error) {
p.Lock()
defer p.Unlock()

documentHandle, err := p.getDocumentHandle(request.Document)
if err != nil {
return nil, err
}

annotationHandle, err := p.getAnnotationHandle(request.Annotation)
if err != nil {
return nil, err
}

namePointer, err := p.CFPDF_WIDESTRING(request.Name)
if err != nil {
return nil, err

Check warning on line 2249 in internal/implementation_webassembly/fpdf_annot.go

View check run for this annotation

Codecov / codecov/patch

internal/implementation_webassembly/fpdf_annot.go#L2249

Added line #L2249 was not covered by tests
}
defer namePointer.Free()

res, err := p.Module.ExportedFunction("FPDFAnnot_AddFileAttachment").Call(p.Context, *annotationHandle.handle, namePointer.Pointer)
if err != nil {
return nil, err

Check warning on line 2255 in internal/implementation_webassembly/fpdf_annot.go

View check run for this annotation

Codecov / codecov/patch

internal/implementation_webassembly/fpdf_annot.go#L2255

Added line #L2255 was not covered by tests
}

handle := res[0]
if handle == 0 {
return nil, errors.New("could not get attachment object")

Check warning on line 2260 in internal/implementation_webassembly/fpdf_annot.go

View check run for this annotation

Codecov / codecov/patch

internal/implementation_webassembly/fpdf_annot.go#L2260

Added line #L2260 was not covered by tests
}

attachmentHandle := p.registerAttachment(&handle, documentHandle)

return &responses.FPDFAnnot_AddFileAttachment{
Attachment: attachmentHandle.nativeRef,
}, nil
}
16 changes: 16 additions & 0 deletions multi_threaded/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pdfium.go
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,14 @@ type Pdfium interface {
// Experimental API.
FPDFAnnot_SetURI(request *requests.FPDFAnnot_SetURI) (*responses.FPDFAnnot_SetURI, error)

// FPDFAnnot_GetFileAttachment get the attachment from the given annotation.
// Experimental API.
FPDFAnnot_GetFileAttachment(request *requests.FPDFAnnot_GetFileAttachment) (*responses.FPDFAnnot_GetFileAttachment, error)

// FPDFAnnot_AddFileAttachment Add an embedded file to the given annotation.
// Experimental API.
FPDFAnnot_AddFileAttachment(request *requests.FPDFAnnot_AddFileAttachment) (*responses.FPDFAnnot_AddFileAttachment, error)

// End fpdf_annot.h

// Start fpdf_formfill.h
Expand Down
11 changes: 11 additions & 0 deletions requests/fpdf_annot.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,14 @@ type FPDFAnnot_SetURI struct {
Annotation references.FPDF_ANNOTATION
URI string
}

type FPDFAnnot_GetFileAttachment struct {
Document references.FPDF_DOCUMENT
Annotation references.FPDF_ANNOTATION
}

type FPDFAnnot_AddFileAttachment struct {
Document references.FPDF_DOCUMENT
Annotation references.FPDF_ANNOTATION
Name string
}
8 changes: 8 additions & 0 deletions responses/fpdf_annot.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,11 @@ type FPDFAnnot_GetFormFieldExportValue struct {
}

type FPDFAnnot_SetURI struct{}

type FPDFAnnot_GetFileAttachment struct {
Attachment references.FPDF_ATTACHMENT
}

type FPDFAnnot_AddFileAttachment struct {
Attachment references.FPDF_ATTACHMENT
}
Loading
Loading