From 12bf6b6d32fd173908a51daaf8138e3d0e7c7359 Mon Sep 17 00:00:00 2001 From: Said Ryan Ackley Date: Tue, 1 Jul 2003 23:59:59 +0000 Subject: [PATCH] Praveen's contribution git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353187 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hwpf/model/hdftypes/Ffn.java | 148 +++++++++++++++++ .../poi/hwpf/model/hdftypes/FontTable.java | 154 ++++++++++++++++++ 2 files changed, 302 insertions(+) create mode 100644 src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/Ffn.java create mode 100644 src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/FontTable.java diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/Ffn.java b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/Ffn.java new file mode 100644 index 0000000000..92113a3abf --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/Ffn.java @@ -0,0 +1,148 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +package org.apache.poi.hwpf.model.hdftypes; + +import org.apache.poi.util.BitField; +import org.apache.poi.util.LittleEndian; + + +public class Ffn +{ + private int field1_cbFfnM1; //total length of FFN - 1. + private byte field2; + private static BitField _prq = new BitField(0x0003);// pitch request + private static BitField _fTrueType = new BitField(0x0004);// when 1, font is a TrueType font + private static BitField _ff = new BitField(0x0070); + private short field3_wWeight;// base weight of font + private byte field4_chs;// character set identifier + private byte field5_ixchSzAlt; // index into ffn.szFfn to the name of + // the alternate font + private byte [] panose = new byte[10]; //???? + private byte [] fontSig = new byte[24]; //???? + + // zero terminated string that records name of font, cuurently not + // supporting Extended chars + private char [] xszFfn; + private int xszFfnLength; + + public Ffn(byte[] buf, int offset) + { + field1_cbFfnM1 = LittleEndian.getUnsignedByte(buf, offset); + offset += LittleEndian.BYTE_SIZE; + field2 = buf[offset]; + offset += LittleEndian.BYTE_SIZE; + field3_wWeight = LittleEndian.getShort(buf, offset); + offset += LittleEndian.SHORT_SIZE; + field4_chs = buf[offset]; + offset += LittleEndian.BYTE_SIZE; + field5_ixchSzAlt = buf[offset]; + offset += LittleEndian.BYTE_SIZE; + + // read panose and fs so we can write them back out. + System.arraycopy(buf, offset, panose, 0, panose.length); + offset += panose.length; + System.arraycopy(buf, offset, fontSig, 0, fontSig.length); + offset += fontSig.length; + + xszFfnLength = this.getSize() - offset; + xszFfn = new char[xszFfnLength]; + + for(int i = 0; i < xszFfnLength; i++) + { + xszFfn[i] = (char)LittleEndian.getUnsignedByte(buf, offset); + offset += LittleEndian.BYTE_SIZE; + } + + + } + + public int getField1_cbFfnM1() + { + return field1_cbFfnM1; + } + + public int getSize() + { + return (field1_cbFfnM1 + 1); + } + + public char [] getMainFontName() + { + char [] temp = new char[field5_ixchSzAlt]; + System.arraycopy(xszFfn,0,temp,0,temp.length); + return temp; + } + + public char [] getAltFontName() + { + char [] temp = new char[xszFfnLength - field5_ixchSzAlt]; + System.arraycopy(xszFfn, field5_ixchSzAlt, temp, 0, temp.length); + return temp; + } + + public void setField1_cbFfnM1(short field1_cbFfnM1) + { + this.field1_cbFfnM1 = field1_cbFfnM1; + } + + protected byte[] toByteArray() + { + //return buf; + return null; + } + + +} + diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/FontTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/FontTable.java new file mode 100644 index 0000000000..7384be129f --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/FontTable.java @@ -0,0 +1,154 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +package org.apache.poi.hwpf.model.hdftypes; + +import org.apache.poi.util.BitField; +import org.apache.poi.util.LittleEndian; + + +public class FontTable +{ + private short exntdChar; // strings are extended character if = 0xFFFF + private short stringCount; // how many strings are included in the string table + private short extraDataSz; // size in bytes of the extra data + + private int lcbSttbfffn; // count of bytes in sttbfffn + private boolean isExtndChar; + + + // FFN structure containing strings of font names + private Ffn [] fontNames = null; + + public FontTable(byte[] buf, int offset, int lcbSttbfffn) + { + this.lcbSttbfffn = lcbSttbfffn; + + exntdChar = LittleEndian.getShort(buf, offset); + offset += LittleEndian.SHORT_SIZE; + stringCount = LittleEndian.getShort(buf, offset); + offset += LittleEndian.SHORT_SIZE; + extraDataSz = LittleEndian.getShort(buf, offset); + offset += LittleEndian.SHORT_SIZE; + + if ((exntdChar & 0xFFFF) == 0xFFFF) + { + isExtndChar = true; + } + else + { + isExtndChar = false; + } + + fontNames = new Ffn[stringCount]; //Ffn corresponds to a Pascal style String in STTBF. + + for(int i = 0;i= this.getSize()) + { + System.out.println("Total size of Sttbfn mismatched with calculated size"); + break; + } + + fontNames[i] = new Ffn(buf,offset); + offset += fontNames[i].getSize(); + } + } + + public boolean isExtndChar() + { + return isExtndChar; + } + + public short getStringCount() + { + return stringCount; + } + + public int getSize() + { + return lcbSttbfffn; + } + + public char [] getMainFont(int chpFtc ) + { + if(chpFtc >= stringCount) + { + System.out.println("Mismatch in chpFtc with stringCount"); + return null; + } + + return fontNames[chpFtc].getMainFontName(); + } + + public char [] getAltFont(int chpFtc ) + { + if(chpFtc >= stringCount) + { + System.out.println("Mismatch in chpFtc with stringCount"); + return null; + } + + return fontNames[chpFtc].getAltFontName(); + } + + public void setStringCount(short stringCount) + { + this.stringCount = stringCount; + } + + +} + -- 2.39.5