浏览代码

fix painting compile error

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
1878b624
共有 16 个文件被更改,包括 596 次插入336 次删除
  1. 1
      com.unity.uiwidgets/Runtime/painting/binding.cs
  2. 19
      com.unity.uiwidgets/Runtime/painting/box_decoration.cs
  3. 2
      com.unity.uiwidgets/Runtime/painting/colors.cs
  4. 6
      com.unity.uiwidgets/Runtime/painting/decoration_image.cs
  5. 13
      com.unity.uiwidgets/Runtime/painting/gradient.cs
  6. 135
      com.unity.uiwidgets/Runtime/painting/image_provider.cs
  7. 6
      com.unity.uiwidgets/Runtime/painting/image_resolution.cs
  8. 28
      com.unity.uiwidgets/Runtime/painting/image_stream.cs
  9. 36
      com.unity.uiwidgets/Runtime/painting/matrix_utils.cs
  10. 7
      com.unity.uiwidgets/Runtime/painting/shader_warmup.cs
  11. 2
      com.unity.uiwidgets/Runtime/painting/strut_style.cs
  12. 239
      com.unity.uiwidgets/Runtime/painting/text_painter.cs
  13. 190
      com.unity.uiwidgets/Runtime/painting/text_span.cs
  14. 40
      com.unity.uiwidgets/Runtime/painting/text_style.cs
  15. 2
      com.unity.uiwidgets/Runtime/ui2/painting.cs
  16. 206
      com.unity.uiwidgets/Runtime/painting/inline_span.cs

1
com.unity.uiwidgets/Runtime/painting/binding.cs


