Skip to content

Commit

Permalink
Add flags to old-scool rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
jerbob92 committed Feb 6, 2022
1 parent 316d7f7 commit 747ff2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
12 changes: 9 additions & 3 deletions internal/implementation/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"os"
"unsafe"

"github.com/klippa-app/go-pdfium/enums"
"github.com/klippa-app/go-pdfium/requests"
"github.com/klippa-app/go-pdfium/responses"
)
Expand Down Expand Up @@ -108,6 +109,7 @@ func (p *PdfiumImplementation) RenderPageInDPI(request *requests.RenderPageInDPI
Width: widthInPixels,
Height: heightInPixels,
PointToPixelRatio: pointToPixelRatio,
Flags: request.RenderFlags,
},
}, 0)
if err != nil {
Expand Down Expand Up @@ -150,6 +152,7 @@ func (p *PdfiumImplementation) RenderPagesInDPI(request *requests.RenderPagesInD
Width: widthInPixels,
Height: heightInPixels,
PointToPixelRatio: pointToPixelRatio,
Flags: request.Pages[i].RenderFlags,
}
}

Expand Down Expand Up @@ -222,6 +225,7 @@ func (p *PdfiumImplementation) RenderPageInPixels(request *requests.RenderPageIn
Width: width,
Height: height,
PointToPixelRatio: ratio,
Flags: request.RenderFlags,
},
}, 0)
if err != nil {
Expand Down Expand Up @@ -266,6 +270,7 @@ func (p *PdfiumImplementation) RenderPagesInPixels(request *requests.RenderPages
Width: width,
Height: height,
PointToPixelRatio: ratio,
Flags: request.Pages[i].RenderFlags,
}
}

Expand All @@ -281,6 +286,7 @@ func (p *PdfiumImplementation) RenderPagesInPixels(request *requests.RenderPages

type renderPage struct {
Page requests.Page
Flags enums.FPDF_RENDER_FLAG
Width int
Height int
PointToPixelRatio float64
Expand Down Expand Up @@ -322,7 +328,7 @@ func (p *PdfiumImplementation) renderPages(pages []renderPage, padding int) (*re
X: 0,
Y: currentOffset,
}
index, err := p.renderPage(bitmap, pages[i].Page, pages[i].Width, pages[i].Height, currentOffset)
index, err := p.renderPage(bitmap, pages[i].Page, pages[i].Width, pages[i].Height, currentOffset, pages[i].Flags)
if err != nil {
return nil, err
}
Expand All @@ -343,7 +349,7 @@ func (p *PdfiumImplementation) renderPages(pages []renderPage, padding int) (*re
}

// renderPage renders a specific page in a specific size on a bitmap.
func (p *PdfiumImplementation) renderPage(bitmap C.FPDF_BITMAP, page requests.Page, width, height, offset int) (int, error) {
func (p *PdfiumImplementation) renderPage(bitmap C.FPDF_BITMAP, page requests.Page, width, height, offset int, flags enums.FPDF_RENDER_FLAG) (int, error) {
pageHandle, err := p.loadPage(page)
if err != nil {
return 0, err
Expand All @@ -365,7 +371,7 @@ func (p *PdfiumImplementation) renderPage(bitmap C.FPDF_BITMAP, page requests.Pa

// Render the bitmap into the given external bitmap, write the bytes
// in reverse order so that BGRA becomes RGBA.
C.FPDF_RenderPageBitmap(bitmap, pageHandle.handle, 0, C.int(offset), C.int(width), C.int(height), 0, C.FPDF_ANNOT|C.FPDF_REVERSE_BYTE_ORDER)
C.FPDF_RenderPageBitmap(bitmap, pageHandle.handle, 0, C.int(offset), C.int(width), C.int(height), 0, C.int(flags)|C.FPDF_REVERSE_BYTE_ORDER)

return pageHandle.index, nil
}
Expand Down
14 changes: 9 additions & 5 deletions requests/render.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package requests

import "github.com/klippa-app/go-pdfium/enums"

type RenderPageInDPI struct {
Page Page
DPI int // The DPI to render the page in.
Page Page
DPI int // The DPI to render the page in.
RenderFlags enums.FPDF_RENDER_FLAG // FPDF_RENDER_FLAG_REVERSE_BYTE_ORDER will always be set to render to Go image.
}

type RenderPagesInDPI struct {
Expand All @@ -11,9 +14,10 @@ type RenderPagesInDPI struct {
}

type RenderPageInPixels struct {
Page Page
Width int // The maximum width of the image.
Height int // The maximum height of the image.
Page Page
Width int // The maximum width of the image.
Height int // The maximum height of the image.
RenderFlags enums.FPDF_RENDER_FLAG // FPDF_RENDER_FLAG_REVERSE_BYTE_ORDER will always be set to render to Go image.
}

type RenderPagesInPixels struct {
Expand Down

0 comments on commit 747ff2f

Please sign in to comment.