Exemplo n.º 1
0
        /**
         * Rationalizes all the fonts, removing any duplicates
         *
         * @return the mappings between new indexes and old ones
         */
        public IndexMapping rationalize()
        {
            IndexMapping mapping = new IndexMapping(fonts.Count + 1);
            // allow for skipping record 4

            ArrayList newfonts   = new ArrayList();
            int       numremoved = 0;

            // Preserve the default fonts
            for (int i = 0; i < numDefaultFonts; i++)
            {
                FontRecord fr = (FontRecord)fonts[i];
                newfonts.Add(fr);
                mapping.setMapping(fr.getFontIndex(), fr.getFontIndex());
            }

            // Now do the rest
            bool duplicate = false;

            for (int i = numDefaultFonts; i < fonts.Count; i++)
            {
                FontRecord fr = (FontRecord)fonts[i];

                // Compare to all the fonts currently on the list
                duplicate = false;
                foreach (FontRecord fr2 in newfonts)
                {
                    if (fr.Equals(fr2))
                    {
                        duplicate = true;
                        mapping.setMapping(fr.getFontIndex(), mapping.getNewIndex(fr2.getFontIndex()));
                        numremoved++;

                        break;
                    }
                }

                if (!duplicate)
                {
                    // Add to the new list
                    newfonts.Add(fr);
                    int newindex = fr.getFontIndex() - numremoved;
                    Assert.verify(newindex > 4);
                    mapping.setMapping(fr.getFontIndex(), newindex);
                }
            }

            // Iterate through the remaining fonts, updating all the font indices
            foreach (FontRecord fr in newfonts)
            {
                fr.initialize(mapping.getNewIndex(fr.getFontIndex()));
            }

            fonts = newfonts;

            return(mapping);
        }
Exemplo n.º 2
0
        /**
         * Rationalizes the display formats.  Duplicate
         * formats are removed and the format indices of the cells
         * adjusted accordingly.  It is invoked immediately prior to writing
         * writing out the sheet
         * @return the index mapping between the old display formats and the
         * rationalized ones
         */
        public IndexMapping rationalizeDisplayFormats()
        {
            ArrayList    newformats = new ArrayList();
            int          numremoved = 0;
            IndexMapping mapping    = new IndexMapping(nextCustomIndexNumber);

            // Iterate through the old list
            bool duplicate = false;

            foreach (DisplayFormat df in formatsList)
            {
                Assert.verify(!df.isBuiltIn());

                // Compare against formats already on the list
                duplicate = false;
                foreach (DisplayFormat df2 in newformats)
                {
                    if (df2.Equals(df))
                    {
                        duplicate = true;
                        mapping.setMapping(df.getFormatIndex(), mapping.getNewIndex(df2.getFormatIndex()));
                        numremoved++;
                    }
                }

                // If this format is not a duplicate then add it to the new list
                if (!duplicate)
                {
                    newformats.Add(df);
                    int indexnum = df.getFormatIndex() - numremoved;
                    if (indexnum > maxFormatRecordsIndex)
                    {
                        //logger.warn("Too many number formats - using default format.");
                        indexnum = 0;                         // the default number format index
                    }
                    mapping.setMapping(df.getFormatIndex(),
                                       df.getFormatIndex() - numremoved);
                }
            }

            // Set the new list
            formatsList = newformats;

            // Update the index codes for the remaining formats
            foreach (DisplayFormat df in formatsList)
            {
                df.initialize(mapping.getNewIndex(df.getFormatIndex()));
            }

            return(mapping);
        }
