use of org.eclipse.swt.graphics.Font in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_custom_StyledText_VariableLineHeight method testBigFontSeveralRanges.
@Test
public void testBigFontSeveralRanges() {
styledText.setText("abc\nd");
// Create little, big font
Font initialFont = styledText.getFont();
FontData[] fontData = initialFont.getFontData();
for (int i = 0; i < fontData.length; i++) {
fontData[i].setHeight(fontData[i].getHeight() * 2);
}
Font bigFont = new Font(styledText.getDisplay(), fontData);
fontData = initialFont.getFontData();
for (int i = 0; i < fontData.length; i++) {
fontData[i].setHeight(fontData[i].getHeight() / 2);
}
Font littleFont = new Font(styledText.getDisplay(), fontData);
StyleRange[] ranges = new StyleRange[2];
ranges[0] = new StyleRange();
ranges[0].start = 0;
ranges[0].length = 1;
ranges[0].font = bigFont;
ranges[1] = new StyleRange();
ranges[1].start = 1;
ranges[1].length = 1;
ranges[1].font = littleFont;
styledText.replaceStyleRanges(0, 3, ranges);
// line height is the height of the big font
assertVariableLineHeightEquals(0, 0, bigFont);
bigFont.dispose();
littleFont.dispose();
}
use of org.eclipse.swt.graphics.Font in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_custom_StyledText_VariableLineHeight method testLittleFontSeveralRanges.
@Test
public void testLittleFontSeveralRanges() {
styledText.setText("abc\nd");
// Create little, big font
Font initialFont = styledText.getFont();
FontData[] fontData = initialFont.getFontData();
for (int i = 0; i < fontData.length; i++) {
fontData[i].setHeight(fontData[i].getHeight() / 2);
}
Font littleFont1 = new Font(styledText.getDisplay(), fontData);
fontData = initialFont.getFontData();
for (int i = 0; i < fontData.length; i++) {
fontData[i].setHeight(fontData[i].getHeight() / 4);
}
Font littleFont2 = new Font(styledText.getDisplay(), fontData);
StyleRange[] ranges = new StyleRange[2];
ranges[0] = new StyleRange();
ranges[0].start = 0;
ranges[0].length = 1;
ranges[0].font = littleFont1;
ranges[1] = new StyleRange();
ranges[1].start = 1;
ranges[1].length = 1;
ranges[1].font = littleFont2;
styledText.replaceStyleRanges(0, 3, ranges);
// 2 little fonts, line height is the height of the default font of StyledText
assertVariableLineHeightEquals(0, 0);
littleFont1.dispose();
littleFont2.dispose();
}
use of org.eclipse.swt.graphics.Font in project eclipse.platform.swt by eclipse.
the class CTableItem method setFont.
/**
* Sets the font that the receiver will use to paint textual information
* for the specified cell in this item to the font specified by the
* argument, or to the default font for that kind of control if the
* argument is null.
*
* @param index the column index
* @param font the new font (or null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 3.0
*/
public void setFont(int columnIndex, Font font) {
checkWidget();
if (font != null && font.isDisposed()) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
int validColumnCount = Math.max(1, parent.columns.length);
if (!(0 <= columnIndex && columnIndex < validColumnCount))
return;
if (cellFonts == null) {
if (font == null)
return;
cellFonts = new Font[validColumnCount];
}
Font oldFont = cellFonts[columnIndex];
if (oldFont == font)
return;
cellFonts[columnIndex] = font;
if (oldFont != null && oldFont.equals(font))
return;
if ((parent.getStyle() & SWT.VIRTUAL) != 0)
cached = true;
/* recompute cached values for string measurements */
GC gc = new GC(parent);
gc.setFont(getFont(columnIndex, false));
if (fontHeights == null)
fontHeights = new int[validColumnCount];
fontHeights[columnIndex] = gc.getFontMetrics().getHeight();
computeDisplayText(columnIndex, gc);
gc.dispose();
if (isInViewport()) {
Rectangle bounds = getCellBounds(columnIndex);
parent.redraw(bounds.x, bounds.y, bounds.width, bounds.height, false);
}
}
use of org.eclipse.swt.graphics.Font in project eclipse.platform.swt by eclipse.
the class CTableItem method addColumn.
/*
* Updates internal structures in the receiver and its child items to handle the creation of a new column.
*/
void addColumn(CTableColumn column) {
int index = column.getIndex();
int columnCount = parent.columns.length;
if (columnCount > 1) {
if (columnCount == 2) {
texts = new String[2];
} else {
String[] newTexts = new String[columnCount];
System.arraycopy(texts, 0, newTexts, 0, index);
System.arraycopy(texts, index, newTexts, index + 1, columnCount - index - 1);
texts = newTexts;
}
if (index == 0) {
texts[1] = super.getText();
// $NON-NLS-1$
super.setText("");
}
if (columnCount == 2) {
images = new Image[2];
} else {
Image[] newImages = new Image[columnCount];
System.arraycopy(images, 0, newImages, 0, index);
System.arraycopy(images, index, newImages, index + 1, columnCount - index - 1);
images = newImages;
}
if (index == 0) {
images[1] = super.getImage();
super.setImage(null);
}
int[] newTextWidths = new int[columnCount];
System.arraycopy(textWidths, 0, newTextWidths, 0, index);
System.arraycopy(textWidths, index, newTextWidths, index + 1, columnCount - index - 1);
textWidths = newTextWidths;
} else {
customWidth = -1;
/* columnCount == 1 */
}
/*
* The length of displayTexts always matches the parent's column count, unless this
* count is zero, in which case displayTexts is null.
*/
String[] newDisplayTexts = new String[columnCount];
if (columnCount > 1) {
System.arraycopy(displayTexts, 0, newDisplayTexts, 0, index);
System.arraycopy(displayTexts, index, newDisplayTexts, index + 1, columnCount - index - 1);
}
displayTexts = newDisplayTexts;
if (cellBackgrounds != null) {
Color[] newCellBackgrounds = new Color[columnCount];
System.arraycopy(cellBackgrounds, 0, newCellBackgrounds, 0, index);
System.arraycopy(cellBackgrounds, index, newCellBackgrounds, index + 1, columnCount - index - 1);
cellBackgrounds = newCellBackgrounds;
}
if (cellForegrounds != null) {
Color[] newCellForegrounds = new Color[columnCount];
System.arraycopy(cellForegrounds, 0, newCellForegrounds, 0, index);
System.arraycopy(cellForegrounds, index, newCellForegrounds, index + 1, columnCount - index - 1);
cellForegrounds = newCellForegrounds;
}
if (cellFonts != null) {
Font[] newCellFonts = new Font[columnCount];
System.arraycopy(cellFonts, 0, newCellFonts, 0, index);
System.arraycopy(cellFonts, index, newCellFonts, index + 1, columnCount - index - 1);
cellFonts = newCellFonts;
int[] newFontHeights = new int[columnCount];
System.arraycopy(fontHeights, 0, newFontHeights, 0, index);
System.arraycopy(fontHeights, index, newFontHeights, index + 1, columnCount - index - 1);
fontHeights = newFontHeights;
}
if (columnCount > accessibles.length) {
Accessible[] newAccessibles = new Accessible[columnCount];
System.arraycopy(accessibles, 0, newAccessibles, 0, index);
System.arraycopy(accessibles, index, newAccessibles, index + 1, columnCount - index - 1);
accessibles = newAccessibles;
}
if (index == 0 && columnCount > 1) {
/*
* The new second column may have more width available to it than it did when it was
* the first column if checkboxes are being shown, so recompute its displayText if needed.
*/
if ((parent.getStyle() & SWT.CHECK) != 0) {
GC gc = new GC(parent);
gc.setFont(getFont(1, false));
computeDisplayText(1, gc);
gc.dispose();
}
}
}
use of org.eclipse.swt.graphics.Font in project eclipse.platform.swt by eclipse.
the class CTabFolderTab method setItemFont.
/**
* Sets the font of CTabItem 0.
*/
void setItemFont() {
if (!instance.startup) {
tabFolder1.getItem(0).setFont(itemFont);
setExampleWidgetSize();
}
/* Set the font item's image to match the font of the item. */
Font ft = itemFont;
if (ft == null)
ft = tabFolder1.getItem(0).getFont();
TableItem item = colorAndFontTable.getItem(ITEM_FONT);
Image oldImage = item.getImage();
if (oldImage != null)
oldImage.dispose();
item.setImage(fontImage(ft));
item.setFont(ft);
colorAndFontTable.layout();
}
Aggregations