Inline-Level Formatting Objects

Inline-Level Formatting Objects

In addition to the block objects in XSL-FO, you can also create inline objects. An inline object represents part of a larger formatting region, such as a block; for example, it might represent a word or two in a block. Inline objects are usually used to format part of the text as that text follows the normal flow in the page. For example, you can make the first character in a paragraph larger, make the whole first line blue, insert page numbers , add images, and so on.

One reason you might create inline objects is to format parts of a blocks text; for example, in Chapter 11, you saw the following use of the text-decoration property of <fo:inline> to underline text:

 <xsl:template match="PLANET/MASS">      <fo:block font-size="24pt" line-height="32pt"          font-family="Times">          <fo:inline text-decoration="underline">              Mass          </fo:inline>:          <xsl:apply-templates/>          [Earth = 1]      </fo:block>  </xsl:template> 

The following list includes the inline formatting elements:

  • <fo: bidi-override >

  • <fo:character>

  • <fo: initial-property-set >

  • <fo:external-graphic>

  • <fo:instream-foreign-object>

  • <fo:inline>

  • <fo:inline-container>

  • <fo:leader>

  • <fo: page-number >

  • <fo:page-number-citation>

Ill take a look at a few of the more common of these inline elements now, starting with <fo:inline> itself.

Creating Inline Regions: <fo:inline>

As you already saw in Chapter 11, you can use the <fo:inline> element to format a part of your text with a background, underline it, or enclose it with a border. This element lets you format an inline area, such as a few words in a block of text, almost as though it were a block itself.

You can use the following properties with <fo:inline> :

  • Common accessibility properties: source-document, role

  • Common aural properties: azimuth, cue-after, cue-before, elevation, pause-after, pause-before, pitch, pitch-range, play-during, richness, speak, speak-header, speak-numeral, speak-punctuation, speech-rate, stress, voice-family, volume

  • Common border, padding, and background properties: background-attachment , background- color , background-image, background-repeat , background-position-horizontal, background-position-vertical, border-before-color, border-before-style, border-before-width, border-after-color, border-after-style, border-after-width, border-start-color, border-start-style, border-start-width, border-end-color, border-end-style, border-end-width, border-top-color, border-top-style, border-top-width, border-bottom-color, border- bottom-style, border-bottom-width, border-left-color, border-left-style, border-left-width, border-right-color, border-right-style, border-right-width, padding-before, padding-after, padding-start, padding-end, padding-top, padding-bottom, padding-left, padding-right

  • Common font properties: font-family, font-size, font-stretch, font-size-adjust, font-style, font-variant, font-weight

  • Common inline margin properties: space-end, space-start

  • alignment-adjust

  • baseline-identifier

  • baseline-shift

  • color

  • dominant-baseline

  • id

  • keep-together

  • keep-with- next

  • keep-with-previous

  • line-height

  • line-height-shift-adjustment

  • relative-position

  • text-decoration

  • visibility

  • z-index

For example, youve already seen how to add an underline to a single word inside other text using the text-decoration property:

 <xsl:template match="PLANET/MASS">          <fo:block font-size="24pt" line-height="32pt"              font-family="Times">              <fo:inline text-decoration="underline">                  Mass              </fo:inline>:              <xsl:apply-templates/>              [Earth = 1]          </fo:block>      </xsl:template> 

Youll see more on how to use <fo:inline> when working with footnotes later in this chapter.

Handling Characters Individually: <fo:character>

As you can guess from its name , the <fo:character> object enables you to handle the characters in a document individually. One place to use <fo:character> is when you want to replace certain characters with other characters. In the following example, I match an element named <PASSWORD> and replace the characters in it with the character *:

 <xsl:template match="PASSWORD">      <fo:character character="*">          <xsl:value-of select="."/>      </fo:character>  </xsl:template> 

You can use the <fo:character> element to format individual characters, as in this case, which formats the characters in Hello using different colors:

 <fo:character character="H" font-size="24pt" color="red"/>  <fo:character character="E" font-size="24pt" color="yellow"/>  <fo:character character="L" font-size="24pt" color="green/>  <fo:character character="L" font-size="24pt" color="blue"/>  <fo:character character="O" font-size="24pt" color="orange"/> 

