浏览代码

Fix issues.

/main
Yuncong Zhang 6 年前
当前提交
11f1d8a3
共有 11 个文件被更改,包括 54 次插入47 次删除
  1. 4
      Runtime/painting/text_painter.cs
  2. 10
      Runtime/rendering/editable.cs
  3. 2
      Runtime/ui/painting/draw_cmd.cs
  4. 2
      Runtime/ui/painting/picture.cs
  5. 20
      Runtime/ui/painting/txt/mesh_generator.cs
  6. 34
      Runtime/ui/painting/txt/text_blob.cs
  7. 11
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs
  8. 3
      Runtime/ui/renderer/common/draw_cmd.cs
  9. 3
      Runtime/ui/renderer/common/picture.cs
  10. 10
      Runtime/ui/txt/paragraph.cs
  11. 2
      Tests/Editor/CanvasAndLayers.cs

4
Runtime/painting/text_painter.cs


this._ellipsis = ellipsis;
}
~TextPainter() {
Paragraph.release(ref this._paragraph);
}
public float textScaleFactor {
get { return this._textScaleFactor; }
set {

10
Runtime/rendering/editable.cs


Paragraph.LineRange? line = null;
for (int i = 0; i < lineCount; ++i) {
line = this._textPainter.getLineRange(i);
if (!((Paragraph.LineRange) line).hardBreak) {
if (!line.Value.hardBreak) {
if (((Paragraph.LineRange) line).end > position.offset) {
if (line.Value.end > position.offset) {
break;
}
}

}
return new TextPosition(((Paragraph.LineRange) line).end, affinity ?? position.affinity);
return new TextPosition(line.Value.end, affinity ?? position.affinity);
}

continue;
}
if (((Paragraph.LineRange) line).start < position.offset) {
if (line.Value.start < position.offset) {
break;
}
}

}
return new TextPosition(((Paragraph.LineRange) line).start, affinity ?? position.affinity);
return new TextPosition(line.Value.start, affinity ?? position.affinity);
}
protected override float computeMinIntrinsicWidth(float height) {

2
Runtime/ui/painting/draw_cmd.cs


}
public class DrawTextBlob : DrawCmd {
public TextBlob textBlob;
public TextBlob? textBlob;
public Offset offset;
public Paint paint;
}

2
Runtime/ui/painting/picture.cs


