use of org.eclipse.swt.graphics.GlyphMetrics in project eclipse.platform.swt by eclipse.
the class TextEditor method addImage.
void addImage(Image image) {
int offset = styledText.getCaretOffset();
// $NON-NLS-1$
styledText.replaceTextRange(offset, 0, "\uFFFC");
StyleRange style = new StyleRange();
Rectangle rect = image.getBounds();
style.metrics = new GlyphMetrics(rect.height, 0, rect.width);
style.data = image;
int[] ranges = { offset, 1 };
StyleRange[] styles = { style };
styledText.setStyleRanges(0, 0, ranges, styles);
}
use of org.eclipse.swt.graphics.GlyphMetrics in project translationstudio8 by heartsome.
the class PresentationRepairer method addRange.
/**
* 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); }
*/
}
}
use of org.eclipse.swt.graphics.GlyphMetrics in project translationstudio8 by heartsome.
the class XGridCellRenderer method attachInnertTagStyle.
protected void attachInnertTagStyle(GC gc, TextLayout layout, boolean drawInnerTag) {
String displayStr = layout.getText();
List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
Rectangle bounds = getBounds();
for (InnerTagBean innerTagBean : innerTagBeans) {
String placeHolder = placeHolderBuilder.getPlaceHolder(innerTagBeans, innerTagBeans.indexOf(innerTagBean));
int start = displayStr.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);
if (drawInnerTag && gc != null) {
Point p = layout.getLocation(start, false);
int x = bounds.x + p.x + leftMargin;
x += SEGMENT_LINE_SPACING;
Point tagSize = tagRender.calculateTagSize(innerTagBean);
int lineIdx = layout.getLineIndex(start);
Rectangle r = layout.getLineBounds(lineIdx);
int y = bounds.y + p.y + topMargin + r.height / 2 - tagSize.y / 2;
tagRender.draw(gc, innerTagBean, x, y - layout.getAscent());
}
}
}
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 width only if needed.
*
* @param annotation the line content annotation
* @param style the current style and null otherwise.
* @return the style to apply with GlyphMetrics width only if needed.
*/
static StyleRange updateStyle(LineContentAnnotation annotation, StyleRange style) {
int width = annotation.getWidth();
if (width == 0) {
return null;
}
int fullWidth = width + annotation.getRedrawnCharacterWidth();
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(0, 0, fullWidth);
} else {
if (metrics.width == fullWidth) {
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(0, 0, fullWidth);
}
} 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 addControl.
void addControl(Control control) {
int offset = styledText.getCaretOffset();
// $NON-NLS-1$
styledText.replaceTextRange(offset, 0, "\uFFFC");
StyleRange style = new StyleRange();
Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
int ascent = 2 * size.y / 3;
int descent = size.y - ascent;
style.metrics = new GlyphMetrics(ascent + MARGIN, descent + MARGIN, size.x + 2 * MARGIN);
style.data = control;
int[] ranges = { offset, 1 };
StyleRange[] styles = { style };
styledText.setStyleRanges(0, 0, ranges, styles);
control.setSize(size);
}
Aggregations