【问题】
docbook生成的pdf中,默认的qandaentry中的question部分,是没有任何提示显示的,即没有像HTML中那样的背景色的:
该HTML中背景色,是我通过css控制的:
/* QandA: Question and Answer */ tr.question { background-color: antiquewhite ; }
而pdf中,是没有此背景色的:
现在希望给pdf中也添加同样的配置,给question内容添加背景色。
【解决过程】
1.还是用之前的照葫芦画瓢的方法,先找到相关的fo的源码:
<fo:list-item id="id36188865" space-before.optimum="1em" space-before.minimum="0.8em" space-before.maximum="1.2em"> <fo:list-item-label id="id36188867" end-indent="label-end()"> <fo:block font-weight="bold">3.2.</fo:block> </fo:list-item-label> <fo:list-item-body start-indent="body-start()"> <fo:block space-before.optimum="1em" space-before.minimum="0.8em" space-before.maximum="1.2em"> 除了章(Chapter)有编号之外,其他不同层级的小节(section)都是没有编号的,想要给各小节添加索引编号 </fo:block> </fo:list-item-body> </fo:list-item>
然后想到了,之前别的pdf中,table的thead部分的已经添加了背景色了:
其对应的fo源码为:
<fo:table-row keep-with-next.within-column="always"><fo:table-cell padding-start="2pt" padding-end="2pt" padding-top="2pt" padding-bottom="2pt" background-color="antiquewhite" border-bottom-width="0.5pt" border-bottom-style="solid" border-bottom-color="green" border-end-width="0.5pt" border-end-style="solid" border-end-color="green"><fo:block font-weight="bold">位置(bit)</fo:block></fo:table-cell><fo:table-cell padding-start="2pt" padding-end="2pt" padding-top="2pt" padding-bottom="2pt" background-color="antiquewhite" border-bottom-width="0.5pt" border-bottom-style="solid" border-bottom-color="green" border-end-width="0.5pt" border-end-style="solid" border-end-color="green"><fo:block font-weight="bold">长度(bit)</fo:block></fo:table-cell><fo:table-cell padding-start="2pt" padding-end="2pt" padding-top="2pt" padding-bottom="2pt" background-color="antiquewhite" border-bottom-width="0.5pt" border-bottom-style="solid" border-bottom-color="green" border-end-width="0.5pt" border-end-style="solid" border-end-color="green"><fo:block font-weight="bold">含义</fo:block></fo:table-cell><fo:table-cell padding-start="2pt" padding-end="2pt" padding-top="2pt" padding-bottom="2pt" background-color="antiquewhite" border-bottom-width="0.5pt" border-bottom-style="solid" border-bottom-color="green"><fo:block font-weight="bold">示例</fo:block></fo:table-cell></fo:table-row>
可见,其对于相关内容,就只是添加了一个:
background-color="antiquewhite"
而已,就可以实现背景色了。
所以,此处就是想办法,把此设置,添加到question中去,即可。
2.然后试了试,手动给fo:list-item添加了background-color="antiquewhite" ,生成的pdf中,就的确出现了对应的question部分的内容,都添加上了背景色了:
接下来就是看看,如何添加此设置到对应的xsl配置中去。
3.最后是以这样的方式,添加相应设置的:
<!-- heading type background color --> <xsl:param name="heading_type_bgcolor">antiquewhite</xsl:param> <!--============================================================================ question background color setting =============================================================================--> <!-- copy from docbook-xsl-ns-1.77.0\fo\qandaset.xsl --> <xsl:template match="d:question"> <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable> <xsl:variable name="entry.id"> <xsl:call-template name="object.id"> <xsl:with-param name="object" select="parent::*"/> </xsl:call-template> </xsl:variable> <xsl:variable name="deflabel"> <xsl:apply-templates select="." mode="qanda.defaultlabel"/> </xsl:variable> <xsl:variable name="label.content"> <xsl:apply-templates select="." mode="label.markup"/> <xsl:if test="contains($deflabel, 'number') and not(d:label)"> <xsl:apply-templates select="." mode="intralabel.punctuation"/> </xsl:if> </xsl:variable> <!-- changed by crifan start --> <!-- <fo:list-item id="{$entry.id}" xsl:use-attribute-sets="list.item.spacing"> --> <!-- <fo:list-item background-color="antiquewhite" id="{$entry.id}" xsl:use-attribute-sets="list.item.spacing"> --> <fo:list-item id="{$entry.id}" xsl:use-attribute-sets="list.item.spacing"> <!-- <xsl:attribute name="background-color">antiquewhite</xsl:attribute> --> <xsl:attribute name="background-color"> <xsl:value-of select="$heading_type_bgcolor"/> </xsl:attribute> <!-- changed by crifan end --> <fo:list-item-label id="{$id}" end-indent="label-end()"> <xsl:if test="string-length($label.content) > 0"> <fo:block font-weight="bold"> <xsl:copy-of select="$label.content"/> </fo:block> </xsl:if> </fo:list-item-label> <fo:list-item-body start-indent="body-start()"> <xsl:choose> <xsl:when test="$deflabel = 'none' and not(d:label)"> <fo:block font-weight="bold"> <xsl:apply-templates select="*[local-name(.)!='label']"/> </fo:block> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="*[local-name(.)!='label']"/> </xsl:otherwise> </xsl:choose> <!-- Uncomment this line to get revhistory output in the question --> <!-- <xsl:apply-templates select="preceding-sibling::d:revhistory"/> --> </fo:list-item-body> </fo:list-item> </xsl:template>