use of org.eclipse.swt.graphics.GlyphMetrics in project tesb-studio-se by Talend.
the class AnsiConsoleStyleListener method addRange.
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;
}
use of org.eclipse.swt.graphics.GlyphMetrics in project translationstudio8 by heartsome.
the class TextPainterWithPadding method getCellTextLayout.
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);
// 和 StyledTextEditor 同步
layout.setDescent(descent);
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;
}
use of org.eclipse.swt.graphics.GlyphMetrics in project translationstudio8 by heartsome.
the class InnerTagScanner method createTextStyle.
private TextStyle createTextStyle() {
TextStyle style = new TextStyle();
style.metrics = new GlyphMetrics(0, 0, 0);
return style;
}
use of org.eclipse.swt.graphics.GlyphMetrics in project eclipse.platform.text by eclipse.
the class InlinedAnnotationDrawingStrategy method updateStyle.
/**
* Returns the style to apply with GlyphMetrics ascent only if needed.
*
* @param annotation the line header annotation
* @param style the current style and null otherwise.
* @return the style to apply with GlyphMetrics ascent only if needed.
*/
static StyleRange updateStyle(LineHeaderAnnotation annotation, StyleRange style) {
int width = annotation.getRedrawnCharacterWidth();
if (width == 0) {
// Update GlyphMetrics only when mining was already drawn
return null;
}
int height = annotation.getHeight();
if (height == 0) {
return null;
}
int fullHeight = height + annotation.getRedrawnCharacterHeight();
if (style == null) {
style = new StyleRange();
Position position = annotation.getPosition();
style.start = position.getOffset();
style.length = 1;
}
GlyphMetrics metrics = style.metrics;
if (!annotation.isMarkedDeleted()) {
if (metrics == null) {
metrics = new GlyphMetrics(fullHeight, 0, width);
} else {
if (metrics.ascent == fullHeight) {
return null;
}
/**
* We must create a new GlyphMetrics instance because comparison with similarTo used
* later in StyledText#setStyleRange will compare the same (modified) and won't
* realize an update happened.
*/
metrics = new GlyphMetrics(fullHeight, 0, width);
}
} else {
metrics = null;
}
style.metrics = metrics;
return style;
}
use of org.eclipse.swt.graphics.GlyphMetrics in project eclipse.platform.swt by eclipse.
the class TextEditor method setBullet.
void setBullet(int type) {
Point selection = styledText.getSelection();
int lineStart = styledText.getLineAtOffset(selection.x);
int lineEnd = styledText.getLineAtOffset(selection.y);
StyleRange styleRange = new StyleRange();
styleRange.metrics = new GlyphMetrics(0, 0, BULLET_WIDTH);
Bullet bullet = new Bullet(type, styleRange);
bullet.text = ".";
for (int lineIndex = lineStart; lineIndex <= lineEnd; lineIndex++) {
Bullet oldBullet = styledText.getLineBullet(lineIndex);
styledText.setLineBullet(lineIndex, 1, oldBullet != null ? null : bullet);
}
}
Aggregations