Project

General

Profile

Download (3.45 KB) Statistics
| Branch: | Tag: | Revision:
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11

    
12
package org.eclipse.draw2d.text;
13

    
14
import org.eclipse.draw2d.geometry.Translatable;
15

    
16
/**
17
 * Stores positional information about where a caret should be placed. This
18
 * structure currently only offers integer precision. Scaling operations will
19
 * result in rounding.
20
 * 
21
 * @since 3.1
22
 */
23
public class CaretInfo implements Translatable {
24

    
25
	private int ascent, lineAscent, descent, lineDescent, baseline, x;
26

    
27
	/**
28
	 * Constructor for use by TextFlow. Constructs a new CaretInfo with the
29
	 * figure's ascent and descent and line information.
30
	 * <P>
31
	 * <EM>WARNING:</EM> This constructor should not be called by clients. It is
32
	 * for use by {@link TextFlow}, and may change in future releases.
33
	 * 
34
	 * @param x
35
	 *            the x location
36
	 * @param y
37
	 *            the y location of the top of the caret
38
	 * @param ascent
39
	 *            the ascent
40
	 * @param descent
41
	 *            the descent
42
	 * @param lineAscent
43
	 *            the ascent of the line on which the caret is placed
44
	 * @param lineDescent
45
	 *            the descent of the line on which the caret is placed
46
	 */
47
	protected CaretInfo(int x, int y, int ascent, int descent, int lineAscent,
48
			int lineDescent) {
49
		this.x = x;
50
		this.baseline = y + ascent;
51
		this.ascent = ascent;
52
		this.descent = descent;
53
		this.lineAscent = lineAscent;
54
		this.lineDescent = lineDescent;
55
	}
56

    
57
	/**
58
	 * Constructs a CaretInfo object by copying the values from another
59
	 * instance.
60
	 * 
61
	 * @param info
62
	 *            the reference
63
	 * @since 3.2
64
	 */
65
	protected CaretInfo(CaretInfo info) {
66
		this.ascent = info.ascent;
67
		this.baseline = info.baseline;
68
		this.descent = info.descent;
69
		this.lineAscent = info.lineAscent;
70
		this.lineDescent = info.lineDescent;
71
		this.x = info.x;
72
	}
73

    
74
	/**
75
	 * Returns the y location of the baseline.
76
	 * 
77
	 * @return the y coordinate of the baseline
78
	 */
79
	public int getBaseline() {
80
		return baseline;
81
	}
82

    
83
	/**
84
	 * Returns the total height of the caret. The height is the sum of the
85
	 * ascent and descent.
86
	 * 
87
	 * @return the height
88
	 */
89
	public int getHeight() {
90
		return ascent + descent;
91
	}
92

    
93
	/**
94
	 * @return the total height of the line on which the caret is placed
95
	 */
96
	public int getLineHeight() {
97
		return lineAscent + lineDescent;
98
	}
99

    
100
	/**
101
	 * @return the y location of the line on which the caret is placed
102
	 */
103
	public int getLineY() {
104
		return baseline - lineAscent;
105
	}
106

    
107
	/**
108
	 * Returns the x location of the caret.
109
	 * 
110
	 * @return the x coordinate
111
	 */
112
	public int getX() {
113
		return x;
114
	}
115

    
116
	/**
117
	 * Returns the y location of the caret.
118
	 * 
119
	 * @return the y coordinate
120
	 */
121
	public int getY() {
122
		return baseline - ascent;
123
	}
124

    
125
	/**
126
	 * @see Translatable#performScale(double)
127
	 */
128
	public void performScale(double factor) {
129
		x *= factor;
130
		baseline *= factor;
131
		descent *= factor;
132
		ascent *= factor;
133
		lineAscent *= factor;
134
		lineDescent *= factor;
135
	}
136

    
137
	/**
138
	 * @see Translatable#performTranslate(int, int)
139
	 */
140
	public void performTranslate(int dx, int dy) {
141
		x += dx;
142
		baseline += dy;
143
	}
144

    
145
}
(8-8/31)