blob: 92558ebfa31b41d904d330f72d1d5bf432d45da4 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.text.style;
18
19import android.graphics.Paint;
20import 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 */
26public abstract class MetricAffectingSpan
27extends CharacterStyle
28implements UpdateLayout {
29
30 public abstract void updateMeasureState(TextPaint p);
31
32 /**
33 * Returns "this" for most MetricAffectingSpans, but for
34 * MetricAffectingSpans that were generated by {@link #wrap},
35 * returns the underlying MetricAffectingSpan.
36 */
37 @Override
38 public MetricAffectingSpan getUnderlying() {
39 return this;
40 }
41
42 /**
43 * A Passthrough MetricAffectingSpan is one that
44 * passes {@link #updateDrawState} and {@link #updateMeasureState}
45 * calls through to the specified MetricAffectingSpan
46 * while still being a distinct object,
47 * and is therefore able to be attached to the same Spannable
48 * to which the specified MetricAffectingSpan is already attached.
49 */
50 /* package */ static class Passthrough extends MetricAffectingSpan {
51 private MetricAffectingSpan mStyle;
52
53 /**
54 * Creates a new Passthrough of the specfied MetricAffectingSpan.
55 */
56 public Passthrough(MetricAffectingSpan cs) {
57 mStyle = cs;
58 }
59
60 /**
61 * Passes updateDrawState through to the underlying MetricAffectingSpan.
62 */
63 @Override
64 public void updateDrawState(TextPaint tp) {
65 mStyle.updateDrawState(tp);
66 }
67
68 /**
69 * Passes updateMeasureState through to the underlying MetricAffectingSpan.
70 */
71 @Override
72 public void updateMeasureState(TextPaint tp) {
73 mStyle.updateMeasureState(tp);
74 }
75
76 /**
77 * Returns the MetricAffectingSpan underlying this one, or the one
78 * underlying it if it too is a Passthrough.
79 */
80 @Override
81 public MetricAffectingSpan getUnderlying() {
82 return mStyle.getUnderlying();
83 }
84 }
85}