浏览代码

Code cleanup.

/main
Yuncong Zhang 5 年前
当前提交
d0c40629
共有 8 个文件被更改,包括 46 次插入54 次删除
  1. 5
      Runtime/ui/painting/txt/text_blob.cs
  2. 2
      Runtime/ui/txt/emoji.cs
  3. 7
      Runtime/ui/txt/layout_utils.cs
  4. 13
      Runtime/ui/txt/linebreaker.cs
  5. 35
      Runtime/ui/txt/paragraph.cs
  6. 1
      Runtime/ui/txt/text_buff.cs
  7. 16
      Runtime/ui/txt/wordbreaker.cs
  8. 21
      Tests/Editor/CanvasAndLayers.cs

5
Runtime/ui/painting/txt/text_blob.cs


namespace Unity.UIWidgets.ui {
public struct TextBlob {
internal TextBlob(string text, int textOffset, int textSize, float[] positions,
UnityEngine.Rect bounds, TextStyle style) {
this.instanceId = ++_nextInstanceId;

get {
var pos = this.getPosition(0);
return Rect.fromLTWH(this._bounds.xMin + pos, this._bounds.yMin,
this._bounds.width, this._bounds.height);
this._bounds.width, this._bounds.height);
}
}

this._bounds.width, this._bounds.height);
this._bounds.width, this._bounds.height);
}
public float getPosition(int i) {

2
Runtime/ui/txt/emoji.cs


{0x2935, 1224}, {0x2b05, 1225}, {0x2b06, 1226}, {0x2b07, 1227}, {0x2b1b, 1228}, {0x2b1c, 1229},
{0x2b50, 1230}, {0x2b55, 1231}, {0x3030, 1232}, {0x303d, 1233}, {0x3297, 1234}, {0x3299, 1235},
};
public static readonly HashSet<int> SingleCharEmojiCodePoints = new HashSet<int> {
0x203c, 0x2049, 0x2122, 0x2139, 0x2194,
0x2195, 0x2196, 0x2197, 0x2198, 0x2199, 0x21a9,

7
Runtime/ui/txt/layout_utils.cs


c == 0x205F || c == 0x3000;
}
if (offset >= len) {
return len;
}

public static bool isWordBreakAfter(ushort c) {
return isWordSpace(c) || (c >= 0x2000 && c <= 0x200a) || c == 0x3000;
}
public static bool isWordBreakBefore(ushort c) {
return isWordBreakAfter(c) || (c >= 0x3400 && c <= 0x9fff);
}

i = i | (i >> 16);
return i + 1;
}
}
}

13
Runtime/ui/txt/linebreaker.cs


public static LineBreaker instance {
get {
if(_instance == null)
if (_instance == null) {
}
return _instance;
}
}

_newLinePositions[count++] = i;
}
}
_newLinePositions[count++] = text.Length;
return _newLinePositions;

