public override void clear() { this.textBlob = null; ObjectPool <uiMeshMesh> .release(this._mesh); this._mesh = null; this._resolved = false; }
public void drawTextBlob(TextBlob textBlob, Offset offset, Paint paint) { this._recorder.addDrawCmd(new DrawTextBlob { textBlob = textBlob, offset = offset, paint = new Paint(paint), }); }
public void drawTextBlob(TextBlob textBlob, Offset offset, Paint paint) { this._recorder.addDrawCmd(uiDrawTextBlob.create( textBlob: textBlob, offset: uiOffset.fromOffset(offset), paint: uiPaint.fromPaint(paint) )); }
public TextBlob make() { var result = new TextBlob(this._text, this._textOffset, this._size, this.positions, this._bounds, this._style); this.positions = null; return(result); }
public static TextBlobMesh create(TextBlob textBlob, float scale, uiMatrix3 matrix) { TextBlobMesh newMesh = ObjectPool <TextBlobMesh> .alloc(); newMesh.textBlob = textBlob; newMesh.scale = scale; newMesh.matrix = matrix; return(newMesh); }
void _drawTextBlob(TextBlob textBlob, Offset offset, Paint paint) { D.assert(textBlob != null); D.assert(offset != null); D.assert(paint != null); var state = this._currentLayer.currentState; var scale = state.scale * this._devicePixelRatio; var matrix = new Matrix3(state.matrix); matrix.preTranslate(offset.dx, offset.dy); var mesh = new TextBlobMesh(textBlob, scale, matrix); // request font texture so text mesh could be generated correctly var font = FontManager.instance.getOrCreate(textBlob.style.fontFamily).font; var style = textBlob.style; var fontSizeToLoad = Mathf.CeilToInt(style.UnityFontSize * scale); var subText = textBlob.text.Substring(textBlob.textOffset, textBlob.textSize); font.RequestCharactersInTexture(subText, fontSizeToLoad, style.UnityFontStyle); var tex = font.material.mainTexture; Action <Paint> drawMesh = (Paint p) => { if (!this._applyClip(textBlob.bounds)) { return; } var layer = this._currentLayer; layer.draws.Add(CanvasShader.texAlpha(layer, p, mesh, tex)); }; if (paint.maskFilter != null && paint.maskFilter.sigma != 0) { this._drawWithMaskFilter(textBlob.bounds, drawMesh, paint, paint.maskFilter); return; } drawMesh(paint); }
void _drawTextBlob(TextBlob textBlob, Offset offset, Paint paint) { D.assert(textBlob != null); D.assert(offset != null); D.assert(paint != null); var state = this._currentLayer.currentState; var scale = state.scale * this._devicePixelRatio; var matrix = new Matrix3(state.matrix); matrix.preTranslate(offset.dx, offset.dy); var mesh = MeshGenerator.generateMesh(textBlob, scale)?.transform(matrix); if (mesh == null) { return; } var font = FontManager.instance.getOrCreate(textBlob.style.fontFamily).font; var tex = font.material.mainTexture; Action <Paint> drawMesh = (Paint p) => { if (!this._applyClip(mesh.bounds)) { return; } var layer = this._currentLayer; layer.draws.Add(CanvasShader.texAlpha(layer, p, mesh, tex)); }; if (paint.maskFilter != null && paint.maskFilter.sigma != 0) { this._drawWithMaskFilter(mesh.bounds, drawMesh, paint, paint.maskFilter); return; } drawMesh(paint); }
void _drawTextBlob(TextBlob textBlob, uiOffset offset, uiPaint paint) { D.assert(textBlob != null); var state = this._currentLayer.currentState; var scale = state.scale * this._devicePixelRatio; var matrix = new uiMatrix3(state.matrix.Value); matrix.preTranslate(offset.dx, offset.dy); var mesh = TextBlobMesh.create(textBlob, scale, matrix); var textBlobBounds = matrix.mapRect(uiRectHelper.fromRect(textBlob.boundsInText)); // request font texture so text mesh could be generated correctly var style = textBlob.style; var font = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font; var fontSizeToLoad = Mathf.CeilToInt(style.UnityFontSize * scale); var subText = textBlob.text.Substring(textBlob.textOffset, textBlob.textSize); Texture tex = null; bool notEmoji = !char.IsHighSurrogate(subText[0]) && !EmojiUtils.isSingleCharEmoji(subText[0]); if (notEmoji) { font.RequestCharactersInTextureSafe(subText, fontSizeToLoad, style.UnityFontStyle); tex = font.material.mainTexture; } if (paint.maskFilter != null && paint.maskFilter.Value.sigma != 0) { this._drawWithMaskFilter(textBlobBounds, paint, paint.maskFilter.Value, null, false, 0, tex, textBlobBounds, mesh, notEmoji, this.___drawTextDrawMeshCallback); return; } this._drawTextDrawMeshCallback(paint, null, false, 0, tex, textBlobBounds, mesh, notEmoji); }
public TextBlobMesh(TextBlob textBlob, float scale, Matrix3 transform) { this._textBlob = textBlob; this._scale = scale; this._transform = transform; }
public static MeshMesh generateMesh(TextBlob textBlob, float scale) { var style = textBlob.style; var fontInfo = FontManager.instance.getOrCreate(style.fontFamily); var key = new MeshKey(textBlob.instanceId, scale); _meshes.TryGetValue(key, out var meshInfo); if (meshInfo != null && meshInfo.textureVersion == fontInfo.textureVersion) { meshInfo.touch(); return(meshInfo.mesh); } var font = fontInfo.font; var length = textBlob.textSize; var text = textBlob.text; var fontSizeToLoad = Mathf.CeilToInt(style.UnityFontSize * scale); var subText = textBlob.text.Substring(textBlob.textOffset, textBlob.textSize); font.RequestCharactersInTexture(subText, fontSizeToLoad, style.UnityFontStyle); var vertices = new List <Vector3>(length * 4); var triangles = new List <int>(length * 6); var uv = new List <Vector2>(length * 4); for (int charIndex = 0; charIndex < length; ++charIndex) { var ch = text[charIndex + textBlob.textOffset]; // first char as origin for mesh position var position = textBlob.positions[charIndex]; if (LayoutUtils.isWordSpace(ch) || LayoutUtils.isLineEndSpace(ch) || ch == '\t') { continue; } CharacterInfo charInfo; font.GetCharacterInfo(ch, out charInfo, fontSizeToLoad, style.UnityFontStyle); var minX = charInfo.minX / scale; var maxX = charInfo.maxX / scale; var minY = charInfo.minY / scale; var maxY = charInfo.maxY / scale; var baseIndex = vertices.Count; vertices.Add(new Vector3((float)(position.x + minX), (float)(position.y - maxY), 0)); vertices.Add(new Vector3((float)(position.x + maxX), (float)(position.y - maxY), 0)); vertices.Add(new Vector3((float)(position.x + maxX), (float)(position.y - minY), 0)); vertices.Add(new Vector3((float)(position.x + minX), (float)(position.y - minY), 0)); triangles.Add(baseIndex); triangles.Add(baseIndex + 1); triangles.Add(baseIndex + 2); triangles.Add(baseIndex); triangles.Add(baseIndex + 2); triangles.Add(baseIndex + 3); uv.Add(charInfo.uvTopLeft); uv.Add(charInfo.uvTopRight); uv.Add(charInfo.uvBottomRight); uv.Add(charInfo.uvBottomLeft); } if (vertices.Count == 0) { return(null); } MeshMesh mesh = vertices.Count > 0 ? new MeshMesh(null, vertices, triangles, uv) : null; _meshes[key] = new MeshInfo(key, mesh, fontInfo.textureVersion); return(mesh); }
public TextBlobMesh(TextBlob textBlob, float scale, Matrix3 matrix) { this.textBlob = textBlob; this.scale = scale; this.matrix = matrix; }