mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 17:27:08 +08:00
This commit is contained in:
1 parent
bf27afea13
commit
f924f008a3
9 files changed
+105
-29
No files matched your search
+12
-3
@@ -858,16 +858,21 @@ func (e *Editor) LayoutText(obj *TextObject, value string, options TextLayout) e
|
||||
lineHeight = math.Max(obj.Size, float64(int(ascender)-int(descender)+int(gap))*unit)
|
||||
}
|
||||
var codes []TextCode
|
||||
var missing []rune
|
||||
for _, paragraph := range strings.Split(value, "\n") {
|
||||
runes := []rune(paragraph)
|
||||
advances := make([]float64, len(runes))
|
||||
for i, char := range runes {
|
||||
glyph := sfnt.GlyphIndex(char)
|
||||
if glyph == 0 {
|
||||
return fmt.Errorf("font does not contain U+%04X", char)
|
||||
missing = append(missing, char)
|
||||
continue
|
||||
}
|
||||
advances[i] = float64(sfnt.GlyphAdvance(glyph)) * unit * hScale
|
||||
}
|
||||
if len(missing) != 0 {
|
||||
continue
|
||||
}
|
||||
spaceTextAdvances(runes, advances, options.LetterSpacing)
|
||||
for _, advance := range advances {
|
||||
if !finite(advance) {
|
||||
@@ -884,6 +889,9 @@ func (e *Editor) LayoutText(obj *TextObject, value string, options TextLayout) e
|
||||
codes = append(codes, TextCode{X: ofdNumber(x), Y: ofdNumber(y), DeltaX: deltas, Value: escapeOFDText(string(runes[line[0]:line[1]]))})
|
||||
}
|
||||
}
|
||||
if err := missingGlyphError(obj.Font, missing); err != nil {
|
||||
return err
|
||||
}
|
||||
obj.TextCode = codes
|
||||
obj.layout = nil
|
||||
if options != (TextLayout{}) || e.objectOrigin(obj.ID) != nil {
|
||||
@@ -918,6 +926,7 @@ func (e *Editor) prepareText(obj *TextObject) error {
|
||||
}
|
||||
}
|
||||
obj.TextCode = append([]TextCode(nil), obj.TextCode...)
|
||||
var missing []rune
|
||||
x, y := "", ""
|
||||
for i := range obj.TextCode {
|
||||
code := &obj.TextCode[i]
|
||||
@@ -939,7 +948,7 @@ func (e *Editor) prepareText(obj *TextObject) error {
|
||||
runes := textCodeRunes(code.Value)
|
||||
for _, char := range runes {
|
||||
if sfnt.GlyphIndex(char) == 0 {
|
||||
return fmt.Errorf("font does not contain U+%04X", char)
|
||||
missing = append(missing, char)
|
||||
}
|
||||
}
|
||||
for _, delta := range []string{code.DeltaX, code.DeltaY} {
|
||||
@@ -957,7 +966,7 @@ func (e *Editor) prepareText(obj *TextObject) error {
|
||||
if strings.Trim(obj.Text(), "\n") == "" {
|
||||
return fmt.Errorf("text codes are empty")
|
||||
}
|
||||
return nil
|
||||
return missingGlyphError(obj.Font, missing)
|
||||
}
|
||||
|
||||
// creationDeltas 校验文字位移数组及g重复编码
|
||||
|
||||
Reference in new issue
Block a user