fix some problems of pdf lib
This commit is contained in:
parent
c2ffe43d44
commit
17508f8147
|
|
@ -20,22 +20,20 @@
|
|||
*/
|
||||
package com.sun.pdfview;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.Config;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.util.Log;
|
||||
|
||||
import com.sun.pdfview.colorspace.PDFColorSpace;
|
||||
import com.sun.pdfview.function.FunctionType0;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Bitmap.Config;
|
||||
import android.util.Log;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
|
||||
|
|
@ -83,7 +81,7 @@ public class PDFImage {
|
|||
/** the actual image data */
|
||||
private PDFObject imageObj;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create an instance of a PDFImage
|
||||
*/
|
||||
protected PDFImage(PDFObject imageObj) {
|
||||
|
|
@ -127,9 +125,9 @@ public class PDFImage {
|
|||
|
||||
// create the indexed color space for the mask
|
||||
// [PATCHED by michal.busta@gmail.com] - default value od Decode according to PDF spec. is [0, 1]
|
||||
// so the color arry should be:
|
||||
// so the color arry should be:
|
||||
int[] colors = {Color.BLACK, Color.WHITE};
|
||||
|
||||
|
||||
PDFObject imageMaskDecode = obj.getDictRef("Decode");
|
||||
if (imageMaskDecode != null) {
|
||||
PDFObject[] array = imageMaskDecode.getArray();
|
||||
|
|
@ -260,34 +258,31 @@ public class PDFImage {
|
|||
if (colorSpace == null) {
|
||||
throw new UnsupportedOperationException("image without colorspace");
|
||||
} else if (colorSpace.getType() == PDFColorSpace.COLORSPACE_RGB) {
|
||||
int maxH = getHeight();
|
||||
int maxW = getWidth();
|
||||
if (imgBytes.length == 2*maxW*maxH) {
|
||||
// decoded JPEG as RGB565
|
||||
bi = Bitmap.createBitmap(maxW, maxH, Config.RGB_565);
|
||||
bi.copyPixelsFromBuffer(ByteBuffer.wrap(imgBytes));
|
||||
}
|
||||
else {
|
||||
// create RGB image
|
||||
bi = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888);
|
||||
int[] line = new int[maxW];
|
||||
int n=0;
|
||||
for (int h = 0; h<maxH; h++) {
|
||||
for (int w = 0; w<getWidth(); w++) {
|
||||
line[w] = ((0xff&(int)imgBytes[n])<<8|(0xff&(int)imgBytes[n+1]))<<8|(0xff&(int)imgBytes[n+2])|0xFF000000;
|
||||
// line[w] = Color.rgb(0xff&(int)imgBytes[n], 0xff&(int)imgBytes[n+1],0xff&(int)imgBytes[n+2]);
|
||||
n+=3;
|
||||
}
|
||||
bi.setPixels(line, 0, maxW, 0, h, maxW, 1);
|
||||
}
|
||||
}
|
||||
int maxH = getHeight();
|
||||
int maxW = getWidth();
|
||||
bi = Bitmap.createBitmap(maxW, maxH, imgBytes.length == 2 * maxW
|
||||
* maxH ? Config.RGB_565 : Config.ARGB_8888);
|
||||
try {
|
||||
bi.copyPixelsFromBuffer(ByteBuffer.wrap(imgBytes));
|
||||
} catch (Exception e) {
|
||||
int[] line = new int[maxW];
|
||||
int n = 0;
|
||||
for (int h = 0; h < maxH; h++) {
|
||||
for (int w = 0; w < getWidth(); w++) {
|
||||
line[w] = ((0xff & (int) imgBytes[n]) << 8 | (0xff & (int) imgBytes[n + 1])) << 8
|
||||
| (0xff & (int) imgBytes[n + 2]) | 0xFF000000;
|
||||
n += 3;
|
||||
}
|
||||
bi.setPixels(line, 0, maxW, 0, h, maxW, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (colorSpace.getType() == PDFColorSpace.COLORSPACE_GRAY) {
|
||||
// create gray image
|
||||
bi = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888);
|
||||
int maxH = getHeight();
|
||||
int maxW = getWidth();
|
||||
int[] line = new int[maxW];
|
||||
int[] line = new int[maxW];
|
||||
int n=0;
|
||||
for (int h = 0; h<maxH; h++) {
|
||||
for (int w = 0; w<getWidth(); w++) {
|
||||
|
|
@ -468,7 +463,7 @@ public class PDFImage {
|
|||
/**
|
||||
* set the color key mask. It is an array of start/end entries
|
||||
* to indicate ranges of color indicies that should be masked out.
|
||||
*
|
||||
*
|
||||
* @param maskArrayObject
|
||||
*/
|
||||
private void setColorKeyMask(PDFObject maskArrayObject) throws IOException {
|
||||
|
|
@ -524,7 +519,7 @@ public class PDFImage {
|
|||
this.imageMask = imageMask;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Return the soft mask associated with this image
|
||||
*/
|
||||
public PDFImage getSMask() {
|
||||
|
|
|
|||
|
|
@ -111,9 +111,6 @@ public class HeadTable extends TrueTypeTable {
|
|||
* Parse the data before it is set
|
||||
*/
|
||||
public void setData(ByteBuffer data) {
|
||||
if (data.remaining() != 54) {
|
||||
throw new IllegalArgumentException("Bad Head table size");
|
||||
}
|
||||
setVersion(data.getInt());
|
||||
setFontRevision(data.getInt());
|
||||
setChecksumAdjustment(data.getInt());
|
||||
|
|
|
|||
Loading…
Reference in New Issue