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
        /**
         * Adds a font record to this workbook.  If the FontRecord passed in has not
         * been initialized, then its font index is determined based upon the size
         * of the fonts list.  The FontRecord's initialized method is called, and
         * it is added to the list of fonts.
         *
         * @param f the font to add
         */
        public void addFont(FontRecord f)
        {
            if (!f.isInitialized())
                {
                int pos = fonts.Count;

                // Remember that the pos with index 4 is skipped
                if (pos >= 4)
                    pos++;

                f.initialize(pos);
                fonts.Add(f);
                }
        }
Exemplo n.º 3
0
        /**
         * Adds a font record to this workbook.  If the FontRecord passed in has not
         * been initialized, then its font index is determined based upon the size
         * of the fonts list.  The FontRecord's initialized method is called, and
         * it is added to the list of fonts.
         *
         * @param f the font to add
         */
        public void addFont(FontRecord f)
        {
            if (!f.isInitialized())
            {
                int pos = fonts.Count;

                // Remember that the pos with index 4 is skipped
                if (pos >= 4)
                {
                    pos++;
                }

                f.initialize(pos);
                fonts.Add(f);
            }
        }