feat: 实现 DOCX 可编辑字体嵌入
This commit is contained in:
@@ -31,6 +31,7 @@ const themeTokenReportPath = path.join(
|
||||
"snapshots.json"
|
||||
);
|
||||
const decoder = new TextDecoder();
|
||||
const sharedFontSourcePrefix = "theme-shared:";
|
||||
const placeholderPng = Buffer.from(
|
||||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=",
|
||||
"base64"
|
||||
@@ -104,6 +105,33 @@ function readThemeManifests() {
|
||||
);
|
||||
}
|
||||
|
||||
function readThemeFonts(theme) {
|
||||
return (theme.docxFonts?.faces ?? []).map((face) => {
|
||||
const shared = face.source.startsWith(sharedFontSourcePrefix);
|
||||
const relativePath = shared
|
||||
? path.join(
|
||||
"_shared",
|
||||
face.source.slice(sharedFontSourcePrefix.length)
|
||||
)
|
||||
: path.join(theme.id, face.source);
|
||||
const sourcePath = path.resolve(themesDirectory, relativePath);
|
||||
const relativeSourcePath = path.relative(
|
||||
themesDirectory,
|
||||
sourcePath
|
||||
);
|
||||
assert(
|
||||
relativeSourcePath !== ".." &&
|
||||
!relativeSourcePath.startsWith(`..${path.sep}`) &&
|
||||
!path.isAbsolute(relativeSourcePath),
|
||||
`字体资源路径越界:${face.source}`
|
||||
);
|
||||
return {
|
||||
...face,
|
||||
content: fs.readFileSync(sourcePath)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function structuralValues(document) {
|
||||
if (!document) {
|
||||
return [];
|
||||
@@ -393,6 +421,7 @@ for (const theme of themes) {
|
||||
themeTokens,
|
||||
metadata: rendered.metadata,
|
||||
semanticDocument: rendered.semanticDocument,
|
||||
fonts: readThemeFonts(theme),
|
||||
media: createMedia(markdown)
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user