浏览代码

[1.5.4] Upgrade text painter.

/main
Yuncong Zhang 5 年前
当前提交
150ccf5e
共有 3 个文件被更改,包括 83 次插入21 次删除
  1. 20
      Runtime/painting/notched_shapes.cs
  2. 65
      Runtime/painting/text_painter.cs
  3. 19
      Runtime/ui/painting/path.cs

20
Runtime/painting/notched_shapes.cs


return ret;
}
}
class AutomaticNotchedShape : NotchedShape {
public AutomaticNotchedShape(ShapeBorder host, ShapeBorder guest = null) {
this.host = host;
this.guest = guest;
}
public readonly ShapeBorder host;
public readonly ShapeBorder guest;
public override Path getOuterPath(Rect hostRect, Rect guestRect) {
Path hostPath = this.host.getOuterPath(hostRect);
if (this.guest != null && guestRect != null) {
Path guestPath = this.guest.getOuterPath(guestRect);
return Path.combine(PathOperation.difference, hostPath, guestPath);
}
return hostPath;
}
}
}

65
Runtime/painting/text_painter.cs


using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;

namespace Unity.UIWidgets.painting {
class _CaretMetrics {
public _CaretMetrics(Offset offset, float? fullHeight) {
this.offset = offset;
this.fullHeight = fullHeight;
}
public Offset offset;
public float? fullHeight;
}
public class TextPainter {
TextSpan _text;
TextAlign _textAlign;

}
public Offset getOffsetForCaret(TextPosition position, Rect caretPrototype) {
this._computeCaretMetrics(position, caretPrototype);
return this._caretMetrics.offset;
}
_CaretMetrics _caretMetrics;
TextPosition _previousCaretPosition;
Rect _previousCaretPrototype;
void _computeCaretMetrics(TextPosition position, Rect caretPrototype) {
if (position == this._previousCaretPosition && caretPrototype == this._previousCaretPrototype) {
return;
}
if (offset > 0) {
var prevCodeUnit = this._text.codeUnitAt(offset);
if (prevCodeUnit == null) // out of upper bounds
{
var rectNextLine = this._paragraph.getNextLineStartRect();
if (rectNextLine != null) {
return new Offset(rectNextLine.start, rectNextLine.top);
}
}
}
Rect rect;
return this._getOffsetFromUpstream(offset, caretPrototype) ??
this._getOffsetFromDownstream(offset, caretPrototype) ?? this._emptyOffset;
rect = this._getRectFromUpstream(offset, caretPrototype) ??
this._getRectFromDownStream(offset, caretPrototype);
break;
return this._getOffsetFromDownstream(offset, caretPrototype) ??
this._getOffsetFromUpstream(offset, caretPrototype) ?? this._emptyOffset;
rect = this._getRectFromDownStream(offset, caretPrototype) ??
this._getRectFromUpstream(offset, caretPrototype);
break;
default:
throw new UIWidgetsError("Unknown Position Affinity");
return null;
this._caretMetrics = new _CaretMetrics(
offset: rect != null ? new Offset(rect.left, rect.top) : this._emptyOffset,
fullHeight: rect != null ? (float?) (rect.bottom - rect.top) : null);
}
public Paragraph.LineRange getLineRange(int lineNumber) {

const int _zwjUtf16 = 0x200d;
Offset _getOffsetFromUpstream(int offset, Rect caretPrototype) {
Rect _getRectFromUpstream(int offset, Rect caretPrototype) {
string flattenedText = this._text.toPlainText();
var prevCodeUnit = this._text.codeUnitAt(Mathf.Max(0, offset - 1));
if (prevCodeUnit == null) {

TextBox box = boxes[0];
const int NEWLINE_CODE_UNIT = 10;
if (prevCodeUnit == NEWLINE_CODE_UNIT) {
return new Offset(this._emptyOffset.dx, box.bottom);
return Rect.fromLTRB(this._emptyOffset.dx, box.bottom,
this._emptyOffset.dx, box.bottom + box.bottom - box.top);
return new Offset(dx, box.top);
return Rect.fromLTRB(Mathf.Min(dx, this.width), box.top,
Mathf.Min(dx, this.width), box.bottom);
Offset _getOffsetFromDownstream(int offset, Rect caretPrototype) {
Rect _getRectFromDownStream(int offset, Rect caretPrototype) {
string flattenedText = this._text.toPlainText();
var nextCodeUnit =
this._text.codeUnitAt(Mathf.Min(offset, flattenedText == null ? 0 : flattenedText.Length - 1));

TextBox box = boxes[boxes.Count - 1];
float caretStart = box.start;
float dx = box.direction == TextDirection.rtl ? caretStart - caretPrototype.width : caretStart;
return new Offset(dx, box.top);
return Rect.fromLTRB(Mathf.Min(dx, this.width), box.top,
Mathf.Min(dx, this.width), box.bottom);
}
return null;

19
Runtime/ui/painting/path.cs


using Vector3 = UnityEngine.Vector3;
namespace Unity.UIWidgets.ui {
public enum PathOperation {
difference,
intersect,
union,
xor,
reverseDifference,
}
public class Path {
const float _KAPPA90 = 0.5522847493f;

}
return Rect.fromLTRB(this._minX, this._minY, this._maxX, this._maxY);
}
public static Path combine(PathOperation operation, Path path1, Path path2) {
D.assert(path1 != null);
D.assert(path2 != null);
Path path = new Path();
throw new UIWidgetsError("Path._op() not implemented yet!");
// if (path._op(path1, path2, (int) operation)) {
// return path;
// }
// throw new UIWidgetsError("Path.combine() failed. This may be due an invalid path; " +
// "in particular, check for NaN values.");
}
void _appendMoveTo(float x, float y) {

正在加载...
取消
保存