void FixPoints(EmojiList <EmojiIndex> list, int type, ref TextElementResult result) { for (int k = 0; k < list.Count; k++) { var pointval = list[k]; int cacheval = 0; if (_cache.TryGetValue(pointval.Emojiindex - 1, out cacheval)) { pointval.TextIndex += cacheval; } //result.ParseGroup.emojitypeMap[emojiidx] = type + k *100; list[k] = pointval; } }
public int DoStep(ref TextCotext context, EmojiEvent uievent) { if (uievent == EmojiEvent.PreRender) { for (int i = 0; i < context.AllTexts.Count; i++) { InlineText text = context.AllTexts[i]; if (text == null) { continue; } if (!context.RebuildTexts.Contains(text)) { continue; } _cache.Clear(); TextElementResult result = context.Results[i]; //if (result.ParseGroup.emojitypeMap == null) // result.ParseGroup.emojitypeMap = new Dictionary<int, int>(); //else //result.ParseGroup.emojitypeMap.Clear(); int val = 0; for (int k = 0; k < result.ParseGroup.fillplacemap.Count; k++) { val += result.ParseGroup.fillplacemap[k]; _cache[k] = val; } //emoji FixPoints(result.ParseGroup.EmojiResult.GetEmojiPoints(), 1, ref result); //href FixPoints(result.ParseGroup.HrefResult.GetHrefPoints(), 2, ref result); context.Results[i] = result; } } return(0); }
bool GetIsInVert(ref TextElementResult result, int emojiidx, int textidx, out int type) { bool isinvert = false; int cacheval; if (!_cache.TryGetValue(emojiidx + textidx * 100, out cacheval)) { isinvert = result.ParseGroup.IsInVert(emojiidx, textidx, out type); _cache.Add(emojiidx + textidx * 100, (isinvert ? 200 : 100) + type); } else { int c = cacheval / 100; isinvert = (c == 2); type = cacheval % 100; } return(isinvert); }
public int DoStep(ref TextCotext context, EmojiEvent uievent) { if (uievent == EmojiEvent.PreRender) { int errcode = 0; for (int i = 0; i < context.AllTexts.Count; i++) { InlineText text = context.AllTexts[i]; if (text == null) { continue; } if (!context.RebuildTexts.Contains(text)) { continue; } TextElementResult result = context.Results[i]; result.MeshGroup.TextMeshResult.Init(); result.GizmosResult.Clear(); //text string currenttext = null; if (result.ParseGroup.TextResult.FormatElements != null && result.ParseGroup.TextResult.FormatElements.Count > 0) { currenttext = result.ParseGroup.TextResult.FormatString; } else { currenttext = text.text; } errcode = FillText(text, currenttext, ref context, ref result); context.Results[i] = result; } return(errcode); } return(0); }
int Render(ref TextElementResult result, bool isvisiable, int emojiindex, bool fix = false) { float groupsize; if (!result.ParseGroup.TryGetSize(emojiindex, out groupsize)) { return((int)EmojiErrorCode.GetSizeError); } if (fix) { m_TempEmojiVerts[1].position = m_TempEmojiVerts[0].position + new Vector3(groupsize, 0, 0); m_TempEmojiVerts[2].position = m_TempEmojiVerts[3].position + new Vector3(groupsize, 0, 0); } for (int i = 0; i < m_TempEmojiVerts.Length; i++) { result.MeshGroup.TextMeshResult.EmojiVerts.Add(m_TempEmojiVerts[i].position); } return(0); }
public int DoStep(ref TextCotext context, EmojiEvent uievent) { if (uievent == EmojiEvent.PreRender) { int errcode = 0; foreach (var target in context.RebuildTexts) { if (target == null) { continue; } string text = target.text; if (text.Length > 16381) //65535/4-1 { errcode = (int)EmojiErrorCode.TooMuchChars; continue; } ParseTextResult result = new ParseTextResult(); int index = context.AllTexts.IndexOf(target); if (index != -1) { result = context.Results[index].ParseGroup.TextResult; result.Clear(); } if (_sb == null) { _sb = new StringBuilder(); } _sb.Capacity = text.Length; int textstart = -1; int start = 0; int flag = 0; for (int i = 0; i < text.Length; i++) { char subchar = text[i]; if (subchar == ParsetLeft) { if (flag == 0) { start = i; result.GetPoints().Add(_sb.Length); } flag++; } else if (subchar == ParsetRight) { flag--; if (flag == 0) { string substr = text.Substring(start, i - start + 1); result.GetElements().Add(substr); // textstart = -1; } } else if (flag == 0)//正常显示内容 { if (textstart < 0) { textstart = i; } _sb.Append(subchar); } } if (flag > 0) { string substr = text.Substring(start); _sb.Append(substr); } result.FormatString = _sb.ToString(); FillPart(target, result.FormatString, 0, result.FormatString.Length - 1, ref result); _sb.Length = 0; //assign if (index == -1) { TextElementResult elementresult = new TextElementResult(); elementresult.RenderId = target.GetHashCode(); elementresult.ParseGroup.TextResult = result; elementresult.ParseGroup.fillplacemap = new EmojiList <int>(64); context.AllTexts.Add(target); context.Results.Add(elementresult); } else { TextElementResult elementresult = context.Results[index]; elementresult.ParseGroup.TextResult = result; elementresult.ParseGroup.fillplacemap.Clear(); context.Results[index] = elementresult; } } return(errcode); } return(0); }
int FillText(InlineText text, string currenttext, ref TextCotext context, ref TextElementResult result) { int errcode = 0; //text generate Vector2 extents = text.rectTransform.rect.size; var settings = text.GetGenerationSettings(extents); text.cachedTextGenerator.PopulateWithErrors(currenttext, settings, text.gameObject); // Apply the offset to the vertices IList <UIVertex> verts = text.cachedTextGenerator.verts; float unitsPerPixel = 1 / text.pixelsPerUnit; //Last 4 verts are always a new line... (\n) int vertCount = verts.Count - 4; Vector2 roundingOffset = new Vector2(verts[0].position.x, verts[0].position.y) * unitsPerPixel; roundingOffset = text.PixelAdjustPoint(roundingOffset) - roundingOffset; bool rdeq = roundingOffset != Vector2.zero; int emojiindex = 0; _cache.Clear(); for (int vertidx = 0; vertidx < vertCount; ++vertidx) { int tempVertsIndex = vertidx & 3; int textidx = vertidx / 4; int ctype; bool isinvert = GetIsInVert(ref result, emojiindex, textidx, out ctype); bool isvisiable = IsVisiableType(ctype); ; if (context.Settings.DoubleRender || isvisiable || !isinvert) { FillTextVerts(verts, vertidx, unitsPerPixel, roundingOffset, rdeq); if (tempVertsIndex == 3) { for (int m = 0; m < 4; m++) { result.MeshGroup.TextMeshResult.TextVerts.Add(m_TempVerts[m]); } } } if (isinvert) { int nexttype; int lasttype; bool nextisinvert = GetIsInVert(ref result, emojiindex, textidx + 1, out nexttype); bool lastisinvert = GetIsInVert(ref result, emojiindex, textidx - 1, out lasttype); bool next = nextisinvert && nexttype == ctype; bool last = lastisinvert && lasttype == ctype; if (tempVertsIndex == 0) { if (!last)//qi点 { FillEmojiTextVerts(verts, vertidx, unitsPerPixel, roundingOffset, rdeq); } //else //{ // //skip //} } else if (tempVertsIndex == 1) { if (!next) { FillEmojiTextVerts(verts, vertidx, unitsPerPixel, roundingOffset, rdeq); } //else //{ // //skip //} } else if (tempVertsIndex == 2) { if (!next) { FillEmojiTextVerts(verts, vertidx, unitsPerPixel, roundingOffset, rdeq); if (last)//终点 { bool needfix = result.ParseGroup.NeedFix(emojiindex); errcode = Render(ref result, isvisiable, emojiindex, needfix); } } //else //{ // //skip //} } else if (tempVertsIndex == 3) { if (!last) { FillEmojiTextVerts(verts, vertidx, unitsPerPixel, roundingOffset, rdeq); if (!next)//终点 { bool needfix = result.ParseGroup.NeedFix(emojiindex); errcode = Render(ref result, isvisiable, emojiindex, needfix); emojiindex++; } } else if (last && !next) { emojiindex++; } //else //{ // //skip //} } } } return(errcode); }
void Fill(InlineText target, SpriteInfoGroup group, int elementidx, ref float linesize, ref TextElementResult textresult, out int fillsize) { fillsize = 0; float spacesize = Mathf.Max(_placesize.x, _placesize.y); float minsize = Mathf.Min(group.size, Mathf.Min(_placesize.x, _placesize.y)); if (minsize > 0.1f) { float autosize = Mathf.Min(group.size, spacesize); int fillspacecnt = Mathf.CeilToInt(autosize / minsize);; if (target.horizontalOverflow != HorizontalWrapMode.Overflow && fillspacecnt > 0) { float wid = target.rectTransform.rect.width; float fillwidth = fillspacecnt * (minsize + _space); //填充字符之间穿插了换行的情况 进行检测 if (wid - linesize < fillwidth) { fillspacecnt = 1; linesize = 0; textresult.ParseGroup.EmojiResult.GetFixedIndex().Add(elementidx); } else { linesize += fillwidth; } } fillsize = fillspacecnt; textresult.ParseGroup.EmojiResult.GetEmojiSize().Add(autosize); textresult.ParseGroup.EmojiResult.GetGroups().Add(group); } }
bool InsertEmoji(InlineText text, ref TextElementResult result, ref int emojiidx, ref TextCotext context, ref float linesize, ref int emojistart, ref int addedcnt) { if (emojiidx >= result.ParseGroup.TextResult.FormatElements.Count) { return(false); } string info = result.ParseGroup.TextResult.FormatElements[emojiidx]; int atlasId = 0; string tagKey = null; if (!ParseElement(text, info, ref context, out atlasId, out tagKey)) { return(false); } int fillplacecnt = 0; //Fill SpriteInfoGroup group; bool canrender = CanRender(atlasId, tagKey, ref context, out group); if (canrender && atlasId >= 0) { Fill(text, group, emojiidx, ref linesize, ref result, out fillplacecnt); //Calculate result.ParseGroup.EmojiResult.GetEmojiPoints().Add(new EmojiIndex(emojiidx, emojistart, fillplacecnt)); //Fill placeholder if (canrender && fillplacecnt > 0) { for (int k = 0; k < fillplacecnt; k++) { _sb.Insert(emojistart + k + addedcnt, Placeholder); } } addedcnt += fillplacecnt; emojiidx++; if (emojiidx < result.ParseGroup.TextResult.GetPoints().Count) { emojistart = result.ParseGroup.TextResult.GetPoints()[emojiidx]; } else { emojistart = -1; } // result.ParseGroup.AddExternFill(emojiidx - 1, fillplacecnt); } else { emojiidx++; if (emojiidx < result.ParseGroup.TextResult.GetPoints().Count) { emojistart = result.ParseGroup.TextResult.GetPoints()[emojiidx]; } else { emojistart = -1; } result.ParseGroup.AddExternFill(emojiidx - 1, 0); } return(true); }