最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【记录】另一次的Docbook 5.0的折腾过程

Docbook crifan 2477浏览 0评论

1. 安装cygwin

这一次是在另一台电脑上,尝试搭建出Docbook 5.0的环境。

此台电脑,之前已经过安装过cygwin了。

但是后来运行程序出了问题:

【基本解决】Cygwin中运行程序出现错误:error while loading shared libraries: ?: cannot open shared object file: No such file or directory

所以,后来,就又重新去下载cygwin的setup.exe,然后打算重新安装。

结果此次安装cygwin的过程中,不知道何种原因,安装出来的cygwin,创建出了一些异常的文件夹,文件夹名称中都带等于号,大括号的那种,所以后来干脆就去彻底删除了此次的所安装的cygwin,结果那些异常的文件夹也删除不掉,后来还是通过360的强制删除,才删掉的。

再后来,就是想要去把旧的,已有的cygwin,卸载掉,但是win7中没有对应的cygwin的卸载选项,所以只好手动删除对应所有相关的文件,包括开始菜单,都全部删除了之后,然后重新下载最新的setup.exe,然后选了163的源,然后完全重新安装。

这一次,找到一个小技巧,那就是,把之前cygwin所下载的本地文件,即在:

cygwin\http%3a%2f%2fmirrors.163.com%2fcygwin%2f\release

下面的所有的已经下载的文件,全部都拷贝到当前正在下载的文件夹中,

这样,cygwin去下载的时候,就会自动检测到本地已经下载的文件,就可以免去了再次下载,大大提高了下载的效率。

提示:上述的中的:

http%3a%2f%2fmirrors.163.com%2fcygwin%2f

用python中的urllib.unquote后,即是163的源地址:http://mirrors.163.com/cygwin/

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import urllib
>>> urllib.unquote("http%3a%2f%2fmirrors.163.com%2fcygwin%2f")
‘http://mirrors.163.com/cygwin/’

这次的安装,算是比较顺利的,一路下载安装下来,都没问题,只是在最后的postInstall中,出了点小问题:

still error brltty

不过貌似也没啥大影响。

不过后来是参考:cygwin-1.77 postinstall fails on many mirrors – missing packages,去试了试

cygcheck –svr

结果一大堆输出,其中看到了not found vi和vim,但是也懒得管了。

2.建立docbook5环境

在安装cygwin过程中,看到了,原来现在最新版本的cygwin中,已经包含了docbook的相关的很多东西。

关于docbook相关的东西,可以在

http%3a%2f%2fmirrors.163.com%2fcygwin%2f\setup.ini

中找到。

安装完毕后,也可以看到一些和docbook相关的工具:

Administrator@K470 ~
$ docbook2
docbook2dvi   docbook2html  docbook2man   docbook2pdf   docbook2ps    docbook2rtf   docbook2tex   docbook2texi  docbook2txt

本地之前已有已下载并解压后的:

libxslt-1.1.26.win32

不过,cygwin中,现在本身已经安装了对应工具:

Administrator@K470 ~
$ xsltproc.exe -V
Using libxml 20708, libxslt 10126 and libexslt 815
xsltproc was compiled against libxml 20708, libxslt 10126 and libexslt 815
libxslt 10126 was compiled against libxml 20708
libexslt 815 was compiled against libxml 20708

Administrator@K470 ~
$ which xsltproc.exe
/usr/bin/xsltproc.exe

Administrator@K470 ~
$ iconv –version
iconv (GNU libiconv 1.14)
Copyright (C) 2000-2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
作者 Bruno Haible。

上面说了,在cygwin安装过程中,都看到过docbook的样式表:docbook-xsl-ns的,所以去找找,安装到了哪里了。

后来找到了,在cygwin下面的:

usr\share\sgml\docbook\xsl-ns-stylesheets\html

中,有我要的docbook.xsl,然后照葫芦画瓢,建个docbook_crl.xsl,写入:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version='1.0'>
<xsl:include href="docbook.xsl"/>
<xsl:output method="html"
            encoding="UTF-8"
            indent="no"/>
</xsl:stylesheet>

然后去生成html,是OK的:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/dev/src
$ xsltproc.exe -o output/html/cnBookTest.html /usr/share/sgml/docbook/xsl-ns-stylesheets/html/docbook_crl.xsl cnBookTest.xml

 

