Files
DolanandClaude Opus 5.5 66eaf1c12e feat: read the theme of a Word document or template with readTheme, and theme fonts for other scripts (#878) (#3839)
* feat: Word's themes, colors and fonts, and the theme of a Word document or template, from docx/theme (#878)

docx/theme is a new optional entry, so the main bundle stays as it is:

- Themes: the 29 themes of Word's Design > Themes gallery, each with its
  name, colors, and fonts for headings and body text, as IThemeOptions.
- ColorSchemes and FontSchemes: the 24 color sets and 26 font sets of the
  Design > Colors and Design > Fonts galleries, to mix with a theme as
  Word's Design tab does.
- readTheme: the theme of a .docx, .docm, .dotx, .dotm, .pptx, .xlsx or
  .thmx file, or of a theme1.xml, or colors or fonts Word saved on their
  own. Styles taken from a template with externalStyles then keep the
  template's theme fonts and colors (#878).

The presets are generated from Word for Mac's own theme files by
scripts/generate-word-themes.ts, which reads each one with readTheme.

In docx, a theme font can now have a font for each script (scripts, by
ISO 15924 code), in place of Office's for those scripts, so Word's themes
keep their own fonts for Japanese, Chinese and other scripts. docx also
exports parseXml and unzipFiles, which it already had, so docx/theme
reads files without bundling a second XML parser and unzipper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* refactor: read a template's theme with readTheme from docx, sharing the patcher's theme reader, without docx/theme (#878)

- Word's themes, colour sets and font sets (Themes, ColorSchemes, FontSchemes), the
  script that generated them and the docx/theme entry are dropped. #878 asks only for
  the theme of the template a document's styles come from.
- readTheme moves into the core and is exported from docx. The patcher reads the
  colours of a template's theme with the same code, so parseXml and unzipFiles stay
  internal.
- The paths of a package's parts and its relationships' targets (relationshipsPathOf,
  resolveTarget and the others) move from the patcher to src/util/package-paths.ts,
  so the theme reader in src/file can use them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* fix: read a theme in UTF-16, and inflate only a package's relationships and its theme in readTheme

- A theme, or the XML of one, that starts with UTF-16's byte order mark is read as
  UTF-16, little or big endian, as XML may be written.
- readTheme inflates a package's relationships, and then only the theme they refer to,
  so a large or damaged document, presentation or workbook part doesn't take memory or
  stop it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* fix: find a theme whose relationship's target is in another case than its part, in readTheme and the patcher

The Open Packaging Conventions compare part names without regard to case, so a
relationship's target such as "Theme/THEME1.xml" names word/theme/theme1.xml.
readTheme threw that the file has no theme, and patchDocument used Office's colours.
isSamePart, in src/util/package-paths.ts, compares them as drawing-patch already finds
a relationship's target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 23:02:10 +00:00
..