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 6721 #198

Merged
merged 16 commits into from
Nov 19, 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.21", "1.22", "1.23" ]
pdfium: [ "4849", "6392" ]
pdfium: [ "4849", "6721" ]
env:
PDFIUM_EXPERIMENTAL_VERSION: "6392"
PDFIUM_EXPERIMENTAL_VERSION: "6721"
PDFIUM_EXPERIMENTAL_GO_VERSION: "1.23"
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: 6392
Version: 6721
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: 6392
Version: 6721
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: 6392
Version: 6721
Requires:

Libs: -L${libdir} -lpdfium
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/onsi/ginkgo/v2 v2.20.0
github.com/onsi/gomega v1.34.1
github.com/stretchr/testify v1.9.0
github.com/tetratelabs/wazero v1.7.3
github.com/tetratelabs/wazero v1.8.1
golang.org/x/net v0.29.0
golang.org/x/text v0.18.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tetratelabs/wazero v1.7.3 h1:PBH5KVahrt3S2AHgEjKu4u+LlDbbk+nsGE3KLucy6Rw=
github.com/tetratelabs/wazero v1.7.3/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y=
github.com/tetratelabs/wazero v1.8.1 h1:NrcgVbWfkWvVc4UtT4LRLDf91PsOzDzefMdwhLfA550=
github.com/tetratelabs/wazero v1.8.1/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
Expand Down
284 changes: 258 additions & 26 deletions internal/commons/generated.go

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions internal/implementation_cgo/fpdf_annot.go
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,38 @@
}, nil
}

// FPDFAnnot_GetFontColor returns the RGB value of the font color for an annotation with variable text.
// Experimental API.
func (p *PdfiumImplementation) FPDFAnnot_GetFontColor(request *requests.FPDFAnnot_GetFontColor) (*responses.FPDFAnnot_GetFontColor, error) {
p.Lock()
defer p.Unlock()

formHandle, err := p.getFormHandleHandle(request.FormHandle)
if err != nil {
return nil, err
}

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

r := C.uint(0)
g := C.uint(0)
b := C.uint(0)

success := C.FPDFAnnot_GetFontColor(formHandle.handle, annotationHandle.handle, &r, &g, &b)
if int(success) == 0 {
return nil, errors.New("could not get font color")
}

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

View check run for this annotation

Codecov / codecov/patch

internal/implementation_cgo/fpdf_annot.go#L1402-L1403

Added lines #L1402 - L1403 were not covered by tests

return &responses.FPDFAnnot_GetFontColor{
R: uint(r),
G: uint(g),
B: uint(b),
}, nil
}

// FPDFAnnot_IsChecked returns whether the given annotation is a form widget that is checked. Intended for use with
// checkbox and radio button widgets.
// Experimental API.
Expand Down
6 changes: 6 additions & 0 deletions internal/implementation_cgo/fpdf_annot_no_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ func (p *PdfiumImplementation) FPDFAnnot_GetFontSize(request *requests.FPDFAnnot
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDFAnnot_GetFontColor returns the RGB value of the font color for an annotation with variable text.
// Experimental API.
func (p *PdfiumImplementation) FPDFAnnot_GetFontColor(request *requests.FPDFAnnot_GetFontColor) (*responses.FPDFAnnot_GetFontColor, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDFAnnot_IsChecked returns whether the given annotation is a form widget that is checked. Intended for use with
// checkbox and radio button widgets.
// Experimental API.
Expand Down
26 changes: 26 additions & 0 deletions internal/implementation_cgo/fpdf_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
/*
#cgo pkg-config: pdfium
#include "fpdf_catalog.h"
#include <stdlib.h>
*/
import "C"
import (
"errors"
"unsafe"

"github.com/klippa-app/go-pdfium/requests"
"github.com/klippa-app/go-pdfium/responses"
)
Expand All @@ -31,3 +35,25 @@
IsTagged: int(isTagged) == 1,
}, nil
}