using Unity.UIWidgets.gestures;
using Unity.UIWidgets.scheduler2;
using Unity.UIWidgets.ui;
using Window = Unity.UIWidgets.ui2.Window;
namespace Unity.UIWidgets.painting {
public class PaintingBinding : GestureBinding {

19
com.unity.uiwidgets/Runtime/painting/box_decoration.cs


Rect _rectForCachedBackgroundPaint;
Paint _getBackgroundPaint(Rect rect) {
Paint _getBackgroundPaint(Rect rect, TextDirection textDirection) {
D.assert(rect != null);
D.assert(_decoration.gradient != null || _rectForCachedBackgroundPaint == null);

}
if (_decoration.gradient != null) {
paint.shader = _decoration.gradient.createShader(rect);
paint.shader = _decoration.gradient.createShader(rect, textDirection: textDirection);
_rectForCachedBackgroundPaint = rect;
}

return _cachedBackgroundPaint;
}
void _paintBox(Canvas canvas, Rect rect, Paint paint) {
void _paintBox(Canvas canvas, Rect rect, Paint paint, TextDirection textDirection) {
switch (_decoration.shape) {
case BoxShape.circle:
D.assert(_decoration.borderRadius == null);

}
}
void _paintShadows(Canvas canvas, Rect rect) {
void _paintShadows(Canvas canvas, Rect rect, TextDirection textDirection) {
if (_decoration.boxShadow == null) {
return;
}

Rect bounds = rect.shift(boxShadow.offset).inflate(boxShadow.spreadRadius);
_paintBox(canvas, bounds, paint);
_paintBox(canvas, bounds, paint, textDirection);
void _paintBackgroundColor(Canvas canvas, Rect rect) {
void _paintBackgroundColor(Canvas canvas, Rect rect, TextDirection textDirection) {
_paintBox(canvas, rect, _getBackgroundPaint(rect));
_paintBox(canvas, rect, _getBackgroundPaint(rect, textDirection), textDirection);
}
}

D.assert(configuration.size != null);
Rect rect = offset & configuration.size;
TextDirection textDirection = configuration.textDirection;
_paintShadows(canvas, rect);
_paintBackgroundColor(canvas, rect);
_paintShadows(canvas, rect, textDirection);
_paintBackgroundColor(canvas, rect, textDirection);
_paintBackgroundImage(canvas, rect, configuration);
_decoration.border?.paint(
canvas,

2
com.unity.uiwidgets/Runtime/painting/colors.cs


public class ColorSwatch<T> : Color {
public ColorSwatch(
long primary,
uint primary,
Dictionary<T, Color> swatch) : base(primary) {
_swatch = swatch;
}

6
com.unity.uiwidgets/Runtime/painting/decoration_image.cs


Rect centerSlice = null,
ImageRepeat repeat = ImageRepeat.noRepeat,
bool invertColors = false,
FilterMode filterMode = FilterMode.Bilinear
FilterQuality filterQuality = FilterQuality.low
) {
D.assert(canvas != null);
D.assert(rect != null);

Paint paint = new Paint();
if (colorFilter != null) {
paint.colorFilter = colorFilter;
paint.color = colorFilter.color;
paint.blendMode = colorFilter.blendMode;
paint.filterMode = filterMode;
paint.filterQuality = filterQuality;
}
paint.invertColors = invertColors;

13
com.unity.uiwidgets/Runtime/painting/gradient.cs


using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;
using Shader = Unity.UIWidgets.ui.Shader;
namespace Unity.UIWidgets.painting {
class _ColorsAndStops {

int index = stops.FindLastIndex((float s) => { return s <= t; });
D.assert(index != -1);
return Color.lerp(colors[index], colors[index + 1],
return Color.lerp(colors[index], colors[index + 1],
(t - stops[index]) / (stops[index + 1] - stops[index]));
}

return Enumerable.Range(0, colors.Count).Select(i => i * separation).ToList();
}
public abstract PaintShader createShader(Rect rect);
public abstract Shader createShader(Rect rect, TextDirection? textDirection = null);
public abstract Gradient scale(float factor);

public readonly TileMode tileMode;
public override PaintShader createShader(Rect rect) {
public override Shader createShader(Rect rect, TextDirection? textDirection = null) {
return ui.Gradient.linear(
begin.withinRect(rect),
end.withinRect(rect),

}
public override Gradient scale(float factor) {
return new LinearGradient(
begin: begin,

public readonly TileMode tileMode;
public override PaintShader createShader(Rect rect) {
public override Shader createShader(Rect rect, TextDirection? textDirection = null) {
return ui.Gradient.radial(
center.withinRect(rect),
radius * rect.shortestSide,

public readonly TileMode tileMode;
public override PaintShader createShader(Rect rect) {
public override Shader createShader(Rect rect, TextDirection? textDirection = null) {
return ui.Gradient.sweep(
center.withinRect(rect),
colors, _impliedStops(),

135
com.unity.uiwidgets/Runtime/painting/image_provider.cs


using System.Collections;
using System.Collections.Generic;
using System.Text;
using RSG;
using Unity.UIWidgets.async;
using Unity.UIWidgets.async2;
using Codec = Unity.UIWidgets.ui.Codec;
using Image = Unity.UIWidgets.ui.Image;
using Locale = Unity.UIWidgets.ui.Locale;
using Object = UnityEngine.Object;
using TextDirection = Unity.UIWidgets.ui.TextDirection;
using Window = Unity.UIWidgets.ui.Window;
namespace Unity.UIWidgets.painting {
public class ImageConfiguration : IEquatable<ImageConfiguration> {

public readonly float? devicePixelRatio;
public readonly Locale locale;
public readonly TextDirection textDirection;
public readonly Size size;

}
}
public delegate Future<ui.Codec> DecoderCallback(byte[] bytes, int cacheWidth = 0, int cacheHeight = 0);
public abstract class ImageProvider {
public abstract ImageStream resolve(ImageConfiguration configuration);
}

ImageStream stream = new ImageStream();
T obtainedKey = default;
obtainKey(configuration).Then(key => {
obtainKey(configuration).then_((T key) => {
stream.setCompleter(PaintingBinding.instance.imageCache.putIfAbsent(key, () => load(key)));
}).Catch(ex => {
// TODO : how to load
// stream.setCompleter(PaintingBinding.instance.imageCache.putIfAbsent(key, () => load(key)));
}).catchError(ex => {
UIWidgetsError.reportError(new UIWidgetsErrorDetails(
exception: ex,
library: "services library",

configuration = configuration ?? ImageConfiguration.empty;
cache = cache ?? PaintingBinding.instance.imageCache;
return obtainKey(configuration).Then(key => cache.evict(key));
return obtainKey(configuration).then(key => cache.evict(key)).to<bool>();
protected abstract ImageStreamCompleter load(T key);
protected abstract ImageStreamCompleter load(T assetBundleImageKey, DecoderCallback decode);
protected abstract Future<T> obtainKey(ImageConfiguration configuration);
}

protected AssetBundleImageProvider() {
}
protected override ImageStreamCompleter load(AssetBundleImageKey key) {
protected override ImageStreamCompleter load(AssetBundleImageKey key, DecoderCallback decode) {
codec: _loadAsync(key),
codec: _loadAsync(key, decode),
scale: key.scale,
informationCollector: information => {
information.AppendLine($"Image provider: {this}");

}
Future<Codec> _loadAsync(AssetBundleImageKey key) {
var coroutine = Window.instance.startCoroutine(_loadAssetAsync(key));
return coroutine.promise.Then(result => {
if (result == null) {
if (key.bundle == null) {
throw new Exception($"Unable to find asset \"{key.name}\" from Resources folder");
}
throw new Exception($"Unable to find asset \"{key.name}\" from asset bundle \"{key.bundle}\"");
}
if (result is Texture2D texture) {
return CodecUtils.getCodec(new Image(texture, isAsset: true, bundle: key.bundle));
}
else if (result is TextAsset text) {
var bytes = text.bytes;
if (key.bundle == null) {
Resources.UnloadAsset(text);
}
else {
key.bundle.Unload(text);
}
Future<Codec> _loadAsync(AssetBundleImageKey key, DecoderCallback decode) {
Object data;
// Hot reload/restart could change whether an asset bundle or key in a
// bundle are available, or if it is a network backed bundle.
try {
data = key.bundle.LoadAsset(key.name);
}
catch (Exception e) {
PaintingBinding.instance.imageCache.evict(key);
throw e;
}
return CodecUtils.getCodec(bytes);
}
else {
throw new Exception($"Unknown type for asset \"{key.name}\": \"{result.GetType()}\"");
}
});
if (data != null && data is Texture2D textureData) {
return decode(textureData.EncodeToPNG());
}
else {
PaintingBinding.instance.imageCache.evict(key);
throw new Exception("Unable to read data");
}
}
IEnumerator _loadAssetAsync(AssetBundleImageKey key) {

yield return request.asset;
} else {
}
else {
yield return request;
yield return request.asset;
}

if (request.asset) {
yield return request.asset;
} else {
}
else {
yield return request.asset;
}
}

public readonly IDictionary<string, string> headers;
protected override Future<NetworkImage> obtainKey(ImageConfiguration configuration) {
return Promise<NetworkImage>.Resolved(this);
return new SynchronousFuture<NetworkImage>(this);
protected override ImageStreamCompleter load(NetworkImage key) {
protected override ImageStreamCompleter load(NetworkImage key, DecoderCallback decode) {
codec: _loadAsync(key),
codec: _loadAsync(key, decode),
scale: key.scale,
informationCollector: information => {
information.AppendLine($"Image provider: {this}");

}
Future<Codec> _loadAsync(NetworkImage key) {
var coroutine = Window.instance.startCoroutine(_loadBytes(key));
return coroutine.promise.Then(obj => {
if (obj is byte[] bytes) {
return CodecUtils.getCodec(bytes);
}
Future<Codec> _loadAsync(NetworkImage key, DecoderCallback decode) {
var loaded = _loadBytes(key);
if (loaded.Current is byte[] bytes) {
return decode(bytes);
}
return CodecUtils.getCodec(new Image((Texture2D) obj));
});
throw new Exception("not loaded");
}
IEnumerator _loadBytes(NetworkImage key) {

public readonly float scale;
protected override Future<FileImage> obtainKey(ImageConfiguration configuration) {
return Promise<FileImage>.Resolved(this);
return Future<FileImage>.value(FutureOr.value(this)).to<FileImage>();
protected override ImageStreamCompleter load(FileImage key) {
return new MultiFrameImageStreamCompleter(_loadAsync(key),
protected override ImageStreamCompleter load(FileImage key, DecoderCallback decode) {
return new MultiFrameImageStreamCompleter(_loadAsync(key, decode),
Future<Codec> _loadAsync(FileImage key) {
var coroutine = Window.instance.startCoroutine(_loadBytes(key));
return coroutine.promise.Then(obj => {
if (obj is byte[] bytes) {
return CodecUtils.getCodec(bytes);
}
return CodecUtils.getCodec(new Image((Texture2D) obj));
});
Future<Codec> _loadAsync(FileImage key, DecoderCallback decode) {
var loaded = _loadBytes(key);
if (loaded.Current is byte[] bytes) {
return decode(bytes);
}
throw new Exception("not loaded");
}
IEnumerator _loadBytes(FileImage key) {

public readonly float scale;
protected override Future<MemoryImage> obtainKey(ImageConfiguration configuration) {
return Promise<MemoryImage>.Resolved(this);
return Future<MemoryImage>.value(FutureOr.value(this)).to<MemoryImage>();
protected override ImageStreamCompleter load(MemoryImage key) {
protected override ImageStreamCompleter load(MemoryImage key, DecoderCallback decode) {
_loadAsync(key),
_loadAsync(key, decode),
Future<Codec> _loadAsync(MemoryImage key) {
Future<Codec> _loadAsync(MemoryImage key, DecoderCallback decode) {
return CodecUtils.getCodec(bytes);
return decode(bytes);
}
public bool Equals(MemoryImage other) {

public readonly AssetBundle bundle;
protected override Future<AssetBundleImageKey> obtainKey(ImageConfiguration configuration) {
return Promise<AssetBundleImageKey>.Resolved(new AssetBundleImageKey(
return Future<AssetBundleImageKey>.value(FutureOr.value(new AssetBundleImageKey(
));
))).to<AssetBundleImageKey>();
}
public bool Equals(ExactAssetImage other) {

6
com.unity.uiwidgets/Runtime/painting/image_resolution.cs


using System;
using System.Collections.Generic;
using RSG;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using UnityEngine;

AssetBundleImageKey key;
var cache = AssetBundleCache.instance.get(configuration.bundle);
if (cache.TryGetValue(assetConfig, out key)) {
return Promise<AssetBundleImageKey>.Resolved(key);
return Future<AssetBundleImageKey>.value(FutureOr.value(key)).to<AssetBundleImageKey>();
}
AssetBundle chosenBundle = bundle ? bundle : configuration.bundle;

return Promise<AssetBundleImageKey>.Resolved(key);
return Future<AssetBundleImageKey>.value(FutureOr.value(key)).to<AssetBundleImageKey>();
}
AssetBundleImageKey _loadAsset(AssetBundle bundle, float devicePixelRatio) {

28
com.unity.uiwidgets/Runtime/painting/image_stream.cs


using System;
using System.Collections.Generic;
using System.Linq;
using RSG;
using Unity.UIWidgets.async;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.scheduler2;
using Unity.UIWidgets.ui;

InformationCollector informationCollector = null) {
D.assert(image != null);
image.Then(result => { setImage(result); }).Catch(err => {
image.then_(result => { setImage(result); }).catchError(err => {
reportError(
context: "resolving a single-frame image stream",
exception: err,

_scale = scale;
_informationCollector = informationCollector;
codec.Then((Action<Codec>) _handleCodecReady, ex => {
codec.then_((Action<Codec>) _handleCodecReady, ex => {
reportError(
context: "resolving an image codec",
exception: ex,

return FutureOr.nil;
});
}

TimeSpan delay = _frameDuration.Value - (timestamp - _shownTimestamp.Value);
delay = new TimeSpan((long) (delay.Ticks * scheduler_.timeDilation));
_timer = Window.instance.run(delay, _scheduleAppFrame);
// TODO: time dilation
_timer = Timer.create(delay , ()=> _scheduleAppFrame());
}
bool _isFirstFrame() {

return timestamp - _shownTimestamp >= _frameDuration;
}
void _decodeNextFrameAndSchedule() {
Future _decodeNextFrameAndSchedule() {
_nextFrame = frame;
if (_codec.frameCount == 1) {
_emitFrame(new ImageInfo(image: _nextFrame.image, scale: _scale));
return;
}
return frame.then_(info => {
_nextFrame = info;
if (_codec.frameCount == 1) {
_emitFrame(new ImageInfo(image: _nextFrame.image, scale: _scale));
return;
}
_scheduleAppFrame();
_scheduleAppFrame();
});
}
void _scheduleAppFrame() {

36
com.unity.uiwidgets/Runtime/painting/matrix_utils.cs


static float _max4(float a, float b, float c, float d) {
return Mathf.Max(a, Mathf.Max(b, Mathf.Max(c, d)));
}
public static Matrix4x4 toMatrix4x4(this Matrix3 matrix3) {
var matrix = Matrix4x4.identity;
matrix[0, 0] = matrix3[0]; // row 0
matrix[0, 1] = matrix3[1];
matrix[0, 3] = matrix3[2];
matrix[1, 0] = matrix3[3]; // row 1
matrix[1, 1] = matrix3[4];
matrix[1, 3] = matrix3[5];
matrix[3, 0] = matrix3[6]; // row 2
matrix[3, 1] = matrix3[7];
matrix[3, 3] = matrix3[8];
return matrix;
}
public static Matrix3 toMatrix3(this Matrix4 matrix4) {
var matrix = Matrix3.I();
matrix[0] = matrix4.entry(0, 0);
matrix[1] = matrix4.entry(0, 1);
matrix[2] = matrix4.entry(0, 3);
matrix[3] = matrix4.entry(1, 0);
matrix[4] = matrix4.entry(1, 1);
matrix[5] = matrix4.entry(1, 3);
matrix[6] = matrix4.entry(3, 0);
matrix[7] = matrix4.entry(3, 1);
matrix[8] = matrix4.entry(3, 3);
return matrix;
}
}
public class TransformProperty : DiagnosticsProperty<Matrix4> {

7
com.unity.uiwidgets/Runtime/painting/shader_warmup.cs


using System.Collections.Generic;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.ui;
using Canvas = Unity.UIWidgets.ui2.Canvas;
using Paint = Unity.UIWidgets.ui2.Paint;
using PaintingStyle = Unity.UIWidgets.ui2.PaintingStyle;
using Path = Unity.UIWidgets.ui2.Path;
using Picture = Unity.UIWidgets.ui2.Picture;
using PictureRecorder = Unity.UIWidgets.ui2.PictureRecorder;
using Color = Unity.UIWidgets.ui2.Color;
namespace Unity.UIWidgets.painting {
public abstract class ShaderWarmUp {

2
com.unity.uiwidgets/Runtime/painting/strut_style.cs


defaultValue: foundation_.kNullDefaultValue));
string weightDescription = "";
if (fontWeight != null) {
weightDescription = fontWeight.weightValue.ToString();
weightDescription = $"w${fontWeight.index + 1}00";
}
styles.Add(new DiagnosticsProperty<FontWeight>(

239
com.unity.uiwidgets/Runtime/painting/text_painter.cs


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

namespace Unity.UIWidgets.painting {
public class PlaceholderDimensions {
public PlaceholderDimensions(
Size size,
PlaceholderAlignment alignment,
TextBaseline baseline,
float baselineOffset
) {
D.assert(size != null);
D.assert(alignment != null);
this.size = size;
this.alignment = alignment;
this.baseline = baseline;
this.baselineOffset = baselineOffset;
}
public readonly Size size;
public readonly PlaceholderAlignment alignment;
public readonly float baselineOffset;
public readonly TextBaseline baseline;
public override string ToString() {
return $"PlaceholderDimensions({size}, {baseline})";
}
}
public enum TextWidthBasis {
parent,
longestLine,
}
class _CaretMetrics {
public _CaretMetrics(Offset offset, float? fullHeight) {
this.offset = offset;

}
public class TextPainter {
TextSpan _text;
InlineSpan _text;
TextAlign _textAlign;
TextDirection? _textDirection;
float _textScaleFactor;

string _ellipsis;
float _lastMinWidth;
float _lastMaxWidth;
TextWidthBasis _textWidthBasis;
TextHeightBehavior _textHeightBehavior;
public TextPainter(TextSpan text = null,
public TextPainter(InlineSpan text = null,
StrutStyle strutStyle = null) {
StrutStyle strutStyle = null,
TextWidthBasis textWidthBasis = TextWidthBasis.parent,
TextHeightBehavior textHeightBehavior = null) {
D.assert(text == null || text.debugAssertIsValid());
D.assert(maxLines == null || maxLines > 0);
_text = text;
_textAlign = textAlign;
_textDirection = textDirection;

_strutStyle = strutStyle;
_textWidthBasis = textWidthBasis;
_textHeightBehavior = textHeightBehavior;
}
void markNeedsLayout() {
_paragraph = null;
_needsLayout = true;
_previousCaretPosition = null;
_previousCaretPrototype = null;
}
public float textScaleFactor {

}
_textScaleFactor = value;
markNeedsLayout();
_needsLayout = true;
Paragraph.release(ref _paragraph);
}
}

}
_ellipsis = value;
Paragraph.release(ref _paragraph);
_needsLayout = true;
markNeedsLayout();
public TextSpan text {
public InlineSpan text {
D.assert(value == null || value.debugAssertIsValid());
if ((_text == null && value == null) || (_text != null && text.Equals(value))) {
return;
}

}
_text = value;
Paragraph.release(ref _paragraph);
_needsLayout = true;
markNeedsLayout();
}
}

}
_textDirection = value;
Paragraph.release(ref _paragraph);
markNeedsLayout();
_needsLayout = true;
}
}

}
_textAlign = value;
Paragraph.release(ref _paragraph);
_needsLayout = true;
markNeedsLayout();
}
}

return _paragraph.didExceedMaxLines;
return _paragraph.didExceedMaxLines();
}
}

}
_maxLines = value;
Paragraph.release(ref _paragraph);
_needsLayout = true;
markNeedsLayout();
}
}

}
_strutStyle = value;
_paragraph = null;
_needsLayout = true;
markNeedsLayout();
public TextWidthBasis textWidthBasis {
get { return _textWidthBasis; }
set {
D.assert(value != null);
if (_textWidthBasis == value)
return;
_textWidthBasis = value;
markNeedsLayout();
}
}
public TextHeightBehavior textHeightBehavior {
get { return textHeightBehavior; }
set {
if (_textHeightBehavior == value)
return;
_textHeightBehavior = value;
markNeedsLayout();
}
}
return _applyFloatingPointHack(_paragraph.minIntrinsicWidth);
return _applyFloatingPointHack(_paragraph.minIntrinsicWidth());
}
}

return _applyFloatingPointHack(_paragraph.maxIntrinsicWidth);
return _applyFloatingPointHack(_paragraph.maxIntrinsicWidth());
}
}

return _applyFloatingPointHack(_paragraph.height);
return _applyFloatingPointHack(_paragraph.height());
}
}

return _applyFloatingPointHack(_paragraph.width);
return _applyFloatingPointHack(_paragraph.width());
}
}

case TextBaseline.alphabetic:
return _paragraph.alphabeticBaseline;
return _paragraph.alphabeticBaseline();
return _paragraph.ideographicBaseline;
return _paragraph.ideographicBaseline();
}
return 0.0f;

public void paint(Canvas canvas, Offset offset) {
Debug.Assert(!_needsLayout);
_paragraph.paint(canvas, offset);
canvas.drawParagraph(_paragraph, offset);
}
public Offset getOffsetForCaret(TextPosition position, Rect caretPrototype) {

_caretMetrics = new _CaretMetrics(
offset: rect != null ? new Offset(rect.left, rect.top) : _emptyOffset,
fullHeight: rect != null ? (float?) (rect.bottom - rect.top) : null);
public Paragraph.LineRange getLineRange(int lineNumber) {
public List<TextBox> getBoxesForSelection(TextSelection selection,
ui.BoxHeightStyle boxHeightStyle = ui.BoxHeightStyle.tight,
ui.BoxWidthStyle boxWidthStyle = ui.BoxWidthStyle.tight) {
return _paragraph.getLineRange(lineNumber);
}
public Paragraph.LineRange getLineRange(TextPosition textPosition) {
return getLineRange(getLineIndex(textPosition));
}
public List<TextBox> getBoxesForSelection(TextSelection selection) {
D.assert(!_needsLayout);
var results = _paragraph.getRectsForRange(selection.start, selection.end);
var results = _paragraph.getBoxesForRange(selection.start, selection.end, boxHeightStyle: boxHeightStyle,
boxWidthStyle: boxWidthStyle);
var result = _paragraph.getGlyphPositionAtCoordinate(offset.dx, offset.dy);
return new TextPosition(result.position, result.affinity);
return _paragraph.getPositionForOffset(offset);
var range = _paragraph.getWordBoundary(position.offset);
return new TextRange(range.start, range.end);
}
public TextPosition getPositionVerticalMove(TextPosition position, int move) {
D.assert(!_needsLayout);
var offset = getOffsetForCaret(position, Rect.zero);
var lineIndex = Mathf.Min(Mathf.Max(_paragraph.getLine(position) + move, 0),
_paragraph.getLineCount() - 1);
var targetLineStart = _paragraph.getLineRange(lineIndex).start;
var newLineOffset = getOffsetForCaret(new TextPosition(targetLineStart), Rect.zero);
return getPositionForOffset(new Offset(offset.dx, newLineOffset.dy));
return _paragraph.getWordBoundary(position);
public int getLineIndex(TextPosition position) {
TextRange getLineBoundary(TextPosition position) {
return _paragraph.getLine(position);
}
public int getLineCount() {
D.assert(!_needsLayout);
return _paragraph.getLineCount();
}
public TextPosition getWordRight(TextPosition position) {
D.assert(!_needsLayout);
var offset = position.offset;
while (true) {
var range = _paragraph.getWordBoundary(offset);
if (range.end == range.start) {
break;
}
if (!char.IsWhiteSpace((char) (text.codeUnitAt(range.start) ?? 0))) {
return new TextPosition(range.end);
}
offset = range.end;
}
return new TextPosition(offset, position.affinity);
}
public TextPosition getWordLeft(TextPosition position) {
D.assert(!_needsLayout);
var offset = Mathf.Max(position.offset - 1, 0);
while (true) {
var range = _paragraph.getWordBoundary(offset);
if (!char.IsWhiteSpace((char) (text.codeUnitAt(range.start) ?? 0))) {
return new TextPosition(range.start);
}
offset = Mathf.Max(range.start - 1, 0);
if (offset == 0) {
break;
}
}
return new TextPosition(offset, position.affinity);
return _paragraph.getLineBoundary(position);
if (_text.style == null) {
return new ParagraphStyle(
textAlign: textAlign,
textDirection: textDirection ?? defaultTextDirection,
maxLines: maxLines,
ellipsis: ellipsis,
strutStyle: _strutStyle
);
}
return _text.style.getParagraphStyle(textAlign, textDirection ?? defaultTextDirection,
ellipsis, maxLines, textScaleFactor);
D.assert(textAlign != null);
D.assert(textDirection != null, () => "TextPainter.textDirection must be set to a non-null value before using the TextPainter.");
return _text.style?.getParagraphStyle(
textAlign: textAlign,
textDirection: textDirection ?? defaultTextDirection,
textScaleFactor: textScaleFactor,
maxLines: _maxLines,
// textHeightBehavior: _textHeightBehavior,
ellipsis: _ellipsis
// locale: _locale,
// strutStyle: _strutStyle,
) ?? new ui.ParagraphStyle(
textAlign: textAlign,
textDirection: textDirection ?? defaultTextDirection,
maxLines: maxLines,
textHeightBehavior: _textHeightBehavior,
ellipsis: ellipsis
// locale: locale,
);
}
public float preferredLineHeight {

); // direction doesn't matter, text is just a space
if (text != null && text.style != null) {
builder.pushStyle(text.style, textScaleFactor);
builder.pushStyle(text.style.getTextStyle(textScaleFactor: textScaleFactor));
}
builder.addText(" ");

return _layoutTemplate.height;
return _layoutTemplate.height();
}
}

List<TextBox> boxes = null;
while ((boxes == null || boxes.isEmpty()) && flattenedText != null) {
int prevRuneOffset = offset - graphemeClusterLength;
boxes = _paragraph.getRectsForRange(prevRuneOffset, offset);
boxes = _paragraph.getBoxesForRange(prevRuneOffset, offset);
if (boxes.isEmpty()) {
if (!needsSearch) {
break;

List<TextBox> boxes = null;
while ((boxes == null || boxes.isEmpty()) && flattenedText != null) {
int nextRuneOffset = offset + graphemeClusterLength;
boxes = _paragraph.getRectsForRange(offset, nextRuneOffset);
boxes = _paragraph.getBoxesForRange(offset, nextRuneOffset);
if (boxes.isEmpty()) {
if (!needsSearch) {
break;

190
com.unity.uiwidgets/Runtime/painting/text_span.cs


using UnityEngine.Assertions;
namespace Unity.UIWidgets.painting {
public class TextSpan : DiagnosticableTree, IEquatable<TextSpan> {
public class TextSpan : InlineSpan, IEquatable<TextSpan> {
public List<string> splitedText;
public readonly string semanticsLabel;
public TextSpan(string text = "", TextStyle style = null, List<TextSpan> children = null,
GestureRecognizer recognizer = null, HoverRecognizer hoverRecognizer = null) {
public TextSpan(
string text = "",
TextStyle style = null,
List<TextSpan> children = null,
GestureRecognizer recognizer = null,
HoverRecognizer hoverRecognizer = null,
string semanticsLabel = null) : base(style) {
splitedText = !string.IsNullOrEmpty(text) ? EmojiUtils.splitByEmoji(text) : null;
this.semanticsLabel = semanticsLabel;
public void build(ParagraphBuilder builder, float textScaleFactor = 1.0f) {
var hasStyle = this.style != null;
public override void build(ParagraphBuilder builder, float textScaleFactor = 1.0f,
List<PlaceholderDimensions> dimensions = null) {
D.assert(debugAssertIsValid());
var hasStyle = style != null;
builder.pushStyle(style, textScaleFactor);
builder.pushStyle(style.getTextStyle(textScaleFactor: textScaleFactor));
if (splitedText != null) {
if (splitedText.Count == 1 && !char.IsHighSurrogate(splitedText[0][0]) &&
!EmojiUtils.isSingleCharEmoji(splitedText[0][0])) {
builder.addText(splitedText[0]);
if (text != null)
builder.addText(text);
if (children != null) {
foreach (InlineSpan child in children) {
D.assert(child != null);
child.build(
builder,
textScaleFactor: textScaleFactor,
dimensions: dimensions
);
else {
TextStyle style = this.style ?? new TextStyle();
for (int i = 0; i < splitedText.Count; i++) {
builder.pushStyle(style, textScaleFactor);
builder.addText(splitedText[i]);
builder.pop();
}
}
if (hasStyle) {
builder.pop();
}
}
public override bool visitChildren(InlineSpanVisitor visitor) {
if (text != null) {
if (!visitor(this))
return false;
}
if (children != null) {
foreach (InlineSpan child in children) {
if (!child.visitChildren(visitor))
return false;
return true;
}
protected override InlineSpan getSpanForPositionVisitor(TextPosition position, Accumulator offset) {
if (text == null) {
return null;
}
TextAffinity affinity = position.affinity;
int targetOffset = position.offset;
int endOffset = offset.value + text.Length;
if (offset.value == targetOffset && affinity == TextAffinity.downstream ||
offset.value < targetOffset && targetOffset < endOffset ||
endOffset == targetOffset && affinity == TextAffinity.upstream) {
return this;
}
offset.increment(text.Length);
return null;
}
public override void computeToPlainText(StringBuilder buffer, bool includeSemanticsLabels = true,
bool includePlaceholders = true) {
D.assert(debugAssertIsValid());
if (semanticsLabel != null && includeSemanticsLabels) {
buffer.Append(semanticsLabel);
}
else if (text != null) {
buffer.Append(text);
}
foreach (var child in children) {
Assert.IsNotNull(child);
child.build(builder, textScaleFactor);
foreach (InlineSpan child in children) {
child.computeToPlainText(buffer,
includeSemanticsLabels: includeSemanticsLabels,
includePlaceholders: includePlaceholders
);
}
if (hasStyle) {
builder.pop();
public override void computeSemanticsInformation(List<InlineSpanSemanticsInformation> collector) {
D.assert(debugAssertIsValid());
if (text != null || semanticsLabel != null) {
collector.Add(new InlineSpanSemanticsInformation(
text,
semanticsLabel: semanticsLabel,
recognizer: recognizer
));
}
if (children != null) {
foreach (InlineSpan child in children) {
child.computeSemanticsInformation(collector);
}
protected override int? codeUnitAtVisitor(int index, Accumulator offset) {
if (text == null) {
return null;
}
if (index - offset.value < text.Length) {
return text[index - offset.value];
}
offset.increment(text.Length);
return null;
}
public bool hasHoverRecognizer {
get {
bool need = false;

return result;
}
public string toPlainText() {
var sb = new StringBuilder();
visitTextSpan((span) => {
sb.Append(span.text);
return true;
});
return sb.ToString();
}
public int? codeUnitAt(int index) {
if (index < 0) {
return null;

return true;
}
public RenderComparison compareTo(TextSpan other) {
if (Equals(other)) {
public override RenderComparison compareTo(InlineSpan other) {
if (Equals(this, other))
}
if (other.text != text
|| ((children == null) != (other.children == null))
|| (children != null && other.children != null && children.Count != other.children.Count)
|| ((style == null) != (other.style != null))
) {
if (other.GetType()!= GetType())
}
RenderComparison result = Equals(recognizer, other.recognizer)
? RenderComparison.identical
: RenderComparison.metadata;
if (!Equals(hoverRecognizer, other.hoverRecognizer)) {
result = RenderComparison.function > result ? RenderComparison.function : result;
}
TextSpan textSpan = other as TextSpan;
if (textSpan.text != text ||
children?.Count != textSpan.children?.Count ||
(style == null) != (textSpan.style == null))
return RenderComparison.layout;
RenderComparison result = recognizer == textSpan.recognizer ?
RenderComparison.identical :
RenderComparison.metadata;
var candidate = style.compareTo(other.style);
if (candidate > result) {
RenderComparison candidate = style.compareTo(textSpan.style);
if (candidate > result)
}
if (result == RenderComparison.layout) {
if (result == RenderComparison.layout)
}
for (var index = 0; index < children.Count; index++) {
var candidate = children[index].compareTo(other.children[index]);
if (candidate > result) {
for (int index = 0; index < children.Count; index += 1) {
RenderComparison candidate = children[index].compareTo(textSpan.children[index]);
if (candidate > result)
}
if (result == RenderComparison.layout) {
if (result == RenderComparison.layout)
}
return result;
}

40
com.unity.uiwidgets/Runtime/painting/text_style.cs


public ParagraphStyle getParagraphStyle(TextAlign textAlign,
TextDirection textDirection, string ellipsis, int? maxLines, float textScaleFactor = 1.0f) {
return new ParagraphStyle(
textAlign, textDirection, fontWeight, fontStyle,
maxLines, (fontSize ?? _defaultFontSize) * textScaleFactor, fontFamily, height,
ellipsis
textAlign: textAlign, textDirection: textDirection, fontWeight: fontWeight, fontStyle: fontStyle,
maxLines: maxLines, fontSize: (fontSize ?? _defaultFontSize) * textScaleFactor, fontFamily: fontFamily,
height: height,
ellipsis: ellipsis
);
}

);
}
public ui.TextStyle getTextStyle(float textScaleFactor = 1.0f ) {
var backgroundPaint = new Paint();
if (background != null) {
backgroundPaint = new Paint();
backgroundPaint.color = backgroundColor;
}
return new ui.TextStyle(
color: color,
decoration: decoration,
decorationColor: decorationColor,
decorationStyle: decorationStyle,
decorationThickness: decorationThickness,
fontWeight: fontWeight,
fontStyle: fontStyle,
textBaseline: textBaseline,
fontFamily: fontFamily,
fontFamilyFallback: fontFamilyFallback,
fontSize: fontSize == null ? null : fontSize * textScaleFactor,
letterSpacing: letterSpacing,
wordSpacing: wordSpacing,
height: height,
// locale: locale,
foreground: foreground,
background: background ?? (backgroundColor != null
? backgroundPaint : null
),
shadows: shadows.Cast<Shadow>().ToList()
// fontFeatures: fontFeatures,
);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);

defaultValue: foundation_.kNullDefaultValue));
string weightDescription = "";
if (fontWeight != null) {
weightDescription = fontWeight.weightValue.ToString();
weightDescription = $"{fontWeight.index + 1}00";
}
styles.Add(new DiagnosticsProperty<FontWeight>(

2
com.unity.uiwidgets/Runtime/ui2/painting.cs


}
}
public unsafe void addPath(Path path, Offset offset, float[] matrix4) {
public unsafe void addPath(Path path, Offset offset, float[] matrix4 = null) {
D.assert(path != null); // path is checked on the engine side
D.assert(PaintingUtils._offsetIsValid(offset));

206
com.unity.uiwidgets/Runtime/painting/inline_span.cs


using System;
using System.Collections.Generic;
using System.Text;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.painting {
public class Accumulator {
public Accumulator(int _value = 0) {
this._value = _value;
}
public int value {
get { return _value; }
}
int _value;
public void increment(int addend) {
D.assert(addend >= 0);
_value += addend;
}
}
public delegate bool InlineSpanVisitor(InlineSpan span);
public delegate bool TextSpanVisitor(TextSpan span);
public class InlineSpanSemanticsInformation : IEquatable<InlineSpanSemanticsInformation> {
public InlineSpanSemanticsInformation(
string text,
bool isPlaceholder = false,
string semanticsLabel = null,
GestureRecognizer recognizer = null
) {
D.assert(text != null);
D.assert(isPlaceholder != null);
D.assert(isPlaceholder == false || (text == "\uFFFC" && semanticsLabel == null && recognizer == null));
requiresOwnNode = isPlaceholder || recognizer != null;
}
public static readonly InlineSpanSemanticsInformation placeholder =
new InlineSpanSemanticsInformation("\uFFFC", isPlaceholder: true);
public readonly string text;
public readonly string semanticsLabel;
public readonly GestureRecognizer recognizer;
public readonly bool isPlaceholder;
public readonly bool requiresOwnNode;
public override string ToString() =>
$"{foundation_.objectRuntimeType(this, "InlineSpanSemanticsInformation")}" +
$"{text: $text, semanticsLabel: $semanticsLabel, recognizer: $recognizer}";
public bool Equals(InlineSpanSemanticsInformation other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return text == other.text && semanticsLabel == other.semanticsLabel &&
Equals(recognizer, other.recognizer) && isPlaceholder == other.isPlaceholder;
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {
return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
if (obj.GetType() != GetType()) {
return false;
}
return Equals((InlineSpanSemanticsInformation) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = (text != null ? text.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (semanticsLabel != null ? semanticsLabel.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (recognizer != null ? recognizer.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ isPlaceholder.GetHashCode();
return hashCode;
}
}
}
public abstract class InlineSpan : DiagnosticableTree, IEquatable<InlineSpan> {
public InlineSpan(
TextStyle style = null
) {
this.style = style;
}
public readonly TextStyle style;
public abstract void build(ParagraphBuilder builder,
float textScaleFactor = 1, List<PlaceholderDimensions> dimensions = null
);
public abstract bool visitChildren(InlineSpanVisitor visitor);
public InlineSpan getSpanForPosition(TextPosition position) {
D.assert(debugAssertIsValid());
Accumulator offset = new Accumulator();
InlineSpan result = null;
visitChildren((InlineSpan span) => {
result = span.getSpanForPositionVisitor(position, offset);
return result == null;
});
return result;
}
protected abstract InlineSpan getSpanForPositionVisitor(TextPosition position, Accumulator offset);
public string toPlainText(
bool includeSemanticsLabels = true, bool includePlaceholders = true) {
StringBuilder buffer = new StringBuilder();
computeToPlainText(buffer, includeSemanticsLabels: includeSemanticsLabels,
includePlaceholders: includePlaceholders);
return buffer.ToString();
}
List<InlineSpanSemanticsInformation> getSemanticsInformation() {
List<InlineSpanSemanticsInformation> collector = new List<InlineSpanSemanticsInformation>();
computeSemanticsInformation(collector);
return collector;
}
public abstract void computeSemanticsInformation(List<InlineSpanSemanticsInformation> collector);
public abstract void computeToPlainText(StringBuilder buffer,
bool includeSemanticsLabels = true, bool includePlaceholders = true);
public int? codeUnitAt(int index) {
if (index < 0)
return null;
Accumulator offset = new Accumulator();
int? result = null;
visitChildren((InlineSpan span) => {
result = span.codeUnitAtVisitor(index, offset);
return result == null;
});
return result;
}
protected abstract int? codeUnitAtVisitor(int index, Accumulator offset);
public bool debugAssertIsValid() => true;
public abstract RenderComparison compareTo(InlineSpan other);
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.defaultDiagnosticsTreeStyle = DiagnosticsTreeStyle.whitespace;
if (style != null) {
style.debugFillProperties(properties);
}
}
public bool Equals(InlineSpan other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return Equals(style, other.style);
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {
return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
if (obj.GetType() != GetType()) {
return false;
}
return Equals((InlineSpan) obj);
}
public override int GetHashCode() {
return (style != null ? style.GetHashCode() : 0);
}
}
}
正在加载...
取消
保存