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

Conversation

tmpmachine
Copy link

@tmpmachine tmpmachine commented Feb 2, 2024

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.

@PrzemyslawKlys
Copy link
Member

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

@tmpmachine
Copy link
Author

I'll take a look on the test code.

@tmpmachine
Copy link
Author

tmpmachine commented Feb 5, 2024

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

@PrzemyslawKlys
Copy link
Member

PrzemyslawKlys commented Feb 5, 2024

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
Copy link
Member

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.

@tmpmachine
Copy link
Author

awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants