Search in sources :

Example 1 with GlyphMetrics

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;
}
Also used : GlyphMetrics(org.eclipse.swt.graphics.GlyphMetrics) StyleRange(org.eclipse.swt.custom.StyleRange)

Example 2 with GlyphMetrics

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;
}
Also used : TextStyle(org.eclipse.swt.graphics.TextStyle) GlyphMetrics(org.eclipse.swt.graphics.GlyphMetrics) Rectangle(org.eclipse.swt.graphics.Rectangle) InnerTagBean(net.heartsome.cat.common.innertag.InnerTagBean) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 3 with GlyphMetrics

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;
}
Also used : TextStyle(org.eclipse.swt.graphics.TextStyle) GlyphMetrics(org.eclipse.swt.graphics.GlyphMetrics)

Example 4 with GlyphMetrics

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;
}
Also used : Position(org.eclipse.jface.text.Position) GlyphMetrics(org.eclipse.swt.graphics.GlyphMetrics) StyleRange(org.eclipse.swt.custom.StyleRange) Point(org.eclipse.swt.graphics.Point)

Example 5 with GlyphMetrics

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);
    }
}
Also used : Bullet(org.eclipse.swt.custom.Bullet) GlyphMetrics(org.eclipse.swt.graphics.GlyphMetrics) StyleRange(org.eclipse.swt.custom.StyleRange) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Aggregations

GlyphMetrics (org.eclipse.swt.graphics.GlyphMetrics)13 StyleRange (org.eclipse.swt.custom.StyleRange)10 Point (org.eclipse.swt.graphics.Point)8 Rectangle (org.eclipse.swt.graphics.Rectangle)3 TextStyle (org.eclipse.swt.graphics.TextStyle)3 InnerTagBean (net.heartsome.cat.common.innertag.InnerTagBean)2 Position (org.eclipse.jface.text.Position)2 Bullet (org.eclipse.swt.custom.Bullet)2 InnerTag (net.heartsome.cat.common.ui.innertag.InnerTag)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 TextLayout (org.eclipse.swt.graphics.TextLayout)1 Test (org.junit.Test)1