fix(text): align font status with prepared roots
This commit is contained in:
parent
6d17b92a56
commit
e414cf77ab
|
|
@ -19,7 +19,7 @@ async function prepareFontStatus(
|
|||
fontManager.setOnlineFontProviders({})
|
||||
fontManager.setWebFontFetch(null)
|
||||
try {
|
||||
return await prepareGraphFonts(graph, pageId, [pageId])
|
||||
return await prepareGraphFonts(graph, [pageId])
|
||||
} finally {
|
||||
fontManager.setOnlineFontProviders(
|
||||
Object.fromEntries(previousProviders.map((provider) => [provider, true]))
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ export async function prepareForExport(
|
|||
const previousTextMeasurer = getTextMeasurer()
|
||||
setTextMeasurer((node, maxWidth) => r.measureTextNode(node, maxWidth))
|
||||
|
||||
await prepareGraphFonts(graph, pageId, nodeIds)
|
||||
await prepareGraphFonts(graph, nodeIds)
|
||||
syncFontGeneration(r)
|
||||
computeAllLayouts(graph, pageId)
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ export const fontStatusCommand: RPCCommand<void, DocumentFontStatus> = {
|
|||
name: 'font-status',
|
||||
execute: async (graph) => {
|
||||
const pageIds = graph.getPages().map((page) => page.id)
|
||||
return prepareGraphFonts(graph, pageIds[0] ?? graph.rootId, pageIds)
|
||||
return prepareGraphFonts(graph, pageIds)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,15 +34,15 @@ function faceKey(family: string, style: string): string {
|
|||
return `${family}\0${style}`
|
||||
}
|
||||
|
||||
function pageTextNodes(graph: SceneGraph, pageIds: readonly string[]): SceneNode[] {
|
||||
return pageIds.flatMap((pageId) =>
|
||||
graph.flattenTree(pageId).flatMap(({ node }) => (node.type === 'TEXT' ? [node] : []))
|
||||
function rootTextNodes(graph: SceneGraph, rootIds: readonly string[]): SceneNode[] {
|
||||
return rootIds.flatMap((rootId) =>
|
||||
graph.flattenTree(rootId).flatMap(({ node }) => (node.type === 'TEXT' ? [node] : []))
|
||||
)
|
||||
}
|
||||
|
||||
function collectFaceUses(graph: SceneGraph, pageIds: readonly string[]): MutableFontFaceUse[] {
|
||||
function collectFaceUses(graph: SceneGraph, rootIds: readonly string[]): MutableFontFaceUse[] {
|
||||
const uses = new Map<string, MutableFontFaceUse>()
|
||||
for (const node of pageTextNodes(graph, pageIds)) {
|
||||
for (const node of rootTextNodes(graph, rootIds)) {
|
||||
for (const { family, style } of collectNodeFontFaces(node)) {
|
||||
const key = faceKey(family, style)
|
||||
const use = uses.get(key) ?? {
|
||||
|
|
@ -99,11 +99,11 @@ function faceStatus(use: MutableFontFaceUse, manager: FontManager): DocumentFont
|
|||
|
||||
export function documentFontStatus(
|
||||
graph: SceneGraph,
|
||||
pageId: string | readonly string[],
|
||||
rootIds: string | readonly string[],
|
||||
manager: FontManager = fontManager
|
||||
): DocumentFontStatus {
|
||||
const pageIds = typeof pageId === 'string' ? [pageId] : pageId
|
||||
const faces = collectFaceUses(graph, pageIds)
|
||||
const roots = typeof rootIds === 'string' ? [rootIds] : rootIds
|
||||
const faces = collectFaceUses(graph, roots)
|
||||
.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')
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import { documentFontStatus, type DocumentFontStatus } from './font/status'
|
|||
|
||||
export async function prepareGraphFonts(
|
||||
graph: SceneGraph,
|
||||
pageId: string,
|
||||
nodeIds: readonly string[]
|
||||
): Promise<DocumentFontStatus> {
|
||||
const requirements = collectGraphFontRequirements(graph, nodeIds)
|
||||
|
|
@ -20,5 +19,5 @@ export async function prepareGraphFonts(
|
|||
missingGraphFontScripts(requirements),
|
||||
requirements.characters
|
||||
)
|
||||
return documentFontStatus(graph, pageId)
|
||||
return documentFontStatus(graph, nodeIds)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue