Debian Codegraph @

core/java/android/text/style/MetricAffectingSpan.java

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