void push_link(string szLink, string szCustomDesc, int nCharPos, UIHyperlinkType linkType) { UIFontCustomObject obj = new UIFontCustomObject(); obj.m_type = UIFontUnitType.UnitType_Link; obj.m_szLink = szLink; obj.m_szCustomDesc = szCustomDesc; obj.m_HyperlinkType = linkType; m_CustomObj.Add(obj); int nObjIndex = m_CustomObj.Count - 1; for (int i = 0; i < szLink.Length; ++i) { push_link_char(szLink[i], nCharPos, nObjIndex); } }
// 功能:扫描超连接字符,并去除颜色码 void ScaleLinkColor(string szLink, string szCustomDesc, int nCharPos) { UIHyperlinkType linkType = UIHyperlinkType.None; if (!string.IsNullOrEmpty(szCustomDesc) && szCustomDesc.Length > 2) { char chFirst = '0'; if (szCustomDesc[1] == ':') { chFirst = szCustomDesc[0]; szCustomDesc = szCustomDesc.Substring(2); if (chFirst == 'u' || chFirst == 'U') { linkType = UIHyperlinkType.Underline; } else if (chFirst == 'f' || chFirst == 'F') { linkType = UIHyperlinkType.Underline_Flash; } } } int nIndex = szLink.IndexOf('['); if (nIndex == -1) { push_link(szLink, szCustomDesc, nCharPos, linkType); return; } // 只支持一个颜色码,不支持多组 int nLen = szLink.Length; int[] NewCharPos = new int[nLen]; char[] szNewLink = new char[nLen]; UIFontUnit[] fontUnit = new UIFontUnit[nLen]; int nNewLen = 0; for (int i = 0; i < nLen; ++i) { char chType = szLink[i]; if (chType == '[') { if (i + 3 > nLen || szLink[i + 2] != '#') { // 兼容旧的颜色码 [ff0000] [-] if (TryParseOldColor(szLink, ref i)) { continue; } } if (i + 2 <= nLen) { bool bValidFalgs = false; switch (szLink[i + 1]) { case '0': // 结束符 [0#] { if (szLink[i + 2] == '#') { bValidFalgs = true; m_colors.Pop(); i += 3; } } break; case '1': // [1#ARGB { bValidFalgs = IsColorARGB(szLink, i); if (bValidFalgs) { ParseLinkColorARGB(szLink, ref i); } } break; case '2': // [2#RGB { bValidFalgs = ParseColorRGB(szLink, ref i); } break; case '-': // [-] 旧的结束码 { if (szLink[i + 2] == ']') { bValidFalgs = true; m_colors.Pop(); i += 2; } } break; default: break; } if (bValidFalgs) { continue; } } } push_link_char(chType, nCharPos, m_CustomObj.Count); } UIFontCustomObject obj = new UIFontCustomObject(); obj.m_type = UIFontUnitType.UnitType_Link; obj.m_szLink = new string(szNewLink, 0, nNewLen); obj.m_szCustomDesc = szCustomDesc; obj.m_HyperlinkType = linkType; m_CustomObj.Add(obj); }