Ejemplo n.º 1
0
        public AtlusEncoding(string tableName)
        {
            var tableFilePath = Path.Combine(sCharsetsBaseDirectoryPath, $"{tableName}.tsv");

            if (!File.Exists(tableFilePath))
            {
                throw new ArgumentException($"Unknown encoding: {tableName} ({tableFilePath})", nameof(tableName));
            }

            var charTable = ReadCharsetFile(tableFilePath);

            // build character to codepoint table
            mCharToCodePoint = new Dictionary <string, CodePoint>(charTable.Count);

            // add the ascii range seperately
            for (int charIndex = 0; charIndex < ASCII_RANGE + 1; charIndex++)
            {
                if (!mCharToCodePoint.ContainsKey(charTable[charIndex]))
                {
                    mCharToCodePoint[charTable[charIndex]] = new CodePoint(0, (byte)charIndex);
                }
            }

            // add extended characters, but don't re-include the ascii range
            for (int charIndex = ASCII_RANGE + 1; charIndex < charTable.Count; charIndex++)
            {
                int glyphIndex         = charIndex + CHAR_TO_GLYPH_INDEX_OFFSET;
                int tableIndex         = (glyphIndex / GLYPH_TABLE_SIZE) - 1;
                int tableRelativeIndex = glyphIndex - (tableIndex * GLYPH_TABLE_SIZE);

                if (!mCharToCodePoint.ContainsKey(charTable[charIndex]))
                {
                    mCharToCodePoint[charTable[charIndex]] = new CodePoint((byte)(GLYPH_TABLE_INDEX_MARKER | tableIndex), (byte)(tableRelativeIndex));
                }
            }

            // build code point to character lookup table
            mCodePointToChar = new Dictionary <CodePoint, string>(charTable.Count);

            // add the ascii range seperately
            for (int charIndex = 0; charIndex < ASCII_RANGE + 1; charIndex++)
            {
                mCodePointToChar[new CodePoint(0, (byte)charIndex)] = charTable[charIndex];
            }

            // add extended characters, and make sure to include the ascii range again due to overlap
            for (int charIndex = 0x20; charIndex < charTable.Count; charIndex++)
            {
                int glyphIndex         = charIndex + CHAR_TO_GLYPH_INDEX_OFFSET;
                int tableIndex         = (glyphIndex / GLYPH_TABLE_SIZE) - 1;
                int tableRelativeIndex = glyphIndex - (tableIndex * GLYPH_TABLE_SIZE);

                mCodePointToChar[new CodePoint((byte)(GLYPH_TABLE_INDEX_MARKER | tableIndex), (byte)(tableRelativeIndex))] = charTable[charIndex];
            }
        }
Ejemplo n.º 2
0
        protected AtlusEncoding()
        {
            if (sIsInitialized)
            {
                return;
            }

            // build character to codepoint table
            sCharToCodePoint = new Dictionary <char, CodePoint>(CharTable.Length);

            // add the ascii range seperately
            for (int charIndex = 0; charIndex < ASCII_RANGE + 1; charIndex++)
            {
                if (!sCharToCodePoint.ContainsKey(CharTable[charIndex]))
                {
                    sCharToCodePoint[CharTable[charIndex]] = new CodePoint(0, ( byte )charIndex);
                }
            }

            // add extended characters, but don't re-include the ascii range
            for (int charIndex = ASCII_RANGE + 1; charIndex < CharTable.Length; charIndex++)
            {
                int glyphIndex         = charIndex + CHAR_TO_GLYPH_INDEX_OFFSET;
                int tableIndex         = (glyphIndex / GLYPH_TABLE_SIZE) - 1;
                int tableRelativeIndex = glyphIndex - (tableIndex * GLYPH_TABLE_SIZE);

                if (!sCharToCodePoint.ContainsKey(CharTable[charIndex]))
                {
                    sCharToCodePoint[CharTable[charIndex]] = new CodePoint(( byte )(GLYPH_TABLE_INDEX_MARKER | tableIndex), ( byte )(tableRelativeIndex));
                }
            }

            // build code point to character lookup table
            sCodePointToChar = new Dictionary <CodePoint, char>(CharTable.Length);

            // add the ascii range seperately
            for (int charIndex = 0; charIndex < ASCII_RANGE + 1; charIndex++)
            {
                sCodePointToChar[new CodePoint(0, ( byte )charIndex)] = CharTable[charIndex];
            }

            // add extended characters, and make sure to include the ascii range again due to overlap
            for (int charIndex = 0x20; charIndex < CharTable.Length; charIndex++)
            {
                int glyphIndex         = charIndex + CHAR_TO_GLYPH_INDEX_OFFSET;
                int tableIndex         = (glyphIndex / GLYPH_TABLE_SIZE) - 1;
                int tableRelativeIndex = glyphIndex - (tableIndex * GLYPH_TABLE_SIZE);

                sCodePointToChar[new CodePoint(( byte )(GLYPH_TABLE_INDEX_MARKER | tableIndex), ( byte )(tableRelativeIndex))] = CharTable[charIndex];
            }

            sIsInitialized = true;
        }