The_RTF_Cookbook

The_RTF_Cookbook is a RTF overview and quick reference.
Download

The_RTF_Cookbook Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Sean M. Burke
  • Publisher web site:
  • http://search.cpan.org/~sburke/

The_RTF_Cookbook Tags


The_RTF_Cookbook Description

The_RTF_Cookbook is a RTF overview and quick reference. The_RTF_Cookbook is a RTF overview and quick reference.SYNOPSIS # Time-stamp: "2003-09-23 21:27:56 ADT" # This document is in Perl POD format, but you can read it # with just an ASCII text viewer, if you want.RTF is a nearly ubiquitous text formatting language devised by Microsoft. Microsoft's Rich Text Format Specification is widely available, but it's usable mainly just as a reference for the language's entire command set.This short document, however, is meant as a quick reference and overview. It is meant for people interested in writing programs that generate a minimal subset of RTF.NOTE : I've mostly superceded this document with my book RTF Pocket Guide, which is much longer and more comprehensive -- see http://www.oreilly.com/catalog/rtfpg/INTRODUCTIONRTF code consists of plaintext, commands, escapes, and groups:Plaintext contains seven bit (US ASCII) characters except for , {, and }. Returns and linefeeds can be present but are ignored, and are harmless (as long as they are not in the middle of an RTF command). Space (ASCII 0x20) characters are significant -- five spaces means five spaces. (The only exception is a space that ends an RTF command; such a space is ignored.) Example of plaintext: "I like pie".An RTF command consists of a backslash, then some characters a-z, and then an optional positive or negative integer argument. The command is then terminated either by a space, return, or linefeed (all of which are ignored), or by some character (like brace or backslash, etc.) that couldn't possibly be a continuation of this command. A simple rule of thumb for emitting RTF is that every command should be immediately followed either by a space, return, or linefeed, (as in "foo bar"), or by another command (as in "foobar"). Examples of RTF commands: "page" (command "page" with no parameter), "f3" (command "f" with parameter 3), "li-320" (command "li" with parameter -320).An RTF escape consists of a backslash followed by something other than a letter.There are few of these in the language, and the basic ones to know now are the two-byte long escape sequences: {, }, \ (to convey a literal openbrace, closebrace, or backslash), and the only four-byte-long escape sequence, 'xx, where xx is two hexadecimal digits. This is used for expressing any byte value in a document. For example, x'BB expresses character value BB (decimal 187), which for Latin-1/ANSI is close-angle-quote (which looks like a little ">>").An RTF group consists of an openbrace "{", any amount of RTF code (possibly including other groups), and then a closebrace "}". Roughly speaking, you can treat an RTF group as the conceptual equivalent of an SGML element. Effectively, a group limits the scope of commands in that group. So if you're in a group and you turn on italics, then that can apply only as far as the end of the group -- regardless of whether you do this at the start of the group, as in {i I like pie}, or the middle, as in {I like i pie}. Note that you must emit just as many openbraces as closebraces -- otherwise your document is syntactally invalid, and RTF readers will not tolerate that.This is an example of a paragraph using plaintext, escapes, commands, and groups: {pardfs32b NOTESpar} {pardfs26 Recently I skimmed {i Structure and Interpretation of Computer Programs}, by Sussman and Abelson, and I think there should have been more pictures. line I like pictures. Is that so na'efve? par}('ef makes an i-dieresis, in the Latin-1/ANSI character set.)Note that "foobar" isn't the same as "foo bar", it's the same as "foobar", because the newline is ignored. So if you mean "foo bar", and want to work in a newline, you should consider "foo bar", or "foo bar", or even things like "foo bar".Note that newlines aren't needed in your output file at all, and there's no reason to get your RTF code to be wrapped at 72 columns or anywhere else; but it's very useful to be able to open a RTF file in a plaintext editor and see something other than a giant sea of unbroken text. So at the very least, I emit a newline before every paragraph.(Note that if you are ambitiously trying to wrap your RTF code by inserting newlines, consider that just about the only really harmful places to insert a newline are in the middle of a command or an escape -- because "page" doesn't mean the same as "page", it means the same as "pa ge" (i.e., a pa command, and then two text characters "ge"); and "'f8" is not good RTF. So I suggest making wrapping algorithms insert a newline only after a space character -- a guaranteed safe spot.) Requirements: · Perl


The_RTF_Cookbook Related Software