fix(cli): prepare fonts across complete documents
This commit is contained in:
parent
41f445ebab
commit
7c67390707
|
|
@ -10,7 +10,7 @@ import {
|
|||
SIZE_FONT_SIZE
|
||||
} from '#core/constants'
|
||||
import { fontManager } from '#core/text/fonts'
|
||||
import { collectGraphFontRequirements } from '#core/text/requirements'
|
||||
import { collectGraphFontRequirements, collectNodeFontFaces } from '#core/text/requirements'
|
||||
import { missingGraphFontScripts } from '#core/text/resolved-requirements'
|
||||
import type { FontResolutionSnapshot } from '#core/text/resolver'
|
||||
|
||||
|
|
|
|||
|
|
@ -80,8 +80,8 @@ export const infoCommand: RPCCommand<void, InfoResult> = {
|
|||
export const fontStatusCommand: RPCCommand<void, DocumentFontStatus> = {
|
||||
name: 'font-status',
|
||||
execute: async (graph) => {
|
||||
const pageId = graph.getPages()[0]?.id ?? graph.rootId
|
||||
return prepareGraphFonts(graph, pageId, [pageId])
|
||||
const pageIds = graph.getPages().map((page) => page.id)
|
||||
return prepareGraphFonts(graph, pageIds[0] ?? graph.rootId, pageIds)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,13 +34,15 @@ function faceKey(family: string, style: string): string {
|
|||
return `${family}\0${style}`
|
||||
}
|
||||
|
||||
function pageTextNodes(graph: SceneGraph, pageId: string): SceneNode[] {
|
||||
return graph.flattenTree(pageId).flatMap(({ node }) => (node.type === 'TEXT' ? [node] : []))
|
||||
function pageTextNodes(graph: SceneGraph, pageIds: readonly string[]): SceneNode[] {
|
||||
return pageIds.flatMap((pageId) =>
|
||||
graph.flattenTree(pageId).flatMap(({ node }) => (node.type === 'TEXT' ? [node] : []))
|
||||
)
|
||||
}
|
||||
|
||||
function collectFaceUses(graph: SceneGraph, pageId: string): MutableFontFaceUse[] {
|
||||
function collectFaceUses(graph: SceneGraph, pageIds: readonly string[]): MutableFontFaceUse[] {
|
||||
const uses = new Map<string, MutableFontFaceUse>()
|
||||
for (const node of pageTextNodes(graph, pageId)) {
|
||||
for (const node of pageTextNodes(graph, pageIds)) {
|
||||
for (const { family, style } of collectNodeFontFaces(node)) {
|
||||
const key = faceKey(family, style)
|
||||
const use = uses.get(key) ?? {
|
||||
|
|
@ -97,10 +99,11 @@ function faceStatus(use: MutableFontFaceUse, manager: FontManager): DocumentFont
|
|||
|
||||
export function documentFontStatus(
|
||||
graph: SceneGraph,
|
||||
pageId: string,
|
||||
pageId: string | readonly string[],
|
||||
manager: FontManager = fontManager
|
||||
): DocumentFontStatus {
|
||||
const faces = collectFaceUses(graph, pageId)
|
||||
const pageIds = typeof pageId === 'string' ? [pageId] : pageId
|
||||
const faces = collectFaceUses(graph, pageIds)
|
||||
.map((use) => faceStatus(use, manager))
|
||||
.sort((a, b) => a.family.localeCompare(b.family) || a.style.localeCompare(b.style))
|
||||
const issues = faces.filter((face) => face.status !== 'available')
|
||||
|
|
|
|||
|
|
@ -20,6 +20,5 @@ export async function prepareGraphFonts(
|
|||
missingGraphFontScripts(requirements),
|
||||
requirements.characters
|
||||
)
|
||||
const status = documentFontStatus(graph, pageId)
|
||||
return status
|
||||
return documentFontStatus(graph, pageId)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue