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; |
package gr.thmmy.mthmmy.utils; |
||||
|
|
||||
import android.text.TextPaint; |
import android.graphics.Canvas; |
||||
import android.text.style.SuperscriptSpan; |
import android.graphics.Paint; |
||||
import android.util.Log; |
import android.graphics.Rect; |
||||
|
import android.support.annotation.NonNull; |
||||
public class CenterVerticalSpan extends SuperscriptSpan { |
import android.text.style.ReplacementSpan; |
||||
public CenterVerticalSpan() { |
|
||||
} |
|
||||
|
|
||||
|
public class CenterVerticalSpan extends ReplacementSpan { |
||||
@Override |
@Override |
||||
public void updateDrawState(TextPaint textPaint) { |
public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { |
||||
textPaint.baselineShift -= 7f; |
text = text.subSequence(start, end); |
||||
|
return (int) paint.measureText(text.toString()); |
||||
} |
} |
||||
|
|
||||
@Override |
@Override |
||||
public void updateMeasureState(TextPaint tp) { |
public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) { |
||||
updateDrawState(tp); |
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