@docx4j/core-ts 0.1.0 → 0.1.1
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/README.md +410 -10
- package/dist/model/content/Body.d.mts +109 -4
- package/dist/model/content/Body.mjs +300 -29
- package/dist/model/content/Comment.d.mts +78 -0
- package/dist/model/content/Comment.mjs +429 -0
- package/dist/model/content/ContentControl.d.mts +173 -0
- package/dist/model/content/ContentControl.mjs +638 -0
- package/dist/model/content/Font.d.mts +48 -8
- package/dist/model/content/Font.mjs +55 -13
- package/dist/model/content/InlinePicture.d.mts +103 -0
- package/dist/model/content/InlinePicture.mjs +361 -0
- package/dist/model/content/List.d.mts +253 -0
- package/dist/model/content/List.mjs +778 -0
- package/dist/model/content/Paragraph.d.mts +213 -16
- package/dist/model/content/Paragraph.mjs +611 -57
- package/dist/model/content/Range.d.mts +48 -4
- package/dist/model/content/Range.mjs +161 -4
- package/dist/model/content/Table.d.mts +130 -0
- package/dist/model/content/Table.mjs +429 -0
- package/dist/model/content/TrackedChange.d.mts +96 -0
- package/dist/model/content/TrackedChange.mjs +352 -0
- package/dist/model/content/comments.d.mts +122 -0
- package/dist/model/content/comments.mjs +248 -0
- package/dist/model/content/index.d.mts +13 -3
- package/dist/model/content/index.mjs +15 -3
- package/dist/model/content/ooxml.d.mts +17 -0
- package/dist/model/content/ooxml.mjs +214 -0
- package/dist/model/content/styles.d.mts +21 -0
- package/dist/model/content/styles.mjs +86 -0
- package/dist/model/content/tracking.d.mts +104 -0
- package/dist/model/content/tracking.mjs +313 -0
- package/dist/model/content/tree.d.mts +56 -9
- package/dist/model/content/tree.mjs +104 -31
- package/dist/model/customxml/CustomXmlPart.d.mts +158 -0
- package/dist/model/customxml/CustomXmlPart.mjs +415 -0
- package/dist/model/customxml/CustomXmlPartCollection.d.mts +68 -0
- package/dist/model/customxml/CustomXmlPartCollection.mjs +183 -0
- package/dist/model/customxml/XmlMapping.d.mts +46 -0
- package/dist/model/customxml/XmlMapping.mjs +98 -0
- package/dist/model/customxml/bindings.d.mts +41 -0
- package/dist/model/customxml/bindings.mjs +230 -0
- package/dist/model/customxml/index.d.mts +7 -0
- package/dist/model/customxml/index.mjs +9 -0
- package/dist/model/customxml/insert.d.mts +20 -0
- package/dist/model/customxml/insert.mjs +22 -0
- package/dist/model/customxml/kinds.d.mts +103 -0
- package/dist/model/customxml/kinds.mjs +267 -0
- package/dist/model/customxml/xpath.d.mts +52 -0
- package/dist/model/customxml/xpath.mjs +205 -0
- package/dist/model/fonts/CJKToEnglish.d.mts +2 -0
- package/dist/model/fonts/CJKToEnglish.mjs +16 -0
- package/dist/model/fonts/FontFallback.d.mts +58 -0
- package/dist/model/fonts/FontFallback.mjs +219 -0
- package/dist/model/fonts/IdentityPlusMapper.d.mts +7 -0
- package/dist/model/fonts/IdentityPlusMapper.mjs +19 -0
- package/dist/model/fonts/LanguageTagToScriptMapping.d.mts +7 -0
- package/dist/model/fonts/LanguageTagToScriptMapping.mjs +67 -0
- package/dist/model/fonts/Mapper.d.mts +190 -0
- package/dist/model/fonts/Mapper.mjs +481 -0
- package/dist/model/fonts/PhysicalFont.d.mts +34 -0
- package/dist/model/fonts/PhysicalFont.mjs +62 -0
- package/dist/model/fonts/RunFontSelector.d.mts +194 -0
- package/dist/model/fonts/RunFontSelector.mjs +441 -0
- package/dist/model/fonts/ThemeFonts.d.mts +17 -0
- package/dist/model/fonts/ThemeFonts.mjs +76 -0
- package/dist/model/fonts/defaultTheme.d.mts +37 -0
- package/dist/model/fonts/defaultTheme.mjs +57 -0
- package/dist/model/fonts/families.generated.d.mts +11 -0
- package/dist/model/fonts/families.generated.mjs +17 -0
- package/dist/model/fonts/fontsInUse.d.mts +39 -0
- package/dist/model/fonts/fontsInUse.mjs +183 -0
- package/dist/model/fonts/index.d.mts +14 -0
- package/dist/model/fonts/index.mjs +29 -0
- package/dist/model/fonts/lookup.d.mts +5 -0
- package/dist/model/fonts/lookup.mjs +12 -0
- package/dist/model/fonts/registry.d.mts +31 -0
- package/dist/model/fonts/registry.mjs +103 -0
- package/dist/model/fonts/scripts.d.mts +2 -0
- package/dist/model/fonts/scripts.mjs +78 -0
- package/dist/model/fonts/substitutions.generated.d.mts +30 -0
- package/dist/model/fonts/substitutions.generated.mjs +12 -0
- package/dist/model/fonts/themes.generated.d.mts +6 -0
- package/dist/model/fonts/themes.generated.mjs +11 -0
- package/dist/model/index.d.mts +5 -0
- package/dist/model/index.mjs +13 -1
- package/dist/model/listnumbering/Emulator.d.mts +187 -0
- package/dist/model/listnumbering/Emulator.mjs +332 -0
- package/dist/model/listnumbering/definitions.d.mts +251 -0
- package/dist/model/listnumbering/definitions.mjs +571 -0
- package/dist/model/listnumbering/formats.d.mts +25 -0
- package/dist/model/listnumbering/formats.mjs +320 -0
- package/dist/model/listnumbering/index.d.mts +4 -0
- package/dist/model/listnumbering/index.mjs +15 -0
- package/dist/model/listnumbering/state.d.mts +97 -0
- package/dist/model/listnumbering/state.mjs +179 -0
- package/dist/model/properties/PropertyResolver.d.mts +216 -0
- package/dist/model/properties/PropertyResolver.mjs +524 -0
- package/dist/model/properties/catalogue.d.mts +179 -0
- package/dist/model/properties/catalogue.mjs +860 -0
- package/dist/model/properties/index.d.mts +4 -0
- package/dist/model/properties/index.mjs +9 -0
- package/dist/model/properties/log.d.mts +7 -0
- package/dist/model/properties/log.mjs +25 -0
- package/dist/model/properties/styleUtil.d.mts +112 -0
- package/dist/model/properties/styleUtil.mjs +359 -0
- package/dist/node/index.d.mts +1 -0
- package/dist/node/index.mjs +12 -0
- package/dist/office-js/document.d.mts +111 -0
- package/dist/office-js/document.mjs +267 -0
- package/dist/office-js/enums.d.mts +187 -0
- package/dist/office-js/enums.mjs +176 -0
- package/dist/office-js/errors.d.mts +29 -0
- package/dist/office-js/errors.mjs +39 -0
- package/dist/office-js/extras.d.mts +5 -0
- package/dist/office-js/extras.mjs +29 -0
- package/dist/office-js/fragment.d.mts +10 -0
- package/dist/office-js/fragment.mjs +23 -0
- package/dist/office-js/index.d.mts +183 -0
- package/dist/office-js/index.mjs +54 -0
- package/dist/office-js/proxy.d.mts +72 -0
- package/dist/office-js/proxy.mjs +279 -0
- package/dist/office-js/run.d.mts +32 -0
- package/dist/office-js/run.mjs +66 -0
- package/dist/office-js/supported.d.mts +7 -0
- package/dist/office-js/supported.generated.d.mts +1 -0
- package/dist/office-js/supported.generated.mjs +235 -0
- package/dist/office-js/supported.mjs +53 -0
- package/dist/office-js/toApiScript.d.mts +25 -0
- package/dist/office-js/toApiScript.mjs +394 -0
- package/dist/opc/ContentTypes.d.mts +1 -0
- package/dist/opc/ContentTypes.mjs +1 -0
- package/dist/opc/DirectoryPartStore.d.mts +47 -0
- package/dist/opc/DirectoryPartStore.mjs +123 -0
- package/dist/opc/exceptions.d.mts +30 -0
- package/dist/opc/exceptions.mjs +38 -0
- package/dist/opc/index.d.mts +1 -1
- package/dist/opc/index.mjs +1 -1
- package/dist/packages/OpcPackage.d.mts +19 -1
- package/dist/packages/OpcPackage.mjs +29 -0
- package/dist/packages/PresentationMLPackage.d.mts +71 -1
- package/dist/packages/PresentationMLPackage.mjs +179 -0
- package/dist/packages/SpreadsheetMLPackage.d.mts +30 -1
- package/dist/packages/SpreadsheetMLPackage.mjs +78 -0
- package/dist/packages/WordprocessingMLPackage.d.mts +124 -2
- package/dist/packages/WordprocessingMLPackage.mjs +309 -2
- package/dist/packages/index.d.mts +1 -1
- package/dist/packages/index.mjs +1 -1
- package/dist/parts/DefaultXmlPart.d.mts +18 -0
- package/dist/parts/DefaultXmlPart.mjs +34 -5
- package/dist/parts/PartRegistry.mjs +1 -0
- package/dist/parts/XmlPart.d.mts +33 -0
- package/dist/parts/XmlPart.mjs +105 -2
- package/dist/parts/pml/defaults.d.mts +6 -0
- package/dist/parts/pml/defaults.mjs +53 -0
- package/dist/parts/pml/index.d.mts +66 -3
- package/dist/parts/pml/index.mjs +206 -7
- package/dist/parts/pml/placeholders.d.mts +71 -0
- package/dist/parts/pml/placeholders.mjs +141 -0
- package/dist/parts/sml/index.d.mts +19 -1
- package/dist/parts/sml/index.mjs +60 -1
- package/dist/parts/wml/comments.d.mts +1 -0
- package/dist/parts/wml/comments.mjs +179 -0
- package/dist/parts/wml/defaultNumbering.d.mts +1 -0
- package/dist/parts/wml/defaultNumbering.mjs +216 -0
- package/dist/parts/wml/index.d.mts +121 -0
- package/dist/parts/wml/index.mjs +291 -0
- package/dist/xml/dom.mjs +1 -2
- package/package.json +25 -4
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { getScriptForLanguageTag } from './LanguageTagToScriptMapping.mjs';
|
|
2
|
+
function fontScheme(theme) {
|
|
3
|
+
var _a;
|
|
4
|
+
if (theme === undefined)
|
|
5
|
+
return undefined;
|
|
6
|
+
if ('majorFont' in theme)
|
|
7
|
+
return theme;
|
|
8
|
+
return (_a = theme.themeElements) === null || _a === void 0 ? void 0 : _a.fontScheme;
|
|
9
|
+
}
|
|
10
|
+
function isMajor(type) {
|
|
11
|
+
return type === 'majorAscii' || type === 'majorBidi' || type === 'majorEastAsia' || type === 'majorHAnsi';
|
|
12
|
+
}
|
|
13
|
+
/** `ThemePart.getLang`: which of `w:themeFontLang`'s three attributes this reference reads. */
|
|
14
|
+
function langFor(themeFontLang, type) {
|
|
15
|
+
var _a, _b, _c;
|
|
16
|
+
if (type === 'majorAscii' || type === 'minorAscii' || type === 'majorHAnsi' || type === 'minorHAnsi') {
|
|
17
|
+
return (_a = themeFontLang.val) !== null && _a !== void 0 ? _a : undefined;
|
|
18
|
+
}
|
|
19
|
+
if (type === 'majorBidi' || type === 'minorBidi')
|
|
20
|
+
return (_b = themeFontLang.bidi) !== null && _b !== void 0 ? _b : undefined;
|
|
21
|
+
return (_c = themeFontLang.eastAsia) !== null && _c !== void 0 ? _c : undefined;
|
|
22
|
+
}
|
|
23
|
+
/** The collection's own `a:latin` / `a:ea` / `a:cs` for this reference. */
|
|
24
|
+
function textFontFromTheme(scheme, type) {
|
|
25
|
+
const collection = isMajor(type) ? scheme.majorFont : scheme.minorFont;
|
|
26
|
+
if (collection === undefined)
|
|
27
|
+
return undefined;
|
|
28
|
+
switch (type) {
|
|
29
|
+
case 'majorEastAsia':
|
|
30
|
+
case 'minorEastAsia': return collection.ea;
|
|
31
|
+
case 'majorBidi':
|
|
32
|
+
case 'minorBidi': return collection.cs;
|
|
33
|
+
// majorAscii / minorAscii / majorHAnsi / minorHAnsi, and anything unknown: a:latin
|
|
34
|
+
default: return collection.latin;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** The typeface of a collection's own face for this reference; undefined where it is absent or
|
|
38
|
+
* empty (`<a:ea typeface=""/>`, which the Office theme writes). */
|
|
39
|
+
function fontFromTheme(scheme, type) {
|
|
40
|
+
var _a;
|
|
41
|
+
const typeface = (_a = textFontFromTheme(scheme, type)) === null || _a === void 0 ? void 0 : _a.typeface;
|
|
42
|
+
if (typeface === undefined || typeface.trim().length === 0)
|
|
43
|
+
return undefined;
|
|
44
|
+
return typeface;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The face a theme reference names in this theme, for this `w:themeFontLang`.
|
|
48
|
+
*
|
|
49
|
+
* With no `w:themeFontLang` (or none that applies to this reference), the collection's own
|
|
50
|
+
* `a:latin` / `a:ea` / `a:cs`. With one, the language's script (`Jpan`, `Hans`, `Geor` ...)
|
|
51
|
+
* picks from the collection's `a:font` list, falling back to the collection's own face where
|
|
52
|
+
* the language selects no script or the list has no entry for it.
|
|
53
|
+
*
|
|
54
|
+
* @returns the typeface, or undefined where the theme answers nothing.
|
|
55
|
+
*/
|
|
56
|
+
export function themeFontOf(theme, type, themeFontLang) {
|
|
57
|
+
var _a;
|
|
58
|
+
if (type === undefined || type === null)
|
|
59
|
+
return undefined;
|
|
60
|
+
const scheme = fontScheme(theme);
|
|
61
|
+
if (scheme === undefined)
|
|
62
|
+
return undefined;
|
|
63
|
+
if (themeFontLang === undefined || themeFontLang === null)
|
|
64
|
+
return fontFromTheme(scheme, type);
|
|
65
|
+
const lang = langFor(themeFontLang, type);
|
|
66
|
+
if (lang === undefined)
|
|
67
|
+
return fontFromTheme(scheme, type);
|
|
68
|
+
const script = getScriptForLanguageTag(lang);
|
|
69
|
+
if (script === undefined)
|
|
70
|
+
return fontFromTheme(scheme, type);
|
|
71
|
+
const collection = isMajor(type) ? scheme.majorFont : scheme.minorFont;
|
|
72
|
+
const entry = (_a = collection === null || collection === void 0 ? void 0 : collection.font) === null || _a === void 0 ? void 0 : _a.find((f) => f.script === script);
|
|
73
|
+
// as docx4j: only a script the list does not carry falls back; an entry with an empty
|
|
74
|
+
// typeface answers the empty string, and the caller's explicit attribute does not stand
|
|
75
|
+
return entry === undefined ? fontFromTheme(scheme, type) : entry.typeface;
|
|
76
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** The values `docx4j.fonts.defaultTheme` takes. */
|
|
2
|
+
export type DefaultThemeValue = '2023' | '2013' | '2007';
|
|
3
|
+
/** A default theme: the Latin faces its font scheme names, and the theme part docx4j bundles. */
|
|
4
|
+
export interface DefaultTheme {
|
|
5
|
+
readonly value: DefaultThemeValue;
|
|
6
|
+
/** The face its font scheme names for the major (heading) Latin slot. */
|
|
7
|
+
readonly majorLatin: string;
|
|
8
|
+
/** The face its font scheme names for the minor (body) Latin slot. */
|
|
9
|
+
readonly minorLatin: string;
|
|
10
|
+
/** That theme's own `theme1.xml`, as docx4j ships it. */
|
|
11
|
+
readonly xml: string;
|
|
12
|
+
}
|
|
13
|
+
/** Word 365's Office theme: Aptos Display / Aptos. The default. */
|
|
14
|
+
export declare const THEME_2023: DefaultTheme;
|
|
15
|
+
/** Office 2013 to 2022: Calibri Light / Calibri. */
|
|
16
|
+
export declare const THEME_2013: DefaultTheme;
|
|
17
|
+
/** Office 2007 to 2010: Cambria / Calibri; docx4j's answer up to 17.1.0. */
|
|
18
|
+
export declare const THEME_2007: DefaultTheme;
|
|
19
|
+
export declare const DEFAULT_THEMES: readonly DefaultTheme[];
|
|
20
|
+
/** The theme a value names; undefined where it names none. */
|
|
21
|
+
export declare function defaultThemeOf(value: string | undefined): DefaultTheme | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* The package-level default, for a selector or a `createPackage()` that is not told otherwise.
|
|
24
|
+
* `'2023'` unless set; an unknown value throws rather than being silently ignored.
|
|
25
|
+
*/
|
|
26
|
+
export declare function defaultThemeSetting(): DefaultTheme;
|
|
27
|
+
export declare function defaultThemeSetting(value: DefaultThemeValue | DefaultTheme): DefaultTheme;
|
|
28
|
+
/** What a package carries: `pkg.fonts.defaultTheme`. */
|
|
29
|
+
export interface FontSettings {
|
|
30
|
+
/** Which Office theme this package's themeless font references resolve against, and which
|
|
31
|
+
* theme part `createPackage()` gives it. Defaults to {@link defaultThemeSetting}. */
|
|
32
|
+
defaultTheme: DefaultThemeValue;
|
|
33
|
+
}
|
|
34
|
+
/** A package's font settings, defaulting to the process-wide setting when they are created. */
|
|
35
|
+
export declare function newFontSettings(): FontSettings;
|
|
36
|
+
/** The theme a package's settings name, falling back to the process-wide setting. */
|
|
37
|
+
export declare function themeOfSettings(settings: FontSettings | undefined): DefaultTheme;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Which Office theme a package that has **no theme part** is read as having, and which theme
|
|
2
|
+
// part `WordprocessingMLPackage.createPackage` puts in a new one.
|
|
3
|
+
//
|
|
4
|
+
// docx4j `org.docx4j.Docx4jProperties.DefaultTheme` and the property
|
|
5
|
+
// `docx4j.fonts.defaultTheme` (docx4j CR-001 batch 49 item 6). Word supplies its own default
|
|
6
|
+
// theme to a themeless document, and which faces that names has changed twice: measured on a
|
|
7
|
+
// Word 365 rendering of a package with no theme part (probe `theme-fonts-no-theme-part`), the
|
|
8
|
+
// body face is **Aptos** and the heading face **Aptos Display**, where Office 2013 to 2022
|
|
9
|
+
// answered Calibri and Calibri Light and Office 2007 to 2010 answered Calibri and Cambria. So
|
|
10
|
+
// this says which version of Word a themeless document is read as having come from - not a
|
|
11
|
+
// preference - and the default is the current one.
|
|
12
|
+
//
|
|
13
|
+
// **The shape here.** docx4j has one JVM-wide property; this package has no properties file,
|
|
14
|
+
// and a browser or an add-in may hold several packages at once, so the setting lives on the
|
|
15
|
+
// package: `pkg.fonts.defaultTheme = '2013'`. {@link defaultThemeSetting} is the fallback for
|
|
16
|
+
// a selector built without a package, and is what a caller changes to move every package at
|
|
17
|
+
// once.
|
|
18
|
+
import { THEME_2007_XML, THEME_2013_XML, THEME_2023_XML } from './themes.generated.mjs';
|
|
19
|
+
/** Word 365's Office theme: Aptos Display / Aptos. The default. */
|
|
20
|
+
export const THEME_2023 = {
|
|
21
|
+
value: '2023', majorLatin: 'Aptos Display', minorLatin: 'Aptos', xml: THEME_2023_XML,
|
|
22
|
+
};
|
|
23
|
+
/** Office 2013 to 2022: Calibri Light / Calibri. */
|
|
24
|
+
export const THEME_2013 = {
|
|
25
|
+
value: '2013', majorLatin: 'Calibri Light', minorLatin: 'Calibri', xml: THEME_2013_XML,
|
|
26
|
+
};
|
|
27
|
+
/** Office 2007 to 2010: Cambria / Calibri; docx4j's answer up to 17.1.0. */
|
|
28
|
+
export const THEME_2007 = {
|
|
29
|
+
value: '2007', majorLatin: 'Cambria', minorLatin: 'Calibri', xml: THEME_2007_XML,
|
|
30
|
+
};
|
|
31
|
+
export const DEFAULT_THEMES = [THEME_2023, THEME_2013, THEME_2007];
|
|
32
|
+
/** The theme a value names; undefined where it names none. */
|
|
33
|
+
export function defaultThemeOf(value) {
|
|
34
|
+
if (value === undefined || value === null)
|
|
35
|
+
return undefined;
|
|
36
|
+
const v = value.trim();
|
|
37
|
+
return DEFAULT_THEMES.find((t) => t.value.toLowerCase() === v.toLowerCase());
|
|
38
|
+
}
|
|
39
|
+
let setting = THEME_2023;
|
|
40
|
+
export function defaultThemeSetting(value) {
|
|
41
|
+
if (value !== undefined) {
|
|
42
|
+
const theme = typeof value === 'string' ? defaultThemeOf(value) : value;
|
|
43
|
+
if (!theme)
|
|
44
|
+
throw new Error(`docx4j.fonts.defaultTheme: not one of 2023, 2013, 2007: ${String(value)}`);
|
|
45
|
+
setting = theme;
|
|
46
|
+
}
|
|
47
|
+
return setting;
|
|
48
|
+
}
|
|
49
|
+
/** A package's font settings, defaulting to the process-wide setting when they are created. */
|
|
50
|
+
export function newFontSettings() {
|
|
51
|
+
return { defaultTheme: defaultThemeSetting().value };
|
|
52
|
+
}
|
|
53
|
+
/** The theme a package's settings name, falling back to the process-wide setting. */
|
|
54
|
+
export function themeOfSettings(settings) {
|
|
55
|
+
var _a;
|
|
56
|
+
return (_a = (settings === undefined ? undefined : defaultThemeOf(settings.defaultTheme))) !== null && _a !== void 0 ? _a : defaultThemeSetting();
|
|
57
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The families `MicrosoftFonts.xml` lists, as it writes them. `MicrosoftFontsRegistry`
|
|
2
|
+
* keys that map by the name exactly, so the lookup is case-sensitive here too. */
|
|
3
|
+
export declare const MS_FONT_NAMES: readonly string[];
|
|
4
|
+
/** Those of {@link MS_FONT_NAMES} whose entry has a `<bold>` element. A family in the
|
|
5
|
+
* registry without one has no bold face of its own (Franklin Gothic Book), which is what
|
|
6
|
+
* `Mapper.hasBoldFace` answers on. */
|
|
7
|
+
export declare const MS_FONTS_WITH_BOLD: readonly string[];
|
|
8
|
+
/** The families `word-line-metrics.properties` holds, lower-cased. */
|
|
9
|
+
export declare const LINE_METRIC_FAMILIES: readonly string[];
|
|
10
|
+
/** Those of {@link LINE_METRIC_FAMILIES} the table's optional field 7 flags East Asian. */
|
|
11
|
+
export declare const EAST_ASIAN_FAMILIES: readonly string[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// The font families docx4j's own tables know: which have a bold face of their own, and which have Word line metrics recorded.
|
|
2
|
+
//
|
|
3
|
+
// Generated by scripts/generate-substitutions.mjs from docx4j 7fba7a1507fc01fdd7f4dc2f79cdbd6988c044f7:
|
|
4
|
+
// org/docx4j/fonts/microsoft/MicrosoftFonts.xml (149 families)
|
|
5
|
+
// org/docx4j/fonts/word-line-metrics.properties (512 families)
|
|
6
|
+
// Do not edit; run `npm run generate:fonts` instead.
|
|
7
|
+
/** The families `MicrosoftFonts.xml` lists, as it writes them. `MicrosoftFontsRegistry`
|
|
8
|
+
* keys that map by the name exactly, so the lookup is case-sensitive here too. */
|
|
9
|
+
export const MS_FONT_NAMES = ["Arial", "Arial Black", "Comic Sans MS", "Courier New", "Georgia", "Impact", "Times New Roman", "Trebuchet MS", "Verdana", "Webdings", "Microsoft Sans Serif", "Segoe UI", "Tahoma", "Calibri", "Cambria", "Candara", "Consolas", "Constantia", "Corbel", "Franklin Gothic Medium", "Lucida Console", "Palatino Linotype", "Marlett", "Symbol", "Wingdings", "Algerian", "Arial Narrow", "Arial Unicode MS", "Baskerville Old Face", "Batang", "BatangChe", "Gungsuh", "GungsuhChe", "Bauhaus 93", "Bell MT", "Berlin Sans FB", "Berlin Sans FB Demi", "Bernard MT Condensed", "Bodoni MT Poster Compressed", "Book Antiqua", "Bookman Old Style", "Bookshelf Symbol 7", "Britannic Bold", "Broadway", "Brush Script MT", "Californian FB", "Cambria Math", "Centaur", "Century", "Century Gothic", "Chiller", "Colonna MT", "Cooper Black", "Estrangelo Edessa", "Footlight MT Light", "Freestyle Script", "Garamond", "Gautami", "Gulim", "GulimChe", "Dotum", "DotumChe", "Harlow Solid Italic", "Harrington", "High Tower Text", "Informal Roman", "Jokerman", "Juice ITC", "Kristen ITC", "Kunstler Script", "Latha", "Lucida Bright", "Lucida Calligraphy", "Lucida Fax", "Lucida Handwriting", "Lucida Sans", "Lucida Sans Unicode", "Magneto", "Malgun Gothic", "Mangal", "Marlett", "Matura MT Script Capitals", "MingLiU", "PMingLiU", "Mistral", "Modern No. 20", "Monotype Corsiva", "MS Gothic", "MS PGothic", "MS UI Gothic", "MS Mincho", "MS PMincho", "MS Reference Sans Serif", "MS Reference Specialty", "MT Extra", "MV Boli", "Niagara Engraved", "Niagara Solid", "Nina", "Old English Text MT", "Onyx", "Parchment", "Playbill", "Poor Richard", "Raavi", "Ravie", "Showcard Gothic", "Shruti", "SimHei", "SimSun", "NSimSun", "Snap ITC", "Stencil", "Sylfaen", "Tempus Sans ITC", "Tunga", "Viner Hand ITC", "Vivaldi", "Vladimir Script", "Wide Latin", "Wingdings 2", "Wingdings 3", "Liberation Serif", "Liberation Sans", "Liberation Mono", "Noto Sans Symbols Regular", "Noto Sans Symbols 2 Regular", "DejaVu Serif", "Segoe UI Symbol", "Franklin Gothic Book", "Franklin Gothic Demi", "Rockwell", "Carlito Regular", "Caladea Regular", "Cousine Regular", "Arimo Regular", "Tinos Regular"];
|
|
10
|
+
/** Those of {@link MS_FONT_NAMES} whose entry has a `<bold>` element. A family in the
|
|
11
|
+
* registry without one has no bold face of its own (Franklin Gothic Book), which is what
|
|
12
|
+
* `Mapper.hasBoldFace` answers on. */
|
|
13
|
+
export const MS_FONTS_WITH_BOLD = ["Arial", "Comic Sans MS", "Courier New", "Georgia", "Times New Roman", "Trebuchet MS", "Verdana", "Segoe UI", "Tahoma", "Calibri", "Cambria", "Candara", "Consolas", "Constantia", "Corbel", "Palatino Linotype", "Arial Narrow", "Bell MT", "Berlin Sans FB", "Bookman Old Style", "Californian FB", "Cambria Math", "Century Gothic", "Garamond", "Lucida Bright", "Lucida Fax", "Lucida Sans", "Malgun Gothic", "Nina", "Liberation Serif", "Liberation Sans", "Liberation Mono", "Noto Sans Symbols Regular", "DejaVu Serif", "Franklin Gothic Demi", "Rockwell", "Carlito Regular", "Caladea Regular", "Cousine Regular", "Arimo Regular", "Tinos Regular"];
|
|
14
|
+
/** The families `word-line-metrics.properties` holds, lower-cased. */
|
|
15
|
+
export const LINE_METRIC_FAMILIES = ["abhaya libre", "agency fb", "aharoni", "algerian", "aller", "aller light", "amasis mt pro", "amasis mt pro black", "amasis mt pro medium", "amienne", "angsana new", "aptos", "aptos display", "aptos light", "aptos narrow", "archivo narrow", "arial", "arial black", "arial narrow", "arial nova", "arial nova cond", "arial nova light", "arial rounded mt bold", "arial unicode ms", "arnprior", "avenir next lt pro", "avenir next lt pro light", "bahnschrift", "barlow", "barts and the london logo", "baskerville old face", "batang", "batangche", "bauhaus 93", "baveuse", "bell mt", "bella donna", "bembo", "berlin sans fb", "berlin sans fb demi", "bernard mt condensed", "berylium", "bierstadt", "biondi", "blackadder itc", "blue highway", "blue highway condensed", "blue highway d type", "blue highway linocut", "bodoni mt", "bodoni mt black", "bodoni mt condensed", "bodoni mt poster compressed", "book antiqua", "bookman old style", "bookshelf symbol 7", "boopee", "bradley hand itc", "britannic bold", "broadway", "brush script mt", "burnstown dam", "buxton sketch", "byington", "calibri", "calibri light", "californian fb", "calisto mt", "cambria", "cambria math", "candara", "candara light", "carbon block", "carlito", "castellar", "catholicschoolgirls intl bb", "catriel", "cavolini", "centaur", "century", "century gothic", "century schoolbook", "chiller", "colonna mt", "comic sans ms", "consolas", "constantia", "cooper black", "copperplate gothic bold", "copperplate gothic light", "corbel", "corbel light", "cordia new", "courier new", "credit valley", "curlz mt", "dante", "dejavu sans", "dengxian", "dengxian light", "dokchampa", "dotum", "dotumche", "dubai", "dubai light", "dubai medium", "earwig factory", "ebrima", "edwardian script itc", "elephant", "engravers mt", "eras bold itc", "eras demi itc", "eras light itc", "eras medium itc", "euclid", "euclid extra", "euclid fraktur", "euclid math one", "euclid math two", "euclid symbol", "euphorigenic s", "felix titling", "fences", "fira sans", "footlight mt light", "forte", "franklin gothic book", "franklin gothic demi", "franklin gothic demi cond", "franklin gothic heavy", "franklin gothic medium", "franklin gothic medium cond", "free 3 of 9", "free 3 of 9 extended", "freestyle script", "french script mt", "gabriola", "gadugi", "garamond", "gautami", "geeznewa", "georgia", "georgia pro", "georgia pro cond black", "georgia pro cond light", "georgia pro light", "georgia pro semibold", "gigi", "gill sans mt", "gill sans mt condensed", "gill sans mt ext condensed bold", "gill sans nova", "gill sans ultra bold", "gill sans ultra bold condensed", "gloucester mt extra condensed", "goudy old style", "goudy stout", "grad", "grandview", "grandview display", "gulim", "gulimche", "gungsuh", "gungsuhche", "haettenschweiler", "harlow solid italic", "harrington", "heavy heap", "hggothice", "hggothicm", "hggyoshotai", "hgkyokashotai", "hgmarugothicmpro", "hgminchob", "hgminchoe", "hgpgothice", "hgpgothicm", "hgpgyoshotai", "hgpkyokashotai", "hgpminchob", "hgpminchoe", "hgpsoeikakugothicub", "hgpsoeikakupoptai", "hgpsoeipresenceeb", "hgseikaishotaipro", "hgsgothice", "hgsgothicm", "hgsgyoshotai", "hgskyokashotai", "hgsminchob", "hgsminchoe", "hgsoeikakugothicub", "hgsoeikakupoptai", "hgsoeipresenceeb", "hgssoeikakugothicub", "hgssoeikakupoptai", "hgssoeipresenceeb", "high tower text", "hololens mdl2 assets", "hp simplified", "hp simplified light", "hurry up", "huxtable", "impact", "imprint mt shadow", "informal roman", "ink free", "iskoola pota", "javanese text", "jokerman", "juice itc", "kaiti", "kredit", "kristen itc", "kunstler script", "latha", "leelawadee ui", "leelawadee ui semilight", "liberation sans", "liberation serif", "ligurino", "ligurino condensed", "lucida bright", "lucida calligraphy", "lucida console", "lucida fax", "lucida handwriting", "lucida sans", "lucida sans typewriter", "lucida sans unicode", "magneto", "maiandra gd", "malgun gothic", "malgun gothic semilight", "mangal", "marlett", "matura mt script capitals", "meiryo", "merriweather", "microsoft gothicneo", "microsoft himalaya", "microsoft jhenghei", "microsoft jhenghei ui", "microsoft mhei", "microsoft neogothic", "microsoft new tai lue", "microsoft phagspa", "microsoft sans serif", "microsoft tai le", "microsoft yahei", "microsoft yahei ui", "microsoft yi baiti", "mingliu", "mingliu-extb", "mingliu_hkscs-extb", "minya nouvelle", "mistral", "modern love", "modern no. 20", "mongolian baiti", "monotype corsiva", "montserrat", "ms gothic", "ms mincho", "ms outlook", "ms pgothic", "ms pmincho", "ms reference sans serif", "ms reference specialty", "ms ui gothic", "mt extra", "mt extra tiger", "mufferaw", "mv boli", "myanmar text", "neue haas grotesk text pro", "neuropol", "niagara engraved", "niagara solid", "nimbus sans narrow", "nina", "nirmala ui", "nirmala ui semilight", "noto sans", "noto sans black", "noto sans condensed", "noto sans condensed black", "noto sans condensed extrabold", "noto sans condensed extralight", "noto sans condensed light", "noto sans condensed medium", "noto sans condensed semibold", "noto sans condensed thin", "noto sans extrabold", "noto sans extracondensed", "noto sans extracondensed black", "noto sans extracondensed extrabold", "noto sans extracondensed extralight", "noto sans extracondensed light", "noto sans extracondensed medium", "noto sans extracondensed semibold", "noto sans extracondensed thin", "noto sans extralight", "noto sans light", "noto sans medium", "noto sans semibold", "noto sans semicondensed", "noto sans semicondensed black", "noto sans semicondensed extrabold", "noto sans semicondensed extralight", "noto sans semicondensed light", "noto sans semicondensed medium", "noto sans semicondensed semibold", "noto sans semicondensed thin", "noto sans sinhala", "noto sans sinhala blk", "noto sans sinhala cond", "noto sans sinhala cond blk", "noto sans sinhala cond extbd", "noto sans sinhala cond extlt", "noto sans sinhala cond light", "noto sans sinhala cond med", "noto sans sinhala cond sembd", "noto sans sinhala cond thin", "noto sans sinhala extbd", "noto sans sinhala extcond", "noto sans sinhala extcond blk", "noto sans sinhala extcond extbd", "noto sans sinhala extcond extlt", "noto sans sinhala extcond light", "noto sans sinhala extcond med", "noto sans sinhala extcond sembd", "noto sans sinhala extcond thin", "noto sans sinhala extlt", "noto sans sinhala light", "noto sans sinhala med", "noto sans sinhala sembd", "noto sans sinhala semcond", "noto sans sinhala semcond blk", "noto sans sinhala semcond extbd", "noto sans sinhala semcond extlt", "noto sans sinhala semcond light", "noto sans sinhala semcond med", "noto sans sinhala semcond sembd", "noto sans sinhala semcond thin", "noto sans sinhala thin", "noto sans sinhala ui", "noto sans symbols", "noto sans thin", "noto serif sinhala", "noto serif sinhala black", "noto serif sinhala condensed", "noto serif sinhala condensed black", "noto serif sinhala condensed extrabold", "noto serif sinhala condensed extralight", "noto serif sinhala condensed light", "noto serif sinhala condensed medium", "noto serif sinhala condensed semibold", "noto serif sinhala condensed thin", "noto serif sinhala extrabold", "noto serif sinhala extracondensed", "noto serif sinhala extracondensed black", "noto serif sinhala extracondensed extrabold", "noto serif sinhala extracondensed extralight", "noto serif sinhala extracondensed light", "noto serif sinhala extracondensed medium", "noto serif sinhala extracondensed semibold", "noto serif sinhala extracondensed thin", "noto serif sinhala extralight", "noto serif sinhala light", "noto serif sinhala medium", "noto serif sinhala semibold", "noto serif sinhala semicondensed", "noto serif sinhala semicondensed black", "noto serif sinhala semicondensed extrabold", "noto serif sinhala semicondensed extralight", "noto serif sinhala semicondensed light", "noto serif sinhala semicondensed medium", "noto serif sinhala semicondensed semibold", "noto serif sinhala semicondensed thin", "noto serif sinhala thin", "nsimsun", "nunito sans", "ocr a extended", "ocrb", "old english text mt", "onyx", "open sans", "oswald", "pacifico", "palace script mt", "palatino linotype", "papyrus", "parchment", "perpetua", "perpetua titling mt", "planet benson 2", "playbill", "playfair display", "pmingliu", "pmingliu-extb", "poor richard", "posterama", "pristina", "pupcat", "raavi", "rage italic", "ravie", "roboto", "roboto condensed", "rockwell", "rockwell condensed", "rockwell extra bold", "rockwell nova", "rockwell nova light", "sabon next lt", "sagona", "sagona book", "sagona extralight", "sans serif collection", "script mt bold", "seaford", "seaford display", "segoe marker", "segoe mdl2 assets", "segoe print", "segoe script", "segoe ui", "segoe ui black", "segoe ui emoji", "segoe ui historic", "segoe ui light", "segoe ui semibold", "segoe ui semilight", "segoe ui symbol", "segoe wp", "segoe wp black", "segoe wp light", "segoe wp semibold", "segoe wp semilight", "shell", "showcard gothic", "shruti", "simhei", "simsun", "simsun-extb", "simsun-extg", "sitka", "sketchflow print", "snap itc", "source han serif cn", "source sans pro", "source sans pro semibold", "speak pro", "srisakdi", "stencil", "stereofidelic", "stzhongsong", "sybil green", "sylfaen", "symbol", "symbol tiger", "symbol tiger expert", "tahoma", "tandelle", "teen", "teen light", "tempus sans itc", "tenorite", "the hand", "the hand extrablack", "the serif hand", "the serif hand black", "think nothing", "tiger expert", "times new roman", "trade gothic next", "trade gothic next cond", "trade gothic next light", "trebuchet ms", "tunga", "tw cen mt", "tw cen mt condensed", "tw cen mt condensed extra bold", "ubuntu", "univers", "univers condensed", "univers condensed light", "univers light", "velvenda cooler", "verdana", "verdana pro", "verdana pro cond semibold", "vijaya", "viner hand itc", "vivaldi", "vladimir script", "waker", "walbaum", "walbaum display", "walbaum display light", "webdings", "wickenden cafe ndp", "wide latin", "wingdings", "wingdings 2", "wingdings 3", "yu gothic", "yu gothic ui", "yu mincho", "yu mincho demibold"];
|
|
16
|
+
/** Those of {@link LINE_METRIC_FAMILIES} the table's optional field 7 flags East Asian. */
|
|
17
|
+
export const EAST_ASIAN_FAMILIES = ["arial unicode ms", "batang", "batangche", "dengxian", "dengxian light", "dotum", "dotumche", "gulim", "gulimche", "gungsuh", "gungsuhche", "hggothice", "hggothicm", "hggyoshotai", "hgkyokashotai", "hgmarugothicmpro", "hgminchob", "hgminchoe", "hgseikaishotaipro", "hgsoeikakugothicub", "hgsoeikakupoptai", "hgsoeipresenceeb", "kaiti", "malgun gothic", "malgun gothic semilight", "meiryo", "microsoft gothicneo", "microsoft jhenghei", "microsoft mhei", "microsoft neogothic", "microsoft yahei", "mingliu", "mingliu-extb", "ms gothic", "ms mincho", "ms pmincho", "pmingliu", "simhei", "simsun", "simsun-extb", "simsun-extg", "source han serif cn", "stzhongsong", "yu gothic", "yu mincho", "yu mincho demibold"];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type * as wml from '@docx4j/generated-objects-ts/modules/org_docx4j_wml';
|
|
2
|
+
import type { RunFontSelector } from './RunFontSelector.mjs';
|
|
3
|
+
/** The stories a walk covers, in docx4j's order: the body, then headers and footers, endnotes,
|
|
4
|
+
* footnotes and comments. Each value is whatever holds block-level content. */
|
|
5
|
+
export type Stories = Iterable<unknown>;
|
|
6
|
+
/** The styles part, as much of it as the walk needs. */
|
|
7
|
+
export interface StyleSource {
|
|
8
|
+
styles?: wml.Styles | undefined;
|
|
9
|
+
/** The `w:default="1"` paragraph, character and table style ids. */
|
|
10
|
+
defaultParagraphStyleId?: string | undefined;
|
|
11
|
+
defaultCharacterStyleId?: string | undefined;
|
|
12
|
+
defaultTableStyleId?: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
/** What one walk found. */
|
|
15
|
+
export interface FontsAndStyles {
|
|
16
|
+
/** The document font names, theme references resolved, CJK names in English. */
|
|
17
|
+
fonts: Set<string>;
|
|
18
|
+
/** The style ids used directly (not those merely based on). */
|
|
19
|
+
styles: Set<string>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* One traversal of every story, collecting font names and the style ids used directly
|
|
23
|
+
* (docx4j's `FontAndStyleFinder`). The default paragraph, character and table styles count as
|
|
24
|
+
* used where a paragraph, run or table names none of its own.
|
|
25
|
+
*
|
|
26
|
+
* @param selector resolves theme references; omit to collect styles only
|
|
27
|
+
*/
|
|
28
|
+
export declare function walkStories(stories: Stories, styleSource: StyleSource | undefined, selector: RunFontSelector | undefined, collectFonts: boolean): FontsAndStyles;
|
|
29
|
+
/**
|
|
30
|
+
* The font names a document uses: the walk above, then the styles in use with their `w:basedOn`
|
|
31
|
+
* chains, the numbering levels, the document defaults, and the default font.
|
|
32
|
+
*
|
|
33
|
+
* @param stories the body and the other story parts' content
|
|
34
|
+
* @param styleSource the styles part
|
|
35
|
+
* @param numbering the numbering part's content, or undefined
|
|
36
|
+
* @param selector the package's selector (it resolves the theme references and answers the
|
|
37
|
+
* default font)
|
|
38
|
+
*/
|
|
39
|
+
export declare function fontsInUse(stories: Stories, styleSource: StyleSource | undefined, numbering: wml.Numbering | undefined, selector: RunFontSelector): Set<string>;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { walk } from '@docx4j/generated-objects-ts/builders/wml';
|
|
2
|
+
import { toEnglish } from './CJKToEnglish.mjs';
|
|
3
|
+
function collector(selector, into) {
|
|
4
|
+
const add = (fontName) => {
|
|
5
|
+
var _a;
|
|
6
|
+
if (fontName === undefined || fontName === null)
|
|
7
|
+
return;
|
|
8
|
+
const name = fontName.trim();
|
|
9
|
+
if (name.length === 0)
|
|
10
|
+
return;
|
|
11
|
+
// where there is an English name, no point adding the original CJK name
|
|
12
|
+
into.add((_a = toEnglish(name)) !== null && _a !== void 0 ? _a : name);
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
name: add,
|
|
16
|
+
rFonts(rFonts) {
|
|
17
|
+
if (rFonts === undefined || selector === undefined)
|
|
18
|
+
return;
|
|
19
|
+
for (const name of selector.documentFontsOf(rFonts))
|
|
20
|
+
add(name);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** The `w:rPr` a content control's `w:sdtPr` carries, if any. */
|
|
25
|
+
function sdtRPr(sdtPr) {
|
|
26
|
+
var _a;
|
|
27
|
+
for (const entry of (_a = sdtPr.rPrOrAliasOrLock) !== null && _a !== void 0 ? _a : []) {
|
|
28
|
+
const value = entry.value;
|
|
29
|
+
if ((value === null || value === void 0 ? void 0 : value.TYPE_NAME) === 'org_docx4j_wml.RPr')
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* One traversal of every story, collecting font names and the style ids used directly
|
|
36
|
+
* (docx4j's `FontAndStyleFinder`). The default paragraph, character and table styles count as
|
|
37
|
+
* used where a paragraph, run or table names none of its own.
|
|
38
|
+
*
|
|
39
|
+
* @param selector resolves theme references; omit to collect styles only
|
|
40
|
+
*/
|
|
41
|
+
export function walkStories(stories, styleSource, selector, collectFonts) {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
const fonts = new Set();
|
|
44
|
+
const styles = new Set();
|
|
45
|
+
const add = collector(selector, fonts);
|
|
46
|
+
let defaultParagraphStyleUsed = false;
|
|
47
|
+
let defaultCharacterStyleUsed = false;
|
|
48
|
+
let defaultTableStyleUsed = false;
|
|
49
|
+
for (const story of stories) {
|
|
50
|
+
walk(story, (value) => {
|
|
51
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
52
|
+
switch (value.TYPE_NAME) {
|
|
53
|
+
case 'org_docx4j_wml.P': {
|
|
54
|
+
const pPr = value.pPr;
|
|
55
|
+
if (collectFonts && (pPr === null || pPr === void 0 ? void 0 : pPr.rPr) !== undefined)
|
|
56
|
+
add.rFonts(pPr.rPr.rFonts); // the paragraph mark's
|
|
57
|
+
let customPStyle = false;
|
|
58
|
+
if (pPr !== undefined) {
|
|
59
|
+
if (((_a = pPr.pStyle) === null || _a === void 0 ? void 0 : _a.val) !== undefined) {
|
|
60
|
+
customPStyle = true;
|
|
61
|
+
styles.add(pPr.pStyle.val);
|
|
62
|
+
}
|
|
63
|
+
if (((_c = (_b = pPr.rPr) === null || _b === void 0 ? void 0 : _b.rStyle) === null || _c === void 0 ? void 0 : _c.val) !== undefined)
|
|
64
|
+
styles.add(pPr.rPr.rStyle.val);
|
|
65
|
+
}
|
|
66
|
+
defaultParagraphStyleUsed || (defaultParagraphStyleUsed = !customPStyle);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case 'org_docx4j_wml.R': {
|
|
70
|
+
const rPr = value.rPr;
|
|
71
|
+
if (collectFonts && rPr !== undefined)
|
|
72
|
+
add.rFonts(rPr.rFonts);
|
|
73
|
+
if (rPr !== undefined) {
|
|
74
|
+
if (((_d = rPr.rStyle) === null || _d === void 0 ? void 0 : _d.val) === undefined)
|
|
75
|
+
defaultCharacterStyleUsed = true;
|
|
76
|
+
else
|
|
77
|
+
styles.add(rPr.rStyle.val);
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case 'org_docx4j_wml.R.Sym':
|
|
82
|
+
if (collectFonts)
|
|
83
|
+
add.name(value.font);
|
|
84
|
+
break;
|
|
85
|
+
case 'org_docx4j_wml.Tbl': {
|
|
86
|
+
const tblStyle = (_f = (_e = value.tblPr) === null || _e === void 0 ? void 0 : _e.tblStyle) === null || _f === void 0 ? void 0 : _f.val;
|
|
87
|
+
if (tblStyle !== undefined)
|
|
88
|
+
styles.add(tblStyle);
|
|
89
|
+
defaultTableStyleUsed || (defaultTableStyleUsed = tblStyle === undefined);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case 'org_docx4j_wml.SdtPr': {
|
|
93
|
+
const rPr = sdtRPr(value);
|
|
94
|
+
if (rPr === undefined)
|
|
95
|
+
break;
|
|
96
|
+
if (collectFonts)
|
|
97
|
+
add.rFonts(rPr.rFonts);
|
|
98
|
+
const rStyle = (_g = rPr.rStyle) === null || _g === void 0 ? void 0 : _g.val;
|
|
99
|
+
if (rStyle !== undefined) {
|
|
100
|
+
styles.add(rStyle);
|
|
101
|
+
// and the linked paragraph style, if any
|
|
102
|
+
const linked = linkedStyleOf(styleSource === null || styleSource === void 0 ? void 0 : styleSource.styles, rStyle);
|
|
103
|
+
if (linked !== undefined)
|
|
104
|
+
styles.add(linked);
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
default:
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
return undefined;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (defaultParagraphStyleUsed && (styleSource === null || styleSource === void 0 ? void 0 : styleSource.defaultParagraphStyleId) !== undefined) {
|
|
115
|
+
styles.add(styleSource.defaultParagraphStyleId);
|
|
116
|
+
const style = styleById(styleSource.styles, styleSource.defaultParagraphStyleId);
|
|
117
|
+
if (((_b = (_a = style === null || style === void 0 ? void 0 : style.rPr) === null || _a === void 0 ? void 0 : _a.rStyle) === null || _b === void 0 ? void 0 : _b.val) !== undefined)
|
|
118
|
+
styles.add(style.rPr.rStyle.val);
|
|
119
|
+
}
|
|
120
|
+
if (defaultCharacterStyleUsed && (styleSource === null || styleSource === void 0 ? void 0 : styleSource.defaultCharacterStyleId) !== undefined) {
|
|
121
|
+
styles.add(styleSource.defaultCharacterStyleId);
|
|
122
|
+
}
|
|
123
|
+
if (defaultTableStyleUsed && (styleSource === null || styleSource === void 0 ? void 0 : styleSource.defaultTableStyleId) !== undefined) {
|
|
124
|
+
styles.add(styleSource.defaultTableStyleId);
|
|
125
|
+
}
|
|
126
|
+
return { fonts, styles };
|
|
127
|
+
}
|
|
128
|
+
function styleById(styles, styleId) {
|
|
129
|
+
var _a;
|
|
130
|
+
return (_a = styles === null || styles === void 0 ? void 0 : styles.style) === null || _a === void 0 ? void 0 : _a.find((s) => s.styleId === styleId);
|
|
131
|
+
}
|
|
132
|
+
/** The paragraph style a character style is linked to (`w:link`), by style id. */
|
|
133
|
+
function linkedStyleOf(styles, styleId) {
|
|
134
|
+
var _a, _b, _c;
|
|
135
|
+
const link = (_b = (_a = styleById(styles, styleId)) === null || _a === void 0 ? void 0 : _a.link) === null || _b === void 0 ? void 0 : _b.val;
|
|
136
|
+
if (link === undefined)
|
|
137
|
+
return undefined;
|
|
138
|
+
return (_c = styleById(styles, link)) === null || _c === void 0 ? void 0 : _c.styleId;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The font names a document uses: the walk above, then the styles in use with their `w:basedOn`
|
|
142
|
+
* chains, the numbering levels, the document defaults, and the default font.
|
|
143
|
+
*
|
|
144
|
+
* @param stories the body and the other story parts' content
|
|
145
|
+
* @param styleSource the styles part
|
|
146
|
+
* @param numbering the numbering part's content, or undefined
|
|
147
|
+
* @param selector the package's selector (it resolves the theme references and answers the
|
|
148
|
+
* default font)
|
|
149
|
+
*/
|
|
150
|
+
export function fontsInUse(stories, styleSource, numbering, selector) {
|
|
151
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
152
|
+
const { fonts, styles } = walkStories(stories, styleSource, selector, true);
|
|
153
|
+
const add = collector(selector, fonts);
|
|
154
|
+
const allStyles = styleSource === null || styleSource === void 0 ? void 0 : styleSource.styles;
|
|
155
|
+
const docDefaultsRFonts = (_c = (_b = (_a = allStyles === null || allStyles === void 0 ? void 0 : allStyles.docDefaults) === null || _a === void 0 ? void 0 : _a.rPrDefault) === null || _b === void 0 ? void 0 : _b.rPr) === null || _c === void 0 ? void 0 : _c.rFonts;
|
|
156
|
+
if (allStyles !== undefined) {
|
|
157
|
+
add.rFonts(docDefaultsRFonts);
|
|
158
|
+
// the styles in use, each with the chain it is based on
|
|
159
|
+
for (const styleId of styles) {
|
|
160
|
+
let style = styleById(allStyles, styleId);
|
|
161
|
+
for (let guard = 0; style !== undefined && guard < 64; guard++) {
|
|
162
|
+
if (style.rPr !== undefined)
|
|
163
|
+
add.rFonts(style.rPr.rFonts);
|
|
164
|
+
for (const tblStylePr of (_d = style.tblStylePr) !== null && _d !== void 0 ? _d : []) {
|
|
165
|
+
if (tblStylePr.rPr !== undefined)
|
|
166
|
+
add.rFonts(tblStylePr.rPr.rFonts);
|
|
167
|
+
}
|
|
168
|
+
const basedOn = (_e = style.basedOn) === null || _e === void 0 ? void 0 : _e.val;
|
|
169
|
+
style = basedOn === undefined ? undefined : styleById(allStyles, basedOn);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// Fonts can also be used in the numbering part. For now, treat any font mentioned in that
|
|
174
|
+
// part as in use (docx4j's comment: ideally only the levels actually used).
|
|
175
|
+
for (const abstractNum of (_f = numbering === null || numbering === void 0 ? void 0 : numbering.abstractNum) !== null && _f !== void 0 ? _f : []) {
|
|
176
|
+
for (const lvl of (_g = abstractNum.lvl) !== null && _g !== void 0 ? _g : []) {
|
|
177
|
+
if (lvl.rPr !== undefined)
|
|
178
|
+
add.rFonts(lvl.rPr.rFonts);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
fonts.add(selector.defaultFontOf(docDefaultsRFonts));
|
|
182
|
+
return fonts;
|
|
183
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { PhysicalFont, NOBOLD_SUFFIX, stripSuffixes } from './PhysicalFont.mjs';
|
|
2
|
+
export { type FontRegistry, SimpleFontRegistry, DEFAULT_FONT_REGISTRY, EMPTY_FONT_REGISTRY, } from './registry.mjs';
|
|
3
|
+
export { Mapper, type FontDecision, type FontDecisionSource, UNKNOWN_ERROR, FONT_FALLBACK, isKnownFamily, hasBoldFace, isEastAsianFamily, wordDefaultFor, fontTableOf, } from './Mapper.mjs';
|
|
4
|
+
export { IdentityPlusMapper } from './IdentityPlusMapper.mjs';
|
|
5
|
+
export { type FontClass, classOf, classFromName, substitutionClass, isCondensed, leftToTheDocumentDefault, selectByClass, shortKey, vclEntryFor, isSymbol, isEastAsianForm, coverageGroupOf, SYMBOL_GROUP, EMOJI_GROUP, } from './FontFallback.mjs';
|
|
6
|
+
export { scriptOf } from './scripts.mjs';
|
|
7
|
+
export { RunFontSelector, type RunFontSelectorSource, type FontSpan, type SpansOptions, BUILT_IN_DEFAULT_FONT, isOn, symbolFontName, isEmoji, spanScript, preambleRule, runLocale, } from './RunFontSelector.mjs';
|
|
8
|
+
export { themeFontOf, type ThemeFontLang, type ThemeSource } from './ThemeFonts.mjs';
|
|
9
|
+
export { getScriptForLanguageTag } from './LanguageTagToScriptMapping.mjs';
|
|
10
|
+
export { toEnglish } from './CJKToEnglish.mjs';
|
|
11
|
+
export { type DefaultTheme, type DefaultThemeValue, type FontSettings, THEME_2007, THEME_2013, THEME_2023, DEFAULT_THEMES, defaultThemeOf, defaultThemeSetting, newFontSettings, themeOfSettings, } from './defaultTheme.mjs';
|
|
12
|
+
export { fontsInUse, walkStories, type FontsAndStyles, type StyleSource } from './fontsInUse.mjs';
|
|
13
|
+
export { runFontSelectorOf } from './lookup.mjs';
|
|
14
|
+
export { type Substitute, type SubstituteRow, type VclEntry, SUBSTITUTE_ROWS, VCL_ENTRIES, } from './substitutions.generated.mjs';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// CR-001 Phase B step 4: fonts (docx4j `org.docx4j.fonts`).
|
|
2
|
+
//
|
|
3
|
+
// Two halves, as in docx4j:
|
|
4
|
+
//
|
|
5
|
+
// - {@link RunFontSelector} decides which *document* font formats each character of a run: the
|
|
6
|
+
// effective `w:rFonts` with its theme references resolved, `w:cs` / `w:rtl` by value, the
|
|
7
|
+
// symbol fonts, and the [MS-OI29500] 17.3.2.26 character-range table. Its answer is
|
|
8
|
+
// `FontSpan[]`, which is what a renderer, a text extractor or a measurement routine needs.
|
|
9
|
+
// - {@link Mapper} maps a document font name to a {@link PhysicalFont}. This CR ships
|
|
10
|
+
// {@link IdentityPlusMapper} over a {@link FontRegistry} the caller supplies; docx4j's
|
|
11
|
+
// `BestMatchingMapper`, the glyph-coverage pass and font metrics need font files and are a
|
|
12
|
+
// later CR, but the interface is fixed here so a consumer with `fontkit` can plug its own in.
|
|
13
|
+
//
|
|
14
|
+
// The theme a package with no theme part is read as having is {@link defaultThemeSetting} /
|
|
15
|
+
// `pkg.fonts.defaultTheme`, and `createPackage()` gives a new package that theme's part.
|
|
16
|
+
export { PhysicalFont, NOBOLD_SUFFIX, stripSuffixes } from './PhysicalFont.mjs';
|
|
17
|
+
export { SimpleFontRegistry, DEFAULT_FONT_REGISTRY, EMPTY_FONT_REGISTRY, } from './registry.mjs';
|
|
18
|
+
export { Mapper, UNKNOWN_ERROR, FONT_FALLBACK, isKnownFamily, hasBoldFace, isEastAsianFamily, wordDefaultFor, fontTableOf, } from './Mapper.mjs';
|
|
19
|
+
export { IdentityPlusMapper } from './IdentityPlusMapper.mjs';
|
|
20
|
+
export { classOf, classFromName, substitutionClass, isCondensed, leftToTheDocumentDefault, selectByClass, shortKey, vclEntryFor, isSymbol, isEastAsianForm, coverageGroupOf, SYMBOL_GROUP, EMOJI_GROUP, } from './FontFallback.mjs';
|
|
21
|
+
export { scriptOf } from './scripts.mjs';
|
|
22
|
+
export { RunFontSelector, BUILT_IN_DEFAULT_FONT, isOn, symbolFontName, isEmoji, spanScript, preambleRule, runLocale, } from './RunFontSelector.mjs';
|
|
23
|
+
export { themeFontOf } from './ThemeFonts.mjs';
|
|
24
|
+
export { getScriptForLanguageTag } from './LanguageTagToScriptMapping.mjs';
|
|
25
|
+
export { toEnglish } from './CJKToEnglish.mjs';
|
|
26
|
+
export { THEME_2007, THEME_2013, THEME_2023, DEFAULT_THEMES, defaultThemeOf, defaultThemeSetting, newFontSettings, themeOfSettings, } from './defaultTheme.mjs';
|
|
27
|
+
export { fontsInUse, walkStories } from './fontsInUse.mjs';
|
|
28
|
+
export { runFontSelectorOf } from './lookup.mjs';
|
|
29
|
+
export { SUBSTITUTE_ROWS, VCL_ENTRIES, } from './substitutions.generated.mjs';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RunFontSelector } from './RunFontSelector.mjs';
|
|
2
|
+
/** The package's selector, or undefined where it has none yet (nothing has awaited
|
|
3
|
+
* `getRunFontSelector()`), where the package has no main document part, or where there is no
|
|
4
|
+
* package at all - a fragment built on its own. */
|
|
5
|
+
export declare function runFontSelectorOf(pkg: unknown): RunFontSelector | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The package's selector, or undefined where it has none yet (nothing has awaited
|
|
2
|
+
* `getRunFontSelector()`), where the package has no main document part, or where there is no
|
|
3
|
+
* package at all - a fragment built on its own. */
|
|
4
|
+
export function runFontSelectorOf(pkg) {
|
|
5
|
+
var _a;
|
|
6
|
+
try {
|
|
7
|
+
return (_a = pkg === null || pkg === void 0 ? void 0 : pkg.getMainDocumentPart) === null || _a === void 0 ? void 0 : _a.call(pkg).runFontSelectorOrUndefined;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PhysicalFont } from './PhysicalFont.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* The fonts available, by name. The only thing the mapping passes ask of a font environment.
|
|
4
|
+
*
|
|
5
|
+
* Lookups are case-insensitive and strip a twin suffix, as docx4j's `PhysicalFonts.get` does.
|
|
6
|
+
*/
|
|
7
|
+
export interface FontRegistry {
|
|
8
|
+
/** The font of this name, or undefined where the environment has none. */
|
|
9
|
+
get(name: string | undefined | null): PhysicalFont | undefined;
|
|
10
|
+
/** Every font, for the passes that search by a short key (`FontFallback`'s candidate lists). */
|
|
11
|
+
all(): readonly PhysicalFont[];
|
|
12
|
+
}
|
|
13
|
+
/** A `FontRegistry` over a fixed list of faces. */
|
|
14
|
+
export declare class SimpleFontRegistry implements FontRegistry {
|
|
15
|
+
private readonly byKey;
|
|
16
|
+
private readonly fonts;
|
|
17
|
+
constructor(fonts?: Iterable<PhysicalFont>);
|
|
18
|
+
add(font: PhysicalFont): this;
|
|
19
|
+
get(name: string | undefined | null): PhysicalFont | undefined;
|
|
20
|
+
all(): readonly PhysicalFont[];
|
|
21
|
+
}
|
|
22
|
+
/** A registry with nothing in it: every document font is `UNMAPPED`. */
|
|
23
|
+
export declare const EMPTY_FONT_REGISTRY: FontRegistry;
|
|
24
|
+
/**
|
|
25
|
+
* The default `FontRegistry`: the faces docx4j's four font jars provide, and nothing else.
|
|
26
|
+
*
|
|
27
|
+
* It is what `IdentityPlusMapper` uses where the caller supplies none, and the reason a
|
|
28
|
+
* mapping computed here can be compared with a parity golden. A consumer with real fonts
|
|
29
|
+
* passes its own (a `SimpleFontRegistry` over what `fontkit` or `@font-face` reports).
|
|
30
|
+
*/
|
|
31
|
+
export declare const DEFAULT_FONT_REGISTRY: FontRegistry;
|