mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 08:46:55 +08:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4429b126a | ||
|
|
50898934dc |
No files matched your search
+21
-13
@@ -4351,10 +4351,16 @@ async function beginCanvasText(index, box, surface, page) {
|
||||
|
||||
function editorFonts(item) {
|
||||
const fonts = fontManager.editorFonts();
|
||||
if (item) {
|
||||
fonts.unshift({ id: `embedded:${item.font}`, name: item.fontName || item.font, embedded: true, disabled: !canEditObject(item, "textContent") });
|
||||
const embedded = new Map();
|
||||
for (const member of item?.items || (item ? [item] : [])) {
|
||||
for (const id of member.richText ? member.richText.runs.map(run => run.format.font) : [member.font]) {
|
||||
if (!id || embedded.has(id)) continue;
|
||||
const font = state.doc?.fonts?.find(font => font.id === id);
|
||||
embedded.set(id, { id: `embedded:${id}`, name: font?.fontName || (id === member.font ? member.fontName : "") || id,
|
||||
embedded: true, disabled: !canEditObject(member, "textContent") });
|
||||
}
|
||||
}
|
||||
return fonts;
|
||||
return [...embedded.values(), ...fonts];
|
||||
}
|
||||
|
||||
async function loadEditorFonts() {
|
||||
@@ -4417,21 +4423,23 @@ function updateTextFonts(item, refresh = false) {
|
||||
if (document.activeElement === el.textFont && fontPicker.open) return;
|
||||
state.textFontID = key;
|
||||
state.textFonts = editorFonts(null);
|
||||
for (const [font, face] of rich.faces) {
|
||||
for (const font of rich.faces.keys()) {
|
||||
const choice = rich.choices?.get(font);
|
||||
state.textFonts.unshift(choice || { id: `embedded:${font}`, name: font === rich.editing.item.font ? rich.editing.item.fontName || font : face.family, embedded: !rich.imports.has(font), richKey: font });
|
||||
state.textFonts.unshift({ ...(choice || { id: `embedded:${font}`,
|
||||
name: state.doc?.fonts?.find(value => value.id === font)?.fontName || (font === rich.editing.item.font ? rich.editing.item.fontName : "") || font,
|
||||
embedded: !rich.imports.has(font) }), richKey: font });
|
||||
}
|
||||
fontPicker.setFonts(state.textFonts, id === undefined ? null : state.textFonts.find(font => font.richKey === id || rich.choices?.get(id) === font));
|
||||
fontPicker.setFonts(state.textFonts, id === undefined ? null : state.textFonts.find(font => font.richKey === id));
|
||||
el.textFont.placeholder = id === undefined ? "混合" : "";
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (item?.richText) item = { ...item, font: currentTextStyle().font };
|
||||
const id = item?.type === "TextObject" && !item.draft ? item.font : null;
|
||||
const key = item?.items ? `selection:${item.items.map(member => member.id).join(",")}:${id || ""}` : id;
|
||||
const id = item?.type === "TextObject" && !item.draft ? item.richText ? currentTextStyle().font : item.font : null;
|
||||
const key = item?.items ? `selection:${item.items.map(member => member.id).join(",")}:${id || ""}`
|
||||
: item?.richText ? `rich:${item.id}:${item.richText.runs.map(run => run.format.font).join(",")}` : id;
|
||||
if (refresh || state.textFontID !== key) {
|
||||
state.textFontID = key;
|
||||
state.textFonts = editorFonts(id ? item : null);
|
||||
state.textFonts = editorFonts(item?.type === "TextObject" && !item.draft ? item : null);
|
||||
const selected = canvasEditor.input?.fontChoice || (id ? state.textFonts[0] : state.textDefaults.fontChoice);
|
||||
if (selected && (canvasEditor.input || selected.embedded)
|
||||
&& !state.textFonts.some(font => (font.id || font.postscriptName) === (selected.id || selected.postscriptName))) {
|
||||
@@ -4473,7 +4481,7 @@ async function changeTextFont() {
|
||||
await face.load();
|
||||
if (!isForegroundDocument(tab) || openSeq !== state.openSeq || canvasEditor.input !== editing) return;
|
||||
editing.fontChoice = font;
|
||||
if (item.draft) state.textDefaults.fontChoice = font;
|
||||
if (item.draft && !font.richKey) state.textDefaults.fontChoice = font;
|
||||
if (editing.rich) {
|
||||
const key = font.richKey || (font.embedded ? font.id.slice(9) : `temp-font-${crypto.randomUUID()}`);
|
||||
editing.rich.choices ||= new Map();
|
||||
@@ -4490,8 +4498,8 @@ async function changeTextFont() {
|
||||
setBusy(false, "", 0, "", tab);
|
||||
}
|
||||
} else if (item?.type === "TextObject") {
|
||||
if (canEditObject(item, "replaceFont") && (!font.embedded || item.font !== font.id.slice(9))) {
|
||||
const changed = await changeDocument("ofdgoStyleText", { ...item, id: (item.items || [item]).map(member => member.id) }, readTextFont(font, tab), 0, null);
|
||||
if (canEditObject(item, "replaceFont") && (!font.embedded || currentTextStyle().font !== font.id.slice(9))) {
|
||||
const changed = await changeDocument("ofdgoStyleText", { ...item, id: (item.items || [item]).map(member => member.id) }, () => readTextFont(font, tab), 0, null);
|
||||
if (isForegroundDocument(tab) && (changed || openSeq === state.openSeq)) updateTextFonts(canvasEditor.selected, true);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -413,7 +413,9 @@ export class RichTextSession {
|
||||
}
|
||||
setFont(face, data, key) {
|
||||
key ||= `temp-font-${crypto.randomUUID()}`;
|
||||
const previous = this.faces.get(key);
|
||||
this.faces.set(key, face);
|
||||
if (previous && ![...this.faces.values()].includes(previous)) document.fonts.delete(previous);
|
||||
if (data) this.imports.set(key, data);
|
||||
document.fonts.add(face);
|
||||
this.apply({ font: key });
|
||||
|
||||
@@ -31,7 +31,7 @@ export class FontPicker {
|
||||
const name = (font.fullName || font.name).normalize("NFKC").toLocaleLowerCase();
|
||||
this.names.set(name, (this.names.get(name) || 0) + 1);
|
||||
}
|
||||
const key = font => font?.id || font?.postscriptName;
|
||||
const key = font => font?.richKey || font?.id || font?.postscriptName;
|
||||
this.value = !fonts.length ? "" : selected === null ? "-1" : String(Math.max(0, fonts.findIndex(font => key(font) === key(selected))));
|
||||
this.restore();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user