1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-03 07:05:24 +02:00

FIXED - bug 206328: [regression] Terminal does not draw correctly with proportional font

https://bugs.eclipse.org/bugs/show_bug.cgi?id=206328
patch applied
This commit is contained in:
Michael Scharf 2007-10-26 05:13:35 +00:00
parent 250d3197ba
commit 54925f0d08
2 changed files with 58 additions and 3 deletions

View file

@ -33,7 +33,7 @@ public class StyleMap {
private static final String BLUE = "blue"; //$NON-NLS-1$
private static final String GREEN = "green"; //$NON-NLS-1$
private static final String RED = "red"; //$NON-NLS-1$
private static final String PREFIX = "org.eclipse.tm.internal."; //$NON-NLS-1$
// TODO propagate the name of the font in the FontRegistry
String fFontName="terminal.views.view.font.definition"; //$NON-NLS-1$
@ -42,6 +42,8 @@ public class StyleMap {
private Point fCharSize;
private Style fDefaultStyle;
private boolean fInvertColors;
private boolean fProportional;
private final int[] fOffsets=new int[256];
StyleMap() {
addColor(WHITE, 255,255,255);
addColor(BLACK, 0,0,0);
@ -138,6 +140,44 @@ public class StyleMap {
GC gc = new GC (display);
gc.setFont(getFont());
fCharSize = gc.textExtent ("W"); //$NON-NLS-1$
fProportional=false;
for (char c = ' '; c <= '~'; c++) {
// consider only the first 128 chars for deciding if a font
// is proportional
if(measureChar(gc, c))
fProportional=true;
}
// TODO should we also consider the upper 128 chars??
// for (char c = ' '+128; c <= '~'+128; c++) {
// measureChar(gc, c);
// }
for (int i = 0; i < fOffsets.length; i++) {
fOffsets[i]=(fCharSize.x-fOffsets[i])/2;
}
gc.dispose ();
}
private boolean measureChar(GC gc, char c) {
boolean proportional=false;
Point ext=gc.textExtent(String.valueOf(c));
if(ext.x>0 && ext.y>0 && (fCharSize.x!=ext.x || fCharSize.y!=ext.y)) {
proportional=true;
fCharSize.x=Math.max(fCharSize.x, ext.x);
fCharSize.y=Math.max(fCharSize.y, ext.y);
}
fOffsets[c]=ext.x;
return proportional;
}
public boolean isFontProportional() {
return fProportional;
}
/**
* @param c
* @return the offset in x direction to center this character
*/
public int getCharOffset(char c) {
if(c>=fOffsets.length)
return 0;
return fOffsets[c];
}
}

View file

@ -116,8 +116,23 @@ public class TextLineRenderer implements ILinelRenderer {
}
private void drawText(GC gc, int x, int y, int colFirst, int col, String text) {
int offset=(col-colFirst)*getCellWidth();
text=text.replace('\000', ' ');
gc.drawString(text,x+offset,y,false);
if(fStyleMap.isFontProportional()) {
// draw the background
// TODO why does this not work???????
// gc.fillRectangle(x,y,fStyleMap.getFontWidth()*text.length(),fStyleMap.getFontHeight());
for (int i = 0; i < text.length(); i++) {
char c=text.charAt(i);
int xx=x+offset+i*fStyleMap.getFontWidth();
// TODO why do I have to draw the background character by character??????
gc.fillRectangle(xx,y,fStyleMap.getFontWidth(),fStyleMap.getFontHeight());
if(c!=' ' && c!='\000') {
gc.drawString(String.valueOf(c),fStyleMap.getCharOffset(c)+xx,y,true);
}
}
} else {
text=text.replace('\000', ' ');
gc.drawString(text,x+offset,y,false);
}
}
private void setupGC(GC gc, Style style) {
Color c=fStyleMap.getForegrondColor(style);