Esempio n. 1
0
        // Token: 0x06002FD7 RID: 12247 RVA: 0x000D7794 File Offset: 0x000D5994
        private int ParseGlyphsProperty(GlyphTypeface fontFace, string unicodeString, bool sideways, out List <Glyphs.ParsedGlyphData> parsedGlyphs, out ushort[] clusterMap)
        {
            string indices = this.Indices;
            int    num     = 0;
            int    i       = 0;
            int    num2    = 1;
            int    num3    = 1;
            bool   flag    = false;
            int    num4;

            if (!string.IsNullOrEmpty(unicodeString))
            {
                clusterMap = new ushort[unicodeString.Length];
                num4       = unicodeString.Length;
            }
            else
            {
                clusterMap = null;
                num4       = 8;
            }
            if (!string.IsNullOrEmpty(indices))
            {
                num4 = Math.Max(num4, indices.Length / 5);
            }
            parsedGlyphs = new List <Glyphs.ParsedGlyphData>(num4);
            Glyphs.ParsedGlyphData parsedGlyphData = new Glyphs.ParsedGlyphData();
            if (!string.IsNullOrEmpty(indices))
            {
                int num5 = 0;
                int num6 = 0;
                for (int j = 0; j <= indices.Length; j++)
                {
                    char c = (j < indices.Length) ? indices[j] : '\0';
                    if (c == ',' || c == ';' || j == indices.Length)
                    {
                        int    length = j - num6;
                        string text   = indices.Substring(num6, length);
                        switch (num5)
                        {
                        case 0:
                        {
                            bool flag2 = flag;
                            if (!this.ReadGlyphIndex(text, ref flag, ref num3, ref num2, ref parsedGlyphData.glyphIndex))
                            {
                                if (string.IsNullOrEmpty(unicodeString))
                                {
                                    throw new ArgumentException(SR.Get("GlyphsIndexRequiredIfNoUnicode"));
                                }
                                if (unicodeString.Length <= i)
                                {
                                    throw new ArgumentException(SR.Get("GlyphsUnicodeStringIsTooShort"));
                                }
                                parsedGlyphData.glyphIndex = this.GetGlyphFromCharacter(fontFace, unicodeString[i]);
                            }
                            if (!flag2 && clusterMap != null)
                            {
                                if (flag)
                                {
                                    for (int k = i; k < i + num2; k++)
                                    {
                                        Glyphs.SetClusterMapEntry(clusterMap, k, (ushort)num);
                                    }
                                }
                                else
                                {
                                    Glyphs.SetClusterMapEntry(clusterMap, i, (ushort)num);
                                }
                            }
                            parsedGlyphData.advanceWidth = Glyphs.GetAdvanceWidth(fontFace, parsedGlyphData.glyphIndex, sideways);
                            break;
                        }

                        case 1:
                            if (!Glyphs.IsEmpty(text))
                            {
                                parsedGlyphData.advanceWidth = double.Parse(text, CultureInfo.InvariantCulture);
                                if (parsedGlyphData.advanceWidth < 0.0)
                                {
                                    throw new ArgumentException(SR.Get("GlyphsAdvanceWidthCannotBeNegative"));
                                }
                            }
                            break;

                        case 2:
                            if (!Glyphs.IsEmpty(text))
                            {
                                parsedGlyphData.offsetX = double.Parse(text, CultureInfo.InvariantCulture);
                            }
                            break;

                        case 3:
                            if (!Glyphs.IsEmpty(text))
                            {
                                parsedGlyphData.offsetY = double.Parse(text, CultureInfo.InvariantCulture);
                            }
                            break;

                        default:
                            throw new ArgumentException(SR.Get("GlyphsTooManyCommas"));
                        }
                        num5++;
                        num6 = j + 1;
                    }
                    if (c == ';' || j == indices.Length)
                    {
                        parsedGlyphs.Add(parsedGlyphData);
                        parsedGlyphData = new Glyphs.ParsedGlyphData();
                        if (flag)
                        {
                            num3--;
                            if (num3 == 0)
                            {
                                i   += num2;
                                flag = false;
                            }
                        }
                        else
                        {
                            i++;
                        }
                        num++;
                        num5 = 0;
                        num6 = j + 1;
                    }
                }
            }
            if (unicodeString != null)
            {
                while (i < unicodeString.Length)
                {
                    if (flag)
                    {
                        throw new ArgumentException(SR.Get("GlyphsIndexRequiredWithinCluster"));
                    }
                    if (unicodeString.Length <= i)
                    {
                        throw new ArgumentException(SR.Get("GlyphsUnicodeStringIsTooShort"));
                    }
                    parsedGlyphData.glyphIndex   = this.GetGlyphFromCharacter(fontFace, unicodeString[i]);
                    parsedGlyphData.advanceWidth = Glyphs.GetAdvanceWidth(fontFace, parsedGlyphData.glyphIndex, sideways);
                    parsedGlyphs.Add(parsedGlyphData);
                    parsedGlyphData = new Glyphs.ParsedGlyphData();
                    Glyphs.SetClusterMapEntry(clusterMap, i, (ushort)num);
                    i++;
                    num++;
                }
            }
            return(num);
        }