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 to pdfium 6150 #122

Merged
merged 6 commits into from
Nov 28, 2023
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" ]
pdfium: [ "4849", "6029" ]
pdfium: [ "4849", "6150" ]
env:
PDFIUM_EXPERIMENTAL_VERSION: "6029"
PDFIUM_EXPERIMENTAL_VERSION: "6150"
PDFIUM_EXPERIMENTAL_GO_VERSION: "1.21"
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: 6029
Version: 6150
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: 6029
Version: 6150
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: 6029
Version: 6150
Requires:

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

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

2 changes: 2 additions & 0 deletions internal/implementation_cgo/fpdf_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
)

// FPDFBookmark_GetFirstChild returns the first child of a bookmark item, or the first top level bookmark item.
// Note that another name for the bookmarks is the document outline, as
// described in ISO 32000-1:2008, section 12.3.3.
func (p *PdfiumImplementation) FPDFBookmark_GetFirstChild(request *requests.FPDFBookmark_GetFirstChild) (*responses.FPDFBookmark_GetFirstChild, error) {
p.Lock()
defer p.Unlock()
Expand Down
30 changes: 30 additions & 0 deletions internal/implementation_cgo/fpdf_edit_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -1187,3 +1187,33 @@ func (p *PdfiumImplementation) FPDFImageObj_GetImagePixelSize(request *requests.
Height: uint(height),
}, nil
}

