summaryrefslogtreecommitdiffstats
path: root/awt/org/apache/harmony/awt/gl/font/TextRunSegment.java
blob: 1cd2c055ae3b3763f95fd108c9523becbd662f8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
/*
 * @author Oleg V. Khaschansky
 * @version $Revision$
 */

package org.apache.harmony.awt.gl.font;

import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.font.TextHitInfo;
import java.awt.geom.Rectangle2D;

/**
 * Abstract class which represents the segment of the text with constant attributes
 * running in one direction (i.e. constant level).
 */
public abstract class TextRunSegment implements Cloneable {
    float x; // Calculated x location of this segment on the screen
    float y; // Calculated y location of this segment on the screen

    BasicMetrics metrics; // Metrics of this text run segment
    TextDecorator.Decoration decoration; // Underline, srikethrough, etc.
    Rectangle2D logicalBounds = null; // Logical bounding box for the segment
    Rectangle2D visualBounds = null; // Visual bounding box for the segment

    /**
     * Returns start index of the segment
     * @return start index
     */
    abstract int getStart();

    /**
     * Returns end index of the segment
     * @return end index
     */
    abstract int getEnd();

    /**
     * Returns the number of characters in the segment
     * @return number of characters
     */
    abstract int getLength();

    /**
     * Renders this text run segment
     * @param g2d - graphics to render to
     * @param xOffset - X offset from the graphics origin to the
     * origin of the text layout
     * @param yOffset - Y offset from the graphics origin to the
     * origin of the text layout
     */
    abstract void draw(Graphics2D g2d, float xOffset, float yOffset);

    /**
     * Creates black box bounds shape for the specified range
     * @param start - range sart
     * @param limit - range end
     * @return black box bounds shape
     */
    abstract Shape getCharsBlackBoxBounds(int start, int limit);

    /**
     * Returns the outline shape
     * @return outline
     */
    abstract Shape getOutline();

    /**
     * Returns visual bounds of this segment
     * @return visual bounds
     */
    abstract Rectangle2D getVisualBounds();

    /**
     * Returns logical bounds of this segment
     * @return logical bounds
     */
    abstract Rectangle2D getLogicalBounds();

    /**
     * Calculates advance of the segment
     * @return advance
     */
    abstract float getAdvance();

    /**
     * Calculates advance delta between two characters
     * @param start - 1st position
     * @param end - 2nd position
     * @return advance increment between specified positions
     */
    abstract float getAdvanceDelta(int start, int end);

    /**
     * Calculates index of the character which advance is equal to
     * the given. If the given advance is greater then the segment
     * advance it returns the position after the last character.
     * @param advance - given advance
     * @param start - character, from which to start measuring advance
     * @return character index
     */
    abstract int getCharIndexFromAdvance(float advance, int start);

    /**
     * Checks if the character doesn't contribute to the text advance
     * @param index - character index
     * @return true if the character has zero advance
     */
    abstract boolean charHasZeroAdvance(int index);

    /**
     * Calculates position of the character on the screen
     * @param index - character index
     * @return X coordinate of the character position
     */
    abstract float getCharPosition(int index);

    /**
     * Returns the advance of the individual character
     * @param index - character index
     * @return character advance
     */
    abstract float getCharAdvance(int index);

    /**
     * Creates text hit info from the hit position
     * @param x - X coordinate relative to the origin of the layout
     * @param y - Y coordinate relative to the origin of the layout
     * @return hit info
     */
    abstract TextHitInfo hitTest(float x, float y);

    /**
     * Collects justification information into JustificationInfo object
     * @param jInfo - JustificationInfo object
     */
    abstract void updateJustificationInfo(TextRunBreaker.JustificationInfo jInfo);

    /**
     * Performs justification of the segment.
     * Updates positions of individual characters.
     * @param jInfos - justification information, gathered by the previous passes
     * @return amount of growth or shrink of the segment
     */    
    abstract float doJustification(TextRunBreaker.JustificationInfo jInfos[]);

    @Override
    public abstract Object clone();
}