@@ -476,4 +476,96 @@ This method, however gets only called, if the widget resizes or if a new input i
}
```
## Displaying the text in different Fonts (that is the type, its size and styling)
We are currently sitting pretty. We are capable of calculating the bounds (x and y offsets alongside the width and height) of every single EditorLine. What is left is to actually display them. After wrapping the lines (as well as several other operations on the widget) we need to actually display the result. This is done in two steps. The first step is to actually *measure* the lines (huh again? i thought all is known!). To be fair, we still need to assign the topYOffset and the attribute whether a line is currently visible, this is done is the method ```measureLines()```
```java
privatevoidmeasureLines(GCgcOff){
intyOffset=0;
// draw the content that is the text and the selection
yOffset=getTopMargin();
intlineOffset=0;
booleanbottomlineSet=false;
for(EditorLineline:editorLines){
// reset its styleranges
line.getStyleRanges().clear();
// draw the selection here
if(lineOffset<this.topLineOffset){
lineOffset++;
line.setVisible(false);
continue;
}
// stop drawing if we are outside bounds
if(yOffset>getBounds().height-bottomMargin){
line.setVisible(false);
if(!bottomlineSet){
bottomLineOffset=line.getLineNumber();
bottomlineSet=true;
}
continue;
}
line.setVisible(true);
// update the line height
line.setTopYOffset(yOffset);
yOffset+=line.getLineHeight();
// update by line spacing
yOffset+=lineSpacing;
lineOffset++;
}
// if bottomline was never updates we set it to max!
if(!bottomlineSet){
bottomLineOffset=editorLines.size()-1;
}
}
```
Afterwards, we can finally draw the text. This is done in the method ```drawLines()```:
Note the last argument, which tells SWT to only draw the text using a transparent background (we want our annotations to be visible and not overwritten by the background of the text all the time - and the background is a box!)
To be continued...
Things that can be made faster:
* Binary search for the wrapping
* Only iterate through the visible lines instead of all lines while drawing