Пример #1
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
//ORIGINAL LINE: private int calcLineBreak(final int pos, final float maxAdvance)
        private int CalcLineBreak(int pos, float maxAdvance)
        {
            // either of these statements removes the bug:
            //generateComponents(0, fChars.length);
            //generateComponents(pos, fChars.length);

            int   startPos = pos;
            float width    = maxAdvance;

            int tlcIndex;
            int tlcStart = FComponentStart;

            for (tlcIndex = 0; tlcIndex < FComponents.Length; tlcIndex++)
            {
                int gaLimit = tlcStart + FComponents[tlcIndex].NumCharacters;
                if (gaLimit > startPos)
                {
                    break;
                }
                else
                {
                    tlcStart = gaLimit;
                }
            }

            // tlcStart is now the start of the tlc at tlcIndex

            for (; tlcIndex < FComponents.Length; tlcIndex++)
            {
                TextLineComponent tlc = FComponents[tlcIndex];
                int numCharsInGa      = tlc.NumCharacters;

                int lineBreak = tlc.getLineBreakIndex(startPos - tlcStart, width);
                if (lineBreak == numCharsInGa && tlcIndex < FComponents.Length)
                {
                    width    -= tlc.getAdvanceBetween(startPos - tlcStart, lineBreak);
                    tlcStart += numCharsInGa;
                    startPos  = tlcStart;
                }
                else
                {
                    return(tlcStart + lineBreak);
                }
            }

            if (FComponentLimit < FChars.Length)
            {
                // format more text and try again
                //if (haveLayoutWindow) {
                //    outOfWindow++;
                //}

                GenerateComponents(pos, FChars.Length);
                return(CalcLineBreak(pos, maxAdvance));
            }

            return(FChars.Length);
        }
Пример #2
0
        private TextLineComponent[] MakeComponentsOnRange(int startPos, int limitPos)
        {
            // sigh I really hate to do this here since it's part of the
            // bidi algorithm.
            // cdWsStart is the start of the trailing counterdirectional
            // whitespace
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int cdWsStart = trailingCdWhitespaceStart(startPos, limitPos);
            int cdWsStart = TrailingCdWhitespaceStart(startPos, limitPos);

            int tlcIndex;
            int tlcStart = FComponentStart;

            for (tlcIndex = 0; tlcIndex < FComponents.Length; tlcIndex++)
            {
                int gaLimit = tlcStart + FComponents[tlcIndex].NumCharacters;
                if (gaLimit > startPos)
                {
                    break;
                }
                else
                {
                    tlcStart = gaLimit;
                }
            }

            // tlcStart is now the start of the tlc at tlcIndex

            int componentCount;

            {
                bool split     = false;
                int  compStart = tlcStart;
                int  lim       = tlcIndex;
                for (bool cont = true; cont; lim++)
                {
                    int gaLimit = compStart + FComponents[lim].NumCharacters;
                    if (cdWsStart > System.Math.Max(compStart, startPos) && cdWsStart < System.Math.Min(gaLimit, limitPos))
                    {
                        split = true;
                    }
                    if (gaLimit >= limitPos)
                    {
                        cont = false;
                    }
                    else
                    {
                        compStart = gaLimit;
                    }
                }
                componentCount = lim - tlcIndex;
                if (split)
                {
                    componentCount++;
                }
            }

            TextLineComponent[] components = new TextLineComponent[componentCount];
            int newCompIndex = 0;
            int linePos      = startPos;

            int breakPt = cdWsStart;

            int subsetFlag;

            if (breakPt == startPos)
            {
                subsetFlag = FIsDirectionLTR? TextLineComponent.LEFT_TO_RIGHT : TextLineComponent.RIGHT_TO_LEFT;
                breakPt    = limitPos;
            }
            else
            {
                subsetFlag = TextLineComponent.UNCHANGED;
            }

            while (linePos < limitPos)
            {
                int compLength = FComponents[tlcIndex].NumCharacters;
                int tlcLimit   = tlcStart + compLength;

                int start = System.Math.Max(linePos, tlcStart);
                int limit = System.Math.Min(breakPt, tlcLimit);

                components[newCompIndex++] = FComponents[tlcIndex].getSubset(start - tlcStart, limit - tlcStart, subsetFlag);
                linePos += (limit - start);
                if (linePos == breakPt)
                {
                    breakPt    = limitPos;
                    subsetFlag = FIsDirectionLTR? TextLineComponent.LEFT_TO_RIGHT : TextLineComponent.RIGHT_TO_LEFT;
                }
                if (linePos == tlcLimit)
                {
                    tlcIndex++;
                    tlcStart = tlcLimit;
                }
            }

            return(components);
        }