Style.FontColor
محتويات
[
يخفي
]Style.FontColor property
يحصل أو يضبط لون الخط.
public Color FontColor { get; set; }
أمثلة
يظهر كيفية تغيير النمط لنص.
string dataDir = RunExamples.GetDataDir_Text();
// حمّل المستند إلى Aspose.Note.
Document document = new Document(dataDir + "Aspose.one");
// احصل على عقدة RichText معينة
RichText richText = document.GetChildNodes<RichText>().First();
foreach (var run in richText.TextRuns)
{
// تعيين لون الخط
run.Style.FontColor = Color.Yellow;
// تعيين لون التظليل
run.Style.Highlight = Color.Blue;
// تعيين حجم الخط
run.Style.FontSize = 20;
}
يظهر كيفية تطبيق نمط السمة الداكنة على مستند.
// المسار إلى دليل المستندات.
string dataDir = RunExamples.GetDataDir_Text();
// حمّل المستند إلى Aspose.Note.
Document doc = new Document(Path.Combine(dataDir, "Aspose.one"));
foreach (var page in doc)
{
page.BackgroundColor = Color.Black;
}
foreach (var node in doc.GetChildNodes<RichText>())
{
var c = node.ParagraphStyle.FontColor;
if (c.IsEmpty || Math.Abs(c.R - Color.Black.R) + Math.Abs(c.G - Color.Black.G) + Math.Abs(c.B - Color.Black.B) <= 30)
{
node.ParagraphStyle.FontColor = Color.White;
}
}
doc.Save(Path.Combine(dataDir, "AsposeDarkTheme.pdf"));
يعرض كيفية إدراج قائمة جديدة بترقيم صيني.
string dataDir = RunExamples.GetDataDir_Text();
// تهيئة مستند OneNote.
Document doc = new Document();
// تهيئة صفحة OneNote.
Page page = new Page();
Outline outline = new Outline();
// تطبيق إعدادات نمط النص.
ParagraphStyle defaultStyle = new ParagraphStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };
// الأرقام في نفس المخطط تُزاد تلقائيًا.
OutlineElement outlineElem1 = new OutlineElement() { NumberList = new NumberList("{0})", NumberFormat.ChineseCounting, "Arial", 10) };
RichText text1 = new RichText() { Text = "First", ParagraphStyle = defaultStyle };
outlineElem1.AppendChildLast(text1);
//------------------------
OutlineElement outlineElem2 = new OutlineElement() { NumberList = new NumberList("{0})", NumberFormat.ChineseCounting, "Arial", 10) };
RichText text2 = new RichText() { Text = "Second", ParagraphStyle = defaultStyle };
outlineElem2.AppendChildLast(text2);
//------------------------
OutlineElement outlineElem3 = new OutlineElement() { NumberList = new NumberList("{0})", NumberFormat.ChineseCounting, "Arial", 10) };
RichText text3 = new RichText() { Text = "Third", ParagraphStyle = defaultStyle };
outlineElem3.AppendChildLast(text3);
//------------------------
outline.AppendChildLast(outlineElem1);
outline.AppendChildLast(outlineElem2);
outline.AppendChildLast(outlineElem3);
page.AppendChildLast(outline);
doc.AppendChildLast(page);
// حفظ مستند OneNote.
dataDir = dataDir + "InsertChineseNumberList_out.one";
doc.Save(dataDir);
يعرض كيفية إدراج قائمة نقطية جديدة.
string dataDir = RunExamples.GetDataDir_Text();
// إنشاء كائن من فئة Document
Document doc = new Document();
// تهيئة كائن فئة Page
Page page = new Page();
// تهيئة كائن فئة Outline
Outline outline = new Outline();
// تهيئة كائن الفئة TextStyle وتعيين خصائص التنسيق
ParagraphStyle defaultStyle = new ParagraphStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };
// تهيئة كائنات الفئة OutlineElement وتطبيق النقاط
OutlineElement outlineElem1 = new OutlineElement() { NumberList = new NumberList("*", "Arial", 10) };
// تهيئة كائن الفئة RichText وتطبيق نمط النص
RichText text1 = new RichText() { Text = "First", ParagraphStyle = defaultStyle };
outlineElem1.AppendChildLast(text1);
OutlineElement outlineElem2 = new OutlineElement() { NumberList = new NumberList("*", "Arial", 10) };
RichText text2 = new RichText( ) { Text = "Second", ParagraphStyle = defaultStyle };
outlineElem2.AppendChildLast(text2);
OutlineElement outlineElem3 = new OutlineElement() { NumberList = new NumberList("*", "Arial", 10) };
RichText text3 = new RichText() { Text = "Third", ParagraphStyle = defaultStyle };
outlineElem3.AppendChildLast(text3);
// إضافة عناصر المخطط
outline.AppendChildLast(outlineElem1);
outline.AppendChildLast(outlineElem2);
outline.AppendChildLast(outlineElem3);
// إضافة عقدة المخطط
page.AppendChildLast(outline);
// إضافة عقدة الصفحة
doc.AppendChildLast(page);
// حفظ مستند OneNote.
dataDir = dataDir + "ApplyBulletsOnText_out.one";
doc.Save(dataDir);
يعرض كيفية إدراج قائمة جديدة مع الترقيم.
string dataDir = RunExamples.GetDataDir_Text();
// إنشاء كائن من فئة Document
Document doc = new Document();
// تهيئة كائن فئة Page
Page page = new Page();
// تهيئة كائن فئة Outline
Outline outline = new Outline();
// تهيئة كائن الفئة TextStyle وتعيين خصائص التنسيق
ParagraphStyle defaultStyle = new ParagraphStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };
// تهيئة كائنات الفئة OutlineElement وتطبيق الترقيم.
// الأرقام في نفس المخطط تُزاد تلقائيًا.
OutlineElement outlineElem1 = new OutlineElement() { NumberList = new NumberList("{0})", NumberFormat.DecimalNumbers, "Arial", 10) };
RichText text1 = new RichText() { Text = "First", ParagraphStyle = defaultStyle };
outlineElem1.AppendChildLast(text1);
OutlineElement outlineElem2 = new OutlineElement() { NumberList = new NumberList("{0})", NumberFormat.DecimalNumbers, "Arial", 10) };
RichText text2 = new RichText() { Text = "Second", ParagraphStyle = defaultStyle };
outlineElem2.AppendChildLast(text2);
OutlineElement outlineElem3 = new OutlineElement() { NumberList = new NumberList("{0})", NumberFormat.DecimalNumbers, "Arial", 10) };
RichText text3 = new RichText() { Text = "Third", ParagraphStyle = defaultStyle };
outlineElem3.AppendChildLast(text3);
// إضافة عناصر المخطط
outline.AppendChildLast(outlineElem1);
outline.AppendChildLast(outlineElem2);
outline.AppendChildLast(outlineElem3);
// إضافة عقدة المخطط
page.AppendChildLast(outline);
// إضافة عقدة الصفحة
doc.AppendChildLast(page);
// حفظ مستند OneNote.
dataDir = dataDir + "ApplyNumberingOnText_out.one";
doc.Save(dataDir);
يظهر كيفية ربط ارتباط تشعبي بنص.
// المسار إلى دليل المستندات.
string dataDir = RunExamples.GetDataDir_Tasks();
// إنشاء كائن من فئة Document
Document doc = new Document();
RichText titleText = new RichText() { ParagraphStyle = ParagraphStyle.Default }.Append("Title!");
Outline outline = new Outline()
{
MaxWidth = 200,
MaxHeight = 200,
VerticalOffset = 100,
HorizontalOffset = 100
};
TextStyle textStyleRed = new TextStyle
{
FontColor = Color.Red,
FontName = "Arial",
FontSize = 10,
};
TextStyle textStyleHyperlink = new TextStyle
{
HyperlinkAddress = "https://www.google.com"
};
RichText text = new RichText() { ParagraphStyle = ParagraphStyle.Default }
.Append("This is ", textStyleRed)
.Append("hyperlink", textStyleHyperlink)
.Append(". This text is not a hyperlink.", TextStyle.Default);
OutlineElement outlineElem = new OutlineElement();
outlineElem.AppendChildLast(text);
// إضافة عناصر المخطط
outline.AppendChildLast(outlineElem);
// تهيئة كائن فئة Title
Title title = new Title() { TitleText = titleText };
// تهيئة كائن فئة Page
Page page = new Note.Page() { Title = title };
// إضافة عقدة المخطط
page.AppendChildLast(outline);
// إضافة عقدة الصفحة
doc.AppendChildLast(page);
// حفظ مستند OneNote.
dataDir = dataDir + "AddHyperlink_out.one";
doc.Save(dataDir);
يظهر كيفية إنشاء جدول يحتوي على نص بأنماط مختلفة.
string dataDir = RunExamples.GetDataDir_Text();
var headerText = new RichText() { ParagraphStyle = new ParagraphStyle() { FontSize = 18, IsBold = true }, Alignment = HorizontalAlignment.Center }
.Append("Super contest for suppliers.");
var page = new Page();
var outline = page.AppendChildLast(new Outline() { HorizontalOffset = 50 });
outline.AppendChildLast(new OutlineElement()).AppendChildLast(headerText);
// نص الملخص قبل الجدول
var bodyTextHeader = outline.AppendChildLast(new OutlineElement()).AppendChildLast(new RichText() { ParagraphStyle = ParagraphStyle.Default });
bodyTextHeader.Append("This is the final ranking of proposals got from our suppliers.");
var ranking = outline.AppendChildLast(new OutlineElement()).AppendChildLast(new Table());
var headerRow = ranking.AppendChildFirst(new TableRow());
var headerStyle = ParagraphStyle.Default;
headerStyle.IsBold = true;
// لنضيف مجموعة من الأعمدة وصفًا رأسياً
var backGroundColor = Color.LightGray;
foreach (var header in new[] { "Supplier", "Contacts", "Score A", "Score B", "Score C", "Final score", "Attached materials", "Comments" })
{
ranking.Columns.Add(new TableColumn());
headerRow.AppendChildLast(new TableCell() { BackgroundColor = backGroundColor })
.AppendChildLast(new OutlineElement())
.AppendChildLast(new RichText() { ParagraphStyle = headerStyle })
.Append(header);
}
// لنضيف 5 صفوف فارغة. الصفوف لها لون خلفية متناوب
for (int i = 0; i < 5; i++)
{
backGroundColor = backGroundColor.IsEmpty ? Color.LightGray : Color.Empty;
var row = ranking.AppendChildLast(new TableRow());
for (int j = 0; j < ranking.Columns.Count(); j++)
{
row.AppendChildLast(new TableCell() { BackgroundColor = backGroundColor })
.AppendChildLast(new OutlineElement())
.AppendChildLast(new RichText() { ParagraphStyle = ParagraphStyle.Default });
}
}
// لنضيف بعض القالب للمحتوى في عمود 'Contacts'
foreach (var row in ranking.Skip(1))
{
var contactsCell = row.ElementAt(1);
contactsCell.AppendChildLast(new OutlineElement())
.AppendChildLast(new RichText() { ParagraphStyle = ParagraphStyle.Default })
.Append("Web: ").Append("link", new TextStyle() { HyperlinkAddress = "https://www.link.com" });
contactsCell.AppendChildLast(new OutlineElement())
.AppendChildLast(new RichText() { ParagraphStyle = ParagraphStyle.Default })
.Append("E-mail: ").Append("mail", new TextStyle() { HyperlinkAddress = "mailto:hi@link.com" });
}
var d = new Document();
d.AppendChildLast(page);
d.Save(Path.Combine(dataDir, "ComposeTable_out.one"));
انظر أيضًا
- class Style
- namespace Aspose.Note
- assembly Aspose.Note