reamkit 1.22.0 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/core/converter/ream.d.ts +16 -0
- package/dist/esm/core/converter/ream.js +59 -9
- package/dist/esm/core/document-model/types.d.ts +18 -0
- package/dist/esm/core/drawingml/chart-geometry.js +11 -5
- package/dist/esm/core/drawingml/colors.d.ts +4 -2
- package/dist/esm/core/drawingml/colors.js +15 -0
- package/dist/esm/core/drawingml/theme-parser.d.ts +38 -0
- package/dist/esm/core/drawingml/theme-parser.js +64 -1
- package/dist/esm/core/fonts/families.d.ts +10 -0
- package/dist/esm/core/fonts/families.js +44 -0
- package/dist/esm/core/fonts/index.d.ts +3 -2
- package/dist/esm/core/fonts/remote-fonts.d.ts +50 -0
- package/dist/esm/core/fonts/remote-fonts.js +114 -8
- package/dist/esm/core/fonts/scripts.d.ts +26 -0
- package/dist/esm/core/fonts/scripts.js +177 -0
- package/dist/esm/core/metafile/blit.d.ts +33 -0
- package/dist/esm/core/metafile/blit.js +67 -0
- package/dist/esm/core/metafile/dib.d.ts +61 -0
- package/dist/esm/core/metafile/dib.js +205 -0
- package/dist/esm/core/metafile/emf.js +137 -23
- package/dist/esm/core/metafile/picture.d.ts +12 -1
- package/dist/esm/core/metafile/wmf.js +149 -9
- package/dist/esm/core/ole/escher-blip.d.ts +12 -0
- package/dist/esm/core/ole/escher-blip.js +88 -0
- package/dist/esm/{pdf-reader → core}/png-encode.js +1 -1
- package/dist/esm/excel/print-model.js +3 -1
- package/dist/esm/excel/styles-parser.js +1 -1
- package/dist/esm/excel/xls/biff-reader.js +53 -18
- package/dist/esm/excel/xls/biff-styles.d.ts +5 -2
- package/dist/esm/excel/xls/biff-styles.js +9 -7
- package/dist/esm/excel/xls/escher.js +90 -24
- package/dist/esm/layout/page-doc.d.ts +39 -0
- package/dist/esm/layout/styled-layout.d.ts +2 -2
- package/dist/esm/layout/styled-layout.js +301 -35
- package/dist/esm/pdf/styled-page-emitter.js +35 -2
- package/dist/esm/pdf-reader/image-decode.js +1 -1
- package/dist/esm/pptx/embedded-fonts.d.ts +31 -0
- package/dist/esm/pptx/embedded-fonts.js +104 -0
- package/dist/esm/pptx/placeholder-cascade.d.ts +73 -6
- package/dist/esm/pptx/placeholder-cascade.js +114 -18
- package/dist/esm/pptx/ppt/ppt-reader.js +120 -10
- package/dist/esm/pptx/ppt/ppt-text.d.ts +66 -1
- package/dist/esm/pptx/ppt/ppt-text.js +576 -137
- package/dist/esm/pptx/pptx-reader.d.ts +8 -0
- package/dist/esm/pptx/pptx-reader.js +27 -5
- package/dist/esm/pptx/preset-table-styles.d.ts +9 -0
- package/dist/esm/pptx/preset-table-styles.js +27 -0
- package/dist/esm/pptx/slide-parser.d.ts +7 -1
- package/dist/esm/pptx/slide-parser.js +106 -33
- package/dist/esm/pptx/sp-helpers.d.ts +2 -1
- package/dist/esm/pptx/sp-helpers.js +3 -2
- package/dist/esm/pptx/table-style.d.ts +9 -1
- package/dist/esm/pptx/table-style.js +49 -7
- package/dist/esm/word/document-parser.d.ts +7 -1
- package/dist/esm/word/document-parser.js +6 -6
- package/dist/esm/word/docx-reader.js +6 -3
- package/dist/esm/word/docx-to-pdf.d.ts +8 -7
- package/dist/esm/word/docx-to-pdf.js +25 -7
- package/dist/esm/word/drawing-parser.js +31 -19
- package/dist/esm/word/numbering-parser.d.ts +2 -1
- package/dist/esm/word/numbering-parser.js +6 -6
- package/dist/esm/word/paragraph-properties.d.ts +2 -1
- package/dist/esm/word/paragraph-properties.js +2 -2
- package/dist/esm/word/run-properties.d.ts +5 -2
- package/dist/esm/word/run-properties.js +13 -8
- package/dist/esm/word/styles-parser.d.ts +2 -1
- package/dist/esm/word/styles-parser.js +12 -12
- package/dist/esm/word/table-parser.js +3 -3
- package/dist/esm/word/theme-fonts.d.ts +10 -0
- package/dist/esm/word/theme-fonts.js +28 -0
- package/package.json +1 -1
- /package/dist/esm/{pdf-reader → core}/png-encode.d.ts +0 -0
|
@@ -2,6 +2,7 @@ import { BodyElement, Comment, RunProperties, Section, SectionProperties, ShapeF
|
|
|
2
2
|
import { ColorResolver } from '../core/drawingml/colors.js';
|
|
3
3
|
import { Loss, ResourceId } from '../core/ir/index.js';
|
|
4
4
|
import { PoNode } from '../core/po-helpers.js';
|
|
5
|
+
import { ThemeFonts } from '../core/drawingml/theme-parser.js';
|
|
5
6
|
import { ThemeStyles } from './drawing-parser.js';
|
|
6
7
|
/**
|
|
7
8
|
* Resolves a drawing relationship id to a content-addressed `ResourceId` —
|
|
@@ -57,6 +58,11 @@ export interface ParseContext {
|
|
|
57
58
|
* the shadow a gallery-drawn shape wears.
|
|
58
59
|
*/
|
|
59
60
|
readonly themeStyles?: ThemeStyles;
|
|
61
|
+
/**
|
|
62
|
+
* §20.1.4.1.16 — the theme's font scheme, for the typefaces a run names by
|
|
63
|
+
* slot (`w:asciiTheme="minorHAnsi"`) rather than by name.
|
|
64
|
+
*/
|
|
65
|
+
readonly themeFonts?: ThemeFonts;
|
|
60
66
|
/**
|
|
61
67
|
* Sink for graceful-degradation notices (E-SMARTART SA3): a SmartArt with no
|
|
62
68
|
* drawing override records a dropped-feature {@link Loss} rather than vanishing.
|
|
@@ -185,7 +191,7 @@ export declare function parseBodyElements(children: ReadonlyArray<PoNode>, ctx?:
|
|
|
185
191
|
* @param sdt The `w:sdt` element.
|
|
186
192
|
* @returns The properties, or `undefined` when the control states none.
|
|
187
193
|
*/
|
|
188
|
-
export declare function sdtRunProperties(sdt: PoNode): RunProperties | undefined;
|
|
194
|
+
export declare function sdtRunProperties(sdt: PoNode, themeFonts?: ThemeFonts): RunProperties | undefined;
|
|
189
195
|
/**
|
|
190
196
|
* Parse `footnotes.xml` / `endnotes.xml` (§17.11) into note content by id. The
|
|
191
197
|
* separator / continuationSeparator / continuationNotice stubs (negative ids or
|
|
@@ -425,7 +425,7 @@ function tryExtractDrawingFromParagraph(p, ctx) {
|
|
|
425
425
|
if (!vml && drawings.every((d) => poChildren(d).some((c) => poIs(c, "wp:anchor")))) return null;
|
|
426
426
|
const parseBody = (children) => parseBodyElements(children, ctx);
|
|
427
427
|
const pPrNode = poChildren(p).find((c) => poIs(c, "w:pPr"));
|
|
428
|
-
const paragraphProperties = pPrNode ? parseParagraphProperties(poElementToFlat(pPrNode), ctx.autoSpacingPt) : {};
|
|
428
|
+
const paragraphProperties = pPrNode ? parseParagraphProperties(poElementToFlat(pPrNode), ctx.autoSpacingPt, ctx.themeFonts) : {};
|
|
429
429
|
if (drawings.length === 0) {
|
|
430
430
|
const content = parseVmlPicture(vml, parseBody);
|
|
431
431
|
if (!content) return null;
|
|
@@ -536,7 +536,7 @@ function parseParagraph(p, ctx, extraBookmarks, anchored, sdtRunProps) {
|
|
|
536
536
|
if (bookmarkName !== void 0 && bookmarkName !== "" && bookmarkName !== "_GoBack") bookmarks.push(bookmarkName);
|
|
537
537
|
}
|
|
538
538
|
const pPr = poChildren(p).find((c) => poIs(c, "w:pPr"));
|
|
539
|
-
let properties = parseParagraphProperties(pPr ? poElementToFlat(pPr) : void 0, ctx.autoSpacingPt);
|
|
539
|
+
let properties = parseParagraphProperties(pPr ? poElementToFlat(pPr) : void 0, ctx.autoSpacingPt, ctx.themeFonts);
|
|
540
540
|
if (pPr && poChildren(pPr).some((c) => poIs(c, "w:sectPr"))) properties = {
|
|
541
541
|
...properties,
|
|
542
542
|
sectionBreak: true
|
|
@@ -773,7 +773,7 @@ function collectRuns(container, out, ctx, href, anchor, anchored, sdtRunProps) {
|
|
|
773
773
|
if (bookmark !== void 0 && bookmark !== "") childAnchor = bookmark;
|
|
774
774
|
}
|
|
775
775
|
}
|
|
776
|
-
const childProps = tag === "w:sdt" ? sdtRunProperties(child) ?? sdtRunProps : sdtRunProps;
|
|
776
|
+
const childProps = tag === "w:sdt" ? sdtRunProperties(child, ctx.themeFonts) ?? sdtRunProps : sdtRunProps;
|
|
777
777
|
collectRuns(child, out, ctx, childHref, childAnchor, anchored, childProps);
|
|
778
778
|
}
|
|
779
779
|
}
|
|
@@ -785,11 +785,11 @@ function collectRuns(container, out, ctx, href, anchor, anchored, sdtRunProps) {
|
|
|
785
785
|
* @param sdt The `w:sdt` element.
|
|
786
786
|
* @returns The properties, or `undefined` when the control states none.
|
|
787
787
|
*/
|
|
788
|
-
function sdtRunProperties(sdt) {
|
|
788
|
+
function sdtRunProperties(sdt, themeFonts) {
|
|
789
789
|
const sdtPr = poChildren(sdt).find((c) => poIs(c, "w:sdtPr"));
|
|
790
790
|
const rPr = sdtPr ? poChildren(sdtPr).find((c) => poIs(c, "w:rPr")) : void 0;
|
|
791
791
|
if (!rPr) return void 0;
|
|
792
|
-
const props = parseRunProperties(poElementToFlat(rPr));
|
|
792
|
+
const props = parseRunProperties(poElementToFlat(rPr), themeFonts);
|
|
793
793
|
return Object.keys(props).length > 0 ? props : void 0;
|
|
794
794
|
}
|
|
795
795
|
var WINGDINGS_TO_UNICODE = new Map([
|
|
@@ -870,7 +870,7 @@ function symbolChar(font, char) {
|
|
|
870
870
|
}
|
|
871
871
|
function parseRun(r, ctx, anchored) {
|
|
872
872
|
const rPr = poChildren(r).find((c) => poIs(c, "w:rPr"));
|
|
873
|
-
const properties = parseRunProperties(rPr ? poElementToFlat(rPr) : void 0);
|
|
873
|
+
const properties = parseRunProperties(rPr ? poElementToFlat(rPr) : void 0, ctx.themeFonts);
|
|
874
874
|
let text = "";
|
|
875
875
|
let pageBreak = false;
|
|
876
876
|
let columnBreak = false;
|
|
@@ -9,7 +9,7 @@ import { poFindDescendant } from "../core/po-helpers.js";
|
|
|
9
9
|
import { packageHasPart } from "../core/bytes.js";
|
|
10
10
|
import { DEFAULT_THEME_PALETTE, makeColorResolver } from "../core/drawingml/colors.js";
|
|
11
11
|
import { parseChart, withChartColorStyle } from "../core/drawingml/chart-parser.js";
|
|
12
|
-
import { parseTheme, parseThemeBgFillStyles, parseThemeEffectStyles, parseThemeFillStyles, parseThemeLineWidths } from "../core/drawingml/theme-parser.js";
|
|
12
|
+
import { parseTheme, parseThemeBgFillStyles, parseThemeEffectStyles, parseThemeFillStyles, parseThemeFonts, parseThemeLineWidths } from "../core/drawingml/theme-parser.js";
|
|
13
13
|
import { isOoxmlRel } from "../core/opc/relationship-types.js";
|
|
14
14
|
import { OpcPackage } from "../core/opc/package.js";
|
|
15
15
|
import { parseCoreProperties } from "../core/opc/core-properties.js";
|
|
@@ -52,6 +52,7 @@ function readDocx(docx) {
|
|
|
52
52
|
const resolveColor = buildColorResolver(pkg, main.path);
|
|
53
53
|
const themeData = loadTheme(pkg, main.path);
|
|
54
54
|
const themeLineWidths = themeData ? parseThemeLineWidths(themeData) : void 0;
|
|
55
|
+
const themeFonts = themeData ? parseThemeFonts(themeData) : void 0;
|
|
55
56
|
const themeStyles = themeData ? {
|
|
56
57
|
fills: parseThemeFillStyles(themeData),
|
|
57
58
|
bgFills: parseThemeBgFillStyles(themeData),
|
|
@@ -68,6 +69,7 @@ function readDocx(docx) {
|
|
|
68
69
|
...settings.compatibilityMode === void 0 ? { autoSpacingPt: 14 } : {},
|
|
69
70
|
...themeLineWidths && themeLineWidths.length > 0 ? { themeLineWidths } : {},
|
|
70
71
|
...themeStyles ? { themeStyles } : {},
|
|
72
|
+
...themeFonts ? { themeFonts } : {},
|
|
71
73
|
resolveImage,
|
|
72
74
|
resolveHyperlink,
|
|
73
75
|
resolveDiagram: makeDiagramResolver(pkg, main.path, resources),
|
|
@@ -84,11 +86,12 @@ function readDocx(docx) {
|
|
|
84
86
|
endIndex: bodyIndexForBlock(blocks, s.endIndex)
|
|
85
87
|
}));
|
|
86
88
|
const stylesData = pkg.getPart(STYLES_PART);
|
|
87
|
-
const styles = stylesData ? parseStyles(stylesData) : EMPTY_STYLE_SHEET;
|
|
89
|
+
const styles = stylesData ? parseStyles(stylesData, themeFonts) : EMPTY_STYLE_SHEET;
|
|
88
90
|
const numberingData = pkg.getPart(NUMBERING_PART);
|
|
89
|
-
const numbering = numberingData ? parseNumbering(numberingData, makeImageResolver(pkg, resources, NUMBERING_PART)) : EMPTY_NUMBERING;
|
|
91
|
+
const numbering = numberingData ? parseNumbering(numberingData, makeImageResolver(pkg, resources, NUMBERING_PART), themeFonts) : EMPTY_NUMBERING;
|
|
90
92
|
const noteCtx = (part) => ({
|
|
91
93
|
resolveColor,
|
|
94
|
+
...themeFonts ? { themeFonts } : {},
|
|
92
95
|
resolveImage: makeImageResolver(pkg, resources, part),
|
|
93
96
|
resolveHyperlink: makeHyperlinkResolver(pkg, part)
|
|
94
97
|
});
|
|
@@ -38,10 +38,11 @@ export interface ConvertDocxOptions extends Omit<StyledRenderOptions, 'registry'
|
|
|
38
38
|
*/
|
|
39
39
|
export declare function convertDocxToPdfSync(docx: Uint8Array, options: ConvertDocxOptions): Uint8Array;
|
|
40
40
|
/**
|
|
41
|
-
* The distinct curated font families the document references
|
|
42
|
-
* `
|
|
43
|
-
* `'arimo'` as a fallback for
|
|
44
|
-
*
|
|
41
|
+
* The distinct curated font families the document references — the `w:ascii` of
|
|
42
|
+
* `styles.xml` + `document.xml`, and the theme slots they point at instead
|
|
43
|
+
* (§17.3.2.26) — always including the sans default `'arimo'` as a fallback for
|
|
44
|
+
* unstyled runs / math / charts. The async path fetches one substitute set per
|
|
45
|
+
* family so each run renders in the right one.
|
|
45
46
|
*
|
|
46
47
|
* @param docx The `.docx` bytes.
|
|
47
48
|
* @returns The resolved {@link FamilyKey} set; just the default when the package
|
|
@@ -76,9 +77,9 @@ export declare function resolveDocxAutoFonts(docx: Uint8Array, options?: {
|
|
|
76
77
|
}>;
|
|
77
78
|
/**
|
|
78
79
|
* Best-effort detection of the document's primary font family, used to choose a
|
|
79
|
-
* substitute for auto-download. Prefers the document defaults'
|
|
80
|
-
*
|
|
81
|
-
* need to fully parse for this hint.
|
|
80
|
+
* substitute for auto-download. Prefers the document defaults' font — spelled
|
|
81
|
+
* out or pointed at in the theme — then falls back to the most frequent run
|
|
82
|
+
* font. A cheap regex over the XML: no need to fully parse for this hint.
|
|
82
83
|
*
|
|
83
84
|
* @param docx The `.docx` bytes.
|
|
84
85
|
* @returns The detected family name, or `undefined` when none is found.
|
|
@@ -3,12 +3,15 @@ import { FontRegistry } from "../core/font/font-registry.js";
|
|
|
3
3
|
import { signPdf } from "../pdf/signature.js";
|
|
4
4
|
import { renderStyledPdf, renderStyledPdfEncrypted } from "../pdf/styled-page-renderer.js";
|
|
5
5
|
import "../pdf/index.js";
|
|
6
|
+
import { parseThemeFonts } from "../core/drawingml/theme-parser.js";
|
|
6
7
|
import { OpcPackage } from "../core/opc/package.js";
|
|
7
8
|
import "../core/opc/index.js";
|
|
9
|
+
import { resolveWordThemeFont } from "./theme-fonts.js";
|
|
8
10
|
import { readDocx } from "./docx-reader.js";
|
|
9
11
|
import { flowRenderOptions } from "../core/converter/project.js";
|
|
10
12
|
//#region src/word/docx-to-pdf.ts
|
|
11
13
|
var STYLES_PART = "word/styles.xml";
|
|
14
|
+
var THEME_PART = "word/theme/theme1.xml";
|
|
12
15
|
var MAIN_DOCUMENT_PART = "word/document.xml";
|
|
13
16
|
/**
|
|
14
17
|
* Synchronous one-shot conversion (requires `fonts`/`fontBytes`, no network).
|
|
@@ -49,10 +52,11 @@ function prepareDocxStyledRender(docx, options) {
|
|
|
49
52
|
};
|
|
50
53
|
}
|
|
51
54
|
/**
|
|
52
|
-
* The distinct curated font families the document references
|
|
53
|
-
* `
|
|
54
|
-
* `'arimo'` as a fallback for
|
|
55
|
-
*
|
|
55
|
+
* The distinct curated font families the document references — the `w:ascii` of
|
|
56
|
+
* `styles.xml` + `document.xml`, and the theme slots they point at instead
|
|
57
|
+
* (§17.3.2.26) — always including the sans default `'arimo'` as a fallback for
|
|
58
|
+
* unstyled runs / math / charts. The async path fetches one substitute set per
|
|
59
|
+
* family so each run renders in the right one.
|
|
56
60
|
*
|
|
57
61
|
* @param docx The `.docx` bytes.
|
|
58
62
|
* @returns The resolved {@link FamilyKey} set; just the default when the package
|
|
@@ -67,16 +71,30 @@ function detectDocxFamilyKeys(docx) {
|
|
|
67
71
|
return keys;
|
|
68
72
|
}
|
|
69
73
|
const decoder = new TextDecoder("utf-8");
|
|
70
|
-
const
|
|
74
|
+
const themeFonts = docxThemeFonts(pkg);
|
|
75
|
+
const re = /<w:rFonts[^>]*?\bw:(ascii|asciiTheme)="([^"]+)"/g;
|
|
71
76
|
for (const part of [STYLES_PART, MAIN_DOCUMENT_PART]) {
|
|
72
77
|
const data = pkg.getPart(part);
|
|
73
78
|
if (!data) continue;
|
|
74
79
|
const xml = decoder.decode(data);
|
|
75
80
|
let m;
|
|
76
|
-
while ((m = re.exec(xml)) !== null)
|
|
81
|
+
while ((m = re.exec(xml)) !== null) {
|
|
82
|
+
const name = m[1] === "ascii" ? m[2] : resolveWordThemeFont(m[2], themeFonts);
|
|
83
|
+
if (name !== void 0) keys.add(resolveFamilyKey(name));
|
|
84
|
+
}
|
|
77
85
|
}
|
|
78
86
|
return keys;
|
|
79
87
|
}
|
|
88
|
+
/** §20.1.4.1.16 — the theme's font scheme, for the slots `w:rFonts` points at. */
|
|
89
|
+
function docxThemeFonts(pkg) {
|
|
90
|
+
const data = pkg.getPart(THEME_PART);
|
|
91
|
+
if (!data) return void 0;
|
|
92
|
+
try {
|
|
93
|
+
return parseThemeFonts(data);
|
|
94
|
+
} catch {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
80
98
|
/**
|
|
81
99
|
* One-shot .docx → PDF (auto-downloads a substitute font set when the caller
|
|
82
100
|
* supplies none; zero network with `fonts`/`fontBytes`).
|
|
@@ -140,4 +158,4 @@ async function resolveDocxAutoFonts(docx, options = {}) {
|
|
|
140
158
|
};
|
|
141
159
|
}
|
|
142
160
|
//#endregion
|
|
143
|
-
export { convertDocxToPdf
|
|
161
|
+
export { convertDocxToPdf };
|
|
@@ -1818,7 +1818,9 @@ function fillFromNode(child, resolveColor, resolveImage) {
|
|
|
1818
1818
|
const crop = parseSrcRect(poFindDescendant(child, "a:srcRect")) ?? fillRectCrop(child);
|
|
1819
1819
|
const rect = fillRectBox(child);
|
|
1820
1820
|
const duotone = blip ? duotoneOf(blip, resolveColor) : void 0;
|
|
1821
|
-
const
|
|
1821
|
+
const tile = poChildren(child).find((c) => poIs(c, "a:tile"));
|
|
1822
|
+
const tiled = tile !== void 0;
|
|
1823
|
+
const tileScale = tile ? tileScaleOf(tile) : void 0;
|
|
1822
1824
|
const fixed = blip ? poChildren(blip).find((c) => poIs(c, "a:alphaModFix")) : void 0;
|
|
1823
1825
|
const amt = fixed ? poIntAttr(fixed, "amt") : void 0;
|
|
1824
1826
|
const alpha = amt === void 0 ? void 0 : Math.min(1, Math.max(0, amt / 1e5));
|
|
@@ -1826,6 +1828,7 @@ function fillFromNode(child, resolveColor, resolveImage) {
|
|
|
1826
1828
|
kind: "picture",
|
|
1827
1829
|
imageResource: resource,
|
|
1828
1830
|
...tiled ? { tiled: true } : {},
|
|
1831
|
+
...tileScale ? { tileScale } : {},
|
|
1829
1832
|
...crop ? { imageCrop: crop } : {},
|
|
1830
1833
|
...rect ? { imageFillRect: rect } : {},
|
|
1831
1834
|
...duotone ? { duotone } : {},
|
|
@@ -1997,6 +2000,18 @@ function duotoneOf(blip, resolveColor) {
|
|
|
1997
2000
|
* @returns The rect as fractions of the box, or `undefined` when every inset
|
|
1998
2001
|
* is zero or negative.
|
|
1999
2002
|
*/
|
|
2003
|
+
function tileScaleOf(tile) {
|
|
2004
|
+
const pct = (name) => {
|
|
2005
|
+
const v = poIntAttr(tile, name);
|
|
2006
|
+
return v === void 0 || v <= 0 ? 1 : v / 1e5;
|
|
2007
|
+
};
|
|
2008
|
+
const sx = pct("sx");
|
|
2009
|
+
const sy = pct("sy");
|
|
2010
|
+
return sx === 1 && sy === 1 ? void 0 : {
|
|
2011
|
+
sx,
|
|
2012
|
+
sy
|
|
2013
|
+
};
|
|
2014
|
+
}
|
|
2000
2015
|
function fillRectBox(blipFill) {
|
|
2001
2016
|
const stretch = poChildren(blipFill).find((c) => poIs(c, "a:stretch"));
|
|
2002
2017
|
const rect = stretch ? poChildren(stretch).find((c) => poIs(c, "a:fillRect")) : void 0;
|
|
@@ -2047,14 +2062,15 @@ function shadowFromOuterShdw(shdw, resolveColor) {
|
|
|
2047
2062
|
const colorHex = colorNode ? resolveColorNode(colorNode, resolveColor) : void 0;
|
|
2048
2063
|
if (!colorHex) return void 0;
|
|
2049
2064
|
const alphaMod = colorNode ? readColorMods(colorNode).find((m) => m.kind === "alpha") : void 0;
|
|
2065
|
+
const alpha = alphaMod ? alphaMod.val : 1;
|
|
2050
2066
|
const dist = emuToPt(poIntAttr(shdw, "dist") ?? 0);
|
|
2051
2067
|
const rad = (poIntAttr(shdw, "dir") ?? 0) / 6e4 * Math.PI / 180;
|
|
2052
2068
|
return {
|
|
2053
2069
|
dxPt: dist * Math.cos(rad),
|
|
2054
2070
|
dyPt: dist * Math.sin(rad),
|
|
2055
2071
|
blurPt: emuToPt(poIntAttr(shdw, "blurRad") ?? 0),
|
|
2056
|
-
colorHex,
|
|
2057
|
-
alpha
|
|
2072
|
+
colorHex: alpha < 1 ? unblendWhite(colorHex, alpha) : colorHex,
|
|
2073
|
+
alpha
|
|
2058
2074
|
};
|
|
2059
2075
|
}
|
|
2060
2076
|
/**
|
|
@@ -2203,25 +2219,21 @@ function colorFromContainer(parent, resolveColor) {
|
|
|
2203
2219
|
/**
|
|
2204
2220
|
* §20.1.2.3.1 — a gradient's stop transparencies, settled.
|
|
2205
2221
|
*
|
|
2206
|
-
*
|
|
2207
|
-
*
|
|
2208
|
-
*
|
|
2209
|
-
*
|
|
2210
|
-
*
|
|
2222
|
+
* The resolver composites a translucent colour over the PAPER, because a solid
|
|
2223
|
+
* fill has nowhere else to put the transparency. A gradient does: its stops
|
|
2224
|
+
* become a luminosity soft mask of the same sweep (§11.6.5.2,
|
|
2225
|
+
* `buildGradientAlphaMask`), so each stop keeps its own alpha and its own
|
|
2226
|
+
* colour, and the mask decides what shows through.
|
|
2211
2227
|
*
|
|
2212
|
-
*
|
|
2213
|
-
*
|
|
2214
|
-
*
|
|
2215
|
-
*
|
|
2228
|
+
* That means the washing has to be undone here, on every stop — including the
|
|
2229
|
+
* opaque ones, where undoing it is a no-op. It used to be undone only when
|
|
2230
|
+
* EVERY stop was translucent, on the reasoning that a page paints a gradient at
|
|
2231
|
+
* one transparency; the mask makes that false, and the cost of the old reading
|
|
2232
|
+
* was a band that should have been half-transparent over a blue slide drawn as
|
|
2233
|
+
* an opaque pale stripe (45541's layout fades the middle of its left rule to
|
|
2234
|
+
* 50 %).
|
|
2216
2235
|
*/
|
|
2217
2236
|
function normalizeStopAlpha(stops) {
|
|
2218
|
-
if (gradientAlpha(stops) === void 0) {
|
|
2219
|
-
for (const [i, s] of stops.entries()) if (s.alpha !== void 0) stops[i] = {
|
|
2220
|
-
offset: s.offset,
|
|
2221
|
-
colorHex: s.colorHex
|
|
2222
|
-
};
|
|
2223
|
-
return;
|
|
2224
|
-
}
|
|
2225
2237
|
for (const [i, s] of stops.entries()) stops[i] = {
|
|
2226
2238
|
...s,
|
|
2227
2239
|
colorHex: unblendWhite(s.colorHex, s.alpha ?? 1)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Numbering } from '../core/document-model/index.js';
|
|
2
2
|
import { ResourceId } from '../core/ir/index.js';
|
|
3
|
+
import { ThemeFonts } from '../core/drawingml/theme-parser.js';
|
|
3
4
|
/** The empty {@link Numbering} returned when a document has no `numbering.xml`. */
|
|
4
5
|
export declare const EMPTY_NUMBERING: Numbering;
|
|
5
6
|
/**
|
|
@@ -12,4 +13,4 @@ export declare const EMPTY_NUMBERING: Numbering;
|
|
|
12
13
|
* @param data The raw `numbering.xml` bytes.
|
|
13
14
|
* @returns The parsed numbering, or {@link EMPTY_NUMBERING} when the root is absent.
|
|
14
15
|
*/
|
|
15
|
-
export declare function parseNumbering(data: Uint8Array, resolveImage?: (relId: string) => ResourceId | undefined): Numbering;
|
|
16
|
+
export declare function parseNumbering(data: Uint8Array, resolveImage?: (relId: string) => ResourceId | undefined, themeFonts?: ThemeFonts): Numbering;
|
|
@@ -56,7 +56,7 @@ var EMPTY_NUMBERING = {
|
|
|
56
56
|
* @param data The raw `numbering.xml` bytes.
|
|
57
57
|
* @returns The parsed numbering, or {@link EMPTY_NUMBERING} when the root is absent.
|
|
58
58
|
*/
|
|
59
|
-
function parseNumbering(data, resolveImage) {
|
|
59
|
+
function parseNumbering(data, resolveImage, themeFonts) {
|
|
60
60
|
const xml = decoder.decode(data);
|
|
61
61
|
const root = asElement(parser.parse(xml)["w:numbering"]);
|
|
62
62
|
if (!root) return EMPTY_NUMBERING;
|
|
@@ -69,7 +69,7 @@ function parseNumbering(data, resolveImage) {
|
|
|
69
69
|
if (!id) continue;
|
|
70
70
|
const levels = /* @__PURE__ */ new Map();
|
|
71
71
|
for (const lvlNode of asArray(el["w:lvl"])) {
|
|
72
|
-
const lvl = parseLevel(lvlNode, picBullets);
|
|
72
|
+
const lvl = parseLevel(lvlNode, picBullets, themeFonts);
|
|
73
73
|
if (lvl) levels.set(lvl.ilvl, lvl);
|
|
74
74
|
}
|
|
75
75
|
abstractNums.set(id, {
|
|
@@ -94,7 +94,7 @@ function parseNumbering(data, resolveImage) {
|
|
|
94
94
|
if (!Number.isFinite(ilvl)) continue;
|
|
95
95
|
const start = Number(getValVal(ovr["w:startOverride"]));
|
|
96
96
|
if (Number.isFinite(start)) startOverrides.set(ilvl, start);
|
|
97
|
-
const lvl = parseLevel(ovr["w:lvl"], picBullets);
|
|
97
|
+
const lvl = parseLevel(ovr["w:lvl"], picBullets, themeFonts);
|
|
98
98
|
if (lvl) levelOverrides.set(ilvl, lvl);
|
|
99
99
|
}
|
|
100
100
|
numInstances.set(numId, {
|
|
@@ -109,7 +109,7 @@ function parseNumbering(data, resolveImage) {
|
|
|
109
109
|
numInstances
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
-
function parseLevel(node, picBullets) {
|
|
112
|
+
function parseLevel(node, picBullets, themeFonts) {
|
|
113
113
|
const lvlEl = asElement(node);
|
|
114
114
|
if (!lvlEl) return void 0;
|
|
115
115
|
const ilvlStr = getAttr(lvlEl, "ilvl");
|
|
@@ -131,8 +131,8 @@ function parseLevel(node, picBullets) {
|
|
|
131
131
|
lvlText,
|
|
132
132
|
...isLegal ? { isLegal: true } : {},
|
|
133
133
|
...picBullet ? { picBullet } : {},
|
|
134
|
-
paragraphProperties: parseParagraphProperties(lvlEl["w:pPr"]),
|
|
135
|
-
runProperties: parseRunProperties(lvlEl["w:rPr"])
|
|
134
|
+
paragraphProperties: parseParagraphProperties(lvlEl["w:pPr"], 0, themeFonts),
|
|
135
|
+
runProperties: parseRunProperties(lvlEl["w:rPr"], themeFonts)
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
138
|
function parsePicBullets(root, resolveImage) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ParagraphProperties } from '../core/document-model/index.js';
|
|
2
|
+
import { ThemeFonts } from '../core/drawingml/theme-parser.js';
|
|
2
3
|
/**
|
|
3
4
|
* §17.3.1.1/§17.3.1.3 — the gap `w:*Autospacing` asks the consumer for. Word's
|
|
4
5
|
* own automatic value is HTML's 14pt, and only a document old enough to state
|
|
@@ -19,4 +20,4 @@ export declare const HTML_AUTO_SPACING_PT = 14;
|
|
|
19
20
|
* compatibility mode, and 0 (the default) for every Word 2007-or-later one.
|
|
20
21
|
* @returns The extracted properties; an empty object when `pPr` is absent.
|
|
21
22
|
*/
|
|
22
|
-
export declare function parseParagraphProperties(pPr: unknown, autoSpacingPt?: number): ParagraphProperties;
|
|
23
|
+
export declare function parseParagraphProperties(pPr: unknown, autoSpacingPt?: number, themeFonts?: ThemeFonts): ParagraphProperties;
|
|
@@ -104,7 +104,7 @@ function parseFramePr(node) {
|
|
|
104
104
|
* compatibility mode, and 0 (the default) for every Word 2007-or-later one.
|
|
105
105
|
* @returns The extracted properties; an empty object when `pPr` is absent.
|
|
106
106
|
*/
|
|
107
|
-
function parseParagraphProperties(pPr, autoSpacingPt = 0) {
|
|
107
|
+
function parseParagraphProperties(pPr, autoSpacingPt = 0, themeFonts) {
|
|
108
108
|
const el = asElement(pPr);
|
|
109
109
|
if (!el) return {};
|
|
110
110
|
const out = {};
|
|
@@ -197,7 +197,7 @@ function parseParagraphProperties(pPr, autoSpacingPt = 0) {
|
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
if ("w:rPr" in el) {
|
|
200
|
-
const rPr = parseRunProperties(el["w:rPr"]);
|
|
200
|
+
const rPr = parseRunProperties(el["w:rPr"], themeFonts);
|
|
201
201
|
if (Object.keys(rPr).length > 0) out.runProperties = rPr;
|
|
202
202
|
}
|
|
203
203
|
return out;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RunProperties } from '../core/document-model/index.js';
|
|
2
|
+
import { ThemeFonts } from '../core/drawingml/theme-parser.js';
|
|
2
3
|
/**
|
|
3
4
|
* Parse a run-properties element (`w:rPr`, ECMA-376 Part 1 §17.3.2) into the
|
|
4
5
|
* typed {@link RunProperties}. Reads the character formatting the renderer needs:
|
|
@@ -6,7 +7,9 @@ import { RunProperties } from '../core/document-model/index.js';
|
|
|
6
7
|
* font family map, vertical alignment, RTL, and language; sizes convert from
|
|
7
8
|
* half-points to points and colours normalize to uppercase hex.
|
|
8
9
|
*
|
|
9
|
-
* @param rPr
|
|
10
|
+
* @param rPr The flat-tree `w:rPr` element (or `undefined`/non-element).
|
|
11
|
+
* @param themeFonts The document theme's font scheme, for the fonts a run names
|
|
12
|
+
* by slot rather than by name (§17.3.2.26 `w:asciiTheme`).
|
|
10
13
|
* @returns The parsed properties; an empty object when `rPr` is absent.
|
|
11
14
|
*/
|
|
12
|
-
export declare function parseRunProperties(rPr: unknown): RunProperties;
|
|
15
|
+
export declare function parseRunProperties(rPr: unknown, themeFonts?: ThemeFonts): RunProperties;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { halfPtToPt, twipsToPt } from "../core/ir/units.js";
|
|
2
|
+
import { resolveThemeFont } from "../core/drawingml/theme-parser.js";
|
|
2
3
|
import { asElement, getAttr, getVal, parseHalfPointAttr, parseToggle } from "./xml-helpers.js";
|
|
4
|
+
import { resolveWordThemeFont } from "./theme-fonts.js";
|
|
3
5
|
import { shadingFillHex } from "./shading.js";
|
|
4
6
|
//#region src/word/run-properties.ts
|
|
5
7
|
var UNDERLINE_STYLES = new Set([
|
|
@@ -43,10 +45,12 @@ var HIGHLIGHT_COLORS = new Map([
|
|
|
43
45
|
* font family map, vertical alignment, RTL, and language; sizes convert from
|
|
44
46
|
* half-points to points and colours normalize to uppercase hex.
|
|
45
47
|
*
|
|
46
|
-
* @param rPr
|
|
48
|
+
* @param rPr The flat-tree `w:rPr` element (or `undefined`/non-element).
|
|
49
|
+
* @param themeFonts The document theme's font scheme, for the fonts a run names
|
|
50
|
+
* by slot rather than by name (§17.3.2.26 `w:asciiTheme`).
|
|
47
51
|
* @returns The parsed properties; an empty object when `rPr` is absent.
|
|
48
52
|
*/
|
|
49
|
-
function parseRunProperties(rPr) {
|
|
53
|
+
function parseRunProperties(rPr, themeFonts) {
|
|
50
54
|
const el = asElement(rPr);
|
|
51
55
|
if (!el) return {};
|
|
52
56
|
const out = {};
|
|
@@ -90,7 +94,7 @@ function parseRunProperties(rPr) {
|
|
|
90
94
|
else if (v === "auto") out.colorHex = "000000";
|
|
91
95
|
}
|
|
92
96
|
if ("w:rFonts" in el) {
|
|
93
|
-
const ff = parseFontFamily(el["w:rFonts"]);
|
|
97
|
+
const ff = parseFontFamily(el["w:rFonts"], themeFonts);
|
|
94
98
|
if (ff) out.fontFamily = ff;
|
|
95
99
|
}
|
|
96
100
|
if ("w:vertAlign" in el) {
|
|
@@ -121,12 +125,13 @@ function parseRunProperties(rPr) {
|
|
|
121
125
|
}
|
|
122
126
|
return out;
|
|
123
127
|
}
|
|
124
|
-
function parseFontFamily(node) {
|
|
128
|
+
function parseFontFamily(node, themeFonts) {
|
|
125
129
|
const ff = {};
|
|
126
|
-
const
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
+
const slot = (literal, theme) => resolveThemeFont(getAttr(node, literal), themeFonts) ?? resolveWordThemeFont(getAttr(node, theme), themeFonts);
|
|
131
|
+
const ascii = slot("ascii", "asciiTheme");
|
|
132
|
+
const hAnsi = slot("hAnsi", "hAnsiTheme");
|
|
133
|
+
const cs = slot("cs", "cstheme");
|
|
134
|
+
const eastAsia = slot("eastAsia", "eastAsiaTheme");
|
|
130
135
|
if (ascii) ff.ascii = ascii;
|
|
131
136
|
if (hAnsi) ff.hAnsi = hAnsi;
|
|
132
137
|
if (cs) ff.cs = cs;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { StyleSheet } from '../core/document-model/index.js';
|
|
2
|
+
import { ThemeFonts } from '../core/drawingml/theme-parser.js';
|
|
2
3
|
/**
|
|
3
4
|
* Parse `word/styles.xml` (ECMA-376 Part 1 §17.7) into a {@link StyleSheet}: the
|
|
4
5
|
* document defaults (`w:docDefaults` run/paragraph properties) plus the named
|
|
@@ -9,4 +10,4 @@ import { StyleSheet } from '../core/document-model/index.js';
|
|
|
9
10
|
* @param stylesXml The raw `styles.xml` bytes.
|
|
10
11
|
* @returns The parsed stylesheet, or `EMPTY_STYLE_SHEET` when the root is absent.
|
|
11
12
|
*/
|
|
12
|
-
export declare function parseStyles(stylesXml: Uint8Array): StyleSheet;
|
|
13
|
+
export declare function parseStyles(stylesXml: Uint8Array, themeFonts?: ThemeFonts): StyleSheet;
|
|
@@ -32,7 +32,7 @@ var STYLE_TYPES = new Set([
|
|
|
32
32
|
* @param stylesXml The raw `styles.xml` bytes.
|
|
33
33
|
* @returns The parsed stylesheet, or `EMPTY_STYLE_SHEET` when the root is absent.
|
|
34
34
|
*/
|
|
35
|
-
function parseStyles(stylesXml) {
|
|
35
|
+
function parseStyles(stylesXml, themeFonts) {
|
|
36
36
|
const xml = decoder.decode(stylesXml);
|
|
37
37
|
const root = asElement(parser.parse(xml)["w:styles"]);
|
|
38
38
|
if (!root) return EMPTY_STYLE_SHEET;
|
|
@@ -41,9 +41,9 @@ function parseStyles(stylesXml) {
|
|
|
41
41
|
let defaultParagraphProperties = {};
|
|
42
42
|
if (docDefaults) {
|
|
43
43
|
const rPrDef = asElement(docDefaults["w:rPrDefault"]);
|
|
44
|
-
if (rPrDef) defaultRunProperties = parseRunProperties(rPrDef["w:rPr"]);
|
|
44
|
+
if (rPrDef) defaultRunProperties = parseRunProperties(rPrDef["w:rPr"], themeFonts);
|
|
45
45
|
const pPrDef = asElement(docDefaults["w:pPrDefault"]);
|
|
46
|
-
if (pPrDef) defaultParagraphProperties = parseParagraphProperties(pPrDef["w:pPr"]);
|
|
46
|
+
if (pPrDef) defaultParagraphProperties = parseParagraphProperties(pPrDef["w:pPr"], 0, themeFonts);
|
|
47
47
|
}
|
|
48
48
|
const styles = /* @__PURE__ */ new Map();
|
|
49
49
|
for (const s of asArray(root["w:style"])) {
|
|
@@ -61,9 +61,9 @@ function parseStyles(stylesXml) {
|
|
|
61
61
|
type,
|
|
62
62
|
...basedOnVal ? { basedOn: basedOnVal } : {},
|
|
63
63
|
isDefault,
|
|
64
|
-
runProperties: parseRunProperties(el["w:rPr"]),
|
|
65
|
-
paragraphProperties: parseParagraphProperties(el["w:pPr"]),
|
|
66
|
-
...type === "table" ? parseTableStyleParts(el) : {}
|
|
64
|
+
runProperties: parseRunProperties(el["w:rPr"], themeFonts),
|
|
65
|
+
paragraphProperties: parseParagraphProperties(el["w:pPr"], 0, themeFonts),
|
|
66
|
+
...type === "table" ? parseTableStyleParts(el, themeFonts) : {}
|
|
67
67
|
};
|
|
68
68
|
styles.set(id, style);
|
|
69
69
|
}
|
|
@@ -88,9 +88,9 @@ var CONDITION_TYPES = new Set([
|
|
|
88
88
|
"swCell",
|
|
89
89
|
"seCell"
|
|
90
90
|
]);
|
|
91
|
-
function parseTableStyleParts(el) {
|
|
91
|
+
function parseTableStyleParts(el, themeFonts) {
|
|
92
92
|
const out = {};
|
|
93
|
-
const base = parseTableStyleLayer(el);
|
|
93
|
+
const base = parseTableStyleLayer(el, themeFonts);
|
|
94
94
|
if (base) out.tableLayer = base;
|
|
95
95
|
const tblPr = asElement(el["w:tblPr"]);
|
|
96
96
|
if (tblPr) {
|
|
@@ -105,7 +105,7 @@ function parseTableStyleParts(el) {
|
|
|
105
105
|
if (!cond) continue;
|
|
106
106
|
const typeAttr = getAttr(cond, "type");
|
|
107
107
|
if (!typeAttr || !CONDITION_TYPES.has(typeAttr)) continue;
|
|
108
|
-
const layer = parseTableStyleLayer(cond);
|
|
108
|
+
const layer = parseTableStyleLayer(cond, themeFonts);
|
|
109
109
|
if (layer) conditions.push({
|
|
110
110
|
type: typeAttr,
|
|
111
111
|
layer
|
|
@@ -114,7 +114,7 @@ function parseTableStyleParts(el) {
|
|
|
114
114
|
if (conditions.length > 0) out.tableConditions = conditions;
|
|
115
115
|
return out;
|
|
116
116
|
}
|
|
117
|
-
function parseTableStyleLayer(el) {
|
|
117
|
+
function parseTableStyleLayer(el, themeFonts) {
|
|
118
118
|
const tblPr = asElement(el["w:tblPr"]);
|
|
119
119
|
const tcPr = asElement(el["w:tcPr"]);
|
|
120
120
|
const borders = parseFlatBorders(tblPr ? asElement(tblPr["w:tblBorders"]) : void 0) ?? parseFlatBorders(tcPr ? asElement(tcPr["w:tcBorders"]) : void 0);
|
|
@@ -124,8 +124,8 @@ function parseTableStyleLayer(el) {
|
|
|
124
124
|
const indType = tblInd ? getAttr(tblInd, "type") : void 0;
|
|
125
125
|
const indentPt = indW !== void 0 && (indType === void 0 || indType === "dxa") ? twipsToPt(indW) : void 0;
|
|
126
126
|
const shading = parseFlatShading(tcPr ? tcPr["w:shd"] : void 0);
|
|
127
|
-
const runProperties = parseRunProperties(el["w:rPr"]);
|
|
128
|
-
const paragraphProperties = parseParagraphProperties(el["w:pPr"]);
|
|
127
|
+
const runProperties = parseRunProperties(el["w:rPr"], themeFonts);
|
|
128
|
+
const paragraphProperties = parseParagraphProperties(el["w:pPr"], 0, themeFonts);
|
|
129
129
|
const layer = {
|
|
130
130
|
...borders ? { borders } : {},
|
|
131
131
|
...cellMargins ? { cellMargins } : {},
|
|
@@ -115,11 +115,11 @@ function parseTable(tbl, ctx = DEFAULT_PARSE_CONTEXT) {
|
|
|
115
115
|
function poChildrenThroughSdt(node, tag) {
|
|
116
116
|
return childrenThroughSdt(node, tag).map((c) => c.node);
|
|
117
117
|
}
|
|
118
|
-
function childrenThroughSdt(node, tag) {
|
|
118
|
+
function childrenThroughSdt(node, tag, themeFonts) {
|
|
119
119
|
const out = [];
|
|
120
120
|
for (const child of poChildren(node)) if (poIs(child, tag)) out.push({ node: child });
|
|
121
121
|
else if (poIs(child, "w:sdt")) {
|
|
122
|
-
const props = sdtRunProperties(child);
|
|
122
|
+
const props = sdtRunProperties(child, themeFonts);
|
|
123
123
|
for (const inner of poChildrenWith(poFirstChild(child, "w:sdtContent"), tag)) out.push({
|
|
124
124
|
node: inner,
|
|
125
125
|
...props ? { sdtRunProps: props } : {}
|
|
@@ -270,7 +270,7 @@ function isDeletedRow(tr) {
|
|
|
270
270
|
function parseTableRow(tr, ctx) {
|
|
271
271
|
const properties = parseRowProperties(poFirstChild(tr, "w:trPr"));
|
|
272
272
|
const cells = [];
|
|
273
|
-
for (const { node, sdtRunProps } of childrenThroughSdt(tr, "w:tc")) cells.push(parseTableCell(node, ctx, sdtRunProps));
|
|
273
|
+
for (const { node, sdtRunProps } of childrenThroughSdt(tr, "w:tc", ctx.themeFonts)) cells.push(parseTableCell(node, ctx, sdtRunProps));
|
|
274
274
|
return {
|
|
275
275
|
properties,
|
|
276
276
|
cells
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ThemeFonts } from '../core/drawingml/theme-parser.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve a `w:rFonts` theme attribute to the typeface it stands for.
|
|
4
|
+
*
|
|
5
|
+
* @param value The attribute as written (`minorHAnsi`, `majorBidi`, …).
|
|
6
|
+
* @param fonts The theme's font scheme, when the part was read.
|
|
7
|
+
* @returns The typeface, or `undefined` for an unknown slot, a missing theme,
|
|
8
|
+
* or a slot the theme leaves empty.
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveWordThemeFont(value: string | undefined, fonts: ThemeFonts | undefined): string | undefined;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/word/theme-fonts.ts
|
|
2
|
+
var THEME_SLOTS = new Map([
|
|
3
|
+
["majorascii", ["major", "latin"]],
|
|
4
|
+
["majorhansi", ["major", "latin"]],
|
|
5
|
+
["majoreastasia", ["major", "ea"]],
|
|
6
|
+
["majorbidi", ["major", "cs"]],
|
|
7
|
+
["minorascii", ["minor", "latin"]],
|
|
8
|
+
["minorhansi", ["minor", "latin"]],
|
|
9
|
+
["minoreastasia", ["minor", "ea"]],
|
|
10
|
+
["minorbidi", ["minor", "cs"]]
|
|
11
|
+
]);
|
|
12
|
+
/**
|
|
13
|
+
* Resolve a `w:rFonts` theme attribute to the typeface it stands for.
|
|
14
|
+
*
|
|
15
|
+
* @param value The attribute as written (`minorHAnsi`, `majorBidi`, …).
|
|
16
|
+
* @param fonts The theme's font scheme, when the part was read.
|
|
17
|
+
* @returns The typeface, or `undefined` for an unknown slot, a missing theme,
|
|
18
|
+
* or a slot the theme leaves empty.
|
|
19
|
+
*/
|
|
20
|
+
function resolveWordThemeFont(value, fonts) {
|
|
21
|
+
if (value === void 0 || !fonts) return void 0;
|
|
22
|
+
const slot = THEME_SLOTS.get(value.trim().toLowerCase());
|
|
23
|
+
if (!slot) return void 0;
|
|
24
|
+
const [which, script] = slot;
|
|
25
|
+
return fonts[which][script];
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { resolveWordThemeFont };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reamkit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0",
|
|
4
4
|
"description": "Ream — convert DOCX, XLSX, PPTX and PDF to PDF, SVG, HTML, DOCX and XLSX, built from scratch on the ECMA-376 and ISO 32000 specifications. Parse once, convert anywhere.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Alex Krassavin <info@reamkit.dev>",
|
|
File without changes
|