Exemplo n.º 3
0
        /**
         * Rationalizes the cell formats.  Duplicate
         * formats are removed and the format indexed of the cells
         * adjusted accordingly
         *
         * @param fontMapping the font mapping index numbers
         * @param formatMapping the format mapping index numbers
         * @return the list of new font index number
         */
        public IndexMapping rationalize(IndexMapping fontMapping,
                                        IndexMapping formatMapping)
        {
            // Update the index codes for the XF records using the format
            // mapping and the font mapping
            // at the same time
//			XFRecord xfr = null;
            foreach (XFRecord xfr in xfRecords)
            {
                if (xfr.getFormatRecord() >= customFormatStartIndex)
                {
                    xfr.setFormatIndex(formatMapping.getNewIndex(xfr.getFormatRecord()));
                }
                xfr.setFontIndex(fontMapping.getNewIndex(xfr.getFontIndex()));
            }

            ArrayList    newrecords = new ArrayList(minXFRecords);
            IndexMapping mapping    = new IndexMapping(xfRecords.Count);
            int          numremoved = 0;

            int numXFRecords = System.Math.Min(minXFRecords, xfRecords.Count);

            // Copy across the fundamental styles
            for (int i = 0; i < numXFRecords; i++)
            {
                newrecords.Add(xfRecords[i]);
                mapping.setMapping(i, i);
            }

            if (numXFRecords < minXFRecords)
            {
                //logger.warn("There are less than the expected minimum number of XF records");
                return(mapping);
            }

            // Iterate through the old list
            for (int i = minXFRecords; i < xfRecords.Count; i++)
            {
                XFRecord xf = (XFRecord)xfRecords[i];

                // Compare against formats already on the list
                bool duplicate = false;
                foreach (XFRecord xf2 in newrecords)
                {
                    if (xf2.Equals(xf))
                    {
                        duplicate = true;
                        mapping.setMapping(i, mapping.getNewIndex(xf2.getXFIndex()));
                        numremoved++;
                        break;
                    }
                }

                // If this format is not a duplicate then add it to the new list
                if (!duplicate)
                {
                    newrecords.Add(xf);
                    mapping.setMapping(i, i - numremoved);
                }
            }

            // It is sufficient to merely change the xf index field on all XFRecords
            // In this case, CellValues which refer to defunct format records
            // will nevertheless be written out with the correct index number
            foreach (XFRecord xf in xfRecords)
            {
                xf.rationalize(mapping);
            }

            // Set the new list
            xfRecords = newrecords;

            return(mapping);
        }
 /**
  * Rationalizes the sheets xf index mapping
  * @param xfmapping the index mapping
  */
 public void rationalize(IndexMapping xfmapping)
 {
     xfIndex = xfmapping.getNewIndex(xfIndex);
 }
Exemplo n.º 5
0
        /**
         * Rationalizes all the fonts, removing any duplicates
         *
         * @return the mappings between new indexes and old ones
         */
        public IndexMapping rationalize()
        {
            IndexMapping mapping = new IndexMapping(fonts.Count + 1);
            // allow for skipping record 4

            ArrayList newfonts = new ArrayList();
            int numremoved = 0;

            // Preserve the default fonts
            for (int i = 0; i < numDefaultFonts; i++)
                {
                FontRecord fr = (FontRecord)fonts[i];
                newfonts.Add(fr);
                mapping.setMapping(fr.getFontIndex(),fr.getFontIndex());
                }

            // Now do the rest
            bool duplicate = false;
            for (int i = numDefaultFonts; i < fonts.Count; i++)
                {
                FontRecord fr = (FontRecord)fonts[i];

                // Compare to all the fonts currently on the list
                duplicate = false;
                foreach (FontRecord fr2 in newfonts)
                    {
                    if (fr.Equals(fr2))
                        {
                        duplicate = true;
                        mapping.setMapping(fr.getFontIndex(),mapping.getNewIndex(fr2.getFontIndex()));
                        numremoved++;

                        break;
                        }
                    }

                if (!duplicate)
                    {
                    // Add to the new list
                    newfonts.Add(fr);
                    int newindex = fr.getFontIndex() - numremoved;
                    Assert.verify(newindex > 4);
                    mapping.setMapping(fr.getFontIndex(),newindex);
                    }
                }

            // Iterate through the remaining fonts, updating all the font indices
            foreach (FontRecord fr in newfonts)
                fr.initialize(mapping.getNewIndex(fr.getFontIndex()));

            fonts = newfonts;

            return mapping;
        }
Exemplo n.º 6
0
 /**
  * Rationalizes the sheets xf index mapping
  * @param xfmapping the index mapping
  */
 public void rationalize(IndexMapping xfmapping)
 {
     if (defaultFormat)
         {
         xfIndex = xfmapping.getNewIndex(xfIndex);
         }
 }
Exemplo n.º 7
0
        /**
         * Changes the appropriate indexes during the rationalization process
         * @param xfMapping the xf index re-mappings
         */
        public void rationalize(IndexMapping xfMapping)
        {
            xfIndex = xfMapping.getNewIndex(xfIndex);

            if (xfFormatType == cell)
                {
                parentFormat = xfMapping.getNewIndex(parentFormat);
                }
        }