如何使用 FOP 在 XML-FO 中指定 2ch 的缩进 [英] How to specify an indent of 2ch in XML-FO using FOP

查看:24
本文介绍了如何使用 FOP 在 XML-FO 中指定 2ch 的缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 XML-FO 文档中使用固定宽度字体创建两个字符的缩进.我正在使用 FOP 翻译它.

I'm trying to create an indentation of two characters with a fixed-width font in an XML-FO document. I'm translating it using FOP.

不幸的是,当我指定像 "2ch" 这样的长度时,FOP 会产生以下错误消息:

Unfortunately, when I specify a length like "2ch", FOP produces this error message:

[ERROR] PropertyMaker - Unknown length unit 'ch'

XML-FO 文档声明允许任何 CSS 已知的长度单位,并且 CSS 指定 ch0 字符的宽度.所以 AFAIU 这应该有效,但仍然无效.

The XML-FO documentation states that any CSS-known length unit is allowed, and CSS specifies that ch is the width of the 0 character. So AFAIU this should work and still doesn't.

我也没有找到 FOP 理解的长度单位的具体列表(ix 也不起作用).不过,em 是可以理解的.但它表示(即使使用固定宽度字体等宽字体)宽度约为 1.5 个字符.

I also failed to find a concrete list of length units understood by FOP (the ix also didn't work). The em is understood, though. But it represents (even while using the fixed-width font monospace) a width about as wide as 1.5 characters.

有没有办法指定等宽缩进两个字符?

Is there a way to specify to have an indent of two characters in monospace?

是否有 FOP 支持的长度单位的完整列表?

Is there a comprehensive list of length units supported by FOP?

是否有另一种方法可以实现我缩进具体数量的字符的目标?我可以使用像 1.3em 这样的 hack,但这可能不准确.

Is there another way to achieve my goal of indenting by a concrete amount of characters? I could use a hack like 1.3em but that is probably not exact.

推荐答案

XSL 推荐 是:

  • cm(厘米)
  • mm(毫米)
  • in(英寸)
  • pt(点数)
  • pc (picas)
  • px(像素)
  • em(当前字体大小)
  • cm (centimetres)
  • mm (millimetres)
  • in (inches)
  • pt (points)
  • pc (picas)
  • px (pixels)
  • em (current font-size)

FOP 支持所有这些,并添加了 mpt(毫点),但正如您所注意到的,没有一个是指等宽字符的字符宽度字体.

FOP supports them all, with the addition of mpt (millipoints), but none of them, as you noticed, refer to the width of a character for a monospaced font.

其他格式化程序可能支持其他度量单位,例如我看到 AntennaHouse XSLFormatter 支持 ch.

Other formatters may support additional units of measure, for example I see AntennaHouse XSLFormatter supports ch.

如果您只需要一个 text-indent(即仅用于第一行),您可以使用不间断空格:

If you need only a text-indent (i.e. just for the first line), you can use non-breaking spaces:

<fo:block>&#x00A0;&#x00A0;Lorem ipsum dolor ...</fo:block>

如果您事先知道该块只会生成一行,您还可以使用保留的常规空格来使 FO 文件更易于阅读:

If you know in advance the block will generate just one line, you could also use preserved regular spaces for easier readability of the FO file:

<fo:block white-space-treatment="preserve" 
    white-space-collapse="false">  Lorem ipsum dolor ...</fo:block>

在最一般的情况下(如果你想定义一个 start-indent, end-indent, ...),你可以使用字体信息:

In the most general case (if you want to define a start-indent, end-indent, ...), you can compute the exact value using the font information:

  1. 创建字体度量

  1. create the font metrics

java -classpath build/fop.jar:fop/lib/avalon-framework-api-4.3.1.jar:fop/lib/commons-logging-1.0.4.jar:fop/lib/commons-io-1.3.1.jar:fop/lib/xmlgraphics-commons-svn-trunk.jar org.apache.fop.fonts.apps.TTFReader -enc ansi/path/to/font.ttf metrics.xml

打开 metrics.xml 并查找类似于 (wdt 值可以不同,但​​对于所有 char 元素应该相同)

open metrics.xml and look for an element similar to <char idx="29" wdt="600"/> (the wdt value can be different, but it should be the same for all char elements)

wdt 是以毫点为单位的字符宽度:将它乘以 font-size 和字符数,你得到你需要的长度

wdt is the width of a character in millipoints: multiply it for the font-size and the number of characters, and you get the length you need

例如: 600 x 12 x 2 = 14400mpt = 14.4pt = font-size 为 12pt 的两个字符的长度

For example: 600 x 12 x 2 = 14400mpt = 14.4pt = length of two characters with a font-size of 12pt

这篇关于如何使用 FOP 在 XML-FO 中指定 2ch 的缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