?? textlayout.java
字號:
return untranslateOffset(lastRun.start); } else { if (trailing != null) trailing[0] = 1; return untranslateOffset(lastRun.start + lastRun.length - 1); } } int width = 0; for (int i = 0; i < lineRuns.length; i++) { StyleItem run = lineRuns[i]; if (run.lineBreak && !run.softBreak) return untranslateOffset(run.start); if (width + run.width > x) { if (run.tab) { if (trailing != null) trailing[0] = x < (width + run.width / 2) ? 0 : 1; return untranslateOffset(run.start); } int cChars = run.length; int cGlyphs = run.glyphCount; int xRun = x - width; int[] piCP = new int[1]; int[] piTrailing = new int[1]; if ((orientation & SWT.RIGHT_TO_LEFT) != 0) { xRun = run.width - xRun; } OS.ScriptXtoCP(xRun, cChars, cGlyphs, run.clusters, run.visAttrs, run.advances, run.analysis, piCP, piTrailing); if (trailing != null) trailing[0] = piTrailing[0]; return untranslateOffset(run.start + piCP[0]); } width += run.width; } if (trailing != null) trailing[0] = 0; return untranslateOffset(lineOffset[line + 1]);}/** * Returns the orientation of the receiver. * * @return the orientation style * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public int getOrientation () { checkLayout(); return orientation;}/** * Returns the previous 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 previous 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 #getNextOffset(int, int) */public int getPreviousOffset (int offset, int movement) { checkLayout(); return _getOffset (offset, movement, false);}/** * Returns the text segments offsets of the receiver. * * @return the text segments offsets * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public int[] getSegments () { checkLayout(); return segments;}String getSegmentsText() { if (segments == null) return text; int nSegments = segments.length; if (nSegments <= 1) return text; int length = text.length(); if (length == 0) return text; if (nSegments == 2) { if (segments[0] == 0 && segments[1] == length) return text; } char[] oldChars = new char[length]; text.getChars(0, length, oldChars, 0); char[] newChars = new char[length + nSegments]; int charCount = 0, segmentCount = 0; char separator = orientation == SWT.RIGHT_TO_LEFT ? RTL_MARK : LTR_MARK; while (charCount < length) { if (segmentCount < nSegments && charCount == segments[segmentCount]) { newChars[charCount + segmentCount++] = separator; } else { newChars[charCount + segmentCount] = oldChars[charCount++]; } } if (segmentCount < nSegments) { segments[segmentCount] = charCount; newChars[charCount + segmentCount++] = separator; } return new String(newChars, 0, Math.min(charCount + segmentCount, newChars.length));}/** * Returns the line spacing of the receiver. * * @return the line spacing * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public int getSpacing () { checkLayout(); return lineSpacing;}/** * Gets the style of the receiver at the specified character offset. * * @param offset the text offset * @return the style or <code>null</code> if not set * * @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 TextStyle getStyle (int offset) { checkLayout(); int length = text.length(); if (!(0 <= offset && offset < length)) SWT.error(SWT.ERROR_INVALID_RANGE); for (int i=1; i<styles.length; i++) { if (styles[i].start > offset) { return styles[i - 1].style; } } return null;}/** * Returns the tab list of the receiver. * * @return the tab list * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public int[] getTabs () { checkLayout(); return tabs;}/** * Gets the receiver's text, which will be an empty * string if it has never been set. * * @return the receiver's text * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public String getText () { checkLayout(); return text;}/** * Returns the width of the receiver. * * @return the width * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public int getWidth () { checkLayout(); return wrapWidth;}/** * Returns <code>true</code> if the text layout has been disposed, * and <code>false</code> otherwise. * <p> * This method gets the dispose state for the text layout. * When a text layout has been disposed, it is an error to * * @return <code>true</code> when the text layout is disposed and <code>false</code> otherwise */public boolean isDisposed () { return device == null;}/* * Itemize the receiver text */StyleItem[] itemize () { segmentsText = getSegmentsText(); int length = segmentsText.length(); SCRIPT_CONTROL scriptControl = new SCRIPT_CONTROL(); SCRIPT_STATE scriptState = new SCRIPT_STATE(); final int MAX_ITEM = length + 1; if ((orientation & SWT.RIGHT_TO_LEFT) != 0) { scriptState.uBidiLevel = 1; scriptState.fArabicNumContext = true; } int hHeap = OS.GetProcessHeap(); int pItems = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, MAX_ITEM * SCRIPT_ITEM.sizeof); int[] pcItems = new int[1]; char[] chars = new char[length]; segmentsText.getChars(0, length, chars, 0); OS.ScriptItemize(chars, length, MAX_ITEM, scriptControl, scriptState, pItems, pcItems);// if (hr == E_OUTOFMEMORY) //TODO handle it StyleItem[] runs = merge(pItems, pcItems[0]); OS.HeapFree(hHeap, 0, pItems); return runs;}/* * Merge styles ranges and script items */StyleItem[] merge (int items, int itemCount) { int count = 0, start = 0, end = segmentsText.length(), itemIndex = 0, styleIndex = 0; StyleItem[] runs = new StyleItem[itemCount + styles.length]; SCRIPT_ITEM scriptItem = new SCRIPT_ITEM(); while (start < end) { StyleItem item = new StyleItem(); item.start = start; item.style = styles[styleIndex].style; runs[count++] = item; OS.MoveMemory(scriptItem, items + itemIndex * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof); item.analysis = scriptItem.a; scriptItem.a = new SCRIPT_ANALYSIS(); OS.MoveMemory(scriptItem, items + (itemIndex + 1) * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof); int itemLimit = scriptItem.iCharPos; int styleLimit = translateOffset(styles[styleIndex + 1].start); if (styleLimit <= itemLimit) { styleIndex++; start = styleLimit; } if (itemLimit <= styleLimit) { itemIndex++; start = itemLimit; } item.length = start - item.start; } StyleItem item = new StyleItem(); item.start = end; OS.MoveMemory(scriptItem, items + itemCount * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof); item.analysis = scriptItem.a; runs[count++] = item; if (runs.length != count) { StyleItem[] result = new StyleItem[count]; System.arraycopy(runs, 0, result, 0, count); return result; } return runs;}/* * Reorder the run */StyleItem[] reorder (StyleItem[] runs) { byte[] bidiLevels = new byte[runs.length]; for (int i=0; i<runs.length; i++) { bidiLevels[i] = (byte)(runs[i].analysis.s.uBidiLevel & 0x1F); } int[] log2vis = new int[runs.length]; OS.ScriptLayout(runs.length, bidiLevels, null, log2vis); StyleItem[] result = new StyleItem[runs.length]; for (int i=0; i<runs.length; i++) { result[log2vis[i]] = runs[i]; } if ((orientation & SWT.RIGHT_TO_LEFT) != 0) { for (int i = 0; i < (result.length - 1) / 2 ; i++) { StyleItem tmp = result[i]; result[i] = result[result.length - i - 2]; result[result.length - i - 2] = tmp; } } return result;}/** * Sets the text alignment for the receiver. The alignment controls * how a line of text is positioned horizontally. The argument should * be one of <code>SWT.LEFT</code>, <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>. * <p> * The default alignment is <code>SWT.LEFT</code>. Note that the receiver's * width must be set in order to use <code>SWT.RIGHT</code> or <code>SWT.CENTER</code> * alignment. *</p> * * @param alignment the new alignment * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #setWidth(int) */public void setAlignment (int alignment) { checkLayout(); int mask = SWT.LEFT | SWT.CENTER | SWT.RIGHT; alignment &= mask; if (alignment == 0) return; if ((alignment & SWT.LEFT) != 0) alignment = SWT.LEFT; if ((alignment & SWT.RIGHT) != 0) alignment = SWT.RIGHT; this.alignment = alignment;}/** * Sets the ascent of the receiver. The ascent is distance in pixels * from the baseline to the top of the line and it is applied to all * lines. The default value is <code>-1</code> which means that the * ascent is calculated from the line fonts. * * @param ascent the new ascent * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the ascent is less than <code>-1</code></li> * </ul> * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #setDescent(int) * @see #getLineMetrics() */public void setAscent(int ascent) { checkLayout(); if (ascent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); if (this.ascent == ascent) return; freeRuns(); this.ascent = ascent;}/** * Sets the descent of the receiver. The descent is distance in pixels * from the baseline to the bottom of the line and it is applied to all * lines. The default value is <code>-1</code> which means that the * descent is calculated from the line fonts. * * @param descent the new descent * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the descent is less than <code>-1</code></li> * </ul> * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #setAscent(int) * @see #getLineMetrics() */public void setDescent(int descent) { checkLayout(); if (descent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); if (this.descent == descent) return; freeRuns(); this.descent = descent;}/** * Sets the default font which will be used by the receiver * to draw and measure text. If the * argument is null, then a default font appropriate * for the platform will be used instead. Note that a text * style can override the default font. * * @param font the new font for the receiver, or null to indicate a default font * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li> * </ul> * @exception SWTException <ul>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -