1 /*
2 * Copyright (c) 1999, 2014, 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
181 int retValue = p0 + offs;
182 if(retValue == p1) {
183 // No need to return backward bias as GlyphPainter1 is used for
184 // ltr text only.
185 retValue--;
186 }
187 biasReturn[0] = Position.Bias.Forward;
188 return retValue;
189 }
190
191 /**
192 * Determines the best location (in the model) to break
193 * the given view.
194 * This method attempts to break on a whitespace
195 * location. If a whitespace location can't be found, the
196 * nearest character location is returned.
197 *
198 * @param v the view
199 * @param p0 the location in the model where the
200 * fragment should start its representation >= 0
201 * @param pos the graphic location along the axis that the
202 * broken view would occupy >= 0; this may be useful for
203 * things like tab calculations
204 * @param len specifies the distance into the view
205 * where a potential break is desired >= 0
206 * @return the model location desired for a break
207 * @see View#breakView
208 */
209 public int getBoundedPosition(GlyphView v, int p0, float x, float len) {
210 sync(v);
211 TabExpander expander = v.getTabExpander();
212 Segment s = v.getText(p0, v.getEndOffset());
213 int[] justificationData = getJustificationData(v);
214 int index = Utilities.getTabbedTextOffset(v, s, metrics, x, (x+len),
215 expander, p0, false,
216 justificationData, true);
217 SegmentCache.releaseSharedSegment(s);
218 int p1 = p0 + index;
219 return p1;
220 }
221
|
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
181 int retValue = p0 + offs;
182 if(retValue == p1) {
183 // No need to return backward bias as GlyphPainter1 is used for
184 // ltr text only.
185 retValue--;
186 }
187 biasReturn[0] = Position.Bias.Forward;
188 return retValue;
189 }
190
191 /**
192 * Determines the best location (in the model) to break
193 * the given view.
194 * This method attempts to break on a whitespace
195 * location. If a whitespace location can't be found, the
196 * nearest character location is returned.
197 *
198 * @param v the view
199 * @param p0 the location in the model where the
200 * fragment should start its representation >= 0
201 * @param x the graphic location along the axis that the
202 * broken view would occupy >= 0; this may be useful for
203 * things like tab calculations
204 * @param len specifies the distance into the view
205 * where a potential break is desired >= 0
206 * @return the model location desired for a break
207 * @see View#breakView
208 */
209 public int getBoundedPosition(GlyphView v, int p0, float x, float len) {
210 sync(v);
211 TabExpander expander = v.getTabExpander();
212 Segment s = v.getText(p0, v.getEndOffset());
213 int[] justificationData = getJustificationData(v);
214 int index = Utilities.getTabbedTextOffset(v, s, metrics, x, (x+len),
215 expander, p0, false,
216 justificationData, true);
217 SegmentCache.releaseSharedSegment(s);
218 int p1 = p0 + index;
219 return p1;
220 }
221
|