Selecting file formats

Graphics files come in many different formats, such as PNG, EPS, and JPEG. Unfortunately, there is no single graphics file format that meets all needs. HTML output files require bitmap graphics such as PNG or JPEG. Some browsers are beginning to accept SVG (scalable vector graphics), but support is not universal. XSL-FO processors generally accept bitmap graphics and vector graphics, but not all of them accept all formats.

If you are publishing only HTML output, then you just need to convert your pictures to one of the common bitmap formats such as PNG, GIF, or JPEG. All graphical browsers support these formats. But if you need to produce both HTML and print output from the same DocBook documents, then you may need more than one format. The formats you choose will depend on the type of illustration and the XSL-FO processor you use.

If you are using a screenshot, then a bitmap graphic can work for both HTML and print output. That's because the original screen itself was a bitmap display, so it will look good in HTML. It also won't improve or degrade when used in print. You still may want to scale the graphic differently for the two outputs.

If you are using a drawn illustration, you probably want to generate two graphic files derived from the same source drawing. Computer drawings use vector graphics, which produce smooth lines when reproduced at high resolution, such as in print. They can also be rendered at lower resolution if needed. But most HTML browsers don't accept vector graphics at all. So a typical solution is to produce two versions of the same picture, using a vector graphic format for print, and a bitmap format for HTML. All drawing programs provide several output formats to choose from, so check your software documentation to see which formats it can export to.

You also need to check the documentation of your XSL-FO processor to see what graphics file formats it supports. The following is a list as of this writing.

Table 17.1. XSL-FO processor supported graphics formats

FO ProcessorBitmap formatsVector formats
Antenna House PNG JPEG GIF BMPSVG EPS EMF WMF CGM
FOP PNG JPEG GIF TIFF BMPSVG EPS
XEP PNG JPEG GIF TIFFSVG PDF EPS

Once you have determined which graphics formats are supported, you can convert your graphics to those formats and save the files with the appropriate filename extensions. Then you can create your mediaobject elements with multiple formats. See the section “Stylesheet's selection process” to see how a given format is chosen.

Adding graphics formats

What if you have a graphics file format that is supported in your output but isn't supported by the stylesheets? For example, the Macromedia Flash Movie file format has a format of SWF. This file format is supported in browsers with the Flash plugin.

To add a graphics format to the list of supported formats in the HTML stylesheet, copy the template named is.graphic.format from html/graphics.xsl to your customization layer. Add your new format to the xml:if statement, as in the following example:

<xsl:template name="is.graphic.format">
  <xsl:param name="format"></xsl:param>
  <xsl:if test="$format = 'SVG'
                or $format = 'PNG'
                or $format = 'JPG'
                or $format = 'JPEG'
                or $format = 'linespecific'
                or $format = 'GIF'
                or $format = 'GIF87a'
                or $format = 'GIF89a'
                or $format = 'BMP'
                or $format = 'SWF'">1</xsl:if>
</xsl:template>

Now you can add a format="SWF" attribute to a videodata element in your DocBook file. You will likely have to do some further customization of the videodata template to output the correct HTML to support Flash movies, though.

You may also want to add a new graphics format when your XSL-FO processor upgrades to support a new format before the DocBook stylesheet distribution can catch up. In that case, copy the same template from the fo/graphics.xsl stylesheet file to your customization layer and add the new format name.