int mFirstTabIndex;
List<Candidate> _candidates = new List<Candidate>();
int _candidatesCount = 0;
public int computeBreaks() {
int nCand = this._candidatesCount;
if (nCand > 0 && (nCand == 1 || this._lastBreak != nCand - 1)) {

void _addWordBreak(int offset, float preBreak, float postBreak, int preSpaceCount, int postSpaceCount,
float penalty) {
this._addCandidate(new Candidate {
offset = offset,
preBreak = preBreak,

if (this._bestBreak == this._lastBreak) {
this._bestBreak = candIndex;
}
this._pushGreedyBreak();
}

this._bestScore = penalty;
}
}
this._pushGreedyBreak();
}

35
Runtime/ui/txt/paragraph.cs


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

ParagraphStyle _paragraphStyle;
List<LineRange> _lineRanges = new List<LineRange>();
// float[] _lineBaseLines;
GlyphLine[] _glyphLines;
GlyphPosition[] _glyphPositions;

public bool didExceedMaxLines {
get { return this._didExceedMaxLines; }
}
static List<Paragraph> _paragraphs = new List<Paragraph>();
public static Paragraph create() {

Paragraph ret = _paragraphs.last();
_paragraphs.RemoveAt(_paragraphs.Count-1);
_paragraphs.RemoveAt(_paragraphs.Count - 1);
return ret;
}

this._width = Mathf.Floor(constraints.width);
int lineStyleRunsCount = this._computeLineBreak();
if (this._glyphLines == null || this._glyphLines.Length < this._lineRangeCount) {
this._glyphLines = new GlyphLine[LayoutUtils.minPowerOfTwo(this._lineRangeCount)];
}

if (this._paintRecords == null || this._paintRecords.Length < lineStyleRunsCount) {
this._paintRecords = new PaintRecord[LayoutUtils.minPowerOfTwo(lineStyleRunsCount)];
}
this._paintRecordsCount = 0;
if (this._codeUnitRuns == null || this._codeUnitRuns.Length < lineStyleRunsCount) {

TextBlobBuilder builder = new TextBlobBuilder();
int ellipsizedLength = this._text.Length + (this._paragraphStyle.ellipsis?.Length ?? 0);
builder.setPositions(this._textBlobPositions);
// this._glyphLines and this._codeUnitRuns will refer to this array for glyph positions
if (this._glyphPositions == null || this._glyphPositions.Length < ellipsizedLength) {

// Pointer to the _glyphPositions array, to keep track of where the next glyph is stored
int pGlyphPositions = 0;
// Compute max(NumberOfWords(line) for line in lines), to determine the size of word buffers
int maxWordCount = this._computeMaxWordCount();

(lineNumber == lineLimit - 1 || this._paragraphStyle.maxLines == null)) {
maxTextCount += ellipsis.Length;
}
// Allocate the advances and positions to store the layout result
// TODO: find a way to compute the maxTextCount for the entire paragraph, so that this allocation
// happens only once

int truncateCount = Layout.computeTruncateCount(runXOffset, text, textStart,
textCount, style, this._width - ellipsisWidth, this._tabStops);
if(!(this._ellipsizedLength == textStart + textCount - truncateCount &&
this._ellipsizedText.Length == this._ellipsizedLength + ellipsis.Length &&
this._ellipsizedText.EndsWith(ellipsis))) {
if (!(this._ellipsizedLength == textStart + textCount - truncateCount &&
this._ellipsizedText.Length == this._ellipsizedLength + ellipsis.Length &&
this._ellipsizedText.EndsWith(ellipsis))) {
text = this._ellipsizedText;
textCount = text.Length - textStart;
D.assert(textCount != 0);

this._codeUnitRuns[this._codeUnitRunsCount++] = new CodeUnitRun(
new Range<int>(start, end),
new Range<float>(this._glyphPositions[glyphPositionStyleRunStart].xPos.start,
this._glyphPositions[pGlyphPositions-1].xPos.end),
this._glyphPositions[pGlyphPositions - 1].xPos.end),
lineNumber, TextDirection.ltr, glyphPositionStyleRunStart, textCount);
lineStyleRunIndex++;

}
this._lineHeights[lineNumber] = ((lineNumber == 0 ? 0 : this._lineHeights[lineNumber - 1])
+ Mathf.Round(maxLineSpacing + maxDescent));
+ Mathf.Round(maxLineSpacing + maxDescent));
// this._lineBaseLines[lineNumber] = this._lineHeights[lineNumber] - maxDescent;
yOffset += Mathf.Round(maxLineSpacing + preMaxDescent);
preMaxDescent = maxDescent;

int nextLineStart = lineNumber < this._lineRangeCount - 1
? this._lineRanges[lineNumber + 1].start
: this._text.Length;
this._glyphLines[lineNumber] =
this._glyphLines[lineNumber] =
new GlyphLine(glyphPositionLineStart, count, nextLineStart - lineStart);
for (int i = 0; i < lineStyleRunCount; i++) {
var paintRecord = this._paintRecords[this._paintRecordsCount - 1 - i];

for (int i = 0; i < yIndex; i++) {
lineStartIndex += this._glyphLines[i].totalCountUnits;
}
return new PositionWithAffinity(lineStartIndex, TextAffinity.downstream);
}

if (lineLimit != 0 && this._lineRangeCount >= lineLimit) {
break;
}
var blockStart = newlineIndex > 0 ? newLinePositions[newlineIndex - 1] + 1 : 0;
var blockEnd = newLinePositions[newlineIndex];
var blockSize = blockEnd - blockStart;

}
this._resetLineBreaker(lineBreaker, blockStart, blockSize,
this._resetLineBreaker(lineBreaker, blockStart, blockSize,
lineLimit == 0 ? 0 : lineLimit - this._lineRangeCount);
countRuns += this._addStyleRuns(lineBreaker, ref runIndex, blockStart, blockEnd);

1
Runtime/ui/txt/text_buff.cs


using System;
using Unity.UIWidgets.foundation;
namespace Unity.UIWidgets.ui {

16
Runtime/ui/txt/wordbreaker.cs


namespace Unity.UIWidgets.ui {
struct WordBreaker {
public const uint U16_SURROGATE_OFFSET = ((0xd800 << 10) + 0xdc00 - 0x10000);

if (preBoundaryChar) {
return this._current;
}
return this._current;
}

if (currentType != preWhiteSpace) {
break;
}
void _detectEmailOrUrl() {
}

}
public static uint getSupplementary(uint lead, uint trail) {
return (char) ((lead << 10) + (trail - U16_SURROGATE_OFFSET));
return (char) ((lead << 10) + (trail - U16_SURROGATE_OFFSET));
&& (char.IsLowSurrogate(this._text.charAt(this._current))
|| char.IsHighSurrogate(this._text.charAt(this._current)))) {
&& (char.IsLowSurrogate(this._text.charAt(this._current))
|| char.IsHighSurrogate(this._text.charAt(this._current)))) {
this._current++;
}
}

21
Tests/Editor/CanvasAndLayers.cs


string text = "This is a text blob";
builder.setBounds(new Rect(-10, -20, 200, 50));
builder.setPositions(new float[] {
10,
20,
30,
40,
50,
60,
70,
80,
90,
100,
110,
120,
130,
140,
150,
160,
170,
180,
190
10, 20, 30, 40, 50, 60, 70, 80, 90, 100,
110, 120, 130, 140, 150, 160, 170, 180, 190
});
builder.allocRunPos(new TextStyle(), text, 0, text.Length);

正在加载...
取消
保存