use of org.eclipse.swt.graphics.FontData in project eclipse.platform.swt by eclipse.
the class PaintExample method initActions.
/**
* Sets the action field of the tools
*/
private void initActions() {
for (Tool tool2 : tools) {
final Tool tool = tool2;
String group = tool.group;
if (group.equals("tool")) {
tool.action = () -> setPaintTool(tool.id);
} else if (group.equals("fill")) {
tool.action = () -> setFillType(tool.id);
} else if (group.equals("linestyle")) {
tool.action = () -> setLineStyle(tool.id);
} else if (group.equals("options")) {
tool.action = () -> {
FontDialog fontDialog = new FontDialog(paintSurface.getShell(), SWT.PRIMARY_MODAL);
FontData[] fontDatum = toolSettings.commonFont.getFontData();
if (fontDatum != null && fontDatum.length > 0) {
fontDialog.setFontList(fontDatum);
}
fontDialog.setText(getResourceString("options.Font.dialog.title"));
paintSurface.hideRubberband();
FontData fontData = fontDialog.open();
paintSurface.showRubberband();
if (fontData != null) {
try {
Font font = new Font(mainComposite.getDisplay(), fontData);
toolSettings.commonFont = font;
updateToolSettings();
} catch (SWTException ex) {
}
}
};
}
}
}
use of org.eclipse.swt.graphics.FontData in project eclipse.platform.swt by eclipse.
the class TextEditor method updateToolBar.
void updateToolBar() {
styleState = 0;
link = null;
boolean bold = false, italic = false;
Font font = null;
int offset = styledText.getCaretOffset();
StyleRange range = offset > 0 ? styledText.getStyleRangeAtOffset(offset - 1) : null;
if (range != null) {
if (range.font != null) {
font = range.font;
FontData[] fds = font.getFontData();
for (FontData fd : fds) {
int fontStyle = fd.getStyle();
if (!bold && (fontStyle & SWT.BOLD) != 0)
bold = true;
if (!italic && (fontStyle & SWT.ITALIC) != 0)
italic = true;
}
} else {
bold = (range.fontStyle & SWT.BOLD) != 0;
italic = (range.fontStyle & SWT.ITALIC) != 0;
}
if (range.foreground != null) {
styleState |= FOREGROUND;
if (textForeground != range.foreground) {
disposeResource(textForeground);
textForeground = range.foreground;
}
}
if (range.background != null) {
styleState |= BACKGROUND;
if (textBackground != range.background) {
disposeResource(textBackground);
textBackground = range.background;
}
}
if (range.underline) {
switch(range.underlineStyle) {
case SWT.UNDERLINE_SINGLE:
styleState |= UNDERLINE_SINGLE;
break;
case SWT.UNDERLINE_DOUBLE:
styleState |= UNDERLINE_DOUBLE;
break;
case SWT.UNDERLINE_SQUIGGLE:
styleState |= UNDERLINE_SQUIGGLE;
break;
case SWT.UNDERLINE_ERROR:
styleState |= UNDERLINE_ERROR;
break;
case SWT.UNDERLINE_LINK:
styleState |= UNDERLINE_LINK;
link = (String) range.data;
break;
}
if (range.underlineStyle != SWT.UNDERLINE_LINK) {
underlineSingleItem.setSelection((styleState & UNDERLINE_SINGLE) != 0);
underlineDoubleItem.setSelection((styleState & UNDERLINE_DOUBLE) != 0);
underlineErrorItem.setSelection((styleState & UNDERLINE_ERROR) != 0);
underlineSquiggleItem.setSelection((styleState & UNDERLINE_SQUIGGLE) != 0);
disposeResource(underlineColor);
underlineColor = range.underlineColor;
}
}
if (range.strikeout) {
styleState |= STRIKEOUT;
disposeResource(strikeoutColor);
strikeoutColor = range.strikeoutColor;
}
if (range.borderStyle != SWT.NONE) {
switch(range.borderStyle) {
case SWT.BORDER_SOLID:
styleState |= BORDER_SOLID;
break;
case SWT.BORDER_DASH:
styleState |= BORDER_DASH;
break;
case SWT.BORDER_DOT:
styleState |= BORDER_DOT;
break;
}
borderSolidItem.setSelection((styleState & BORDER_SOLID) != 0);
borderDashItem.setSelection((styleState & BORDER_DASH) != 0);
borderDotItem.setSelection((styleState & BORDER_DOT) != 0);
disposeResource(borderColor);
borderColor = range.borderColor;
}
}
boldControl.setSelection(bold);
italicControl.setSelection(italic);
FontData fontData = font != null ? font.getFontData()[0] : styledText.getFont().getFontData()[0];
int index = 0;
int count = fontNameControl.getItemCount();
String fontName = fontData.getName();
while (index < count) {
if (fontNameControl.getItem(index).equals(fontName)) {
fontNameControl.select(index);
break;
}
index++;
}
index = 0;
count = fontSizeControl.getItemCount();
int fontSize = fontData.getHeight();
while (index < count) {
int size = Integer.parseInt(fontSizeControl.getItem(index));
if (fontSize == size) {
fontSizeControl.select(index);
break;
}
if (size > fontSize) {
fontSizeControl.add(String.valueOf(fontSize), index);
fontSizeControl.select(index);
break;
}
index++;
}
disposeResource(textFont);
textFont = font;
int lineIndex = styledText.getLineAtOffset(offset);
int alignment = styledText.getLineAlignment(lineIndex);
leftAlignmentItem.setSelection((alignment & SWT.LEFT) != 0);
centerAlignmentItem.setSelection((alignment & SWT.CENTER) != 0);
rightAlignmentItem.setSelection((alignment & SWT.RIGHT) != 0);
boolean justify = styledText.getLineJustify(lineIndex);
justifyAlignmentItem.setSelection(justify);
}
use of org.eclipse.swt.graphics.FontData in project eclipse.platform.swt by eclipse.
the class TextEditor method getFontNames.
String[] getFontNames() {
FontData[] fontNames = display.getFontList(null, true);
String[] names = new String[fontNames.length];
int count = 0;
mainfor: for (int i = 0; i < fontNames.length; i++) {
String fontName = fontNames[i].getName();
if (// $NON-NLS-1$
fontName.startsWith("@"))
continue;
for (int j = 0; j < count; j++) {
if (names[j].equals(fontName))
continue mainfor;
}
names[count++] = fontName;
}
if (count < names.length) {
String[] newNames = new String[count];
System.arraycopy(names, 0, newNames, 0, count);
names = newNames;
}
return names;
}
use of org.eclipse.swt.graphics.FontData in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_custom_StyledText method test_setFontLorg_eclipse_swt_graphics_Font.
@Override
@Test
public void test_setFontLorg_eclipse_swt_graphics_Font() {
FontData fontData = text.getFont().getFontData()[0];
int lineHeight;
Font font;
font = new Font(text.getDisplay(), fontData.getName(), 20, fontData.getStyle());
text.setFont(font);
lineHeight = text.getLineHeight();
text.setFont(null);
font.dispose();
font = new Font(text.getDisplay(), fontData.getName(), 25, fontData.getStyle());
text.setFont(font);
assertTrue(":a:", text.getLineHeight() > lineHeight && font.equals(text.getFont()));
text.setFont(null);
font.dispose();
}
use of org.eclipse.swt.graphics.FontData in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_custom_StyledText_VariableLineHeight method testFont.
@Test
public void testFont() {
styledText.setText("a\nb\nc\nd");
// Create little, big font
Font initialFont = styledText.getFont();
FontData[] fontData = initialFont.getFontData();
for (int i = 0; i < fontData.length; i++) {
fontData[i].setHeight(24);
}
Font bigFont = new Font(styledText.getDisplay(), fontData);
fontData = initialFont.getFontData();
for (int i = 0; i < fontData.length; i++) {
fontData[i].setHeight(fontData[i].getHeight() - 1);
}
Font littleFont = new Font(styledText.getDisplay(), fontData);
int length = styledText.getCharCount();
// No style
assertVariableLineHeightEquals(0, 0);
// style with big font
StyleRange style = new StyleRange();
style.start = 0;
style.length = length;
style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
style.font = bigFont;
styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
assertVariableLineHeightEquals(0, 0, bigFont);
// style with no font
style = new StyleRange();
style.start = 0;
style.length = length;
style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
style.font = null;
styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
assertVariableLineHeightEquals(0, 0);
// style with big font
style = new StyleRange();
style.start = 0;
style.length = length;
style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
style.font = bigFont;
styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
assertVariableLineHeightEquals(0, 0, bigFont);
// style with little font
style = new StyleRange();
style.start = 0;
style.length = length;
style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
style.font = littleFont;
styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
assertVariableLineHeightEquals(0, 0);
// style with no font
style = new StyleRange();
style.start = 0;
style.length = length;
style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
style.font = null;
styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
assertVariableLineHeightEquals(0, 0);
// style with little font
style = new StyleRange();
style.start = 0;
style.length = length;
style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
style.font = littleFont;
styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
assertVariableLineHeightEquals(0, 0);
bigFont.dispose();
littleFont.dispose();
}
Aggregations