You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PICFAndOfficeArtData.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hwpf.model;
  16. import java.util.LinkedList;
  17. import java.util.List;
  18. import org.apache.poi.ddf.DefaultEscherRecordFactory;
  19. import org.apache.poi.ddf.EscherContainerRecord;
  20. import org.apache.poi.ddf.EscherRecord;
  21. import org.apache.poi.hwpf.model.types.PICFAbstractType;
  22. import org.apache.poi.util.Internal;
  23. import org.apache.poi.util.LittleEndian;
  24. @Internal
  25. public class PICFAndOfficeArtData
  26. {
  27. //arbitrarily selected; may need to increase
  28. private static final int MAX_RECORD_LENGTH = 100_000;
  29. private List<EscherRecord> _blipRecords;
  30. private short _cchPicName;
  31. private PICF _picf;
  32. private EscherContainerRecord _shape;
  33. private byte[] _stPicName;
  34. public PICFAndOfficeArtData( byte[] dataStream, int startOffset )
  35. {
  36. int offset = startOffset;
  37. _picf = new PICF( dataStream, offset );
  38. offset += PICFAbstractType.getSize();
  39. if ( _picf.getMm() == 0x0066 )
  40. {
  41. _cchPicName = LittleEndian.getUByte( dataStream, offset );
  42. offset += 1;
  43. _stPicName = LittleEndian.getByteArray( dataStream, offset,
  44. _cchPicName, MAX_RECORD_LENGTH);
  45. offset += _cchPicName;
  46. }
  47. final DefaultEscherRecordFactory escherRecordFactory = new DefaultEscherRecordFactory();
  48. _shape = new EscherContainerRecord();
  49. int recordSize = _shape.fillFields( dataStream, offset,
  50. escherRecordFactory );
  51. offset += recordSize;
  52. _blipRecords = new LinkedList<>();
  53. while ( ( offset - startOffset ) < _picf.getLcb() )
  54. {
  55. EscherRecord nextRecord = escherRecordFactory.createRecord(
  56. dataStream, offset );
  57. if ( nextRecord.getRecordId() != (short) 0xF007
  58. && ( nextRecord.getRecordId() < (short) 0xF018 || nextRecord
  59. .getRecordId() > (short) 0xF117 ) )
  60. break;
  61. int blipRecordSize = nextRecord.fillFields( dataStream, offset,
  62. escherRecordFactory );
  63. offset += blipRecordSize;
  64. _blipRecords.add( nextRecord );
  65. }
  66. }
  67. public List<EscherRecord> getBlipRecords()
  68. {
  69. return _blipRecords;
  70. }
  71. public PICF getPicf()
  72. {
  73. return _picf;
  74. }
  75. public EscherContainerRecord getShape()
  76. {
  77. return _shape;
  78. }
  79. public byte[] getStPicName()
  80. {
  81. return _stPicName;
  82. }
  83. }