Exemplo n.º 1
0
        //C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
        //ORIGINAL LINE: void itemize(const UInt16* string, int string_length, FontStyle style, ClassicVector<Run>* result) const;
        public void itemize(UInt16 @string, int string_size, FontStyle style, vector <Run> result)
        {
            uint       langListId = style.getLanguageListId();
            int        variant    = style.getVariant();
            FontFamily lastFamily = null;
            Run        run        = null;

            if (string_size == 0)
            {
                return;
            }

            const uint kEndOfString = 0xFFFFFFFF;

            uint nextCh       = 0;
            uint prevCh       = 0;
            int  nextUtf16Pos = 0;
            int  readLength   = 0;

            U16_NEXT(@string, readLength, string_size, nextCh);

            do
            {
                uint ch       = new uint(nextCh);
                int  utf16Pos = nextUtf16Pos;
                //C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
                //ORIGINAL LINE: nextUtf16Pos = readLength;
                nextUtf16Pos.CopyFrom(readLength);
                if (readLength < string_size)
                {
                    U16_NEXT(@string, readLength, string_size, nextCh);
                }
                else
                {
                    //C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
                    //ORIGINAL LINE: nextCh = kEndOfString;
                    nextCh = kEndOfString;
                }

                bool shouldContinueRun = false;
                if (lastFamily != null)
                {
                    if (isStickyWhitelisted(ch))
                    {
                        // Continue using existing font as long as it has coverage and is
                        // whitelisted
                        shouldContinueRun = lastFamily.getCoverage().get(ch);
                    }
                    else if (ch == SOFT_HYPHEN || isVariationSelector(ch))
                    {
                        // Always continue if the character is the soft hyphen or a variation
                        // selector.
                        shouldContinueRun = true;
                    }
                }

                if (!shouldContinueRun)
                {
                    FontFamily *family = getFamilyForChar(ch, isVariationSelector(new uint(nextCh)) ? nextCh : 0, langListId, variant);
                    if (utf16Pos == 0 || family.get() != lastFamily)
                    {
                        int start = utf16Pos;
                        // Workaround for combining marks and emoji modifiers until we implement
                        // per-cluster font selection: if a combining mark or an emoji modifier
                        // is found in a different font that also supports the previous
                        // character, attach previous character to the new run. U+20E3 COMBINING
                        // ENCLOSING KEYCAP, used in emoji, is handled properly by this since
                        // it's a combining mark too.
                        if (utf16Pos != 0 && ((U_GET_GC_MASK(ch) & U_GC_M_MASK) != 0 || (isEmojiModifier(ch) && isEmojiBase(prevCh))) && family != null && family.getCoverage().get(prevCh))
                        {
                            int prevChLength = U16_LENGTH(prevCh);
                            run.end -= prevChLength;
                            if (run.start == run.end)
                            {
                                result.pop_back();
                            }
                            start -= prevChLength;
                        }
                        result.push_back({ family.getClosestMatch(style), (int)start, 0 });
                        run        = result.back();
                        lastFamily = family.get();
                    }