mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 14:31:12 +08:00
Compare commits
6
Commits
7a23dcc6dd
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb51fd3b07 | ||
|
|
80e548f93e | ||
|
|
9c3a04b7eb | ||
|
|
9bb6c9141a | ||
|
|
4320b53d4a | ||
|
|
e5d7f577c7 |
No files matched your search
+1
-1
@@ -1,5 +1,5 @@
|
||||
# 基础镜像
|
||||
FROM alpine:3.24.2
|
||||
FROM alpine:3.24.3
|
||||
|
||||
# 作者信息
|
||||
LABEL authors="肖其顿 (XIAO QI DUN)"
|
||||
|
||||
+58
-17
@@ -110,6 +110,7 @@ function createDocumentState() {
|
||||
styleOriginal: null,
|
||||
objectClipboardToken: null,
|
||||
styleClipboard: null,
|
||||
objectDistribution: null,
|
||||
outlineExpanded: new Map(),
|
||||
textFonts: [],
|
||||
textFontID: null,
|
||||
@@ -1260,7 +1261,7 @@ el.objectAlign.addEventListener("change", () => {
|
||||
el.objectDistribute.addEventListener("change", () => {
|
||||
const axis = el.objectDistribute.value;
|
||||
el.objectDistribute.value = "";
|
||||
if (axis && canvasEditor.items().length >= 3) {
|
||||
if (axis && !el.objectDistribute.disabled && state.objectDistribution?.axes?.includes(axis)) {
|
||||
return changeDocument("ofdgoDistributeObjects", canvasEditor.selected, axis);
|
||||
}
|
||||
});
|
||||
@@ -1807,6 +1808,7 @@ el.annotationButton.addEventListener("click", toggleAnnotations);
|
||||
document.addEventListener("copy", copySelection);
|
||||
document.addEventListener("cut", copySelection);
|
||||
el.viewerPanel.addEventListener("paste", pasteEditorContent);
|
||||
el.editorTools.addEventListener("paste", pasteEditorContent);
|
||||
document.addEventListener("selectionchange", syncSelection);
|
||||
el.exportFormat.addEventListener("change", () => updateDPIControl());
|
||||
el.outputCompression.addEventListener("change", () => {
|
||||
@@ -1933,6 +1935,11 @@ el.documentNewTab.addEventListener("click", openEmptyDocumentTab);
|
||||
updateSidebarState();
|
||||
boot();
|
||||
|
||||
function editorShortcutTarget(target) {
|
||||
const field = target.closest?.("input, textarea, select, [contenteditable]");
|
||||
return !field || el.editorTools.contains(field) && field.matches('select, input[type="checkbox"], input[type="radio"], input[type="color"], input[type="range"]');
|
||||
}
|
||||
|
||||
function handleKeyDown(event) {
|
||||
if (sealPreview) {
|
||||
if (event.key === "Escape") { event.preventDefault(); finishSealPosition(); }
|
||||
@@ -1994,7 +2001,7 @@ function handleKeyDown(event) {
|
||||
}
|
||||
}
|
||||
if (event.ctrlKey || event.metaKey) {
|
||||
if (state.editing && !target.closest("input, textarea, select, [contenteditable]")
|
||||
if (state.editing && editorShortcutTarget(target)
|
||||
&& (key.toLowerCase() === "z" || (!event.shiftKey && key.toLowerCase() === "y"))) {
|
||||
event.preventDefault();
|
||||
(key.toLowerCase() === "y" || event.shiftKey ? el.redoButton : el.undoButton).click();
|
||||
@@ -4353,15 +4360,15 @@ async function validateRichText(item, model, width, fonts = []) {
|
||||
attempted.add(id);
|
||||
const original = (await callWASM("ofdgoEditorFont", id)).bytes;
|
||||
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));
|
||||
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;
|
||||
for (const choice of candidates) {
|
||||
try {
|
||||
const data = await readTextFont(choice, tab);
|
||||
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(""));
|
||||
recovered = { key: id, data, choice };
|
||||
break;
|
||||
@@ -4376,8 +4383,9 @@ async function validateRichText(item, model, width, fonts = []) {
|
||||
rich.imports.set(id, recovered.data);
|
||||
rich.choices.set(id, recovered.choice);
|
||||
const previous = rich.faces.get(id);
|
||||
if (previous) document.fonts.delete(previous);
|
||||
rich.faces.set(id, face); document.fonts.add(face);
|
||||
rich.faces.set(id, 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); }
|
||||
}
|
||||
}
|
||||
@@ -4443,9 +4451,10 @@ async function beginCanvasText(index, box, surface, page) {
|
||||
const item = { ...state.textDefaults, ...box, wrap: Boolean(box.wrap),
|
||||
index, page, surface, node, text: "", draft: true, fontData: data };
|
||||
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;
|
||||
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) {
|
||||
if (isForegroundDocument(tab) && openSeq === state.openSeq) showError(err, false);
|
||||
} finally {
|
||||
@@ -4608,8 +4617,12 @@ async function prepareTextFaces(tab, runs, font, key, value, rich) {
|
||||
const candidates = [...choices.values()];
|
||||
for (const choice of candidates) {
|
||||
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));
|
||||
if (metadata) Object.assign(choice, metadata, { index: choice.index });
|
||||
try {
|
||||
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();
|
||||
for (const run of runs) {
|
||||
@@ -4675,7 +4688,9 @@ async function changeTextFace(font, key, value) {
|
||||
tab.editTask = busy;
|
||||
setBusy(true, "", 0, "", tab);
|
||||
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;
|
||||
const index = fonts.findIndex(choice => textFontIdentity(choice) === textFontIdentity(source));
|
||||
const faces = (groups.find(group => group.includes(index)) || []).map(index => fonts[index]);
|
||||
@@ -4726,6 +4741,7 @@ async function changeTextFace(font, key, value) {
|
||||
rich.faces.set(entry.key, entry.face);
|
||||
if (previous && ![...rich.faces.values()].includes(previous)) document.fonts.delete(previous);
|
||||
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);
|
||||
document.fonts.add(entry.face);
|
||||
}
|
||||
@@ -10842,8 +10858,9 @@ async function selectDocumentText() {
|
||||
|
||||
function copyEditorSelection(event) {
|
||||
const tab = documentTab(), state = tab.state;
|
||||
if (!state.editing || !canvasEditor.enabled || !canvasEditor.selected || !el.viewerPanel.contains(event.target)
|
||||
|| canvasEditor.input || canvasEditor.crop || canvasEditor.drag || document.body.hasAttribute("data-busy")) return false;
|
||||
if (!state.editing || !canvasEditor.enabled || !canvasEditor.selected || !editorShortcutTarget(event.target)
|
||||
|| !el.viewerPanel.contains(event.target) && !el.editorTools.contains(event.target)
|
||||
|| canvasEditor.input || canvasEditor.crop || canvasEditor.drag || document.body.hasAttribute("data-busy") || formDialogOpen()) return false;
|
||||
const items = canvasEditor.items().slice().sort((a, b) => a.order - b.order);
|
||||
const cut = event.type === "cut";
|
||||
if (!canEditObject(canvasEditor.selected, "copy") || cut && !canEditObject(canvasEditor.selected, "delete")) {
|
||||
@@ -10919,7 +10936,7 @@ function visiblePageBounds(index) {
|
||||
|
||||
async function pasteEditorContent(event) {
|
||||
const tab = documentTab(), state = tab.state;
|
||||
if (!state.editing || event.target.closest?.("input, textarea, select, [contenteditable]") || formDialogOpen()) return;
|
||||
if (!state.editing || !editorShortcutTarget(event.target) || formDialogOpen()) return;
|
||||
event.preventDefault();
|
||||
const token = event.clipboardData.getData(OBJECT_CLIPBOARD_TYPE);
|
||||
const files = Array.from(event.clipboardData.files);
|
||||
@@ -10988,7 +11005,7 @@ async function pasteEditorContent(event) {
|
||||
|
||||
function copySelection(event) {
|
||||
if (sealPreview) return;
|
||||
if (event.target.closest?.("input, textarea, [contenteditable]")) {
|
||||
if (!editorShortcutTarget(event.target)) {
|
||||
return;
|
||||
}
|
||||
const selection = document.getSelection();
|
||||
@@ -12737,6 +12754,30 @@ function updateEditorTools() {
|
||||
updateObjectControls(canvasEditor.selected);
|
||||
}
|
||||
|
||||
function updateObjectDistribution(item, disabled) {
|
||||
const tab = documentTab(), state = tab.state;
|
||||
const ids = item?.items?.slice().sort((a, b) => a.order - b.order).map(member => member.id) || [];
|
||||
if (disabled || ids.length < 3) state.objectDistribution = null;
|
||||
else {
|
||||
const { openSeq, wasmSeq } = state, revision = state.editorInfo?.revision;
|
||||
const key = JSON.stringify([openSeq, wasmSeq, revision, item.index, ids]);
|
||||
if (state.objectDistribution?.key !== key) {
|
||||
const request = state.objectDistribution = { key, axes: [] };
|
||||
const current = () => !tab.closed && state.objectDistribution === request && state.openSeq === openSeq && state.wasmSeq === wasmSeq && state.editorInfo?.revision === revision;
|
||||
callTabWASM(tab, "ofdgoDistributionAxes", item.index, ids).then(axes => {
|
||||
if (!current()) return;
|
||||
request.axes = axes;
|
||||
if (isForegroundDocument(tab)) updateObjectControls(canvasEditor.selected);
|
||||
}).catch(error => {
|
||||
if (current() && isForegroundDocument(tab)) showError(error, false);
|
||||
});
|
||||
}
|
||||
}
|
||||
const axes = state.objectDistribution?.axes || [];
|
||||
el.objectDistribute.disabled = disabled || !axes.length;
|
||||
for (const option of el.objectDistribute.options) if (option.value) option.disabled = !axes.includes(option.value);
|
||||
}
|
||||
|
||||
function updateObjectControls(item, reset = false) {
|
||||
const members = item?.items || (item ? [item] : []);
|
||||
const disabled = !item || Boolean(item.draft) || !state.ready || state.exporting;
|
||||
@@ -12754,7 +12795,7 @@ function updateObjectControls(item, reset = false) {
|
||||
el.cropImageButton.setAttribute("data-pressed", String(cropping));
|
||||
el.resetCropButton.textContent = cropping ? "取消" : "还原";
|
||||
el.resetCropButton.disabled = canEditObject(item, "resetCrop") ? disabled : el.cropImageButton.disabled || !cropping && (item.scoped ? !item.cropped : !item.imageBounds || ["x", "y", "width", "height"].every(key => Math.abs(item[key] - item.imageBounds[key]) < 1e-9));
|
||||
el.objectDistribute.disabled = el.objectAlign.disabled || !item.items || item.items.length < 3;
|
||||
updateObjectDistribution(item, el.objectAlign.disabled);
|
||||
el.editObjectButton.disabled = disabled || (item.items ? !item.items.every(member => member.type === "TextObject" && !member.richText)
|
||||
: !canEditObject(item, "children") && (item.type === "PathObject"
|
||||
|| !(item.type === "TextObject" && canEditObject(item, "rewriteText")) && !canEditObject(item, item.type === "TextObject" ? "textContent" : item.type === "ImageObject" ? "replaceImage" : "update")));
|
||||
|
||||
@@ -5703,6 +5703,20 @@ func (e *businessEngine) orderObjects(args []platformValue) (any, error) {
|
||||
})
|
||||
}
|
||||
|
||||
// distributionAxes 获取画布选区可用的等间距分布方向
|
||||
// 入参: args 页面索引和画布对象标识数组
|
||||
// 返回: any 可用方向, error 路径或度量错误
|
||||
func (e *businessEngine) distributionAxes(args []platformValue) (any, error) {
|
||||
if e.currentEditor == nil {
|
||||
return nil, fmt.Errorf("no document is being edited")
|
||||
}
|
||||
paths, err := e.editorTargetPaths(e.stringsFromJS(args[1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return e.currentEditor.DistributionAxes(args[0].Int(), paths)
|
||||
}
|
||||
|
||||
// distributeObjects 按指定轴等距分布选区
|
||||
// 入参: args 页面索引、对象标识数组和分布轴
|
||||
// 返回: any 文档信息, error 错误信息
|
||||
@@ -8159,6 +8173,7 @@ func (e *businessEngine) businessCommands() map[string]func([]platformValue) (an
|
||||
"ofdgoImportObjects": e.importObjects,
|
||||
"ofdgoOrderObjects": e.orderObjects,
|
||||
"ofdgoDistributeObjects": e.distributeObjects,
|
||||
"ofdgoDistributionAxes": e.distributionAxes,
|
||||
"ofdgoRotateObjects": e.rotateObjects,
|
||||
"ofdgoFlipObjects": e.flipObjects,
|
||||
"ofdgoCropImage": e.cropImage,
|
||||
|
||||
@@ -808,6 +808,40 @@ func (e *Editor) ResizeTargets(page int, paths []ObjectPath, box Box) error {
|
||||
return e.TransformTargets(page, paths, Matrix{a: sx, d: sy, e: box.X - bounds.X*sx, f: box.Y - bounds.Y*sy})
|
||||
}
|
||||
|
||||
// DistributionAxes 获取选区可保持位置顺序的等间距分布方向,不修改文档或历史
|
||||
// 入参: page 页面索引, paths 按绘制顺序排列的完整路径
|
||||
// 返回: []string 可用的horizontal和vertical方向, error 路径或度量错误
|
||||
func (e *Editor) DistributionAxes(page int, paths []ObjectPath) ([]string, error) {
|
||||
objects, annotations, groups, err := editorTargetGroups(paths)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var boxes []Box
|
||||
var positions []editorObjectPosition
|
||||
if len(groups) == 0 {
|
||||
boxes, positions, _, err = e.selectionGeometry(page, objects, annotations)
|
||||
} else {
|
||||
boxes, _, _, err = e.targetGeometry(page, paths)
|
||||
positions = make([]editorObjectPosition, len(paths))
|
||||
for i := range positions {
|
||||
positions[i].index = i
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
axes := []string{}
|
||||
if len(boxes) < 3 {
|
||||
return axes, nil
|
||||
}
|
||||
for _, axis := range []string{"horizontal", "vertical"} {
|
||||
if _, err := editorDistribution(boxes, positions, axis); err == nil {
|
||||
axes = append(axes, axis)
|
||||
}
|
||||
}
|
||||
return axes, nil
|
||||
}
|
||||
|
||||
// ArrangeTargets 对齐或等距分布跨容器选区,单选对齐页面
|
||||
// 入参: page 页面索引, paths 按绘制顺序排列的完整路径, distribute 是否分布, direction 对齐方向或分布轴
|
||||
// 返回: error 路径、方向或编辑错误
|
||||
|
||||
Reference in new issue
Block a user