case DrawTextBlob cmd: {
var state = this._getState();
var scale = XformUtils.getScale(state.xform);
var rect = cmd.textBlob.shiftedBoundsInText(cmd.offset);
var rect = cmd.textBlob.Value.shiftedBoundsInText(cmd.offset.dx, cmd.offset.dy);
rect = state.xform.mapRect(rect);
var paint = cmd.paint;

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


var uvRect = EmojiUtils.getUVRect(code);
var pos = this.textBlob.getPosition(i);
var positionX = this.textBlob.getPositionX(i);
vert.Add(new Vector3(pos + minX, minY, 0));
vert.Add(new Vector3(pos + maxX, minY, 0));
vert.Add(new Vector3(pos + maxX, maxY, 0));
vert.Add(new Vector3(pos + minX, maxY, 0));
vert.Add(new Vector3(positionX + minX, minY, 0));
vert.Add(new Vector3(positionX + maxX, minY, 0));
vert.Add(new Vector3(positionX + maxX, maxY, 0));
vert.Add(new Vector3(positionX + minX, maxY, 0));
tri.Add(baseIndex);
tri.Add(baseIndex + 1);
tri.Add(baseIndex + 2);

for (int charIndex = 0; charIndex < length; ++charIndex) {
var ch = text[charIndex + this.textBlob.textOffset];
// first char as origin for mesh position
var position = this.textBlob.getPosition(charIndex);
var positionX = this.textBlob.getPositionX(charIndex);
if (LayoutUtils.isWordSpace(ch) || LayoutUtils.isLineEndSpace(ch) || ch == '\t') {
continue;
}

var baseIndex = vertices.Count;
vertices.Add(new Vector3(position + minX, minY, 0));
vertices.Add(new Vector3(position + maxX, minY, 0));
vertices.Add(new Vector3(position + maxX, maxY, 0));
vertices.Add(new Vector3(position + minX, maxY, 0));
vertices.Add(new Vector3(positionX + minX, minY, 0));
vertices.Add(new Vector3(positionX + maxX, minY, 0));
vertices.Add(new Vector3(positionX + maxX, maxY, 0));
vertices.Add(new Vector3(positionX + minX, maxY, 0));
triangles.Add(baseIndex);
triangles.Add(baseIndex + 1);

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


namespace Unity.UIWidgets.ui {
public struct TextBlob {
internal TextBlob(string text, int textOffset, int textSize, float[] positions,
internal TextBlob(string text, int textOffset, int textSize, float[] positionXs,
this._positions = positions;
this._positionXs = positionXs;
this.text = text;
this.textOffset = textOffset;
this.textSize = textSize;

public Rect boundsInText {
get {
if (this._boundsInText == null) {
var pos = this.getPosition(0);
var pos = this.getPositionX(0);
this._boundsInText = Rect.fromLTWH(this._bounds.xMin + pos, this._bounds.yMin,
this._bounds.width, this._bounds.height);
}

}
public Rect shiftedBoundsInText(Offset offset) {
var pos = this.getPosition(0);
return Rect.fromLTWH(this._bounds.xMin + pos + offset.dx, this._bounds.yMin + offset.dy,
public Rect shiftedBoundsInText(float dx, float dy) {
var pos = this.getPositionX(0);
return Rect.fromLTWH(this._bounds.xMin + pos + dx, this._bounds.yMin + dy,
public float getPosition(int i) {
return this._positions[this.textOffset + i];
public float getPositionX(int i) {
return this._positionXs[this.textOffset + i];
}
static long _nextInstanceId;

internal readonly int textSize;
internal readonly TextStyle style;
readonly UnityEngine.Rect _bounds; // bounds with positions[start] as origin
readonly float[] _positions;
readonly float[] _positionXs;
Rect _boundsInText;
}

float[] _positions;
float[] _positionXs;
string _text;
int _textOffset;
int _size;

}
internal void allocPos(int size) {
if (this._positions == null || this._positions.Length < size) {
this._positions = new float[size];
if (this._positionXs == null || this._positionXs.Length < size) {
this._positionXs = new float[size];
public void setPosition(int i, float position) {
this._positions[this._textOffset + i] = position;
public void setPositionX(int i, float positionX) {
this._positionXs[this._textOffset + i] = positionX;
public void setPositions(float[] positions) {
this._positions = positions;
public void setPositionXs(float[] positionXs) {
this._positionXs = positionXs;
}
public void setBounds(UnityEngine.Rect bounds) {

public TextBlob make() {
var result = new TextBlob(this._text, this._textOffset,
this._size, this._positions, this._bounds, this._style);
this._size, this._positionXs, this._bounds, this._style);
return result;
}
}

11
Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs


}
}
void _drawTextBlob(TextBlob textBlob, uiOffset offset, uiPaint paint) {
void _drawTextBlob(TextBlob? textBlob, uiOffset offset, uiPaint paint) {
D.assert(textBlob != null);
var state = this._currentLayer.currentState;
var scale = state.scale * this._devicePixelRatio;

var mesh = TextBlobMesh.create(textBlob, scale, matrix);
var textBlobBounds = matrix.mapRect(uiRectHelper.fromRect(textBlob.boundsInText));
var mesh = TextBlobMesh.create(textBlob.Value, scale, matrix);
var textBlobBounds = matrix.mapRect(uiRectHelper.fromRect(textBlob.Value.boundsInText));
var style = textBlob.style;
var style = textBlob.Value.style;
var subText = textBlob.text.Substring(textBlob.textOffset, textBlob.textSize);
var subText = textBlob.Value.text.Substring(textBlob.Value.textOffset, textBlob.Value.textSize);
Texture tex = null;
bool notEmoji = !char.IsHighSurrogate(subText[0]) && !EmojiUtils.isSingleCharEmoji(subText[0]);
if (notEmoji) {

3
Runtime/ui/renderer/common/draw_cmd.cs


}
public override void clear() {
this.textBlob = null;
public TextBlob textBlob;
public TextBlob? textBlob;
public uiOffset? offset;
public uiPaint paint;
}

3
Runtime/ui/renderer/common/picture.cs


case uiDrawTextBlob cmd: {
var state = this._getState();
var scale = uiXformUtils.getScale(state.xform);
var rect = uiRectHelper.fromRect(cmd.textBlob.boundsInText).shift(cmd.offset.Value);
var rect = uiRectHelper.fromRect(
cmd.textBlob.Value.shiftedBoundsInText(cmd.offset.Value.dx, cmd.offset.Value.dy));
rect = state.xform.mapRect(rect);
var paint = cmd.paint;

10
Runtime/ui/txt/paragraph.cs


PaintRecord[] _paintRecords;
CodeUnitRun[] _codeUnitRuns;
float[] _lineHeights;
float[] _textBlobPositions;
float[] _textBlobPositionXs;
float _maxIntrinsicWidth;
float _minIntrinsicWidth;
float _alphabeticBaseline;

int ellipsizedLength = this._text.Length + (this._paragraphStyle.ellipsis?.Length ?? 0);
// All text blobs share a single position buffer, which is big enough taking ellipsis into consideration
if (this._textBlobPositions == null || this._textBlobPositions.Length < ellipsizedLength) {
this._textBlobPositions = new float[LayoutUtils.minPowerOfTwo(ellipsizedLength)];
if (this._textBlobPositionXs == null || this._textBlobPositionXs.Length < ellipsizedLength) {
this._textBlobPositionXs = new float[LayoutUtils.minPowerOfTwo(ellipsizedLength)];
builder.setPositions(this._textBlobPositions);
builder.setPositionXs(this._textBlobPositionXs);
// this._glyphLines and this._codeUnitRuns will refer to this array for glyph positions
if (this._glyphPositions == null || this._glyphPositions.Length < ellipsizedLength) {
this._glyphPositions = new GlyphPosition[LayoutUtils.minPowerOfTwo(ellipsizedLength)];

for (int glyphIndex = 0; glyphIndex < textCount; ++glyphIndex) {
float glyphXOffset = _positionsBuffer[glyphIndex] + justifyXOffset;
float glyphAdvance = _advancesBuffer[glyphIndex];
builder.setPosition(glyphIndex, glyphXOffset);
builder.setPositionX(glyphIndex, glyphXOffset);
this._glyphPositions[pGlyphPositions++] = new GlyphPosition(runXOffset + glyphXOffset,
glyphAdvance, textStart + glyphIndex);
if (wordIndex < wordCount) {

2
Tests/Editor/CanvasAndLayers.cs


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

正在加载...
取消
保存