public virtual void FontStringTtcCacheKeyTest()
        {
            String       fontName = "Font.ttc";
            FontCacheKey ttc0     = FontCacheKey.Create(fontName, 0);
            FontCacheKey ttc1     = FontCacheKey.Create(fontName, 1);

            NUnit.Framework.Assert.IsNull(FontCache.GetFont(ttc0));
            NUnit.Framework.Assert.IsNull(FontCache.GetFont(ttc1));
            FontProgram fontProgram = new FontCacheNoFontAsianTest.FontProgramMock();

            FontCache.SaveFont(fontProgram, ttc1);
            NUnit.Framework.Assert.IsNull(FontCache.GetFont(ttc0));
            NUnit.Framework.Assert.AreEqual(fontProgram, FontCache.GetFont(ttc1));
        }
예제 #2
0
        private static FontCacheKey CreateFontCacheKey(String name, byte[] fontProgram)
        {
            FontCacheKey key;

            if (name != null)
            {
                key = FontCacheKey.Create(name);
            }
            else
            {
                key = FontCacheKey.Create(fontProgram);
            }
            return(key);
        }
        private static FontProgramDescriptor FetchCachedDescriptor(String fontName, byte[] fontProgram)
        {
            FontProgram  fontFound;
            FontCacheKey key;

            if (fontName != null)
            {
                key = FontCacheKey.Create(fontName);
            }
            else
            {
                key = FontCacheKey.Create(fontProgram);
            }
            fontFound = FontCache.GetFont(key);
            return(fontFound != null?FetchDescriptorFromFontProgram(fontFound) : null);
        }
예제 #4
0
        /// <summary>Creates a new TrueType font program from ttc (TrueType Collection) file bytes.</summary>
        /// <param name="ttc">the content of a TrueType Collection file (*.ttc)</param>
        /// <param name="ttcIndex">the index of the font file from the collection to be read</param>
        /// <param name="cached">
        /// true if the font comes from the cache or is added to
        /// the cache if new, false if the font is always created new
        /// </param>
        /// <returns>
        /// returns a new
        /// <see cref="FontProgram"/>
        /// instance. This font may come from the cache but only if cached
        /// is true, otherwise it will always be created new
        /// </returns>
        public static FontProgram CreateFont(byte[] ttc, int ttcIndex, bool cached)
        {
            FontCacheKey fontKey = FontCacheKey.Create(ttc, ttcIndex);

            if (cached)
            {
                FontProgram fontFound = FontCache.GetFont(fontKey);
                if (fontFound != null)
                {
                    return(fontFound);
                }
            }
            FontProgram fontBuilt = new TrueTypeFont(ttc, ttcIndex);

            return(cached ? FontCache.SaveFont(fontBuilt, fontKey) : fontBuilt);
        }
        public virtual void FontBytesTtcCacheKeyTest()
        {
            byte[]       fontBytes       = "SupposedTtcFontData".GetBytes(System.Text.Encoding.UTF8);
            byte[]       otherFontBytes  = "DifferentTtcFontBytes".GetBytes(System.Text.Encoding.UTF8);
            byte[]       normalFontBytes = "NormalFontBytes".GetBytes(System.Text.Encoding.UTF8);
            FontCacheKey ttc0            = FontCacheKey.Create(fontBytes, 1);
            FontCacheKey otherTtc0       = FontCacheKey.Create(otherFontBytes, 1);
            FontCacheKey normal          = FontCacheKey.Create(normalFontBytes);

            NUnit.Framework.Assert.IsNull(FontCache.GetFont(ttc0));
            NUnit.Framework.Assert.IsNull(FontCache.GetFont(otherTtc0));
            NUnit.Framework.Assert.IsNull(FontCache.GetFont(normal));
            FontProgram otherTtc0MockFontProgram = new FontCacheNoFontAsianTest.FontProgramMock();
            FontProgram normalMockFontProgram    = new FontCacheNoFontAsianTest.FontProgramMock();

            FontCache.SaveFont(otherTtc0MockFontProgram, otherTtc0);
            FontCache.SaveFont(normalMockFontProgram, normal);
            NUnit.Framework.Assert.IsNull(FontCache.GetFont(ttc0));
            NUnit.Framework.Assert.AreEqual(otherTtc0MockFontProgram, FontCache.GetFont(otherTtc0));
            NUnit.Framework.Assert.AreEqual(normalMockFontProgram, FontCache.GetFont(normal));
        }
예제 #6
0
 public static FontProgram SaveFont(FontProgram font, String fontName)
 {
     return(SaveFont(font, FontCacheKey.Create(fontName)));
 }
예제 #7
0
 public static FontProgram GetFont(String fontName)
 {
     return(fontCache.Get(FontCacheKey.Create(fontName)));
 }