Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit c5bdf08

Browse files
authored
Merge pull request #326 from IIzzaya/master
[Fix] Gradient Text Support
2 parents 836d2bb + f3283f2 commit c5bdf08

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

Runtime/painting/text_style.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public TextStyle(bool inherit = true,
7878
this.fontFamily = fontFamily;
7979
this._fontFamilyFallback = fontFamilyFallback;
8080
this.debugLabel = debugLabel;
81+
this.foreground = foreground;
8182
this.background = background;
8283
}
8384

@@ -264,6 +265,7 @@ public TextStyle copyWith(
264265
decorationColor: decorationColor ?? this.decorationColor,
265266
decorationStyle: decorationStyle ?? this.decorationStyle,
266267
decorationThickness: decorationThickness ?? this.decorationThickness,
268+
foreground: foreground ?? this.foreground,
267269
background: background ?? this.background,
268270
debugLabel: newDebugLabel
269271
);

Runtime/ui/text.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class TextStyle : IEquatable<TextStyle> {
9797
public readonly Color decorationColor;
9898
public readonly TextDecorationStyle decorationStyle = kDefaultDecorationStyle;
9999
public readonly string fontFamily = kDefaultFontFamily;
100+
public readonly Paint foreground;
100101
public readonly Paint background;
101102

102103
internal UnityEngine.Color UnityColor {
@@ -140,6 +141,7 @@ public static TextStyle applyStyle(TextStyle currentStyle, painting.TextStyle st
140141
decoration: style.decoration ?? currentStyle.decoration,
141142
decorationColor: style.decorationColor ?? currentStyle.decorationColor,
142143
fontFamily: style.fontFamily ?? currentStyle.fontFamily,
144+
foreground: style.foreground ?? currentStyle.foreground,
143145
background: style.background ?? currentStyle.background
144146
);
145147
}
@@ -156,6 +158,7 @@ public static TextStyle applyStyle(TextStyle currentStyle, painting.TextStyle st
156158
decoration: style.decoration,
157159
decorationColor: style.decorationColor,
158160
fontFamily: style.fontFamily,
161+
foreground: style.foreground,
159162
background: style.background
160163
);
161164
}
@@ -227,6 +230,7 @@ public TextStyle(Color color = null, float? fontSize = null,
227230
float? wordSpacing = null, TextBaseline? textBaseline = null, float? height = null,
228231
TextDecoration decoration = null, TextDecorationStyle? decorationStyle = null, Color decorationColor = null,
229232
string fontFamily = null,
233+
Paint foreground = null,
230234
Paint background = null
231235
) {
232236
this.color = color ?? this.color;
@@ -242,6 +246,7 @@ public TextStyle(Color color = null, float? fontSize = null,
242246
this.decorationStyle = decorationStyle ?? this.decorationStyle;
243247
this.decorationColor = decorationColor ?? this.decorationColor;
244248
this.fontFamily = fontFamily ?? this.fontFamily;
249+
this.foreground = foreground ?? this.foreground;
245250
this.background = background ?? this.background;
246251
}
247252
}

Runtime/ui/txt/paragraph.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ public void clear() {
286286
this._paragraphStyle = null;
287287
}
288288

289-
readonly Paint _textPaint = new Paint {
289+
Paint _textPaint = new Paint {
290+
filterMode = FilterMode.Bilinear
291+
};
292+
293+
Paint _defaultPaint = new Paint {
290294
filterMode = FilterMode.Bilinear
291295
};
292296

@@ -298,8 +302,17 @@ public void paint(Canvas canvas, Offset offset) {
298302

299303
for (int i = 0; i < this._paintRecordsCount; i++) {
300304
var paintRecord = this._paintRecords[i];
301-
this._textPaint.color = paintRecord.style.color;
305+
306+
if (paintRecord.style.foreground != null) {
307+
this._textPaint = paintRecord.style.foreground;
308+
}
309+
else {
310+
this._textPaint = this._defaultPaint;
311+
this._textPaint.color = paintRecord.style.color;
312+
}
313+
302314
canvas.drawTextBlob(paintRecord.text, paintRecord.shiftedOffset(offset), this._textPaint);
315+
303316
this.paintDecorations(canvas, paintRecord, offset);
304317
}
305318
}

0 commit comments

Comments
 (0)