Skip to content

Commit

Permalink
Add FPDFPageObj_TransformF and FPDFPageObj_GetMarkedContentID
Browse files Browse the repository at this point in the history
  • Loading branch information
jerbob92 committed Nov 19, 2024
1 parent 036fa6c commit d4791cf
Show file tree
Hide file tree
Showing 11 changed files with 508 additions and 0 deletions.
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.

51 changes: 51 additions & 0 deletions internal/implementation_cgo/fpdf_edit_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,39 @@ func (p *PdfiumImplementation) FPDFPage_RemoveObject(request *requests.FPDFPage_
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")
}

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 @@ func (p *PdfiumImplementation) FPDFPageObj_SetMatrix(request *requests.FPDFPageO
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
30 changes: 30 additions & 0 deletions internal/implementation_cgo/fpdf_edit_no_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ func (p *PdfiumImplementation) FPDFPage_RemoveObject(request *requests.FPDFPage_
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// 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) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDFPageObj_SetMatrix sets the transform matrix on 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_SetMatrix(request *requests.FPDFPageObj_SetMatrix) (*responses.FPDFPageObj_SetMatrix, error) {
return nil, pdfium_errors.ErrExperimentalUnsupported
}

// FPDFPageObj_GetMatrix returns the transform matrix of a page object.
// The matrix is composed as:
//
Expand All @@ -41,6 +65,12 @@ func (p *PdfiumImplementation) FPDFPageObj_SetMatrix(request *requests.FPDFPageO
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
61 changes: 61 additions & 0 deletions internal/implementation_webassembly/fpdf_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,44 @@ func (p *PdfiumImplementation) FPDFPage_RemoveObject(request *requests.FPDFPage_
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
}

matrixPointer, _, err := p.CStructFS_MATRIX(&request.Transform)
if err != nil {
return nil, err
}
defer p.Free(matrixPointer)

res, err := p.Module.ExportedFunction("FPDFPageObj_TransformF").Call(p.Context, *pageObjectHandle.handle, matrixPointer)
if err != nil {
return nil, err
}

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

return &responses.FPDFPageObj_TransformF{}, nil
}

// FPDFPageObj_GetMatrix returns the transform matrix of a page object.
// The matrix is composed as:
//
Expand Down Expand Up @@ -2145,6 +2183,29 @@ func (p *PdfiumImplementation) FPDFPageObj_SetMatrix(request *requests.FPDFPageO
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
}

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

markedContentID := *(*int32)(unsafe.Pointer(&res[0]))

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
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.

12 changes: 12 additions & 0 deletions pdfium.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,14 @@ type Pdfium interface {
// and can be used to scale, rotate, shear and translate the page object.
FPDFPageObj_Transform(request *requests.FPDFPageObj_Transform) (*responses.FPDFPageObj_Transform, error)

// 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.
FPDFPageObj_TransformF(request *requests.FPDFPageObj_TransformF) (*responses.FPDFPageObj_TransformF, error)

// FPDFPageObj_GetMatrix returns the transform matrix of a page object.
// The matrix is composed as:
// |a c e|
Expand All @@ -460,6 +468,10 @@ type Pdfium interface {
// FPDFPageObj_NewImageObj creates a new image object.
FPDFPageObj_NewImageObj(request *requests.FPDFPageObj_NewImageObj) (*responses.FPDFPageObj_NewImageObj, error)

// FPDFPageObj_GetMarkedContentID returns the marked content ID of a page object.
// Experimental API.
FPDFPageObj_GetMarkedContentID(request *requests.FPDFPageObj_GetMarkedContentID) (*responses.FPDFPageObj_GetMarkedContentID, error)

// FPDFPageObj_CountMarks returns the count of content marks in a page object.
// Experimental API.
FPDFPageObj_CountMarks(request *requests.FPDFPageObj_CountMarks) (*responses.FPDFPageObj_CountMarks, error)
Expand Down
9 changes: 9 additions & 0 deletions requests/fpdf_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ type FPDFPageObj_Transform struct {
Transform structs.FPDF_FS_MATRIX
}

type FPDFPageObj_TransformF struct {
PageObject references.FPDF_PAGEOBJECT
Transform structs.FPDF_FS_MATRIX
}

type FPDFPageObj_GetMatrix struct {
PageObject references.FPDF_PAGEOBJECT
}
Expand All @@ -114,6 +119,10 @@ type FPDFPageObj_NewImageObj struct {
Document references.FPDF_DOCUMENT
}

type FPDFPageObj_GetMarkedContentID struct {
PageObject references.FPDF_PAGEOBJECT
}

type FPDFPageObj_CountMarks struct {
PageObject references.FPDF_PAGEOBJECT
}
Expand Down
6 changes: 6 additions & 0 deletions responses/fpdf_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type FPDFPageObj_GetType struct {

type FPDFPageObj_Transform struct{}

type FPDFPageObj_TransformF struct{}

type FPDFPageObj_GetMatrix struct {
Matrix structs.FPDF_FS_MATRIX
}
Expand All @@ -68,6 +70,10 @@ type FPDFPageObj_NewImageObj struct {
PageObject references.FPDF_PAGEOBJECT
}

type FPDFPageObj_GetMarkedContentID struct {
MarkedContentID int
}

type FPDFPageObj_CountMarks struct {
Count int
}
Expand Down
Loading

0 comments on commit d4791cf

Please sign in to comment.