View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript-Excel: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2006 Open World Ltd, Kevin Rogers
4   //
5   // This file is part of MillScript-Excel.
6   //
7   // MillScript-Excel is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript-Excel is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript-Excel; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.office.excel.records.syntax;
22  
23  import org.millscript.office.excel.RecordSyntax;
24  import org.millscript.office.excel.RecordTokenizer;
25  import org.millscript.office.excel.records.CF;
26  import org.millscript.office.excel.versions.BIFF8;
27  import org.millscript.office.excel.versions.BIFF8X;
28  
29  /**
30   * 
31   */
32  public class CFRecordSyntax extends RecordSyntax implements BIFF8, BIFF8X {
33  
34      /**
35       * 
36       */
37      public static class Options {
38  
39          private final int options;
40  
41          public Options( final int o ) {
42              this.options = o;
43          }
44  
45          public boolean containsBorderFormatting() {
46              return 0 != ( this.options & 0x10000000 );
47          }
48  
49          public boolean containsFontFormatting() {
50              return 0 != ( this.options & 0x04000000 );
51          }
52  
53          public boolean containsPatternFormatting() {
54              return 0 != ( this.options & 0x20000000 );
55          }
56  
57      }
58  
59      /**
60       * @see org.millscript.office.excel.RecordSyntax#newRecord(RecordTokenizer)
61       */
62      @Override
63      public CF newRecord( final RecordTokenizer tokenizer ) {
64          final CF cf = new CF();
65          // Set the type of formatting
66          cf.setType(
67              CF.Type.getType( tokenizer.readUnsignedByte() )
68          );
69          // Set the comparison operator
70          cf.setComparisonOperator(
71              CF.ComparisonOperator.getComparisonOperator( tokenizer.readUnsignedByte() )
72          );
73          // Initialise the first and second formula storage
74          final int firstFormulaSize = tokenizer.readUnsigned2Byte();
75          final int secondFormulaSize = tokenizer.readUnsigned2Byte();
76          // Get the CF records options
77          final Options options = new Options( tokenizer.read4ByteInt() );
78          // This is the offset for the remainder of the data
79          tokenizer.skipBytes( 2 );
80          // Set any font block
81          if ( options.containsFontFormatting() ) {
82              cf.setFontFormattingBlock( tokenizer.readBytes( 118 ) );
83          }
84          // Set any border block
85          if ( options.containsBorderFormatting() ) {
86              cf.setBorderFormattingBlock( tokenizer.readBytes( 8 ) );
87          }
88          // Set any pattern block
89          if ( options.containsPatternFormatting() ) {
90              cf.setPatternFormattingBlock( tokenizer.readBytes( 4 ) );
91          }
92          // Now get and set the first formula data
93          cf.setFirstFormulaExpr(
94              tokenizer.readFormula( firstFormulaSize, 0 )
95          );
96          // and the second formula
97          cf.setSecondFormulaExpr(
98              tokenizer.readFormula( secondFormulaSize, 0 )
99          );
100         // and now return the CF block
101         return cf;
102     }
103 
104 }