?? textlayout.java
字號(hào):
*/public int getLevel (int offset) { checkLayout(); computeRuns(null); int length = text.length(); if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE); offset = translateOffset(offset); for (int i=1; i<allRuns.length; i++) { if (allRuns[i].start > offset) { return allRuns[i - 1].analysis.s.uBidiLevel; } } return (orientation & SWT.RIGHT_TO_LEFT) != 0 ? 1 : 0;}/** * Returns the bounds of the line for the specified line index. * * @param lineIndex the line index * @return the line bounds * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li> * </ul> * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public Rectangle getLineBounds(int lineIndex) { checkLayout(); computeRuns(null); if (!(0 <= lineIndex && lineIndex < runs.length)) SWT.error(SWT.ERROR_INVALID_RANGE); int x = 0, y = lineY[lineIndex]; int width = lineWidth[lineIndex], height = lineY[lineIndex + 1] - y; if (wrapWidth != -1) { switch (alignment) { case SWT.CENTER: x = (wrapWidth - width) / 2; break; case SWT.RIGHT: x = wrapWidth - width; break; } } return new Rectangle (x, y, width, height);}/** * Returns the receiver's line count. This includes lines caused * by wrapping. * * @return the line count * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public int getLineCount () { checkLayout(); computeRuns(null); return runs.length;}/** * Returns the index of the line that contains the specified * character offset. * * @param offset the character offset * @return the line index * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li> * </ul> * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public int getLineIndex (int offset) { checkLayout(); computeRuns(null); int length = text.length(); if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE); offset = translateOffset(offset); for (int line=0; line<runs.length; line++) { if (lineOffset[line + 1] > offset) { return line; } } return runs.length - 1;}/** * Returns the font metrics for the specified line index. * * @param lineIndex the line index * @return the font metrics * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li> * </ul> * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public FontMetrics getLineMetrics (int lineIndex) { checkLayout(); computeRuns(null); if (!(0 <= lineIndex && lineIndex < runs.length)) SWT.error(SWT.ERROR_INVALID_RANGE); int hDC = device.internal_new_GC(null); int srcHdc = OS.CreateCompatibleDC(hDC); TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA(); if (text.length() == 0) { Font font = this.font != null ? this.font : device.getSystemFont(); OS.SelectObject(srcHdc, font.handle); OS.GetTextMetrics(srcHdc, lptm); lptm.tmAscent = Math.max(lptm.tmAscent, this.ascent); lptm.tmDescent = Math.max(lptm.tmDescent, this.descent); } else { int ascent = this.ascent, descent = this.descent, leading = 0, aveCharWidth = 0, height = 0; StyleItem[] lineRuns = runs[lineIndex]; for (int i = 0; i<lineRuns.length; i++) { StyleItem run = lineRuns[i]; OS.SelectObject(srcHdc, getItemFont(run)); OS.GetTextMetrics(srcHdc, lptm); ascent = Math.max (ascent, lptm.tmAscent); descent = Math.max (descent, lptm.tmDescent); height = Math.max (height, lptm.tmHeight); leading = Math.max (leading, lptm.tmInternalLeading); aveCharWidth += lptm.tmAveCharWidth; } lptm.tmAscent = ascent; lptm.tmDescent = descent; lptm.tmHeight = height; lptm.tmInternalLeading = leading; lptm.tmAveCharWidth = aveCharWidth / lineRuns.length; } if (srcHdc != 0) OS.DeleteDC(srcHdc); device.internal_dispose_GC(hDC, null); return FontMetrics.win32_new(lptm);}/** * Returns the line offsets. Each value in the array is the * offset for the first character in a line except for the last * value, which contains the length of the text. * * @return the line offsets * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public int[] getLineOffsets () { checkLayout(); computeRuns(null); int[] offsets = new int[lineOffset.length]; for (int i = 0; i < offsets.length; i++) { offsets[i] = untranslateOffset(lineOffset[i]); } return offsets;}/** * Returns the location for the specified character offset. The * <code>trailing</code> argument indicates whether the offset * corresponds to the leading or trailing edge of the cluster. * * @param offset the character offset * @param trailing the trailing flag * @return the location of the character offset * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #getOffset(Point, int[]) * @see #getOffset(int, int, int[]) */public Point getLocation (int offset, boolean trailing) { checkLayout(); computeRuns(null); int length = text.length(); if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE); length = segmentsText.length(); offset = translateOffset(offset); int line; for (line=0; line<runs.length; line++) { if (lineOffset[line + 1] > offset) break; } line = Math.min(line, runs.length - 1); StyleItem[] lineRuns = runs[line]; Point result = null; if (offset == length) { result = new Point(lineWidth[line], lineY[line]); } else { int width = 0; for (int i=0; i<lineRuns.length; i++) { StyleItem run = lineRuns[i]; int end = run.start + run.length; if (run.start <= offset && offset < end) { if (run.tab) { if (trailing || (offset == length)) width += run.width; result = new Point(width, lineY[line]); } else { int runOffset = offset - run.start; int cChars = run.length; int gGlyphs = run.glyphCount; int[] piX = new int[1]; OS.ScriptCPtoX(runOffset, trailing, cChars, gGlyphs, run.clusters, run.visAttrs, run.advances, run.analysis, piX); if ((orientation & SWT.RIGHT_TO_LEFT) != 0) { result = new Point(width + (run.width - piX[0]), lineY[line]); } else { result = new Point(width + piX[0], lineY[line]); } } break; } width += run.width; } } if (result == null) result = new Point(0, 0); if (wrapWidth != -1) { switch (alignment) { case SWT.CENTER: result.x += (wrapWidth - lineWidth[line]) / 2; break; case SWT.RIGHT: result.x += wrapWidth - lineWidth[line]; break; } } return result;}/** * Returns the next offset for the specified offset and movement * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>, * <code>SWT.MOVEMENT_CLUSTER</code> or <code>SWT.MOVEMENT_WORD</code>. * * @param offset the start offset * @param movement the movement type * @return the next offset * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li> * </ul> * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #getPreviousOffset(int, int) */public int getNextOffset (int offset, int movement) { checkLayout(); return _getOffset (offset, movement, true);}int _getOffset(int offset, int movement, boolean forward) { computeRuns(null); int length = text.length(); if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE); if (forward && offset == length) return length; if (!forward && offset == 0) return 0; int step = forward ? 1 : -1; if ((movement & SWT.MOVEMENT_CHAR) != 0) return offset + step; length = segmentsText.length(); offset = translateOffset(offset); SCRIPT_LOGATTR logAttr = new SCRIPT_LOGATTR(); SCRIPT_PROPERTIES properties = new SCRIPT_PROPERTIES(); int i = forward ? 0 : allRuns.length - 1; offset = validadeOffset(offset, step); do { StyleItem run = allRuns[i]; if (run.start <= offset && offset < run.start + run.length) { if (run.lineBreak && !run.softBreak) return untranslateOffset(run.start); if (run.tab) return untranslateOffset(run.start); OS.MoveMemory(properties, device.scripts[run.analysis.eScript], SCRIPT_PROPERTIES.sizeof); boolean isComplex = properties.fNeedsCaretInfo || properties.fNeedsWordBreaking; if (isComplex) breakRun(run); while (run.start <= offset && offset < run.start + run.length) { if (isComplex) { OS.MoveMemory(logAttr, run.psla + ((offset - run.start) * SCRIPT_LOGATTR.sizeof), SCRIPT_LOGATTR.sizeof); } switch (movement) { case SWT.MOVEMENT_CLUSTER: { if (properties.fNeedsCaretInfo) { if (!logAttr.fInvalid && logAttr.fCharStop) return untranslateOffset(offset); } else { return untranslateOffset(offset); } break; } case SWT.MOVEMENT_WORD: { if (properties.fNeedsWordBreaking) { if (!logAttr.fInvalid && logAttr.fWordStop) return untranslateOffset(offset); } else { if (offset > 0) { boolean letterOrDigit = Compatibility.isLetterOrDigit(segmentsText.charAt(offset)); boolean previousLetterOrDigit = Compatibility.isLetterOrDigit(segmentsText.charAt(offset - 1)); if (letterOrDigit != previousLetterOrDigit || !letterOrDigit) { if (!Compatibility.isWhitespace(segmentsText.charAt(offset))) { return untranslateOffset(offset); } } } } break; } } offset = validadeOffset(offset, step); } } i += step; } while (0 <= i && i < allRuns.length - 1 && 0 <= offset && offset < length); return forward ? text.length() : 0;}/** * Returns the character offset for the specified point. * For a typical character, the trailing argument will be filled in to * indicate whether the point is closer to the leading edge (0) or * the trailing edge (1). When the point is over a cluster composed * of multiple characters, the trailing argument will be filled with the * position of the character in the cluster that is closest to * the point. * * @param point the point * @param trailing the trailing buffer * @return the character offset * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li> * </ul> * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #getLocation(int, boolean) */public int getOffset (Point point, int[] trailing) { checkLayout(); if (point == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); return getOffset (point.x, point.y, trailing) ;}/** * Returns the character offset for the specified point. * For a typical character, the trailing argument will be filled in to * indicate whether the point is closer to the leading edge (0) or * the trailing edge (1). When the point is over a cluster composed * of multiple characters, the trailing argument will be filled with the * position of the character in the cluster that is closest to * the point. * * @param x the x coordinate of the point * @param y the y coordinate of the point * @param trailing the trailing buffer * @return the character offset * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li> * </ul> * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #getLocation(int, boolean) */public int getOffset (int x, int y, int[] trailing) { checkLayout(); computeRuns(null); if (trailing != null && trailing.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); int line; int lineCount = runs.length; for (line=0; line<lineCount; line++) { if (lineY[line + 1] > y) break; } line = Math.min(line, runs.length - 1); if (wrapWidth != -1) { switch (alignment) { case SWT.CENTER: x -= (wrapWidth - lineWidth[line]) / 2; break; case SWT.RIGHT: x -= wrapWidth - lineWidth[line]; break; } } StyleItem[] lineRuns = runs[line]; boolean isRTL = (orientation & SWT.RIGHT_TO_LEFT) != 0; if (x < 0) { StyleItem firstRun = lineRuns[0]; if (firstRun.analysis.fRTL ^ isRTL) { if (trailing != null) trailing[0] = 1; return untranslateOffset(firstRun.start + firstRun.length - 1); } else { if (trailing != null) trailing[0] = 0; return untranslateOffset(firstRun.start); } } if (x > lineWidth[line]) { int index = lineRuns.length - 1; if (line == lineCount - 1 && lineRuns.length > 1) index--; StyleItem lastRun = lineRuns[index]; if (lastRun.analysis.fRTL ^ isRTL) { if (trailing != null) trailing[0] = 0;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -