浏览代码

performance improvements...

/main
kg 6 年前
当前提交
a2e4c27c
共有 19 个文件被更改,包括 270 次插入262 次删除
  1. 27
      Runtime/foundation/basic_types.cs
  2. 2
      Runtime/material/user_accounts_drawer_header.cs
  3. 2
      Runtime/physics/friction_simulation.cs
  4. 16
      Runtime/physics/spring_simulation.cs
  5. 10
      Runtime/rendering/editable.cs
  6. 4
      Runtime/rendering/paragraph.cs
  7. 5
      Runtime/service/text_formatter.cs
  8. 2
      Runtime/ui/painting/canvas_impl.cs
  9. 112
      Runtime/ui/painting/path.cs
  10. 187
      Runtime/ui/painting/txt/font_manager.cs
  11. 12
      Runtime/ui/painting/txt/mesh_generator.cs
  12. 2
      Runtime/ui/text.cs
  13. 58
      Runtime/ui/txt/layout.cs
  14. 10
      Runtime/ui/txt/linebreaker.cs
  15. 4
      Runtime/ui/txt/paint_record.cs
  16. 7
      Runtime/ui/txt/paragraph.cs
  17. 4
      Runtime/ui/txt/text_buff.cs
  18. 2
      Runtime/ui/txt/wordbreaker.cs
  19. 66
      Runtime/ui/painting/NoAllocHelpers.cs

27
Runtime/foundation/basic_types.cs


using System;
using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.ui;
using UnityEngine;
using Object = UnityEngine.Object;

return "{ " + string.Join(", ", it.Select(item => item.ToString())) + " }";
}
public static void resize<T>(this List<T> list, int size, T value) {
int curSize = list.Count;
if (size < curSize) {
list.RemoveRange(size, curSize - size);
} else if(size > curSize) {
if (size > list.Capacity) {
list.Capacity = size;
}
list.AddRange(Enumerable.Repeat(value, size - curSize));
}
int remains = Math.Min(curSize, size);
for (int i = 0; i < remains; ++i) {
list[i] = value;
}
public static void reset<T>(this List<T> list, int size) {
NoAllocHelpers<T>.EnsureListElemCount(list, size);
}
public static ref T refAt<T>(this List<T> list, int index) {
var array = NoAllocHelpers<T>.ExtractArrayFromListT(list);
return ref array[index];
}
public static T[] array<T>(this List<T> list) {
return NoAllocHelpers<T>.ExtractArrayFromListT(list);
}
}
}

2
Runtime/material/user_accounts_drawer_header.cs


right: 0.0f,
child: new Row(
children: (this.otherAccountsPictures ?? new List<Widget> { })
.GetRange(0, Math.Min(3, this.otherAccountsPictures?.Count ?? 0))
.GetRange(0, Mathf.Min(3, this.otherAccountsPictures?.Count ?? 0))
.Select<Widget, Widget>(
(Widget picture) => {
return new Padding(

2
Runtime/physics/friction_simulation.cs


readonly float _v;
static float _dragFor(float startPosition, float endPosition, float startVelocity, float endVelocity) {
return Mathf.Pow((float) Math.E, (startVelocity - endVelocity) / (startPosition - endPosition));
return Mathf.Pow( Mathf.Epsilon, (startVelocity - endVelocity) / (startPosition - endPosition));
}
public override float x(float time) {

16
Runtime/physics/spring_simulation.cs


readonly float _r, _c1, _c2;
public override float x(float time) {
return ((this._c1 + this._c2 * time) * Mathf.Pow((float) Math.E, this._r * time));
return ((this._c1 + this._c2 * time) * Mathf.Pow(Mathf.Epsilon, this._r * time));
float power = Mathf.Pow((float) Math.E, this._r * time);
float power = Mathf.Pow(Mathf.Epsilon, this._r * time);
return (this._r * (this._c1 + this._c2 * time) * power + this._c2 * power);
}

readonly float _r1, _r2, _c1, _c2;
public override float x(float time) {
return (this._c1 * Mathf.Pow((float) Math.E, this._r1 * time) +
this._c2 * Mathf.Pow((float) Math.E, this._r2 * time));
return (this._c1 * Mathf.Pow(Mathf.Epsilon, this._r1 * time) +
this._c2 * Mathf.Pow(Mathf.Epsilon, this._r2 * time));
return (this._c1 * this._r1 * Mathf.Pow((float) Math.E, this._r1 * time) +
this._c2 * this._r2 * Mathf.Pow((float) Math.E, this._r2 * time));
return (this._c1 * this._r1 * Mathf.Pow(Mathf.Epsilon, this._r1 * time) +
this._c2 * this._r2 * Mathf.Pow(Mathf.Epsilon, this._r2 * time));
}
public override SpringType type {

readonly float _w, _r, _c1, _c2;
public override float x(float time) {
return (Mathf.Pow((float) Math.E, this._r * time) *
return (Mathf.Pow(Mathf.Epsilon, this._r * time) *
float power = Mathf.Pow((float) Math.E, this._r * time);
float power = Mathf.Pow(Mathf.Epsilon, this._r * time);
float cosine = Mathf.Cos(this._w * time);
float sine = Mathf.Sin(this._w * time);
return (power * (this._c2 * this._w * cosine - this._c1 * this._w * sine) +

10
Runtime/rendering/editable.cs


public TextPosition getParagraphBackward(TextPosition position, TextAffinity? affinity = null) {
var lineCount = this._textPainter.getLineCount();
Paragraph.LineRange line = null;
if (lineCount == 0) {
return new TextPosition(position.offset, affinity ?? position.affinity);
}
Paragraph.LineRange line = default;
for (int i = lineCount - 1; i >= 0; --i) {
line = this._textPainter.getLineRange(i);
if (i != 0 && !this._textPainter.getLineRange(i - 1).hardBreak) {

int baseOffset = fromPosition.offset;
int extentOffset = fromPosition.offset;
if (toPosition != null) {
baseOffset = Math.Min(fromPosition.offset, toPosition.offset);
extentOffset = Math.Max(fromPosition.offset, toPosition.offset);
baseOffset = Mathf.Min(fromPosition.offset, toPosition.offset);
extentOffset = Mathf.Max(fromPosition.offset, toPosition.offset);
}
TextSelection newSelection = new TextSelection(

4
Runtime/rendering/paragraph.cs


int baseOffset = fromPosition.offset;
int extentOffset = fromPosition.offset;
if (toPosition != null) {
baseOffset = Math.Min(fromPosition.offset, toPosition.offset);
extentOffset = Math.Max(fromPosition.offset, toPosition.offset);
baseOffset = Mathf.Min(fromPosition.offset, toPosition.offset);
extentOffset = Mathf.Max(fromPosition.offset, toPosition.offset);
}
TextSelection newSelection = new TextSelection(

5
Runtime/service/text_formatter.cs


using System;
using System.Text.RegularExpressions;
using Unity.UIWidgets.foundation;
using UnityEngine;
namespace Unity.UIWidgets.service {
public abstract class TextInputFormatter {

public override TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
if (this.maxLength != null && this.maxLength > 0 && newValue.text.Length > this.maxLength) {
TextSelection newSelection = newValue.selection.copyWith(
baseOffset: Math.Min(newValue.selection.start, this.maxLength.Value),
extentOffset: Math.Min(newValue.selection.end, this.maxLength.Value)
baseOffset: Mathf.Min(newValue.selection.start, this.maxLength.Value),
extentOffset: Mathf.Min(newValue.selection.end, this.maxLength.Value)
);
string truncated = newValue.text.Substring(0, this.maxLength.Value);

2
Runtime/ui/painting/canvas_impl.cs


// request font texture so text mesh could be generated correctly
var style = textBlob.style;
var font = FontManager.instance.getOrCreate(textBlob.style.fontFamily, style.fontWeight, style.fontStyle).font;
var font = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font;
var fontSizeToLoad = Mathf.CeilToInt(style.UnityFontSize * scale);
var subText = textBlob.text.Substring(textBlob.textOffset, textBlob.textSize);
font.RequestCharactersInTextureSafe(subText, fontSizeToLoad, style.UnityFontStyle);

112
Runtime/ui/painting/path.cs


innerBevel = 0x08,
}
class PathPoint {
struct PathPoint {
public float x, y;
public float dx, dy;
public float len;

class PathPath {
struct PathPath {
public int first;
public int count;
public bool closed;

this.addPath();
this.addPoint(0, 0, PointFlags.corner);
}
var path = this._paths[this._paths.Count - 1];
ref var path = ref this._paths.refAt(this._paths.Count - 1);
var pt = this._points[this._points.Count - 1];
ref var pt = ref this._points.refAt(this._points.Count - 1);
if (PathUtils.ptEquals(pt.x, pt.y, point.x, point.y, this._distTol)) {
pt.flags |= point.flags;
return;

y1 = 0;
}
else {
var pt = this._points[this._points.Count - 1];
ref var pt = ref this._points.refAt(this._points.Count - 1);
x1 = pt.x;
y1 = pt.y;
}

return;
}
var path = this._paths[this._paths.Count - 1];
ref var path = ref this._paths.refAt(this._paths.Count - 1);
path.closed = true;
}

}
var path = this._paths[this._paths.Count - 1];
ref var path = ref this._paths.refAt(this._paths.Count - 1);
for (var j = 0; j < this._paths.Count; j++) {
var path = this._paths[j];
var points = this._points.array();
var paths = this._paths.array();
for (var j = 0; j < paths.Length; j++) {
ref var path = ref paths[j];
if (path.count <= 1) {
continue;
}

var p0 = this._points[ip0];
var p1 = this._points[ip1];
ref var p0 = ref points[ip0];
ref var p1 = ref points[ip1];
if (PathUtils.ptEquals(p0.x, p0.y, p1.x, p1.y, this._distTol)) {
path.count--;
path.closed = true;

}
void _expandFill() {
for (var j = 0; j < this._paths.Count; j++) {
var path = this._paths[j];
var points = this._points.array();
var paths = this._paths.array();
for (var j = 0; j < paths.Length; j++) {
ref var path = ref paths[j];
if (path.count <= 2) {
continue;
}

for (var i = 0; i < path.count; i++) {
var p0 = this._points[ip0];
var p1 = this._points[ip1];
ref var p0 = ref points[ip0];
ref var p1 = ref points[ip1];
p0.dx = p1.x - p0.x; // no need to normalize
p0.dy = p1.y - p0.y;
ip0 = ip1++;

ip0 = path.first + path.count - 1;
ip1 = path.first;
for (var i = 0; i < path.count; i++) {
var p0 = this._points[ip0];
var p1 = this._points[ip1];
ref var p0 = ref points[ip0];
ref var p1 = ref points[ip1];
float cross = p1.dx * p0.dy - p0.dx * p1.dy;
if (cross < 0.0f) {

}
this._vertices.Clear();
for (var i = 0; i < this._paths.Count; i++) {
var path = this._paths[i];
for (var i = 0; i < paths.Length; i++) {
ref var path = ref paths[i];
if (path.count <= 2) {
continue;
}

var p = this._points[path.first + j];
ref var p = ref points[path.first + j];
this._vertices.Add(new Vector2(p.x, p.y));
}

public MeshMesh getFillMesh(out bool convex) {
if (this._fillMesh != null) {
convex = this._fillConvex;
if (this._strokeMesh != null) {
Debug.Log("bingo!");
}
var paths = this._paths.array();
for (var i = 0; i < this._paths.Count; i++) {
var path = this._paths[i];
for (var i = 0; i < paths.Length; i++) {
ref var path = ref paths[i];
if (path.count <= 2) {
continue;
}

}
var indices = new List<int>(cindices);
for (var i = 0; i < this._paths.Count; i++) {
var path = this._paths[i];
for (var i = 0; i < paths.Length; i++) {
ref var path = ref paths[i];
if (path.count <= 2) {
continue;
}

this._fillMesh = mesh;
this._fillConvex = false;
for (var i = 0; i < this._paths.Count; i++) {
var path = this._paths[i];
for (var i = 0; i < paths.Length; i++) {
ref var path = ref paths[i];
if (path.count <= 2) {
continue;
}

void _calculateJoins(float w, StrokeJoin lineJoin, float miterLimit) {
float iw = w > 0.0f ? 1.0f / w : 0.0f;
for (var i = 0; i < this._paths.Count; i++) {
var path = this._paths[i];
var points = this._points.array();
var paths = this._paths.array();
for (var i = 0; i < paths.Length; i++) {
ref var path = ref paths[i];
if (path.count <= 1) {
continue;
}

for (var j = 0; j < path.count; j++) {
var p0 = this._points[ip0];
var p1 = this._points[ip1];
ref var p0 = ref points[ip0];
ref var p1 = ref points[ip1];
p0.dx = p1.x - p0.x;
p0.dy = p1.y - p0.y;
p0.len = PathUtils.normalize(ref p0.dx, ref p0.dy);

ip0 = path.first + path.count - 1;
ip1 = path.first;
for (var j = 0; j < path.count; j++) {
var p0 = this._points[ip0];
var p1 = this._points[ip1];
ref var p0 = ref points[ip0];
ref var p1 = ref points[ip1];
float dlx0 = p0.dy;
float dly0 = -p0.dx;
float dlx1 = p1.dy;

}
this._vertices.Clear();
for (var i = 0; i < this._paths.Count; i++) {
var path = this._paths[i];
var points = this._points.array();
var paths = this._paths.array();
for (var i = 0; i < paths.Length; i++) {
ref var path = ref paths[i];
if (path.count <= 1) {
continue;
}

e = path.count - 1;
}
var p0 = this._points[ip0];
var p1 = this._points[ip1];
ref var p0 = ref points[ip0];
ref var p1 = ref points[ip1];
if (!path.closed) {
if (lineCap == StrokeCap.butt) {

}
for (var j = s; j < e; j++) {
p0 = this._points[ip0];
p1 = this._points[ip1];
p0 = ref points[ip0];
p1 = ref points[ip1];
if ((p1.flags & (PointFlags.bevel | PointFlags.innerBevel)) != 0) {
if (lineJoin == StrokeJoin.round) {

}
if (!path.closed) {
p0 = this._points[ip0];
p1 = this._points[ip1];
p0 = ref points[ip0];
p1 = ref points[ip1];
if (lineCap == StrokeCap.butt) {
this._vertices.buttCapEnd(p1, p0.dx, p0.dy, w, 0.0f);
}

this._lineCap == lineCap &&
this._lineJoin == lineJoin &&
this._miterLimit == miterLimit) {
if (this._fillMesh != null) {
Debug.Log("bingo!");
}
var paths = this._paths.array();
for (var i = 0; i < this._paths.Count; i++) {
var path = this._paths[i];
for (var i = 0; i < paths.Length; i++) {
ref var path = ref paths[i];
if (path.count <= 1) {
continue;
}

}
var indices = new List<int>(cindices);
for (var i = 0; i < this._paths.Count; i++) {
var path = this._paths[i];
for (var i = 0; i < paths.Length; i++) {
ref var path = ref paths[i];
if (path.count <= 1) {
continue;
}

187
Runtime/ui/painting/txt/font_manager.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using UnityEngine;

}
}
class FontRef : IEquatable<FontRef> {
public readonly string familyName;
public readonly FontWeight fontWeight;
public readonly FontStyle fontStyle;
public FontRef(string familyName, FontWeight fontWeight, FontStyle fontStyle) {
this.familyName = familyName;
this.fontWeight = fontWeight;
this.fontStyle = fontStyle;
}
public bool Equals(FontRef other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return string.Equals(this.familyName, other.familyName) && this.fontWeight == other.fontWeight && this.fontStyle == other.fontStyle;
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {
return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
if (obj.GetType() != this.GetType()) {
return false;
}
return this.Equals((FontRef) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = (this.familyName != null ? this.familyName.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.fontWeight != null ? this.fontWeight.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (int) this.fontStyle;
return hashCode;
}
}
public static bool operator ==(FontRef left, FontRef right) {
return Equals(left, right);
}
public static bool operator !=(FontRef left, FontRef right) {
return !Equals(left, right);
}
public override string ToString() {
return $"{nameof(this.familyName)}: {this.familyName}, {nameof(this.fontWeight)}: {this.fontWeight}, {nameof(this.fontStyle)}: {this.fontStyle}";
}
}
readonly Dictionary<FontRef, FontInfo> _fonts = new Dictionary<FontRef, FontInfo>();
readonly Dictionary<string, FontInfo>[] _fonts =
new Dictionary<string, FontInfo>[9 * 2]; // max weight size x max style size
static readonly int defaultFontSize = 14;
public static readonly FontManager instance = new FontManager();

public void addFont(Font font, string familyName,
FontWeight fontWeight = null, FontStyle fontStyle = FontStyle.normal) {
if (fontWeight == null) {
fontWeight = FontWeight.normal;
}
fontWeight = fontWeight ?? FontWeight.normal;
FontRef fontRef = new FontRef(familyName, fontWeight, fontStyle);
FontInfo current;
this._fonts.TryGetValue(fontRef, out current);
D.assert(current == null || current.font == font, () => $"font with key {fontRef} already exists");
var fonts = this._getFonts(fontWeight.index, fontStyle);
fonts.TryGetValue(familyName, out var current);
D.assert(current == null || current.font == font,
() => $"font with key {familyName} {fontWeight} {fontStyle} already exists");
this._fonts[fontRef] = fontInfo;
fonts[familyName] = fontInfo;
}
Dictionary<string, FontInfo> _getFonts(int fontWeight, FontStyle fontStyle) {
var index = fontWeight * 2 + (int) fontStyle;
var fonts = this._fonts[index];
if (fonts == null) {
fonts = this._fonts[index] = new Dictionary<string, FontInfo>();
}
return fonts;
if (fontWeight == null) {
fontWeight = FontWeight.normal;
}
FontRef fontRef = new FontRef(familyName, fontWeight, fontStyle);
if (this._fonts.TryGetValue(fontRef, out var fontInfo)) {
fontWeight = fontWeight ?? FontWeight.normal;
var fonts = this._getFonts(fontWeight.index, fontStyle);
if (fonts.TryGetValue(familyName, out var fontInfo)) {
if (fontWeight != FontWeight.normal || fontStyle != FontStyle.normal) {
if (fontWeight.index != FontWeight.normal.index || fontStyle != FontStyle.normal) {
fontInfo = this.getOrCreate(familyName, FontWeight.normal, FontStyle.normal);
if (fontInfo != null) {
return fontInfo;

osFont.material.mainTexture.hideFlags = HideFlags.DontSave;
var newFont = new FontInfo(osFont);
fontRef = new FontRef(familyName, fontWeight, fontStyle);
this._fonts[fontRef] = newFont;
fonts[familyName] = newFont;
var entry = this._fonts.Values.FirstOrDefault(f => f.font == font);
if (entry != null) {
entry.onTextureRebuilt();
foreach (var fontInfos in this._fonts) {
if (fontInfos != null) {
foreach (var f in fontInfos.Values) {
if (f.font == font) {
f.onTextureRebuilt();
}
}
}
struct GlyphInfo {
public static readonly GlyphInfo empty = new GlyphInfo();
Rect _rect;
readonly CharacterInfo _info;
public GlyphInfo(CharacterInfo info) {
this._rect = null;
this._info = info;
}
public Rect rect {
get {
if (this._rect == null) {
this._rect = Rect.fromLTRB(this._info.minX, -this._info.maxY, this._info.maxX, -this._info.minY);
}
return this._rect;
}
}
public float advance {
get { return this._info.advance; }
}
public float glyphHeight {
get { return this._info.advance; }
}
public Vector2 uvTopLeft {
get { return this._info.uvTopLeft; }
}
public Vector2 uvTopRight {
get { return this._info.uvTopRight; }
}
public Vector2 uvBottomLeft {
get { return this._info.uvBottomLeft; }
}
public Vector2 uvBottomRight {
get { return this._info.uvBottomRight; }
}
}
internal static GlyphInfo getGlyphInfo(this Font font, char ch, int fontSize, UnityEngine.FontStyle fontStyle) {
internal static bool getGlyphInfo(this Font font, char ch, out CharacterInfo info, int fontSize,
UnityEngine.FontStyle fontStyle) {
return GlyphInfo.empty;
info = default;
return false;
CharacterInfo info;
Debug.LogWarning($"character info not found from the given font: character '{ch}' (code{(int)ch}) font: ${font.name}");
Debug.LogWarning(
$"character info not found from the given font: character '{ch}' (code{(int) ch}) font: ${font.name}");
return GlyphInfo.empty;
info = default;
return false;
return new GlyphInfo(info);
return true;
internal static void RequestCharactersInTextureSafe(this Font font, string text, int fontSize,
UnityEngine.FontStyle fontStyle = UnityEngine.FontStyle.Normal) {
if (fontSize <= 0) {

12
Runtime/ui/painting/txt/mesh_generator.cs


if (fontSizeToLoad == 0) {
continue;
}
var glyphInfo = font.getGlyphInfo(ch, fontSizeToLoad, style.UnityFontStyle);
var minX = glyphInfo.rect.left / this.scale;
var maxX = glyphInfo.rect.right / this.scale;
var minY = glyphInfo.rect.top / this.scale;
var maxY = glyphInfo.rect.bottom / this.scale;
font.getGlyphInfo(ch, out var glyphInfo, fontSizeToLoad, style.UnityFontStyle);
var minX = glyphInfo.minX / this.scale;
var maxX = glyphInfo.maxX / this.scale;
var minY = -glyphInfo.maxY / this.scale;
var maxY = -glyphInfo.minY / this.scale;
var baseIndex = vertices.Count;

2
Runtime/ui/text.cs


internal UnityEngine.FontStyle UnityFontStyle {
get {
bool isBold = this.fontWeight == FontWeight.bold;
bool isBold = this.fontWeight.index == FontWeight.bold.index;
if (this.fontStyle == FontStyle.italic) {
if (isBold) {
return UnityEngine.FontStyle.BoldAndItalic;

58
Runtime/ui/txt/layout.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using UnityEngine;
namespace Unity.UIWidgets.ui {

List<float> _advances = new List<float>();
List<float> _positions = new List<float>();
float _advance;
Rect _bounds;
UnityEngine.Rect _bounds;
TabStops _tabStops;

public void doLayout(float offset, TextBuff buff, int start, int count, TextStyle style) {
this._start = start;
this._count = count;
this._advances.resize(count, 0);
this._positions.resize(count, 0);
this._advances.reset(count);
this._positions.reset(count);
this._bounds = null;
this._bounds = UnityEngine.Rect.zero;
var font = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font;
font.RequestCharactersInTextureSafe(buff.text, style.UnityFontSize, style.UnityFontStyle);
int wordstart = start == buff.size
? start
: LayoutUtils.getPrevWordBreakForCache(buff, start + 1);

int wordCount = Math.Min(start + count, wordend) - iter;
int wordCount = Mathf.Min(start + count, wordend) - iter;
iter - wordstart, wordCount, style);
iter - wordstart, wordCount, style, font);
TextBuff buff, int start, int wordCount, TextStyle style) {
TextBuff buff, int start, int wordCount, TextStyle style, Font font) {
var font = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font;
font.RequestCharactersInTextureSafe(buff.subBuff(start, wordCount).getString(),
style.UnityFontSize,
style.UnityFontStyle);
float x = this._advance;
float letterSpace = style.letterSpacing;
float letterSpaceHalfLeft = letterSpace * 0.5f;

x += letterSpace;
}
var glyphInfo = font.getGlyphInfo(ch, style.UnityFontSize, style.UnityFontStyle);
var rect = glyphInfo.rect;
rect = rect.translate(x, 0);
if (this._bounds == null || this._bounds.isEmpty) {
this._bounds = rect;
}
else {
this._bounds = this._bounds.expandToInclude(rect);
if (font.getGlyphInfo(ch, out var glyphInfo, style.UnityFontSize, style.UnityFontStyle)) {
var minX = glyphInfo.minX + x;
var maxX = glyphInfo.maxX + x;
var minY = -glyphInfo.maxY;
var maxY = -glyphInfo.minY;
if (this._bounds.width <= 0 || this._bounds.height <= 0) {
this._bounds = UnityEngine.Rect.MinMaxRect(
minX, minY, maxX, maxY);
} else {
if (minX < this._bounds.x) {
this._bounds.x = minX;
}
if (minY < this._bounds.y) {
this._bounds.y = minY;
}
if (maxX > this._bounds.xMax) {
this._bounds.xMax = maxX;
}
if (maxY > this._bounds.yMax) {
this._bounds.yMax = maxY;
}
}
this._positions[i + layoutOffset] = x;
float advance = glyphInfo.advance;
if (ch == '\t') {

}
public Rect getBounds() {
return this._bounds;
return Rect.fromLTWH(this._bounds.x, this._bounds.y, this._bounds.width, this._bounds.height);
}
}
}

10
Runtime/ui/txt/linebreaker.cs


}
if (this._tabWidth == int.MaxValue) {
this._font.RequestCharactersInTextureSafe(" ", this._fontSize);
var glyphInfo = this._font.getGlyphInfo(' ', this._fontSize, UnityEngine.FontStyle.Normal);
this._tabWidth = (int)Math.Round(glyphInfo.advance * kTabSpaceCount);
this._font.RequestCharactersInTextureSafe(" ", this._fontSize);
this._font.getGlyphInfo(' ', out var glyphInfo, this._fontSize, UnityEngine.FontStyle.Normal);
this._tabWidth = glyphInfo.advance * kTabSpaceCount;
}
}

public void resize(int size) {
if (this._charWidths.Count < size) {
this._charWidths.AddRange(Enumerable.Repeat(0.0f, size - this._charWidths.Count));
NoAllocHelpers<float>.ResizeList(this._charWidths, size);
}
}

this._candidates.Clear();
this._widths.Clear();
this._breaks.Clear();
this._textBuf = null;
this._textBuf = default;
}
public List<float> getWidths() {

4
Runtime/ui/txt/paint_record.cs


namespace Unity.UIWidgets.ui {
class PaintRecord {
public PaintRecord(TextStyle style, Offset offset, TextBlob _text,
public PaintRecord(TextStyle style, Offset offset, TextBlob text,
this._text = _text;
this._text = text;
this._line = line;
this._runWidth = runWidth;
this._metrics = metrics;

7
Runtime/ui/txt/paragraph.cs


var ascent = -font.ascent * fontSize / font.fontSize;
var descent = (font.lineHeight - font.ascent) * fontSize / font.fontSize;
font.RequestCharactersInTextureSafe("x", fontSize, UnityEngine.FontStyle.Normal);
var glyphInfo = font.getGlyphInfo('x', fontSize, UnityEngine.FontStyle.Normal);
font.getGlyphInfo('x', out var glyphInfo, fontSize, UnityEngine.FontStyle.Normal);
float fxHeight = glyphInfo.glyphHeight;
return new FontMetrics(ascent, descent, fxHeight: fxHeight);

public readonly int endIncludingNewLine;
public readonly bool hardBreak;
}
const int TabSpaceCount = 4;
bool _needsLayout = true;

lineBreaker.finish();
}
return;
}
List<Range<int>> findWords(int start, int end) {

4
Runtime/ui/txt/text_buff.cs


using Unity.UIWidgets.foundation;
namespace Unity.UIWidgets.ui {
class TextBuff {
struct TextBuff {
public readonly string text;
public readonly int offset;
public readonly int size;

return new TextBuff(this.text, this.offset + shift, size);
}
public String getString() {
public override string ToString() {
return this.text.Substring(this.offset, this.size);
}
}

2
Runtime/ui/txt/wordbreaker.cs


}
public void finish() {
this._text = null;
this._text = default;
}
int _findNextBreakInEmailOrUrl() {

66
Runtime/ui/painting/NoAllocHelpers.cs


using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
namespace Unity.UIWidgets.ui {
public static class NoAllocHelpers<T> {
static Func<List<T>, T[]> _extractArrayFromListDelegate;
static Action<List<T>, int> _resizeListDelegate;
public static T[] ExtractArrayFromListT(List<T> list) {
if (_extractArrayFromListDelegate == null) {
var ass = Assembly.GetAssembly(typeof(Mesh));
var type = ass.GetType("UnityEngine.NoAllocHelpers");
var methodInfo = type.GetMethod(
"ExtractArrayFromListT",
BindingFlags.Static | BindingFlags.Public)
.MakeGenericMethod(typeof(T));
_extractArrayFromListDelegate = (Func<List<T>, T[]>)
Delegate.CreateDelegate(typeof(Func<List<T>, T[]>), methodInfo);
}
return _extractArrayFromListDelegate(list);
}
public static void ResizeList(List<T> list, int size) {
if (size < list.Count) {
list.RemoveRange(size, list.Count - size);
return;
}
if (size == list.Count) {
return;
}
if (list.Capacity < size) {
list.Capacity = size;
}
if (_resizeListDelegate == null) {
var ass = Assembly.GetAssembly(typeof(Mesh)); // any class in UnityEngine
var type = ass.GetType("UnityEngine.NoAllocHelpers");
var methodInfo = type.GetMethod(
"ResizeList",
BindingFlags.Static | BindingFlags.Public)
.MakeGenericMethod(typeof(T));
_resizeListDelegate = (Action<List<T>, int>)
Delegate.CreateDelegate(typeof(Action<List<T>, int>), methodInfo);
}
_resizeListDelegate(list, size);
}
public static void EnsureListElemCount(List<T> list, int size) {
list.Clear();
if (list.Capacity < size) {
list.Capacity = size;
}
ResizeList(list, size);
}
}
}
正在加载...
取消
保存