void layoutWord(float offset, int layoutOffset, TextBuff buff, int start, int wordCount, TextStyle style, Font font) { float wordSpacing = wordCount == 1 && LayoutUtils.isWordSpace(buff.charAt(start)) ? style.wordSpacing : 0; float x = this._advance; float letterSpace = style.letterSpacing; float letterSpaceHalfLeft = letterSpace * 0.5f; float letterSpaceHalfRight = letterSpace - letterSpaceHalfLeft; for (int i = 0; i < wordCount; i++) { var ch = buff.charAt(start + i); if (i == 0) { x += letterSpaceHalfLeft + wordSpacing; this._advances[i + layoutOffset] += letterSpaceHalfLeft + wordSpacing; } else { this._advances[i - 1 + layoutOffset] += letterSpaceHalfRight; this._advances[i + layoutOffset] += letterSpaceHalfLeft; x += letterSpace; } if (font.getGlyphInfo(ch, out var glyphInfo, style.UnityFontSize, style.UnityFontStyle)) { var minX = glyphInfo.minX + x; var maxX = glyphInfo.maxX + x; var minY = -glyphInfo.maxY; var maxY = -glyphInfo.minY; if (this._bounds.width <= 0 || this._bounds.height <= 0) { this._bounds = UnityEngine.Rect.MinMaxRect( minX, minY, maxX, maxY); } else { if (minX < this._bounds.x) { this._bounds.x = minX; } if (minY < this._bounds.y) { this._bounds.y = minY; } if (maxX > this._bounds.xMax) { this._bounds.xMax = maxX; } if (maxY > this._bounds.yMax) { this._bounds.yMax = maxY; } } } this._positions[i + layoutOffset] = x; float advance = glyphInfo.advance; if (ch == '\t') { advance = this._tabStops.nextTab((this._advance + offset)) - this._advance; } x += advance; this._advances[i + layoutOffset] += advance; if (i + 1 == wordCount) { this._advances[i + layoutOffset] += letterSpaceHalfRight; x += letterSpaceHalfRight; } } this._advance = x; }
public static float measureText(float offset, TextBuff buff, int start, int count, TextStyle style, List <float> advances, int advanceOffset, TabStops tabStops) { Layout layout = new Layout(); layout.setTabStops(tabStops); layout.doLayout(offset, buff, start, count, style); if (advances != null) { var layoutAdv = layout.getAdvances(); for (int i = 0; i < count; i++) { advances[i + advanceOffset] = layoutAdv[i]; } } return(layout.getAdvance()); }
void layoutEmoji(string text, TextStyle style, Font font, int start, int count) { for (int i = 0; i < count; i++) { char c = text[i]; float x = this._advance; if (EmojiUtils.isSingleCharNonEmptyEmoji(c) || char.IsHighSurrogate(c)) { float letterSpace = style.letterSpacing; float letterSpaceHalfLeft = letterSpace * 0.5f; float letterSpaceHalfRight = letterSpace - letterSpaceHalfLeft; x += letterSpaceHalfLeft; this._advances[i] += letterSpaceHalfLeft; var metrics = FontMetrics.fromFont(font, style.UnityFontSize); var minX = x; var maxX = metrics.descent - metrics.ascent + x; var minY = metrics.ascent; var maxY = metrics.descent; if (this._bounds.width <= 0 || this._bounds.height <= 0) { this._bounds = UnityEngine.Rect.MinMaxRect( minX, minY, maxX, maxY); } else { if (minX < this._bounds.x) { this._bounds.x = minX; } if (minY < this._bounds.y) { this._bounds.y = minY; } if (maxX > this._bounds.xMax) { this._bounds.xMax = maxX; } if (maxY > this._bounds.yMax) { this._bounds.yMax = maxY; } } this._positions[i] = x; float advance = style.fontSize; x += advance; this._advances[i] += advance; this._advances[i] += letterSpaceHalfRight; x += letterSpaceHalfRight; } else { this._advances[i] = 0; this._positions[i] = x; } this._advance = x; } }
public float addStyleRun(TextStyle style, int start, int end) { float width = 0.0f; if (style != null) { width = Layout.measureText(this._width - this._preBreak, this._textBuf, start + this._textOffset, end - start, style, this._charWidths, start, this._tabStops); } int current = this._wordBreaker.current(); int afterWord = start; int lastBreak = start; float lastBreakWidth = this._width; float postBreak = this._width; int postSpaceCount = this._spaceCount; for (int i = start; i < end; i++) { char c = this._textBuf[i + this._textOffset]; if (c == '\t') { this._width = this._preBreak + this._tabStops.nextTab((this._width - this._preBreak)); if (this.mFirstTabIndex == int.MaxValue) { this.mFirstTabIndex = i; } } else { if (LayoutUtils.isWordSpace(c)) { this._spaceCount += 1; } this._width += this._charWidths[i]; if (!LayoutUtils.isLineEndSpace(c)) { postBreak = this._width; postSpaceCount = this._spaceCount; afterWord = i + 1; } } if (i + 1 == current) { int wordStart = this._wordBreaker.wordStart(); int wordEnd = this._wordBreaker.wordEnd(); if (style != null || current == end || this._charWidths[current] > 0) { this._addWordBreak(current, this._width, postBreak, this._spaceCount, postSpaceCount, 0); } lastBreak = current; lastBreakWidth = this._width; current = this._wordBreaker.next(); } } return(width); }
public Run(TextStyle style, int start, int end) { this.style = style; this.start = start; this.end = end; }
public TextBlob(string text, int textOffset, int textSize, Vector2d[] positions, Rect bounds, TextStyle style) { this.instanceId = ++_nextInstanceId; this.positions = positions; this.text = text; this.textOffset = textOffset; this.textSize = textSize; this.style = style; this.bounds = bounds; }