1 /*
2 * Copyright (c) 1999, 2013, 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
176
177 if (pos == v.getEndOffset()) {
178 pos--;
179 }
180
181 biasReturn[0] = hit.isLeadingEdge() ? Position.Bias.Forward : Position.Bias.Backward;
182 return pos + v.getStartOffset();
183 }
184
185 /**
186 * Determines the model location that represents the
187 * maximum advance that fits within the given span.
188 * This could be used to break the given view. The result
189 * should be a location just shy of the given advance. This
190 * differs from viewToModel which returns the closest
191 * position which might be proud of the maximum advance.
192 *
193 * @param v the view to find the model location to break at.
194 * @param p0 the location in the model where the
195 * fragment should start it's representation >= 0.
196 * @param pos the graphic location along the axis that the
197 * broken view would occupy >= 0. This may be useful for
198 * things like tab calculations.
199 * @param len specifies the distance into the view
200 * where a potential break is desired >= 0.
201 * @return the maximum model location possible for a break.
202 * @see View#breakView
203 */
204 public int getBoundedPosition(GlyphView v, int p0, float x, float len) {
205 if( len < 0 )
206 throw new IllegalArgumentException("Length must be >= 0.");
207 // note: this only works because swing uses TextLayouts that are
208 // only pure rtl or pure ltr
209 TextHitInfo hit;
210 if (layout.isLeftToRight()) {
211 hit = layout.hitTestChar(len, 0);
212 } else {
213 hit = layout.hitTestChar(layout.getAdvance() - len, 0);
214 }
215 return v.getStartOffset() + hit.getCharIndex();
216 }
|
1 /*
2 * Copyright (c) 1999, 2017, 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
176
177 if (pos == v.getEndOffset()) {
178 pos--;
179 }
180
181 biasReturn[0] = hit.isLeadingEdge() ? Position.Bias.Forward : Position.Bias.Backward;
182 return pos + v.getStartOffset();
183 }
184
185 /**
186 * Determines the model location that represents the
187 * maximum advance that fits within the given span.
188 * This could be used to break the given view. The result
189 * should be a location just shy of the given advance. This
190 * differs from viewToModel which returns the closest
191 * position which might be proud of the maximum advance.
192 *
193 * @param v the view to find the model location to break at.
194 * @param p0 the location in the model where the
195 * fragment should start it's representation >= 0.
196 * @param x the graphic location along the axis that the
197 * broken view would occupy >= 0. This may be useful for
198 * things like tab calculations.
199 * @param len specifies the distance into the view
200 * where a potential break is desired >= 0.
201 * @return the maximum model location possible for a break.
202 * @see View#breakView
203 */
204 public int getBoundedPosition(GlyphView v, int p0, float x, float len) {
205 if( len < 0 )
206 throw new IllegalArgumentException("Length must be >= 0.");
207 // note: this only works because swing uses TextLayouts that are
208 // only pure rtl or pure ltr
209 TextHitInfo hit;
210 if (layout.isLeftToRight()) {
211 hit = layout.hitTestChar(len, 0);
212 } else {
213 hit = layout.hitTestChar(layout.getAdvance() - len, 0);
214 }
215 return v.getStartOffset() + hit.getCharIndex();
216 }
|