OfficeIMO icon indicating copy to clipboard operation
OfficeIMO copied to clipboard

update(lists): add symbol font size option

Open tmpmachine opened this issue 1 year ago • 6 comments

Issue: Currently there's no way to set font size of the list's numbering/bullet symbol.

int listItemFontSize = 14;

WordList wordList1 = document.AddList(WordListStyle.Headings111, false);
wordList1.AddItem("Text 1", 0)
    .SetFontSize(listItemFontSize);
wordList1.AddItem("Text 2", 1);
wordList1.AddItem("Text 3", 2);

image

This PR adds the option to set the font size for numbering symbols in AddList().

// font size for both items and list's symbol
int listFontSize = 14;

WordList wordList1 = document.AddList(WordListStyle.Headings111, false, listFontSize);
wordList1.AddItem("Text 1", 0)
    .SetFontSize(listFontSize);
wordList1.AddItem("Text 2", 1);
wordList1.AddItem("Text 3", 2);

image

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

tmpmachine avatar Feb 02 '24 10:02 tmpmachine

Would you be able to add some tests around it? Checking that expectations meets reality?

PrzemyslawKlys avatar Feb 02 '24 10:02 PrzemyslawKlys

I'll take a look on the test code.

tmpmachine avatar Feb 02 '24 10:02 tmpmachine

Seems like the initial WordListStyle's NumberingSymbolRunProperties is being applied to the whole wordlist of the same style.

~~Not sure where to check next. Got any lead?~~ Nevermind, I'm checking the markup now in open XML productivity tool.

image

// Heading1ai
{
    int listFontSize = 32;
    var wordList2 = doc.AddList(WordListStyle.Heading1ai, false, listFontSize);
    foreach (var point in data.ListContent)
    {
        wordList2.AddItem($"{point}", 0)
            .SetFontSize(listFontSize);
    }
}
{
    // font size on numbering symbol not applied
    int listFontSize = 10;
    var wordList2 = doc.AddList(WordListStyle.Heading1ai, false, listFontSize);
    foreach (var point in data.ListContent)
    {
        wordList2.AddItem($"{point}", 0)
            .SetFontSize(listFontSize);
    }
}

// Bulleted
{
    int listFontSize = 10;
    var wordList2 = doc.AddList(WordListStyle.Bulleted, false, listFontSize);
    foreach (var point in data.ListContent)
    {
        wordList2.AddItem($"{point}", 0)
            .SetFontSize(listFontSize);
    }
}
{
    // font size on numbering symbol not applied
    int listFontSize = 24;
    var wordList2 = doc.AddList(WordListStyle.Bulleted, false, listFontSize);
    foreach (var point in data.ListContent)
    {
        wordList2.AddItem($"{point}", 0)
            .SetFontSize(listFontSize);
    }
}

tmpmachine avatar Feb 05 '24 04:02 tmpmachine

After merging with master

image

internal static void Example_BasicLists8(string folderPath, bool openWord) {
    Console.WriteLine("[*] Creating standard document with lists - Document 8");
    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, 15);
        wordList1.AddItem("Text 1");
        wordList1.AddItem("Text 1.1");
        wordList1.AddItem("Text 1.2");
        wordList1.AddItem("Text 1.3");

        document.AddParagraph("Second List");
        document.AddParagraph();

        WordList wordList2 = document.AddList(WordListStyle.Headings111, false, 25);
        wordList2.AddItem("Text 2");
        wordList2.AddItem("Text 2.1");
        wordList2.AddItem("Text 2.2");
        wordList2.AddItem("Text 2.3");
        wordList2.AddItem("Text 2.4");

        document.AddParagraph("Third List");
        document.AddParagraph();

        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);
    }
}

You're now ready to continue ;)

PrzemyslawKlys avatar Feb 05 '24 14:02 PrzemyslawKlys

Althought it still would be valid what's the difference between using it how you are using and how Word uses Paragraph Properties for that.

PrzemyslawKlys avatar Feb 05 '24 14:02 PrzemyslawKlys

awesome, thanks!

tmpmachine avatar Feb 06 '24 17:02 tmpmachine