int getVisualLineIndex(TextLayout layout, int offsetInLine) { int lineIndex = layout.getLineIndex(offsetInLine); int[] offsets = layout.getLineOffsets(); if (lineIndex != 0 && offsetInLine == offsets[lineIndex]) { int lineY = layout.getLineBounds(lineIndex).y; int caretY = getCaret().getLocation().y - getLinePixel(getCaretLine()); if (lineY > caretY) lineIndex--; caretAlignment = OFFSET_LEADING; } return lineIndex; } int getCaretDirection() {
int getVisualLineIndex(TextLayout layout, int offsetInLine) { int lineIndex = layout.getLineIndex(offsetInLine); int[] offsets = layout.getLineOffsets(); Caret caret = getCaret(); if (caret != null && lineIndex != 0 && offsetInLine == offsets[lineIndex]) { int lineY = layout.getLineBounds(lineIndex).y; int caretY = caret.getLocation().y - getLinePixel(getCaretLine()); if (lineY > caretY) lineIndex--; caretAlignment = OFFSET_LEADING; } return lineIndex; } int getCaretDirection() {
int getVisualLineIndex(TextLayout layout, int offsetInLine) { int lineIndex = layout.getLineIndex(offsetInLine); int[] offsets = layout.getLineOffsets(); Caret caret = getCaret(); if (caret != null && lineIndex != 0 && offsetInLine == offsets[lineIndex]) { int lineY = layout.getLineBounds(lineIndex).y; int caretY = caret.getLocation().y - getLinePixel(getCaretLine()); if (lineY > caretY) lineIndex--; caretAlignment = OFFSET_LEADING; } return lineIndex; } int getCaretDirection() {
int getVisualLineIndex(TextLayout layout, int offsetInLine) { int lineIndex = layout.getLineIndex(offsetInLine); int[] offsets = layout.getLineOffsets(); Caret caret = getCaret(); if (caret != null && lineIndex != 0 && offsetInLine == offsets[lineIndex]) { int lineY = layout.getLineBounds(lineIndex).y; int caretY = caret.getLocation().y - getLinePixel(getCaretLine()); if (lineY > caretY) lineIndex--; caretAlignment = OFFSET_LEADING; } return lineIndex; } int getCaretDirection() {
int getVisualLineIndex(TextLayout layout, int offsetInLine) { int lineIndex = layout.getLineIndex(offsetInLine); int[] offsets = layout.getLineOffsets(); Caret caret = getCaret(); if (caret != null && lineIndex != 0 && offsetInLine == offsets[lineIndex]) { int lineY = layout.getLineBounds(lineIndex).y; int caretY = caret.getLocation().y - getLinePixel(getCaretLine()); if (lineY > caretY) lineIndex--; caretAlignment = OFFSET_LEADING; } return lineIndex; } int getCaretDirection() {
/** * Returns the bounds of the receiver. The width returned is either the * width of the longest line or the width set using {@link TextLayout#setWidth(int)}. * To obtain the text bounds of a line use {@link TextLayout#getLineBounds(int)}. * * @return the bounds of the receiver * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #setWidth(int) * @see #getLineBounds(int) */ public Rectangle getBounds() { checkLayout(); Rectangle bounds = DPIUtil.autoScaleDown(getDevice(), getBoundsInPixels()); int lineCount = OS.pango_layout_get_line_count(layout); int totalLineheight = 0; for (int i = 0; i < lineCount; i++) { totalLineheight += this.getLineBounds(i).height; } bounds.height = totalLineheight; return bounds; } Rectangle getBoundsInPixels() {
/** * Returns the bounds of the receiver. The width returned is either the * width of the longest line or the width set using {@link TextLayout#setWidth(int)}. * To obtain the text bounds of a line use {@link TextLayout#getLineBounds(int)}. * * @return the bounds of the receiver * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #setWidth(int) * @see #getLineBounds(int) */ public Rectangle getBounds() { checkLayout(); Rectangle bounds = DPIUtil.autoScaleDown(getDevice(), getBoundsInPixels()); int lineCount = OS.pango_layout_get_line_count(layout); int totalLineheight = 0; for (int i = 0; i < lineCount; i++) { totalLineheight += this.getLineBounds(i).height; } bounds.height = totalLineheight; return bounds; } Rectangle getBoundsInPixels() {
/** * Returns the bounds of the receiver. The width returned is either the * width of the longest line or the width set using {@link TextLayout#setWidth(int)}. * To obtain the text bounds of a line use {@link TextLayout#getLineBounds(int)}. * * @return the bounds of the receiver * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #setWidth(int) * @see #getLineBounds(int) */ public Rectangle getBounds() { checkLayout(); Rectangle bounds = DPIUtil.autoScaleDown(getDevice(), getBoundsInPixels()); int lineCount = OS.pango_layout_get_line_count(layout); int totalLineheight = 0; for (int i = 0; i < lineCount; i++) { totalLineheight += this.getLineBounds(i).height; } bounds.height = totalLineheight; return bounds; } Rectangle getBoundsInPixels() {
Rectangle [] getRectanglesInPixels (int linkIndex) { int lineCount = layout.getLineCount (); Rectangle [] rects = new Rectangle [lineCount]; int [] lineOffsets = layout.getLineOffsets (); Point point = offsets [linkIndex]; int lineStart = 1; while (point.x > lineOffsets [lineStart]) lineStart++; int lineEnd = 1; while (point.y > lineOffsets [lineEnd]) lineEnd++; int index = 0; if (lineStart == lineEnd) { rects [index++] = DPIUtil.autoScaleUp(layout.getBounds (point.x, point.y)); } else { rects [index++] = DPIUtil.autoScaleUp(layout.getBounds (point.x, lineOffsets [lineStart]-1)); rects [index++] = DPIUtil.autoScaleUp(layout.getBounds (lineOffsets [lineEnd-1], point.y)); if (lineEnd - lineStart > 1) { for (int i = lineStart; i < lineEnd - 1; i++) { rects [index++] = DPIUtil.autoScaleUp(layout.getLineBounds (i)); } } } if (rects.length != index) { Rectangle [] tmp = new Rectangle [index]; System.arraycopy (rects, 0, tmp, 0, index); rects = tmp; } return rects; }
TextLayout layout = renderer.getTextLayout(lineIndex); int lineInParagraph = layout.getLineIndex(Math.min(offset - lineOffset, layout.getText().length())); int height = layout.getLineBounds(lineInParagraph).height; renderer.disposeTextLayout(layout); return height;
TextLayout layout = renderer.getTextLayout(lineIndex); int lineInParagraph = layout.getLineIndex(Math.min(offset - lineOffset, layout.getText().length())); int height = layout.getLineBounds(lineInParagraph).height; renderer.disposeTextLayout(layout); return height;
Rectangle [] getRectanglesInPixels (int linkIndex) { int lineCount = layout.getLineCount (); Rectangle [] rects = new Rectangle [lineCount]; int [] lineOffsets = layout.getLineOffsets (); Point point = offsets [linkIndex]; int lineStart = 1; while (point.x > lineOffsets [lineStart]) lineStart++; int lineEnd = 1; while (point.y > lineOffsets [lineEnd]) lineEnd++; int index = 0; if (lineStart == lineEnd) { rects [index++] = DPIUtil.autoScaleUp (layout.getBounds (point.x, point.y)); } else { rects [index++] = DPIUtil.autoScaleUp (layout.getBounds (point.x, lineOffsets [lineStart]-1)); rects [index++] = DPIUtil.autoScaleUp (layout.getBounds (lineOffsets [lineEnd-1], point.y)); if (lineEnd - lineStart > 1) { for (int i = lineStart; i < lineEnd - 1; i++) { rects [index++] = DPIUtil.autoScaleUp (layout.getLineBounds (i)); } } } if (rects.length != index) { Rectangle [] tmp = new Rectangle [index]; System.arraycopy (rects, 0, tmp, 0, index); rects = tmp; } return rects; }
Rectangle [] getRectanglesInPixels (int linkIndex) { int lineCount = layout.getLineCount (); Rectangle [] rects = new Rectangle [lineCount]; int [] lineOffsets = layout.getLineOffsets (); Point point = offsets [linkIndex]; int lineStart = 1; while (point.x > lineOffsets [lineStart]) lineStart++; int lineEnd = 1; while (point.y > lineOffsets [lineEnd]) lineEnd++; int index = 0; if (lineStart == lineEnd) { rects [index++] = DPIUtil.autoScaleUp (layout.getBounds (point.x, point.y)); } else { rects [index++] = DPIUtil.autoScaleUp (layout.getBounds (point.x, lineOffsets [lineStart]-1)); rects [index++] = DPIUtil.autoScaleUp (layout.getBounds (lineOffsets [lineEnd-1], point.y)); if (lineEnd - lineStart > 1) { for (int i = lineStart; i < lineEnd - 1; i++) { rects [index++] = DPIUtil.autoScaleUp (layout.getLineBounds (i)); } } } if (rects.length != index) { Rectangle [] tmp = new Rectangle [index]; System.arraycopy (rects, 0, tmp, 0, index); rects = tmp; } return rects; }
Rectangle [] getRectanglesInPixels (int linkIndex) { int lineCount = layout.getLineCount (); Rectangle [] rects = new Rectangle [lineCount]; int [] lineOffsets = layout.getLineOffsets (); Point point = offsets [linkIndex]; int lineStart = 1; while (point.x > lineOffsets [lineStart]) lineStart++; int lineEnd = 1; while (point.y > lineOffsets [lineEnd]) lineEnd++; int index = 0; if (lineStart == lineEnd) { rects [index++] = DPIUtil.autoScaleUp (layout.getBounds (point.x, point.y)); } else { rects [index++] = DPIUtil.autoScaleUp (layout.getBounds (point.x, lineOffsets [lineStart]-1)); rects [index++] = DPIUtil.autoScaleUp (layout.getBounds (lineOffsets [lineEnd-1], point.y)); if (lineEnd - lineStart > 1) { for (int i = lineStart; i < lineEnd - 1; i++) { rects [index++] = DPIUtil.autoScaleUp (layout.getLineBounds (i)); } } } if (rects.length != index) { Rectangle [] tmp = new Rectangle [index]; System.arraycopy (rects, 0, tmp, 0, index); rects = tmp; } return rects; }
int index = layout.getLineCount() - 1; while (index >= 0) { Rectangle bounds = layout.getLineBounds(index); if (y >= bounds.y + bounds.height) break; index--;
int getOffsetAtPoint(int x, int y, int[] trailing, boolean inTextOnly) { if (inTextOnly && y + getVerticalScrollOffset() < 0 || x + horizontalScrollOffset < 0) { return -1; } int bottomIndex = getPartialBottomIndex(); int height = getLinePixel(bottomIndex + 1); if (inTextOnly && y > height) { return -1; } int lineIndex = getLineIndex(y); int lineOffset = content.getOffsetAtLine(lineIndex); TextLayout layout = renderer.getTextLayout(lineIndex); x += horizontalScrollOffset - leftMargin; y -= getLinePixel(lineIndex); int offset = layout.getOffset(x, y, trailing); Rectangle rect = layout.getLineBounds(layout.getLineIndex(offset)); renderer.disposeTextLayout(layout); if (inTextOnly && !(rect.x <= x && x <= rect.x + rect.width)) { return -1; } return offset + lineOffset; } /**
int getOffsetAtPoint(int x, int y, int[] trailing, boolean inTextOnly) { if (inTextOnly && y + getVerticalScrollOffset() < 0 || x + horizontalScrollOffset < 0) { return -1; } int bottomIndex = getPartialBottomIndex(); int height = getLinePixel(bottomIndex + 1); if (inTextOnly && y > height) { return -1; } int lineIndex = getLineIndex(y); int lineOffset = content.getOffsetAtLine(lineIndex); TextLayout layout = renderer.getTextLayout(lineIndex); x += horizontalScrollOffset - leftMargin; y -= getLinePixel(lineIndex); int offset = layout.getOffset(x, y, trailing); Rectangle rect = layout.getLineBounds(layout.getLineIndex(offset)); renderer.disposeTextLayout(layout); if (inTextOnly && !(rect.x <= x && x <= rect.x + rect.width)) { return -1; } return offset + lineOffset; } /**
int getOffsetAtPoint(int x, int y, int[] trailing, boolean inTextOnly) { if (inTextOnly && y + getVerticalScrollOffset() < 0 || x + horizontalScrollOffset < 0) { return -1; } int bottomIndex = getPartialBottomIndex(); int height = getLinePixel(bottomIndex + 1); if (inTextOnly && y > height) { return -1; } int lineIndex = getLineIndex(y); int lineOffset = content.getOffsetAtLine(lineIndex); TextLayout layout = renderer.getTextLayout(lineIndex); x += horizontalScrollOffset - leftMargin; y -= getLinePixel(lineIndex); int offset = layout.getOffset(x, y, trailing); Rectangle rect = layout.getLineBounds(layout.getLineIndex(offset)); renderer.disposeTextLayout(layout); if (inTextOnly && !(rect.x <= x && x <= rect.x + rect.width)) { return -1; } return offset + lineOffset; } /**
int getOffsetAtPoint(int x, int y, int[] trailing, boolean inTextOnly) { if (inTextOnly && y + getVerticalScrollOffset() < 0 || x + horizontalScrollOffset < 0) { return -1; } int bottomIndex = getPartialBottomIndex(); int height = getLinePixel(bottomIndex + 1); if (inTextOnly && y > height) { return -1; } int lineIndex = getLineIndex(y); int lineOffset = content.getOffsetAtLine(lineIndex); TextLayout layout = renderer.getTextLayout(lineIndex); x += horizontalScrollOffset - leftMargin; y -= getLinePixel(lineIndex); int offset = layout.getOffset(x, y, trailing); Rectangle rect = layout.getLineBounds(layout.getLineIndex(offset)); renderer.disposeTextLayout(layout); if (inTextOnly && !(rect.x <= x && x <= rect.x + rect.width)) { return -1; } return offset + lineOffset; } /**
int getOffsetAtPoint(int x, int y, int[] trailing, boolean inTextOnly) { if (inTextOnly && y + getVerticalScrollOffset() < 0 || x + horizontalScrollOffset < 0) { return -1; } int bottomIndex = getPartialBottomIndex(); int height = getLinePixel(bottomIndex + 1); if (inTextOnly && y > height) { return -1; } int lineIndex = getLineIndex(y); int lineOffset = content.getOffsetAtLine(lineIndex); TextLayout layout = renderer.getTextLayout(lineIndex); x += horizontalScrollOffset - leftMargin; y -= getLinePixel(lineIndex); int offset = layout.getOffset(x, y, trailing); Rectangle rect = layout.getLineBounds(layout.getLineIndex(offset)); renderer.disposeTextLayout(layout); if (inTextOnly && !(rect.x <= x && x <= rect.x + rect.width)) { return -1; } return offset + lineOffset; } /**