Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ follow semantic versioning; release dates are ISO 8601.
registered again, after a registration of it that travelled, is likewise told only what its
last registration lacks.

### Internal

- **`PptxRenderEnvironment` no longer carries the PPTX backend's font embedding.** Embedding had
grown into most of the class (1,426 lines), and now lives in package-private classes beside it:
`PptxDeckFonts` (which families a render carries, the viewer family a run is written with, and
the `render.pptx.font.substitution` lines), `PptxFontEmbedder` (reading a family's faces,
refusing it whole, handing the programs to the presentation, with the `embed.skipped` lines that
say why a face did not travel and the `shared.family` and `name.mismatch` lines about what it
noticed on the way), `PptxSlotLedger` (which face holds each style slot of a declared viewer
family) and the `PptxFontFace` enum the first two share. The environment keeps every public
method; the font ones delegate. No behaviour changes: decks rendered with `deterministic(...)`
are the same bytes, and the render log carries the same lines in the same order.

### Build

- **The post-release showcase restore in `cut-release.ps1` passes its `--` to git.** PowerShell
Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/backend-capability-details.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ private static Embedded declaring(List<Embedded> embedded, String wordFamily) {
*
* <p>For a free slot, what decides whether that second program is read turns out not to be how
* it is written.
* The PPTX sibling ({@code PptxRenderEnvironment.SlotLedger}) decides the same refusal per
* slot, so two families sharing a name both travel there where their slots do not clash, and
* The PPTX sibling ({@code PptxSlotLedger}) decides the same refusal per slot, so two
* families sharing a name both travel there where their slots do not clash, and
* the format would allow the same here twice over: as a second {@code w:font} element under
* the name, or as another child of the holder's element, since a {@code w:font} holds one
* child per face ({@link #toXml}). Both shapes were measured in Word 16.0.20527 and
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class PptxEmbeddedFont {
* fit, or the part comes back as {@code Buffer overrun, having 1000 bytes in the
* stream}. The second rule is the stricter — it bounds the four together where the
* first bounds them one at a time — so it is the one measured here, where a refusal is
* the checked one {@code readPrograms} already degrades a family on.</p>
* the checked one {@code PptxFontEmbedder.readPrograms} already degrades a family on.</p>
*
* <p>It has to be measured here rather than left to the readers in front of this one.
* {@code java.awt.Font.createFont}, which the viewer metrics are read through, rejects
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.demcha.compose.document.backend.fixed.pptx;

import com.demcha.compose.font.FontFamilyDefinition;

/**
* A family's four faces, as the source set names them.
*
* <p>Shared by {@link PptxDeckFonts}, which records the faces a render's runs drew, and
* {@link PptxFontEmbedder}, which reads the program each of them names.</p>
*/
enum PptxFontFace {
REGULAR, BOLD, ITALIC, BOLD_ITALIC;

static PptxFontFace of(boolean bold, boolean italic) {
if (bold && italic) {
return BOLD_ITALIC;
}
return bold ? BOLD : italic ? ITALIC : REGULAR;
}

FontFamilyDefinition.FontBinarySource in(FontFamilyDefinition.FontSourceSet sources) {
return switch (this) {
case BOLD -> sources.bold();
case ITALIC -> sources.italic();
case BOLD_ITALIC -> sources.boldItalic();
case REGULAR -> sources.regular();
};
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package com.demcha.compose.document.backend.fixed.pptx;

import com.demcha.compose.font.FontFamilyDefinition;
import com.demcha.compose.font.FontName;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
* Which face holds each style slot of each declared family name, for this render.
*
* <p>A style slot's capacity belongs to the <em>declared</em> family name rather than to
* a definition: {@code XSLFFontInfo} looks an entry up by typeface, ignoring case, so two
* definitions whose {@link FontFamilyDefinition#wordFamily()} matches that way write into
* one entry and one set of four slots. Keyed the way that lookup is, and shared across
* the whole render rather than built per definition, because the two halves of it are far
* apart: a registered family is carried while the environment is being constructed, and a
* bundled one after the last slide is drawn.</p>
*
* <p>Nothing here is claimed until the caller is about to hand a family's faces over, so
* a family whose read or whose viewer metrics refuse claims nothing: a claim is what
* stops a later family writing over a part, and it has to stand for a part that is about
* to exist. It is made before the hand-over rather than after, because a hand-over that
* fails part way through has still written what it took. What that leaves is a family the
* presentation refuses the <em>first</em> of its faces, which holds claimed slots with
* only a declaration written — and the one refusal still possible there is POI's part
* store, which no font can provoke (see {@code PptxFontEmbedder.handOverPrograms}).</p>
*/
final class PptxSlotLedger {

/**
* A face already seated in a style slot, as a refusal over that slot has to name it.
*
* <p>Its own weight, not the colliding face's: the two differ — a bold slot holding a
* 300-weight face collides with a 400-weight regular — and the weight is what a caller
* can go and look for in their font, so naming one of the two for both would send them
* after the wrong face. The italic flag is not here because the two always agree on it:
* the slot is read from the weight's side of 400 and that flag, so faces that share a
* slot share the flag.</p>
*
* <p>Not a {@link PptxFontFace}, which is the slot a family <em>registers</em> a face
* under. The slot a refusal is about is the one the container reads back as, and the whole
* of what is guarded is that the two need not agree.</p>
*
* @param family the family the face was registered under, for a refusal that
* crosses two of them. A {@link FontName}, so that two registrations
* the rest of the engine treats as one family — the name being
* case-insensitive — are one family here too
* @param description the source the face was read from, as it names itself
* @param weight that face's own weight, as the presentation reads it
*/
record Seated(FontName family, String description, int weight) {
}

/**
* One declared family name, as the first family to declare it spelled it, the face
* holding each of its four style slots, and whether the sharing of it has been
* reported.
*
* <p>Held in a list walked with {@link String#equalsIgnoreCase}, not in a map on a
* case-folded key: that operator is the one {@code XSLFFontInfo} matches an entry
* with, and a key derived here instead could disagree with it for a name where
* folding and {@code equalsIgnoreCase} part company — which would be a collision the
* deck makes and this does not see. A render declares a handful of families, so the
* walk is the cheaper half of that trade as well.</p>
*/
private static final class Declared {
private final String typeface;
private final Map<String, Seated> bySlot = new LinkedHashMap<>();
private boolean sharingReported;

private Declared(String typeface) {
this.typeface = typeface;
}
}

private final List<Declared> declared = new ArrayList<>();

/** The face holding that slot of that declared name, or {@code null}. */
Seated holderOf(String typeface, String slot) {
return entry(typeface).map(found -> found.bySlot.get(slot)).orElse(null);
}

/** Records that these faces hold these slots of that declared name. */
void claim(String typeface, Map<String, Seated> bySlot) {
entry(typeface).orElseGet(() -> {
Declared fresh = new Declared(typeface);
declared.add(fresh);
return fresh;
}).bySlot.putAll(bySlot);
}

/**
* That name as the deck declares it: the spelling of the family that declared it
* first, which is the one {@code XSLFFontInfo} writes into the entry and keeps.
*
* <p>What a line about the <em>entry</em> has to name, since a later family's own
* spelling appears nowhere in the package and would send a reader looking for a
* declaration the deck does not contain.</p>
*/
String asDeclared(String typeface) {
return entry(typeface).map(found -> found.typeface).orElse(typeface);
}

/** Whether that declared name already carries a face of another family. */
boolean alreadyDeclaredByAnother(String typeface, FontName family) {
return entry(typeface).stream()
.flatMap(found -> found.bySlot.values().stream())
.anyMatch(seated -> !seated.family().equals(family));
}

/**
* Whether the sharing of that declared name is still to be reported, marking it
* reported if so — once for the name, however many families join it.
*
* <p>Only ever asked of a name an entry already exists for, the caller having found
* another family in it first, so the flag can live on the entry.</p>
*/
boolean reportSharingOnce(String typeface) {
Optional<Declared> owed = entry(typeface).filter(found -> !found.sharingReported);
owed.ifPresent(found -> found.sharingReported = true);
return owed.isPresent();
}

private Optional<Declared> entry(String typeface) {
return declared.stream()
.filter(found -> typeface.equalsIgnoreCase(found.typeface))
.findFirst();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final class PptxFontMapping {
*
* <p>Passed by a caller that knows nothing about the family's faces — a bundled or
* standard-14 name, which no registration covers, and the geometry mirror in the tests. A
* caller that does know passes what {@code PptxRenderEnvironment} works out from the faces
* caller that does know passes what {@code PptxDeckFonts} works out from the faces
* the family carries.</p>
*/
public static final Set<String> ANY_TOKEN = Set.of("bold", "italic", "oblique");
Expand Down Expand Up @@ -203,7 +203,7 @@ public static boolean isItalic(TextStyle style, Set<String> nameMaySpeak) {
* ascent arm was not demonstrated, the line top being identical in every deck measured.</p>
*
* <p><b>And only where the family's own faces cannot say it.</b> {@code nameMaySpeak} is that
* permission, worked out by {@code PptxRenderEnvironment} from the faces a registered family
* permission, worked out by {@code PptxDeckFonts} from the faces a registered family
* carries: a family carrying two or more programs distinguishes its faces by the slot a run
* asks for, so its name says nothing and the decoration decides; a family carrying one program
* may be named only in the style that program itself is; a family carrying none has nothing but
Expand Down