You can use the following properties with <fo:character> :

  • Common aural properties: azimuth, cue-after, cue-before, elevation, pause-after, pause-before, pitch, pitch-range, play-during, richness, speak, speak-header, speak-numeral, speak-punctuation, speech-rate, stress, voice-family, volume

  • Common border, padding, and background properties: background-attachment, background-color, background-image, background-repeat, background-position-horizontal, background-position-vertical, border-before-color, border-before-style, border-before-width, border-after-color, border-after-style, border-after-width, border-start-color, border-start-style, border-start-width, border-end-color, border-end-style, border-end-width, border-top-color, border-top-style, border-top-width, border-bottom-color, border-bottom-style, border-bottom-width, border-left-color, border-left-style, border-left-width, border-right-color, border-right-style, border-right-width, padding-before, padding-after, padding-start, padding-end, padding-top, padding-bottom, padding-left, padding-right

  • Common font properties: font-family, font-size, font-stretch, font-size-adjust, font-style, font-variant, font-weight

  • Common hyphenation properties: country, language, script, hyphenate , hyphenation-character, hyphenation-push-character-count, hyphenation- remain -character-count

  • Common inline margin properties: space-end, space-start

  • alignment-adjust

  • treat-as-word-space

  • baseline-identifier

  • baseline-shift

  • character

  • color

  • dominant-baseline

  • font-height-override-after

  • font-height-override-before

  • glyph-orientation-horizontal

  • glyph-orientation-vertical

  • id

  • keep-with-next

  • keep-with-previous

  • letter-spacing

  • line-height

  • line-height-shift-adjustment

  • relative-position

  • score-spaces

  • suppress-at-line-break

  • text-decoration

  • text-shadow

  • text-transform

  • word-spacing

Creating Page Numbers: <fo:page-number>

Another useful inline formatting object is <fo:page-number> . This element creates an inline area displaying the current page number. Heres an example:

 <fo:block>      You are now reading page <fo:page-number/>.  </fo:block> 

You can use the following properties with <fo:page-number> :

  • Common accessibility properties: source-document, role

  • Common aural properties: azimuth, cue-after, cue-before, elevation, pause-after, pause-before, pitch, pitch-range, play-during, richness, speak, speak-header, speak-numeral, speak-punctuation, speech-rate, stress, voice-family, volume

  • Common border, padding, and background properties: background-attachment, background-color, background-image, background-repeat, background-position-horizontal, background-position-vertical, border-before-color, border-before-style, border-before-width, border-after-color, border-after-style, border-after-width, border-start-color, border-start-style, border-start-width, border-end-color, border-end-style, border-end-width, border-top-color, border-top-style, border-top-width, border-bottom-color, border-bottom-style, border-bottom-width, border-left-color, border-left-style, border-left-width, border-right-color, border-right-style, border-right-width, padding-before, padding-after, padding-start, padding-end, padding-top, padding-bottom, padding-left, padding-right

  • Common font properties: font-family, font-size, font-stretch, font-size-adjust, font-style, font-variant, font-weight

  • Common inline margin properties: space-end, space-start

  • alignment-adjust

  • baseline-identifier

  • baseline-shift

  • dominant-baseline

  • id

  • keep-with-next

  • keep-with-previous

  • letter-spacing

  • line-height

  • line-height-shift-adjustment

  • relative-position

  • score-spaces

  • text-decoration

  • text-shadow

  • text-transform

  • word-spacing

Youll see an example using page numbers during the discussion of page sequences at the end of this chapter.

Inserting Graphics: <fo:external-graphic>

A popular element in XSL-FO formatting is <fo:external-graphic> , which you use to embed an image in a document.

You can use the following properties with <fo:external-graphic> :

  • Common accessibility properties: source-document, role

  • Common aural properties: azimuth, cue-after, cue-before, elevation, pause-after, pause-before, pitch, pitch-range, play-during, richness, speak, speak-header, speak-numeral, speak-punctuation, speech-rate, stress, voice-family, volume

  • Common border, padding, and background properties: background-attachment, background-color, background-image, background-repeat, background-position-horizontal, background-position-vertical, border-before-color, border-before-style, border-before-width, border-after-color, border-after-style, border-after-width, border-start-color, border-start-style, border-start-width, border-end-color, border-end-style, border-end-width, border-top-color, border-top-style, border-top-width, border-bottom-color, border-bottom-style, border-bottom-width, border-left-color, border-left-style, border-left-width, border-right-color, border-right-style, border-right-width, padding-before, padding-after, padding-start, padding-end, padding-top, padding-bottom, padding-left, padding-right

  • Common inline margin properties: space-end, space-start

  • alignment-adjust

  • baseline-identifier

  • baseline-shift

  • block-progression-dimension

  • content-height

  • content-type

  • content-width

  • dominant-baseline

  • height

  • id

  • inline-progression-dimension

  • keep-with-next

  • keep-with-previous

  • line-height

  • line-height-shift-adjustment

  • relative-position

  • overflow

  • scaling

  • scaling-method

  • src

  • width

