Example #1
0
 public bool TryGetChar(int c, out BMFontCharacterData charData)
 {
     return(charDataList.TryGetValue(new RehashedValue <int> (c), out charData));
 }
Example #2
0
        private void ParseChar(ref ReadOnlySpan <char> line)
        {
            bool parsedId = false;

            var cData = new BMFontCharacterData();

            while (line.Length > 0)
            {
                SkipWhitespace(ref line);

                var tagName = ParseIdentifier(ref line, "page");

                if (CheckTag(tagName, "id"))
                {
                    cData.CharId = ParseIntTag(ref line, "id");
                    parsedId     = true;
                }

                else if (CheckTag(tagName, "x"))
                {
                    cData.PosX = ParseIntTag(ref line, "x");
                }
                else if (CheckTag(tagName, "y"))
                {
                    cData.PosY = ParseIntTag(ref line, "y");
                }

                else if (CheckTag(tagName, "width"))
                {
                    cData.Width = ParseIntTag(ref line, "width");
                }
                else if (CheckTag(tagName, "height"))
                {
                    cData.Height = ParseIntTag(ref line, "height");
                }

                else if (CheckTag(tagName, "xoffset"))
                {
                    cData.OffsetX = ParseIntTag(ref line, "xoffset");
                }
                else if (CheckTag(tagName, "yoffset"))
                {
                    cData.OffsetY = ParseIntTag(ref line, "yoffset");
                }

                else if (CheckTag(tagName, "xadvance"))
                {
                    cData.AdvanceX = ParseIntTag(ref line, "xadvance");
                }

                else if (CheckTag(tagName, "page"))
                {
                    cData.Page = ParseIntTag(ref line, "page");
                }

                else if (CheckTag(tagName, "chnl"))
                {
                    cData.Channel = (BMFontCharacterChannel)ParseIntTag(ref line, "chnl");
                }

                else
                {
                    throw new BMFontParseException(
                              string.Format("Unsupported tag \"{0}\" on line \"{1}\".",
                                            tagName.ToString(),
                                            currentLine
                                            ));
                }
            }

            if (!parsedId)
            {
                throw new BMFontParseException($"Missing char id on line {currentLine}.");
            }
            if (!charData.TryAdd(new RehashedValue <int> (cData.CharId), cData))
            {
                throw new BMFontParseException($"Duplicate char ({cData.CharId}) on line {currentLine}.");
            }
        }