Inserted lists become Arial 11 regardless of default font

Hello,
I am using the Aspose words 21.2(Licensed),
I have set the default font as Garamond and the font size as 12 in the generated doc file. The issue is when I try to add a list inside it, its default font is getting changed in Microsoft Word. The solution I want is consistent font in the whole document.

Also note that this behavior is specific to Microsoft Word editor only, not to other editors. and the font is not changed when I add paragraphs.

@wivo Could you please attach your input and output documents along with code that will allow us to reproduce the problem on our side? We will check the issue and provide you more information.

Formatting of list items are defined in list levels:
https://reference.aspose.com/words/java/com.aspose.words/listlevel/

So most likely in your case different font is defined in the list level.

Here is code snippet and output file.

package nl.nobilex.document.generation.service

import com.aspose.words.Document
import com.aspose.words.DocumentVisitor
import com.aspose.words.Run
import com.aspose.words.VisitorAction

fun main() {
    val doc = Document("Desktop/template.doc")
    doc.accept(FontChanger("Garamond", 14.0))
    doc.save("modified-template.docx")
}

class FontChanger(val fontName: String, val fontSize: Double) : DocumentVisitor() {
    override fun visitRun(run: Run): Int {
        run.font.name = fontName
        run.font.size = fontSize
        return VisitorAction.CONTINUE
    }
}

modified-template.docx (18.8 KB)

@wivo Please try using the following FontChnager:

import com.aspose.words.*;

public class FontChanger extends DocumentVisitor {
    
    public FontChanger(String fontName)  {
        mFontName = fontName;
        mFontSize = 0;
    }
    
    public FontChanger(String fontName, double fontSize)
    {
        mFontName = fontName;
        mFontSize = fontSize;
    }

    /// <summary>
    /// Called when a FieldEnd node is encountered in the document.
    /// </summary>
    @Override
    public int visitFieldEnd(FieldEnd fieldEnd)
    {
        //Simply change font name
        resetFont(fieldEnd.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a FieldSeparator node is encountered in the document.
    /// </summary>
    @Override
    public int visitFieldSeparator(FieldSeparator fieldSeparator)
    {
        resetFont(fieldSeparator.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a FieldStart node is encountered in the document.
    /// </summary>
    @Override
    public int visitFieldStart(FieldStart fieldStart)
    {
        resetFont(fieldStart.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a Footnote end is encountered in the document.
    /// </summary>
    @Override
    public int visitFootnoteEnd(Footnote footnote)
    {
        resetFont(footnote.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a FormField node is encountered in the document.
    /// </summary>
    @Override
    public int visitFormField(FormField formField)
    {
        resetFont(formField.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a Paragraph end is encountered in the document.
    /// </summary>
    @Override
    public int visitParagraphEnd(Paragraph paragraph)
    {
        resetFont(paragraph.getParagraphBreakFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a Run node is encountered in the document.
    /// </summary>
    @Override
    public int visitRun(Run run)
    {
        resetFont(run.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a SpecialChar is encountered in the document.
    /// </summary>
    @Override
    public int visitSpecialChar(SpecialChar specialChar)
    {
        resetFont(specialChar.getFont());
        return VisitorAction.CONTINUE;
    }

    private void resetFont(Font font)
    {
        font.setName(mFontName);
        if(mFontSize > 0)
            font.setSize(mFontSize);
    }

    private String mFontName = "Arial";
    private double mFontSize = 0;
}

Thanks, @alexey.noskov for your reply. This works with numbered lists, bulleted lists, and multilevel lists. However, the issue persists when I add a list with a heading.

@wivo In this case formatting is defined in heading style. So you should change the heading style in your document.