package com.zzhoujay.markdown.style;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.text.style.LineHeightSpan;
import android.text.style.ReplacementSpan;

/**
 * Created by zhou on 16-7-2.
 */
public class UnderLineSpan extends ReplacementSpan implements LineHeightSpan {

    private int height;
    private int width;
    private Drawable drawable;

    public UnderLineSpan(Drawable drawable, int width, int height) {
        this.height = height;
        this.width = width;
        this.drawable = drawable;
    }


    @Override
    public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
        return (int) paint.measureText(text, start, end);
    }

    @Override
    public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
        drawable.setBounds((int) x, bottom - height, (int) x + width, bottom);
        drawable.draw(canvas);
    }

    @Override
    public void chooseHeight(CharSequence text, int start, int end, int spanstartv, int v, Paint.FontMetricsInt fm) {
        fm.top /= 3;
        fm.ascent /= 3;
        fm.bottom /= 3;
        fm.descent /= 3;
    }
}

@@ -353,21 +353,66 @@
 private 
-int h
+static final int PADDING = 12;%0A%0A    private int mH
 eight;%0A 
@@ -422,25 +422,26 @@
 private int 
-w
+mW
 idth;%0A    pr
@@ -451,25 +451,26 @@
 te Drawable 
-d
+mD
 rawable;%0A%0A  
@@ -549,17 +549,18 @@
    this.
-h
+mH
 eight = 
@@ -580,17 +580,18 @@
    this.
-w
+mW
 idth = w
@@ -609,17 +609,18 @@
    this.
-d
+mD
 rawable 
@@ -638,17 +638,16 @@
 %0A    %7D%0A%0A
-%0A
     @Ove
@@ -960,33 +960,34 @@
 aint) %7B%0A        
-d
+mD
 rawable.setBound
@@ -1001,23 +1001,21 @@
  x, 
-bottom - height
+top + PADDING
 , (i
@@ -1026,21 +1026,39 @@
 x + 
-w
+mW
 idth, 
-bottom
+top + mHeight + PADDING
 );%0A 
@@ -1064,17 +1064,18 @@
         
-d
+mD
 rawable.

improve UnderLineSpan