浏览代码

Change TextBlob positions to float.

/main
Yuncong Zhang 5 年前
当前提交
2939cc54
共有 4 个文件被更改,包括 38 次插入40 次删除
  1. 16
      Runtime/ui/painting/txt/mesh_generator.cs
  2. 20
      Runtime/ui/painting/txt/text_blob.cs
  3. 2
      Runtime/ui/txt/paragraph.cs
  4. 40
      Tests/Editor/CanvasAndLayers.cs

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


var pos = this.textBlob.getPosition(i);
int baseIndex = vert.Count;
vert.Add(new Vector3(pos.x + minX, pos.y + minY, 0));
vert.Add(new Vector3(pos.x + maxX, pos.y + minY, 0));
vert.Add(new Vector3(pos.x + maxX, pos.y + maxY, 0));
vert.Add(new Vector3(pos.x + minX, pos.y + maxY, 0));
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));
tri.Add(baseIndex);
tri.Add(baseIndex + 1);

var baseIndex = vertices.Count;
vertices.Add(new Vector3((position.x + minX), (position.y + minY), 0));
vertices.Add(new Vector3((position.x + maxX), (position.y + minY), 0));
vertices.Add(new Vector3((position.x + maxX), (position.y + maxY), 0));
vertices.Add(new Vector3((position.x + minX), (position.y + maxY), 0));
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));
triangles.Add(baseIndex);
triangles.Add(baseIndex + 1);

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


namespace Unity.UIWidgets.ui {
public struct TextBlob {
internal TextBlob(string text, int textOffset, int textSize, Vector2d[] positions,
internal TextBlob(string text, int textOffset, int textSize, float[] positions,
float minX, float minY, float width, float height, TextStyle style) {
this.instanceId = ++_nextInstanceId;
this.text = text;

public Rect boundsInText {
get {
var pos = this._positions[this.textOffset];
return Rect.fromLTWH(this._minX + pos.x, this._minY + pos.y, this._width, this._height);
return Rect.fromLTWH(this._minX + pos, this._minY, this._width, this._height);
pos.x += offset.dx;
pos.y += offset.dy;
return Rect.fromLTWH(this._minX + pos.x, this._minY + pos.y, this._width, this._height);
return Rect.fromLTWH(this._minX + pos + offset.dx, this._minY + offset.dy, this._width, this._height);
public Vector2d getPosition(int i) {
public float getPosition(int i) {
return this._positions[this.textOffset + i];
}

internal readonly int textSize;
internal readonly TextStyle style;
readonly float _minX, _minY, _width, _height; // bounds with positions[start] as origin
readonly Vector2d[] _positions;
readonly float[] _positions;
Vector2d[] _positions;
float[] _positions;
string _text;
int _textOffset;
int _size;

internal void allocPos(int size) {
if (this._positions == null || this._positions.Length < size) {
this._positions = new Vector2d[size];
this._positions = new float[size];
public void setPosition(int i, Vector2d position) {
public void setPosition(int i, float position) {
public void setPositions(Vector2d[] positions) {
public void setPositions(float[] positions) {
this._positions = positions;
}

2
Runtime/ui/txt/paragraph.cs


for (int glyphIndex = 0; glyphIndex < textCount; ++glyphIndex) {
float glyphXOffset = layout.getX(glyphIndex) + justifyXOffset;
float glyphAdvance = layout.getCharAdvance(glyphIndex);
builder.setPosition(glyphIndex, new Vector2d(glyphXOffset));
builder.setPosition(glyphIndex, glyphXOffset);
glyphPositions[pLineGlyphPositions++] = new GlyphPosition(runXOffset + glyphXOffset,
glyphAdvance, new Range<int>(textStart + glyphIndex, textStart + glyphIndex + 1));
if (words != null && wordIndex < words.Length) {

40
Tests/Editor/CanvasAndLayers.cs


TextBlobBuilder builder = new TextBlobBuilder();
string text = "This is a text blob";
builder.setBounds(-10, -20, 200, 50);
builder.setPositions(new [] {
new Vector2d(10, 0),
new Vector2d(20, 0),
new Vector2d(30, 0),
new Vector2d(40, 0),
new Vector2d(50, 0),
new Vector2d(60, 0),
new Vector2d(70, 0),
new Vector2d(80, 0),
new Vector2d(90, 0),
new Vector2d(100, 0),
new Vector2d(110, 0),
new Vector2d(120, 0),
new Vector2d(130, 0),
new Vector2d(140, 0),
new Vector2d(150, 0),
new Vector2d(160, 0),
new Vector2d(170, 0),
new Vector2d(180, 0),
new Vector2d(190, 0),
builder.setPositions(new float[] {
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);

正在加载...
取消
保存