Replace magic constant use of Escher Blip Start type ID with reference

Instead of referring to the magic constant 0xF018, reference the value in the EscherRecordTypes enum.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886987 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Marius Volkhart 2021-02-27 18:26:36 +00:00
parent d543e89185
commit b9bbac0005
4 changed files with 7 additions and 6 deletions

View File

@ -72,7 +72,7 @@ public class HSSFPictureData implements PictureData
* @see HSSFWorkbook#PICTURE_TYPE_PICT
*/
public int getFormat(){
return blip.getRecordId() - (short)0xF018;
return blip.getRecordId() - EscherRecordTypes.BLIP_START.typeID;
}
/**

View File

@ -28,6 +28,7 @@ import java.util.Map;
import java.util.function.Supplier;
import org.apache.poi.common.usermodel.GenericRecord;
import org.apache.poi.ddf.EscherRecordTypes;
import org.apache.poi.hslf.blip.DIB;
import org.apache.poi.hslf.blip.EMF;
import org.apache.poi.hslf.blip.JPEG;
@ -159,7 +160,7 @@ public abstract class HSLFPictureData implements PictureData, GenericRecord {
data = new byte[LittleEndianConsts.SHORT_SIZE];
PictureType pt = getType();
LittleEndian.putUShort(data, 0, pt.nativeId + 0xF018);
LittleEndian.putUShort(data, 0, pt.nativeId + EscherRecordTypes.BLIP_START.typeID);
out.write(data);
byte[] rd = getRawData();

View File

@ -381,7 +381,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
// When parsing the BStoreDelay stream, [MS-ODRAW] says that we
// should terminate if the type isn't 0xf007 or 0xf018->0xf117
if (!((type == EscherRecordTypes.BSE.typeID) || (type >= 0xf018 && type <= 0xf117))) {
if (!((type == EscherRecordTypes.BSE.typeID) || (type >= EscherRecordTypes.BLIP_START.typeID && type <= 0xf117))) {
break;
}
@ -392,8 +392,8 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
throw new CorruptPowerPointFileException("The file contains a picture, at position " + _pictures.size() + ", which has a negatively sized data length, so we can't trust any of the picture data");
}
// If they type (including the bonus 0xF018) is 0, skip it
PictureType pt = PictureType.forNativeID(type - 0xF018);
// If the type (including the bonus 0xF018) is 0, skip it
PictureType pt = PictureType.forNativeID(type - EscherRecordTypes.BLIP_START.typeID);
if (pt == null) {
LOG.atError().log("Problem reading picture: Invalid image type 0, on picture with length {}.\nYour document will probably become corrupted if you save it! Position: {}", box(imgsize),box(pos));
} else {

View File

@ -73,7 +73,7 @@ public class PICFAndOfficeArtData
EscherRecord nextRecord = escherRecordFactory.createRecord(
dataStream, offset );
if ( nextRecord.getRecordId() != EscherRecordTypes.BSE.typeID
&& ( nextRecord.getRecordId() < (short) 0xF018 || nextRecord
&& ( nextRecord.getRecordId() < EscherRecordTypes.BLIP_START.typeID || nextRecord
.getRecordId() > (short) 0xF117 ) )
break;