blob: e6abf6f9b776a2adc9270cd9e88fbde814e66498 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1998-2003 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25/*
26 *
27 * (C) Copyright IBM Corp. 1998-2003 All Rights Reserved
28 */
29
30package sun.font;
31
32import java.awt.Graphics2D;
33import java.awt.Shape;
34
35import java.awt.geom.Rectangle2D;
36
37/**
38 * A label.
39 * Visual bounds is a rect that encompasses the entire rendered area.
40 * Logical bounds is a rect that defines how to position this next
41 * to other objects.
42 * Align bounds is a rect that defines how to align this to margins.
43 * it generally allows some overhang that logical bounds would prevent.
44 */
45public abstract class TextLabel {
46
47 /**
48 * Return a rectangle that surrounds the text outline when this label is rendered at x, y.
49 */
50 public abstract Rectangle2D getVisualBounds(float x, float y);
51
52 /**
53 * Return a rectangle that corresponds to the logical bounds of the text
54 * when this label is rendered at x, y.
55 * This rectangle is used when positioning text next to other text.
56 */
57 public abstract Rectangle2D getLogicalBounds(float x, float y);
58
59 /**
60 * Return a rectangle that corresponds to the alignment bounds of the text
61 * when this label is rendered at x, y. This rectangle is used when positioning text next
62 * to a margin. It differs from the logical bounds in that it does not include leading or
63 * trailing whitespace.
64 */
65 public abstract Rectangle2D getAlignBounds(float x, float y);
66
67 /**
68 * Return a rectangle that corresponds to the logical bounds of the text, adjusted
69 * to angle the leading and trailing edges by the italic angle.
70 */
71 public abstract Rectangle2D getItalicBounds(float x, float y);
72
73 /**
74 * Return an outline of the characters in the label when rendered at x, y.
75 */
76 public abstract Shape getOutline(float x, float y);
77
78 /**
79 * Render the label at x, y in the graphics.
80 */
81 public abstract void draw(Graphics2D g, float x, float y);
82
83 /**
84 * A convenience method that returns the visual bounds when rendered at 0, 0.
85 */
86 public Rectangle2D getVisualBounds() {
87 return getVisualBounds(0f, 0f);
88 }
89
90 /**
91 * A convenience method that returns the logical bounds when rendered at 0, 0.
92 */
93 public Rectangle2D getLogicalBounds() {
94 return getLogicalBounds(0f, 0f);
95 }
96
97 /**
98 * A convenience method that returns the align bounds when rendered at 0, 0.
99 */
100 public Rectangle2D getAlignBounds() {
101 return getAlignBounds(0f, 0f);
102 }
103
104 /**
105 * A convenience method that returns the italic bounds when rendered at 0, 0.
106 */
107 public Rectangle2D getItalicBounds() {
108 return getItalicBounds(0f, 0f);
109 }
110
111 /**
112 * A convenience method that returns the outline when rendered at 0, 0.
113 */
114 public Shape getOutline() {
115 return getOutline(0f, 0f);
116 }
117
118 /**
119 * A convenience method that renders the label at 0, 0.
120 */
121 public void draw(Graphics2D g) {
122 draw(g, 0f, 0f);
123 }
124}