浏览代码

Remove getTextStyle from _layout.

/main
Yuncong Zhang 5 年前
当前提交
b45ec371
共有 2 个文件被更改,包括 41 次插入29 次删除
  1. 34
      Runtime/ui/text.cs
  2. 36
      Runtime/ui/txt/paragraph.cs

34
Runtime/ui/text.cs


}
class TextStyle : IEquatable<TextStyle> {
public readonly Color color = Color.fromARGB(255, 0, 0, 0);
public readonly float fontSize = 14.0f;
public readonly FontWeight fontWeight = FontWeight.w400;
public readonly FontStyle fontStyle = FontStyle.normal;
public readonly float letterSpacing = 0.0f;
public readonly float wordSpacing = 0.0f;
public readonly TextBaseline textBaseline = TextBaseline.alphabetic;
public readonly float height = 1.0f;
public readonly TextDecoration decoration = TextDecoration.none;
public static readonly Color kDefaultColor = Color.fromARGB(255, 0, 0, 0);
public const float kDefaultFontSize = 14.0f;
public static readonly FontWeight kDefaultFontWeight = FontWeight.w400;
public const FontStyle kDefaultfontStyle = FontStyle.normal;
public const float kDefaultLetterSpacing = 0.0f;
public const float kDefaultWordSpacing = 0.0f;
public const TextBaseline kDefaultTextBaseline = TextBaseline.alphabetic;
public const float kDefaultHeight = 1.0f;
public static readonly TextDecoration kDefaultDecoration = TextDecoration.none;
public const TextDecorationStyle kDefaultDecorationStyle = TextDecorationStyle.solid;
public const string kDefaultFontFamily = "Helvetica";
public readonly Color color = kDefaultColor;
public readonly float fontSize = kDefaultFontSize;
public readonly FontWeight fontWeight = kDefaultFontWeight;
public readonly FontStyle fontStyle = kDefaultfontStyle;
public readonly float letterSpacing = kDefaultLetterSpacing;
public readonly float wordSpacing = kDefaultWordSpacing;
public readonly TextBaseline textBaseline = kDefaultTextBaseline;
public readonly float height = kDefaultHeight;
public readonly TextDecoration decoration = kDefaultDecoration;
public readonly TextDecorationStyle decorationStyle = TextDecorationStyle.solid;
public readonly string fontFamily = "Helvetica";
public readonly TextDecorationStyle decorationStyle = kDefaultDecorationStyle;
public readonly string fontFamily = kDefaultFontFamily;
public readonly Paint background;
internal UnityEngine.Color UnityColor {

36
Runtime/ui/txt/paragraph.cs


this.codeUnits = codeUnits;
}
public GlyphPosition shift(float shift) {
return new GlyphPosition(this.xPos.start + shift, this.xPos.end - this.xPos.start, this.codeUnits);
}
public void shiftSelf(float shift) {
this.xPos = new Range<float>(this.xPos.start + shift, this.xPos.end + shift);
}

return;
}
var textStyle = this._paragraphStyle.getTextStyle();
FontManager.instance.getOrCreate(textStyle.fontFamily, textStyle.fontWeight, textStyle.fontStyle).font,
textStyle.UnityFontSize);
FontManager.instance.getOrCreate(
this._paragraphStyle.fontFamily ?? TextStyle.kDefaultFontFamily,
this._paragraphStyle.fontWeight ?? TextStyle.kDefaultFontWeight,
this._paragraphStyle.fontStyle ?? TextStyle.kDefaultfontStyle).font,
(int) (this._paragraphStyle.fontSize ?? TextStyle.kDefaultFontSize));
this._needsLayout = false;
this._width = Mathf.Floor(constraints.width);

ref float justifyXOffset,
ref float maxWordWidth,
Range<int>[] words,
GlyphPosition[] lineGlyphPositions,
GlyphPosition[] glyphPositions,
ref int pLineGlyphPositions) {
string text = this._text;
int textStart = run.start;

textStart, textCount,
builder, layout,
words,
lineGlyphPositions,
glyphPositions,
run.start,
runXOffset,
wordGapWidth,

float advance = layout.getAdvance();
PaintRecord paintRecord = this._generatePaintRecord(run.style, textBlob, runXOffset, advance);
runXOffset += advance;
this._codeUnitRuns.Add(this._generateCodeUnitRun(run, lineNumber, lineGlyphPositions,
this._codeUnitRuns.Add(this._generateCodeUnitRun(run, lineNumber, glyphPositions,
pLineGlyphPositions - textCount, textCount));
return paintRecord;

void _populateGlyphPositions(int textStart, int textCount,
TextBlobBuilder builder, Layout layout,
Range<int>[] words,
GlyphPosition[] lineGlyphPositions,
GlyphPosition[] glyphPositions,
int runStart,
float runXOffset,
float wordGapWidth,

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

wordIndex++;
if (!float.IsNaN(wordStartPosition)) {
float wordWidth = lineGlyphPositions[pLineGlyphPositions-1].xPos.end - wordStartPosition;
float wordWidth = glyphPositions[pLineGlyphPositions-1].xPos.end - wordStartPosition;
maxWordWidth = Mathf.Max(wordWidth, maxWordWidth);
wordStartPosition = float.NaN;
}

// TODO: the default values are filled in directly, to avoid the cost of creating a new TextStyle
// However this may become inconsistent with the default values in TextStyle (text.cs)
// A better way is to define some global constants used in both places.
var defaultFont = FontManager.instance.getOrCreate(this._paragraphStyle.fontFamily ?? "Helvetica",
this._paragraphStyle.fontWeight ?? FontWeight.w400, this._paragraphStyle.fontStyle ?? FontStyle.normal).font;
var metrics = FontMetrics.fromFont(defaultFont, (int) (this._paragraphStyle.fontSize ?? 14.0f));
updateLineMetrics(metrics, this._paragraphStyle.lineHeight ?? 1.0f);
var defaultFont = FontManager.instance.getOrCreate(
this._paragraphStyle.fontFamily ?? TextStyle.kDefaultFontFamily,
this._paragraphStyle.fontWeight ?? TextStyle.kDefaultFontWeight,
this._paragraphStyle.fontStyle ?? TextStyle.kDefaultfontStyle).font;
var metrics = FontMetrics.fromFont(defaultFont, (int) (this._paragraphStyle.fontSize ?? TextStyle.kDefaultFontSize));
updateLineMetrics(metrics, this._paragraphStyle.lineHeight ?? TextStyle.kDefaultHeight);
}
this._lineHeights.Add(

正在加载...
取消
保存