mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 13:56:32 +08:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4320b53d4a | ||
|
|
e5d7f577c7 |
+19
-10
@@ -4353,15 +4353,15 @@ async function validateRichText(item, model, width, fonts = []) {
|
|||||||
attempted.add(id);
|
attempted.add(id);
|
||||||
const original = (await callWASM("ofdgoEditorFont", id)).bytes;
|
const original = (await callWASM("ofdgoEditorFont", id)).bytes;
|
||||||
const [source] = await callWASM("ofdgoFontFaces", original);
|
const [source] = await callWASM("ofdgoFontFaces", original);
|
||||||
if (!source?.postscriptName) throw error;
|
if (!source?.postscriptName || !source.familyKey) throw error;
|
||||||
await fontManager.loadFaces(data => callWASM("ofdgoFontFaces", data));
|
await fontManager.loadFaces(data => callWASM("ofdgoFontFaces", data));
|
||||||
const candidates = fontManager.editorFonts().filter(font => !font.disabled && font.postscriptName === source.postscriptName);
|
const candidates = fontManager.editorFonts().filter(font => !font.disabled && font.postscriptName === source.postscriptName && font.familyKey === source.familyKey);
|
||||||
let recovered;
|
let recovered;
|
||||||
for (const choice of candidates) {
|
for (const choice of candidates) {
|
||||||
try {
|
try {
|
||||||
const data = await readTextFont(choice, tab);
|
const data = await readTextFont(choice, tab);
|
||||||
const [face] = await callWASM("ofdgoFontFaces", data);
|
const [face] = await callWASM("ofdgoFontFaces", data);
|
||||||
if (face?.postscriptName !== source.postscriptName) continue;
|
if (face?.postscriptName !== source.postscriptName || face.familyKey !== source.familyKey) continue;
|
||||||
await callWASM("ofdgoCheckTextFont", data, model.runs.filter(run => run.format.font === id).map(run => run.text).join(""));
|
await callWASM("ofdgoCheckTextFont", data, model.runs.filter(run => run.format.font === id).map(run => run.text).join(""));
|
||||||
recovered = { key: id, data, choice };
|
recovered = { key: id, data, choice };
|
||||||
break;
|
break;
|
||||||
@@ -4376,8 +4376,9 @@ async function validateRichText(item, model, width, fonts = []) {
|
|||||||
rich.imports.set(id, recovered.data);
|
rich.imports.set(id, recovered.data);
|
||||||
rich.choices.set(id, recovered.choice);
|
rich.choices.set(id, recovered.choice);
|
||||||
const previous = rich.faces.get(id);
|
const previous = rich.faces.get(id);
|
||||||
if (previous) document.fonts.delete(previous);
|
rich.faces.set(id, face);
|
||||||
rich.faces.set(id, face); document.fonts.add(face);
|
if (previous && ![...rich.faces.values()].includes(previous)) document.fonts.delete(previous);
|
||||||
|
document.fonts.add(face);
|
||||||
if (!editing.composing && !editing.saving) { rich.selection(); rich.render(); updateObjectControls(canvasEditor.selected); }
|
if (!editing.composing && !editing.saving) { rich.selection(); rich.render(); updateObjectControls(canvasEditor.selected); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4443,9 +4444,10 @@ async function beginCanvasText(index, box, surface, page) {
|
|||||||
const item = { ...state.textDefaults, ...box, wrap: Boolean(box.wrap),
|
const item = { ...state.textDefaults, ...box, wrap: Boolean(box.wrap),
|
||||||
index, page, surface, node, text: "", draft: true, fontData: data };
|
index, page, surface, node, text: "", draft: true, fontData: data };
|
||||||
const model = { ...richTextModel(item), autoWidth: !box.wrap };
|
const model = { ...richTextModel(item), autoWidth: !box.wrap };
|
||||||
const key = `temp-font-${crypto.randomUUID()}`;
|
const key = font.embedded ? font.id.slice(9) : `temp-font-${crypto.randomUUID()}`;
|
||||||
|
const embedded = font.embedded && state.doc?.fonts?.some(font => font.id === key && font.embedded);
|
||||||
model.runs[0].format.font = key;
|
model.runs[0].format.font = key;
|
||||||
canvasEditor.editText(item, face, null, { model, faces: new Map([[key, face]]), fonts: [{ key, data }] });
|
canvasEditor.editText(item, face, null, { model, faces: new Map([[key, face]]), fonts: embedded ? [] : [{ key, data }], resources: new Map([[key, data]]) });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (isForegroundDocument(tab) && openSeq === state.openSeq) showError(err, false);
|
if (isForegroundDocument(tab) && openSeq === state.openSeq) showError(err, false);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -4608,8 +4610,12 @@ async function prepareTextFaces(tab, runs, font, key, value, rich) {
|
|||||||
const candidates = [...choices.values()];
|
const candidates = [...choices.values()];
|
||||||
for (const choice of candidates) {
|
for (const choice of candidates) {
|
||||||
if (choice.menuFamily || ![...originals.values()].some(font => textFontIdentity(font || {}) === textFontIdentity(choice)) && (!font || textFontIdentity(choice) !== textFontIdentity(font))) continue;
|
if (choice.menuFamily || ![...originals.values()].some(font => textFontIdentity(font || {}) === textFontIdentity(choice)) && (!font || textFontIdentity(choice) !== textFontIdentity(font))) continue;
|
||||||
const [metadata] = await callWASM("ofdgoFontFaces", await read(choice));
|
try {
|
||||||
if (metadata) Object.assign(choice, metadata, { index: choice.index });
|
const [metadata] = await callWASM("ofdgoFontFaces", await read(choice));
|
||||||
|
if (metadata) Object.assign(choice, metadata, { index: choice.index });
|
||||||
|
} catch (error) {
|
||||||
|
if (!current() || !font || textFontIdentity(choice) === textFontIdentity(font)) throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const groups = await groupTextFonts(candidates, tab), changes = new Map(), prepared = new Map();
|
const groups = await groupTextFonts(candidates, tab), changes = new Map(), prepared = new Map();
|
||||||
for (const run of runs) {
|
for (const run of runs) {
|
||||||
@@ -4675,7 +4681,9 @@ async function changeTextFace(font, key, value) {
|
|||||||
tab.editTask = busy;
|
tab.editTask = busy;
|
||||||
setBusy(true, "", 0, "", tab);
|
setBusy(true, "", 0, "", tab);
|
||||||
try {
|
try {
|
||||||
const fonts = fontManager.editorFonts().filter(font => font.familyKey === source.familyKey && textFontSource(font) === textFontSource(source)), groups = await groupTextFonts(fonts, tab);
|
const available = source.embedded ? (state.doc?.fonts || []).filter(font => font.embedded || font.status === "matched").map(font => documentFontChoice(font.id)) : fontManager.editorFonts();
|
||||||
|
const fonts = [source, ...available.filter(font => textFontIdentity(font) !== textFontIdentity(source))].filter(font => font.familyKey === source.familyKey && textFontSource(font) === textFontSource(source));
|
||||||
|
const groups = await groupTextFonts(fonts, tab);
|
||||||
if (!current()) return;
|
if (!current()) return;
|
||||||
const index = fonts.findIndex(choice => textFontIdentity(choice) === textFontIdentity(source));
|
const index = fonts.findIndex(choice => textFontIdentity(choice) === textFontIdentity(source));
|
||||||
const faces = (groups.find(group => group.includes(index)) || []).map(index => fonts[index]);
|
const faces = (groups.find(group => group.includes(index)) || []).map(index => fonts[index]);
|
||||||
@@ -4726,6 +4734,7 @@ async function changeTextFace(font, key, value) {
|
|||||||
rich.faces.set(entry.key, entry.face);
|
rich.faces.set(entry.key, entry.face);
|
||||||
if (previous && ![...rich.faces.values()].includes(previous)) document.fonts.delete(previous);
|
if (previous && ![...rich.faces.values()].includes(previous)) document.fonts.delete(previous);
|
||||||
if (!entry.choice.embedded) rich.imports.set(entry.key, entry.data);
|
if (!entry.choice.embedded) rich.imports.set(entry.key, entry.data);
|
||||||
|
else rich.resources.set(entry.key, entry.data);
|
||||||
rich.choices.set(entry.key, entry.choice);
|
rich.choices.set(entry.key, entry.choice);
|
||||||
document.fonts.add(entry.face);
|
document.fonts.add(entry.face);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user