// FPDF_MovePages Move the given pages to a new index position.
// When this call fails, the document may be left in an indeterminate state.
// Experimental API.
func (p *PdfiumImplementation) FPDF_MovePages(request *requests.FPDF_MovePages) (*responses.FPDF_MovePages, error) {
p.Lock()
defer p.Unlock()

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

if len(request.PageIndices) == 0 {
return nil, errors.New("no page indices were given")
}

// Create an array that's big enough.
valueData := make([]C.int, len(request.PageIndices))
for i := range request.PageIndices {
valueData[i] = C.int(request.PageIndices[i])
}

result := C.FPDF_MovePages(documentHandle.handle, &valueData[0], C.ulong(len(valueData)), C.int(request.DestPageIndex))
if int(result) == 0 {
return nil, errors.New("could not move pages")
}

return &responses.FPDF_MovePages{}, nil
}
7 changes: 7 additions & 0 deletions internal/implementation_cgo/fpdf_edit_no_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,10 @@ func (p *PdfiumImplementation) FPDFGlyphPath_GetGlyphPathSegment(request *reques
func (p *PdfiumImplementation) FPDFImageObj_GetImagePixelSize(request *requests.FPDFImageObj_GetImagePixelSize) (*responses.FPDFImageObj_GetImagePixelSize, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDF_MovePages Move the given pages to a new index position.
// When this call fails, the document may be left in an indeterminate state.
// Experimental API.
func (p *PdfiumImplementation) FPDF_MovePages(request *requests.FPDF_MovePages) (*responses.FPDF_MovePages, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}
25 changes: 25 additions & 0 deletions internal/implementation_cgo/fpdf_structtree_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,28 @@ func (p *PdfiumImplementation) FPDF_StructElement_GetMarkedContentIdAtIndex(requ
MarkedContentID: int(markedContentID),
}, nil
}

// FPDF_StructElement_GetChildMarkedContentID returns the child's content id.
// If the child exists but is not a stream or object, then this
// function will return an error. This will also return an error for out of bounds
// indices. Compared to FPDF_StructElement_GetMarkedContentIdAtIndex,
// it is scoped to the current page.
// Experimental API.
func (p *PdfiumImplementation) FPDF_StructElement_GetChildMarkedContentID(request *requests.FPDF_StructElement_GetChildMarkedContentID) (*responses.FPDF_StructElement_GetChildMarkedContentID, error) {
p.Lock()
defer p.Unlock()

parentStructElementHandle, err := p.getStructElementHandle(request.StructElement)
if err != nil {
return nil, err
}

markedContentID := C.FPDF_StructElement_GetChildMarkedContentID(parentStructElementHandle.handle, C.int(request.Index))
if int(markedContentID) == -1 {
return nil, errors.New("could not get struct element child marked content id")
}

return &responses.FPDF_StructElement_GetChildMarkedContentID{
ChildMarkedContentID: int(markedContentID),
}, nil
}
10 changes: 10 additions & 0 deletions internal/implementation_cgo/fpdf_structtree_no_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,13 @@ func (p *PdfiumImplementation) FPDF_StructElement_GetMarkedContentIdCount(reques
func (p *PdfiumImplementation) FPDF_StructElement_GetMarkedContentIdAtIndex(request *requests.FPDF_StructElement_GetMarkedContentIdAtIndex) (*responses.FPDF_StructElement_GetMarkedContentIdAtIndex, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDF_StructElement_GetChildMarkedContentID returns the child's content id.
// If the child exists but is not a stream or object, then this
// function will return an error. This will also return an error for out of bounds
// indices. Compared to FPDF_StructElement_GetMarkedContentIdAtIndex,
// it is scoped to the current page.
// Experimental API.
func (p *PdfiumImplementation) FPDF_StructElement_GetChildMarkedContentID(request *requests.FPDF_StructElement_GetChildMarkedContentID) (*responses.FPDF_StructElement_GetChildMarkedContentID, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}
50 changes: 50 additions & 0 deletions internal/implementation_cgo/fpdfview_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,53 @@ func (p *PdfiumImplementation) FPDF_GetXFAPacketContent(request *requests.FPDF_G
Content: contentData,
}, nil
}

// FPDF_GetDocUserPermissions returns the user permissions of the PDF.
// Experimental API.
func (p *PdfiumImplementation) FPDF_GetDocUserPermissions(request *requests.FPDF_GetDocUserPermissions) (*responses.FPDF_GetDocUserPermissions, error) {
p.Lock()
defer p.Unlock()

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

permissions := C.FPDF_GetDocUserPermissions(documentHandle.handle)

docPermissions := &responses.FPDF_GetDocUserPermissions{
DocUserPermissions: uint32(permissions),
}

PrintDocument := uint32(1 << 2)
ModifyContents := uint32(1 << 3)
CopyOrExtractText := uint32(1 << 4)
AddOrModifyTextAnnotations := uint32(1 << 5)
FillInExistingInteractiveFormFields := uint32(1 << 8)
ExtractTextAndGraphics := uint32(1 << 9)
AssembleDocument := uint32(1 << 10)
PrintDocumentAsFaithfulDigitalCopy := uint32(1 << 11)

hasPermission := func(permission uint32) bool {
if docPermissions.DocUserPermissions&permission > 0 {
return true
}

return false
}

docPermissions.PrintDocument = hasPermission(PrintDocument)
docPermissions.ModifyContents = hasPermission(ModifyContents)
docPermissions.CopyOrExtractText = hasPermission(CopyOrExtractText)
docPermissions.AddOrModifyTextAnnotations = hasPermission(AddOrModifyTextAnnotations)
docPermissions.FillInInteractiveFormFields = hasPermission(AddOrModifyTextAnnotations)
docPermissions.FillInExistingInteractiveFormFields = hasPermission(FillInExistingInteractiveFormFields)
docPermissions.ExtractTextAndGraphics = hasPermission(ExtractTextAndGraphics)
docPermissions.AssembleDocument = hasPermission(AssembleDocument)
docPermissions.PrintDocumentAsFaithfulDigitalCopy = hasPermission(PrintDocumentAsFaithfulDigitalCopy)

// Calculated permissions
docPermissions.CreateOrModifyInteractiveFormFields = docPermissions.ModifyContents && docPermissions.AddOrModifyTextAnnotations

return docPermissions, nil
}
6 changes: 6 additions & 0 deletions internal/implementation_cgo/fpdfview_no_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,9 @@ func (p *PdfiumImplementation) FPDF_GetXFAPacketName(request *requests.FPDF_GetX
func (p *PdfiumImplementation) FPDF_GetXFAPacketContent(request *requests.FPDF_GetXFAPacketContent) (*responses.FPDF_GetXFAPacketContent, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDF_GetDocUserPermissions returns the user permissions of the PDF.
// Experimental API.
func (p *PdfiumImplementation) FPDF_GetDocUserPermissions(request *requests.FPDF_GetDocUserPermissions) (*responses.FPDF_GetDocUserPermissions, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}
2 changes: 2 additions & 0 deletions internal/implementation_webassembly/fpdf_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
)

// FPDFBookmark_GetFirstChild returns the first child of a bookmark item, or the first top level bookmark item.
// Note that another name for the bookmarks is the document outline, as
// described in ISO 32000-1:2008, section 12.3.3.
func (p *PdfiumImplementation) FPDFBookmark_GetFirstChild(request *requests.FPDFBookmark_GetFirstChild) (*responses.FPDFBookmark_GetFirstChild, error) {
p.Lock()
defer p.Unlock()
Expand Down
Loading
Loading