Skip to content

refactor(docx): split DocxFontTable in four - #1085

Merged
DemchaAV merged 2 commits into
developfrom
refactor/docx-split-font-table
Nov 25, 2026
Merged

DemchaAV merged 2 commits into
developfrom
refactor/docx-split-font-table

Conversation

@DemchaAV

@DemchaAV DemchaAV commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Why

DocxFontTable writes the DOCX font table, and the rest of font embedding grew inside it until it was 868 lines, against the project's 500. The class did four things:

  • the font table itself: which faces a document asks for, which family keeps a declared name, the refusal of the one that does not, and the parts and XML it writes;
  • the line an editor sets each shipped face in (ShippedLines), which DocxGrownLines reads;
  • a family's faces: the slot each fills, reading each file and its licence terms, and the note on a face an editor will not draw;
  • reading the typeface a program states.

DocxFontTableTest grew with it, to 1,020 lines and 29 tests, eleven of them about two families asking for one name.

What changed

Three package-private classes in com.demcha.compose.document.backend.semantic.docx take the code that is not the table:

  • DocxShippedLines (131 lines) — the former DocxFontTable.ShippedLines.
  • DocxFontFaces (278 lines, static) — the Face class and the Slot enum, facesOf, addFace and the note on a face of another typeface than the family's regular one.
  • DocxTypeface (51 lines) — typefaceOf, which reads name id 16, else id 1, from the Windows en-US record.

DocxFontTable (477 lines) keeps write, familiesByName, the Embedded record, resolve with the shared-name refusal, the walk over the faces a document names, and the XML. write and familiesByName keep their parameters; write returns the renamed DocxShippedLines. Public API is unchanged and the knowledge pack is untouched.

The moved code is the original lines, sliced from the file rather than retyped. Every non-blank line of the original is accounted for in the four files. What differs:

  • visibility: private → package-private where another class now uses a member (Embedded, Face, Slot, facesOf, the ShippedLines constructor);
  • names: ShippedLines → DocxShippedLines, and calls qualified with DocxFontFaces. and DocxTypeface.;
  • two accessors on Face, fontKey() and relationshipId(), which the XML read as fields while Face was nested in the table;
  • javadoc references that now cross a class, the class javadoc of DocxFontTable pointing at DocxFontFaces for the licence terms, and the javadoc lines rewrapped around them;
  • continuation indents realigned after the renames;
  • the unused LinkedHashSet import, dropped.

DocxFontFaces logs under the DocxFontTable category, so the export's lines about its fonts keep the logger name they had.

Tests, the same 29, moved and not rewritten:

  • DocxSharedFontNameTest — the eleven cases of one declared name: which family keeps it, the refusal and its note, the line each family's paragraphs read, a family reached by two names writing one element.
  • DocxFontTableFixtures — the font constants, exportSetIn, and the readers of the font table and its parts that both classes use.
  • DocxFontTableTest keeps the other eighteen, in 537 lines: still over the guide, by its four cases of a family holding two typefaces, which are not moved here. Its one-paragraph exportSetIn overload is renamed exportOneFace, because a method of its own with that name would shadow the fixtures' statically imported one.

Documentation: CHANGELOG.md (2.5.2, Internal) and docs/architecture/backend-capability-details.md, which now names DocxFontFaces beside DocxFontTable and DocxFontEmbedding.

Verification

  • The DOCX fidelity corpus is the same bytes. All 105 documents, exported before (develop at b3e774d19) and after, are identical in every part, with the same 1,718 report notes (corpus-diff: unchanged).
  • ./mvnw -B -ntp test -pl :graph-compose-render-docx -am: 2,787 tests, 0 failures, 1 skipped; DocxFontTableTest ran 18 and DocxSharedFontNameTest 11, where DocxFontTableTest ran 29 before. ./mvnw -B -ntp test -f qa/pom.xml: 1,926 tests, 0 failures, 1 skipped.
  • The tests still catch what they caught. Each of six sabotages breaks one moved rule and was caught by a named failing test, in the class the test now lives in, with 29 tests run each time:
    • the shared-name refusal skipped → DocxSharedFontNameTest.twoFamiliesUnderOneNameShipOneFaceSet;
    • shipped lines stored under a name no run spells → DocxSharedFontNameTest.theFamilyThatKeepsTheNameKeepsTheLineItsParagraphsMayGrowTo;
    • the typeface read from id 1 only → DocxFontTableTest.aBundledFamilyWhoseItalicStatesAnotherFamilyRecordIsNotNamed;
    • Face.fontKey() returning another key → DocxFontTableTest.theShippedFaceIsTheRealFontBehindItsScrambledHeader;
    • a face's licence terms not read → DocxFontTableTest.aFaceThatMayNotTravelLeavesNoRequestToSaveFacesEither;
    • a face of another typeface not named → DocxFontTableTest.aFaceOfAnotherTypefaceThanTheFamilysRegularOneIsNamedAsUndrawn.
  • Full gate on 2d8dc8158: the reactor clean verify as CI runs it, the four knowledge checks, core javadoc, then install and the examples tests (93, CommittedAssetDriftTest included) — all passed.

Lane: render-docx internals, no public surface.

DocxFontTable had grown to 868 lines, against the project's 500. It
keeps the font table itself: which faces a document asks for, which
family keeps a declared name and the refusal of the one that does not,
and the parts and XML it writes (478 lines). Three package-private
classes take the rest, moved line for line:

- DocxShippedLines: the former DocxFontTable.ShippedLines;
- DocxFontFaces: the Face class and Slot enum, reading a family's faces
  and their licence terms, and the note on a face of another typeface
  than the family's regular one;
- DocxTypeface: the typeface a program states.

Face gains fontKey() and relationshipId() accessors, which the XML read
as fields while Face was nested in the table. DocxFontFaces logs under
the DocxFontTable category, as the code did before the move.

DocxFontTableTest's eleven shared-name cases move to
DocxSharedFontNameTest, and the helpers both classes use to
DocxFontTableFixtures; the eighteen others stay. 29 tests before and
after.

No behaviour change: the 105 documents of the DOCX fidelity corpus are
identical in every part, with the same 1,718 report notes.
The CHANGELOG heading said DocxFontTable no longer carried the whole of
the backend's font embedding; it never did, since DocxFontEmbedding
already held the licence bits and the obfuscation. It now says the
class is split in four.

The move was line for line apart from visibility, names, two Face
accessors and javadoc that now crosses a class; this rewraps one
javadoc paragraph in refuseForASharedName that a reference change had
left with a stranded line, and reflows the CHANGELOG entry.
@DemchaAV DemchaAV changed the title refactor(docx): split font embedding out of DocxFontTable refactor(docx): split DocxFontTable in four Nov 25, 2026
@DemchaAV
DemchaAV marked this pull request as ready for review November 25, 2026 11:46
@DemchaAV
DemchaAV merged commit bb71d58 into develop Nov 25, 2026
13 checks passed
@DemchaAV
DemchaAV deleted the refactor/docx-split-font-table branch November 25, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant