Page 1 of 1

Define default font for XHTMImporter ?

PostPosted: Wed Mar 18, 2015 5:14 am
by PeterR
Hello,

I use XHTMLImporter to insert html code into a Winword document.

There is no kind of font definition in the html code.

This gets imported as "Times New Roman".

Any way to change the default font to "Arial" for all imported text ?

Thank you!

Peter

Re: Define default font for XHTMImporter ?

PostPosted: Fri Mar 20, 2015 5:55 pm
by jason
XHTMLImporterImpl contains:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting

       
    /**
         * Map a font family, for example "Century Gothic" in:
         *
         *    font-family:"Century Gothic", Helvetica, Arial, sans-serif;
         *
         * to a w:rFonts object, for example:
         *
         *    <w:rFonts w:ascii="Arial Black" w:hAnsi="Arial Black"/>
         *
         * Assuming style font-family:"Century Gothic", Helvetica, Arial, sans-serif;
         * the first font family for which there is a mapping is the one
         * which will be used.
         *
         * xhtml-renderer's CSSName defaults font-family: serif
         *
         * It is your responsibility to ensure a suitable font is available
         * on the target system (or embedded in the docx package).  If we
         * (eventually) support CSS @font-face, docx4j could do that
         * for you (at least for font formats we can convert to something
         * embeddable).
         *
         * You should set these up once, for all your subsequent
         * imports, since some stuff is cached and currently won't get updated
         * if you add fonts later.
         *
         * @since 3.0
         */

        public static void addFontMapping(String cssFontFamily, RFonts rFonts) {
                FontHandler.addFontMapping(cssFontFamily, rFonts);
        }

        public static void addFontMapping(String cssFontFamily, String font) {
               
                FontHandler.addFontMapping(cssFontFamily, font);
        }
 
Parsed in 0.015 seconds, using GeSHi 1.0.8.4


Although the CSS defaults https://github.com/plutext/docx4j-Impor ... andler.css don't
specify the font for most elements, note the comment above which says defaults font-family: serif is used.

See also https://github.com/plutext/docx4j-Impor ... ndler.java