Inline Objects

In addition to block formatting objects, there are a number of other objects that are inline objects.

These objects are designed to be integrated into lines within block objects, or within sections of text. These inline objects allow you to manipulate sentences, words, or characters.

The inline objects include

  • bidi-override— This overrides the direction in which text is written. Normally, the default will be appropriate to the language. However, there are times when the algorithm might make the wrong choice, or where you want to write text in a different way. Although English is top-to-bottom, left-to-right, other languages or specific applications (such as engineering specifications) might be written differently.

  • character— This object allows you to apply detailed formatting to a single letter (or glyph). Unlike most objects, you don't put the character inside the tags—you use the character object's character property.

  • inline— This is used to format a section of text inside a block. It can be used to add a border, change fonts and/or background, keep text together, and so on. We will look at this more when we discuss working with text later in the chapter.

  • inline-container— This is an inline object that serves as a reference area, such as a block-container.

  • leader— The leader object is used to create both leaders and rules, which can be inserted into text lines in a block.

  • page-number— The page number object is used to insert page numbers into your document, such as placing a page number in the page's footer.

  • basic-link— This object is used to create a link to another document or position within the same document. Internal links use the internal-destination property and jump to a position base on the id property. External links use the external-destination property and use a URI.

  • external-graphic— This is used to embed a graphic stored in an external file. The src property takes the form of a URI pointing to the file to be included, much like an HTML <img> tag. You can specify a height and width or let it be automatically determined.

  • instream-foreign-object— This object is used to embed a graphic or other object described as XML, such as an SVG-based graphic.

The most commonly used of the inline objects will relate to including graphics in documents, both in the form of images and rule lines. Another very common use of inline objects is including page numbers. So, let's take a closer look at both of these applications.

Working with Graphics

Many documents include graphics along with text, from charts and graphs to logos and photographs. Graphic images included in a stylesheet are treated as inline objects, and can take one of a few forms.

The instream-foreign-object object can be used to contain a section of XML-based code, which generates a graphic. That code might take the form of an SVG image, or a MathML-formatted equation, or some yet-to-be-developed format.

More common, though, will be the inclusion of familiar graphic formats such as .gif or .jpeg images, similarly to how images are included in HTML pages.

To include an external graphic in an XSL-FO document, the external-graphic object is used, which accepts a URI pointing to the image to be included:

<fo:external-graphic src="http://www.myserver.com/logo.jpg"/> 

The URI can be either an absolute or relative URI. For example, if we wanted to include a photograph with a caption, we would use the following:

Listing 10.2. Including Graphics with XSL-FO and the external-graphic Object
<?xml version="1.0"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <fo:layout-master-set>
  <fo:simple-page-master master-name="page">
   <fo:region-body/>
  </fo:simple-page-master>
</fo:layout-master-set>

 <fo:page-sequence master-name="page">
  <fo:flow flow-name="xsl-region-body">   <fo:block>
    <fo:external-graphic src="L.jpg"/>
   </fo:block>

   <fo:block font-size="14pt" font-family="serif">
    Trains in Chicago are called the "L" for eLevated.
   </fo:block>
  </fo:flow>
 </fo:page-sequence>

</fo:root>
						

This creates a document with an inline graphic, in the form of a JPEG image, and then places a caption underneath the image. The rendered results are shown in Figure 10.4.

Figure 10.4. A photo and a caption generated using blocks and the inline external-graphic object.


In addition to graphics in the form of imported images, another common type of graphic element used in documents comes in the form of the rule line. So, now let's take a look at how rules are handled in XSL-FO.

Leaders and Page Numbers

XSL-FO treats leaders and rules as the same object. A leader is a series of glyphs linking two pieces of text. For example, in a table of contents:

Chapter 5...................................................................... 40 

The series of “dots” linking the Chapter label and the page number is a leader. Leaders can be composed of any character, and the leader object allows you to set the character used with the leader-pattern property, which is also how XSL-FO handles rule lines.

A rule line is a horizontal graphic line, used to separate sections or as a decorative element. In HTML, rule lines are created using the <hr> tag. With XSL-FO, rules are created using the leader object, and setting the leader-pattern value to rule.

For example, to create a rule line 60 picas long (approximately 5 inches), we would use

<fo:leader leader-pattern="rule" leader-length="60pc" /> 

The leader-pattern could also be set to a color value, which would create a colored rule line.

One use for creating a rule line might be to set apart a page footer that contained a page number for the page. To include page numbers in a document, we would need to use the page-number object, and include it in a static-content object, located in the appropriate region on our page.

Let's say that we wanted to create a footer that included a rule line and a page number:

<fo:static-content flow-name="xsl-region-after"> 
 <fo:block font-size="12pt" font-family="serif" text-align="center">
  <fo:leader leader-pattern="rule" leader-length="7.0in" />
  Page # <fo:page-number/>
 </fo:block>
</fo:static-content>

We accomplish this by creating a static-content object in the region-after area of the page. Within that object, we have a leader object and a page-number object. The complete document looks like this:

Listing 10.3. Using the leader and page-number Objects to Create a Page Footer
<?xml version="1.0"?>
 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <fo:layout-master-set>
  <fo:simple-page-master master-name="Letter"
      page-width="4in" page-height="4in"
      margin-top="0.5in" margin-bottom="0.5in"
      margin-left="0.5in" margin-right="0.5in">
   <fo:region-body margin-top="1.0in" margin-bottom="1.0in"/>
   <fo:region-after  extent="0.5in"/>
  </fo:simple-page-master>
 </fo:layout-master-set>
 <fo:page-sequence master-name="Letter">
  <fo:static-content flow-name="xsl-region-after">
   <fo:block font-size="12pt" font-family="serif" text-align="center">
    <fo:leader leader-pattern="rule" leader-length="7.0in" />
    Page # <fo:page-number/>
   </fo:block>
  </fo:static-content>  <fo:flow flow-name="xsl-region-body">
   <fo:block font-size="12pt" font-family="serif">
    The contents of the page...
   </fo:block>
  </fo:flow>
 </fo:page-sequence>
</fo:root>

When rendered, the complete page appears as shown in Figure 10.5, complete with our footer, separated by a rule line and containing a page number.

Figure 10.5. A page with a footer featuring a leader object and a page number.


Because the pages are generated dynamically by the XSL processor, the page numbers are also determined automatically by the XSL processor. By manipulating the various page- number properties (see Appendix B “Guide to Reading the XML Recommendation” for a full list), you can control how page numbers appear, such as only numbering even or odd pages, or skipping the first page, and start numbering the document with page 2.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.173.249