Rich-Text Format Specification V. 2 Introduction 2 rtf syntax 2 Conventions of an rtf reader 4

Download 1.09 Mb.
Size1.09 Mb.
1   2   3   4   5   6   7   8   9   ...   15

Contents of an RTF File

An RTF file has the following syntax:


This syntax is overly strict; all RTF readers must read RTF that does not conform to this syntax. However, all RTF readers must correctly read RTF written according to this syntax. If you write RTF that conforms to this syntax, all correct RTF readers will read it.


The header has the following syntax:

\ rtf \ deff? ?

RTF Version

An entire RTF file is considered a group and must be enclosed in braces. The control word \ rtfN must follow the opening brace. The numeric parameter N identifies the version of the RTF standard used. The RTF standard described in this chapter corresponds to RTF Specification Version 1.

Character Set

After specifying the RTF version, you must declare the character set used in this document. The control word for the character set must precede any plain text or any table control words. The RTF specification currently supports the following character sets:

Control word

Character set

\ ansi

ANSI (default)

\ mac

Apple Macintosh

\ pc

IBM PC code page 437

\ pca

IBM PC code page 850, used by IBM Personal System/2 (not implemented in version 1 of Word for OS/2)

Font Table

The \ fonttbl control word introduces the font table group. This group defines the fonts available in the document and has the following syntax:

'{' \ fonttbl ( | ('{' '}'))+ '}'

?? ';'

\ f

\ fnil | \ froman | \ fswiss | \ fmodern | \ fscript | \ fdecor | \ ftech | \ fbidi

\ fcharset

\ fprq


'{\*' \falt #PCDATA '}'

'{\ *' \ fontemb ? ? '}'

\ ftnil | \ fttruetype

'{\ * \ fontfile ? #PCDATA '}'

\ cpg

Note for that either or must be present, although both may be present.

All fonts available to the RTF writer can be included in the font table, even if the document doesn't use all the fonts.

RTF also supports font families, so that applications can attempt to intelligently choose fonts if the exact font is not present on the reading system. RTF uses the following control words to describe the various font families.

Control word

Font family

\ fnil

Unknown or default fonts (default)

\ froman

Roman, proportionally spaced serif fonts (Tms Rmn, Palatino, etc.)

\ fswiss

Swiss, proportionally spaced sans serif fonts (Swiss, etc.)

\ fmodern

Fixed-pitch serif and sans serif fonts (Courier, Pica, etc.)

\ fscript

Script fonts (Cursive, etc.)

\ fdecor

Decorative fonts (Old English, ITC Zapf Chancery, etc.)

\ ftech

Technical, symbol, and mathematical fonts (Symbol, etc.)

\ fbidi

Arabic, Hebrew, or other bi-directional font (Miriam, etc.)

If an RTF file uses a default font, the default font number is specified with the \ deffN control word, which must precede the font-table group. The RTF writer supplies the default font number used in the creation of the document as the numeric argument N. The RTF reader then translates this number through the font table into the most similar font available on the reader's system.

The following control words specify the character set and pitch of a font in the font table:

Control word


\ fcharsetN

Specifies the character set of a font in the font table.

\ fprqN

Specifies the pitch of a font in the font table.

If \fcharset is specified, the N argument can be one of the following types:

Character set

N value





























If \fprq is specified, the N argument can be one of the following values:



Default pitch


Fixed pitch


Variable pitch


Code Page Support

A font may have a different character set from the character set of the document. For example, the Symbol font has the same characters in the same positions on both the Macintosh and Windows. RTF describes this with the \ cpg control word, which names the character set used by the font. In addition, file names (used in field instructions and in embedded fonts) may not necessarily be the same as the character set of the document, and the \ cpg control word can change the character set for these file names, as well. However, all RTF documents must still declare a character set, to maintain backwards compatibility with older RTF readers.

The table below describes valid values for \ cpg:




United States IBM


Arabic (ASMO 708)


Arabic (ASMO 449+, BCON V4)


