Skip to content

Commit

Permalink
Merge branch 'usef-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
barteksc committed Jul 12, 2016
2 parents 918146e + 4bcf723 commit 312fbe5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
25 changes: 20 additions & 5 deletions src/main/java/com/shockwave/pdfium/PdfiumCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ public class PdfiumCore {
//private native void nativeRenderPage(long pagePtr, long nativeWindowPtr);
private native void nativeRenderPage(long pagePtr, Surface surface, int dpi,
int startX, int startY,
int drawSizeHor, int drawSizeVer);
int drawSizeHor, int drawSizeVer,
boolean drawAnnot);

private native void nativeRenderPageBitmap(long pagePtr, Bitmap bitmap, int dpi,
int startX, int startY,
int drawSizeHor, int drawSizeVer);
int drawSizeHor, int drawSizeVer,
boolean drawAnnot);

private native String nativeGetDocumentMetaText(long docPtr, String tag);

Expand Down Expand Up @@ -178,12 +180,19 @@ public int getPageHeightPoint(PdfDocument doc, int index) {
}

public void renderPage(PdfDocument doc, Surface surface, int pageIndex,
int startX, int startY, int drawSizeX, int drawSizeY) {
int startX, int startY, int drawSizeX, int drawSizeY)
{
renderPage(doc, surface, pageIndex, startX, startY, drawSizeX, drawSizeY, false);
}

public void renderPage(PdfDocument doc, Surface surface, int pageIndex,
int startX, int startY, int drawSizeX, int drawSizeY,
boolean drawAnnot) {
synchronized (lock) {
try {
//nativeRenderPage(doc.mNativePagesPtr.get(pageIndex), surface, mCurrentDpi);
nativeRenderPage(doc.mNativePagesPtr.get(pageIndex), surface, mCurrentDpi,
startX, startY, drawSizeX, drawSizeY);
startX, startY, drawSizeX, drawSizeY, drawAnnot);
} catch (NullPointerException e) {
Log.e(TAG, "mContext may be null");
e.printStackTrace();
Expand All @@ -196,10 +205,16 @@ public void renderPage(PdfDocument doc, Surface surface, int pageIndex,

public void renderPageBitmap(PdfDocument doc, Bitmap bitmap, int pageIndex,
int startX, int startY, int drawSizeX, int drawSizeY) {
renderPageBitmap(doc, bitmap, pageIndex, startX, startY, drawSizeX, drawSizeY, false);
}

public void renderPageBitmap(PdfDocument doc, Bitmap bitmap, int pageIndex,
int startX, int startY, int drawSizeX, int drawSizeY,
boolean drawAnnot) {
synchronized (lock) {
try {
nativeRenderPageBitmap(doc.mNativePagesPtr.get(pageIndex), bitmap, mCurrentDpi,
startX, startY, drawSizeX, drawSizeY);
startX, startY, drawSizeX, drawSizeY, drawAnnot);
} catch (NullPointerException e) {
Log.e(TAG, "mContext may be null");
e.printStackTrace();
Expand Down
26 changes: 20 additions & 6 deletions src/main/jni/src/mainJNILib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ static void renderPageInternal( FPDF_PAGE page,
ANativeWindow_Buffer *windowBuffer,
int startX, int startY,
int canvasHorSize, int canvasVerSize,
int drawSizeHor, int drawSizeVer){
int drawSizeHor, int drawSizeVer,
bool drawAnnot){

FPDF_BITMAP pdfBitmap = FPDFBitmap_CreateEx( canvasHorSize, canvasVerSize,
FPDFBitmap_BGRA,
Expand All @@ -305,18 +306,24 @@ static void renderPageInternal( FPDF_PAGE page,
int baseVerSize = (canvasVerSize < drawSizeVer)? canvasVerSize : drawSizeVer;
int baseX = (startX < 0)? 0 : startX;
int baseY = (startY < 0)? 0 : startY;
int flags = FPDF_REVERSE_BYTE_ORDER;

if(drawAnnot)
flags |= FPDF_ANNOT;

FPDFBitmap_FillRect( pdfBitmap, baseX, baseY, baseHorSize, baseVerSize,
255, 255, 255, 255); //White

FPDF_RenderPageBitmap( pdfBitmap, page,
startX, startY,
drawSizeHor, drawSizeVer,
0, FPDF_REVERSE_BYTE_ORDER );
0, flags );
}

JNI_FUNC(void, PdfiumCore, nativeRenderPage)(JNI_ARGS, jlong pagePtr, jobject objSurface,
jint dpi, jint startX, jint startY,
jint drawSizeHor, jint drawSizeVer){
jint drawSizeHor, jint drawSizeVer,
jboolean drawAnnot){
ANativeWindow *nativeWindow = ANativeWindow_fromSurface(env, objSurface);
if(nativeWindow == NULL){
LOGE("native window pointer null");
Expand Down Expand Up @@ -347,15 +354,17 @@ JNI_FUNC(void, PdfiumCore, nativeRenderPage)(JNI_ARGS, jlong pagePtr, jobject ob
renderPageInternal(page, &buffer,
(int)startX, (int)startY,
buffer.width, buffer.height,
(int)drawSizeHor, (int)drawSizeVer);
(int)drawSizeHor, (int)drawSizeVer,
(bool)drawAnnot);

ANativeWindow_unlockAndPost(nativeWindow);
ANativeWindow_release(nativeWindow);
}

JNI_FUNC(void, PdfiumCore, nativeRenderPageBitmap)(JNI_ARGS, jlong pagePtr, jobject bitmap,
jint dpi, jint startX, jint startY,
jint drawSizeHor, jint drawSizeVer){
jint drawSizeHor, jint drawSizeVer,
jboolean drawAnnot){

FPDF_PAGE page = reinterpret_cast<FPDF_PAGE>(pagePtr);

Expand Down Expand Up @@ -405,13 +414,18 @@ JNI_FUNC(void, PdfiumCore, nativeRenderPageBitmap)(JNI_ARGS, jlong pagePtr, jobj
int baseVerSize = (canvasVerSize < drawSizeVer)? canvasVerSize : (int)drawSizeVer;
int baseX = (startX < 0)? 0 : (int)startX;
int baseY = (startY < 0)? 0 : (int)startY;
int flags = FPDF_REVERSE_BYTE_ORDER;

if(drawAnnot)
flags |= FPDF_ANNOT;

FPDFBitmap_FillRect( pdfBitmap, baseX, baseY, baseHorSize, baseVerSize,
255, 255, 255, 255); //White

FPDF_RenderPageBitmap( pdfBitmap, page,
startX, startY,
(int)drawSizeHor, (int)drawSizeVer,
0, FPDF_REVERSE_BYTE_ORDER );
0, flags );

AndroidBitmap_unlockPixels(env, bitmap);
}
Expand Down

0 comments on commit 312fbe5

Please sign in to comment.