|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2007 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2008 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 10-15
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.draw2d.text; |
11 |
package org.eclipse.draw2d.text; |
| 12 |
|
12 |
|
|
|
13 |
import java.util.List; |
| 14 |
|
| 13 |
import org.eclipse.swt.SWT; |
15 |
import org.eclipse.swt.SWT; |
| 14 |
import org.eclipse.swt.graphics.Color; |
16 |
import org.eclipse.swt.graphics.Color; |
| 15 |
import org.eclipse.swt.graphics.TextLayout; |
17 |
import org.eclipse.swt.graphics.TextLayout; |
|
Lines 23-29
Link Here
|
| 23 |
|
25 |
|
| 24 |
/** |
26 |
/** |
| 25 |
* An inline flow figure that renders a string of text across one or more lines. A |
27 |
* An inline flow figure that renders a string of text across one or more lines. A |
| 26 |
* TextFlow can not contain children. All <code>InlineFlow</code> figure's must be |
28 |
* TextFlow cannot contain children. All <code>InlineFlow</code> figure's must be |
| 27 |
* parented by a <code>FlowFigure</code>. |
29 |
* parented by a <code>FlowFigure</code>. |
| 28 |
* <p> |
30 |
* <p> |
| 29 |
* WARNING: This class is not intended to be subclassed by clients. |
31 |
* WARNING: This class is not intended to be subclassed by clients. |
|
Lines 126-131
Link Here
|
| 126 |
|
128 |
|
| 127 |
TextFragmentBox closestBox = null; |
129 |
TextFragmentBox closestBox = null; |
| 128 |
int index = 0; |
130 |
int index = 0; |
|
|
131 |
List fragments = getFragmentsWithoutBorder(); |
| 129 |
for (int i = fragments.size() - 1; i >= 0; i--) { |
132 |
for (int i = fragments.size() - 1; i >= 0; i--) { |
| 130 |
TextFragmentBox box = (TextFragmentBox)fragments.get(i); |
133 |
TextFragmentBox box = (TextFragmentBox)fragments.get(i); |
| 131 |
if (box.getBaseline() - box.getLineRoot().getAscent() > p.y |
134 |
if (box.getBaseline() - box.getLineRoot().getAscent() > p.y |
|
Lines 159-164
Link Here
|
| 159 |
|
162 |
|
| 160 |
TextFragmentBox closestBox = null; |
163 |
TextFragmentBox closestBox = null; |
| 161 |
int index = 0; |
164 |
int index = 0; |
|
|
165 |
List fragments = getFragmentsWithoutBorder(); |
| 162 |
for (int i = fragments.size() - 1; i >= 0; i--) { |
166 |
for (int i = fragments.size() - 1; i >= 0; i--) { |
| 163 |
TextFragmentBox box = (TextFragmentBox)fragments.get(i); |
167 |
TextFragmentBox box = (TextFragmentBox)fragments.get(i); |
| 164 |
if (box.getBaseline() + box.getLineRoot().getDescent() < p.y |
168 |
if (box.getBaseline() + box.getLineRoot().getDescent() < p.y |
|
Lines 209-215
Link Here
|
| 209 |
if (index == 0 && bidiInfo.leadingJoiner) |
213 |
if (index == 0 && bidiInfo.leadingJoiner) |
| 210 |
buffer.append(BidiChars.ZWJ); |
214 |
buffer.append(BidiChars.ZWJ); |
| 211 |
buffer.append(getText().substring(box.offset, box.offset + box.length)); |
215 |
buffer.append(getText().substring(box.offset, box.offset + box.length)); |
| 212 |
if (index == fragments.size() - 1 && bidiInfo.trailingJoiner) |
216 |
if (index == getFragmentsWithoutBorder().size() - 1 && bidiInfo.trailingJoiner) |
| 213 |
buffer.append(BidiChars.ZWJ); |
217 |
buffer.append(BidiChars.ZWJ); |
| 214 |
return buffer.toString(); |
218 |
return buffer.toString(); |
| 215 |
} |
219 |
} |
|
Lines 232-247
Link Here
|
| 232 |
if (offset == getText().length()) |
236 |
if (offset == getText().length()) |
| 233 |
trailing = false; |
237 |
trailing = false; |
| 234 |
|
238 |
|
|
|
239 |
List fragments = getFragmentsWithoutBorder(); |
| 235 |
int i = fragments.size(); |
240 |
int i = fragments.size(); |
| 236 |
int stop = 0; |
|
|
| 237 |
if (getBorder() instanceof FlowBorder) { |
| 238 |
i--; |
| 239 |
stop++; |
| 240 |
} |
| 241 |
TextFragmentBox box; |
241 |
TextFragmentBox box; |
| 242 |
do |
242 |
do |
| 243 |
box = (TextFragmentBox)fragments.get(--i); |
243 |
box = (TextFragmentBox)fragments.get(--i); |
| 244 |
while (offset < box.offset && i > stop); |
244 |
while (offset < box.offset && i > 0); |
| 245 |
|
245 |
|
| 246 |
// Cannot be trailing and after the last char, so go to first char in next box |
246 |
// Cannot be trailing and after the last char, so go to first char in next box |
| 247 |
if (trailing && box.offset + box.length <= offset) { |
247 |
if (trailing && box.offset + box.length <= offset) { |
|
Lines 294-299
Link Here
|
| 294 |
*/ |
294 |
*/ |
| 295 |
public int getFirstOffsetForLine(int baseline) { |
295 |
public int getFirstOffsetForLine(int baseline) { |
| 296 |
TextFragmentBox box; |
296 |
TextFragmentBox box; |
|
|
297 |
List fragments = getFragmentsWithoutBorder(); |
| 297 |
for (int i = 0; i < fragments.size(); i++) { |
298 |
for (int i = 0; i < fragments.size(); i++) { |
| 298 |
box = (TextFragmentBox)fragments.get(i); |
299 |
box = (TextFragmentBox)fragments.get(i); |
| 299 |
if (baseline == box.getBaseline()) |
300 |
if (baseline == box.getBaseline()) |
|
Lines 303-308
Link Here
|
| 303 |
} |
304 |
} |
| 304 |
|
305 |
|
| 305 |
/** |
306 |
/** |
|
|
307 |
* Returns the <code>TextFragmentBox</code> fragments contained in this TextFlow, not |
| 308 |
* including the border fragments. The returned list should not be modified. |
| 309 |
* @return list of fragments without the border fragments |
| 310 |
* @since 3.4 |
| 311 |
*/ |
| 312 |
protected List getFragmentsWithoutBorder() { |
| 313 |
List fragments = getFragments(); |
| 314 |
if (getBorder() != null) |
| 315 |
fragments = fragments.subList(1, fragments.size() - 1); |
| 316 |
return fragments; |
| 317 |
} |
| 318 |
|
| 319 |
/** |
| 306 |
* Returns the maximum offset for a character which is on the given baseline y-coordinate. |
320 |
* Returns the maximum offset for a character which is on the given baseline y-coordinate. |
| 307 |
* The y location should be relative to this figure. The return value will be between |
321 |
* The y location should be relative to this figure. The return value will be between |
| 308 |
* 0 and N-1. If no fragment is located on the baseline, <code>-1</code> is returned. |
322 |
* 0 and N-1. If no fragment is located on the baseline, <code>-1</code> is returned. |
|
Lines 312-317
Link Here
|
| 312 |
*/ |
326 |
*/ |
| 313 |
public int getLastOffsetForLine(int baseline) { |
327 |
public int getLastOffsetForLine(int baseline) { |
| 314 |
TextFragmentBox box; |
328 |
TextFragmentBox box; |
|
|
329 |
List fragments = getFragmentsWithoutBorder(); |
| 315 |
for (int i = fragments.size() - 1; i >= 0; i--) { |
330 |
for (int i = fragments.size() - 1; i >= 0; i--) { |
| 316 |
box = (TextFragmentBox)fragments.get(i); |
331 |
box = (TextFragmentBox)fragments.get(i); |
| 317 |
if (baseline == box.getBaseline()) |
332 |
if (baseline == box.getBaseline()) |
|
Lines 346-351
Link Here
|
| 346 |
*/ |
361 |
*/ |
| 347 |
public int getNextVisibleOffset(int offset) { |
362 |
public int getNextVisibleOffset(int offset) { |
| 348 |
TextFragmentBox box; |
363 |
TextFragmentBox box; |
|
|
364 |
List fragments = getFragmentsWithoutBorder(); |
| 349 |
for (int i = 0; i < fragments.size(); i++) { |
365 |
for (int i = 0; i < fragments.size(); i++) { |
| 350 |
box = (TextFragmentBox)fragments.get(i); |
366 |
box = (TextFragmentBox)fragments.get(i); |
| 351 |
if (box.offset + box.length <= offset) |
367 |
if (box.offset + box.length <= offset) |
|
Lines 425-430
Link Here
|
| 425 |
TextFragmentBox box; |
441 |
TextFragmentBox box; |
| 426 |
if (offset == -1) |
442 |
if (offset == -1) |
| 427 |
offset = Integer.MAX_VALUE; |
443 |
offset = Integer.MAX_VALUE; |
|
|
444 |
List fragments = getFragmentsWithoutBorder(); |
| 428 |
for (int i = fragments.size() - 1; i >= 0; i--) { |
445 |
for (int i = fragments.size() - 1; i >= 0; i--) { |
| 429 |
box = (TextFragmentBox)fragments.get(i); |
446 |
box = (TextFragmentBox)fragments.get(i); |
| 430 |
if (box.offset >= offset) |
447 |
if (box.offset >= offset) |
|
Lines 648-651
Link Here
|
| 648 |
protected TextUtilities getTextUtilities() { |
665 |
protected TextUtilities getTextUtilities() { |
| 649 |
return TextUtilities.INSTANCE; |
666 |
return TextUtilities.INSTANCE; |
| 650 |
} |
667 |
} |
|
|
668 |
|
| 651 |
} |
669 |
} |