3.用docbook生产pdf

接着去折腾如何生成pdf。

本地现在已经有了fop-1.0了。

然后去fop文件夹下执行fop结果出错:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/config/tool/fop/fop-1.0

$ ./fop

cygwin warning:

  MS-DOS style path detected: E:\Dev_Root\docbook\config\tool\fop\fop-1.0;

  Preferred POSIX equivalent is: /cygdrive/e/Dev_Root/docbook/config/tool/fop/fop-1.0;

  CYGWIN environment variable option "nodosfilewarning" turns off this warning.

  Consult the user’s guide for more details about POSIX paths:

    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames

Error: JAVA_HOME is not defined correctly.

  We cannot execute /cygdrive/d/Program Files/Java/jre6/bin;/bin/java

后来发现,貌似系统有不止一个版本的java:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/config/tool/fop/fop-1.0

$ ./fop

Error: JAVA_HOME is not defined correctly.

  We cannot execute /cygdrive/d/Program Files/Java/jre6/bin;/bin/java

Administrator@K470 /cygdrive/e/Dev_Root/docbook/config/tool/fop/fop-1.0

$ which java

/cygdrive/c/Windows/system32/java

所以去删除system32下面的java试试。

不过发现system32下面的java,版本是7.0.10.8,其实是:

D:\Program Files\Java\jre7

的java,而上面环境变量中的java,则写的是

D:\Program Files\Java\jre6\bin

所以,应该去,删除jre6,然后重新设置正确的JAVA_HOME变量。

结果删除了jre6,把JAVA_HOME改为:

D:\Program Files\Java\jre7;

还是不行:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/config/tool/fop/fop-1.0

$ ./fop

cygwin warning:

  MS-DOS style path detected: E:\Dev_Root\docbook\config\tool\fop\fop-1.0;

  Preferred POSIX equivalent is: /cygdrive/e/Dev_Root/docbook/config/tool/fop/fop-1.0;

  CYGWIN environment variable option "nodosfilewarning" turns off this warning.

  Consult the user’s guide for more details about POSIX paths:

    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames

Error: JAVA_HOME is not defined correctly.

  We cannot execute /cygdrive/d/Program Files/Java/jre7;/bin/java

后来改为把JAVA_HOME改为:

D:\Program Files\Java\jre7

就可以了:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/config/tool/fop/fop-1.0
$ ./fop
cygwin warning:
  MS-DOS style path detected: E:\Dev_Root\docbook\config\tool\fop\fop-1.0;
  Preferred POSIX equivalent is: /cygdrive/e/Dev_Root/docbook/config/tool/fop/fop-1.0;
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlgraphics/image/loader/ImageContext
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.apache.fop.cli.CommandLineOptions.<init>(CommandLineOptions.java:121)
        at org.apache.fop.cli.Main.startFOP(Main.java:157)
        at org.apache.fop.cli.Main.main(Main.java:205)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlgraphics.image.loader.ImageContext
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 15 more

但是却发现,运行windows版本的fop却是可以的:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/config/tool/fop/fop-1.0
$ ./fop.bat
FOP Version 1.0
USAGE
fop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-rtf|-tiff|-png|-pcl|-ps|-txt|-at [mime]|-print] <outfile>
[OPTIONS]
  -version          print FOP version and exit
  -d                debug mode
  -x                dump configuration settings
  -q                quiet mode
  -c cfg.xml        use additional configuration file cfg.xml
  -l lang           the language to use for user information
  -r                relaxed/less strict validation (where available)
  -dpi xxx          target resolution in dots per inch (dpi) where xxx is a number
  -s                for area tree XML, down to block areas only
  -v                run in verbose mode (currently simply print FOP version and continue)
  -o [password]     PDF file will be encrypted with option owner password
  -u [password]     PDF file will be encrypted with option user password
  -noprint          PDF file will be encrypted without printing permission
  -nocopy           PDF file will be encrypted without copy content permission
  -noedit           PDF file will be encrypted without edit content permission
  -noannotations    PDF file will be encrypted without edit annotation permission
  -a                enables accessibility features (Tagged PDF etc., default off)
  -pdfprofile prof  PDF file will be generated with the specified profile
                    (Examples for prof: PDF/A-1b or PDF/X-3:2003)
  -conserve         Enable memory-conservation policy (trades memory-consumption for disk I/O)
                    (Note: currently only influences whether the area tree is serialized.)