// FPDFCatalog_SetLanguage sets the language of a document.
// Experimental API.
func (p *PdfiumImplementation) FPDFCatalog_SetLanguage(request *requests.FPDFCatalog_SetLanguage) (*responses.FPDFCatalog_SetLanguage, error) {
p.Lock()
defer p.Unlock()

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

languageStr := C.CString(request.Language)
defer C.free(unsafe.Pointer(languageStr))

success := C.FPDFCatalog_SetLanguage(documentHandle.handle, languageStr)
if int(success) == 0 {
return nil, errors.New("could not set language")
}

Check warning on line 56 in internal/implementation_cgo/fpdf_catalog.go

View check run for this annotation

Codecov / codecov/patch

internal/implementation_cgo/fpdf_catalog.go#L55-L56

Added lines #L55 - L56 were not covered by tests

return &responses.FPDFCatalog_SetLanguage{}, nil
}
6 changes: 6 additions & 0 deletions internal/implementation_cgo/fpdf_catalog_no_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ import (
func (p *PdfiumImplementation) FPDFCatalog_IsTagged(request *requests.FPDFCatalog_IsTagged) (*responses.FPDFCatalog_IsTagged, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDFCatalog_SetLanguage sets the language of a document.
// Experimental API.
func (p *PdfiumImplementation) FPDFCatalog_SetLanguage(request *requests.FPDFCatalog_SetLanguage) (*responses.FPDFCatalog_SetLanguage, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}
88 changes: 82 additions & 6 deletions internal/implementation_cgo/fpdf_edit_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,39 @@
return &responses.FPDFPage_RemoveObject{}, nil
}

// FPDFPageObj_TransformF transforms the page object by the given matrix.
// The matrix is composed as:
//
// |a c e|
// |b d f|
//
// and can be used to scale, rotate, shear and translate the page object.
// Experimental API.
func (p *PdfiumImplementation) FPDFPageObj_TransformF(request *requests.FPDFPageObj_TransformF) (*responses.FPDFPageObj_TransformF, error) {
p.Lock()
defer p.Unlock()

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

matrix := C.FS_MATRIX{}
matrix.a = C.float(request.Transform.A)
matrix.b = C.float(request.Transform.B)
matrix.c = C.float(request.Transform.C)
matrix.d = C.float(request.Transform.D)
matrix.e = C.float(request.Transform.E)
matrix.f = C.float(request.Transform.F)

success := C.FPDFPageObj_TransformF(pageObjectHandle.handle, &matrix)
if int(success) == 0 {
return nil, errors.New("could not transform object")
}

Check warning on line 74 in internal/implementation_cgo/fpdf_edit_experimental.go

View check run for this annotation

Codecov / codecov/patch

internal/implementation_cgo/fpdf_edit_experimental.go#L73-L74

Added lines #L73 - L74 were not covered by tests

return &responses.FPDFPageObj_TransformF{}, nil
}

// FPDFPageObj_GetMatrix returns the transform matrix of a page object.
// The matrix is composed as:
//
Expand Down Expand Up @@ -112,6 +145,24 @@
return &responses.FPDFPageObj_SetMatrix{}, nil
}

// FPDFPageObj_GetMarkedContentID returns the marked content ID of a page object.
// Experimental API.
func (p *PdfiumImplementation) FPDFPageObj_GetMarkedContentID(request *requests.FPDFPageObj_GetMarkedContentID) (*responses.FPDFPageObj_GetMarkedContentID, error) {
p.Lock()
defer p.Unlock()

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

markedContentID := C.FPDFPageObj_GetMarkedContentID(pageObjectHandle.handle)

return &responses.FPDFPageObj_GetMarkedContentID{
MarkedContentID: int(markedContentID),
}, nil
}

// FPDFPageObj_CountMarks returns the count of content marks in a page object.
// Experimental API.
func (p *PdfiumImplementation) FPDFPageObj_CountMarks(request *requests.FPDFPageObj_CountMarks) (*responses.FPDFPageObj_CountMarks, error) {
Expand Down Expand Up @@ -874,9 +925,34 @@
}, nil
}

// FPDFFont_GetFontName returns the font name of a font.
// FPDFFont_GetBaseFontName returns the base font name of a font.
// Experimental API.
func (p *PdfiumImplementation) FPDFFont_GetBaseFontName(request *requests.FPDFFont_GetBaseFontName) (*responses.FPDFFont_GetBaseFontName, error) {
p.Lock()
defer p.Unlock()

fontHandle, err := p.getFontHandle(request.Font)
if err != nil {
return nil, err
}

// First get the text value length.
nameSize := C.FPDFFont_GetBaseFontName(fontHandle.handle, nil, 0)
if nameSize == 0 {
return nil, errors.New("could not get font name")
}

Check warning on line 943 in internal/implementation_cgo/fpdf_edit_experimental.go

View check run for this annotation

Codecov / codecov/patch

internal/implementation_cgo/fpdf_edit_experimental.go#L942-L943

Added lines #L942 - L943 were not covered by tests

charData := make([]byte, nameSize)
C.FPDFFont_GetBaseFontName(fontHandle.handle, (*C.char)(unsafe.Pointer(&charData[0])), C.size_t(len(charData)))

return &responses.FPDFFont_GetBaseFontName{
BaseFontName: string(charData[:len(charData)-1]), // Remove NULL-terminator
}, nil
}

