Repository navigation
Releases: TwelveTake-Studios/rtf-parser-tt
Releases · TwelveTake-Studios/rtf-parser-tt
Release list
rtf-parser-tt 0.6.0
Added
RtfDocument::from_bytesparses an RTF document from bytes. UTF-8 input is read as is; any
other input is decoded with the code page the document declares.RtfDocument::from_filepath
andTryFrom<&mut File>read files the same way, so a file no longer needs to be valid UTF-8.RtfDocument::get_text_withreturns the plain text according toTextOptions: hidden text
(off by default), footnotes with their numbers (on by default), and headers and footers (on by
default).RtfDocument::get_textuses the defaults.StyleBlock::partidentifies the part of the document a block belongs to:Part::Body,
Part::NoteReference(n)for a footnote number in the body text,Part::Note(n),
Part::HeaderorPart::Footer.RtfDocument::infoholds the document properties from the\infogroup: title, subject,
author, manager, company, operator, category, keywords and comment.\'xxescapes are decoded through the code page that\ansicpg,\mac,\pcor\pca
declares, or that the current font's\fcharsetselects: Windows code pages 874 and 1250 to
1258, DOS code pages 437, 850 and 866, Mac Roman, UTF-8, and the Symbol font.- The
encoding_rsfeature, enabled by default, decodes the Japanese (932), Simplified Chinese
(936), Korean (949) and Traditional Chinese (950) code pages. RtfErroris the error type ofparse_rtfand of theRtfDocumentconstructors. It implements
std::error::Errorand isSendandSync, andLexerErrorandParserErrorconvert into it.Painter::hiddenmarks hidden text (\v).Styleexposes the name, character formatting and paragraph properties of a stylesheet entry.- Footnote numbers (
\chftn) appear in the text.
Changed
RtfDocument::try_from,RtfDocument::from_filepathandparse_rtfreturnRtfErroron
failure.parse_rtfreturns aResult; it previously returned the document directly.- Public enums and structs are marked
#[non_exhaustive]. Amatchon an enum from this crate
needs a wildcard arm, and a struct is created from its default value and then modified.
TextOptionssets each option with a method, for example
TextOptions::default().hidden_text(true). Lexer::scanreports\v,\sect,\page,\cell,\rowand 11 other control words with
their ownControlWordvariants. 0.5.x reported them asControlWord::Unknown.- Paragraph, section and page breaks (
\par,\sect,\page) produce a line break, as\line
does. Table cells are separated by a tab, and each table row ends with a line break. In 0.5.x,
paragraphs and table cells ran together. - A
StyleBlockcontinues across paragraph breaks while the formatting stays the same, so its
text can contain line breaks between other text. Code that treats a block containing a line
break as a paragraph break alone must split the text at each line break. - Characters that follow
\uNare skipped according to\ucN(one character by default), as the
RTF specification requires. 0.5.x kept them in the text:\u8212 ?produced an em dash
followed by a question mark. A document that writes no replacement character without first
setting\uc0loses the character after each\uN. - Hidden text (
\v) is omitted fromget_text.get_text_withincludes it when
TextOptions::hidden_textis set. - Footnotes, headers and footers follow the body text, in the order Word uses when it saves a
document as plain text. In 0.5.x their text appeared where it occurs in the file, inside the
body text. - Picture data (
\pict) and document properties (\info) no longer appear in the text. - Only the space that ends a control word is consumed. A further space, or a tab after a control
word, is text, and whitespace-only groups such as{ }are kept. - Parsing takes about half the time it took in 0.5.1, or less, on the crate's benchmark
documents.
Removed
- The
recursive_tokenize!andrecursive_tokenize_with_init!macros.
Fixed
parse_rtfreturns an error for malformed input instead of panicking.- Text that directly follows a control word is kept when it begins with punctuation or a
non-ASCII character, for example a comma after\b0or Cyrillic text after\i. Letters that
directly follow a control word are part of the control word, as the RTF specification defines,
so\iwordremains a single control word. \uNfollowed directly by its replacement character, as in\u8212?, produces the character.- The control symbols
\~(no-break space),\-(soft hyphen) and\_(non-breaking hyphen)
produce their characters, and the text after them is kept. - A control word with a nonzero parameter, such as
\b2, turns its formatting on. - Paragraph indents (
\li,\ri,\fi) and the line spacing multiple (\slmult) are applied
toParagraph. - Font names written with hex escapes, or followed by an alternate name (
\*\falt), are read. In
0.5.x these names were empty. - Color table entries are numbered by position, counting empty entries, so
\cfNselects the
intended color. - A document followed by NUL bytes after its closing brace parses.
Known issues
- Endnotes are numbered in sequence with footnotes and listed among them in file order. Word
numbers endnotes separately and lists them after the footnotes. - Text in the Korean Johab code page (1361) is not decoded.