Arabic (Transparent Arabic)


Arabic (Nafitha Enhanced)


Arabic (Transparent ASMO)


Windows 3.1 (United States & Western Europe)


IBM Multilingual


Eastern European






French Canadian






Soviet Union




Windows 3.1 (Eastern European)


Windows 3.1 (Soviet Union)

Font Embedding

RTF supports embedded fonts with the \ fontemb group located inside a font definition. An embedded font can be specified by a file name, or the actual font data may be located inside the group. If a file name is specified, it is contained in the \ fontfile group. The \ cpg control word can be used to specify the character set for the file name.

RTF supports TrueType‘ and other embedded fonts. The type of the embedded font is described by the following control words:

Control word

Embedded font type

\ ftnil

Unknown or default font type (default)

\ fttruetype

TrueType font

The File Table

The \ filetbl control word introduces the file table destination, a new destination. This group defines the files referenced in the document and has the following syntax:

'{\ *' \ filetbl ('{' '}')+ '}'

'{' \ file ?? + ';}'

\ fid

\ frelative


\ fvalidmac | \ fvaliddos | \ fvalidntfs | \ fvalidhpfs | \ fnetwork


Note that the filename can be any valid alphanumeric string for the named file system, giving the complete path and filename.

Control word


\ filetbl

A structure analogous to the style or font table, the file table is a list of documents referenced by the current document. This is a destination control word output as part of the document header.

\ file

This marks the beginning of a file group, which lists relevant information about the referenced file. This is a destination control word.

\ fidN

File ID number. Files are referenced later in the document using this number.

\ frelativeN

The character position within the path (starting at zero) where the referenced file's path starts to be relative to the path of the owning document. For example, a document is saved to the path c:\ private\ resume\ foo.doc and its file table contains the path c:\ private\ resume\ edu\ bar.doc, then that entry in the file table will be \ frelative18, to point at the character 'e' in "edu". This is to allow preservation of relative paths.

\ fosnumN

Currently only filled in for paths from the Macintosh file system. It is a OS-specific number for identifying the file, which may be used to speed up access to the file, or find it if it has been moved to another folder on disk. The MacOS name for this number is the "file id". Additional meanings of the \ fosnumN may be defined for other file systems in the future.

\ fvalidmac

Macintosh file system.

\ fvaliddos

MS-DOS file system.

\ fvalidntfs

NTFS file system.

\ fvalidhpfs

HPFS file system.

\ fnetwork

Network file system. This keyword may be used in conjunction with any of the previous file source keywords.

Color Table

The \ colortbl control word introduces the color table group, which defines screen colors, character colors, and other color information. This group has the following syntax:

'{' \ colortbl + '}'

\ red ? & \ green ? & \ blue ? ';'

The following are valid control words for this group:

Control word


\ redN

Red index

\ greenN

Green index

\ blueN

Blue index

Each definition must be delimited by a semicolon, even if the definition is omitted. If a color definition is omitted, the RTF reader uses its default color. In the example below, three colors are defined. The first color is omitted, as shown by the semicolon following the \ colortbl control word.

The foreground and background colors use indexes into the color table to define a color. For more information on color setup, see your Windows documentation.

The following example defines a block of text in color (where supported). Note that the cf/cb index is the index of an entry in the color table, which represents a red/green/blue color combination.

{\f1\cb1\cf2 This is colored text. The background is color

1 and the foreground is color 2.}

If the file is translated for software that does not display color, the reader ignores the color-table group.

Style Sheet

The \ stylesheet control word introduces the style sheet group, which contains definitions and descriptions of the various styles used in the document. All styles in the document's style sheet can be included, even if not all the styles are used. In RTF, a style is a shorthand used to specify a set of character, paragraph, or section formatting.

The style-sheet group has the following syntax:

'{' \ stylesheet

Share with your friends:
1   2   3   4   5   6   7   8   9   ...   15

The database is protected by copyright © 2020
send message

    Main page