Java Code Examples for org.eclipse.swt.graphics.TextLayout#setOrientation()

The following examples show how to use org.eclipse.swt.graphics.TextLayout#setOrientation() . 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: XGridCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public TextLayout getTextLayout(GC gc, GridItem item, int columnIndex, boolean innerTagStyled, boolean drawInnerTag) {
	TextLayout layout = new TextLayout(gc.getDevice());
	layout.setFont(font);
	layout.setTabs(new int[]{tabWidth});
	innerTagFactory.reset();
	
	String displayStr = "";
	try{
		displayStr = InnerTagUtil.resolveTag(innerTagFactory.parseInnerTag(item.getText(columnIndex)));
	}catch (NullPointerException e) {
		return null;
	}
	layout.setText(displayStr);
	int width = getBounds().width - leftMargin - rightMargin;
	layout.setWidth(width < 1 ? 1 : width);
	layout.setSpacing(Constants.SEGMENT_LINE_SPACING);
	layout.setAlignment(SWT.LEFT);
	layout.setOrientation(item.getParent().getOrientation());
	if (displayStr.length() != 0 && innerTagStyled) {
		attachInnertTagStyle(gc, layout, drawInnerTag);
	}
	return layout;
}
 
Example 2
Source File: CellFigure.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected void drawBlankString( Graphics g, String s )
{
	TextLayout tl = new TextLayout( Display.getCurrent( ) );

	// bidi_hcg: Apply text direction
	tl.setOrientation( this.rtl ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT );
	
	tl.setText( s );
	Rectangle rc = tl.getBounds( );

	int left = ( getClientArea( ).width - rc.width ) / 2;
	int top = ( getClientArea( ).height - rc.height ) / 2;

	g.drawText( s, getClientArea( ).x + left, getClientArea( ).y + top );
	tl.dispose();
}
 
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: 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;
}