Sorry Ryan I was on leave suffering from bad cold & fever, I couldnt
proceed any more.
Currently I am breaking my head to put into form a code that can modify an
existing tableStream read for some very basic features like...
(Provided that the input Doc file has only 1 single word ) (tommorow
Deadline!!!!!!!!!!)
1. Add one more word
2. Change the format of the added word (to a different font or to
uppercase or Bold etc..).
then write out this stream to create the new Doc file.
For this I defenitely need your help, I will be disturbing you with some
doubts. Please help me.
By the way why have u commented most parts of the new StyleSheet.java??
any problems in code??
Thanks & Regards
Praveen
"Ryan Ackley" <[EMAIL PROTECTED]>
26/06/2003 07:11
Please respond to "POI Developers List"
To: "POI Developers List" <[EMAIL PROTECTED]>
cc:
Subject: Re: HWPF again
Thanks Praveen, I will commit it as soon as I get a chance. I haven't had
much time to work on it tonight because I have to be up early tomorrow
morning. If you are looking for something else to do, you can write unit
tests for what is already there.
Ryan
----- Original Message -----
From: "Praveen Mathew" <[EMAIL PROTECTED]>
To: "POI Developers List" <[EMAIL PROTECTED]>
Sent: Wednesday, June 25, 2003 12:22 PM
Subject: Re: HWPF again
> Hi,
>
> The enhanced Fontable class & Ffn class are given below...
>
> Ffn.java....
>
> package org.apache.poi.hwpf.model.hdftypes;
>
> import org.apache.poi.util.BitField;
> import org.apache.poi.util.LittleEndian;
>
>
> public class Ffn
> {
> private byte 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 [] fs = new byte[24]; //????
>
> // zero terminated string that records name of font, cuurently
not
> supporting Extended chars
>
> private char [] xszFfn;
> private byte xszFfnLength;
>
> public Ffn(byte[] buf, int offset)
> {
> field1_cbFfnM1 = LittleEndian.getUnsignedByte(buf,
> offset);
> offset += LittleEndian.BYTE_SIZE;
> field2 = LittleEndian.getUnsignedByte(buf, offset);
> offset += LittleEndian.BYTE_SIZE;
> field3_wWeight = LittleEndian.getShort(buf, offset);
> offset += LittleEndian.SHORT_SIZE;
> field4_chs = LittleEndian.getUnsignedByte(buf, offset);
> offset += LittleEndian.BYTE_SIZE;
> field5_ixchSzAltx = LittleEndian.getUnsignedByte(buf,
> offset);
> offset += LittleEndian.BYTE_SIZE;
>
> // not reading panose & fs, just skipping them
> offset += panose.length;
> offset += fs.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 short GetField1_cbFfnM1()
> {
> return field1_cbFfnM1;
> }
>
> public short 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 short SetField1_cbFfnM1(short field1_cbFfnM1)
> {
> this.field1_cbFfnM1 = field1_cbFfnM1;
> }
>
> protected byte[] toByteArray()
> {
> //
>
> return buf;
> }
>
>
> }
>
>
> FontTable.java......
>
> 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<stringCount; i++)
> {
> // some mistake in the fields we have chosen
> if(offset >= 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 short 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 short SetStringCount(short stringCount)
> {
> this.stringCount = stringCount;
> }
>
>
> }
>
> Thanks & Regards
> Praveen
>
> Praveen Mathew
> IBM Software Labs,Airport Road,
> Bangalore - 560 017,India.
> Ph : +91- 80 - 504 4609 (Direct)
> +91 - 80 - 5262355 Extn: 3609
> Email: [EMAIL PROTECTED]
>
>
>
>
> "Ryan Ackley" <[EMAIL PROTECTED]>
> 25/06/2003 16:07
> Please respond to "POI Developers List"
>
>
> To: "POI Developers List" <[EMAIL PROTECTED]>
> cc:
> Subject: Re: HWPF again
>
>
>
> Not sure.
>
> ----- Original Message -----
> From: "Praveen Mathew" <[EMAIL PROTECTED]>
> To: "POI Developers List" <[EMAIL PROTECTED]>
> Sent: Wednesday, June 25, 2003 3:15 AM
> Subject: Re: HWPF again
>
>
> > Ryan,
> >
> > In Pascal style strings they are talking about an Extra
Data
> > with each String.
> >
> > For an FFn structure is this extra Data going to be the alternate Font
> in
> > each XCHAR[] ????
> >
> > Thanks & Regards
> > Praveen
> >
> > Praveen Mathew
> > IBM Software Labs,Airport Road,
> > Bangalore - 560 017,India.
> > Ph : +91- 80 - 504 4609 (Direct)
> > +91 - 80 - 5262355 Extn: 3609
> > Email: [EMAIL PROTECTED]
> >
> >
> >
> >
> > "Ryan Ackley" <[EMAIL PROTECTED]>
> > 24/06/2003 19:35
> > Please respond to "POI Developers List"
> >
> >
> > To: "POI Developers List" <[EMAIL PROTECTED]>
> > cc:
> > Subject: Re: HWPF again
> >
> >
> >
> >
> > ----- Original Message -----
> > From: "Praveen Mathew" <[EMAIL PROTECTED]>
> > To: "POI Developers List" <[EMAIL PROTECTED]>
> > Sent: Tuesday, June 24, 2003 8:07 AM
> > Subject: Re: HWPF again
> >
> >
> > > Ryan,
> > >
> > > According to spec an STTBF has 3 shorts followed by
the
> > String and extra Data following it. It also
> > > says that all the pascal strings are concatenated one after another
> > until
> > the length of the STTBF
> > > recorded in the FIB is exhausted ( lcbSttbfffn).
> > >
> > > What I understand is STTBF is one single BLOCK in table Stream, with
> the
> > > small header (3 shorts), & then Strings (font names) concatenated to
> > each
> > > other.
> > >
> > > I suppose this should be implemented using an array of Strings which
> has
> > > 1. initial byte storing the no: of characters in the string
excluding
> > > itself
> > > 2. last 2 bytes(short) having extra data for that string.
> >
> > An STTBF and STTBFFFN are completely different because the STTBFFFN
uses
> > FFN
> > structures instead of Strings. So the first 3 shorts are there but
> instead
> > of Strings you have FFN structures. If you do create an STTBF class I
> > think
> > it should use byte arrays instead Strings so it can handle arbitrary
> data
> > and not just Strings.
> >
> > > My doubt:
> > > in the header I asumed a short indicating the size in bytes of the
> > extra
> > > data stored ( not able to find which string's data its refering?) ,
is
> > it
> > > correct? or is it the short after each String storing the extra data
?
> >
> > I believe the way you have done it is correct.
> >
> > > In case of Fontable i,e sttbfffn, we should replace the Strings with
> FFN
> > > structure acc to spec.
> > > but the spec of FFN structure says that it has some more header
> fields.
> > > My Doubt:
> > > is the XCHAR[] storing 2 strings i,e Main font & alternate
> font
> > > concatenated to each other?
> >
> > Yes, but both names are zero terminated. So there will be '\0'
character
> > between the Main and alternate font. XCHAR[] is the same as char[].
> >
> > > also 65 is the limit for these 2 combined??
> >
> > Yes, but I'm not sure if this is 65 bytes or 65 double-byte chars.
> >
> > > is cbFfnM1 the total no of bytes including the XCHAR[]
minus
> 1
> > ??
> >
> > I believe so.
> >
> > > is ixchSzAlt (the index) always 1 since XCHAR[0] is main
font
> > > XCHAR[1] is alternate font?
> >
> > No, I believe this is the index in XCHAR[] where the alternate font
> > starts.
> > XCHAR[] is an array of characters not Strings.
> >
> >
> > > Lastly for STTBFFFN we may have to use an array of FFN rit??
> >
> > Yes.
> >
> > > Also how will we track the end of STTBFFFN ??
> > > is it using lcbSttbfffn ???
> >
> > Yes.
> >
> > Keep asking me questions no matter how small. A lot of times I will
step
> > through the code with a debugger and it makes some things clearer.
> >
> > If you want to step through your FontTable class you need to get my
> latest
> > update from CVS. Add the following line to the end of the HWPFDocument
> > constructor:
> >
> > FontTable ft = new FontTable(_tableStream, _fib.getFcSttbfffn(),
> > _fib.getLcbSttbfffn());
> >
> > There is a main function in HWPFDocument whose only argument is Word
> file.
> > Just step into the above line of code.
> >
> > Keep asking questions!
> >
> > Ryan
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]