Skip to content

Commit

Permalink
Update to pdfium 5854
Browse files Browse the repository at this point in the history
  • Loading branch information
jerbob92 committed Jun 28, 2023
1 parent c3e871c commit 1ef2e12
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 5 deletions.
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.18", "1.19", "1.20" ]
pdfium: [ "4849", "4874", "4929", "5038", "5079", "5254", "5378", "5664" ]
pdfium: [ "4849", "4874", "4929", "5038", "5079", "5254", "5378", "5664", "5854" ]
env:
PDFIUM_EXPERIMENTAL_VERSION: "5664"
PDFIUM_EXPERIMENTAL_VERSION: "5854"
PDFIUM_EXPERIMENTAL_GO_VERSION: "1.20"
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: 5664
Version: 5854
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: 5664
Version: 5854
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: 5664
Version: 5854
Requires:
Libs: -L${libdir} -lpdfium
Expand Down
29 changes: 29 additions & 0 deletions internal/commons/generated.go

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

25 changes: 25 additions & 0 deletions internal/implementation_cgo/fpdf_edit_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -1162,3 +1162,28 @@ func (p *PdfiumImplementation) FPDFGlyphPath_GetGlyphPathSegment(request *reques
GlyphPathSegment: segmentHandle.nativeRef,
}, nil
}

// FPDFImageObj_GetImagePixelSize get the image size in pixels. Faster method to get only image size.
// Experimental API.
func (p *PdfiumImplementation) FPDFImageObj_GetImagePixelSize(request *requests.FPDFImageObj_GetImagePixelSize) (*responses.FPDFImageObj_GetImagePixelSize, error) {
p.Lock()
defer p.Unlock()

imageObjectHandle, err := p.getPageObjectHandle(request.ImageObject)
if err != nil {
return nil, err
}

width := C.uint(0)
height := C.uint(0)

result := C.FPDFImageObj_GetImagePixelSize(imageObjectHandle.handle, &width, &height)
if int(result) == 0 {
return nil, errors.New("could not get image pixel size")
}

return &responses.FPDFImageObj_GetImagePixelSize{
Width: uint(width),
Height: uint(height),
}, nil
}
6 changes: 6 additions & 0 deletions internal/implementation_cgo/fpdf_edit_no_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,9 @@ func (p *PdfiumImplementation) FPDFGlyphPath_CountGlyphSegments(request *request
func (p *PdfiumImplementation) FPDFGlyphPath_GetGlyphPathSegment(request *requests.FPDFGlyphPath_GetGlyphPathSegment) (*responses.FPDFGlyphPath_GetGlyphPathSegment, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDFImageObj_GetImagePixelSize get the image size in pixels. Faster method to get only image size.
// Experimental API.
func (p *PdfiumImplementation) FPDFImageObj_GetImagePixelSize(request *requests.FPDFImageObj_GetImagePixelSize) (*responses.FPDFImageObj_GetImagePixelSize, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}
49 changes: 49 additions & 0 deletions internal/implementation_webassembly/fpdf_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,55 @@ func (p *PdfiumImplementation) FPDFImageObj_GetImageMetadata(request *requests.F
}, nil
}

// FPDFImageObj_GetImagePixelSize get the image size in pixels. Faster method to get only image size.
// Experimental API.
func (p *PdfiumImplementation) FPDFImageObj_GetImagePixelSize(request *requests.FPDFImageObj_GetImagePixelSize) (*responses.FPDFImageObj_GetImagePixelSize, error) {
p.Lock()
defer p.Unlock()

imageObjectHandle, err := p.getPageObjectHandle(request.ImageObject)
if err != nil {
return nil, err
}

widthPointer, err := p.UIntPointer()
if err != nil {
return nil, err
}
defer widthPointer.Free()

heightPointer, err := p.UIntPointer()
if err != nil {
return nil, err
}
defer heightPointer.Free()

res, err := p.Module.ExportedFunction("FPDFImageObj_GetImagePixelSize").Call(p.Context, *imageObjectHandle.handle, widthPointer.Pointer, heightPointer.Pointer)
if err != nil {
return nil, err
}

success := *(*int32)(unsafe.Pointer(&res[0]))
if int(success) == 0 {
return nil, errors.New("could not get image pixel size")
}

widthValue, err := widthPointer.Value()
if err != nil {
return nil, err
}

heightValue, err := heightPointer.Value()
if err != nil {
return nil, err
}

return &responses.FPDFImageObj_GetImagePixelSize{
Width: widthValue,
Height: heightValue,
}, nil
}

// FPDFPageObj_CreateNewPath creates a new path object at an initial position.
func (p *PdfiumImplementation) FPDFPageObj_CreateNewPath(request *requests.FPDFPageObj_CreateNewPath) (*responses.FPDFPageObj_CreateNewPath, error) {
p.Lock()
Expand Down
8 changes: 8 additions & 0 deletions multi_threaded/generated.go

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

4 changes: 4 additions & 0 deletions pdfium.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,10 @@ type Pdfium interface {
// failure to retrieve any specific parameter would result in its value being 0.
FPDFImageObj_GetImageMetadata(request *requests.FPDFImageObj_GetImageMetadata) (*responses.FPDFImageObj_GetImageMetadata, error)

// FPDFImageObj_GetImagePixelSize get the image size in pixels. Faster method to get only image size.
// Experimental API.
FPDFImageObj_GetImagePixelSize(request *requests.FPDFImageObj_GetImagePixelSize) (*responses.FPDFImageObj_GetImagePixelSize, error)

// FPDFPageObj_CreateNewPath creates a new path object at an initial position.
FPDFPageObj_CreateNewPath(request *requests.FPDFPageObj_CreateNewPath) (*responses.FPDFPageObj_CreateNewPath, error)

Expand Down
4 changes: 4 additions & 0 deletions requests/fpdf_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ type FPDFImageObj_GetImageMetadata struct {
Page Page
}

type FPDFImageObj_GetImagePixelSize struct {
ImageObject references.FPDF_PAGEOBJECT
}

type FPDFPageObj_CreateNewPath struct {
X float32
Y float32
Expand Down
5 changes: 5 additions & 0 deletions responses/fpdf_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ type FPDFImageObj_GetImageMetadata struct {
ImageMetadata structs.FPDF_IMAGEOBJ_METADATA
}

type FPDFImageObj_GetImagePixelSize struct {
Width uint
Height uint
}

type FPDFPageObj_CreateNewPath struct {
PageObject references.FPDF_PAGEOBJECT
}
Expand Down
17 changes: 17 additions & 0 deletions shared_tests/fpdf_edit_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ var _ = Describe("fpdf_edit", func() {
Expect(err).To(MatchError("pageObject not given"))
Expect(FPDFPageObj_GetRotatedBounds).To(BeNil())
})

It("returns an error when calling FPDFImageObj_GetImagePixelSize", func() {
FPDFImageObj_GetImagePixelSize, err := PdfiumInstance.FPDFImageObj_GetImagePixelSize(&requests.FPDFImageObj_GetImagePixelSize{})
Expect(err).To(MatchError("pageObject not given"))
Expect(FPDFImageObj_GetImagePixelSize).To(BeNil())
})
})
})

