浏览代码

Implement text shadow.

/main
Yuncong Zhang 5 年前
当前提交
251189b5
共有 3 个文件被更改,包括 65 次插入18 次删除
  1. 32
      Runtime/painting/text_style.cs
  2. 19
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs
  3. 32
      Runtime/ui/text.cs

32
Runtime/painting/text_style.cs


public readonly Paint foreground;
public readonly Paint background;
public readonly string fontFamily;
public readonly List<BoxShadow> shadows;
public List<string> fontFamilyFallback {
get { return this._fontFamilyFallback; }

float? decorationThickness = null,
string fontFamily = null,
List<string> fontFamilyFallback = null,
List<BoxShadow> shadows = null,
string debugLabel = null) {
D.assert(color == null || foreground == null, () => _kColorForegroundWarning);
D.assert(backgroundColor == null || background == null, () => _kColorBackgroundWarning);

this.debugLabel = debugLabel;
this.foreground = foreground;
this.background = background;
this.shadows = shadows;
if (this.inherit != other.inherit || this.fontFamily != other.fontFamily
|| this.fontSize != other.fontSize || this.fontWeight != other.fontWeight
|| this.fontStyle != other.fontStyle ||
this.letterSpacing != other.letterSpacing
|| this.wordSpacing != other.wordSpacing ||
this.textBaseline != other.textBaseline
|| this.height != other.height || this.background != other.background) {
if (this.inherit != other.inherit || this.fontFamily != other.fontFamily ||
this.fontSize != other.fontSize || this.fontWeight != other.fontWeight ||
this.fontStyle != other.fontStyle || this.letterSpacing != other.letterSpacing ||
this.wordSpacing != other.wordSpacing || this.textBaseline != other.textBaseline ||
this.height != other.height || this.background != other.background ||
this.shadows.equalsList(other.shadows)) {
this.decorationColor != other.decorationColor
|| this.decorationStyle != other.decorationStyle) {
this.decorationColor != other.decorationColor ||
this.decorationStyle != other.decorationStyle) {
return RenderComparison.paint;
}

float decorationThicknessDelta = 0.0f,
string fontFamily = null,
List<string> fontFamilyFallback = null,
List<BoxShadow> shadows = null,
float fontSizeFactor = 1.0f,
float fontSizeDelta = 0.0f,
int fontWeightDelta = 0,

decorationThickness: this.decorationThickness == null
? null
: this.decorationThickness * decorationThicknessFactor + decorationThicknessDelta,
shadows: shadows ?? this.shadows,
debugLabel: modifiedDebugLabel
);
}

decorationColor: other.decorationColor,
decorationStyle: other.decorationStyle,
decorationThickness: other.decorationThickness,
shadows: other.shadows,
debugLabel: mergedDebugLabel
);
}

Color decorationColor = null,
TextDecorationStyle? decorationStyle = null,
float? decorationThickness = null,
List<BoxShadow> shadows = null,
string debugLabel = null) {
D.assert(color == null || foreground == null, () => _kColorForegroundWarning);
D.assert(backgroundColor == null || background == null, () => _kColorBackgroundWarning);

decorationThickness: decorationThickness ?? this.decorationThickness,
foreground: foreground ?? this.foreground,
background: background ?? this.background,
shadows: shadows ?? this.shadows,
debugLabel: newDebugLabel
);
}

decorationColor: Color.lerp(null, b.decorationColor, t),
decorationStyle: t < 0.5f ? null : b.decorationStyle,
decorationThickness: t < 0.5f ? null : b.decorationThickness,
shadows: t < 0.5f ? null : b.shadows,
debugLabel: lerpDebugLabel
);
}

decorationColor: Color.lerp(a.decorationColor, null, t),
decorationStyle: t < 0.5f ? a.decorationStyle : null,
decorationThickness: t < 0.5f ? a.decorationThickness : null,
shadows: t < 0.5f ? a.shadows : null,
debugLabel: lerpDebugLabel
);
}

decorationThickness: MathUtils.lerpFloat(
a.decorationThickness ?? b.decorationThickness ?? 0.0f,
b.decorationThickness ?? a.decorationThickness ?? 0.0f, t),
shadows: t < 0.5f ? a.shadows : b.shadows,
debugLabel: lerpDebugLabel
);
}

this.decorationThickness == other.decorationThickness &&
Equals(this.foreground, other.foreground) &&
Equals(this.background, other.background) &&
CollectionUtils.equalsList(this.fontFamilyFallback, other.fontFamilyFallback) &&
this.fontFamilyFallback.equalsList(other.fontFamilyFallback) &&
this.shadows.equalsList(other.shadows) &&
string.Equals(this.fontFamily, other.fontFamily);
}

