public int Find(string vs, int index, ref CharUV uV) { if (dat == null) { return(-1); } if (index + len > vs.Length) { return(-1); } int c = dat.Length / len; for (int i = 0; i < c; i++) { int s = i * len; int t = index; for (int j = 0; j < len; j++) { if (vs[t] != dat[s]) { goto label; } t++; s++; } uV = uVs[i]; return(i); label :; } return(-1); }
public static int FindEmojiInfo(string buff, int index, int len, ref CharUV uV) { len -= 1; if (len < 0) { return(-1); } if (len > charInfos.Length) { return(-1); } if (charInfos[len] == null) { return(-1); } return(charInfos[len].Find(buff, index, ref uV)); }
/// <summary> /// 字符布局 /// </summary> static void LayoutText(StringEx str, ref TextGenerationSettings setting) { int[] eles = str.noEmojiInfo.lens; if (eles == null) { return; } lineInfo = new TextLineInfo(); var font = setting.font; string full = str.FullString; string no = str.noEmoji; font.RequestCharactersInTexture(no, setting.fontSize, setting.fontStyle); CharacterInfoEx info = new CharacterInfoEx(); info.color = setting.color; CharUV uV = new CharUV(); int s = 0; float w = setting.generationExtents.x; float lw = 0; lineInfo.fontSize = setting.fontSize; for (int i = 0; i < eles.Length; i++) { int len = eles[i]; if (no[i] == '\n')//行结束 { font.GetCharacterInfo(no[i], out info.info, setting.fontSize, setting.fontStyle); info.type = -3; info.info.glyphWidth = 0; info.info.advance = 0; lineInfo.CharEnd = i - 1; lineInfos[MaxLine] = lineInfo; MaxLine++; lineInfo.CharStart = i; lineInfo.minY = 0; lineInfo.maxY = 0; lw = 0; s++; } else { if (len == 1) { if (no[i] == ' ') { info.type = -2; } else { info.type = 0; } if (customFont != null) { if (customFont.GetCharacterInfo(no[i], ref info.info, setting.fontSize)) { info.type = 1; } else { font.GetCharacterInfo(no[i], out info.info, setting.fontSize, setting.fontStyle); } } else { font.GetCharacterInfo(no[i], out info.info, setting.fontSize, setting.fontStyle); } } else { font.GetCharacterInfo('@', out info.info, setting.fontSize, setting.fontStyle); int index = EmojiMap.FindEmojiInfo(full, s, len, ref uV); if (index >= 0) { info.type = -1; info.info.uvBottomLeft = uV.uv3; info.info.uvTopLeft = uV.uv0; info.info.uvTopRight = uV.uv1; info.info.uvBottomRight = uV.uv2; } else { info.type = 0; } } if (setting.horizontalOverflow == HorizontalWrapMode.Wrap) { if (lw + info.info.advance > w) { lineInfo.CharEnd = i - 1; lineInfos[MaxLine] = lineInfo; MaxLine++; lineInfo.CharStart = i; lineInfo.minY = 0; lineInfo.maxY = 0; lw = info.info.advance; } else { lw += info.info.advance; } } else { lw += info.info.advance; } if (info.info.maxY > lineInfo.maxY) { lineInfo.maxY = info.info.maxY; } if (info.info.minY < lineInfo.minY) { lineInfo.minY = info.info.minY; } lineInfo.Width = lw; s += len; } characters[MaxChar] = info; characters[MaxChar].fontSize = setting.fontSize; characters[MaxChar].ch = no[i]; MaxChar++; } int end = eles.Length - 1; if (MaxLine > 0) { if (lineInfos[MaxLine - 1].CharEnd < end) { lineInfo.CharEnd = end; lineInfos[MaxLine] = lineInfo; MaxLine++; } } else { lineInfo.CharEnd = end; lineInfos[MaxLine] = lineInfo; MaxLine++; } }