1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.text.style; 18 19 import android.text.TextPaint; 20 21 /** 22 * The classes that affect character-level text formatting in a way that 23 * changes the width or height of characters extend this class. 24 */ 25 public abstract class MetricAffectingSpan 26 extends CharacterStyle 27 implements UpdateLayout { 28 29 public abstract void updateMeasureState(TextPaint p); 30 31 /** 32 * Returns "this" for most MetricAffectingSpans, but for 33 * MetricAffectingSpans that were generated by {@link #wrap}, 34 * returns the underlying MetricAffectingSpan. 35 */ 36 @Override 37 public MetricAffectingSpan getUnderlying() { 38 return this; 39 } 40 41 /** 42 * A Passthrough MetricAffectingSpan is one that 43 * passes {@link #updateDrawState} and {@link #updateMeasureState} 44 * calls through to the specified MetricAffectingSpan 45 * while still being a distinct object, 46 * and is therefore able to be attached to the same Spannable 47 * to which the specified MetricAffectingSpan is already attached. 48 */ 49 /* package */ static class Passthrough extends MetricAffectingSpan { 50 private MetricAffectingSpan mStyle; 51 52 /** 53 * Creates a new Passthrough of the specfied MetricAffectingSpan. 54 */ 55 public Passthrough(MetricAffectingSpan cs) { 56 mStyle = cs; 57 } 58 59 /** 60 * Passes updateDrawState through to the underlying MetricAffectingSpan. 61 */ 62 @Override 63 public void updateDrawState(TextPaint tp) { 64 mStyle.updateDrawState(tp); 65 } 66 67 /** 68 * Passes updateMeasureState through to the underlying MetricAffectingSpan. 69 */ 70 @Override 71 public void updateMeasureState(TextPaint tp) { 72 mStyle.updateMeasureState(tp); 73 } 74 75 /** 76 * Returns the MetricAffectingSpan underlying this one, or the one 77 * underlying it if it too is a Passthrough. 78 */ 79 @Override 80 public MetricAffectingSpan getUnderlying() { 81 return mStyle.getUnderlying(); 82 } 83 } 84 } 85