mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 08:46:55 +08:00
fix(编辑能力): 修复文本框留白与缩放异常
This commit is contained in:
1 parent
48d1d29b7e
commit
1215f7aa08
3 files changed
+9
-10
No files matched your search
@@ -1037,7 +1037,7 @@ export class CanvasEditor {
|
|||||||
const handles = !canEditObject(item, "transform") ? [] : lineShape(item.shape) ? ["start", "end"]
|
const handles = !canEditObject(item, "transform") ? [] : lineShape(item.shape) ? ["start", "end"]
|
||||||
: item.shape || item.oriented || canEditObject(item, "stretch") ? ["nw", "n", "ne", "e", "se", "s", "sw", "w"]
|
: item.shape || item.oriented || canEditObject(item, "stretch") ? ["nw", "n", "ne", "e", "se", "s", "sw", "w"]
|
||||||
: item.type === "TextObject" && canEditObject(item, "reflow") && canEditObject(item, "layoutKnown")
|
: item.type === "TextObject" && canEditObject(item, "reflow") && canEditObject(item, "layoutKnown")
|
||||||
? ["nw", "n", "ne", "e", "se", "s", "sw", "w"] : ["nw", "ne", "sw", "se"];
|
? ["w", "e"] : ["nw", "ne", "sw", "se"];
|
||||||
for (const corner of handles) {
|
for (const corner of handles) {
|
||||||
const handle = document.createElement("span");
|
const handle = document.createElement("span");
|
||||||
handle.className = `edit-handle edit-${corner}`;
|
handle.className = `edit-handle edit-${corner}`;
|
||||||
|
|||||||
@@ -4956,11 +4956,12 @@ func (e *businessEngine) editorRichText(item map[string]any, object ofdgo.Graphi
|
|||||||
if len(value.Runs) == 0 || object.CompositeGraphicUnit.Clips != nil {
|
if len(value.Runs) == 0 || object.CompositeGraphicUnit.Clips != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
width, height := local.W, local.H
|
width := local.W
|
||||||
_, contentBounds, err := e.currentEditor.LayoutRichText(value, width)
|
_, contentBounds, err := e.currentEditor.LayoutRichText(value, width)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
height := contentBounds.Y + contentBounds.H
|
||||||
format, layout := value.Runs[0].Format, value.Layout
|
format, layout := value.Runs[0].Format, value.Layout
|
||||||
selection := contentBounds
|
selection := contentBounds
|
||||||
if !value.AutoWidth || layout.Wrap {
|
if !value.AutoWidth || layout.Wrap {
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ type richTextIndex struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddRichText 原子添加标准组合及持久化编辑标引,成功时只产生一条历史
|
// AddRichText 原子添加标准组合及持久化编辑标引,成功时只产生一条历史
|
||||||
|
// 按给定宽度排版,高度随内容自适应
|
||||||
// 入参: page 页面索引, box 页面编辑框, value 富文本内容
|
// 入参: page 页面索引, box 页面编辑框, value 富文本内容
|
||||||
// 返回: string 组合对象标识, error 排版、资源或持久化错误
|
// 返回: string 组合对象标识, error 排版、资源或持久化错误
|
||||||
func (e *Editor) AddRichText(page int, box Box, value RichText) (string, error) {
|
func (e *Editor) AddRichText(page int, box Box, value RichText) (string, error) {
|
||||||
@@ -96,7 +97,7 @@ func (e *Editor) AddRichText(page int, box Box, value RichText) (string, error)
|
|||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateRichText 原子替换富文本内容,保留对象标识、局部编辑框及页面变换
|
// UpdateRichText 原子替换富文本内容,保留对象标识、段落宽度及页面变换,高度随内容调整
|
||||||
// 安全普通文字显式重排后提升为组合;不修改共享的旧组合资源
|
// 安全普通文字显式重排后提升为组合;不修改共享的旧组合资源
|
||||||
// 入参: page 页面索引, id 对象标识, value 完整富文本
|
// 入参: page 页面索引, id 对象标识, value 完整富文本
|
||||||
// 返回: error 识别、排版或提交错误
|
// 返回: error 识别、排版或提交错误
|
||||||
@@ -452,7 +453,7 @@ func (e *Editor) putCompositeRichTextCopies(page int, path ObjectPath, indexes [
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepareRichText 构造独立组合资源和不含字体编号的编辑标引
|
// prepareRichText 构造独立组合资源和不含字体编号的编辑标引,高度随排版内容自适应
|
||||||
// 入参: box 页面或局部编辑框, value 富文本
|
// 入参: box 页面或局部编辑框, value 富文本
|
||||||
// 返回: GraphicObject 标准组合, richTextMetadata 标引, error 准备错误
|
// 返回: GraphicObject 标准组合, richTextMetadata 标引, error 准备错误
|
||||||
func (e *Editor) prepareRichText(box Box, value RichText) (GraphicObject, richTextMetadata, error) {
|
func (e *Editor) prepareRichText(box Box, value RichText) (GraphicObject, richTextMetadata, error) {
|
||||||
@@ -466,12 +467,9 @@ func (e *Editor) prepareRichText(box Box, value RichText) (GraphicObject, richTe
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return GraphicObject{}, richTextMetadata{}, err
|
return GraphicObject{}, richTextMetadata{}, err
|
||||||
}
|
}
|
||||||
box.W = result.width
|
box.W, box.H = result.width, result.bounds.Y+result.bounds.H
|
||||||
if value.AutoWidth && !value.Layout.Wrap {
|
|
||||||
box.H = result.bounds.Y + result.bounds.H
|
|
||||||
}
|
|
||||||
padX, padY := -min(0, result.bounds.X), -min(0, result.bounds.Y)
|
padX, padY := -min(0, result.bounds.X), -min(0, result.bounds.Y)
|
||||||
extent := Box{W: max(box.W, result.bounds.X+result.bounds.W) + padX, H: max(box.H, result.bounds.Y+result.bounds.H) + padY}
|
extent := Box{W: max(box.W, result.bounds.X+result.bounds.W) + padX, H: box.H + padY}
|
||||||
if !finite(extent.W) || !finite(extent.H) || extent.W <= 0 || extent.H <= 0 {
|
if !finite(extent.W) || !finite(extent.H) || extent.W <= 0 || extent.H <= 0 {
|
||||||
return GraphicObject{}, richTextMetadata{}, fmt.Errorf("rich text extent exceeds finite range")
|
return GraphicObject{}, richTextMetadata{}, fmt.Errorf("rich text extent exceeds finite range")
|
||||||
}
|
}
|
||||||
@@ -494,7 +492,7 @@ func (e *Editor) prepareRichText(box Box, value RichText) (GraphicObject, richTe
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return GraphicObject{}, richTextMetadata{}, err
|
return GraphicObject{}, richTextMetadata{}, err
|
||||||
}
|
}
|
||||||
meta := richTextMetadata{Version: 1, Value: cloneEditorData(value), Frame: Box{W: box.W, H: max(box.H, result.bounds.Y+result.bounds.H)}, Extent: extent, Offset: [2]float64{padX, padY}, Anchors: result.anchors, Digest: richTextDigest(unit.object.CompositeGraphicUnit.Objects)}
|
meta := richTextMetadata{Version: 1, Value: cloneEditorData(value), Frame: Box{W: box.W, H: box.H}, Extent: extent, Offset: [2]float64{padX, padY}, Anchors: result.anchors, Digest: richTextDigest(unit.object.CompositeGraphicUnit.Objects)}
|
||||||
for i := range meta.Value.Runs {
|
for i := range meta.Value.Runs {
|
||||||
meta.Value.Runs[i].Format.Font = ""
|
meta.Value.Runs[i].Format.Font = ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user