KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hdf > extractor > StyleSheet


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19
20 package org.apache.poi.hdf.extractor;
21
22 import java.util.*;
23
24 /**
25  * Comment me
26  *
27  * @author Ryan Ackley
28  */

29
30 public class StyleSheet
31 {
32
33   private static final int NIL_STYLE = 4095;
34   private static final int PAP_TYPE = 1;
35   private static final int CHP_TYPE = 2;
36   private static final int SEP_TYPE = 4;
37   private static final int TAP_TYPE = 5;
38   //Vector _styleDescriptions;
39
StyleDescription _nilStyle = new StyleDescription();
40   StyleDescription[] _styleDescriptions;
41
42   public StyleSheet(byte[] styleSheet)
43   {
44       int stshiLength = Utils.convertBytesToShort(styleSheet, 0);
45       int stdCount = Utils.convertBytesToShort(styleSheet, 2);
46       int baseLength = Utils.convertBytesToShort(styleSheet, 4);
47       int[] rgftc = new int[3];
48
49       rgftc[0] = Utils.convertBytesToInt(styleSheet, 14);
50       rgftc[1] = Utils.convertBytesToInt(styleSheet, 18);
51       rgftc[2] = Utils.convertBytesToInt(styleSheet, 22);
52
53       int offset = 0;
54       _styleDescriptions = new StyleDescription[stdCount];
55       for(int x = 0; x < stdCount; x++)
56       {
57           int stdOffset = (2 + stshiLength) + offset;
58           int stdSize = Utils.convertBytesToShort(styleSheet, stdOffset);
59           if(stdSize > 0)
60           {
61               byte[] std = new byte[stdSize];
62
63               //get past the size
64
stdOffset += 2;
65               System.arraycopy(styleSheet, stdOffset, std, 0, stdSize);
66               StyleDescription aStyle = new StyleDescription(std, baseLength, true);
67
68               _styleDescriptions[x] = aStyle;
69           }
70
71
72           offset += stdSize + 2;
73
74       }
75       for(int x = 0; x < _styleDescriptions.length; x++)
76       {
77           if(_styleDescriptions[x] != null)
78           {
79               createPap(x);
80               createChp(x);
81           }
82       }
83   }
84   private void createPap(int istd)
85   {
86       StyleDescription sd = _styleDescriptions[istd];
87       PAP pap = sd.getPAP();
88       byte[] papx = sd.getPAPX();
89       int baseIndex = sd.getBaseStyle();
90       if(pap == null && papx != null)
91       {
92           PAP parentPAP = _nilStyle.getPAP();
93           if(baseIndex != NIL_STYLE)
94           {
95
96               parentPAP = _styleDescriptions[baseIndex].getPAP();
97               if(parentPAP == null)
98               {
99                   createPap(baseIndex);
100                   parentPAP = _styleDescriptions[baseIndex].getPAP();
101               }
102
103           }
104
105           pap = (PAP)uncompressProperty(papx, parentPAP, this);
106           sd.setPAP(pap);
107       }
108   }
109   private void createChp(int istd)
110   {
111       StyleDescription sd = _styleDescriptions[istd];
112       CHP chp = sd.getCHP();
113       byte[] chpx = sd.getCHPX();
114       int baseIndex = sd.getBaseStyle();
115       if(chp == null && chpx != null)
116       {
117           CHP parentCHP = _nilStyle.getCHP();
118           if(baseIndex != NIL_STYLE)
119           {
120
121               parentCHP = _styleDescriptions[baseIndex].getCHP();
122               if(parentCHP == null)
123               {
124                   createChp(baseIndex);
125                   parentCHP = _styleDescriptions[baseIndex].getCHP();
126               }
127
128           }
129
130           chp = (CHP)uncompressProperty(chpx, parentCHP, this);
131           sd.setCHP(chp);
132       }
133   }
134   public StyleDescription getStyleDescription(int x)
135   {
136       return _styleDescriptions[x];
137   }
138   static void doCHPOperation(CHP oldCHP, CHP newCHP, int operand, int param,
139                              byte[] varParam, byte[] grpprl, int offset,
140                              StyleSheet styleSheet)
141   {
142       switch(operand)
143       {
144           case 0:
145                newCHP._fRMarkDel = getFlag(param);
146                break;
147           case 0x1:
148                newCHP._fRMark = getFlag(param);
149                break;
150           case 0x2:
151                break;
152           case 0x3:
153                newCHP._fcPic = param;
154                newCHP._fSpec = true;
155                break;
156           case 0x4:
157                newCHP._ibstRMark = (short)param;
158                break;
159           case 0x5:
160                newCHP._dttmRMark[0] = Utils.convertBytesToShort(grpprl, (offset - 4));
161                newCHP._dttmRMark[1] = Utils.convertBytesToShort(grpprl, (offset - 2));
162                break;
163           case 0x6:
164                newCHP._fData = getFlag(param);
165                break;
166           case 0x7:
167                //don't care about this
168
break;
169           case 0x8:
170                short chsDiff = (short)((param & 0xff0000) >>> 8);
171                newCHP._fChsDiff = getFlag(chsDiff);
172                newCHP._chse = (short)(param & 0xffff);
173                break;
174           case 0x9:
175                newCHP._fSpec = true;
176                newCHP._ftcSym = (short)Utils.convertBytesToShort(varParam, 0);
177                newCHP._xchSym = (short)Utils.convertBytesToShort(varParam, 2);
178                break;
179           case 0xa:
180                newCHP._fOle2 = getFlag(param);
181                break;
182           case 0xb:
183                //?
184
break;
185           case 0xc:
186                newCHP._icoHighlight = (byte)param;
187                newCHP._highlighted = getFlag(param);
188                break;
189           case 0xd:
190                break;
191           case 0xe:
192                newCHP._fcObj = param;
193                break;
194           case 0xf:
195                break;
196           case 0x10:
197                //?
198
break;
199           case 0x11:
200                break;
201           case 0x12:
202                break;
203           case 0x13:
204                break;
205           case 0x14:
206                break;
207           case 0x15:
208                break;
209           case 0x16:
210                break;
211           case 0x17:
212                break;
213           case 0x18:
214                break;
215           case 0x19:
216                break;
217           case 0x1a:
218                break;
219           case 0x1b:
220                break;
221           case 0x1c:
222                break;
223           case 0x1d:
224                break;
225           case 0x1e:
226                break;
227           case 0x1f:
228                break;
229           case 0x20:
230                break;
231           case 0x21:
232                break;
233           case 0x22:
234                break;
235           case 0x23:
236                break;
237           case 0x24:
238                break;
239           case 0x25:
240                break;
241           case 0x26:
242                break;
243           case 0x27:
244                break;
245           case 0x28:
246                break;
247           case 0x29:
248                break;
249           case 0x2a:
250                break;
251           case 0x2b:
252                break;
253           case 0x2c:
254                break;
255           case 0x2d:
256                break;
257           case 0x2e:
258                break;
259           case 0x2f:
260                break;
261           case 0x30:
262                newCHP._istd = param;
263                break;
264           case 0x31:
265                //permutation vector for fast saves who cares!
266
break;
267           case 0x32:
268                newCHP._bold = false;
269                newCHP._italic = false;
270                newCHP._fOutline = false;
271                newCHP._fStrike = false;
272                newCHP._fShadow = false;
273                newCHP._fSmallCaps = false;
274                newCHP._fCaps = false;
275                newCHP._fVanish = false;
276                newCHP._kul = 0;
277                newCHP._ico = 0;
278                break;
279           case 0x33:
280                newCHP.copy(oldCHP);
281                return;
282           case 0x34:
283                break;
284           case 0x35:
285                newCHP._bold = getCHPFlag((byte)param, oldCHP._bold);
286                break;
287           case 0x36:
288                newCHP._italic = getCHPFlag((byte)param, oldCHP._italic);
289                break;
290           case 0x37:
291                newCHP._fStrike = getCHPFlag((byte)param, oldCHP._fStrike);
292                break;
293           case 0x38:
294                newCHP._fOutline = getCHPFlag((byte)param, oldCHP._fOutline);
295                break;
296           case 0x39:
297                newCHP._fShadow = getCHPFlag((byte)param, oldCHP._fShadow);
298                break;
299           case 0x3a:
300                newCHP._fSmallCaps = getCHPFlag((byte)param, oldCHP._fSmallCaps);
301                break;
302           case 0x3b:
303                newCHP._fCaps = getCHPFlag((byte)param, oldCHP._fCaps);
304                break;
305           case 0x3c:
306                newCHP._fVanish = getCHPFlag((byte)param, oldCHP._fVanish);
307                break;
308           case 0x3d:
309                newCHP._ftc = (short)param;
310                break;
311           case 0x3e:
312                newCHP._kul = (byte)param;
313                break;
314           case 0x3f:
315                int hps = param & 0xff;
316                if(hps != 0)
317                {
318                   newCHP._hps = hps;
319                }
320                byte cInc = (byte)(((byte)(param & 0xfe00) >>> 4) >> 1);
321                if(cInc != 0)
322                {
323                   newCHP._hps = Math.max(newCHP._hps + (cInc * 2), 2);
324                }
325                byte hpsPos = (byte)((param & 0xff0000) >>> 8);
326                if(hpsPos != 0x80)
327                {
328                   newCHP._hpsPos = hpsPos;
329                }
330                boolean fAdjust = (param & 0x0100) > 0;
331                if(fAdjust && hpsPos != 128 && hpsPos != 0 && oldCHP._hpsPos == 0)
332                {
333                   newCHP._hps = Math.max(newCHP._hps + (-2), 2);
334                }
335                if(fAdjust && hpsPos == 0 && oldCHP._hpsPos != 0)
336                {
337                   newCHP._hps = Math.max(newCHP._hps + 2, 2);
338                }
339                break;
340           case 0x40:
341                newCHP._dxaSpace = param;
342                break;
343           case 0x41:
344                newCHP._lidDefault = (short)param;
345                break;
346           case 0x42:
347                newCHP._ico = (byte)param;
348                break;
349           case 0x43:
350                newCHP._hps = param;
351                break;
352           case 0x44:
353                byte hpsLvl = (byte)param;
354                newCHP._hps = Math.max(newCHP._hps + (hpsLvl * 2), 2);
355                break;
356           case 0x45:
357                newCHP._hpsPos = (short)param;
358                break;
359           case 0x46:
360                if(param != 0)
361                {
362                   if(oldCHP._hpsPos == 0)
363                   {
364                       newCHP._hps = Math.max(newCHP._hps + (-2), 2);
365                   }
366                }
367                else
368                {
369                   if(oldCHP._hpsPos != 0)
370                   {
371                       newCHP._hps = Math.max(newCHP._hps + 2, 2);
372                   }
373                }
374                break;
375           case 0x47:
376                CHP genCHP = new CHP();
377                genCHP._ftc = 4;
378                genCHP = (CHP)uncompressProperty(varParam, genCHP, styleSheet);
379                CHP styleCHP = styleSheet.getStyleDescription(oldCHP._baseIstd).getCHP();
380                if(genCHP._bold == newCHP._bold)
381                {
382                   newCHP._bold = styleCHP._bold;
383                }
384                if(genCHP._italic == newCHP._italic)
385                {
386                   newCHP._italic = styleCHP._italic;
387                }
388                if(genCHP._fSmallCaps == newCHP._fSmallCaps)
389                {
390                   newCHP._fSmallCaps = styleCHP._fSmallCaps;
391                }
392                if(genCHP._fVanish == newCHP._fVanish)
393                {
394                   newCHP._fVanish = styleCHP._fVanish;
395                }
396                if(genCHP._fStrike == newCHP._fStrike)
397                {
398                   newCHP._fStrike = styleCHP._fStrike;
399                }
400                if(genCHP._fCaps == newCHP._fCaps)
401                {
402                   newCHP._fCaps = styleCHP._fCaps;
403                }
404                if(genCHP._ftcAscii == newCHP._ftcAscii)
405                {
406                   newCHP._ftcAscii = styleCHP._ftcAscii;
407                }
408                if(genCHP._ftcFE == newCHP._ftcFE)
409                {
410                   newCHP._ftcFE = styleCHP._ftcFE;
411                }
412                if(genCHP._ftcOther == newCHP._ftcOther)
413                {
414                   newCHP._ftcOther = styleCHP._ftcOther;
415                }
416                if(genCHP._hps == newCHP._hps)
417                {
418                   newCHP._hps = styleCHP._hps;
419                }
420                if(genCHP._hpsPos == newCHP._hpsPos)
421                {
422                   newCHP._hpsPos = styleCHP._hpsPos;
423                }
424                if(genCHP._kul == newCHP._kul)
425                {
426                   newCHP._kul = styleCHP._kul;
427                }
428                if(genCHP._dxaSpace == newCHP._dxaSpace)
429                {
430                   newCHP._dxaSpace = styleCHP._dxaSpace;
431                }
432                if(genCHP._ico == newCHP._ico)
433                {
434                   newCHP._ico = styleCHP._ico;
435                }
436                if(genCHP._lidDefault == newCHP._lidDefault)
437                {
438                   newCHP._lidDefault = styleCHP._lidDefault;
439                }
440                if(genCHP._lidFE == newCHP._lidFE)
441                {
442                   newCHP._lidFE = styleCHP._lidFE;
443                }
444                break;
445           case 0x48:
446                newCHP._iss = (byte)param;
447                break;
448           case 0x49:
449                newCHP._hps = Utils.convertBytesToShort(varParam, 0);
450                break;
451           case 0x4a:
452                int increment = Utils.convertBytesToShort(varParam, 0);
453                newCHP._hps = Math.max(newCHP._hps + increment, 8);
454                break;
455           case 0x4b:
456                newCHP._hpsKern = param;
457                break;
458           case 0x4c:
459                doCHPOperation(oldCHP, newCHP, 0x47, param, varParam, grpprl, offset, styleSheet);
460                break;
461           case 0x4d:
462                float percentage = (float)param/100.0f;
463                int add = (int)((float)percentage * (float)newCHP._hps);
464                newCHP._hps += add;
465                break;
466           case 0x4e:
467                newCHP._ysr = (byte)param;
468                break;
469           case 0x4f:
470                newCHP._ftcAscii = (short)param;
471                break;
472           case 0x50:
473                newCHP._ftcFE = (short)param;
474                break;
475           case 0x51:
476                newCHP._ftcOther = (short)param;
477                break;
478           case 0x52:
479                break;
480           case 0x53:
481                newCHP._fDStrike = getFlag(param);
482                break;
483           case 0x54:
484                newCHP._fImprint = getFlag(param);
485                break;
486           case 0x55:
487                newCHP._fSpec = getFlag(param);
488                break;
489           case 0x56:
490                newCHP._fObj = getFlag(param);
491                break;
492           case 0x57:
493                newCHP._fPropMark = getFlag(varParam[0]);
494                newCHP._ibstPropRMark = (short)Utils.convertBytesToShort(varParam, 1);
495                newCHP._dttmPropRMark = Utils.convertBytesToInt(varParam, 3);
496                break;
497           case 0x58:
498                newCHP._fEmboss = getFlag(param);
499                break;
500           case 0x59:
501                newCHP._sfxtText = (byte)param;
502                break;
503           case 0x5a:
504                break;
505           case 0x5b:
506                break;
507           case 0x5c:
508                break;
509           case 0x5d:
510                break;
511           case 0x5e:
512                break;
513           case 0x5f:
514                break;
515           case 0x60:
516                break;
517           case 0x61:
518                break;
519           case 0x62:
520                newCHP._fDispFldRMark = getFlag(varParam[0]);
521                newCHP._ibstDispFldRMark = (short)Utils.convertBytesToShort(varParam, 1);
522                newCHP._dttmDispFldRMark = Utils.convertBytesToInt(varParam, 3);
523                System.arraycopy(varParam, 7, newCHP._xstDispFldRMark, 0, 32);
524                break;
525           case 0x63:
526                newCHP._ibstRMarkDel = (short)param;
527                break;
528           case 0x64:
529                newCHP._dttmRMarkDel[0] = Utils.convertBytesToShort(grpprl, offset - 4);
530                newCHP._dttmRMarkDel[1] = Utils.convertBytesToShort(grpprl, offset - 2);
531                break;
532           case 0x65:
533                newCHP._brc[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4);
534                newCHP._brc[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2);
535                break;
536           case 0x66:
537                newCHP._shd = (short)param;
538                break;
539           case 0x67:
540                break;
541           case 0x68:
542                break;
543           case 0x69:
544                break;
545           case 0x6a:
546                break;
547           case 0x6b:
548                break;
549           case 0x6c:
550                break;
551           case 0x6d:
552                newCHP._lidDefault = (short)param;
553                break;
554           case 0x6e:
555                newCHP._lidFE = (short)param;
556                break;
557           case 0x6f:
558                newCHP._idctHint = (byte)param;
559                break;
560       }
561   }
562
563   static Object JavaDoc uncompressProperty(byte[] grpprl, Object JavaDoc parent, StyleSheet styleSheet)
564   {
565     return uncompressProperty(grpprl, parent, styleSheet, true);
566   }
567
568
569   static Object JavaDoc uncompressProperty(byte[] grpprl, Object JavaDoc parent, StyleSheet styleSheet, boolean doIstd)
570   {
571       Object JavaDoc newProperty = null;
572       int offset = 0;
573       int propertyType = PAP_TYPE;
574
575
576       if(parent instanceof PAP)
577       {
578           try
579           {
580               newProperty = ((PAP)parent).clone();
581           }
582           catch(Exception JavaDoc e){}
583           if(doIstd)
584           {
585             ((PAP)newProperty)._istd = Utils.convertBytesToShort(grpprl, 0);
586
587             offset = 2;
588           }
589       }
590       else if(parent instanceof CHP)
591       {
592           try
593           {
594               newProperty = ((CHP)parent).clone();
595               ((CHP)newProperty)._baseIstd = ((CHP)parent)._istd;
596           }
597           catch(Exception JavaDoc e){}
598           propertyType = CHP_TYPE;
599       }
600       else if(parent instanceof SEP)
601       {
602           newProperty = parent;
603           propertyType = SEP_TYPE;
604       }
605       else if(parent instanceof TAP)
606       {
607           newProperty = parent;
608           propertyType = TAP_TYPE;
609           offset = 2;//because this is really just a papx
610
}
611       else
612       {
613           return null;
614       }
615
616       while(offset < grpprl.length)
617       {
618           short sprm = Utils.convertBytesToShort(grpprl, offset);
619           offset += 2;
620
621           byte spra = (byte)((sprm & 0xe000) >> 13);
622           int opSize = 0;
623           int param = 0;
624           byte[] varParam = null;
625
626           switch(spra)
627           {
628               case 0:
629               case 1:
630                    opSize = 1;
631                    param = grpprl[offset];
632                    break;
633               case 2:
634                    opSize = 2;
635                    param = Utils.convertBytesToShort(grpprl, offset);
636                    break;
637               case 3:
638                    opSize = 4;
639                    param = Utils.convertBytesToInt(grpprl, offset);
640                    break;
641               case 4:
642               case 5:
643                    opSize = 2;
644                    param = Utils.convertBytesToShort(grpprl, offset);
645                    break;
646               case 6://variable size
647

648                    //there is one sprm that is a very special case
649
if(sprm != (short)0xd608)
650                    {
651                      opSize = Utils.convertUnsignedByteToInt(grpprl[offset]);
652                      offset++;
653                    }
654                    else
655                    {
656                      opSize = Utils.convertBytesToShort(grpprl, offset) - 1;
657                      offset += 2;
658                    }
659                    varParam = new byte[opSize];
660                    System.arraycopy(grpprl, offset, varParam, 0, opSize);
661
662                    break;
663               case 7:
664                    opSize = 3;
665                    param = Utils.convertBytesToInt((byte)0, grpprl[offset + 2], grpprl[offset + 1], grpprl[offset]);
666                    break;
667               default:
668                   throw new RuntimeException JavaDoc("unrecognized pap opcode");
669           }
670
671           offset += opSize;
672           short operand = (short)(sprm & 0x1ff);
673           byte type = (byte)((sprm & 0x1c00) >> 10);
674           switch(propertyType)
675           {
676               case PAP_TYPE:
677                    if(type == 1)//papx stores TAP sprms along with PAP sprms
678
{
679                      doPAPOperation((PAP)newProperty, operand, param, varParam, grpprl,
680                                     offset, spra);
681                    }
682                    break;
683               case CHP_TYPE:
684
685                    doCHPOperation((CHP)parent, (CHP)newProperty, operand, param, varParam,
686                                   grpprl, offset, styleSheet);
687                    break;
688               case SEP_TYPE:
689
690                    doSEPOperation((SEP)newProperty, operand, param, varParam);
691                    break;
692               case TAP_TYPE:
693                    if(type == 5)
694                    {
695                      doTAPOperation((TAP)newProperty, operand, param, varParam);
696                    }
697                    break;
698           }
699
700
701       }
702       return newProperty;
703
704   }
705   static void doPAPOperation(PAP newPAP, int operand, int param,
706                              byte[] varParam, byte[] grpprl, int offset,
707                              int spra)
708   {
709       switch(operand)
710       {
711           case 0:
712                newPAP._istd = param;
713                break;
714           case 0x1:
715                //permuteIstd(newPAP, varParam);
716
break;
717           case 0x2:
718                if(newPAP._istd <=9 || newPAP._istd >=1)
719                {
720                   newPAP._istd += param;
721                   if(param > 0)
722                   {
723                       newPAP._istd = Math.max(newPAP._istd, 9);
724                   }
725                   else
726                   {
727                       newPAP._istd = Math.min(newPAP._istd, 1);
728                   }
729                }
730                break;
731           case 0x3:
732                newPAP._jc = (byte)param;
733                break;
734           case 0x4:
735                newPAP._fSideBySide = (byte)param;
736                break;
737           case 0x5:
738                newPAP._fKeep = (byte)param;
739                break;
740           case 0x6:
741                newPAP._fKeepFollow = (byte)param;
742                break;
743           case 0x7:
744                newPAP._fPageBreakBefore = (byte)param;
745                break;
746           case 0x8:
747                newPAP._brcl = (byte)param;
748                break;
749           case 0x9:
750                newPAP._brcp = (byte)param;
751                break;
752           case 0xa:
753                newPAP._ilvl = (byte)param;
754                break;
755           case 0xb:
756                newPAP._ilfo = param;
757                break;
758           case 0xc:
759                newPAP._fNoLnn = (byte)param;
760                break;
761           case 0xd:
762                /**@todo handle tabs*/
763                break;
764           case 0xe:
765                newPAP._dxaRight = param;
766                break;
767           case 0xf:
768                newPAP._dxaLeft = param;
769                break;
770           case 0x10:
771                newPAP._dxaLeft += param;
772                newPAP._dxaLeft = Math.max(0, newPAP._dxaLeft);
773                break;
774           case 0x11:
775                newPAP._dxaLeft1 = param;
776                break;
777           case 0x12:
778                newPAP._lspd[0] = Utils.convertBytesToShort(grpprl, offset - 4);
779                newPAP._lspd[1] = Utils.convertBytesToShort(grpprl, offset - 2);
780                break;
781           case 0x13:
782                newPAP._dyaBefore = param;
783                break;
784           case 0x14:
785                newPAP._dyaAfter = param;
786                break;
787           case 0x15:
788                /**@todo handle tabs*/
789                break;
790           case 0x16:
791                newPAP._fInTable = (byte)param;
792                break;
793           case 0x17:
794                newPAP._fTtp =(byte)param;
795                break;
796           case 0x18:
797                newPAP._dxaAbs = param;
798                break;
799           case 0x19:
800                newPAP._dyaAbs = param;
801                break;
802           case 0x1a:
803                newPAP._dxaWidth = param;
804                break;
805           case 0x1b:
806                /** @todo handle paragraph postioning*/
807                /*byte pcVert = (param & 0x0c) >> 2;
808                byte pcHorz = param & 0x03;
809                if(pcVert != 3)
810                {
811                   newPAP._pcVert = pcVert;
812                }
813                if(pcHorz != 3)
814                {
815                   newPAP._pcHorz = pcHorz;
816                }*/

817                break;
818           case 0x1c:
819                newPAP._brcTop1 = (short)param;
820                break;
821           case 0x1d:
822                newPAP._brcLeft1 = (short)param;
823                break;
824           case 0x1e:
825                newPAP._brcBottom1 = (short)param;
826                break;
827           case 0x1f:
828                newPAP._brcRight1 = (short)param;
829                break;
830           case 0x20:
831                newPAP._brcBetween1 = (short)param;
832                break;
833           case 0x21:
834                newPAP._brcBar1 = (byte)param;
835                break;
836           case 0x22:
837                newPAP._dxaFromText = param;
838                break;
839           case 0x23:
840                newPAP._wr = (byte)param;
841                break;
842           case 0x24:
843                newPAP._brcTop[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4);
844                newPAP._brcTop[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2);
845                break;
846           case 0x25:
847                newPAP._brcLeft[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4);
848                newPAP._brcLeft[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2);
849                break;
850           case 0x26:
851                newPAP._brcBottom[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4);
852                newPAP._brcBottom[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2);
853                break;
854           case 0x27:
855                newPAP._brcRight[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4);
856                newPAP._brcRight[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2);
857                break;
858           case 0x28:
859                newPAP._brcBetween[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4);
860                newPAP._brcBetween[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2);
861                break;
862           case 0x29:
863                newPAP._brcBar[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4);
864                newPAP._brcBar[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2);
865                break;
866           case 0x2a:
867                newPAP._fNoAutoHyph = (byte)param;
868                break;
869           case 0x2b:
870                newPAP._dyaHeight = param;
871                break;
872           case 0x2c:
873                newPAP._dcs = param;
874                break;
875           case 0x2d:
876                newPAP._shd = param;
877                break;
878           case 0x2e:
879                newPAP._dyaFromText = param;
880                break;
881           case 0x2f:
882                newPAP._dxaFromText = param;
883                break;
884           case 0x30:
885                newPAP._fLocked = (byte)param;
886                break;
887           case 0x31:
888                newPAP._fWindowControl = (byte)param;
889                break;
890           case 0x32:
891                //undocumented
892
break;
893           case 0x33:
894                newPAP._fKinsoku = (byte)param;
895                break;
896           case 0x34:
897                newPAP._fWordWrap = (byte)param;
898                break;
899           case 0x35:
900                newPAP._fOverflowPunct = (byte)param;
901                break;
902           case 0x36:
903                newPAP._fTopLinePunct = (byte)param;
904                break;
905           case 0x37:
906                newPAP._fAutoSpaceDE = (byte)param;
907                break;
908           case 0x38:
909                newPAP._fAutoSpaceDN = (byte)param;
910                break;
911           case 0x39:
912                newPAP._wAlignFont = param;
913                break;
914           case 0x3a:
915                newPAP._fontAlign = (short)param;
916                break;
917           case 0x3b:
918                //obsolete
919
break;
920           case 0x3e:
921                newPAP._anld = varParam;
922                break;
923           case 0x3f:
924                //don't really need this. spec is confusing regarding this
925
//sprm
926
break;
927           case 0x40:
928                //newPAP._lvl = param;
929
break;
930           case 0x41:
931                //?
932
break;
933           case 0x43:
934                //?
935
break;
936           case 0x44:
937                //?
938
break;
939           case 0x45:
940                if(spra == 6)
941                {
942                   newPAP._numrm = varParam;
943                }
944                else
945                {
946                   /**@todo handle large PAPX from data stream*/
947                }
948                break;
949
950           case 0x47:
951                newPAP._fUsePgsuSettings = (byte)param;
952                break;
953           case 0x48:
954                newPAP._fAdjustRight = (byte)param;
955                break;
956           default:
957                break;
958       }
959   }
960   static void doTAPOperation(TAP newTAP, int operand, int param, byte[] varParam)
961   {
962       switch(operand)
963       {
964           case 0:
965                newTAP._jc = (short)param;
966                break;
967           case 0x01:
968           {
969                int adjust = param - (newTAP._rgdxaCenter[0] + newTAP._dxaGapHalf);
970                for(int x = 0; x < newTAP._itcMac; x++)
971                {
972                   newTAP._rgdxaCenter[x] += adjust;
973                }
974                break;
975           }
976           case 0x02:
977                if(newTAP._rgdxaCenter != null)
978                {
979                  int adjust = newTAP._dxaGapHalf - param;
980                  newTAP._rgdxaCenter[0] += adjust;
981                }
982                newTAP._dxaGapHalf = param;
983                break;
984           case 0x03:
985                newTAP._fCantSplit = getFlag(param);
986                break;
987           case 0x04:
988                newTAP._fTableHeader = getFlag(param);
989                break;
990           case 0x05:
991
992                newTAP._brcTop[0] = Utils.convertBytesToShort(varParam, 0);
993                newTAP._brcTop[1] = Utils.convertBytesToShort(varParam, 2);
994
995                newTAP._brcLeft[0] = Utils.convertBytesToShort(varParam, 4);
996                newTAP._brcLeft[1] = Utils.convertBytesToShort(varParam, 6);
997
998                newTAP._brcBottom[0] = Utils.convertBytesToShort(varParam, 8);
999                newTAP._brcBottom[1] = Utils.convertBytesToShort(varParam, 10);
1000
1001               newTAP._brcRight[0] = Utils.convertBytesToShort(varParam, 12);
1002               newTAP._brcRight[1] = Utils.convertBytesToShort(varParam, 14);
1003
1004               newTAP._brcHorizontal[0] = Utils.convertBytesToShort(varParam, 16);
1005               newTAP._brcHorizontal[1] = Utils.convertBytesToShort(varParam, 18);
1006
1007               newTAP._brcVertical[0] = Utils.convertBytesToShort(varParam, 20);
1008               newTAP._brcVertical[1] = Utils.convertBytesToShort(varParam, 22);
1009               break;
1010          case 0x06:
1011               //obsolete, used in word 1.x
1012
break;
1013          case 0x07:
1014               newTAP._dyaRowHeight = param;
1015               break;
1016          case 0x08:
1017               //I use varParam[0] and newTAP._itcMac interchangably
1018
newTAP._itcMac = varParam[0];
1019               newTAP._rgdxaCenter = new short[varParam[0] + 1];
1020               newTAP._rgtc = new TC[varParam[0]];
1021
1022               for(int x = 0; x < newTAP._itcMac; x++)
1023               {
1024                 newTAP._rgdxaCenter[x] = Utils.convertBytesToShort(varParam , 1 + (x * 2));
1025                 newTAP._rgtc[x] = TC.convertBytesToTC(varParam, 1 + ((varParam[0] + 1) * 2) + (x * 20));
1026               }
1027               newTAP._rgdxaCenter[newTAP._itcMac] = Utils.convertBytesToShort(varParam , 1 + (newTAP._itcMac * 2));
1028               break;
1029          case 0x09:
1030               /** @todo handle cell shading*/
1031               break;
1032          case 0x0a:
1033               /** @todo handle word defined table styles*/
1034               break;
1035          case 0x20:
1036               for(int x = varParam[0]; x < varParam[1]; x++)
1037               {
1038                 if((varParam[2] & 0x08) > 0)
1039                 {
1040                   newTAP._rgtc[x]._brcRight[0] = Utils.convertBytesToShort(varParam, 6);
1041                   newTAP._rgtc[x]._brcRight[1] = Utils.convertBytesToShort(varParam, 8);
1042                 }
1043                 else if((varParam[2] & 0x04) > 0)
1044                 {
1045                   newTAP._rgtc[x]._brcBottom[0] = Utils.convertBytesToShort(varParam, 6);
1046                   newTAP._rgtc[x]._brcBottom[1] = Utils.convertBytesToShort(varParam, 8);
1047                 }
1048                 else if((varParam[2] & 0x02) > 0)
1049                 {
1050                   newTAP._rgtc[x]._brcLeft[0] = Utils.convertBytesToShort(varParam, 6);
1051                   newTAP._rgtc[x]._brcLeft[1] = Utils.convertBytesToShort(varParam, 8);
1052                 }
1053                 else if((varParam[2] & 0x01) > 0)
1054                 {
1055                   newTAP._rgtc[x]._brcTop[0] = Utils.convertBytesToShort(varParam, 6);
1056                   newTAP._rgtc[x]._brcTop[1] = Utils.convertBytesToShort(varParam, 8);
1057                 }
1058               }
1059               break;
1060          case 0x21:
1061               int index = (param & 0xff000000) >> 24;
1062               int count = (param & 0x00ff0000) >> 16;
1063               int width = (param & 0x0000ffff);
1064
1065               short[] rgdxaCenter = new short[newTAP._itcMac + count + 1];
1066               TC[] rgtc = new TC[newTAP._itcMac + count];
1067               if(index >= newTAP._itcMac)
1068               {
1069                 index = newTAP._itcMac;
1070                 System.arraycopy(newTAP._rgdxaCenter, 0, rgdxaCenter, 0, newTAP._itcMac + 1);
1071                 System.arraycopy(newTAP._rgtc, 0, rgtc, 0, newTAP._itcMac);
1072               }
1073               else
1074               {
1075                 //copy rgdxaCenter
1076
System.arraycopy(newTAP._rgdxaCenter, 0, rgdxaCenter, 0, index + 1);
1077                 System.arraycopy(newTAP._rgdxaCenter, index + 1, rgdxaCenter, index + count, (newTAP._itcMac) - (index));
1078                 //copy rgtc
1079
System.arraycopy(newTAP._rgtc, 0, rgtc, 0, index);
1080                 System.arraycopy(newTAP._rgtc, index, rgtc, index + count, newTAP._itcMac - index);
1081               }
1082
1083               for(int x = index; x < index + count; x++)
1084               {
1085                 rgtc[x] = new TC();
1086                 rgdxaCenter[x] = (short)(rgdxaCenter[x-1] + width);
1087               }
1088               rgdxaCenter[index + count] = (short)(rgdxaCenter[(index + count)-1] + width);
1089               break;
1090          /**@todo handle table sprms from complex files*/
1091          case 0x22:
1092          case 0x23:
1093          case 0x24:
1094          case 0x25:
1095          case 0x26:
1096          case 0x27:
1097          case 0x28:
1098          case 0x29:
1099          case 0x2a:
1100          case 0x2b:
1101          case 0x2c:
1102               break;
1103          default:
1104               break;
1105      }
1106  }
1107  static void doSEPOperation(SEP newSEP, int operand, int param, byte[] varParam)
1108  {
1109      switch(operand)
1110      {
1111          case 0:
1112               newSEP._cnsPgn = (byte)param;
1113               break;
1114          case 0x1:
1115               newSEP._iHeadingPgn = (byte)param;
1116               break;
1117          case 0x2:
1118               newSEP._olstAnn = varParam;
1119               break;
1120          case 0x3:
1121               //not quite sure
1122
break;
1123          case 0x4:
1124               //not quite sure
1125
break;
1126          case 0x5:
1127               newSEP._fEvenlySpaced = getFlag(param);
1128               break;
1129          case 0x6:
1130               newSEP._fUnlocked = getFlag(param);
1131               break;
1132          case 0x7:
1133               newSEP._dmBinFirst = (short)param;
1134               break;
1135          case 0x8:
1136               newSEP._dmBinOther = (short)param;
1137               break;
1138          case 0x9:
1139               newSEP._bkc = (byte)param;
1140               break;
1141          case 0xa:
1142               newSEP._fTitlePage = getFlag(param);
1143               break;
1144          case 0xb:
1145               newSEP._ccolM1 = (short)param;
1146               break;
1147          case 0xc:
1148               newSEP._dxaColumns = param;
1149               break;
1150          case 0xd:
1151               newSEP._fAutoPgn = getFlag(param);
1152               break;
1153          case 0xe:
1154               newSEP._nfcPgn = (byte)param;
1155               break;
1156          case 0xf:
1157               newSEP._dyaPgn = (short)param;
1158               break;
1159          case 0x10:
1160               newSEP._dxaPgn = (short)param;
1161               break;
1162          case 0x11:
1163               newSEP._fPgnRestart = getFlag(param);
1164               break;
1165          case 0x12:
1166               newSEP._fEndNote = getFlag(param);
1167               break;
1168          case 0x13:
1169               newSEP._lnc = (byte)param;
1170               break;
1171          case 0x14:
1172               newSEP._grpfIhdt = (byte)param;
1173               break;
1174          case 0x15:
1175               newSEP._nLnnMod = (short)param;
1176               break;
1177          case 0x16:
1178               newSEP._dxaLnn = param;
1179               break;
1180          case 0x17:
1181               newSEP._dyaHdrTop = param;
1182               break;
1183          case 0x18:
1184               newSEP._dyaHdrBottom = param;
1185               break;
1186          case 0x19:
1187               newSEP._fLBetween = getFlag(param);
1188               break;
1189          case 0x1a:
1190               newSEP._vjc = (byte)param;
1191               break;
1192          case 0x1b:
1193               newSEP._lnnMin = (short)param;
1194               break;
1195          case 0x1c:
1196               newSEP._pgnStart = (short)param;
1197               break;
1198          case 0x1d:
1199               newSEP._dmOrientPage = (byte)param;
1200               break;
1201          case 0x1e:
1202               //nothing
1203
break;
1204          case 0x1f:
1205               newSEP._xaPage = param;
1206               break;
1207          case 0x20:
1208               newSEP._yaPage = param;
1209               break;
1210          case 0x21:
1211               newSEP._dxaLeft = param;
1212               break;
1213          case 0x22:
1214               newSEP._dxaRight = param;
1215               break;
1216          case 0x23:
1217               newSEP._dyaTop = param;
1218               break;
1219          case 0x24:
1220               newSEP._dyaBottom = param;
1221               break;
1222          case 0x25:
1223               newSEP._dzaGutter = param;
1224               break;
1225          case 0x26:
1226               newSEP._dmPaperReq = (short)param;
1227               break;
1228          case 0x27:
1229               newSEP._fPropMark = getFlag(varParam[0]);
1230               break;
1231          case 0x28:
1232               break;
1233          case 0x29:
1234               break;
1235          case 0x2a:
1236               break;
1237          case 0x2b:
1238               newSEP._brcTop[0] = (short)(param & 0xffff);
1239               newSEP._brcTop[1] = (short)((param & 0xffff0000) >> 16);
1240               break;
1241          case 0x2c:
1242               newSEP._brcLeft[0] = (short)(param & 0xffff);
1243               newSEP._brcLeft[1] = (short)((param & 0xffff0000) >> 16);
1244               break;
1245          case 0x2d:
1246               newSEP._brcBottom[0] = (short)(param & 0xffff);
1247               newSEP._brcBottom[1] = (short)((param & 0xffff0000) >> 16);
1248               break;
1249          case 0x2e:
1250               newSEP._brcRight[0] = (short)(param & 0xffff);
1251               newSEP._brcRight[1] = (short)((param & 0xffff0000) >> 16);
1252               break;
1253          case 0x2f:
1254               newSEP._pgbProp = (short)param;
1255               break;
1256          case 0x30:
1257               newSEP._dxtCharSpace = param;
1258               break;
1259          case 0x31:
1260               newSEP._dyaLinePitch = param;
1261               break;
1262          case 0x33:
1263               newSEP._wTextFlow = (short)param;
1264               break;
1265          default:
1266               break;
1267      }
1268
1269  }
1270  private static boolean getCHPFlag(byte x, boolean oldVal)
1271  {
1272      switch(x)
1273      {
1274          case 0:
1275               return false;
1276          case 1:
1277               return true;
1278          case (byte)0x80:
1279               return oldVal;
1280          case (byte)0x81:
1281               return !oldVal;
1282          default:
1283               return false;
1284      }
1285  }
1286  public static boolean getFlag(int x)
1287  {
1288      if(x != 0)
1289      {
1290          return true;
1291      }
1292      else
1293      {
1294          return false;
1295      }
1296  }
1297}
1298
Popular Tags