浏览代码

some fix

/main
fzhangtj 6 年前
当前提交
65454de6
共有 9 个文件被更改,包括 87 次插入113 次删除
  1. 2
      Assets/UIWidgets/painting/text_painter.cs
  2. 2
      Assets/UIWidgets/painting/text_span.cs
  3. 31
      Assets/UIWidgets/painting/text_style.cs
  4. 2
      Assets/UIWidgets/ui/painting/canvas_impl.cs
  5. 2
      Assets/UIWidgets/ui/painting/txt/mesh_generator.cs
  6. 129
      Assets/UIWidgets/ui/text.cs
  7. 2
      Assets/UIWidgets/ui/txt/linebreaker.cs
  8. 14
      Assets/UIWidgets/ui/txt/paragraph.cs
  9. 16
      Assets/UIWidgets/ui/txt/paragraph_builder.cs

2
Assets/UIWidgets/painting/text_painter.cs


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

2
Assets/UIWidgets/painting/text_span.cs


var hasTyle = style != null;
if (hasTyle)
{
builder.pushStyle(style.getTextStyle(textScaleFactor));
builder.pushStyle(style);
}
if (!string.IsNullOrEmpty(text))
{

31
Assets/UIWidgets/painting/text_style.cs


namespace UIWidgets.painting
{
public class TextStyle : Diagnosticable, IEquatable<TextStyle>
public class TextStyle : Diagnosticable, IEquatable<TextStyle>, ParagraphBuilder.ITextStyleProvider
{
public static readonly double _defaultFontSize = 14.0;
public readonly bool inherit;

this.background = background;
}
public ui.TextStyle getTextStyle(double textScaleFactor = 1.0)
public ui.TextStyle getTextStyle(ui.TextStyle currentStyle = null)
if (currentStyle != null)
{
return new ui.TextStyle(
color: color??currentStyle.color,
fontSize: fontSize??currentStyle.fontSize,
fontWeight: fontWeight??currentStyle.fontWeight,
fontStyle: fontStyle??currentStyle.fontStyle,
letterSpacing: letterSpacing??currentStyle.letterSpacing,
wordSpacing: wordSpacing??currentStyle.wordSpacing,
textBaseline: textBaseline??currentStyle.textBaseline,
height: height??currentStyle.height,
decoration: decoration??currentStyle.decoration,
decorationColor: decorationColor??currentStyle.decorationColor,
fontFamily: fontFamily??currentStyle.fontFamily,
background: background??currentStyle.background
);
}
color: color,
decoration: decoration,
decorationColor: decorationColor,
decorationStyle: decorationStyle,
color: color,
fontSize: fontSize,
fontSize: fontSize == null ? null : fontSize * textScaleFactor,
decoration: decoration,
decorationColor: decorationColor,
fontFamily: fontFamily,
background: background
);

2
Assets/UIWidgets/ui/painting/canvas_impl.cs


public void drawTextBlob(TextBlob textBlob, double x, double y)
{
var mesh = MeshGenrator.generateMesh(textBlob, x, y);
var font = FontManager.instance.getOrCreate(textBlob.style.fontFamilyOrDefault, textBlob.style.UnityFontSize);
var font = FontManager.instance.getOrCreate(textBlob.style.fontFamily, textBlob.style.UnityFontSize);
prepareGL(font.material);
font.material.SetPass(0);
Graphics.DrawMeshNow(mesh, Matrix4x4.identity);

2
Assets/UIWidgets/ui/painting/txt/mesh_generator.cs


public static Mesh generateMesh(TextBlob textBlob, double x, double y)
{
var style = textBlob.style;
var font = FontManager.instance.getOrCreate(style.fontFamilyOrDefault, style.UnityFontSize);
var font = FontManager.instance.getOrCreate(style.fontFamily, style.UnityFontSize);
var length = textBlob.end - textBlob.start;
var vertices = new Vector3[length * 4];
var triangles = new int[length * 6];

129
Assets/UIWidgets/ui/text.cs


public class TextStyle : IEquatable<TextStyle>
{
public static readonly string defaultFontFamily = "Helvetica";
public static readonly double defaultFontSize = 14.0;
public static readonly FontWeight defaultFontWeight = FontWeight.w400;
public static readonly FontStyle defaultFontStyle = FontStyle.normal;
public static readonly Color defaultColor = Color.fromARGB(255, 0, 0, 0);
public readonly Color color;
public readonly double? fontSize;
public readonly FontWeight? fontWeight;
public readonly FontStyle? fontStyle;
public readonly double? letterSpacing;
public readonly double? wordSpacing;
public readonly TextBaseline? textBaseline;
public readonly double? height;
public readonly TextDecoration decoration;
public readonly Color color = Color.fromARGB(255, 0, 0, 0);
public readonly double fontSize = 14.0;
public readonly FontWeight fontWeight = FontWeight.w400;
public readonly FontStyle fontStyle = FontStyle.normal;
public readonly double letterSpacing = 0.0;
public readonly double wordSpacing = 0.0;
public readonly TextBaseline textBaseline = TextBaseline.alphabetic;
public readonly double height = 1.0;
public readonly TextDecoration decoration = TextDecoration.none;
public readonly TextDecorationStyle? decorationStyle;
public readonly string fontFamily;
public readonly TextDecorationStyle decorationStyle = TextDecorationStyle.solid;
public readonly string fontFamily = "Helvetica";
public FontStyle fontStyleOrDefault
{
get { return fontStyle ?? defaultFontStyle; }
}
public string fontFamilyOrDefault
{
get { return fontFamily ?? defaultFontFamily; }
}
public double fontSizeOrDefault
{
get { return fontSize ?? defaultFontSize; }
}
public Color colorOrDefault
{
get { return color ?? defaultColor; }
}
public TextDecorationStyle decorationStyleOrDefault
{
get { return decorationStyle ?? TextDecorationStyle.solid; }
}
public FontWeight safeFontWeight
{
get { return fontWeight ?? defaultFontWeight; }
}
get { return (color ?? defaultColor).toColor(); }
get { return color.toColor(); }
}
public UnityEngine.FontStyle UnityFontStyle

if (fontStyleOrDefault == FontStyle.italic)
if (fontStyle == FontStyle.italic)
if (safeFontWeight == FontWeight.w700)
if (fontWeight == FontWeight.w700)
{
return UnityEngine.FontStyle.BoldAndItalic;
}

}
}
else if (safeFontWeight == FontWeight.w700)
else if (fontWeight == FontWeight.w700)
{
return UnityEngine.FontStyle.Bold;
}

public int UnityFontSize
{
get { return (int) fontSizeOrDefault; }
}
public TextStyle merge(TextStyle style)
{
var ret = new TextStyle(
color: style.color ?? color,
fontSize: style.fontSize ?? fontSize,
fontWeight: style.fontWeight ?? fontWeight,
fontStyle: style.fontStyle ?? fontStyle,
letterSpacing: style.letterSpacing ?? letterSpacing,
textBaseline: style.textBaseline ?? textBaseline,
height: style.height ?? height,
decoration: style.decoration ?? decoration,
decorationColor: style.decorationColor ?? decorationColor,
decorationStyle: style.decorationStyle ?? decorationStyle,
background: style.background ?? background,
fontFamily: style.fontFamily ?? fontFamily
);
return ret;
get { return (int) fontSize; }
public bool Equals(TextStyle other)
{

return !Equals(left, right);
}
public TextStyle(Color color = null, double? fontSize = default(double?),
FontWeight? fontWeight = default(FontWeight?),
FontStyle? fontStyle = default(FontStyle?), double? letterSpacing = default(double?),
double? wordSpacing = default(double?), TextBaseline? textBaseline = default(TextBaseline?),
double? height = default(double?), TextDecoration decoration = null, Color decorationColor = null,
TextDecorationStyle? decorationStyle = null, string fontFamily = null, Paint background = null)
public TextStyle(Color color = null, double? fontSize = null,
FontWeight? fontWeight = null, FontStyle? fontStyle = null, double? letterSpacing = null,
double? wordSpacing = null, TextBaseline? textBaseline = null, double? height= null,
TextDecoration decoration = null, TextDecorationStyle? decorationStyle = null, Color decorationColor = null, string fontFamily = null,
Paint background = null
)
this.color = color;
this.fontSize = fontSize;
this.fontWeight = fontWeight;
this.fontStyle = fontStyle;
this.letterSpacing = letterSpacing;
this.wordSpacing = wordSpacing;
this.textBaseline = textBaseline;
this.height = height;
this.decoration = decoration;
this.fontFamily = fontFamily;
this.decorationStyle = decorationStyle;
this.decorationColor = decorationColor;
this.background = background;
this.color = color ?? this.color;
this.fontSize = fontSize ?? this.fontSize;
this.fontWeight = fontWeight ?? this.fontWeight;
this.fontStyle = fontStyle ?? this.fontStyle;
this.letterSpacing = letterSpacing ?? this.letterSpacing;
this.wordSpacing = wordSpacing ?? this.wordSpacing;
this.fontSize = fontSize ?? this.fontSize;
this.textBaseline = textBaseline ?? this.textBaseline;
this.height = height ?? this.height;
this.decoration = decoration ?? this.decoration;
this.decorationStyle = decorationStyle ?? this.decorationStyle;
this.decorationColor = decorationColor ?? this.decorationColor;
this.fontFamily = fontFamily ?? this.fontFamily;
this.background = background ?? this.background;
}
}