// FPDFFont_GetFamilyName returns the family name of a font.
// Experimental API.
func (p *PdfiumImplementation) FPDFFont_GetFontName(request *requests.FPDFFont_GetFontName) (*responses.FPDFFont_GetFontName, error) {
func (p *PdfiumImplementation) FPDFFont_GetFamilyName(request *requests.FPDFFont_GetFamilyName) (*responses.FPDFFont_GetFamilyName, error) {
p.Lock()
defer p.Unlock()

Expand All @@ -886,16 +962,16 @@
}

// First get the text value length.
nameSize := C.FPDFFont_GetFontName(fontHandle.handle, nil, 0)
nameSize := C.FPDFFont_GetFamilyName(fontHandle.handle, nil, 0)
if nameSize == 0 {
return nil, errors.New("could not get font name")
}

charData := make([]byte, nameSize)
C.FPDFFont_GetFontName(fontHandle.handle, (*C.char)(unsafe.Pointer(&charData[0])), C.ulong(len(charData)))
C.FPDFFont_GetFamilyName(fontHandle.handle, (*C.char)(unsafe.Pointer(&charData[0])), C.size_t(len(charData)))

return &responses.FPDFFont_GetFontName{
FontName: string(charData[:len(charData)-1]), // Remove NULL-terminator
return &responses.FPDFFont_GetFamilyName{
FamilyName: string(charData[:len(charData)-1]), // Remove NULL-terminator
}, nil
}

Expand Down
32 changes: 28 additions & 4 deletions internal/implementation_cgo/fpdf_edit_no_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ func (p *PdfiumImplementation) FPDFPage_RemoveObject(request *requests.FPDFPage_
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDFPageObj_GetMatrix returns the transform matrix of a page object.
// FPDFPageObj_TransformF transforms the page object by the given matrix.
// The matrix is composed as:
//
// |a c e|
// |b d f|
//
// and can be used to scale, rotate, shear and translate the page object.
// Experimental API.
func (p *PdfiumImplementation) FPDFPageObj_GetMatrix(request *requests.FPDFPageObj_GetMatrix) (*responses.FPDFPageObj_GetMatrix, error) {
func (p *PdfiumImplementation) FPDFPageObj_TransformF(request *requests.FPDFPageObj_TransformF) (*responses.FPDFPageObj_TransformF, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}

Expand All @@ -41,6 +41,24 @@ func (p *PdfiumImplementation) FPDFPageObj_SetMatrix(request *requests.FPDFPageO
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDFPageObj_GetMatrix returns the transform matrix of a page object.
// The matrix is composed as:
//
// |a c e|
// |b d f|
//
// and can be used to scale, rotate, shear and translate the page object.
// Experimental API.
func (p *PdfiumImplementation) FPDFPageObj_GetMatrix(request *requests.FPDFPageObj_GetMatrix) (*responses.FPDFPageObj_GetMatrix, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDFPageObj_GetMarkedContentID returns the marked content ID of a page object.
// Experimental API.
func (p *PdfiumImplementation) FPDFPageObj_GetMarkedContentID(request *requests.FPDFPageObj_GetMarkedContentID) (*responses.FPDFPageObj_GetMarkedContentID, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDFPageObj_CountMarks returns the count of content marks in a page object.
// Experimental API.
func (p *PdfiumImplementation) FPDFPageObj_CountMarks(request *requests.FPDFPageObj_CountMarks) (*responses.FPDFPageObj_CountMarks, error) {
Expand Down Expand Up @@ -233,9 +251,15 @@ func (p *PdfiumImplementation) FPDFTextObj_GetFont(request *requests.FPDFTextObj
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDFFont_GetFontName returns the font name of a font.
// FPDFFont_GetBaseFontName returns the base font name of a font.
// Experimental API.
func (p *PdfiumImplementation) FPDFFont_GetBaseFontName(request *requests.FPDFFont_GetBaseFontName) (*responses.FPDFFont_GetBaseFontName, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDFFont_GetFamilyName returns the family name of a font.
// Experimental API.
func (p *PdfiumImplementation) FPDFFont_GetFontName(request *requests.FPDFFont_GetFontName) (*responses.FPDFFont_GetFontName, error) {
func (p *PdfiumImplementation) FPDFFont_GetFamilyName(request *requests.FPDFFont_GetFamilyName) (*responses.FPDFFont_GetFamilyName, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}

Expand Down
Loading
Loading