.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "RTF::Writer 3pm" .TH RTF::Writer 3pm "2022-11-19" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" RTF::Writer \- for generating documents in Rich Text Format .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 9 \& use RTF::Writer; \& my $rtf = RTF::Writer\->new_to_file("greetings.rtf"); \& $rtf\->prolog( \*(Aqtitle\*(Aq => "Greetings, hyoomon" ); \& $rtf\->number_pages; \& $rtf\->paragraph( \& \e\*(Aq\efs40\eb\ei\*(Aq, # 20pt, bold, italic \& "Hi there!" \& ); \& $rtf\->close; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module is for generating documents in Rich Text Format. .PP This module is a class; an object belonging to this class acts like an output filehandle, and calling methods on it causes \s-1RTF\s0 text to be written. .PP Incidentally, this module also exports a few useful functions, upon request. .PP The following documentation assumes some familiarity with the \&\s-1RTF\s0 Specification. Users not already intimately familiar with \s-1RTF\s0 should look at RTF::Cookbook and/or my book \fI\s-1RTF\s0 Pocket Guide\fR from O'Reilly, .SH "METHODS" .IX Header "METHODS" .ie n .IP "$h = RTF::Writer\->new_to_file($filename);" 4 .el .IP "\f(CW$h\fR = RTF::Writer\->new_to_file($filename);" 4 .IX Item "$h = RTF::Writer->new_to_file($filename);" This creates a new \s-1RTF\s0 output stream object, such that sending text to this object will write to the filespec given. This is basically a wrapper around new_to_handle. If opening a write-handle to \f(CW$filename\fR fails (or if \&\f(CW$filename\fR is undef or zero-length), then a fatal error results. .ie n .IP "$h = RTF::Writer\->new_to_handle(*FILEHANDLE);" 4 .el .IP "\f(CW$h\fR = RTF::Writer\->new_to_handle(*FILEHANDLE);" 4 .IX Item "$h = RTF::Writer->new_to_handle(*FILEHANDLE);" This creates a new \s-1RTF\s0 output stream object, such that sending text to this object will write to the filehandle given. The filehandle can be a glob (*FH) or a filehandle object (*FH{\s-1IO\s0} or the value from \&\f(CW\*(C`IO::File\->new(...)\*(C'\fR). .ie n .IP "$h = RTF::Writer\->new_to_string(\e$string);" 4 .el .IP "\f(CW$h\fR = RTF::Writer\->new_to_string(\e$string);" 4 .IX Item "$h = RTF::Writer->new_to_string($string);" This creates a new \s-1RTF\s0 output stream object, such that sending text to this object will append to the string that you've passed a reference to. .ie n .IP "$h\->print(...);" 4 .el .IP "\f(CW$h\fR\->print(...);" 4 .IX Item "$h->print(...);" This is the basic method for writing text to an \s-1RTF\s0 stream. This takes a list of items. Each item is either: .RS 4 .ie n .IP "a plain string, like ""foo\en""" 4 .el .IP "a plain string, like ``foo\en''" 4 .IX Item "a plain string, like foon" In this case, the value is imputed to be a plaintext string, and an rtf-escaped version of it is written. For example \f(CW"Stuff\en\et\etUmmm\en"\fR causes \f(CW\*(AqStuff\eline \etab \etab Umm\eline \*(Aq\fR to be written. See \&\f(CWrtfesc(x)\fR for further details of escaping. .IP "a scalar-reference, like \e'\eul'" 4 .IX Item "a scalar-reference, like 'ul'" In this case, the value is imputed to be a reference to \fIalready escaped\fR text. This is the basic way to emit \s-1RTF\s0 codes. Text passed this way will be written without any additional escaping. .Sp Unless \f(CW$RTF::Writer::AUTO_NL\fR (normally on) has been turned off, the item written will be followed with a (presumably harmless) newline character to delimit any code in there from any following text, \&\fIif\fR the last character of this string is a digit or a lowercase letter. This is so that \f(CW\*(C`(\e\*(Aq\ei\*(Aq, "foo!")\*(C'\fR emits \f(CW\*(C`\ei[newline]foo!\*(Aq\*(C'\fR (which does what you expected), instead of \f(CW\*(Aq\eifoo!\*(Aq\fR, which looks like an \s-1RTF\s0 command \*(L"ifoo\*(R" followed by a plaintext \*(L"!\*(R". .IP "an array-reference, like [ \e'\eul', 'foo' ]" 4 .IX Item "an array-reference, like [ 'ul', 'foo' ]" This emits an open-brace \*(L"{\*(R", as \s-1RTF\s0 uses for opening \*(L"groups\*(R" (generally for delimiting the effects of character-formatting commands like '\eul', or a few formatting commands like '\efootnote'); then it emits the items in the referred-to array; and then emits a closing \*(L"}\*(R". I intend this to be useful is making sure that you don't emit more open-braces than close-braces, since that usually makes \s-1RTF\s0 readers immediately reject such a file. .Sp You can nest these array-references, like: .Sp .Vb 10 \& $h\->print( \& \e\*(Aq\ecol2\*(Aq, \& [ \e\*(Aq\epard\*(Aq, \& "It is now ", \& [ \e\*(Aq\ef1\*(Aq, \& scalar(localtime), " local, or ", \& scalar(gmtime), " GMT.", \& ], \& " \-\- if you\*(Aqre ", \& [ \e\*(Aq\ei\*(Aq, \& "keeping track.", \& ], \& ], \& \e\*(Aq\epar\epage\*(Aq, \& ); .Ve .RE .RS 4 .Sp The return value of the \fBprint()\fR method is currently always the value 1, although this may change. .RE .ie n .IP "$h\->prolog(...);" 4 .el .IP "\f(CW$h\fR\->prolog(...);" 4 .IX Item "$h->prolog(...);" This writes an \s-1RTF\s0 prolog to \f(CW$h\fR. You are free to make your own prolog using just \f(CW$h\fR\->print(\e'...your own code...'), but I find in easier to automate this task, particularly with some sane defaults. .Sp Since emitting a prolog opens a \*(L"{\*(R"\-group, calling \f(CW$h\fR\->prolog(...) sets a flag in \f(CW$h\fR so that when you call \f(CW$h\fR\->\fBclose()\fR, a closing \*(L"}\*(R" will automatically be written before the stream object is actually closed. .Sp The options to the \fBprolog()\fR method are passed as a list of keys and values, for controlling the contents of the prolog written. The options are listed below, roughly with the most important options first. .Sp (Be careful with the spelling of these options. Some are rather odd, because they are (mostly) based on the name of the relevent \s-1RTF\s0 command, and a systematic naming scheme for commands is one thing you won't find in \s-1RTF\s0!) .RS 4 .ie n .IP "'fonts' => [ ""Courier New"", ""Georgia"", ""Whatever""...]," 4 .el .IP "'fonts' => [ ``Courier New'', ``Georgia'', ``Whatever''...]," 4 .IX Item "'fonts' => [ Courier New, Georgia, Whatever...]," This value is for the font table section of the prolog. If the value is an arrayref, then it should be a reference to an array whose items should be either plain text strings, like \*(L"Times Roman\*(R", which are the (unescaped) names of fonts; or the items in the array can be scalar-refs, for expressing \&\s-1RTF\s0 control words along with the (escaped) font name, as in \&\f(CW\*(C`\e\*(Aq\efroman Times New Roman\*(Aq\*(C'\fR. If the value of the \*(L"fonts\*(R" parameters is a scalar ref, then it is taken to be a reference to code of your own that expresses the whole font table. If you don't specify a value for the \*(L"font\*(R" option, then you get a font table with one entry, \*(L"Times New Roman\*(R". .Sp You should be sure to declare all fonts that you switch to in your document (as with \e'\ef3', to change the current font to what's declared in entry 3 (counting from 0) in the font table). .IP "'deff' => \s-1INTEGER,\s0" 4 .IX Item "'deff' => INTEGER," This is for expressing, in the prolog, the font-table number of the default font for this document. The default is 0, which is an often useful value. .IP "'colors' => [ undef, [0,142,252], [200,32,0], ...]," 4 .IX Item "'colors' => [ undef, [0,142,252], [200,32,0], ...]," This value is for expressing the document's (generally optional) color table. If you stipulate an arrayref value, then each item of the array should be either an \s-1RGB\s0 triplet expressed as an arrayref like [200,32,0], or undef, for a null color-entry. If you stipulate a scalar-ref value for 'colors', then it is taken to be a reference to code of your own that expresses the whole font table. .Sp If you don't stipulate any value for 'colors', then you get a table consisting of three colors: null/default (undef), 100% red ([2550,0,0]), and 100% blue ([0,0,255]). .Sp You can freely ignore concerns of color tables if you don't use color-changing codes in your document (like \e'\ecf2', to switch the text foreground color to what's declared at entry 2 (starting from 0) in the color table). .IP "'stylesheet' => \s-1STRING,\s0" 4 .IX Item "'stylesheet' => STRING," .PD 0 .IP "'filetbl' => \s-1STRING,\s0" 4 .IX Item "'filetbl' => STRING," .IP "'listtables' => \s-1STRING,\s0" 4 .IX Item "'listtables' => STRING," .IP "'revtbl' => \s-1STRING,\s0" 4 .IX Item "'revtbl' => STRING," .PD These are for expressing, in the prolog, code constituting the document's style sheet, table-of-files, table-of-lists, and table-of-revisions, respectively. The default value of each of these is empty-string. None of these are needed by a typical \s-1RTF\s0 document. .IP "'more_default' => \s-1STRING,\s0" 4 .IX Item "'more_default' => STRING," This is for inserting any additional code just after the '\edeffN' in the start of the prolog, before the font table. A common useful value here is \e'\edeflang1033', to express the default language (1033 = RTFese for \&\s-1US\s0 English) for the document, although my reading of the \s-1RTF\s0 spec leads me to believe that this doesn't need to be in the prolog here (where many writers put it, as apparently accepted by many \s-1RTF\s0 readers), but should (instead?) go just after the prolog, with other \*(L"document formatting\*(R" commands described in the \*(L"Document Formatting Properties\*(R" section of the \s-1RTF\s0 Specification. .IP "'doccomm' => \s-1STRING,\s0" 4 .IX Item "'doccomm' => STRING," This value is for the \*(L"document comment\*(R" metainformation item in the prolog, which appears as the \*(L"Comment\*(R" field in the \*(L"File Properties\*(R" panel in MSWord, or as the \*(L"Abstract\*(R" field in the \*(L"File Properties\*(R" window in WordPerfect. .Sp If no value is specified, then RTF::Writer puts a string noting the value of \f(CW$0\fR (typically the filespec to the current Perl program), and the version of RTF::Writer used. .IP "'title' => \s-1STRING,\s0" 4 .IX Item "'title' => STRING," .PD 0 .IP "'subject' => \s-1STRING,\s0" 4 .IX Item "'subject' => STRING," .IP "'author' => \s-1STRING,\s0" 4 .IX Item "'author' => STRING," .IP "'manager' => \s-1STRING,\s0" 4 .IX Item "'manager' => STRING," .IP "'company' => \s-1STRING,\s0" 4 .IX Item "'company' => STRING," .IP "'operator' => \s-1STRING,\s0" 4 .IX Item "'operator' => STRING," .IP "'category' => \s-1STRING,\s0" 4 .IX Item "'category' => STRING," .IP "'keywords' => \s-1STRING,\s0" 4 .IX Item "'keywords' => STRING," .IP "'hlinkbase' => \s-1STRING,\s0" 4 .IX Item "'hlinkbase' => STRING," .IP "'comment' => \s-1STRING,\s0" 4 .IX Item "'comment' => STRING," .PD These are for stipulating the string values of these various optional document metainformation items. 'operator' is for the name of the person who last made changes to the document; 'hlinkbase' is which is the \s-1URL\s0 or path that is used for for resolving any all relative hyperlinks in the document; 'comment' is reportedly just ignored (cf. the 'doccomm' attribute, which is \fInot\fR ignored); and you can guess the rest. .Sp The meanings of all of these are explained in greater detail in the \s-1RTF\s0 spec. .IP "'revtim' => \s-1EPOCH_NUMBER,\s0" 4 .IX Item "'revtim' => EPOCH_NUMBER," This value is for the document metainformation section of the prolog. It signifies the last-modified time of the document. \&\s-1EPOCH_NUMBER\s0 is the number of seconds since the epoch, such as one gets from \f(CW\*(C`(stat($thing)[9])\*(C'\fR or \f(CW\*(C`time()\*(C'\fR; or you may pass a reference a timelist, like [localtime($whatever)]. .Sp If no defined value for revtime is stipulated in the call to prolog(...) then the current value of \fBtime()\fR is used. Explicitly pass a value of undef to suppress emitting any 'creatim' value. .IP "'creatim' => \s-1EPOCH_NUMBER,\s0" 4 .IX Item "'creatim' => EPOCH_NUMBER," This value is for the document metainformation section of the prolog. It signifies the last-modified time of the document. If no defined value for 'creatim' is stipulated in the call to prolog(...) then the current value of \fBtime()\fR is used. Explicitly pass a value of undef to suppress emitting any 'creatim' value. .IP "'printim' => \s-1EPOCH_NUMBER,\s0" 4 .IX Item "'printim' => EPOCH_NUMBER," This value is for the document metainformation section of the prolog. It signifies the time when this document was last printed. If you don't stipulate a defined value here, no 'printim' metainformation is written. .IP "'buptim' => \s-1EPOCH_NUMBER,\s0" 4 .IX Item "'buptim' => EPOCH_NUMBER," This value is for the document metainformation section of the prolog. It signifies the \*(L"backup time\*(R" of this document. If you don't stipulate a defined value here, no 'buptim' metainformation is written. .IP "'version' => \s-1INTEGER,\s0" 4 .IX Item "'version' => INTEGER," .PD 0 .IP "'vern' => \s-1INTEGER,\s0" 4 .IX Item "'vern' => INTEGER," .IP "'edmins' => \s-1INTEGER,\s0" 4 .IX Item "'edmins' => INTEGER," .IP "'nofpages' => \s-1INTEGER,\s0" 4 .IX Item "'nofpages' => INTEGER," .IP "'nofwords' => \s-1INTEGER,\s0" 4 .IX Item "'nofwords' => INTEGER," .IP "'nofchars' => \s-1INTEGER,\s0" 4 .IX Item "'nofchars' => INTEGER," .IP "'nofcharsws' => \s-1INTEGER,\s0" 4 .IX Item "'nofcharsws' => INTEGER," .IP "'id' => \s-1INTEGER,\s0" 4 .IX Item "'id' => INTEGER," .PD These are for stipulating the integer values of these various optional (and not terribly useful, for most purposes!) document metainformation items. The meanings of all of these are explained in the \s-1RTF\s0 spec. .IP "'charset' => \s-1STRING,\s0" 4 .IX Item "'charset' => STRING," This is for expressing, in the prolog, \s-1RTF\s0 codename for the character set being used in this document. The default is \*(L"ansi\*(R", and don't stipulate anything else (like \*(L"mac\*(R", \*(L"pc\*(R", or \*(L"pca\*(R") unless you know what you're doing. .IP "'rtf_version' => \s-1INTEGER,\s0" 4 .IX Item "'rtf_version' => INTEGER," This is for expressing, in the prolog, what major version of \s-1RTF\s0 is being used in this document. The default is 1, and don't use anything else unless you really know what you're doing. .RE .RS 4 .RE .ie n .IP "$h\->printf('format', ...items...);" 4 .el .IP "\f(CW$h\fR\->printf('format', ...items...);" 4 .IX Item "$h->printf('format', ...items...);" This is just short for \f(CW$h\fR\->print(sprintf('format', ...items...) .ie n .IP "$h\->printf(\e'format', ...items...);" 4 .el .IP "\f(CW$h\fR\->printf(\e'format', ...items...);" 4 .IX Item "$h->printf('format', ...items...);" In this case, 'format' is assumed to contain already-escaped \s-1RTF\s0 code. The items in ...items... are escaped as necessary, and then interpolated. I.e., this is rather like: \&\f(CW$h\fR\->print(\esprintf 'format', map rtfesc($_), ...items...)) except that numeric items don't get escaped (and don't need to be). Example: .Sp .Vb 4 \& $h\->printf( \& \e\*(Aq{\ei "%s"} was found in %2.2f percent of matches\epar\*(Aq, \& $word, 100 * $count / $total \& ); .Ve .ie n .IP "$h\->\fBnumber_pages()\fR;" 4 .el .IP "\f(CW$h\fR\->\fBnumber_pages()\fR;" 4 .IX Item "$h->number_pages();" .PD 0 .ie n .IP "$h\->number_pages(...);" 4 .el .IP "\f(CW$h\fR\->number_pages(...);" 4 .IX Item "$h->number_pages(...);" .PD This is just a handy wrapper for some code that turns on page numbering. If you call this method, you should call it right after you emit a prolog. .Sp The page numbering consists of just putting the page number at the top-right of each page. If you provide items in the list (...), then that is pre-pended to the page number. Example: .Sp .Vb 1 \& $h\->number_pages("Lexicon, p."); .Ve .Sp Or: .Sp .Vb 1 \& $h\->number_pages(\e\*(Aq\eb\efs30\ef2\*(Aq, "page "); .Ve .ie n .IP "$trdecl = RTF::Writer::TableRowDecl\->new( ...options... )" 4 .el .IP "\f(CW$trdecl\fR = RTF::Writer::TableRowDecl\->new( ...options... )" 4 .IX Item "$trdecl = RTF::Writer::TableRowDecl->new( ...options... )" This constructs an object representing a declaration for a table row. You can have to use it in calls to \f(CW$h\fR\->row($tabldecl,...), and can reuse it on subsequent calls. This object is for declaring the dimensions of table rows. .Sp The work that a declaration has to do, is best explained in this diagram of a bordered three-cell table (first cell containing \*(L"Foo ya!\*(R"), placed near a left margin (shown as the line of colons). The things in brackets are not on the page, but just for our reference: .Sp .Vb 10 \& : [..w1...] \& : [......w2.......] \& : [...w3....] \& [.A..] [.B.] [.B.] \& : \& : +\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-+ \& : | Foo | Bar baz | Yee! | \& : | ya! | quuxi quuxo | | \& : | | quaqua. | | \& : +\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-+ \& : \& [.A..] [.B.] [.B.] \& [..r1........] \& [.....r2.....................] \& [........r3............................] .Ve .Sp Here the horizontal dimensions of the three-celled table are expressed in terms of: A, the distance from the current left margin; B, the minimum distance between the content of the cells (or you can think of this as twice the internal left or right borders in each cell); and then \s-1EITHER\s0 [w1, w2, w3], expressing the width of each cell, \s-1OR\s0 [r1, r2, r3], expressing each cell's right end's distance from the current left margin. All distances are, of course, in twips. .Sp Options to RTF::Writer::TableRowDecl\->new( ...options... ) are: .RS 4 .IP "left_start => \s-1TWIPS,\s0" 4 .IX Item "left_start => TWIPS," This declares the distance between the left margin, and the left end of the table. Default is 0. .IP "inbetween => \s-1TWIPS,\s0" 4 .IX Item "inbetween => TWIPS," This declares the distance labelled \*(L"B\*(R", above. Default is 120, which is 6 points, 1/12th\-inch, about 2mm. .IP "widths => [\s-1TWIPS, TWIPS, TWIPS, ...\s0 ]," 4 .IX Item "widths => [TWIPS, TWIPS, TWIPS, ... ]," This expresses the widths of each of the cells in this row, starting from the leftmost. .IP "reaches => [\s-1TWIPS, TWIPS, TWIPS, ...\s0 ]," 4 .IX Item "reaches => [TWIPS, TWIPS, TWIPS, ... ]," This expresses the rightmost extreme of each of the cells in this row. .IP "align => \fIalignmentspecs\fR," 4 .IX Item "align => alignmentspecs," This is explained in detail in the section \*(L"Cell Alignment Syntax\*(R", below. .IP "borders => \fIborderspecs\fR," 4 .IX Item "borders => borderspecs," This is explained in detail in the section \*(L"Cell Border Syntax\*(R", below. .RE .RS 4 .RE .ie n .IP "$h\->paragraph(...);" 4 .el .IP "\f(CW$h\fR\->paragraph(...);" 4 .IX Item "$h->paragraph(...);" This makes the items in the list (...) into a paragraph. Basically just a wrapper for \f(CW$h\fR\->print([ \e'{\epar', ..., \e'\epard}', ]) .ie n .IP "$h\->row($trdecl, ...items...);" 4 .el .IP "\f(CW$h\fR\->row($trdecl, ...items...);" 4 .IX Item "$h->row($trdecl, ...items...);" This emits a table row, with dimensions as stipulated by the \&\f(CW$trdecl\fR object, and with row content from the items given. .Sp You must provide a value for \f(CW$trdecl\fR, or a fatal error results. .Sp If you provide \fIfewer\fR items than \f(CW$trdecl\fR declares cells, then you get empty cells to fill out the row. If you provide \fImore\fR items than \f(CW$trdecl\fR declares cells, then the width of the last declared row is used in figuring the width of the additional cells for this row. .Sp Example: .Sp .Vb 4 \& my $decl = RTF::Writer::TableRowDecl\->new(\*(Aqwidths\*(Aq => [1500,1900]); \& $h\->row($decl, "Stuff", "Hmmm"); \& $h\->row($decl, [\e\*(Aq\eul\*(Aq, \*(AqFoo\*(Aq], \*(AqBar\*(Aq, \e\*(Aq\ebullet\*(Aq); \& $h\->row($decl, "Hooboy."); .Ve .Sp This creates a table resembing: .Sp .Vb 7 \& +\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ \& | Stuff | Hmm | \& +\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ \& | _Foo_ | Bar | * | \& +\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ \& | "Hooboy." | | \& +\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ .Ve .Sp Note that you \fI\s-1MUST NOT\s0\fR use '\epar' commands in any items you emit in row cells! .Sp The \f(CW$h\fR\->row(...) method is a wrapper for producing elementary tables in \s-1RTF,\s0 with the minimum of parameters; the myriad other options that tables can have (for example, changing borders) are not supported. If you really need to generate tables fancier than what \f(CW$h\fR\->row(...) can produce, start off reading the \s-1RTF\s0 spec, reading the source for \fBrow()\fR (and the RTF::Writer::TableRowDecl class), and progress from there. Note that MSWord has been known to crash when given malformed \&\s-1RTF\s0 table code. .ie n .IP "$h\->table($trdecl, [...row1 items...], [...row2 items...], ... );" 4 .el .IP "\f(CW$h\fR\->table($trdecl, [...row1 items...], [...row2 items...], ... );" 4 .IX Item "$h->table($trdecl, [...row1 items...], [...row2 items...], ... );" .PD 0 .ie n .IP "$h\->table([...row1 items...], [...row2 items...], ... );" 4 .el .IP "\f(CW$h\fR\->table([...row1 items...], [...row2 items...], ... );" 4 .IX Item "$h->table([...row1 items...], [...row2 items...], ... );" .PD This is a wrapper around \f(CW$h\fR\->row. It takes a list of arrayrefs, which are fed to calls to h\->row($tr_decl, @$each_arrayref). You should provide a \f(CW$trdecl\fR, but if you don't, then one is \fIcrudely\fR guessed at, based on the maximum number of columns in all rows. .ie n .IP "$h\->image( \fIimage_parameters\fR )" 4 .el .IP "\f(CW$h\fR\->image( \fIimage_parameters\fR )" 4 .IX Item "$h->image( image_parameters )" This returns a scalar-reference to RTF-code representing the given image with given parameters. For example: .Sp .Vb 4 \& $h\->paragraph( \& "See here: ", \& $h\->image( \*(Aqfilename\*(Aq => "foo.png", ), \& ); .Ve .Sp The legal options are explained below: .RS 4 .IP "filename => \s-1FILENAME,\s0" 4 .IX Item "filename => FILENAME," This should be the path to a readable filename. You have to specify this. If you don't specify this, or if the value isn't a readable file, then a fatal error results. Currently, only JPEGs and PNGs are allowed; specifying any other kind of file causes a fatal error. .Sp (The \f(CW\*(C`filename\*(C'\fR option above is required, but the following options are all generally optional \*(-- altho some \s-1RTF\s0 processors may be finicky if you set some of the following but not others, for no apparent reason. When in doubt, test.) .IP "wgoal => \s-1TWIPS,\s0" 4 .IX Item "wgoal => TWIPS," The desired width of the image .IP "hgoal => \s-1TWIPS,\s0" 4 .IX Item "hgoal => TWIPS," The desired height of the image .IP "scalex => \s-1PERCENT,\s0" 4 .IX Item "scalex => PERCENT," .PD 0 .IP "scaley => \s-1PERCENT,\s0" 4 .IX Item "scaley => PERCENT," .PD Respectively, the horizontal (X) or vertical (Y) scaling value. The argument is an integer representing a percentage. (The default is 100 percent) .IP "cropt => \s-1TWIPS,\s0" 4 .IX Item "cropt => TWIPS," .PD 0 .IP "cropb => \s-1TWIPS,\s0" 4 .IX Item "cropb => TWIPS," .IP "cropl => \s-1TWIPS,\s0" 4 .IX Item "cropl => TWIPS," .IP "cropr => \s-1TWIPS,\s0" 4 .IX Item "cropr => TWIPS," .PD These specify the top, bottom, left, and right cropping values. A positive value crops \fItoward\fR the center of the image. A negative value crops \&\fIaway\fR from the center, adding a padding space around the image. .Sp (The default is to do neither, as you'd get from a cropping value of 0.) .IP "picspecs => \eSCALARVALUE," 4 .IX Item "picspecs => SCALARVALUE," This overrides generation of the normal image values based the image and the above parameters, and instead uses whatever value you pass a reference to. You normally shouldn't need to use this. .RE .RS 4 .RE .ie n .IP "$h\->image_paragraph( \fIimage_parameters\fR );" 4 .el .IP "\f(CW$h\fR\->image_paragraph( \fIimage_parameters\fR );" 4 .IX Item "$h->image_paragraph( image_parameters );" This take the same options as \f(CW\*(C`$h\->image(...)\*(C'\fR, but has three differences: First, it is a shortcut for this: .Sp .Vb 3 \& $h\->paragraph( \e\*(Aq\eqc\*(Aq, \& $h\->image( ...params...), \& ); .Ve .Sp Secondly, whereas \f(CW\*(C`$h\->image(...)\*(C'\fR returns the image data (as an \s-1RTF\s0 scalarref), \f(CW\*(C`$h\->image_paragraph(...)\*(C'\fR doesn't return much of anything. .Sp Thirdly, \f(CW\*(C`$h\->image_paragraph(...)\*(C'\fR is often much more memory-efficient, since it can write the image data to a file as it's RTF-ified, instead of building it all up in memory. .ie n .IP "$h\->\fBclose()\fR;" 4 .el .IP "\f(CW$h\fR\->\fBclose()\fR;" 4 .IX Item "$h->close();" This completes writing to the stream denoted by the object in \f(CW$h\fR; this generally (assuming you'd called \f(CW$h\fR\->prolog) involves just writing a final close-brace to \f(CW$h\fR, and then closing whatever filehandle or file \f(CW$h\fR writes to (unless we're writing to a string, in which case we just discard \f(CW$h\fR's reference to it). After you call \f(CW\*(C`$h\->close\*(C'\fR, you should not call any other methods with \f(CW$h\fR! .Sp Note that you don't \fIhave\fR to explicitly call \f(CW\*(C`$h\->close\*(C'\fR \*(-- when an unclosed RTF::Writer object goes out of scope (or, more precisely speaking, when if its refcount hits zero), then something equivalent to calling \f(CW\*(C`$h\->close\*(C'\fR is done automatically for you. .SH "AUTOMETHODS" .IX Header "AUTOMETHODS" In addition to any of the above methods, you can use any \s-1RTF\s0 command (and optional integer arguments) as a valid method name, by just capitalizing its first letter, as shown below: .ie n .IP "$h\->\fBFoo()\fR;" 4 .el .IP "\f(CW$h\fR\->\fBFoo()\fR;" 4 .IX Item "$h->Foo();" The same as \f(CW$h\fR\->print( \e'\efoo' ); .Sp For example, \f(CW$h\fR\->\fBPage()\fR is the same as \f(CW$h\fR\->print(\e'\epage') .ie n .IP "$h\->Foo(...);" 4 .el .IP "\f(CW$h\fR\->Foo(...);" 4 .IX Item "$h->Foo(...);" (Where \*(L"...\*(R" is a non-empty list.) .Sp The same as \f(CW$h\fR\->print( [ \e'\efoo', ... ] ); .Sp For example: \&\f(CW\*(C`$h\->I(\*(Aqstuff\*(Aq)\*(C'\fR is the same as \f(CW$h\fR\->print([\e'\ei', 'stuff']) .ie n .IP "$h\->\fBFoo123()\fR;" 4 .el .IP "\f(CW$h\fR\->\fBFoo123()\fR;" 4 .IX Item "$h->Foo123();" The same as \f(CW$h\fR\->print( \e'\efoo123' ). I.e., command word \*(L"\efoo\*(R" with an integer argument of 123. .Sp For example: \f(CW$h\fR\->\fBCols2()\fR is the same as \f(CW$h\fR\->print(\e'\ecols2') .ie n .IP "$h\->Foo123(...);" 4 .el .IP "\f(CW$h\fR\->Foo123(...);" 4 .IX Item "$h->Foo123(...);" (Where \*(L"...\*(R" is a non-empty list.) .Sp The same as \f(CW$h\fR\->print( [ \e'\efoo123', ... ] ); .Sp For example: \f(CW$h\fR\->F2('stuff') is the same as \&\f(CW$h\fR\->print([\e'\ef2', 'stuff']). .ie n .IP "$h\->\fBFoo_123()\fR;" 4 .el .IP "\f(CW$h\fR\->\fBFoo_123()\fR;" 4 .IX Item "$h->Foo_123();" The same as \f(CW$h\fR\->print( \e'\efoo\-123' );, i.e., command word \*(L"\efoo\*(R" with an integer argument of negative 123. (You can't have a \*(L"\-\*(R" in a method name, so I use an underscore instead.) .Sp For example: \f(CW$h\fR\->\fBLi_1440()\fR is the same as \f(CW$h\fR\->print([\e'\eli\-1440', 'stuff']) .ie n .IP "$h\->Foo_123(...);" 4 .el .IP "\f(CW$h\fR\->Foo_123(...);" 4 .IX Item "$h->Foo_123(...);" (Where \*(L"...\*(R" is a non-empty list.) .Sp The same as \f(CW$h\fR\->print( [ \e'\efoo\-123', ... ] ); .SH "FUNCTIONS" .IX Header "FUNCTIONS" None of these functions are exported by default, but they can be exported on request, as in: .PP .Vb 1 \& use RTF::Writer qw(inches cm rtfesc); .Ve .IP "inch($x), inches($x), in($x)" 4 .IX Item "inch($x), inches($x), in($x)" These synonymous functions all construe the numeric value in \f(CW$x\fR as inches, and return the equivalent number of twips. For example, \f(CW\*(C`inches(1.5)\*(C'\fR returns 2160, because an inch and a half is exactly 2160 twips. The return value of these functions is always an integer, as fractions of twips are not used in \s-1RTF.\s0 .IP "point($x), points($x), pt($x)" 4 .IX Item "point($x), points($x), pt($x)" These synonymous functions all construe the numeric value in \f(CW$x\fR as points, and return the equivalent number of twips. For example, \f(CW\*(C`points(54)\*(C'\fR returns 1080, because fifty-four points is exactly 1080 twips. The return value of these functions is always an integer, as fractions of twips are not used in \s-1RTF.\s0 .IP "cm(x)" 4 .IX Item "cm(x)" This function construes the numeric value in \f(CW$x\fR as centimeters, and returns the equivalent number of twips. For example, \f(CW\*(C`cm(1.5)\*(C'\fR returns 850, because 1.5cm is approximately 850 twips (i.e., it's 850, when rounded to the nearest whole number). Since twips and points are both are defined in terms of inches (1440 twips = 72 points = 1 inch), conversion between cm and these other units is approximate. .Sp The return value of \f(CW\*(C`cm($x)\*(C'\fR is always an integer, as fractions of twips are not used in \s-1RTF.\s0 .IP "rtfesc($text); # void context" 4 .IX Item "rtfesc($text); # void context" .PD 0 .ie n .IP "rtfesc($x, $y); # void context" 4 .el .IP "rtfesc($x, \f(CW$y\fR); # void context" 4 .IX Item "rtfesc($x, $y); # void context" .IP "rtfesc(@z); # void context" 4 .IX Item "rtfesc(@z); # void context" .ie n .IP "$escaped = rtfesc($x);" 4 .el .IP "\f(CW$escaped\fR = rtfesc($x);" 4 .IX Item "$escaped = rtfesc($x);" .ie n .IP "@escaped = rtfesc($x, $y, ...);" 4 .el .IP "\f(CW@escaped\fR = rtfesc($x, \f(CW$y\fR, ...);" 4 .IX Item "@escaped = rtfesc($x, $y, ...);" .PD This escapes some plaintext so it's good \s-1RTF.\s0 E.g., it turns \*(L"Foo\enBar\e\e\*(R" into \*(L"Foo\en\e\eline Bar\e\e'5c\*(R" (since a plaintext backslash needs to be escaped in \s-1RTF,\s0 and a \*(L"\en\*(R"'s \s-1RTF\s0 equivalent is the '\eline' command). .Sp In void context (i.e., where you aren't capturing the return value), this in-place alters the values you pass it. .Sp In scalar or list context, doesn't alter the original(s), but returns an escaped copy of what you pass in. .SS "Cell Alignment Syntax" .IX Subsection "Cell Alignment Syntax" To control alignment of cells, specify \f(CW\*(C`align => "\f(CIdirection direction direction...\f(CW"\*(C'\fR, where each direction is one of these alphametic strings for the given directions (based on the abbreviated English names for map directions and canvas directions): .PP .Vb 5 \& NW N NE TL T TR \& \e | / \e | / \& W \- C \- E L \- C \- R \& / | \e / | \e \& SW S SE BL B BR .Ve .PP For example, \f(CW\*(C`align => "nw c"\*(C'\fR means that the first cell will be aligned to the \fB\f(BIn\fB\fRorth\fB\f(BIw\fB\fRest (a.k.a. the \fB\f(BIt\fB\fRop\-\fB\f(BIl\fB\fReft), and that the second cell (and any cells thereafter) will be aligned to the \fB\f(BIc\fB\fRenter. .PP An acceptable alternate syntax is to \&\f(CW\*(C`align => [\*(Aqnw\*(Aq, \*(Aqc\*(Aq]\*(C'\fR \*(-- i.e., to pass a reference to an array of \fI'direction'\fR items, instead of just passing a single scalar of whitespace-padded directions. .PP (Note that alignment syntax and cell border syntax, may look a bit alike, but are really very different; try not to mix them up.) .SS "Cell Border Syntax" .IX Subsection "Cell Border Syntax" To specify what borders occur on cells, use one of the following syntaxes: .ie n .IP """borders => 1,"" or ""borders => \*(Aqall\*(Aq,"" to turn on a simple border for all sides of all cells. \fBThis is the default \-\-\fR so if you don't specify a ""borders => \fIsomething\fP"" option, it will be as if you specified ""borders => 1""." 4 .el .IP "\f(CWborders => 1,\fR or \f(CWborders => \*(Aqall\*(Aq,\fR to turn on a simple border for all sides of all cells. \fBThis is the default \-\-\fR so if you don't specify a \f(CWborders => \f(CIsomething\f(CW\fR option, it will be as if you specified \f(CWborders => 1\fR." 4 .IX Item "borders => 1, or borders => all, to turn on a simple border for all sides of all cells. This is the default -- so if you don't specify a borders => something option, it will be as if you specified borders => 1." .PD 0 .ie n .IP """borders => 0,"" or ""borders => \*(Aqnone\*(Aq,"" to turn off all borders for all cells. \fBIn previous versions of RTF::Writer, this \f(BIwas\fB the default.\fR" 4 .el .IP "\f(CWborders => 0,\fR or \f(CWborders => \*(Aqnone\*(Aq,\fR to turn off all borders for all cells. \fBIn previous versions of RTF::Writer, this \f(BIwas\fB the default.\fR" 4 .IX Item "borders => 0, or borders => none, to turn off all borders for all cells. In previous versions of RTF::Writer, this was the default." .PD .PP or use this complex syntax for finer control: .ie n .IP """borders => [ \fIcellborders, cellborders, ...\fP ],""" 4 .el .IP "\f(CWborders => [ \f(CIcellborders, cellborders, ...\f(CW ],\fR" 4 .IX Item "borders => [ cellborders, cellborders, ... ]," .PP \&...where each \f(CW\*(C`cellborders\*(C'\fR is a string in the form "\fIborder border border\fR", where, in turn, each \&\fIborder\fR is a substring in the form \&\fI\*(L"direction-thickness-type\*(R",\fR \&\fI\*(L"direction-type\*(R"\fR \&\fI\*(L"direction-thickness\*(R",\fR or \fI\*(L"direction\*(R".\fR Alternately, \f(CW\*(C`cellborders\*(C'\fR can be one of these shorter values: .ie n .IP "the value ""none"" \*(-- meaning no borders in any direction" 4 .el .IP "the value ``none'' \*(-- meaning no borders in any direction" 4 .IX Item "the value none meaning no borders in any direction" .PD 0 .ie n .IP "an integer between 2 and 75 \*(-- meaning a simple border that's that many twips thick, on all sides. (So specifying ""22"" is synonymous with ""all\-22\-s"" in the longer syntax.)" 4 .el .IP "an integer between 2 and 75 \*(-- meaning a simple border that's that many twips thick, on all sides. (So specifying ``22'' is synonymous with ``all\-22\-s'' in the longer syntax.)" 4 .IX Item "an integer between 2 and 75 meaning a simple border that's that many twips thick, on all sides. (So specifying 22 is synonymous with all-22-s in the longer syntax.)" .ie n .IP "empty-string or undef \*(-- meaning a simple border of the default thickness on all sides. (So specifying """" is synonymous with ""all"", which is in turn synonymous with ""nsew\-15\-s"".)" 4 .el .IP "empty-string or undef \*(-- meaning a simple border of the default thickness on all sides. (So specifying ``'' is synonymous with ``all'', which is in turn synonymous with ``nsew\-15\-s''.)" 4 .IX Item "empty-string or undef meaning a simple border of the default thickness on all sides. (So specifying "" is synonymous with all, which is in turn synonymous with nsew-15-s"".)" .PD .PP \&\fIdirection\fR is either \*(L"all\*(R", or a combination of some of the uppercase or lowercase letters N, S, E, W, T, B, R, L. (Of course, the first four are synonymous with the other four, respectively.) .PP \&\fIthickness\fR (by default, 15) is an integer between 1 and 75, specifying the thickness of the border, in twips. .PP And \fItype\fR (by default, \*(L"s\*(R") is one of these, as specified in the \s-1RTF\s0 spec: .PP .Vb 6 \& s : Single\-thickness border \& th : Double\-thickness border \& sh : Shadowed border \& db : Double border \& dot : Dotted border \& hair : Hairline border \& \& dash : Dashed border \& inset : Inset border \& dashsm : Dashed border (small) \& dashd : Dot\-dashed border \& dashdd : Dot\-dot\-dashed border \& outset : Outset border \& triple : Triple border \& tnthsg : Thick\-thin border (small) \& thtnsg : Thin\-thick border (small) \& tnthtnsg : Thin\-thick thin border (small) \& tnthmg : Thick\-thin border (medium) \& thtnmg : Thin\-thick border (medium) \& tnthtnmg : Thin\-thick thin border (medium) \& tnthlg : Thick\-thin border (large) \& thtnlg : Thin\-thick border (large) \& tnthtnlg : Thin\-thick\-thin border (large) \& wavy : Wavy border \& wavydb : Double wavy border \& dashdotstr : Striped border \& emboss : Embossed border \& engrave : Engraved border \& frame : Border resembles a "frame" .Ve .PP Not all of the above are supported by all \s-1RTF\s0 readers. If you're concerned about portability, consider sticking to the core set of just the first six listed above. .PP Also, the syntax \f(CW\*(C`borders => cellspec\*(C'\fR is accepted as a synonym for \f(CW\*(C`borders => [cellspec]\*(C'\fR, for when you're specifying just a single cellspec, for use the the first and all subsequent cells. .PP Cell border syntax is best shown by example: .PP .Vb 1 \& borders=> [ "ns\-30\-db w\-25", "all\-10\-wavy", "none", 13 ], .Ve .PP That means to that the first cell should have a 30\-twip\-thick double border on the top and bottom (north and south) and a 25\-twip\-thick single border on the west (and no border on the east side); the second cell should have a 10\-twip\-thick wavy border on all sides; the third cell should have no borders on any sides; and the fourth (and any additional) cells should have a 13\-twip\-thick single border on all sides. .PP Incidentally, when a particular \fIcellspec\fR contains apparently contradictory declarations, the last one is the one that has an effect. For example, consider \f(CW"all\-20\-db w\-10\-s"\fR \*(-- the first part turns on 20\-twip double borders on all sides, and the second part turns on a 10\-twip single border on the west side. Since the second part is last, that's the one that has an effect \*(-- so just the north, south, and east sides actually get a 20\-twip double border, and the west side gets the 10\-twip single border. .PP (This means that if you say \f(CW"w\-10\-s all\-20\-db"\fR, the first part will have no effect, because the second part will override the west-side declaration.) .SS "Cell Border Syntax, Formally" .IX Subsection "Cell Border Syntax, Formally" If you'd prefer a more formal grammar for this all, this should help: .PP .Vb 5 \& borderdec := \& \*(Aqborders\*(Aq => \*(Aq0\*(Aq # no borders at all \& | \*(Aq1\*(Aq # same as ["all\-15\-s"] \& | [ cellspec, cellspec, ... ] \& | cellspec # default for one\-cell form of the above \& \& cellspec := "" | undef # same as "all\-15\-s" \& | int # same as "all\-INT\-s" (note: 2 <= int <= 75) \& | "none" # no borders on this cell \& | (border ( \*(Aq, \*(Aq . border )* ) \& # a list of border expressions separated by \& # a comma (and/or whitespace, in fact) \& \& border := direction\-thickness\-type # For example, "nse\-15\-s" \& | direction\-type # same as "DIR\-15\-TYPE" \& | direction\-thickness # same as "DIR\-THICK\-s" \& | direction # same as "DIR\-15\-s" \& \& direction := "all" | qr/^[nsewtblrNSEWTBLR]+$/ \& # Note that "nw" doesn\*(Aqt mean the direction northwest, but \& # simultaneously the north and west sides. \& \& thickness := integer in the range 1 \- 75 \& \& type := "s" | "th" | "sh" | "db" | "dot" | "hair" | (etc) .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" RTF::Cookbook .PP The book \fI\s-1RTF\s0 Pocket Guide\fR from O'Reilly. .SH "COPYRIGHT AND DISCLAIMER" .IX Header "COPYRIGHT AND DISCLAIMER" Copyright 2001,2,3 Sean M. Burke. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. .PP The author of this document is not affiliated with the Microsoft corporation. .PP Product and company names mentioned in this document may be the trademarks or service marks of their respective owners. Trademarks and service marks are not identified, although this must not be construed as the author's expression of validity or invalidity of each trademark or service mark. .SH "AUTHOR" .IX Header "AUTHOR" Sean M. Burke,