org.eclipse.swt.graphics.GlyphMetrics Java Examples

The following examples show how to use org.eclipse.swt.graphics.GlyphMetrics. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BulletListBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void configureStyledText(String text, boolean enabled) {
	if (fStyledText == null)
		return;

	fStyledText.setText(text);
	int count= fStyledText.getCharCount();
	if (count == 0)
		return;

	Color foreground= enabled ? null : Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY);

	fStyledText.setStyleRange(new StyleRange(0, count, foreground, null));

	StyleRange styleRange= new StyleRange(0, count, foreground, null);
	styleRange.metrics= new GlyphMetrics(0, 0, 20);
	fStyledText.setLineBullet(0, fStyledText.getLineCount(), new Bullet(styleRange));

	fStyledText.setEnabled(enabled);
}
 
Example #2
Source File: XStyledString.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public void append(Image im) {
    StyleRange sr = mkSRange(" ", null, SWT.NORMAL);
    sr.data = im;
    Rectangle rect = im.getBounds();
    sr.metrics = new GlyphMetrics(rect.height, 0, rect.width);
    sb.append(" ");
    srarr.add(sr);
}
 
Example #3
Source File: TextPainterWithPadding.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
private TextLayout getCellTextLayout(LayerCell cell) {
	int orientation = editor.getTable().getStyle() & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
	TextLayout layout = new TextLayout(editor.getTable().getDisplay());
	layout.setOrientation(orientation);
	layout.setSpacing(Constants.SEGMENT_LINE_SPACING);
	layout.setFont(font);
	layout.setAscent(ascent);
	layout.setDescent(descent); // 和 StyledTextEditor 同步
	layout.setTabs(new int[] { tabWidth });

	Rectangle rectangle = cell.getBounds();
	int width = rectangle.width - leftPadding - rightPadding;
	width -= 1;
	if (wrapText && width > 0) {
		layout.setWidth(width);
	}

	String displayText = InnerTagUtil.resolveTag(innerTagFactory.parseInnerTag((String) cell.getDataValue()));
	if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
		displayText = displayText.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
		displayText = displayText.replaceAll("\\t", Constants.TAB_CHARACTER + "\u200B");
		displayText = displayText.replaceAll(" ", Constants.SPACE_CHARACTER + "\u200B");
	}
	layout.setText(displayText);
	List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
	for (InnerTagBean innerTagBean : innerTagBeans) {
		String placeHolder = placeHolderBuilder.getPlaceHolder(innerTagBeans, innerTagBeans.indexOf(innerTagBean));
		int start = displayText.indexOf(placeHolder);
		if (start == -1) {
			continue;
		}
		TextStyle style = new TextStyle();
		Point rect = tagRender.calculateTagSize(innerTagBean);
		style.metrics = new GlyphMetrics(rect.y, 0, rect.x + SEGMENT_LINE_SPACING * 2);
		layout.setStyle(style, start, start + placeHolder.length() - 1);
	}

	return layout;
}
 
Example #4
Source File: PresentationRepairer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds style information to the given text presentation.
 * @param presentation
 *            the text presentation to be extended
 * @param offset
 *            the offset of the range to be styled
 * @param length
 *            the length of the range to be styled
 * @param textStyle
 *            the style of the range to be styled
 */
protected void addRange(TextPresentation presentation, int offset, int length, TextStyle textStyle) {
	if (textStyle != null) {

		if (textStyle.metrics != null && length >= 1) {
			for (int i = offset; i < offset + length; i++) {
				try {
					StyleRange styleRange = new StyleRange(textStyle);
					String placeHolder = fDocument.get(i, 1);
					InnerTag innerTag = InnerTagUtil.getInnerTag(fViewer.getInnerTagCacheList(), placeHolder);
					if (innerTag != null) {
						Point rect = innerTag.computeSize(SWT.DEFAULT, SWT.DEFAULT);
						// int ascent = 4 * rect.height / 5 + SEGMENT_LINE_SPACING / 2;
						// int descent = rect.height - ascent + SEGMENT_LINE_SPACING;
						styleRange.metrics = new GlyphMetrics(rect.y, 0, rect.x + SEGMENT_LINE_SPACING * 2);
					}
					styleRange.start = i;
					styleRange.length = 1;
					presentation.addStyleRange(styleRange);
				} catch (BadLocationException e) {
					e.printStackTrace();
				}
			}
		} /*
		 * else { StyleRange styleRange = new StyleRange(textStyle); styleRange.start = offset; styleRange.length =
		 * length; presentation.addStyleRange(styleRange); }
		 */
	}
}
 
Example #5
Source File: AnsiConsoleStyleListener.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
private void addRange(List<StyleRange> ranges, int start, int length, Color foreground, boolean isCode) {
    StyleRange range = new StyleRange(start, length, foreground, null);
    AnsiConsoleAttributes.updateRangeStyle(range, lastAttributes);
    if (isCode) {
        range.metrics = new GlyphMetrics(0, 0, 0);
    }
    ranges.add(range);
    lastRangeEnd = lastRangeEnd + range.length;
}
 
Example #6
Source File: TextPainterWithPadding.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
private TextLayout getCellTextLayout(LayerCell cell) {
	int orientation = editor.getTable().getStyle() & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
	TextLayout layout = new TextLayout(editor.getTable().getDisplay());
	layout.setOrientation(orientation);
	layout.setSpacing(Constants.SEGMENT_LINE_SPACING);
	layout.setFont(font);
	layout.setAscent(ascent);
	layout.setDescent(descent); // 和 StyledTextEditor 同步
	layout.setTabs(new int[] { tabWidth });

	Rectangle rectangle = cell.getBounds();
	int width = rectangle.width - leftPadding - rightPadding;
	width -= 1;
	if (wrapText && width > 0) {
		layout.setWidth(width);
	}

	String displayText = InnerTagUtil.resolveTag(innerTagFactory.parseInnerTag((String) cell.getDataValue()));
	if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
		displayText = displayText.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
		displayText = displayText.replaceAll("\\t", Constants.TAB_CHARACTER + "");
		displayText = displayText.replaceAll(" ", Constants.SPACE_CHARACTER + "");
	}
	layout.setText(displayText);
	List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
	for (InnerTagBean innerTagBean : innerTagBeans) {
		String placeHolder = placeHolderBuilder.getPlaceHolder(innerTagBeans, innerTagBeans.indexOf(innerTagBean));
		int start = displayText.indexOf(placeHolder);
		if (start == -1) {
			continue;
		}
		TextStyle style = new TextStyle();
		Point rect = tagRender.calculateTagSize(innerTagBean);
		style.metrics = new GlyphMetrics(rect.y, 0, rect.x + SEGMENT_LINE_SPACING * 2);
		layout.setStyle(style, start, start + placeHolder.length() - 1);
	}

	return layout;
}
 
Example #7
Source File: InnerTagScanner.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
private TextStyle createTextStyle() {
	TextStyle style = new TextStyle();
	style.metrics = new GlyphMetrics(0, 0, 0);
	return style;
}
 
Example #8
Source File: InnerTagScanner.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
private TextStyle createTextStyle() {
	TextStyle style = new TextStyle();
	style.metrics = new GlyphMetrics(0, 0, 0);
	return style;
}
 
Example #9
Source File: InnerTagScanner.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
private TextStyle createTextStyle() {
	TextStyle style = new TextStyle();
	style.metrics = new GlyphMetrics(0, 0, 0);
	return style;
}