oldFont = gc.getFont();
Font newFont = (Font) objectTable.get(fontId);
if (newFont != null)
gc.setFont(newFont);
}
FontMetrics fm = gc.getFontMetrics();
int lineHeight = fm.getHeight();
boolean newLine = false;
if (wHint == SWT.DEFAULT || !wrapAllowed) {
Point extent = gc.textExtent(text);
int totalExtent = locator.x+extent.x;
if (isSelectable())
totalExtent+=1;
if (wHint != SWT.DEFAULT && totalExtent + locator.marginWidth > wHint) {
// new line
locator.resetCaret();
locator.y += locator.rowHeight;
if (computeHeightOnly)
locator.collectHeights();
locator.rowHeight = 0;
locator.leading = 0;
newLine = true;
}
int width = extent.x;
if (isSelectable())
width += 1;
locator.x += width;
locator.width = locator.x;
locator.rowHeight = Math.max(locator.rowHeight, extent.y);
locator.leading = Math.max(locator.leading, fm.getLeading());
return newLine;
}
computeTextFragments(gc);
int width = 0;
Point lineExtent = new Point(0, 0);
for (int i = 0; i < textFragments.length; i++) {
TextFragment textFragment = textFragments[i];
int currentExtent = locator.x + lineExtent.x;
if (isSelectable())
currentExtent += 1;
// i != 0 || locator.x > locator.getStartX() + (isSelectable() ? 1 : 0) means:
// only wrap on the first fragment if we are not at the start of a line
if ((i != 0 || locator.x > locator.getStartX() + (isSelectable() ? 1 : 0)) && currentExtent + textFragment.length > wHint) {
// overflow
int lineWidth = currentExtent;
locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y);
locator.leading = Math.max(locator.leading, fm.getLeading());
if (computeHeightOnly)
locator.collectHeights();
locator.x = locator.indent;
locator.y += locator.rowHeight;
locator.rowHeight = 0;
locator.leading = 0;
lineExtent.x = 0;
lineExtent.y = 0;
width = Math.max(width, lineWidth);
newLine = true;
}
lineExtent.x += textFragment.length;
lineExtent.y = Math.max(lineHeight, lineExtent.y);
width = Math.max (width, locator.x + lineExtent.x);
}
int lineWidth = lineExtent.x;
if (isSelectable())
lineWidth += 1;
locator.x += lineWidth;
locator.width = width;
locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y);
locator.leading = Math.max(locator.leading, fm.getLeading());
if (oldFont != null) {
gc.setFont(oldFont);
}
return newLine;
}