[INPUT]
  infile            xsl:fo input file (the same as the next)
                    (use '-' for infile to pipe input from stdin)
  -fo  infile       xsl:fo input file
  -xml infile       xml input file, must be used together with -xsl
  -atin infile      area tree input file
  -ifin infile      intermediate format input file
  -imagein infile   image input file (piping through stdin not supported)
  -xsl stylesheet   xslt stylesheet
  -param name value <value> to use for parameter <name> in xslt stylesheet
                    (repeat '-param name value' for each parameter)
  -catalog          use catalog resolver for input XML and XSLT files
[OUTPUT]
  outfile           input will be rendered as PDF into outfile
                    (use '-' for outfile to pipe output to stdout)
  -pdf outfile      input will be rendered as PDF (outfile req'd)
  -pdfa1b outfile   input will be rendered as PDF/A-1b compliant PDF
                    (outfile req'd, same as "-pdf outfile -pdfprofile PDF/A-1b")
  -awt              input will be displayed on screen
  -rtf outfile      input will be rendered as RTF (outfile req'd)
  -pcl outfile      input will be rendered as PCL (outfile req'd)
  -ps outfile       input will be rendered as PostScript (outfile req'd)
  -afp outfile      input will be rendered as AFP (outfile req'd)
  -tiff outfile     input will be rendered as TIFF (outfile req'd)
  -png outfile      input will be rendered as PNG (outfile req'd)
  -txt outfile      input will be rendered as plain text (outfile req'd)
  -at [mime] out    representation of area tree as XML (outfile req'd)
                    specify optional mime output to allow the AT to be converted
                    to final format later
  -if [mime] out    representation of document in intermediate format XML (outfile req'd)
                    specify optional mime output to allow the IF to be converted
                    to final format later
  -print            input file will be rendered and sent to the printer
                    see options with "-print help"
  -out mime outfile input will be rendered using the given MIME type
                    (outfile req'd) Example: "-out application/pdf D:\out.pdf"
                    (Tip: "-out list" prints the list of supported MIME types)
  -svg outfile      input will be rendered as an SVG slides file (outfile req'd)
                    Experimental feature - requires additional fop-sandbox.jar.
  -foout outfile    input will only be XSL transformed. The intermediate
                    XSL-FO file is saved and no rendering is performed.
                    (Only available if you use -xml and -xsl parameters)
[Examples]
  fop foo.fo foo.pdf
  fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)
  fop -xml foo.xml -xsl foo.xsl -pdf foo.pdf
  fop -xml foo.xml -xsl foo.xsl -foout foo.fo
  fop -xml - -xsl foo.xsl -pdf -
  fop foo.fo -mif foo.mif
  fop foo.fo -rtf foo.rtf
  fop foo.fo -print
  fop foo.fo -awt
Administrator@K470 /cygdrive/e/Dev_Root/docbook/config/tool/fop/fop-1.0
$ ./fop.cmd
FOP Version 1.0
USAGE
fop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-rtf|-tiff|-png|-pcl|-ps|-txt|-at [mime]|-print] <outfile>
[OPTIONS]
  -version          print FOP version and exit
  -d                debug mode
  -x                dump configuration settings
  -q                quiet mode
  -c cfg.xml        use additional configuration file cfg.xml
  -l lang           the language to use for user information
  -r                relaxed/less strict validation (where available)
  -dpi xxx          target resolution in dots per inch (dpi) where xxx is a number
  -s                for area tree XML, down to block areas only
  -v                run in verbose mode (currently simply print FOP version and continue)
  -o [password]     PDF file will be encrypted with option owner password
  -u [password]     PDF file will be encrypted with option user password
  -noprint          PDF file will be encrypted without printing permission
  -nocopy           PDF file will be encrypted without copy content permission
  -noedit           PDF file will be encrypted without edit content permission
  -noannotations    PDF file will be encrypted without edit annotation permission
  -a                enables accessibility features (Tagged PDF etc., default off)
  -pdfprofile prof  PDF file will be generated with the specified profile
                    (Examples for prof: PDF/A-1b or PDF/X-3:2003)
  -conserve         Enable memory-conservation policy (trades memory-consumption for disk I/O)
                    (Note: currently only influences whether the area tree is serialized.)
[INPUT]
  infile            xsl:fo input file (the same as the next)
                    (use '-' for infile to pipe input from stdin)
  -fo  infile       xsl:fo input file
  -xml infile       xml input file, must be used together with -xsl
  -atin infile      area tree input file
  -ifin infile      intermediate format input file
  -imagein infile   image input file (piping through stdin not supported)
  -xsl stylesheet   xslt stylesheet
  -param name value <value> to use for parameter <name> in xslt stylesheet
                    (repeat '-param name value' for each parameter)
  -catalog          use catalog resolver for input XML and XSLT files
[OUTPUT]
  outfile           input will be rendered as PDF into outfile
                    (use '-' for outfile to pipe output to stdout)
  -pdf outfile      input will be rendered as PDF (outfile req'd)
  -pdfa1b outfile   input will be rendered as PDF/A-1b compliant PDF
                    (outfile req'd, same as "-pdf outfile -pdfprofile PDF/A-1b")
  -awt              input will be displayed on screen
  -rtf outfile      input will be rendered as RTF (outfile req'd)
  -pcl outfile      input will be rendered as PCL (outfile req'd)
  -ps outfile       input will be rendered as PostScript (outfile req'd)
  -afp outfile      input will be rendered as AFP (outfile req'd)
  -tiff outfile     input will be rendered as TIFF (outfile req'd)
  -png outfile      input will be rendered as PNG (outfile req'd)
  -txt outfile      input will be rendered as plain text (outfile req'd)
  -at [mime] out    representation of area tree as XML (outfile req'd)
                    specify optional mime output to allow the AT to be converted
                    to final format later
  -if [mime] out    representation of document in intermediate format XML (outfile req'd)
                    specify optional mime output to allow the IF to be converted
                    to final format later
  -print            input file will be rendered and sent to the printer
                    see options with "-print help"
  -out mime outfile input will be rendered using the given MIME type
                    (outfile req'd) Example: "-out application/pdf D:\out.pdf"
                    (Tip: "-out list" prints the list of supported MIME types)
  -svg outfile      input will be rendered as an SVG slides file (outfile req'd)
                    Experimental feature - requires additional fop-sandbox.jar.
  -foout outfile    input will only be XSL transformed. The intermediate
                    XSL-FO file is saved and no rendering is performed.
                    (Only available if you use -xml and -xsl parameters)
[Examples]
  fop foo.fo foo.pdf
  fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)
  fop -xml foo.xml -xsl foo.xsl -pdf foo.pdf
  fop -xml foo.xml -xsl foo.xsl -foout foo.fo
  fop -xml - -xsl foo.xsl -pdf -
  fop foo.fo -mif foo.mif
  fop foo.fo -rtf foo.rtf
  fop foo.fo -print
  fop foo.fo -awt

此处fop/fonts下面也已经有了之前弄好的font了:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/config/tool/fop/fop-1.0

$ ls fonts/ -l

total 1716

-rwx——+ 1 Administrators None 551993 Nov 10 22:36 msyh_ttf.xml

-rwx——+ 1 Administrators None 564198 Nov 10 22:37 msyhbd_ttf.xml

-rwx——+ 1 Administrators None 316624 Nov 10 15:24 simhei.xml

-rwx——+ 1 Administrators None 318963 Nov 10 15:03 simsun.xml

而且fop\fop-1.0\conf\fop.xconf也是之前配置好了的:

 <font metrics-url="fonts/simsun.xml" kerning="yes" embed-url="file:///c:/windows/fonts/simsun.ttc">
    <font-triplet name="SimSun" style="normal" weight="normal"/>
    <font-triplet name="SimSun" style="normal" weight="bold"/>
    <font-triplet name="SimSun" style="italic" weight="normal"/>
    <font-triplet name="SimSun" style="italic" weight="bold"/>
  </font>
  <font metrics-url="fonts/simhei.xml" kerning="yes" embed-url="file:///c:/windows/fonts/simhei.ttf">
    <font-triplet name="SimHei" style="normal" weight="normal"/>
    <font-triplet name="SimHei" style="normal" weight="bold"/>
    <font-triplet name="SimHei" style="italic" weight="normal"/>
    <font-triplet name="SimHei" style="italic" weight="bold"/>
  </font>
    <font metrics-url="fonts/msyh_ttf.xml" kerning="yes" embed-url="file:///c:/windows/fonts/msyh.ttf">
    <font-triplet name="Microsoft YaHei" style="normal" weight="normal"/>
    <font-triplet name="Microsoft YaHei" style="normal" weight="bold"/>
    <font-triplet name="Microsoft YaHei" style="italic" weight="normal"/>
    <font-triplet name="Microsoft YaHei" style="italic" weight="bold"/>
  </font>
  <directory recursive="true">file:///c:/windows/fonts/</directory>
  <auto-detect/>

然后又重新建立了一个docbook_fo_crl.xsl文件:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:exsl="http://exslt.org/common"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  xmlns:ng="http://docbook.org/docbook-ng"
  xmlns:db="http://docbook.org/ns/docbook"
  exclude-result-prefixes="db ng exsl"
  version='1.0'>

  <!-- <xsl:import href="C:/docbook/docbook-xsl-1.74.3/fo/docbook.xsl"/> -->   
  <!-- <xsl:import href="E:/Dev_Root/DocBook/config/style/xsl/1.76.1/docbook-xsl-1.76.1/fo/docbook.xsl"/> -->
  <xsl:import href="docbook.xsl"/>

  <!-- <xsl:param name="body.font.family">SimSun</xsl:param> -->
  <xsl:param name="body.font.family">Microsoft YaHei</xsl:param>
  <xsl:param name="monospace.font.family">SimSun</xsl:param>
  <xsl:param name="title.font.family">SimHei</xsl:param>

</xsl:stylesheet>

放到\usr\share\sgml\docbook\xsl-ns-stylesheets\fo下面,然后去生成fo文件:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/dev/src
$ xsltproc.exe -o output/fo/cnBookTest.fo /usr/share/sgml/docbook/xsl-ns-stylesheets/fo/docbook_fo_crl.xsl cnBookTest.xml
Making portrait pages on USletter paper (8.5inx11in)

后来折腾半天,还是无法在cygwin下使用fop,然后只能在cmd下使用fop:

E:\Dev_Root\docbook\config\tool\fop\fop-1.0>fop -c conf\fop.xconf E:\Dev_Root\docbook\dev\src\output\fo\cnBookTest.fo -pdf E:\Dev_Root\docbook\dev\src\output\pdf\cnBookTest.pdf
四月 29, 2012 2:39:03 下午 org.apache.fop.apps.FopFactoryConfigurator configure
信息: Default page-height set to: 11in
四月 29, 2012 2:39:03 下午 org.apache.fop.apps.FopFactoryConfigurator configure
信息: Default page-width set to: 8.26in
四月 29, 2012 2:39:05 下午 org.apache.fop.events.LoggingEventListener processEvent
警告: Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
四月 29, 2012 2:39:05 下午 org.apache.fop.events.LoggingEventListener processEvent
警告: Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
四月 29, 2012 2:39:05 下午 org.apache.fop.hyphenation.Hyphenator getHyphenationTree
严重: Couldn't find hyphenation pattern zh_cn

但是生成出来的pdf,中文乱码:

cn messy code

折腾了一会,还是乱码。

看了得回去重新生成对应的font,看看是否可行。

在cmd下运行成功:

E:\Dev_Root\docbook\config\tool\fop\fop-1.0>java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar;lib\xmlgraphics-commons-1.4.jar org.apache.fop.fonts.apps.TTFReader -ttcname SimHei c:\WINDOWS\Fonts\simhei.ttf fonts\simhei.xml
TTF Reader for Apache FOP 1.0
Parsing font...
Reading c:\WINDOWS\Fonts\simhei.ttf...
Font Family: [黑体, SimHei]
Creating xml font file...
Creating CID encoded metrics...
Writing xml font file fonts\simhei.xml...
This font contains no embedding license restrictions.
XML font metrics file successfully created.

E:\Dev_Root\docbook\config\tool\fop\fop-1.0>java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar;lib\xmlgraphics-commons-1.4.jar org.apache.fop.fonts.apps.TTFReader -ttcname SimSun c:\WINDOWS\Fonts\simsun.ttc fonts\simsun.xml
TTF Reader for Apache FOP 1.0
Parsing font...
Reading c:\WINDOWS\Fonts\simsun.ttc...
This is a TrueType collection file with 2 fonts
Containing the following fonts:
SimSun <-- selected
NSimSun
Font Family: [宋体, SimSun]
Creating xml font file...
Creating CID encoded metrics...
Writing xml font file fonts\simsun.xml...
This font contains no embedding license restrictions.
XML font metrics file successfully created.

然后再去把:

E:\dev_install_root\cygwin\usr\share\sgml\docbook\xsl-ns-stylesheets\fo\docbook_fo_crl.xsl

改为:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:exsl="http://exslt.org/common"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  xmlns:ng="http://docbook.org/docbook-ng"
  xmlns:db="http://docbook.org/ns/docbook"
  exclude-result-prefixes="db ng exsl"
  version='1.0'>

  <!-- <xsl:import href="C:/docbook/docbook-xsl-1.74.3/fo/docbook.xsl"/> -->   
  <!-- <xsl:import href="E:/Dev_Root/DocBook/config/style/xsl/1.76.1/docbook-xsl-1.76.1/fo/docbook.xsl"/> -->
  <xsl:import href="docbook.xsl"/>

  <!-- <xsl:param name="body.font.family">SimSun</xsl:param> -->
  <!-- <xsl:param name="body.font.family">Microsoft YaHei</xsl:param> -->
<xsl:import href="docbook.xsl"/>
<xsl:param name="body.font.family">SimSun</xsl:param>
<xsl:param name="monospace.font.family">SimSun</xsl:param>
<xsl:param name="title.font.family">SimHei</xsl:param>
</xsl:stylesheet>

去cygwin中:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/config/tool/fop/fop-1.0
$ xsltproc.exe -o /cygdrive/e/Dev_Root/docbook/dev/src/output/fo/cnBookTest.fo /usr/share/sgml/docbook/xsl-ns-stylesheets/fo/docbook_fo_crl.xsl /cygdrive/e/Dev_Root/docbook/dev/src/cnBookTest.xml
Making portrait pages on USletter paper (8.5inx11in)

去cmd中:

E:\Dev_Root\docbook\config\tool\fop\fop-1.0>fop -c conf\fop.xconf E:\Dev_Root\docbook\dev\src\output\fo\cnBookTest.fo -pdf E:\Dev_Root\docbook\dev\src\output\pd
f\cnBookTest.pdf
四月 29, 2012 3:29:44 下午 org.apache.fop.apps.FopFactoryConfigurator configure
信息: Default page-height set to: 11in
四月 29, 2012 3:29:44 下午 org.apache.fop.apps.FopFactoryConfigurator configure
信息: Default page-width set to: 8.26in
四月 29, 2012 3:29:45 下午 org.apache.fop.events.LoggingEventListener processEvent
警告: Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
四月 29, 2012 3:29:45 下午 org.apache.fop.events.LoggingEventListener processEvent
警告: Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
四月 29, 2012 3:29:45 下午 org.apache.fop.hyphenation.Hyphenator getHyphenationTree
严重: Couldn't find hyphenation pattern zh_cn
四月 29, 2012 3:29:45 下午 org.apache.fop.fonts.truetype.TTFFile checkTTC
信息: This is a TrueType collection file with 2 fonts
四月 29, 2012 3:29:45 下午 org.apache.fop.fonts.truetype.TTFFile checkTTC
信息: Containing the following fonts:
四月 29, 2012 3:29:45 下午 org.apache.fop.fonts.truetype.TTFFile checkTTC
信息: SimSun <-- selected
四月 29, 2012 3:29:45 下午 org.apache.fop.fonts.truetype.TTFFile checkTTC
信息: NSimSun

然后生成的cnBookTest.pdf中的中文就正常了:

cn font OK

4.让docbook用雅黑字体

后来想要折腾雅黑字体,就去给win7安装上雅黑字体,然后再生成对应的font的xml文件:

E:\Dev_Root\docbook\config\tool\fop\fop-1.0>java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar;lib\xmlgraphics-commons-1.4.jar org.apache.fop.fonts.apps.TTFReader -ttcname msyh c:\WINDOWS\Fonts\msyh.ttf fonts\msyh.xml
TTF Reader for Apache FOP 1.0

Parsing font...
Reading c:\WINDOWS\Fonts\msyh.ttf...
Font Family: [微软雅黑, Microsoft YaHei]
Creating xml font file...
Creating CID encoded metrics...
Writing xml font file fonts\msyh.xml...
This font contains no embedding license restrictions.

XML font metrics file successfully created.

E:\Dev_Root\docbook\config\tool\fop\fop-1.0>java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar;lib\xml
graphics-commons-1.4.jar org.apache.fop.fonts.apps.TTFReader -ttcname msyhbd c:\WINDOWS\Fonts\msyhbd.ttf fonts\msyhbd.xml
TTF Reader for Apache FOP 1.0

Parsing font...
Reading c:\WINDOWS\Fonts\msyhbd.ttf...
Font Family: [微软雅黑, Microsoft YaHei]
Creating xml font file...
Creating CID encoded metrics...
Writing xml font file fonts\msyhbd.xml...
This font contains no embedding license restrictions.

XML font metrics file successfully created.

然后新添加了个docbook_fo_cr_yahei.xsl:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:exsl="http://exslt.org/common"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  xmlns:ng="http://docbook.org/docbook-ng"
  xmlns:db="http://docbook.org/ns/docbook"
  exclude-result-prefixes="db ng exsl"
  version='1.0'>

  <!-- <xsl:import href="C:/docbook/docbook-xsl-1.74.3/fo/docbook.xsl"/> -->   
  <!-- <xsl:import href="E:/Dev_Root/DocBook/config/style/xsl/1.76.1/docbook-xsl-1.76.1/fo/docbook.xsl"/> -->
  <xsl:import href="docbook.xsl"/>

  <!-- <xsl:param name="body.font.family">SimSun</xsl:param> -->
  <!-- <xsl:param name="body.font.family">Microsoft YaHei</xsl:param> -->
<xsl:import href="docbook.xsl"/>
<xsl:param name="body.font.family">msyh</xsl:param>
<xsl:param name="monospace.font.family">msyh</xsl:param>
<xsl:param name="title.font.family">msyh</xsl:param>
</xsl:stylesheet>

给fop.xconf中添加了:

  		  <!-- <font metrics-url="fonts/msyh_ttf.xml" kerning="yes" embed-url="file:///c:/windows/fonts/msyh.ttf"> -->
          <font metrics-url="E:\Dev_Root\docbook\config\tool\fop\fop-1.0\fonts\msyh.xml" kerning="yes" embed-url="C:\Windows\Fonts\msyh.ttf">
			<font-triplet name="msyh" style="normal" weight="normal"/>
			<font-triplet name="msyh" style="normal" weight="bold"/>
			<font-triplet name="msyh" style="italic" weight="normal"/>
			<font-triplet name="msyh" style="italic" weight="bold"/>
		  </font>

然后再去编译:

cygwin中:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/config/tool/fop/fop-1.0
$ xsltproc.exe -o /cygdrive/e/Dev_Root/docbook/dev/src/output/fo/cnBookTest_yahei.fo /usr/share/sgml/docbook/xsl-ns-stylesheets/fo/docbook_fo_cr_yahei.x       sl /cygdrive/e/Dev_Root/docbook/dev/src/cnBookTest.xml
Making portrait pages on USletter paper (8.5inx11in)

cmd中:

E:\Dev_Root\docbook\config\tool\fop\fop-1.0>fop -c conf\fop.xconf E:\Dev_Root\docbook\dev\src\output\fo\cnBookTest_yahei.fo -pdf E:\Dev_Root\docbook\dev\src\out
put\pdf\cnBookTest_yahei.pdf
四月 29, 2012 4:17:31 下午 org.apache.fop.apps.FopFactoryConfigurator configure
信息: Default page-height set to: 11in
四月 29, 2012 4:17:31 下午 org.apache.fop.apps.FopFactoryConfigurator configure
信息: Default page-width set to: 8.26in
四月 29, 2012 4:17:33 下午 org.apache.fop.events.LoggingEventListener processEvent
警告: Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
四月 29, 2012 4:17:33 下午 org.apache.fop.events.LoggingEventListener processEvent
警告: Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
四月 29, 2012 4:17:33 下午 org.apache.fop.hyphenation.Hyphenator getHyphenationTree
严重: Couldn't find hyphenation pattern zh_cn

就可以生成了对应的雅黑字体的中文pdf了。

和之前simsun和simhei对比效果如下:

msyh vs simsun simhei

转载请注明:在路上 » 【记录】另一次的Docbook 5.0的折腾过程

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.301 seconds, using 22.47MB memory