internal char GetChar(ushort glyf) { if (m_ranges == null) { return('\0'); } int count = m_chars.Count; for (int i = 0; i < count; ++i) { if (m_chars[i].Glyf == glyf) { return(m_chars[i].Char); } } count = m_ranges.Count; for (int i = 0; i < count; ++i) { BfRange range = m_ranges[i]; if (range.FirstGlyf <= glyf && glyf <= range.EndGlyf) { return((char)(range.FirstChar + glyf - range.FirstGlyf)); } } return('\0'); }
public string Get(string index) { // TODO work on this // check range first var indexValue = int.Parse(index, NumberStyles.HexNumber); if (CodeSpaceRange == null || indexValue < FromHex(CodeSpaceRange.Item1) || indexValue > FromHex(CodeSpaceRange.Item2)) { return(null); } // ok, bf range var result = BfRange? .Where(_ => FromHex(index) >= FromHex(_.Item1) && FromHex(index) <= FromHex(_.Item2)) .Select(_ => new { Beginning = FromHex(_.Item1), Values = _.Item3 }) .Select(_ => _.Values.Count() == 1 ? ((FromHex(index) - _.Beginning) + FromHex(_.Values.First())).ToString("X4") : FromHex(index) + _.Values.ElementAt(FromHex(index) - _.Beginning)) .FirstOrDefault(); if (!string.IsNullOrEmpty(result)) { return(System.Convert.ToChar(FromHex(result)).ToString()); } // check individual values string r; return(BfChar != null && BfChar.TryGetValue(index.ToUpper(), out r) ? Regex.Matches(r, ".{4}") .Cast <Match>() .Select(m => System.Convert.ToChar(FromHex(m.Value)).ToString()) .Aggregate((a, b) => a + b) : null); }
internal ushort GetGlyf(char c) { if (m_ranges == null) { return(0); } int count = m_chars.Count; for (int i = 0; i < count; ++i) { if (m_chars[i].Char == c) { return(m_chars[i].Glyf); } } count = m_ranges.Count; for (int i = 0; i < count; ++i) { BfRange range = m_ranges[i]; if (range.FirstChar <= c && c <= range.EndChar) { return((ushort)(range.FirstGlyf + c - range.FirstChar)); } } return(0); }