sonarcube fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1771978 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
200850c1e4
commit
48ff8e5686
@ -28,15 +28,16 @@ import org.apache.poi.util.POILogger;
|
|||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
public class ImageHeaderEMF {
|
public class ImageHeaderEMF {
|
||||||
private static POILogger LOG = POILogFactory.getLogger(ImageHeaderEMF.class);
|
private static final POILogger LOG = POILogFactory.getLogger(ImageHeaderEMF.class);
|
||||||
|
|
||||||
private final static String EMF_SIGNATURE = " EMF"; // 0x464D4520 (LE)
|
private static final String EMF_SIGNATURE = " EMF"; // 0x464D4520 (LE)
|
||||||
|
|
||||||
// rectangular inclusive-inclusive bounds, in device units, of the smallest
|
// rectangular inclusive-inclusive bounds, in device units, of the smallest
|
||||||
// rectangle that can be drawn around the image stored in the metafile.
|
// rectangle that can be drawn around the image stored in the metafile.
|
||||||
private final Rectangle deviceBounds;
|
private final Rectangle deviceBounds;
|
||||||
|
|
||||||
public ImageHeaderEMF(byte data[], int offset) {
|
public ImageHeaderEMF(final byte data[], final int off) {
|
||||||
|
int offset = off;
|
||||||
int type = (int)LittleEndian.getUInt(data, offset); offset += 4;
|
int type = (int)LittleEndian.getUInt(data, offset); offset += 4;
|
||||||
if (type != 1) {
|
if (type != 1) {
|
||||||
LOG.log(POILogger.WARN, "Invalid EMF picture - invalid type");
|
LOG.log(POILogger.WARN, "Invalid EMF picture - invalid type");
|
||||||
@ -61,7 +62,7 @@ public class ImageHeaderEMF {
|
|||||||
public Dimension getSize() {
|
public Dimension getSize() {
|
||||||
return deviceBounds.getSize();
|
return deviceBounds.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rectangle getBounds() {
|
public Rectangle getBounds() {
|
||||||
return deviceBounds;
|
return deviceBounds;
|
||||||
}
|
}
|
||||||
|
@ -29,9 +29,9 @@ public class ImageHeaderPICT {
|
|||||||
* skip the first 512 bytes - they are MAC specific crap
|
* skip the first 512 bytes - they are MAC specific crap
|
||||||
*/
|
*/
|
||||||
public static final int PICT_HEADER_OFFSET = 512;
|
public static final int PICT_HEADER_OFFSET = 512;
|
||||||
|
|
||||||
public static final double DEFAULT_RESOLUTION = Units.POINT_DPI;
|
public static final double DEFAULT_RESOLUTION = Units.POINT_DPI;
|
||||||
|
|
||||||
private static final byte V2_HEADER[] = {
|
private static final byte V2_HEADER[] = {
|
||||||
0x00, 0x11, // v2 version opcode
|
0x00, 0x11, // v2 version opcode
|
||||||
0x02, (byte)0xFF, // version number of new picture
|
0x02, (byte)0xFF, // version number of new picture
|
||||||
@ -41,10 +41,10 @@ public class ImageHeaderPICT {
|
|||||||
|
|
||||||
private final Rectangle bounds;
|
private final Rectangle bounds;
|
||||||
private final double hRes, vRes;
|
private final double hRes, vRes;
|
||||||
|
|
||||||
public ImageHeaderPICT(byte data[], int offset) {
|
|
||||||
// http://mirrors.apple2.org.za/apple.cabi.net/Graphics/PICT.and_QT.INFO/PICT.file.format.TI.txt
|
|
||||||
|
|
||||||
|
public ImageHeaderPICT(byte data[], final int off) {
|
||||||
|
// http://mirrors.apple2.org.za/apple.cabi.net/Graphics/PICT.and_QT.INFO/PICT.file.format.TI.txt
|
||||||
|
int offset = off;
|
||||||
// low order 16 bits of picture size - can be ignored
|
// low order 16 bits of picture size - can be ignored
|
||||||
offset += 2;
|
offset += 2;
|
||||||
// rectangular bounding box of picture, at 72 dpi
|
// rectangular bounding box of picture, at 72 dpi
|
||||||
@ -62,7 +62,7 @@ public class ImageHeaderPICT {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isV2) {
|
if (isV2) {
|
||||||
// 4 bytes - fixed, horizontal resolution (dpi) of source data
|
// 4 bytes - fixed, horizontal resolution (dpi) of source data
|
||||||
hRes = readFixedPoint(data, offset); offset += 4;
|
hRes = readFixedPoint(data, offset); offset += 4;
|
||||||
@ -72,7 +72,7 @@ public class ImageHeaderPICT {
|
|||||||
hRes = DEFAULT_RESOLUTION;
|
hRes = DEFAULT_RESOLUTION;
|
||||||
vRes = DEFAULT_RESOLUTION;
|
vRes = DEFAULT_RESOLUTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
bounds = new Rectangle(x1,y1,x2-x1,y2-y1);
|
bounds = new Rectangle(x1,y1,x2-x1,y2-y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ public class ImageHeaderPICT {
|
|||||||
public Rectangle getBounds() {
|
public Rectangle getBounds() {
|
||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int readUnsignedShort(byte data[], int offset) {
|
private static int readUnsignedShort(byte data[], int offset) {
|
||||||
int b0 = data[offset] & 0xFF;
|
int b0 = data[offset] & 0xFF;
|
||||||
int b1 = data[offset+1] & 0xFF;
|
int b1 = data[offset+1] & 0xFF;
|
||||||
|
@ -46,7 +46,7 @@ import org.apache.poi.util.Units;
|
|||||||
public class ImageHeaderWMF {
|
public class ImageHeaderWMF {
|
||||||
|
|
||||||
public static final int APMHEADER_KEY = 0x9AC6CDD7;
|
public static final int APMHEADER_KEY = 0x9AC6CDD7;
|
||||||
private static POILogger LOG = POILogFactory.getLogger(ImageHeaderWMF.class);
|
private static final POILogger LOG = POILogFactory.getLogger(ImageHeaderWMF.class);
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private final int handle;
|
private final int handle;
|
||||||
@ -55,16 +55,16 @@ public class ImageHeaderWMF {
|
|||||||
/**
|
/**
|
||||||
* The number of logical units per inch used to represent the image.
|
* The number of logical units per inch used to represent the image.
|
||||||
* This value can be used to scale an image. By convention, an image is
|
* This value can be used to scale an image. By convention, an image is
|
||||||
* considered to be recorded at 1440 logical units (twips) per inch.
|
* considered to be recorded at 1440 logical units (twips) per inch.
|
||||||
* Thus, a value of 720 specifies that the image SHOULD be rendered at
|
* Thus, a value of 720 specifies that the image SHOULD be rendered at
|
||||||
* twice its normal size, and a value of 2880 specifies that the image
|
* twice its normal size, and a value of 2880 specifies that the image
|
||||||
* SHOULD be rendered at half its normal size.
|
* SHOULD be rendered at half its normal size.
|
||||||
*/
|
*/
|
||||||
private final int inch;
|
private final int inch;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private final int reserved;
|
private final int reserved;
|
||||||
private int checksum;
|
private int checksum;
|
||||||
|
|
||||||
public ImageHeaderWMF(Rectangle dim) {
|
public ImageHeaderWMF(Rectangle dim) {
|
||||||
handle = 0;
|
handle = 0;
|
||||||
left = dim.x;
|
left = dim.x;
|
||||||
@ -75,8 +75,9 @@ public class ImageHeaderWMF {
|
|||||||
reserved = 0;
|
reserved = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageHeaderWMF(byte[] data, int pos) {
|
public ImageHeaderWMF(byte[] data, final int off) {
|
||||||
int key = LittleEndian.getInt(data, pos); pos += LittleEndian.INT_SIZE; //header key
|
int offset = off;
|
||||||
|
int key = LittleEndian.getInt(data, offset); offset += LittleEndian.INT_SIZE; //header key
|
||||||
if (key != APMHEADER_KEY) {
|
if (key != APMHEADER_KEY) {
|
||||||
LOG.log(POILogger.WARN, "WMF file doesn't contain a placeable header - ignore parsing");
|
LOG.log(POILogger.WARN, "WMF file doesn't contain a placeable header - ignore parsing");
|
||||||
handle = 0;
|
handle = 0;
|
||||||
@ -89,16 +90,16 @@ public class ImageHeaderWMF {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle = LittleEndian.getUShort(data, pos); pos += LittleEndian.SHORT_SIZE;
|
handle = LittleEndian.getUShort(data, offset); offset += LittleEndian.SHORT_SIZE;
|
||||||
left = LittleEndian.getShort(data, pos); pos += LittleEndian.SHORT_SIZE;
|
left = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE;
|
||||||
top = LittleEndian.getShort(data, pos); pos += LittleEndian.SHORT_SIZE;
|
top = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE;
|
||||||
right = LittleEndian.getShort(data, pos); pos += LittleEndian.SHORT_SIZE;
|
right = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE;
|
||||||
bottom = LittleEndian.getShort(data, pos); pos += LittleEndian.SHORT_SIZE;
|
bottom = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE;
|
||||||
|
|
||||||
inch = LittleEndian.getUShort(data, pos); pos += LittleEndian.SHORT_SIZE;
|
inch = LittleEndian.getUShort(data, offset); offset += LittleEndian.SHORT_SIZE;
|
||||||
reserved = LittleEndian.getInt(data, pos); pos += LittleEndian.INT_SIZE;
|
reserved = LittleEndian.getInt(data, offset); offset += LittleEndian.INT_SIZE;
|
||||||
|
|
||||||
checksum = LittleEndian.getShort(data, pos); pos += LittleEndian.SHORT_SIZE;
|
checksum = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE;
|
||||||
if (checksum != getChecksum()){
|
if (checksum != getChecksum()){
|
||||||
LOG.log(POILogger.WARN, "WMF checksum does not match the header data");
|
LOG.log(POILogger.WARN, "WMF checksum does not match the header data");
|
||||||
}
|
}
|
||||||
@ -147,7 +148,7 @@ public class ImageHeaderWMF {
|
|||||||
public Rectangle getBounds() {
|
public Rectangle getBounds() {
|
||||||
return new Rectangle(left, top, right-left, bottom-top);
|
return new Rectangle(left, top, right-left, bottom-top);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLength(){
|
public int getLength(){
|
||||||
return 22;
|
return 22;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user