Exemplo n.º 1
0
        internal virtual void init(java.lang.CharSequence source, android.text.TextPaint
                                   paint, int outerwidth, android.text.Layout.Alignment?align, float spacingmult,
                                   float spacingadd, android.text.BoringLayout.Metrics metrics, bool includepad, bool
                                   trustWidth)
        {
            int spacing;

            if (java.lang.CharSequenceProxy.IsStringProxy(source) && align == android.text.Layout.Alignment
                .ALIGN_NORMAL)
            {
                mDirect = source.ToString();
            }
            else
            {
                mDirect = null;
            }
            mPaint = paint;
            if (includepad)
            {
                spacing = metrics.bottom - metrics.top;
            }
            else
            {
                spacing = metrics.descent - metrics.ascent;
            }
            if (spacingmult != 1 || spacingadd != 0)
            {
                spacing = (int)(spacing * spacingmult + spacingadd + 0.5f);
            }
            mBottom = spacing;
            if (includepad)
            {
                mDesc = spacing + metrics.top;
            }
            else
            {
                mDesc = spacing + metrics.ascent;
            }
            if (trustWidth)
            {
                mMax = metrics.width;
            }
            else
            {
                android.text.TextLine line = android.text.TextLine.obtain();
                line.set(paint, source, 0, source.Length, android.text.Layout.DIR_LEFT_TO_RIGHT,
                         android.text.Layout.DIRS_ALL_LEFT_TO_RIGHT, false, null);
                mMax = (int)android.util.FloatMath.ceil(line.metrics(null));
                android.text.TextLine.recycle(line);
            }
            if (includepad)
            {
                mTopPadding    = metrics.top - metrics.ascent;
                mBottomPadding = metrics.bottom - metrics.descent;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns null if not boring; the width, ascent, and descent in the
        /// provided Metrics object (or a new one if the provided one was null)
        /// if boring.
        /// </summary>
        /// <remarks>
        /// Returns null if not boring; the width, ascent, and descent in the
        /// provided Metrics object (or a new one if the provided one was null)
        /// if boring.
        /// </remarks>
        /// <hide></hide>
        public static android.text.BoringLayout.Metrics isBoring(java.lang.CharSequence text
                                                                 , android.text.TextPaint paint, android.text.TextDirectionHeuristic textDir, android.text.BoringLayout
                                                                 .Metrics metrics)
        {
            char[] temp   = android.text.TextUtils.obtain(500);
            int    length = text.Length;
            bool   boring = true;

            {
                for (int i = 0; i < length; i += 500)
                {
                    int j = i + 500;
                    if (j > length)
                    {
                        j = length;
                    }
                    android.text.TextUtils.getChars(text, i, j, temp, 0);
                    int n = j - i;
                    {
                        for (int a = 0; a < n; a++)
                        {
                            char c = temp[a];
                            if (c == '\n' || c == '\t' || c >= FIRST_RIGHT_TO_LEFT)
                            {
                                boring = false;
                                goto outer_break;
                            }
                        }
                    }
                    if (textDir != null && textDir.isRtl(temp, 0, n))
                    {
                        boring = false;
                        goto outer_break;
                    }
                }
                outer_continue :;
            }
            outer_break :;
            android.text.TextUtils.recycle(temp);
            if (boring && text is android.text.Spanned)
            {
                android.text.Spanned sp     = (android.text.Spanned)text;
                object[]             styles = sp.getSpans <android.text.style.ParagraphStyle>(0, length);
                if (styles.Length > 0)
                {
                    boring = false;
                }
            }
            if (boring)
            {
                android.text.BoringLayout.Metrics fm = metrics;
                if (fm == null)
                {
                    fm = new android.text.BoringLayout.Metrics();
                }
                android.text.TextLine line = android.text.TextLine.obtain();
                line.set(paint, text, 0, length, android.text.Layout.DIR_LEFT_TO_RIGHT, android.text.Layout
                         .DIRS_ALL_LEFT_TO_RIGHT, false, null);
                fm.width = (int)android.util.FloatMath.ceil(line.metrics(fm));
                android.text.TextLine.recycle(line);
                return(fm);
            }
            else
            {
                return(null);
            }
        }