123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- /* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- ==================================================================== */
-
- package org.apache.poi.hemf.record.emfplus;
-
-
- import java.io.IOException;
-
- import org.apache.poi.util.BitField;
- import org.apache.poi.util.BitFieldFactory;
- import org.apache.poi.util.Internal;
- import org.apache.poi.util.LittleEndianConsts;
- import org.apache.poi.util.LittleEndianInputStream;
-
- @Internal
- public class HemfPlusHeader implements HemfPlusRecord {
- /**
- * The GraphicsVersion enumeration defines versions of operating system graphics that are used to
- * create EMF+ metafiles.
- */
- public enum GraphicsVersion {
- V1(0x0001),
- V1_1(0x0002)
- ;
-
- public final int id;
-
- GraphicsVersion(int id) {
- this.id = id;
- }
-
- public static GraphicsVersion valueOf(int id) {
- for (GraphicsVersion wrt : values()) {
- if (wrt.id == id) return wrt;
- }
- return null;
- }
- }
-
-
- private int flags;
- private final EmfPlusGraphicsVersion version = new EmfPlusGraphicsVersion();
- private long emfPlusFlags;
- private long logicalDpiX;
- private long logicalDpiY;
-
- @Override
- public HemfPlusRecordType getEmfPlusRecordType() {
- return HemfPlusRecordType.header;
- }
-
- public int getFlags() {
- return flags;
- }
-
- @Override
- public long init(LittleEndianInputStream leis, long dataSize, long recordId, int flags) throws IOException {
- this.flags = flags;
- version.init(leis);
-
- assert(version.getMetafileSignature() == 0xDBC01 && version.getGraphicsVersion() != null);
-
- emfPlusFlags = leis.readUInt();
-
- logicalDpiX = leis.readUInt();
- logicalDpiY = leis.readUInt();
- return 4* LittleEndianConsts.INT_SIZE;
- }
-
- public EmfPlusGraphicsVersion getVersion() {
- return version;
- }
-
- public long getEmfPlusFlags() {
- return emfPlusFlags;
- }
-
- public long getLogicalDpiX() {
- return logicalDpiX;
- }
-
- public long getLogicalDpiY() {
- return logicalDpiY;
- }
-
- @Override
- public String toString() {
- return "HemfPlusHeader{" +
- "flags=" + flags +
- ", version=" + version +
- ", emfPlusFlags=" + emfPlusFlags +
- ", logicalDpiX=" + logicalDpiX +
- ", logicalDpiY=" + logicalDpiY +
- '}';
- }
-
- public static class EmfPlusGraphicsVersion {
- private static final BitField METAFILE_SIGNATURE = BitFieldFactory.getInstance(0xFFFFF000);
-
- private static final BitField GRAPHICS_VERSION = BitFieldFactory.getInstance(0x00000FFF);
-
-
- private int metafileSignature;
- private GraphicsVersion graphicsVersion;
-
-
- public int getMetafileSignature() {
- return metafileSignature;
- }
-
- public GraphicsVersion getGraphicsVersion() {
- return graphicsVersion;
- }
-
- public long init(LittleEndianInputStream leis) throws IOException {
- int val = leis.readInt();
- // A value that identifies the type of metafile. The value for an EMF+ metafile is 0xDBC01.
- metafileSignature = METAFILE_SIGNATURE.getValue(val);
- // The version of operating system graphics. This value MUST be defined in the GraphicsVersion enumeration
- graphicsVersion = GraphicsVersion.valueOf(GRAPHICS_VERSION.getValue(val));
-
- return LittleEndianConsts.INT_SIZE;
- }
-
- public String toString() {
- return "{ metafileSignature=0x"+Integer.toHexString(metafileSignature)+
- " , graphicsVersion='"+graphicsVersion+"' }";
- }
- }
- }
|