• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.annotation.NonNull;
20 import android.text.TextPaint;
21 
22 /**
23  * The classes that affect character-level text formatting in a way that
24  * changes the width or height of characters extend this class.
25  */
26 @android.ravenwood.annotation.RavenwoodKeepWholeClass
27 public abstract class MetricAffectingSpan
28         extends CharacterStyle
29         implements UpdateLayout {
30 
31     /**
32      * Classes that extend MetricAffectingSpan implement this method to update the text formatting
33      * in a way that can change the width or height of characters.
34      *
35      * @param textPaint the paint used for drawing the text
36      */
updateMeasureState(@onNull TextPaint textPaint)37     public abstract void updateMeasureState(@NonNull TextPaint textPaint);
38 
39     /**
40      * Returns "this" for most MetricAffectingSpans, but for
41      * MetricAffectingSpans that were generated by {@link #wrap},
42      * returns the underlying MetricAffectingSpan.
43      */
44     @Override
getUnderlying()45     public MetricAffectingSpan getUnderlying() {
46         return this;
47     }
48 
49     /**
50      * A Passthrough MetricAffectingSpan is one that
51      * passes {@link #updateDrawState} and {@link #updateMeasureState}
52      * calls through to the specified MetricAffectingSpan
53      * while still being a distinct object,
54      * and is therefore able to be attached to the same Spannable
55      * to which the specified MetricAffectingSpan is already attached.
56      */
57     /* package */ static class Passthrough extends MetricAffectingSpan {
58         private MetricAffectingSpan mStyle;
59 
60         /**
61          * Creates a new Passthrough of the specfied MetricAffectingSpan.
62          */
Passthrough(@onNull MetricAffectingSpan cs)63         Passthrough(@NonNull MetricAffectingSpan cs) {
64             mStyle = cs;
65         }
66 
67         /**
68          * Passes updateDrawState through to the underlying MetricAffectingSpan.
69          */
70         @Override
updateDrawState(@onNull TextPaint tp)71         public void updateDrawState(@NonNull TextPaint tp) {
72             mStyle.updateDrawState(tp);
73         }
74 
75         /**
76          * Passes updateMeasureState through to the underlying MetricAffectingSpan.
77          */
78         @Override
updateMeasureState(@onNull TextPaint tp)79         public void updateMeasureState(@NonNull TextPaint tp) {
80             mStyle.updateMeasureState(tp);
81         }
82 
83         /**
84          * Returns the MetricAffectingSpan underlying this one, or the one
85          * underlying it if it too is a Passthrough.
86          */
87         @Override
getUnderlying()88         public MetricAffectingSpan getUnderlying() {
89             return mStyle.getUnderlying();
90         }
91     }
92 }
93