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.

HemfPlusHeader.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.hemf.record.emfplus;
  16. import java.io.IOException;
  17. import org.apache.poi.util.Internal;
  18. import org.apache.poi.util.LittleEndianConsts;
  19. import org.apache.poi.util.LittleEndianInputStream;
  20. @Internal
  21. public class HemfPlusHeader implements HemfPlusRecord {
  22. private int flags;
  23. private long version; //hack for now; replace with EmfPlusGraphicsVersion object
  24. private long emfPlusFlags;
  25. private long logicalDpiX;
  26. private long logicalDpiY;
  27. @Override
  28. public HemfPlusRecordType getEmfPlusRecordType() {
  29. return HemfPlusRecordType.header;
  30. }
  31. public int getFlags() {
  32. return flags;
  33. }
  34. @Override
  35. public long init(LittleEndianInputStream leis, long dataSize, long recordId, int flags) throws IOException {
  36. this.flags = flags;
  37. version = leis.readUInt();
  38. // verify MetafileSignature (20 bits) == 0xDBC01 and
  39. // GraphicsVersion (12 bits) in (1 or 2)
  40. assert((version & 0xFFFFFA00) == 0xDBC01000L && ((version & 0x3FF) == 1 || (version & 0x3FF) == 2));
  41. emfPlusFlags = leis.readUInt();
  42. logicalDpiX = leis.readUInt();
  43. logicalDpiY = leis.readUInt();
  44. return 4* LittleEndianConsts.INT_SIZE;
  45. }
  46. public long getVersion() {
  47. return version;
  48. }
  49. public long getEmfPlusFlags() {
  50. return emfPlusFlags;
  51. }
  52. public long getLogicalDpiX() {
  53. return logicalDpiX;
  54. }
  55. public long getLogicalDpiY() {
  56. return logicalDpiY;
  57. }
  58. @Override
  59. public String toString() {
  60. return "HemfPlusHeader{" +
  61. "flags=" + flags +
  62. ", version=" + version +
  63. ", emfPlusFlags=" + emfPlusFlags +
  64. ", logicalDpiX=" + logicalDpiX +
  65. ", logicalDpiY=" + logicalDpiY +
  66. '}';
  67. }
  68. }