Add CustomTypefaceSpan
This commit is contained in:
		
							parent
							
								
									0a54ebbd6f
								
							
						
					
					
						commit
						cd8016eb68
					
				| @ -0,0 +1,43 @@ | ||||
| package ru.noties.markwon.core.spans; | ||||
| 
 | ||||
| import android.graphics.Typeface; | ||||
| import android.support.annotation.NonNull; | ||||
| import android.text.TextPaint; | ||||
| import android.text.style.MetricAffectingSpan; | ||||
| 
 | ||||
| /** | ||||
|  * A span implementation that allow applying custom Typeface. Although it is | ||||
|  * not used directly by the library, it\'s helpful for customizations. | ||||
|  * <p> | ||||
|  * Please note that this implementation does not validate current paint state | ||||
|  * and won\'t be updating/modifying supplied Typeface. | ||||
|  * | ||||
|  * @since 3.0.0 | ||||
|  */ | ||||
| public class CustomTypefaceSpan extends MetricAffectingSpan { | ||||
| 
 | ||||
|     @NonNull | ||||
|     public static CustomTypefaceSpan create(@NonNull Typeface typeface) { | ||||
|         return new CustomTypefaceSpan(typeface); | ||||
|     } | ||||
| 
 | ||||
|     private final Typeface typeface; | ||||
| 
 | ||||
|     public CustomTypefaceSpan(@NonNull Typeface typeface) { | ||||
|         this.typeface = typeface; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void updateMeasureState(@NonNull TextPaint p) { | ||||
|         updatePaint(p); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void updateDrawState(TextPaint tp) { | ||||
|         updatePaint(tp); | ||||
|     } | ||||
| 
 | ||||
|     private void updatePaint(@NonNull TextPaint paint) { | ||||
|         paint.setTypeface(typeface); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dimitry Ivanov
						Dimitry Ivanov