Sync snapshot (2026-09-09) (#271)
- **New app: GenOffice HTML.** Open, edit and generate .html pages: a source pane with a sandboxed live preview, click-to-select elements with a floating toolbar and style panel, device-size preview, image tools and a present mode. AI generates whole pages from a brief with style directions and offers page-wide Restyle, Theme and Summarize. Export to Word runs locally through the built-in html2docx converter (native, editable OOXML; no print-to-PDF detour). - **AI:** separate BYOK providers for web search, image generation and image/video analysis; new Codex App Server provider; Ask AI quotes the selected text and keeps it highlighted while it runs; custom AI panel text size; blocked requests retry through the Chromium network stack. - **App:** global AutoSave setting shared by every editor; AI panel text size and chat spellcheck toggles (genoffice#249); Czech (cs) UI locale (genoffice#259); Save As defaults to the document's folder; PDF export no longer aborts on CJK file paths on Windows. - **Docs:** Export as HTML; comments and replies edit in place from the comments pane; the caret can leave a trailing table (genoffice#266); spellcheck re-marks text as soon as it is re-enabled; AI edits are character-precise on partial selections; zoom keeps the scroll position; pasting a cell from Sheets takes the destination font. - **Sheets:** Find no longer freezes on wide or streamed grids; Replace searches as you type; cached values of external-workbook formulas are kept instead of #ERROR! (genoffice#235); "number stored as text" is a warning, not an error (genoffice#236); paste repeats into the target range like Excel; filter criteria survive save/reopen; saves retry when Windows locks the file; many Excel-fidelity fixes for column widths, row heights, charts, slicers, number formats and CJK fonts. - **Slides:** PDF export works for large presentations (genoffice#264); EMF/WMF picture fonts and East Asian theme fonts resolve correctly; decks with missing layouts or embedded styles still open; outline-only pie slices render. - **PDF:** highlight and underline geometry aligns with the text; Shift+arrows extend the selection instead of paging. - **Markdown:** Find and replace (Ctrl+F / Ctrl+H) (genoffice#253); mermaid code blocks render as diagrams (genoffice#263); better print quality. - Thanks to community contributors @GoodScholar, @aniruddhaadak80 and @Sun8854, and to @hanyscz, @qgzln, @zyp997, @bisslot, @krakotay and @Ben03151 for the reports. Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
This commit is contained in:
co-authored by
GenOffice
parent
fa58fff047
commit
d24c964a3e
@@ -25,6 +25,6 @@
|
||||
"@types/node": "^24.10.1",
|
||||
"pptxgenjs": "^4.0.1",
|
||||
"typescript": "^5.9.3",
|
||||
"vitest": "^4.1.0"
|
||||
"vitest": "^4.1.11"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,10 @@ export interface ChartSeries {
|
||||
marker?: boolean
|
||||
/** Explicit per-point colors <c:dPt> (common for pies; render layer palette otherwise) */
|
||||
pointColors?: Array<string | undefined>
|
||||
/** Pie: <c:dPt><c:spPr><a:noFill/> — the wedge is outline-only */
|
||||
pointNoFill?: Array<boolean | undefined>
|
||||
/** Pie: per-point outline <c:dPt><c:spPr><a:ln> (color null = explicit no line) */
|
||||
pointLines?: Array<{ color: string | null; widthPt?: number } | undefined>
|
||||
/** Pie: slice offset from center as percent of diameter (series-level c:explosion → all slices) */
|
||||
explosionPct?: number
|
||||
/** Pie: per-point explosion overrides (c:dPt/c:explosion) */
|
||||
@@ -424,16 +428,32 @@ export function parseChartXml(
|
||||
const dPts: any[] = ser['c:dPt'] ?? []
|
||||
if (dPts.length) {
|
||||
const pointColors: Array<string | undefined> = []
|
||||
const pointNoFill: Array<boolean | undefined> = []
|
||||
const pointLines: Array<{ color: string | null; widthPt?: number } | undefined> = []
|
||||
const pointExpl: Array<number | undefined> = []
|
||||
for (const dPt of dPts) {
|
||||
const idx = parseInt(dPt['c:idx']?.['@_val'], 10)
|
||||
if (Number.isNaN(idx)) continue
|
||||
const c = resolveColorNode(dPt['c:spPr']?.['a:solidFill'], theme)
|
||||
const dSp = dPt['c:spPr']
|
||||
const c = resolveColorNode(dSp?.['a:solidFill'], theme)
|
||||
if (c != null) pointColors[idx] = c
|
||||
if (dSp && 'a:noFill' in dSp) pointNoFill[idx] = true
|
||||
const dLn = dSp?.['a:ln']
|
||||
if (dLn && typeof dLn === 'object') {
|
||||
const lnColor = 'a:noFill' in dLn ? null : resolveColorNode(dLn['a:solidFill'], theme)
|
||||
const lnW = parseInt(dLn['@_w'], 10)
|
||||
if (lnColor !== undefined)
|
||||
pointLines[idx] = {
|
||||
color: lnColor,
|
||||
...(Number.isFinite(lnW) && lnW > 0 ? { widthPt: lnW / 12700 } : {}),
|
||||
}
|
||||
}
|
||||
const pe = parseInt(dPt['c:explosion']?.['@_val'], 10)
|
||||
if (Number.isFinite(pe)) pointExpl[idx] = pe
|
||||
}
|
||||
if (pointColors.length) s.pointColors = pointColors
|
||||
if (pointNoFill.length) s.pointNoFill = pointNoFill
|
||||
if (pointLines.length) s.pointLines = pointLines
|
||||
if (pointExpl.length) s.pointExplosionPct = pointExpl
|
||||
}
|
||||
series.push(s)
|
||||
|
||||
@@ -9,7 +9,14 @@ import { XMLParser } from 'fast-xml-parser'
|
||||
import { layoutHierTree, parseHierConstraints } from './dgm-hier'
|
||||
import { scanSlide, type SpElement } from './scan'
|
||||
import { tableRowGridCols } from './table-grid'
|
||||
import { type Theme, resolveFontRef, resolveSchemeColor, themeWithOverride } from './theme'
|
||||
import {
|
||||
type EaScript,
|
||||
type Theme,
|
||||
eaScriptOfLang,
|
||||
resolveFontRef,
|
||||
resolveSchemeColor,
|
||||
themeWithOverride,
|
||||
} from './theme'
|
||||
import { resolveColorNode as resolveColorNodeShared } from './color'
|
||||
import {
|
||||
resolvePlaceholderPresetGeom,
|
||||
@@ -3438,10 +3445,25 @@ function parseRun(r: any, ctx: ParseContext, dflt?: LevelTextStyle): TextRun {
|
||||
// Text highlight <a:highlight> (PowerPoint draws it as a background behind the run)
|
||||
const highlightNode = rPr['a:highlight']
|
||||
const highlight = highlightNode ? resolveColorNode(highlightNode, ctx) : undefined
|
||||
const langScript = eaScriptOfLang
|
||||
const runLangScript = langScript(rPr['@_altLang']) ?? langScript(rPr['@_lang'])
|
||||
// An ea theme ref on a theme with an empty <a:ea/>: the run's East Asian language (altLang
|
||||
// first), else the text's own kana/hangul, else the placeholder level's lang, else — for
|
||||
// bare ideographs — the theme's single Han script, picks the fontScheme per-script entry
|
||||
const eaScript: EaScript | undefined =
|
||||
runLangScript ??
|
||||
(/[\u3040-\u30ff\u31f0-\u31ff]/.test(text)
|
||||
? 'ja'
|
||||
: /[\uac00-\ud7af\u1100-\u11ff]/.test(text)
|
||||
? 'ko'
|
||||
: undefined) ??
|
||||
dflt?.eaScript ??
|
||||
(/[\u3400-\u9fff\uf900-\ufaff]/.test(text) ? 'han' : undefined)
|
||||
// Font: run explicit (incl. +mj/+mn theme refs) → inherited default → theme font
|
||||
const latin = resolveFontRef(rPr['a:latin']?.['@_typeface'], ctx.theme) ?? dflt?.latinFont
|
||||
const ea = resolveFontRef(rPr['a:ea']?.['@_typeface'], ctx.theme) ?? dflt?.eaFont
|
||||
const cs = resolveFontRef(rPr['a:cs']?.['@_typeface'], ctx.theme) ?? dflt?.csFont
|
||||
const latin =
|
||||
resolveFontRef(rPr['a:latin']?.['@_typeface'], ctx.theme, eaScript) ?? dflt?.latinFont
|
||||
const ea = resolveFontRef(rPr['a:ea']?.['@_typeface'], ctx.theme, eaScript) ?? dflt?.eaFont
|
||||
const cs = resolveFontRef(rPr['a:cs']?.['@_typeface'], ctx.theme, eaScript) ?? dflt?.csFont
|
||||
const sym = resolveFontRef(rPr['a:sym']?.['@_typeface'], ctx.theme)
|
||||
// Symbol-slot characters (Wingdings dots/checkmarks stored as U+F0xx PUA) draw with a:sym,
|
||||
// not the latin font; applied when the run is entirely PUA (the common single-glyph case)
|
||||
@@ -3456,15 +3478,6 @@ function parseRun(r: any, ctx: ParseContext, dflt?: LevelTextStyle): TextRun {
|
||||
134: 'sc', // GB2312
|
||||
136: 'tc', // CHINESEBIG5
|
||||
}
|
||||
const langScript = (tag: unknown): 'ja' | 'ko' | 'sc' | 'tc' | undefined => {
|
||||
const t = String(tag ?? '').toLowerCase()
|
||||
if (t.startsWith('ja')) return 'ja'
|
||||
if (t.startsWith('ko')) return 'ko'
|
||||
if (/^zh(-(tw|hk|mo|hant))/.test(t)) return 'tc'
|
||||
if (t.startsWith('zh')) return 'sc'
|
||||
return undefined
|
||||
}
|
||||
const runLangScript = langScript(rPr['@_altLang']) ?? langScript(rPr['@_lang'])
|
||||
const charsetOf = (bucket: string): ('ja' | 'ko' | 'sc' | 'tc') | undefined => {
|
||||
if (runLangScript) return runLangScript
|
||||
if (rPr[bucket]?.['@_typeface'] == null) return undefined
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
import { XMLParser } from 'fast-xml-parser'
|
||||
import type { Transform, TextAlign } from './types'
|
||||
import { type Theme, resolveFontRef } from './theme'
|
||||
import { type EaScript, type Theme, eaScriptOfLang, resolveFontRef } from './theme'
|
||||
import { resolveColorNode } from './color'
|
||||
import { asXmlNode, xmlArray, type XmlNode } from './xml-utils'
|
||||
|
||||
@@ -41,6 +41,8 @@ export interface LevelTextStyle {
|
||||
latinFont?: string
|
||||
eaFont?: string
|
||||
csFont?: string
|
||||
/** East Asian script of the level's defRPr lang/altLang (steers empty-ea theme refs on runs without a lang of their own) */
|
||||
eaScript?: EaScript
|
||||
align?: TextAlign
|
||||
/** Bullet default (master bodyStyle levels commonly use buChar '•') */
|
||||
bullet?: {
|
||||
@@ -320,11 +322,13 @@ export function parseDefRPrStyle(
|
||||
dirDeg: num('@_dir') / 60000,
|
||||
}
|
||||
}
|
||||
const latin = resolveFontRef(typefaceAttr(defRPr['a:latin']), theme)
|
||||
const eaScript = eaScriptOfLang(defRPr['@_altLang']) ?? eaScriptOfLang(defRPr['@_lang'])
|
||||
if (eaScript) out.eaScript = eaScript
|
||||
const latin = resolveFontRef(typefaceAttr(defRPr['a:latin']), theme, eaScript)
|
||||
if (latin) out.latinFont = latin
|
||||
const ea = resolveFontRef(typefaceAttr(defRPr['a:ea']), theme)
|
||||
const ea = resolveFontRef(typefaceAttr(defRPr['a:ea']), theme, eaScript)
|
||||
if (ea) out.eaFont = ea
|
||||
const cs = resolveFontRef(typefaceAttr(defRPr['a:cs']), theme)
|
||||
const cs = resolveFontRef(typefaceAttr(defRPr['a:cs']), theme, eaScript)
|
||||
if (cs) out.csFont = cs
|
||||
return Object.keys(out).length ? out : undefined
|
||||
}
|
||||
@@ -536,6 +540,7 @@ export function mergeTextStyleChain(
|
||||
if (out.latinFont == null && lvl.latinFont != null) out.latinFont = lvl.latinFont
|
||||
if (out.eaFont == null && lvl.eaFont != null) out.eaFont = lvl.eaFont
|
||||
if (out.csFont == null && lvl.csFont != null) out.csFont = lvl.csFont
|
||||
if (out.eaScript == null && lvl.eaScript != null) out.eaScript = lvl.eaScript
|
||||
if (out.align == null && lvl.align != null) out.align = lvl.align
|
||||
if (out.bullet == null && lvl.bullet != null) out.bullet = lvl.bullet
|
||||
if (out.marL == null && lvl.marL != null) out.marL = lvl.marL
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* schemeClr / theme fonts into final values.
|
||||
*/
|
||||
import { XMLParser } from 'fast-xml-parser'
|
||||
import { asXmlNode, type XmlNode } from './xml-utils'
|
||||
import { asXmlNode, xmlArray, type XmlNode } from './xml-utils'
|
||||
|
||||
const parser = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: '@_' })
|
||||
|
||||
@@ -22,6 +22,9 @@ export interface Theme {
|
||||
/** fontScheme: major / minor East Asian fonts */
|
||||
majorEaFont?: string
|
||||
minorEaFont?: string
|
||||
/** fontScheme per-script fonts (<a:font script="Jpan" typeface=…/>), keyed by script tag */
|
||||
majorScriptFonts?: Record<string, string>
|
||||
minorScriptFonts?: Record<string, string>
|
||||
/** fontScheme: major / minor Complex Script fonts (Arabic/Hebrew/Thai/Hindi etc.) */
|
||||
majorCsFont?: string
|
||||
minorCsFont?: string
|
||||
@@ -84,6 +87,17 @@ function typeface(scheme: XmlNode, font: string, script: string): string | undef
|
||||
return typeof v === 'string' && v ? v : undefined
|
||||
}
|
||||
|
||||
function scriptFonts(scheme: XmlNode, font: string): Record<string, string> | undefined {
|
||||
const out: Record<string, string> = {}
|
||||
for (const f of xmlArray(asXmlNode(scheme[font])['a:font'])) {
|
||||
const n = asXmlNode(f)
|
||||
const script = n['@_script']
|
||||
const face = n['@_typeface']
|
||||
if (typeof script === 'string' && typeof face === 'string' && face) out[script] = face
|
||||
}
|
||||
return Object.keys(out).length ? out : undefined
|
||||
}
|
||||
|
||||
export function parseTheme(themeXml: string): Theme {
|
||||
const doc = asXmlNode(parser.parse(themeXml))
|
||||
const themeEl = asXmlNode(doc['a:theme'] ?? doc.theme)
|
||||
@@ -114,6 +128,8 @@ export function parseTheme(themeXml: string): Theme {
|
||||
const minorEaFont = typeface(fontScheme, 'a:minorFont', 'a:ea')
|
||||
const majorCsFont = typeface(fontScheme, 'a:majorFont', 'a:cs')
|
||||
const minorCsFont = typeface(fontScheme, 'a:minorFont', 'a:cs')
|
||||
const majorScriptFonts = scriptFonts(fontScheme, 'a:majorFont')
|
||||
const minorScriptFonts = scriptFonts(fontScheme, 'a:minorFont')
|
||||
// fmtScheme templates are parsed in order from raw-text slices (fillStyleLst children mix element types; regular parsing would lose the idx order)
|
||||
const fmtM = /<a:fmtScheme\b[^>]*>[\s\S]*?<\/a:fmtScheme>/.exec(themeXml)
|
||||
const fmt = fmtM?.[0] ?? ''
|
||||
@@ -129,6 +145,8 @@ export function parseTheme(themeXml: string): Theme {
|
||||
minorEaFont,
|
||||
majorCsFont,
|
||||
minorCsFont,
|
||||
...(majorScriptFonts ? { majorScriptFonts } : {}),
|
||||
...(minorScriptFonts ? { minorScriptFonts } : {}),
|
||||
...(fillStyles ? { fillStyles } : {}),
|
||||
...(lnStyles ? { lnStyles } : {}),
|
||||
...(effectStyles ? { effectStyles } : {}),
|
||||
@@ -163,21 +181,50 @@ export function themeWithOverride(base: Theme | undefined, overrideXml: string):
|
||||
* Theme font reference ("+mj-lt" / "+mn-ea" etc.) → final font name.
|
||||
* Values not starting with "+" are returned as-is; returns undefined when the theme has no match.
|
||||
*/
|
||||
/** 'han': ideographs without a language — resolves only when the theme names a single Han script */
|
||||
export type EaScript = 'ja' | 'ko' | 'sc' | 'tc' | 'han'
|
||||
const EA_SCRIPT_TAG: Record<Exclude<EaScript, 'han'>, string> = {
|
||||
ja: 'Jpan',
|
||||
ko: 'Hang',
|
||||
sc: 'Hans',
|
||||
tc: 'Hant',
|
||||
}
|
||||
const HAN_SCRIPT_TAGS = ['Jpan', 'Hans', 'Hant']
|
||||
|
||||
/** East Asian script of a BCP-47 lang/altLang tag (ja-JP → ja, zh-TW → tc, zh-CN → sc). */
|
||||
export function eaScriptOfLang(tag: unknown): Exclude<EaScript, 'han'> | undefined {
|
||||
const t = String(tag ?? '').toLowerCase()
|
||||
if (t.startsWith('ja')) return 'ja'
|
||||
if (t.startsWith('ko')) return 'ko'
|
||||
if (/^zh(-(tw|hk|mo|hant))/.test(t)) return 'tc'
|
||||
if (t.startsWith('zh')) return 'sc'
|
||||
return undefined
|
||||
}
|
||||
|
||||
export function resolveFontRef(
|
||||
typeface: string | undefined,
|
||||
theme: Theme | undefined,
|
||||
/** Script of the text using an ea theme ref: with an empty <a:ea typeface=""/> PowerPoint
|
||||
* takes the fontScheme's per-script entry (Jpan/Hang/Hans/Hant) before the Latin font. */
|
||||
eaScript?: EaScript,
|
||||
): string | undefined {
|
||||
if (!typeface) return undefined
|
||||
if (!typeface.startsWith('+')) return typeface
|
||||
const scriptFont = (fonts: Record<string, string> | undefined): string | undefined => {
|
||||
if (!eaScript || !fonts) return undefined
|
||||
if (eaScript !== 'han') return fonts[EA_SCRIPT_TAG[eaScript]]
|
||||
const han = HAN_SCRIPT_TAGS.filter((t) => fonts[t])
|
||||
return han.length === 1 ? fonts[han[0]!] : undefined
|
||||
}
|
||||
switch (typeface) {
|
||||
case '+mj-lt':
|
||||
return theme?.majorFont
|
||||
case '+mn-lt':
|
||||
return theme?.minorFont
|
||||
case '+mj-ea':
|
||||
return theme?.majorEaFont ?? theme?.majorFont
|
||||
return theme?.majorEaFont ?? scriptFont(theme?.majorScriptFonts) ?? theme?.majorFont
|
||||
case '+mn-ea':
|
||||
return theme?.minorEaFont ?? theme?.minorFont
|
||||
return theme?.minorEaFont ?? scriptFont(theme?.minorScriptFonts) ?? theme?.minorFont
|
||||
case '+mj-cs':
|
||||
return theme?.majorCsFont ?? theme?.majorFont
|
||||
case '+mn-cs':
|
||||
|
||||
@@ -124,7 +124,11 @@ export class PackageArchive {
|
||||
}
|
||||
|
||||
/** Resolve a slide's layout / master part paths (via the rels chain). */
|
||||
resolveSlideChain(slidePath: string): { layoutPath?: string; masterPath?: string; themePath?: string } {
|
||||
resolveSlideChain(slidePath: string): {
|
||||
layoutPath?: string
|
||||
masterPath?: string
|
||||
themePath?: string
|
||||
} {
|
||||
const slideRels = this.readRels(slidePath)
|
||||
let layoutPath: string | undefined
|
||||
for (const rel of slideRels.values()) {
|
||||
@@ -133,6 +137,10 @@ export class PackageArchive {
|
||||
break
|
||||
}
|
||||
}
|
||||
// Damaged decks ship slides without a rels part (or without the mandatory slideLayout
|
||||
// relationship). PowerPoint refuses such files; LibreOffice renders them on the first
|
||||
// layout of the first master, which keeps the deck's background/decorations — do the same.
|
||||
if (!layoutPath) layoutPath = this.fallbackLayoutPath(slidePath)
|
||||
let masterPath: string | undefined
|
||||
let themePath: string | undefined
|
||||
if (layoutPath) {
|
||||
@@ -155,6 +163,43 @@ export class PackageArchive {
|
||||
}
|
||||
return { layoutPath, masterPath, themePath }
|
||||
}
|
||||
|
||||
/**
|
||||
* Layout for a slide that lost its slideLayout relationship: the first master's layouts in
|
||||
* sldLayoutIdLst order, preferring the title layout for a slide carrying a ctrTitle placeholder
|
||||
* (what the deck's own title page would have referenced), else the first layout.
|
||||
*/
|
||||
private fallbackLayoutPath(slidePath: string): string | undefined {
|
||||
const presXml = this.readText('ppt/presentation.xml')
|
||||
if (!presXml) return undefined
|
||||
const presRels = this.readRels('ppt/presentation.xml')
|
||||
const masterRid = /<p:sldMasterId\b[^>]*\br:id="([^"]+)"/.exec(presXml)?.[1]
|
||||
const masterRel = masterRid
|
||||
? presRels.get(masterRid)
|
||||
: [...presRels.values()].find((r) => r.type.endsWith('/slideMaster'))
|
||||
if (!masterRel) return undefined
|
||||
const masterPath = resolveTarget('ppt/presentation.xml', masterRel.target)
|
||||
const masterXml = this.readText(masterPath)
|
||||
if (!masterXml) return undefined
|
||||
const masterRels = this.readRels(masterPath)
|
||||
const layouts: string[] = []
|
||||
for (const m of masterXml.matchAll(/<p:sldLayoutId\b[^>]*\br:id="([^"]+)"/g)) {
|
||||
const rel = masterRels.get(m[1]!)
|
||||
if (rel) layouts.push(resolveTarget(masterPath, rel.target))
|
||||
}
|
||||
if (!layouts.length)
|
||||
for (const rel of masterRels.values())
|
||||
if (rel.type.endsWith('/slideLayout')) layouts.push(resolveTarget(masterPath, rel.target))
|
||||
if (!layouts.length) return undefined
|
||||
const wantsTitle = /<p:ph\b[^>]*\btype="ctrTitle"/.test(this.readText(slidePath) ?? '')
|
||||
if (wantsTitle) {
|
||||
const title = layouts.find((p) =>
|
||||
/<p:sldLayout\b[^>]*\btype="title"/.test(this.readText(p) ?? ''),
|
||||
)
|
||||
if (title) return title
|
||||
}
|
||||
return layouts[0]
|
||||
}
|
||||
}
|
||||
|
||||
/** 'ppt/slides/slide1.xml' → 'ppt/slides/_rels/slide1.xml.rels' */
|
||||
|
||||
@@ -108,6 +108,22 @@ describe('parseChartXml', () => {
|
||||
expect(m.series[0]!.pointColors?.[2]).toBe('#0000AA')
|
||||
})
|
||||
|
||||
it('parses outline-only pie points: c:dPt noFill + per-point a:ln', () => {
|
||||
const PIE = `<c:chartSpace xmlns:c="c" xmlns:a="a"><c:chart><c:plotArea>
|
||||
<c:pieChart><c:varyColors val="1"/><c:ser><c:idx val="0"/>
|
||||
<c:dPt><c:idx val="0"/><c:spPr><a:noFill/><a:ln w="19050"><a:solidFill><a:srgbClr val="AA0000"/></a:solidFill></a:ln></c:spPr></c:dPt>
|
||||
<c:dPt><c:idx val="1"/><c:spPr><a:solidFill><a:srgbClr val="0000AA"/></a:solidFill><a:ln><a:noFill/></a:ln></c:spPr></c:dPt>
|
||||
<c:val><c:numRef><c:f>y</c:f><c:numCache><c:ptCount val="3"/><c:pt idx="0"><c:v>1</c:v></c:pt><c:pt idx="1"><c:v>2</c:v></c:pt><c:pt idx="2"><c:v>3</c:v></c:pt></c:numCache></c:numRef></c:val>
|
||||
</c:ser></c:pieChart></c:plotArea></c:chart></c:chartSpace>`
|
||||
const s = parseChartXml(PIE)!.series[0]!
|
||||
expect(s.pointNoFill).toEqual([true])
|
||||
expect(s.pointLines?.[0]).toEqual({ color: '#AA0000', widthPt: 1.5 })
|
||||
expect(s.pointColors?.[1]).toBe('#0000AA')
|
||||
expect(s.pointLines?.[1]).toEqual({ color: null })
|
||||
expect(s.pointNoFill?.[1]).toBeUndefined()
|
||||
expect(s.pointLines?.[2]).toBeUndefined()
|
||||
})
|
||||
|
||||
it('parses pie explosion: series-level c:explosion and per-point c:dPt overrides', () => {
|
||||
const PIE = `<c:chartSpace xmlns:c="c" xmlns:a="a"><c:chart><c:plotArea>
|
||||
<c:pie3DChart><c:ser><c:idx val="0"/>
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { createBlankPptx, openPptx } from '../src/index'
|
||||
|
||||
describe('resolveSlideChain', () => {
|
||||
it('follows the slide rels when present', async () => {
|
||||
const { archive } = await openPptx(await createBlankPptx())
|
||||
const chain = archive.resolveSlideChain('ppt/slides/slide1.xml')
|
||||
expect(chain.layoutPath).toBe('ppt/slideLayouts/slideLayout1.xml')
|
||||
expect(chain.masterPath).toBe('ppt/slideMasters/slideMaster1.xml')
|
||||
expect(chain.themePath).toBe('ppt/theme/theme1.xml')
|
||||
})
|
||||
|
||||
it('a slide with a ctrTitle placeholder falls back to the title layout', async () => {
|
||||
const { archive } = await openPptx(await createBlankPptx())
|
||||
archive.entries.delete('ppt/slides/_rels/slide1.xml.rels')
|
||||
// Add a second layout typed "title" behind the existing one
|
||||
const master = archive.readText('ppt/slideMasters/slideMaster1.xml')!
|
||||
archive.entries.set(
|
||||
'ppt/slideMasters/slideMaster1.xml',
|
||||
Buffer.from(
|
||||
master.replace(
|
||||
'</p:sldLayoutIdLst>',
|
||||
'<p:sldLayoutId id="2147483650" r:id="rIdT"/></p:sldLayoutIdLst>',
|
||||
),
|
||||
'utf8',
|
||||
),
|
||||
)
|
||||
const rels = archive.readText('ppt/slideMasters/_rels/slideMaster1.xml.rels')!
|
||||
archive.entries.set(
|
||||
'ppt/slideMasters/_rels/slideMaster1.xml.rels',
|
||||
Buffer.from(
|
||||
rels.replace(
|
||||
'</Relationships>',
|
||||
'<Relationship Id="rIdT" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayoutT.xml"/></Relationships>',
|
||||
),
|
||||
'utf8',
|
||||
),
|
||||
)
|
||||
archive.entries.set(
|
||||
'ppt/slideLayouts/slideLayoutT.xml',
|
||||
Buffer.from('<p:sldLayout type="title" xmlns:p="p"><p:cSld/></p:sldLayout>', 'utf8'),
|
||||
)
|
||||
const slide = archive.readText('ppt/slides/slide1.xml')!
|
||||
archive.entries.set(
|
||||
'ppt/slides/slide1.xml',
|
||||
Buffer.from(
|
||||
slide.replace(
|
||||
'</p:spTree>',
|
||||
'<p:sp><p:nvSpPr><p:cNvPr id="9" name="t"/><p:cNvSpPr/><p:nvPr><p:ph type="ctrTitle"/></p:nvPr></p:nvSpPr><p:spPr/></p:sp></p:spTree>',
|
||||
),
|
||||
'utf8',
|
||||
),
|
||||
)
|
||||
expect(archive.resolveSlideChain('ppt/slides/slide1.xml').layoutPath).toBe(
|
||||
'ppt/slideLayouts/slideLayoutT.xml',
|
||||
)
|
||||
// Without the ctrTitle placeholder the first layout wins
|
||||
archive.entries.set('ppt/slides/slide1.xml', Buffer.from(slide, 'utf8'))
|
||||
expect(archive.resolveSlideChain('ppt/slides/slide1.xml').layoutPath).toBe(
|
||||
'ppt/slideLayouts/slideLayout1.xml',
|
||||
)
|
||||
})
|
||||
|
||||
it('falls back to the first layout of the first master when the slide has no rels part', async () => {
|
||||
const { archive } = await openPptx(await createBlankPptx())
|
||||
archive.entries.delete('ppt/slides/_rels/slide1.xml.rels')
|
||||
const chain = archive.resolveSlideChain('ppt/slides/slide1.xml')
|
||||
expect(chain.layoutPath).toBe('ppt/slideLayouts/slideLayout1.xml')
|
||||
expect(chain.masterPath).toBe('ppt/slideMasters/slideMaster1.xml')
|
||||
expect(chain.themePath).toBe('ppt/theme/theme1.xml')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,46 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { eaScriptOfLang, parseTheme, resolveFontRef } from '../src/theme'
|
||||
|
||||
const THEME = (ea: string) => `<?xml version="1.0"?><a:theme xmlns:a="a"><a:themeElements>
|
||||
<a:clrScheme name="x"><a:dk1><a:srgbClr val="000000"/></a:dk1></a:clrScheme>
|
||||
<a:fontScheme name="x">
|
||||
<a:majorFont><a:latin typeface="Arial"/><a:ea typeface=""/><a:cs typeface=""/><a:font script="Jpan" typeface="MS Pゴシック"/><a:font script="Hang" typeface="굴림"/></a:majorFont>
|
||||
<a:minorFont><a:latin typeface="Arial"/><a:ea typeface="${ea}"/><a:cs typeface=""/><a:font script="Jpan" typeface="MS Pゴシック"/><a:font script="Hans" typeface="\u9ed1\u4f53"/></a:minorFont>
|
||||
</a:fontScheme><a:fmtScheme name="x"/></a:themeElements></a:theme>`
|
||||
|
||||
describe('theme per-script fonts', () => {
|
||||
it('parses <a:font script=…> entries per major/minor font', () => {
|
||||
const t = parseTheme(THEME(''))
|
||||
expect(t.minorEaFont).toBeUndefined()
|
||||
expect(t.minorScriptFonts).toEqual({ Jpan: 'MS Pゴシック', Hans: '\u9ed1\u4f53' })
|
||||
expect(t.majorScriptFonts).toEqual({ Jpan: 'MS Pゴシック', Hang: '굴림' })
|
||||
})
|
||||
|
||||
it('+mn-ea with an empty ea slot takes the script font for the text language, else Latin', () => {
|
||||
const t = parseTheme(THEME(''))
|
||||
expect(resolveFontRef('+mn-ea', t, 'ja')).toBe('MS Pゴシック')
|
||||
expect(resolveFontRef('+mn-ea', t, 'sc')).toBe('\u9ed1\u4f53')
|
||||
expect(resolveFontRef('+mn-ea', t, 'ko')).toBe('Arial')
|
||||
expect(resolveFontRef('+mn-ea', t)).toBe('Arial')
|
||||
expect(resolveFontRef('+mj-ea', t, 'ko')).toBe('굴림')
|
||||
})
|
||||
|
||||
it("'han' (ideographs without a language) resolves only when the theme names a single Han script", () => {
|
||||
const t = parseTheme(THEME(''))
|
||||
// minor: Jpan + Hans → ambiguous → Latin; major: Jpan only → Jpan
|
||||
expect(resolveFontRef('+mn-ea', t, 'han')).toBe('Arial')
|
||||
expect(resolveFontRef('+mj-ea', t, 'han')).toBe('MS Pゴシック')
|
||||
})
|
||||
|
||||
it('an explicit ea typeface still wins over the script entry', () => {
|
||||
const t = parseTheme(THEME('Meiryo'))
|
||||
expect(resolveFontRef('+mn-ea', t, 'ja')).toBe('Meiryo')
|
||||
})
|
||||
|
||||
it('maps lang tags to East Asian scripts', () => {
|
||||
expect(eaScriptOfLang('ja-JP')).toBe('ja')
|
||||
expect(eaScriptOfLang('zh-TW')).toBe('tc')
|
||||
expect(eaScriptOfLang('zh-CN')).toBe('sc')
|
||||
expect(eaScriptOfLang('en-US')).toBeUndefined()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user