2
Assets/UIWidgets/ui/txt/linebreaker.cs


{
runIterator.nextTo(charIndex);
var run = runIterator.run;
var font = FontManager.instance.getOrCreate(run.style.fontFamilyOrDefault, run.style.UnityFontSize);
var font = FontManager.instance.getOrCreate(run.style.fontFamily, run.style.UnityFontSize);
var style = run.style;
var charInfo = new CharacterInfo();

14
Assets/UIWidgets/ui/txt/paragraph.cs


var run = _runs.getRun(i);
if (run.start < run.end)
{
var font = FontManager.instance.getOrCreate(run.style.fontFamilyOrDefault, run.style.UnityFontSize);
var font = FontManager.instance.getOrCreate(run.style.fontFamily, run.style.UnityFontSize);
font.RequestCharactersInTexture(_text.Substring(run.start, run.end - run.start), 0,
run.style.UnityFontStyle);
}

var run = runIndex < _runs.size ? _runs.getRun(runIndex) : null;
if (run != null && run.start < run.end && run.start < line.end && run.end > line.start)
{
var font = FontManager.instance.getOrCreate(run.style.fontFamilyOrDefault, run.style.UnityFontSize);
var font = FontManager.instance.getOrCreate(run.style.fontFamily, run.style.UnityFontSize);
var ascent = font.ascent * (run.style.height??1.0);
var descent = (font.lineHeight - font.ascent) * (run.style.height??1.0);
var ascent = font.ascent * (run.style.height);
var descent = (font.lineHeight - font.ascent) * (run.style.height);
if (metrics.ascent > maxAscent)
{
maxAscent = metrics.ascent;

var paint = new Paint();
if (record.style.decorationColor == null)
{
paint.color = record.style.colorOrDefault;
paint.color = record.style.color;
}
else
{

var width = record.runWidth;
var metrics = record.metrics;
double underLineThickness = metrics.underlineThickness ?? (record.style.fontSizeOrDefault / 14.0);
double underLineThickness = metrics.underlineThickness ?? (record.style.fontSize / 14.0);
paint.strokeWidth = underLineThickness;
var recordOffset = baseOffset + record.offset;
var x = recordOffset.dx;

switch (record.style.decorationStyleOrDefault)
switch (record.style.decorationStyle)
{
case TextDecorationStyle.doubleLine:
decorationCount = 2;

16
Assets/UIWidgets/ui/txt/paragraph_builder.cs


private List<int> _styleStack = new List<int>();
private int _paragraph_style_index;
public interface ITextStyleProvider
{
TextStyle getTextStyle(TextStyle current = null);
}
public ParagraphBuilder(ParagraphStyle style)
{
setParagraphStyle(style);

return paragraph;
}
public void pushStyle(TextStyle style)
public void pushStyle(ITextStyleProvider style)
var newStyle = peekStyle().merge(style);
var newStyle = style.getTextStyle(peekStyle());
_styleStack.Add(styleIndex);
_runs.startRun(styleIndex, _text.Length);
}
public void pushStyle(TextStyle style)
{
var styleIndex = _runs.addStyle(style);
_styleStack.Add(styleIndex);
_runs.startRun(styleIndex, _text.Length);
}

正在加载...
取消
保存