Exemple #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);
        }