APPLICATION INTERCHANGE FILE FORMATS
Simple tutorial for programmers
RTF - Rich Text Format (.rtf extension) - working with fonts and tabs
This builds upon the basics in the first example. Fonts are straight forward, simply define them in the beginning and reference them with as needed. In the example which follows I use the courier font and Profile as the second font.
{\rtf1\ansi\deff0 {\fonttbl {\f0 Courier;}{\f1 ProFontWindows;}}
This line is font 0 which is courier\line
\f1
This line is font 1\line
\f0
This line is font 0 again\line
}
There are a number of attributes which can be assigned to the text, such as text color and highlight. The color table determines which color is applied. In the basics section I defined the red color. For this page I will add yellow which I like to use to highlight text:
{\rtf1\ansi\deff0 {\fonttbl {\f0 Courier;}{\f1 ProFontWindows;}}
{\colortbl;\red0\green0\blue0;\red255\green0\blue0;\red255\green255\blue0;}
This line is font 0 which is courier\line
\f1
This line is font 1\line
\f0
This line is font 0 again\line
This line has a \cf2 red \cf1 word\line
\highlight3 while this line has a \cf2 red \cf1 word and is highlighted in yellow\highlight0\line
Finally, back to the default color.\line
}
Tabs have lots of characteristics, such as justification and leading characters. In the following example I put a tab stop at 3" and orient the text as noted in the code:
{\rtf1\ansi\deff0 {\fonttbl {\f0 Courier;}}
\tqr\tx4320\tab Right tab\par\pard
\tqc\tx4320\tab Center tab\par\pard
\tx4320\tab Left tab
}
What I did was make each line a new paragraph and define the tabs accordingly. A decimal tab is \tqdec. Leading characters from the beginning of the line or preceeding tab use the following codes:
{\rtf1\ansi\deff0 {\fonttbl {\f0 Courier;}}
\fs28
\tqr\tldot\tx7200\tab Right tab with leading dots\par\pard
\tqr\tlhyph\tx7200\tab Right tab with leading hyphens\par\pard
\tqr\tlul\tx7200\tab Right tab with leading underline\par\pard
\fs18
\tqr\tx1440\tab 1" tab\tldot\tx2880\tab with 1" of dots between\par\pard
\tqr\tlhyph\tx1440\tab 1" tab\tx2880\tab with 1" of space between and hypens outside\tqr\tlhyph\tx8640\tab\par\pard
}