Description
محتويات
[
يخفي
]WarningInfo.Description property
يعيد وصف التحذير.
public string Description { get; }
أمثلة
يوضح كيفية تعيين الخاصية للعثور على أقرب تطابق لخط مفقود من مصادر الخطوط المتوفرة.
public void EnableFontSubstitution()
{
// افتح مستندًا يحتوي على نص منسق بخط غير موجود في أي من مصادر الخطوط لدينا.
Document doc = new Document(MyDir + "Missing font.docx");
// تعيين معاودة الاتصال للتعامل مع تحذيرات استبدال الخط.
HandleDocumentSubstitutionWarnings substitutionWarningHandler = new HandleDocumentSubstitutionWarnings();
doc.WarningCallback = substitutionWarningHandler;
// تعيين اسم الخط الافتراضي وتمكين استبدال الخط.
FontSettings fontSettings = new FontSettings();
fontSettings.SubstitutionSettings.DefaultFontSubstitution.DefaultFontName = "Arial";
;
fontSettings.SubstitutionSettings.FontInfoSubstitution.Enabled = true;
// ينبغي استخدام مقاييس الخط الأصلية بعد استبدال الخط.
doc.LayoutOptions.KeepOriginalFontMetrics = true;
// سوف نحصل على تحذير استبدال الخط إذا قمنا بحفظ مستند بخط مفقود.
doc.FontSettings = fontSettings;
doc.Save(ArtifactsDir + "FontSettings.EnableFontSubstitution.pdf");
using (IEnumerator<WarningInfo> warnings = substitutionWarningHandler.FontWarnings.GetEnumerator())
while (warnings.MoveNext())
Console.WriteLine(warnings.Current.Description);
//يمكننا أيضًا التحقق من التحذيرات الموجودة في المجموعة ومسحها.
Assert.AreEqual(WarningSource.Layout, substitutionWarningHandler.FontWarnings[0].Source);
Assert.AreEqual(
"Font '28 Days Later' has not been found. Using 'Calibri' font instead. Reason: alternative name from document.",
substitutionWarningHandler.FontWarnings[0].Description);
substitutionWarningHandler.FontWarnings.Clear();
Assert.AreEqual(0, substitutionWarningHandler.FontWarnings.Count);
}
public class HandleDocumentSubstitutionWarnings : IWarningCallback
{
/// <summary>
/// يتم استدعاؤها في كل مرة يحدث فيها تحذير أثناء التحميل/الحفظ.
/// </summary>
public void Warning(WarningInfo info)
{
if (info.WarningType == WarningType.FontSubstitution)
FontWarnings.Warning(info);
}
public WarningInfoCollection FontWarnings = new WarningInfoCollection();
}
أنظر أيضا
- class WarningInfo
- مساحة الاسم Aspose.Words
- المجسم Aspose.Words