示例#1
0
        /// <summary>
        /// This will alter the incoming SWF's font references. Any new fonts will be
        /// left untouched. Any fonts that exist in root already will have their glyphs
        /// imported into the root SWF's fonts and references will re-point to the
        /// now possibly larger font. Any fonts that exist only in incoming will be left
        /// alone since importing the SWF as a movieclip will automatically make those
        /// fonts part of root.
        /// </summary>
        /// <param name="incoming">The SWF being absorbed into the root.</param>
        /// <param name="root">The root SWF that will absord new fonts or glyphs.</param>
        private void RemapFonts(SWF incoming, SWF root)
        {
            List <SWFFont> rootFonts = new List <SWFFont>();

            root.FontProc(delegate(SWFFont font)
            {
                rootFonts.Add(font);
            });

            Dictionary <SWFFont, SWFFont> remaps = new Dictionary <SWFFont, SWFFont>();

            incoming.FontProc(delegate(SWFFont font)
            {
                foreach (SWFFont rootFont in rootFonts)
                {
                    if (font.CanMergeWith(rootFont))
                    {
                        remaps.Add(font, rootFont);

                        char[] codes = font.CodePoints;
                        foreach (char c in codes)
                        {
                            bool hasPixelAlignment = font.HasPixelAlignment;
                            bool hasLayout         = font.HasLayout;

                            if (!rootFont.HasGlyph(c))
                            {
                                rootFont.AddGlyph(c, font.GetGlyphShape(c));

                                if (hasPixelAlignment)
                                {
                                    rootFont.AddPixelAlignment(c, font.GetPixelAligment(c));
                                }

                                if (hasLayout)
                                {
                                    rootFont.AddLayout(c, font.GetLayout(c));
                                }
                            }
                        }
                    }
                }
            });

            /* Now we've merged glyphs into our target fonts, we need to go over all
             * uses of the old fonts and remap them... */

            incoming.CharacterProc(delegate(ICharacter ch)
            {
                if (ch is IFontUserProcessor)
                {
                    IFontUserProcessor fup = (IFontUserProcessor)ch;

                    fup.FontUserProc(delegate(IFontUser fu)
                    {
                        if (fu.HasFont && remaps.ContainsKey(fu.Font))
                        {
                            fu.Font = remaps[fu.Font];
                        }
                    });
                }
            });
        }
示例#2
0
        /// <summary>
        /// This will alter the incoming SWF's font references. Any new fonts will be
        /// left untouched. Any fonts that exist in root already will have their glyphs
        /// imported into the root SWF's fonts and references will re-point to the
        /// now possibly larger font. Any fonts that exist only in incoming will be left
        /// alone since importing the SWF as a movieclip will automatically make those
        /// fonts part of root.
        /// </summary>
        /// <param name="incoming">The SWF being absorbed into the root.</param>
        /// <param name="root">The root SWF that will absord new fonts or glyphs.</param>
        private void RemapFonts(SWF incoming, SWF root)
        {
            List<SWFFont> rootFonts = new List<SWFFont>();
            root.FontProc(delegate(SWFFont font)
            {
                rootFonts.Add(font);
            });

            Dictionary<SWFFont, SWFFont> remaps = new Dictionary<SWFFont, SWFFont>();

            incoming.FontProc(delegate(SWFFont font)
            {
                foreach (SWFFont rootFont in rootFonts)
                {
                    if (font.CanMergeWith(rootFont))
                    {
                        remaps.Add(font, rootFont);

                        char[] codes = font.CodePoints;
                        foreach (char c in codes)
                        {
                            bool hasPixelAlignment = font.HasPixelAlignment;
                            bool hasLayout = font.HasLayout;

                            if (!rootFont.HasGlyph(c))
                            {
                                rootFont.AddGlyph(c, font.GetGlyphShape(c));

                                if (hasPixelAlignment)
                                {
                                    rootFont.AddPixelAlignment(c, font.GetPixelAligment(c));
                                }

                                if (hasLayout)
                                {
                                    rootFont.AddLayout(c, font.GetLayout(c));
                                }
                            }
                        }
                    }
                }
            });

            /* Now we've merged glyphs into our target fonts, we need to go over all
             * uses of the old fonts and remap them... */

            incoming.CharacterProc(delegate(ICharacter ch)
            {
                if (ch is IFontUserProcessor)
                {
                    IFontUserProcessor fup = (IFontUserProcessor)ch;

                    fup.FontUserProc(delegate(IFontUser fu)
                    {
                        if (fu.HasFont && remaps.ContainsKey(fu.Font))
                        {
                            fu.Font = remaps[fu.Font];
                        }
                    });
                }
            });
        }