public LineHeightSpan(TextView view, double lineHeight)
 {
     _lineHeight = lineHeight;
     Paint.FontMetricsInt fm = view.Paint.GetFontMetricsInt();
     _ascent  = fm.Ascent;
     _descent = fm.Descent;
 }
Exemple #2
0
 public EmojiSpan(EmojiDrawable d, int verticalAlignment, int s, Paint.FontMetricsInt original) :
     base(d)
 {
     fontMetrics = original;
     if (original != null)
     {
         size = System.Math.Abs(fontMetrics.Descent) + System.Math.Abs(fontMetrics.Ascent);
         if (size == 0)
         {
             size = AndroidUtilities.dp(20);
         }
     }
 }
 protected override void OnDraw(Canvas canvas)
 {
     if (null != text)
     {
         // 画圆
         canvas.DrawCircle(Width / 2, Width / 2, Width / 2, mPaintBackground);
         // 写字
         mPaintText.TextSize    = (Width / 2);
         mPaintText.StrokeWidth = (3);
         mPaintText.GetTextBounds(text, 0, 1, mRect);
         // 垂直居中
         Paint.FontMetricsInt fontMetrics = mPaintText.GetFontMetricsInt();
         int baseline = (MeasuredHeight - fontMetrics.Bottom - fontMetrics.Top) / 2;
         // 左右居中
         mPaintText.TextAlign = Align.Center;
         canvas.DrawText(text, Width / 2, baseline, mPaintText);
     }
 }
        public override int GetSize(Paint paint, ICharSequence text, int start, int end, Paint.FontMetricsInt fm)
        {
            Rect rect = drawable.Bounds;

            if (fm != null)
            {
                Paint.FontMetricsInt fmPaint = paint.GetFontMetricsInt();
                int fontHeight = fmPaint.Bottom - fmPaint.Top;
                int drHeight   = rect.Bottom - rect.Top;

                int top    = drHeight / 2 - fontHeight / 4;
                int bottom = drHeight / 2 + fontHeight / 4;

                fm.Ascent  = -bottom;
                fm.Top     = -bottom;
                fm.Bottom  = top;
                fm.Descent = top;
            }
            return(rect.Right);
        }
Exemple #5
0
            public override int GetSize(Paint paint, ICharSequence text, int start, int end, Paint.FontMetricsInt fm)
            {
                if (fm == null)
                {
                    fm = new Paint.FontMetricsInt();
                }

                if (fontMetrics == null)
                {
                    int sz = base.GetSize(paint, text, start, end, fm);

                    int offset = AndroidUtilities.dp(8);
                    int w      = AndroidUtilities.dp(10);
                    fm.Top     = -w - offset;
                    fm.Bottom  = w - offset;
                    fm.Ascent  = -w - offset;
                    fm.Leading = 0;
                    fm.Descent = w - offset;

                    return(sz);
                }
                else
                {
                    if (fm != null)
                    {
                        fm.Ascent  = fontMetrics.Ascent;
                        fm.Descent = fontMetrics.Descent;

                        fm.Top    = fontMetrics.Top;
                        fm.Bottom = fontMetrics.Bottom;
                    }
                    if (Drawable != null)
                    {
                        Drawable.SetBounds(0, 0, size, size);
                    }
                    return(size);
                }
            }
