Exemplo n.º 1
0
        public IBaseFont GetFontByName(string fontAndColorId)
        {
            string fontColor  = string.Empty;
            string fontName   = string.Empty;
            bool   foundColor = GetColorFromFontName(ref fontColor, ref fontName, fontAndColorId);

            string combinedFontId = foundColor ? fontAndColorId : fontName;

            //if a color is set, it's a unique font
            IBaseFont font;

            Fonts.TryGetValue(combinedFontId, out font);

            //if the font is not found, but has a modified color, store it
            if (font == null && foundColor)
            {
                IBaseFont fontWithoutColor;
                Fonts.TryGetValue(fontName, out fontWithoutColor);
                if (fontWithoutColor != null)
                {
                    if (fontWithoutColor is Models.Font)
                    {
                        font = Models.Font.CopyFont <Models.Font, Models.Font>((Models.Font)fontWithoutColor, combinedFontId);
                        (font as BaseFont).SetColor(GetColor(fontColor));
                    }
                    else if (fontWithoutColor is BaseFont)
                    {
                        font = BaseFont.CopyFont <BaseFont, BaseFont>((BaseFont)fontWithoutColor, combinedFontId);
                        (font as BaseFont).SetColor(GetColor(fontColor));
                    }

                    AddFont(font);
                }
            }

            return(font);
        }