Expand Down Expand Up @@ -950,6 +956,17 @@ var _ = Describe("fpdf_edit", func() {
Expect(FPDFBitmap_Destroy).To(Equal(&responses.FPDFBitmap_Destroy{}))
})

It("returns the correct image pixel size", func() {
FPDFImageObj_GetImagePixelSize, err := PdfiumInstance.FPDFImageObj_GetImagePixelSize(&requests.FPDFImageObj_GetImagePixelSize{
ImageObject: imageObject,
})
Expect(err).To(BeNil())
Expect(FPDFImageObj_GetImagePixelSize).To(Equal(&responses.FPDFImageObj_GetImagePixelSize{
Width: 109,
Height: 88,
}))
})

It("gives an error when trying to remove an object without giving the page object", func() {
FPDFPage_RemoveObject, err := PdfiumInstance.FPDFPage_RemoveObject(&requests.FPDFPage_RemoveObject{
Page: requests.Page{
Expand Down
14 changes: 14 additions & 0 deletions single_threaded/generated.go

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

14 changes: 14 additions & 0 deletions webassembly/generated.go

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

Binary file modified webassembly/pdfium.wasm
Binary file not shown.
7 changes: 7 additions & 0 deletions webassembly/webassembly.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ func Init(config Config) (pdfium.Pool, error) {
newWorker.Module = mod

malloc := mod.ExportedFunction("malloc")
if malloc == nil {
return nil, fmt.Errorf("could not find malloc in exported methods")
}

free := mod.ExportedFunction("free")
if malloc == nil {
return nil, fmt.Errorf("could not find free in exported methods")
}

newWorker.Functions = map[string]api.Function{
"malloc": malloc,
Expand Down

0 comments on commit 1ef2e12

Please sign in to comment.