Exemple #6
0
        public static ICharSequence replaceEmoji(ICharSequence cs, Paint.FontMetricsInt fontMetrics, int size)
        {
            if (cs == null || cs.Length() == 0)
            {
                return(cs);
            }
            ISpannable s;

            if (cs is ISpannable)
            {
                s = (ISpannable)cs;
            }
            else
            {
                s = SpannableFactory.Instance.NewSpannable(cs);
            }
            ulong buf        = 0;
            int   emojiCount = 0;

            try
            {
                for (int i = 0; i < cs.Length(); i++)
                {
                    char c = cs.CharAt(i);
                    if (c == 0xD83C || c == 0xD83D || (buf != 0 && (buf & 0xFFFFFFFF00000000L) == 0 && (c >= 0xDDE6 && c <= 0xDDFA)))
                    {
                        buf <<= 16;
                        buf  |= c;
                    }
                    else if (buf > 0 && (c & 0xF000) == 0xD000)
                    {
                        buf <<= 16;
                        buf  |= c;
                        EmojiDrawable d = Emoji.getEmojiDrawable(buf);
                        if (d != null)
                        {
                            var span = new EmojiSpan(d, (int)SpanAlign.Bottom, size, fontMetrics);
                            emojiCount++;
                            if (c >= 0xDDE6 && c <= 0xDDFA)
                            {
                                s.SetSpan(span, i - 3, i + 1, 0);
                            }
                            else
                            {
                                s.SetSpan(span, i - 1, i + 1, 0);
                            }
                        }
                        buf = 0;
                    }
                    else if (c == 0x20E3)
                    {
                        if (i > 0)
                        {
                            char c2 = cs.CharAt(i - 1);
                            if ((c2 >= '0' && c2 <= '9') || c2 == '#')
                            {
                                buf   = c2;
                                buf <<= 16;
                                buf  |= c;
                                EmojiDrawable d = Emoji.getEmojiDrawable(buf);
                                if (d != null)
                                {
                                    EmojiSpan span = new EmojiSpan(d, (int)SpanAlign.Bottom, size, fontMetrics);
                                    emojiCount++;
                                    s.SetSpan(span, i - 1, i + 1, 0);
                                }
                                buf = 0;
                            }
                        }
                    }
                    else if (inArray(c, emojiChars) == Java.Lang.Boolean.True)
                    {
                        EmojiDrawable d = Emoji.getEmojiDrawable(c);
                        if (d != null)
                        {
                            EmojiSpan span = new EmojiSpan(d, (int)SpanAlign.Bottom, size, fontMetrics);
                            emojiCount++;
                            s.SetSpan(span, i, i + 1, 0);
                        }
                    }
                    if (emojiCount >= 50)
                    {
                        break;
                    }
                }
            }
            catch (Java.Lang.Exception e)
            {
                //FileLog.e("tmessages", e);
                return(cs);
            }
            return(s);
        }
Exemple #7
0
 public override int GetSize(Paint paint, ICharSequence text, int start, int end, Paint.FontMetricsInt fm)
 => (int)(margin + padding + paint.MeasureText(text.SubSequence(start, end)) + padding + margin);
 public void ChooseHeight(Java.Lang.ICharSequence text, int start, int end, int spanstartv, int v, Paint.FontMetricsInt fm)
 {
     fm.Ascent  = (int)(_ascent * _lineHeight);
     fm.Descent = (int)(_descent * _lineHeight);
 }
Exemple #9
0
 public override int GetSize(Paint paint, ICharSequence text, int start, int end, Paint.FontMetricsInt fm)
 {
     LOCAL_PAINT.Set(paint);
     ApplyCustomTypeFace(LOCAL_PAINT, type);
     LOCAL_PAINT.GetTextBounds(icon, 0, 1, TEXT_BOUNDS);
     if (fm != null)
     {
         float baselineRatio = baselineAligned ? 0 : BASELINE_RATIO;
         fm.Descent = (int)(TEXT_BOUNDS.Height() * baselineRatio);
         fm.Ascent  = -(TEXT_BOUNDS.Height() - fm.Descent);
         fm.Top     = fm.Ascent;
         fm.Bottom  = fm.Descent;
     }
     return(TEXT_BOUNDS.Width());
 }
Exemple #10
0
 override public int GetSize(Paint paint, ICharSequence text, int start, int end, Paint.FontMetricsInt fm)
 {
     return((int)System.Math.Round(paint.TextSize));
 }
Exemple #11
0
 public void ChooseHeight(ICharSequence text, int start, int end, int spanstartv, int v, Paint.FontMetricsInt fm)
 {
     throw new NotImplementedException();
 }
 override public int GetSize(Paint paint, ICharSequence text, int start, int end, Paint.
                             FontMetricsInt fm)
 {
     return(0);
 }
 public override int GetSize(Paint paint, ICharSequence text, int start, int end, Paint.FontMetricsInt fm)
 {
     LocalPaint.Set(paint);
     ApplyCustomTypeFace(LocalPaint, _typeface);
     LocalPaint.GetTextBounds(_icon, 0, 1, TextBounds);
     if (fm != null)
     {
         fm.Descent = (int)(TextBounds.Height() * BaselineRatio);
         fm.Ascent  = -(TextBounds.Height() - fm.Descent);
         fm.Top     = fm.Ascent;
         fm.Bottom  = fm.Descent;
     }
     return(TextBounds.Width());
 }