CacheKey
محتويات
[
يخفي
]FileFontSource.CacheKey property
مفتاح هذا المصدر في ذاكرة التخزين المؤقت.
public string CacheKey { get; }
ملاحظات
يتم استخدام هذا المفتاح لتحديد عنصر ذاكرة التخزين المؤقت عند حفظ/تحميل ذاكرة التخزين المؤقت للبحث عن الخط باستخدام SaveSearchCache
و SetFontsSources
طُرق.
إذا لم يتم تحديد المفتاح،FilePath
سيتم استخدامه كمفتاح بدلاً من ذلك.
أمثلة
يوضح كيفية تسريع عملية تهيئة ذاكرة التخزين المؤقت للخط.
public void LoadFontSearchCache()
{
const string cacheKey1 = "Arvo";
const string cacheKey2 = "Arvo-Bold";
FontSettings parsedFonts = new FontSettings();
FontSettings loadedCache = new FontSettings();
parsedFonts.SetFontsSources(new FontSourceBase[]
{
new FileFontSource(FontsDir + "Arvo-Regular.ttf", 0, cacheKey1),
new FileFontSource(FontsDir + "Arvo-Bold.ttf", 0, cacheKey2)
});
using (MemoryStream cacheStream = new MemoryStream())
{
parsedFonts.SaveSearchCache(cacheStream);
loadedCache.SetFontsSources(new FontSourceBase[]
{
new SearchCacheStream(cacheKey1),
new MemoryFontSource(File.ReadAllBytes(FontsDir + "Arvo-Bold.ttf"), 0, cacheKey2)
}, cacheStream);
}
Assert.AreEqual(parsedFonts.GetFontsSources().Length, loadedCache.GetFontsSources().Length);
}
/// <summary>
/// قم بتحميل بيانات الخط فقط عند الحاجة إليها بدلاً من تخزينها في الذاكرة
/// طوال عمر كائن "FontSettings".
/// </summary>
private class SearchCacheStream : StreamFontSource
{
public SearchCacheStream(string cacheKey):base(0, cacheKey)
{
}
public override Stream OpenFontDataStream()
{
return File.OpenRead(FontsDir + "Arvo-Regular.ttf");
}
}
أنظر أيضا
- class FileFontSource
- مساحة الاسم Aspose.Words.Fonts
- المجسم Aspose.Words