1 /*
2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
113 return 0;
114 }
115 }
116
117 @Override
118 public TextLine[] getLines() {
119 return new TextLine[] {new StubTextLine()};
120 }
121
122 @Override
123 public GlyphList[] getRuns() {
124 return new GlyphList[0];
125 }
126
127 @Override
128 public Shape getShape(int type, TextSpan filter) {
129 return new Path2D();
130 }
131
132 @Override
133 public HitInfo getHitInfo(float x, float y) {
134 // TODO this probably needs to be entirely rewritten...
135 if (text == null) {
136 final HitInfo hit = new HitInfo();
137 hit.setCharIndex(0);
138 hit.setLeading(true);
139 return hit;
140 }
141
142 final double fontSize = (font == null ? 0 : ((Font)font).getSize());
143 final String[] lines = text.split("\n");
144 int lineIndex = Math.min(lines.length - 1, (int) (y / fontSize));
145 if (lineIndex >= lines.length) {
146 throw new IllegalStateException("Asked for hit info out of y range: x=" + x + "y=" +
147 + y + "text='" + text + "', lineIndex=" + lineIndex + ", numLines=" + lines.length +
148 ", fontSize=" + fontSize);
149 }
150 int offset = 0;
151 for (int i=0; i<lineIndex; i++) {
152 offset += lines[i].length() + 1; // add in the \n
153 }
154
155 int charPos = (int) (x / lines[lineIndex].length());
156 if (charPos + offset > text.length()) {
157 throw new IllegalStateException("Asked for hit info out of x range");
158 }
159
160 final HitInfo hit = new HitInfo();
161 hit.setCharIndex(offset + charPos);
162 return hit;
163 }
164
165 @Override
166 public PathElement[] getCaretShape(int offset, boolean isLeading, float x,
167 float y) {
168 return new PathElement[0];
169 }
170
171 @Override
172 public PathElement[] getRange(int start, int end, int type, float x, float y) {
173 return new PathElement[0];
174 }
175
176 @Override
177 public BaseBounds getVisualBounds(int type) {
178 return new RectBounds();
179 }
180
181 }
|
1 /*
2 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
113 return 0;
114 }
115 }
116
117 @Override
118 public TextLine[] getLines() {
119 return new TextLine[] {new StubTextLine()};
120 }
121
122 @Override
123 public GlyphList[] getRuns() {
124 return new GlyphList[0];
125 }
126
127 @Override
128 public Shape getShape(int type, TextSpan filter) {
129 return new Path2D();
130 }
131
132 @Override
133 public Hit getHitInfo(float x, float y) {
134 // TODO this probably needs to be entirely rewritten...
135 if (text == null) {
136 return new Hit(0, -1, true);
137 }
138
139 final double fontSize = (font == null ? 0 : ((Font)font).getSize());
140 final String[] lines = text.split("\n");
141 int lineIndex = Math.min(lines.length - 1, (int) (y / fontSize));
142 if (lineIndex >= lines.length) {
143 throw new IllegalStateException("Asked for hit info out of y range: x=" + x + "y=" +
144 + y + "text='" + text + "', lineIndex=" + lineIndex + ", numLines=" + lines.length +
145 ", fontSize=" + fontSize);
146 }
147 int offset = 0;
148 for (int i=0; i<lineIndex; i++) {
149 offset += lines[i].length() + 1; // add in the \n
150 }
151
152 int charPos = (int) (x / lines[lineIndex].length());
153 if (charPos + offset > text.length()) {
154 throw new IllegalStateException("Asked for hit info out of x range");
155 }
156
157 return new Hit(offset + charPos, -1, true);
158 }
159
160 @Override
161 public PathElement[] getCaretShape(int offset, boolean isLeading, float x,
162 float y) {
163 return new PathElement[0];
164 }
165
166 @Override
167 public PathElement[] getRange(int start, int end, int type, float x, float y) {
168 return new PathElement[0];
169 }
170
171 @Override
172 public BaseBounds getVisualBounds(int type) {
173 return new RectBounds();
174 }
175
176 }
|