Page 1 of 1

Docx4j and fonts

PostPosted: Thu Oct 23, 2014 4:36 am
by dreamfall
Hi. I'm trying to use docx4j with jruby to process docx templates. But I've encountered a problem with fonts. Fonts (Algerian in example below) are not being used and document is rendered with default font.

Algerian is installed on my computer, and it is available with a command "fc-list":
Code: Select all
$ fc-list | grep Algerian
/home/lupin/.fonts/ALGER.TTF: Algerian:style=Regular,normal,Standard,Normaali,Normale,Standaard
/usr/local/lib/X11/fonts/lupinfonts/ALGER.TTF: Algerian:style=Regular,normal,Standard,Normaali,Normale,Standaard


I've tried to use fop config with autodetect option:
Code: Select all
foSettings.setApacheFopConfiguration(File.read("fop.xconf")) # File.read("fop.xconf") returns a string containing xml of fop config


Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<fop version="1.1">
  <renderers>
    <renderer mime="application/pdf">
      <fonts>
        <directory>/Library/Fonts</directory>
        <auto-detect/>
      </fonts>
    </renderer>
  </renderers>
</fop>


And by specifying exact path in config:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<fop version="1.1">
  <renderers>
    <renderer mime="application/pdf">   
      <font embed-url="file:/home/dreamfall/.fonts/ALGER.TTF">
        <font-triplet name="Algerian" style="normal" weight="normal"/>
      </font>
   </renderer>
  </renderers>
</fop>


But I still get a bunch of warnings.

Code: Select all
[Ruby-0-Fiber-9] WARN org.docx4j.convert.out.fo.renderers.FORendererApacheFOP - Can't set up FOP svn; org.apache.fop.apps.FopConfParser
Oct 22, 2014 8:23:14 PM org.apache.fop.apps.FOUserAgent processEvent
WARNING: Font "Calibri,normal,400" not found. Substituting with "any,normal,400".
[Ruby-0-Fiber-9] WARN org.docx4j.openpackaging.parts.ThemePart - Empty typeface in font for MAJOR_EAST_ASIA
[Ruby-0-Fiber-9] INFO org.docx4j.fonts.RunFontSelector - theme font for lang org.docx4j.wml.CTLanguage@8facabd is null, but we don't have that
[Ruby-0-Fiber-9] WARN org.docx4j.fonts.RunFontSelector - Font 'Cambria' is not mapped to a physical font.
[Ruby-0-Fiber-9] WARN org.docx4j.fonts.RunFontSelector - Font 'Algerian' is not mapped to a physical font.
[Ruby-0-Fiber-9] WARN org.docx4j.fonts.RunFontSelector - Font 'Algerian' is not mapped to a physical font.
[Ruby-0-Fiber-9] WARN org.docx4j.fonts.RunFontSelector - Font 'Algerian' is not mapped to a physical font.
[Ruby-0-Fiber-9] WARN org.docx4j.fonts.RunFontSelector - Font 'Algerian' is not mapped to a physical font.
<fo:inline xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="Symbol"></fo:inline>
<fo:inline xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="Symbol"></fo:inline>
<fo:inline xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="Symbol"></fo:inline>
[Ruby-0-Fiber-9] WARN org.docx4j.convert.out.fo.renderers.FORendererApacheFOP - Can't set up FOP svn; org.apache.fop.apps.FopConfParser
Oct 22, 2014 8:23:15 PM org.apache.fop.apps.FOUserAgent processEvent
WARNING: Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
Oct 22, 2014 8:23:15 PM org.apache.fop.apps.FOUserAgent processEvent
WARNING: Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
Oct 22, 2014 8:23:15 PM org.apache.fop.apps.FOUserAgent processEvent
WARNING: Font "Calibri,normal,700" not found. Substituting with "Calibri,normal,400".
Oct 22, 2014 8:23:15 PM org.apache.fop.apps.FOUserAgent processEvent


I'm sure, I'm doing something wrong, but I am not experienced with Java enough to find a solution. Please give some advice.

Re: Docx4j and fonts

PostPosted: Fri Oct 24, 2014 9:09 am
by jason
docx4j ought to be finding that font:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
package org.docx4j.fonts.fop.fonts.autodetect;

/**
 * Unix font directory finder
 */

public class UnixFontDirFinder extends NativeFontDirFinder {

    /**
     * Some guesses at possible unix font directory locations
     * @return a list of possible font locations
     */

    protected String[] getSearchableDirectories() {
        return new String[] {
            System.getProperty("user.home") + "/.fonts", // user
            "/usr/local/fonts", // local
            "/usr/local/share/fonts", // local shared
            "/usr/share/fonts", // system
            "/usr/X11R6/lib/X11/fonts" // X
        };
    }
}
 
Parsed in 0.016 seconds, using GeSHi 1.0.8.4


at least in /home/lupin/.fonts, if not /usr/local/lib/X11/fonts/lupinfonts

Check the value of System.getProperty("user.home")? (dreamfall or lupin???)

You should also turn DEBUG level logging on for package org.docx4j.fonts