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.

HwmfHeader.java 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.hwmf.record;
  16. import java.io.IOException;
  17. import org.apache.poi.util.LittleEndianConsts;
  18. import org.apache.poi.util.LittleEndianInputStream;
  19. public class HwmfHeader {
  20. private int type;
  21. private int recordSize;
  22. private int version;
  23. private int filesize;
  24. private int numberOfObjects;
  25. private long maxRecord;
  26. private int numberOfMembers;
  27. public HwmfHeader(LittleEndianInputStream leis) throws IOException {
  28. // Type (2 bytes): A 16-bit unsigned integer that defines the type of metafile
  29. // MEMORYMETAFILE = 0x0001, DISKMETAFILE = 0x0002
  30. type = leis.readUShort();
  31. // HeaderSize (2 bytes): A 16-bit unsigned integer that defines the number
  32. // of 16-bit words in the header.
  33. recordSize = leis.readUShort();
  34. int bytesLeft = recordSize*LittleEndianConsts.SHORT_SIZE-4;
  35. // Version (2 bytes): A 16-bit unsigned integer that defines the metafile version.
  36. // METAVERSION100 = 0x0100, METAVERSION300 = 0x0300
  37. version = leis.readUShort();
  38. bytesLeft -= LittleEndianConsts.SHORT_SIZE;
  39. // SizeLow (2 bytes): A 16-bit unsigned integer that defines the low-order word
  40. // of the number of 16-bit words in the entire metafile.
  41. // SizeHigh (2 bytes): A 16-bit unsigned integer that defines the high-order word
  42. // of the number of 16-bit words in the entire metafile.
  43. filesize = leis.readInt();
  44. bytesLeft -= LittleEndianConsts.INT_SIZE;
  45. // NumberOfObjects (2 bytes): A 16-bit unsigned integer that specifies the number
  46. // of graphics objects that are defined in the entire metafile. These objects include
  47. // brushes, pens, and the other objects
  48. numberOfObjects = leis.readUShort();
  49. bytesLeft -= LittleEndianConsts.SHORT_SIZE;
  50. // MaxRecord (4 bytes): A 32-bit unsigned integer that specifies the size of the
  51. // largest record used in the metafile (in 16-bit elements).
  52. maxRecord = leis.readUInt();
  53. bytesLeft -= LittleEndianConsts.INT_SIZE;
  54. // NumberOfMembers (2 bytes): A 16-bit unsigned integer that is not used.
  55. // It SHOULD be 0x0000.
  56. numberOfMembers = leis.readUShort();
  57. bytesLeft -= LittleEndianConsts.SHORT_SIZE;
  58. if (bytesLeft > 0) {
  59. long len = leis.skip(bytesLeft);
  60. assert(len == bytesLeft);
  61. }
  62. }
  63. }