mirror of
https://github.com/storytold/wordcraft.git
synced 2026-10-29 12:57:09 -06:00
* Open RTF in its code page, and Word/RTF files whose extension is wrong RTF import read every 8-bit byte as Windows-1252, so Cyrillic (and any other non-Western) RTF came out as mojibake. Bytes now decode in the current font's code page (\fcharset, \cpg), else the default font's, else the document's (\ansicpg), for the single-byte Windows code pages 874 and 1250-1258. A .doc, .docx or .rtf whose content is another of these formats now opens by its signature, as Word does: RTF saved as .doc (hh.ru résumés and accounting exports are commonly saved that way), a .docx renamed .doc, a Word 97-2003 file renamed .docx. * RTF: read the page size and margins, lay tables out on their cell edges RTF documents opened on US Letter with 1" margins whatever they said, and every table got equal columns and a full grid. Russian accounting and HR exports (A4, 2 cm margins, borderless layout tables whose rows have different \cellx edges) came out about twice as long as in Word. - \paperw/\paperh/\margl…\margb (and the …sxn section forms), \headery, \footery and \landscape set the document's section; out-of-range values keep Word's defaults. Tables size to that page. - A table's column grid is the union of its rows' \cellx edges; each cell spans the grid columns between its left and right edges, as Word does. - A table with no left/right cell borders is laid out without the grid style (\clbrdrb rules alone don't make it ruled; \brdrnone is no border). On 44 RTF files (mostly .doc-named exports) checked against Word's page counts: total page-count difference 198 -> 30, exact matches 3 -> 17, none worse. * RTF: paragraph spacing and indents, RTF defaults, the default font - \sb, \sa, \sl/\slmult (multiple, at least, exactly), \li/\lin, \ri/\rin and \fi are read onto each paragraph (new model::Spacing); \pard resets them. - The document's paragraph defaults are RTF's (single spacing, no space around paragraphs) instead of a new document's 1.15 and 8 pt after. - Text that never selects a font is in the default font (\deff, font 0 when the file names none), as Word shows it. Against Word's page counts on 251 real documents (44 RTF, mostly .doc-named, plus .docx): exact matches 212 -> 216, within 10% 248 -> 249; a 68-page Russian federal law RTF goes from 89 to 73 pages (the rest is the Word installation's own default margins, which the file doesn't name). * RTF: import headers and footers \header, \headerr, \headerl, \headerf and the \footer… forms were skipped, so letterheads, logos and "page N" lines were lost. Each group is now read into its own output (the body's paragraph, table and row state is set aside and put back when the group closes), built into the document with its pictures (new model::part_blocks), and attached to the section as the default, first-page or even-page header or footer; \titlepg sets the separate first page. A header left open by a truncated file still ends. 40 of 41 RTF files in the corpus have headers or footers; against Word's page counts exact matches go 216 -> 218 of 251, none worse. * RTF: cell and paragraph borders Tables either got a full grid (any left/right cell border) or none, and paragraph borders were kept only on empty paragraphs (as a rule), so the rules under letterheads and section titles were lost. - Cells: \clbrdrt/l/b/r with their line style (\brdrs, \brdrdb, \brdrdot, \brdrdash, \brdrth, \brdrtriple, \brdrwavy…, \brdrnone), \brdrw width and \brdrcf colour become the cell's own borders (model::Cell::borders); RTF tables get no grid style, so only the borders the file names are drawn, as in Word. - Paragraphs: \brdrt/b/l/r likewise become the paragraph's borders (model::Para::borders), reset by \pard; an empty paragraph with only a bottom border stays a rule. 40 of 41 RTF files in the corpus name cell borders; page counts against Word are unchanged (218 of 251 exact). --------- Co-authored-by: Магда М.Г. <mail@mgmagda.ru> Co-authored-by: Brandon Thomas <echelon@gmail.com>