mirror of https://github.com/ThmmyNoLife/mTHMMY
Apostolos Fanakis
8 years ago
3 changed files with 32 additions and 15 deletions
@ -1,20 +1,23 @@ |
|||
package gr.thmmy.mthmmy.utils; |
|||
|
|||
import android.text.TextPaint; |
|||
import android.text.style.SuperscriptSpan; |
|||
import android.util.Log; |
|||
|
|||
public class CenterVerticalSpan extends SuperscriptSpan { |
|||
public CenterVerticalSpan() { |
|||
} |
|||
import android.graphics.Canvas; |
|||
import android.graphics.Paint; |
|||
import android.graphics.Rect; |
|||
import android.support.annotation.NonNull; |
|||
import android.text.style.ReplacementSpan; |
|||
|
|||
public class CenterVerticalSpan extends ReplacementSpan { |
|||
@Override |
|||
public void updateDrawState(TextPaint textPaint) { |
|||
textPaint.baselineShift -= 7f; |
|||
public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { |
|||
text = text.subSequence(start, end); |
|||
return (int) paint.measureText(text.toString()); |
|||
} |
|||
|
|||
@Override |
|||
public void updateMeasureState(TextPaint tp) { |
|||
updateDrawState(tp); |
|||
public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) { |
|||
text = text.subSequence(start, end); |
|||
Rect charSize = new Rect(); |
|||
paint.getTextBounds(text.toString(), 0, 1, charSize); |
|||
canvas.drawText(text.toString(), x, (bottom + charSize.height()) / 2f, paint); |
|||
} |
|||
} |
Loading…
Reference in new issue