The WordPerfect 5 page lists the function codes and sub-codes of 5.0 and 5.1 documents. This page gives the byte layout of the data inside them, as far as libwpd reads it. Numbers are little-endian. Distances are in WordPerfect units (WPU), 1,200 to the inch. Offsets count from the first data byte: for fixed-length groups, the byte after the code; for variable-length groups, the byte after the 16-bit length. Bytes that libwpd skips are not described anywhere public; many hold the previous (“old”) value of a setting. WordPerfect’s own 5.x documentation is not published by Corel.
Fixed-length groups
| Code | Offset | Size | Field |
|---|---|---|---|
C0 extended character | 0 | 1 | Character number in the set |
| 1 | 1 | Character set (0–13) | |
C1 tab | 0 | 1 | Tab type (see the 5.x page) |
| 3 | 2 | Tab position, WPU | |
C2 indent | 0 | 1 | 0 left indent, 1 left and right indent |
| 5 | 2 | Indent position, WPU | |
C3, C4 attribute on, off | 0 | 1 | Attribute number |
The contents of C5 to CF are not known; libwpd skips
them by their lengths.
0xD0 page format
| Sub-code | Data |
|---|---|
| 1 left and right margins | 4 bytes old values; new left margin (2), new right margin (2), WPU |
| 2 line spacing | 2 bytes old; new spacing (2): high byte the whole part, low byte the fraction in 255ths |
| 4 tab set | 100 bytes old table; then up to 40 tab positions (2 bytes each, WPU, ended by FFFF), the rest of the 40 slots; then 20 type bytes, two tabs per byte: bits 4–5 the first tab, bits 0–1 the second (0 left, 1 centre, 2 right, 3 decimal), bit 6 dot leader; when the data is 0xD0 bytes long, 2 bytes and then a 16-bit margin offset (FFFF none) that positions are relative to |
| 5 top and bottom margins | 4 bytes old; new top (2), new bottom (2), WPU |
| 6 justification | 1 byte old; new value: 0 left, 1 full, 2 centre, 3 right; libwpd treats 4 as decimal-aligned |
| 7 suppress page features | 1 byte old; new flags (see the 5.x page) |
| 11 paper form | 99 bytes; desired form length (2) and width (2), WPU; 90 bytes; orientation (0 portrait, 1 landscape) |
0xD1 font
| Sub-code | Data |
|---|---|
| 0 colour | 3 bytes old; red, green, blue (1 byte each) |
| 1 font change | 25 bytes; font number (1), an index into the font list of the prefix; if the group is at least 36 bytes, 2 bytes and then the size (2), which libwpd divides by 50 to get points |
libwpd notes that WordPerfect Graphics (WPG 1) files use two more sub-codes here, 2 colour and 3 fill pattern, whose colours are palette indexes.
0xD2 sub-code 11: define table
| Size | Field |
|---|---|
| 2 | Old values |
| 2 | Old column count nold |
| 20 + 5 × nold | Old table definition |
| 1 | Flags: bits 0–2 the table’s position |
| 1 | – |
| 2 | Column count n (at most 32) |
| 4 | – |
| 2, 2 | Left and right gutter, WPU |
| 10 | – |
| 2 | Left offset, WPU |
| 2 × n | Column widths, WPU |
| 2 × n | Column attribute bits |
| n | Column alignment |
0xDA boxes
libwpd reads only sub-code 0 (figure):
| Offset | Size | Field |
|---|---|---|
| 0 | 2 | Box number |
| 2 | 1 | Position and type: bits 0–1 anchor (0 paragraph, 1 page, 2 character); bits 2–4 vertical position (0 full page, 1 top, 2 centre, 3 bottom, 4 set position) |
| 3 | 1 | Alignment: bits 0–1 horizontal (0 left, 1 right, 2 centre, 3 full width); bit 7 text wraps round the box |
| 4 | 2 | Width, WPU |
| 6 | 2 | Height, WPU |
| 8 | 2 | Horizontal offset, WPU |
| 10 | 2 | Vertical offset, WPU |
| 48 | 1 | Content type: 0x80 a graphic |
| 109 | 2 | For a graphic: its number in the graphics information packet (type 8) |
The meanings of the position fields follow libwpd’s conversion to page positions; the other box types (table, text, user, equation, lines) are not read.
0xDC and 0xDD table codes
DC sub-code 0 (start of a cell):
| Offset | Size | Field |
|---|---|---|
| 0 | 1 | Flags: bit 0 use the cell’s justification, bit 1 use the cell’s attributes, bits 2–3 vertical alignment |
| 1 | 1 | Column number |
| 2 | 1 | Column span (bits 0–6); bit 7: the cell is covered by the one above |
| 3 | 1 | Row span |
| 8 | 2 | Cell attributes |
| 10 | 1 | Cell justification |
Sub-codes 1 (start of row) and 2 (end of table) of DC, and the
DD sub-codes, carry data that libwpd does not read.
Prefix packets
| Type | Contents |
|---|---|
| 2 fonts used (5.0) | 86-byte entries, one per font: 18 bytes, the name’s offset in the font name pool (2), 2 bytes, size (2, divided by 50 for points), 62 bytes |
| 15 fonts used (5.1) | 86-byte entries: 18 bytes, name offset (2), 27 bytes, size (2, divided by 50), 37 bytes |
| 7 font name pool | Null-terminated font names one after another; each is referred to by its offset from the packet’s start |
| 8 graphics information | Count n (2), then n 32-bit sizes, then the pictures one after another, each a WordPerfect Graphics (WPG) file, sometimes without its own 16-byte WPG header |
A font change (D1 sub-code 1) gives the font’s number, its entry in the
fonts-used list, which gives the name’s offset in the pool. Other packet types, such
as printer and document settings, are not described in public.
Source
- libwpd source –
WP5FileStructure.h,WP5VariableLengthGroup,WP5FixedLengthGroup,WP5ExtendedCharacterGroup,WP5TabGroup,WP5IndentGroup,WP5AttributeGroup,WP5PageFormatGroup,WP5FontGroup,WP5DefinitionGroup,WP5HeaderFooterGroup,WP5FootnoteEndnoteGroup,WP5BoxGroup,WP5TableEOLGroup,WP5TableEOPGroup,WP5ListFontsUsedPacket,WP5FontNameStringPoolPacket,WP5GraphicsInformationPacket,WP5ContentListener,WPXContentListener