hashCode = (hashCode * 397) ^ (this.fontFamily != null ? this.fontFamily.GetHashCode() : 0);
hashCode = (hashCode * 397) ^
(this.fontFamilyFallback != null ? this.fontFamilyFallback.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.shadows != null ? this.shadows.GetHashCode() : 0);
return hashCode;
}
}

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


}
case DrawTextBlob cmd: {
this._paintTextShadow(cmd.textBlob, cmd.offset);
this._drawTextBlob(cmd.textBlob, (uiOffset.fromOffset(cmd.offset)).Value,
uiPaint.fromPaint(cmd.paint));
break;

}
case uiDrawTextBlob cmd: {
this._paintTextShadow(cmd.textBlob, new Offset(cmd.offset.Value.dx, cmd.offset.Value.dy));
this._drawTextBlob(cmd.textBlob, cmd.offset.Value, cmd.paint);
break;
}

if (needsSave) {
this._restore();
}
}
void _paintTextShadow(TextBlob? textBlob, Offset offset) {
D.assert(textBlob != null);
if (textBlob.Value.style.shadows != null && textBlob.Value.style.shadows.isNotEmpty()) {
textBlob.Value.style.shadows.ForEach(shadow => {
Paint paint = new Paint {
color = shadow.color,
maskFilter = shadow.blurRadius != 0
? MaskFilter.blur(BlurStyle.normal, shadow.blurRadius)
: null,
};
this._drawTextBlob(textBlob, uiOffset.fromOffset(shadow.offset + offset).Value,
uiPaint.fromPaint(paint));
});
}
}

}
this._drawTextDrawMeshCallback(paint, null, null, false, 0, 0, tex, textBlobBounds, mesh, notEmoji);
}
public void flush(uiPicture picture) {

32
Runtime/ui/text.cs


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

public readonly string fontFamily = kDefaultFontFamily;
public readonly Paint foreground;
public readonly Paint background;
public readonly List<BoxShadow> shadows;
internal UnityEngine.Color UnityColor {
get { return this.color.toColor(); }

decorationColor: style.decorationColor ?? currentStyle.decorationColor,
fontFamily: style.fontFamily ?? currentStyle.fontFamily,
foreground: style.foreground ?? currentStyle.foreground,
background: style.background ?? currentStyle.background
background: style.background ?? currentStyle.background,
shadows: style.shadows ?? currentStyle.shadows
);
}

decorationColor: style.decorationColor,
fontFamily: style.fontFamily,
foreground: style.foreground,
background: style.background
background: style.background,
shadows: style.shadows
);
}

Equals(this.decoration, other.decoration) &&
Equals(this.decorationColor, other.decorationColor) &&
this.decorationStyle == other.decorationStyle &&
string.Equals(this.fontFamily, other.fontFamily);
string.Equals(this.fontFamily, other.fontFamily) &&
this.shadows.equalsList(other.shadows);
}
public override bool Equals(object obj) {

hashCode = (hashCode * 397) ^ (this.decorationColor != null ? this.decorationColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ this.decorationStyle.GetHashCode();
hashCode = (hashCode * 397) ^ (this.fontFamily != null ? this.fontFamily.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.shadows != null ? this.shadows.GetHashCode() : 0);
return hashCode;
}
}

}
public TextStyle(Color color = null, float? fontSize = null,
FontWeight fontWeight = null, FontStyle? fontStyle = null, float? letterSpacing = null,
float? wordSpacing = null, TextBaseline? textBaseline = null, float? height = null,
TextDecoration decoration = null, TextDecorationStyle? decorationStyle = null, Color decorationColor = null,
public TextStyle(Color color = null,
float? fontSize = null,
FontWeight fontWeight = null,
FontStyle? fontStyle = null,
float? letterSpacing = null,
float? wordSpacing = null,
TextBaseline? textBaseline = null,
float? height = null,
TextDecoration decoration = null,
TextDecorationStyle? decorationStyle = null,
Color decorationColor = null,
Paint background = null
Paint background = null,
List<BoxShadow> shadows = null
) {
this.color = color ?? this.color;
this.fontSize = fontSize ?? this.fontSize;

this.fontFamily = fontFamily ?? this.fontFamily;
this.foreground = foreground ?? this.foreground;
this.background = background ?? this.background;
this.shadows = shadows ?? this.shadows;
}
}

正在加载...
取消
保存