use of org.eclipse.swt.custom.StyleRange in project eclipse.platform.text by eclipse.
the class DefaultHyperlinkPresenter method applyTextPresentation.
@Override
public void applyTextPresentation(TextPresentation textPresentation) {
if (fActiveRegion == null)
return;
IRegion region = textPresentation.getExtent();
if (fActiveRegion.getOffset() + fActiveRegion.getLength() >= region.getOffset() && region.getOffset() + region.getLength() > fActiveRegion.getOffset()) {
Color color = null;
if (!fIsUsingNativeLinkColor)
color = fColor;
StyleRange styleRange = new StyleRange(fActiveRegion.getOffset(), fActiveRegion.getLength(), color, null);
styleRange.underlineStyle = SWT.UNDERLINE_LINK;
styleRange.underline = true;
textPresentation.mergeStyleRange(styleRange);
}
}
use of org.eclipse.swt.custom.StyleRange in project eclipse.platform.text by eclipse.
the class HTML2TextReaderTest method verify.
/**
* @param input input
* @param expectedOutput expected output
* @param styleRangeCount count
* @throws IOException test failure
* @deprecated pass actual style ranges
*/
@Deprecated
private void verify(String input, String expectedOutput, int styleRangeCount) throws IOException {
Reader reader = new StringReader(input);
TextPresentation textPresentation = new TextPresentation();
String result;
try (HTML2TextReader htmlReader = new HTML2TextReader(reader, textPresentation)) {
result = htmlReader.getString();
}
if (DEBUG)
System.out.println("<" + result + "/>");
assertEquals(expectedOutput, result);
Iterator<StyleRange> styleRangeIterator = textPresentation.getAllStyleRangeIterator();
List<StyleRange> ranges = new ArrayList<>();
while (styleRangeIterator.hasNext()) {
ranges.add(styleRangeIterator.next());
}
assertEquals("Incorrect number of style ranges", styleRangeCount, ranges.size());
Collections.sort(ranges, (r1, r2) -> r1.start - r2.start);
for (int i = 0; i < ranges.size() - 1; i++) {
StyleRange range1 = ranges.get(i);
StyleRange range2 = ranges.get(i + 1);
if (range1.start + range1.length > range2.start) {
assertTrue("StyleRanges overlap", false);
}
}
}
use of org.eclipse.swt.custom.StyleRange in project eclipse.platform.text by eclipse.
the class HTML2TextReaderTest method testStylesWithPre.
@Test
public void testStylesWithPre() throws IOException {
String string = "I am <b>bold</b>." + LD + "<p>" + LD + "<pre>One" + LD + LD + "<b>T</b>hree.</pre>" + LD + "<p>" + LD + "<b>Author:</b> me.";
String expected = "I am bold. " + LD + "One" + LD + LD + "Three. " + LD + "Author: me.";
StyleRange[] ranges = { new StyleRange(5, 4, null, null, SWT.BOLD), new StyleRange(14 + 3 * LD.length(), 1, null, null, SWT.BOLD), new StyleRange(21 + 4 * LD.length(), 7, null, null, SWT.BOLD) };
verify(string, expected, ranges);
}
use of org.eclipse.swt.custom.StyleRange in project eclipse.platform.text by eclipse.
the class HTML2TextReaderTest method testCombineBoldItalicStriker.
@Test
public void testCombineBoldItalicStriker() throws IOException {
String string = "<strong>strong</strong>,<em>italic</em>,<s>strike</s>," + "<strong><em>strongItalic</em></strong>,<s><strong>strongStrike</strong></s>," + "<em><s>italicStrike</s></em>," + "<em><strong><s>strongItalicStrike</s></strong></em>," + "none";
String expected = "strong,italic,strike,strongItalic,strongStrike,italicStrike,strongItalicStrike,none";
StyleRange[] ranges = { new StyleRange(0, 6, null, null, SWT.BOLD), new StyleRange(7, 6, null, null, SWT.ITALIC), strike(new StyleRange(14, 6, null, null)), new StyleRange(21, 12, null, null, SWT.BOLD | SWT.ITALIC), strike(new StyleRange(34, 12, null, null, SWT.BOLD)), strike(new StyleRange(47, 12, null, null, SWT.ITALIC)), strike(new StyleRange(60, 18, null, null, SWT.BOLD | SWT.ITALIC)) };
verify(string, expected, ranges);
}
use of org.eclipse.swt.custom.StyleRange in project eclipse.platform.text by eclipse.
the class TextPresentationTest method testMergeStyleRange5.
/**
* Merge range at end of existing default range.
*/
@Test
public void testMergeStyleRange5() {
StyleRange range = createStyleRange(45, 47, 1, -1, NORMAL);
fTextPresentation.mergeStyleRange(range);
StyleRange[] expectedAllRanges = new StyleRange[] { createStyleRange(0, 4, NORMAL), createStyleRange(4, 20, BOLD), createStyleRange(20, 45, NORMAL), createStyleRange(45, 47, 1, -1, NORMAL), createStyleRange(47, 54, BOLD), createStyleRange(54, 96, NORMAL), createStyleRange(96, 102, BOLD), createStyleRange(102, 140, NORMAL) };
StyleRange[] expectedNonDefaultRanges = new StyleRange[] { createStyleRange(4, 20, BOLD), createStyleRange(45, 47, 1, -1, NORMAL), createStyleRange(47, 54, BOLD), createStyleRange(96, 102, BOLD) };
checkRegions(expectedAllRanges, expectedNonDefaultRanges);
}
Aggregations