Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update(lists): add symbol font size option #196

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions OfficeIMO.Examples/Word/Lists/Lists.Create8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ internal static void Example_BasicLists8(string folderPath, bool openWord) {
string filePath = System.IO.Path.Combine(folderPath, "Document with Lists11.docx");
using (WordDocument document = WordDocument.Create(filePath)) {

// add list and nest a list
WordList wordList1 = document.AddList(WordListStyle.Headings111, false);
WordList wordList1 = document.AddList(WordListStyle.Headings111, false, 15);
wordList1.AddItem("Text 1");
wordList1.AddItem("Text 1.1");
wordList1.AddItem("Text 1.2");
Expand All @@ -18,7 +17,7 @@ internal static void Example_BasicLists8(string folderPath, bool openWord) {
document.AddParagraph("Second List");
document.AddParagraph();

WordList wordList2 = document.AddList(WordListStyle.Headings111, false);
WordList wordList2 = document.AddList(WordListStyle.Headings111, false, 25);
wordList2.AddItem("Text 2");
wordList2.AddItem("Text 2.1");
wordList2.AddItem("Text 2.2");
Expand All @@ -28,14 +27,13 @@ internal static void Example_BasicLists8(string folderPath, bool openWord) {
document.AddParagraph("Third List");
document.AddParagraph();

WordList wordList3 = document.AddList(WordListStyle.Headings111, false);
WordList wordList3 = document.AddList(WordListStyle.Headings111, false, 50);
wordList3.AddItem("Text 3");
wordList3.AddItem("Text 3.1");
wordList3.AddItem("Text 3.2");
wordList3.AddItem("Text 3.3");
wordList3.AddItem("Text 3.4");


document.Save(openWord);
}
}
Expand Down
8 changes: 4 additions & 4 deletions OfficeIMO.Word/WordDocument.PublicMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ public WordChart AddPieChart(string title = null, bool roundedCorners = false, i
return pieChart;
}

public WordList AddList(WordListStyle style, bool continueNumbering = false) {
public WordList AddList(WordListStyle style, bool continueNumbering = false, int? fontSize = null) {
WordList wordList = new WordList(this);
wordList.AddList(style, continueNumbering);
wordList.AddList(style, continueNumbering, fontSize);
return wordList;
}

public WordList AddTableOfContentList(WordListStyle style) {
public WordList AddTableOfContentList(WordListStyle style, int? fontSize = null) {
WordList wordList = new WordList(this, true);
wordList.AddList(style, continueNumbering: true);
wordList.AddList(style, continueNumbering: true, fontSize);
return wordList;
}

Expand Down
4 changes: 2 additions & 2 deletions OfficeIMO.Word/WordHeaderFooter.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public WordTable AddTable(int rows, int columns, WordTableStyle tableStyle = Wor
}
}

public WordList AddList(WordListStyle style, bool continueNumbering = false) {
public WordList AddList(WordListStyle style, bool continueNumbering = false, int? fontSize = null) {
WordList wordList = new WordList(this._document, this);
wordList.AddList(style, continueNumbering);
wordList.AddList(style, continueNumbering, fontSize);
return wordList;
}
}
Expand Down
18 changes: 17 additions & 1 deletion OfficeIMO.Word/WordList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,30 @@ private static int GetNextNumberingInstance(Numbering numbering) {
return ids.Count > 0 ? ids.Max() + 1 : 1;
}

internal void AddList(WordListStyle style, bool continueNumbering) {
internal void AddList(WordListStyle style, bool continueNumbering, int? numberingSymbolFontSize = null) {
CreateNumberingDefinition(_document);
var numbering = _document._wordprocessingDocument.MainDocumentPart!.NumberingDefinitionsPart!.Numbering;

_abstractId = GetNextAbstractNum(numbering);
_numberId = GetNextNumberingInstance(numbering);

var abstractNum = WordListStyles.GetStyle(style);

// set font size for numbering symbol
if (numberingSymbolFontSize != null) {

// Convert to half-point measure
var val = numberingSymbolFontSize * 2;

foreach (Level level in abstractNum.Elements<Level>()) {
NumberingSymbolRunProperties numberingSymbolRunProperties1 = new NumberingSymbolRunProperties();
numberingSymbolRunProperties1.Append(new FontSize() {
Val = val.ToString()
});
level.Append(numberingSymbolRunProperties1);
}
}

abstractNum.AbstractNumberId = _abstractId;
var abstractNumId = new AbstractNumId {
Val = _abstractId
Expand Down
4 changes: 2 additions & 2 deletions OfficeIMO.Word/WordParagraph.PublicMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ public WordParagraph AddTab() {
return wordParagraph;
}

public WordList AddList(WordListStyle style, bool continueNumbering = false) {
public WordList AddList(WordListStyle style, bool continueNumbering = false, int? fontSize = null) {
WordList wordList = new WordList(this._document, this);
wordList.AddList(style, continueNumbering);
wordList.AddList(style, continueNumbering, fontSize);
return wordList;
}

Expand Down
4 changes: 2 additions & 2 deletions OfficeIMO.Word/WordTableCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,9 @@ public WordTable AddTable(int rows, int columns, WordTableStyle tableStyle = Wor
return wordTable;
}

public WordList AddList(WordListStyle style, bool continueNumbering = false) {
public WordList AddList(WordListStyle style, bool continueNumbering = false, int? fontSize = null) {
WordList wordList = new WordList(this._document, this.Paragraphs.Last());
wordList.AddList(style, continueNumbering);
wordList.AddList(style, continueNumbering, fontSize);
return wordList;
}
}
Expand Down