As in HTML, you can set the size of the image in the document; in XSL-FO, you use the content-height , content-width , and scaling properties, and if you dont set these properties, the image is displayed in its original size. The following example, graphics.fo, displays an image, xslfo.jpg, and a caption:

Listing 12.4 graphics.fo
 <?xml version="1.0" encoding="UTF-8"?>  <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">      <fo:layout-master-set>          <fo:simple-page-master margin-right="20mm              margin-left="20mm" margin-bottom="10mm"              margin-top="10mm" page-width="300mm              page-height="400mm" master-name="page">              <fo:region-body margin-right="0mm"                  margin-left="0mm" margin-bottom="10mm"                  margin-top="0mm"/>          <fo:region-after extent="10mm"/>         </fo:simple-page-master>      </fo:layout-master-set>      <fo:page-sequence master-name="page">          <fo:flow flow-name="xsl-region-body">              <fo:block space-after="12pt" font-weight="bold"                  font-size="36pt" text-align="center">                  Using Graphics              </fo:block>              <fo:block text-align="center">                  <fo:external-graphic src="file:xslfo.jpg"/>              </fo:block>              <fo:block space-before="10pt" text-align="center"                  font-size="24pt">                  An image embedded in a document.              </fo:block>          </fo:flow>       </fo:page-sequence>  </fo:root> 

You can see the PDF document created from graphics.fo in Figure 12.3.

Figure 12.3. Displaying an image using formatting objects.
graphics/12fig03.gif

Actually inserting an image into the result document is easy if your software supports it. The fop processor now supports images (it didnt just a few versions ago), so you can use the <fo:external-graphic> element to insert the image this way:

 <fo:block text-align="center">      <fo:external-graphic src="file:xslfo.jpg"/>  </fo:block> 

Formatting First Lines: <fo:initial-property-set>

You can use the <fo:initial-property-set> element to specify properties for and format the first line of a block. In the following example, Im formatting the first line of a block in small caps using the font-variant property (which, incidentally, fop doesnt support):

 <fo:block>      <fo:initial-property-set font-variant="small-caps"/>          This text will be displayed in the result document.          The first line will be displayed using small caps.  </fo:block> 

You can use the following properties with <fo:initial-property-set> :

  • Common accessibility properties: source-document, role

  • Common aural properties: azimuth, cue-after, cue-before, elevation, pause-after, pause-before, pitch, pitch-range, play-during, richness, speak, speak-header, speak-numeral, speak-punctuation, speech-rate, stress, voice-family, volume

  • Common border, padding, and background properties: background-attachment, background-color, background-image, background-repeat, background-position-horizontal, background-position-vertical, border-before-color, border-before-style, border-before-width, border-after-color, border-after-style, border-after-width, border-start-color, border-start-style, border-start-width, border-end-color, border-end-style, border-end-width, border-top-color, border-top-style, border-top-width, border-bottom-color, border-bottom-style, border-bottom-width, border-left-color, border-left-style, border-left-width, border-right-color, border-right-style, border-right-width, padding-before, padding-after, padding-start, padding-end, padding-top, padding-bottom, padding-left, padding-right

  • Common font properties: font-family, font-size, font-stretch, font-size-adjust, font-style, font-variant, font-weight

  • color

  • id

  • letter-spacing

  • line-height

  • line-height-shift-adjustment

  • relative-position

  • score-spaces

  • text-decoration

  • text-shadow

  • text-transform

  • word-spacing

That completes this overview of the inline formatting objects; the next sections look at an out-of-line formatting object: footnotes.



Inside XSLT
Inside Xslt
ISBN: B0031W8M4K
EAN: N/A
Year: 2005
Pages: 196

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net