?? bidiutil.java
字號:
} if ((fontLanguageInfo & GCP_GLYPHSHAPE) == GCP_GLYPHSHAPE) { dwFlags |= GCP_GLYPHSHAPE; } if ((flags & CLASSIN) == CLASSIN) { // set classification values for the substring, classification values // can be specified on input dwFlags |= GCP_CLASSIN; OS.MoveMemory(result.lpClass, classBuffer, classBuffer.length); } int glyphCount = 0; for (int i=0; i<offsets.length-1; i++) { int offset = offsets [i]; int length = offsets [i+1] - offsets [i]; // The number of glyphs expected is <= length (segment length); // the actual number returned may be less in case of Arabic ligatures. result.nGlyphs = length; TCHAR textBuffer2 = new TCHAR(lpCs[1], text.substring(offset, offset + length), false); OS.GetCharacterPlacement(gc.handle, textBuffer2, textBuffer2.length(), 0, result, dwFlags); if (order != null) { int [] order2 = new int [length]; OS.MoveMemory(order2, result.lpOrder, order2.length * 4); translateOrder(order2, glyphCount, isRightOriented); System.arraycopy (order2, 0, order, offset, length); } if (classBuffer != null) { byte [] classBuffer2 = new byte [length]; OS.MoveMemory(classBuffer2, result.lpClass, classBuffer2.length); System.arraycopy (classBuffer2, 0, classBuffer, offset, length); } glyphCount += result.nGlyphs; // We concatenate successive results of calls to GCP. // For Arabic, it is the only good method since the number of output // glyphs might be less than the number of input characters. // This assumes that the whole line is built by successive adjacent // segments without overlapping. result.lpOrder += length * 4; result.lpClass += length; } /* Free the memory that was allocated. */ OS.HeapFree(hHeap, 0, lpClass); OS.HeapFree(hHeap, 0, lpOrder);}/** * Return bidi attribute information for the font in the specified gc. * <p> * * @param gc the gc to query * @return bitwise OR of the REORDER, LIGATE and GLYPHSHAPE flags * defined by this class. */public static int getFontBidiAttributes(GC gc) { int fontStyle = 0; int fontLanguageInfo = OS.GetFontLanguageInfo(gc.handle); if (((fontLanguageInfo & GCP_REORDER) != 0)) { fontStyle |= REORDER; } if (((fontLanguageInfo & GCP_LIGATE) != 0)) { fontStyle |= LIGATE; } if (((fontLanguageInfo & GCP_GLYPHSHAPE) != 0)) { fontStyle |= GLYPHSHAPE; } return fontStyle; }/** * Return the active keyboard language type. * <p> * * @return an integer representing the active keyboard language (KEYBOARD_BIDI, * KEYBOARD_NON_BIDI) */public static int getKeyboardLanguage() { int layout = OS.GetKeyboardLayout(0); // only interested in low 2 bytes, which is the primary // language identifier layout = layout & 0x000000FF; if (layout == LANG_HEBREW) return KEYBOARD_BIDI; if (layout == LANG_ARABIC) return KEYBOARD_BIDI; // return non-bidi for all other languages return KEYBOARD_NON_BIDI;}/** * Return the languages that are installed for the keyboard. * <p> * * @return integer array with an entry for each installed language */static int[] getKeyboardLanguageList() { int maxSize = 10; int[] tempList = new int[maxSize]; int size = OS.GetKeyboardLayoutList(maxSize, tempList); int[] list = new int[size]; System.arraycopy(tempList, 0, list, 0, size); return list;}/** * Return whether or not the platform supports a bidi language. Determine this * by looking at the languages that are installed. * <p> * * @return true if bidi is supported, false otherwise. Always * false on Windows CE. */public static boolean isBidiPlatform() { if (OS.IsWinCE) return false; if (isBidiPlatform != -1) return isBidiPlatform == 1; // already set isBidiPlatform = 0; // The following test is a workaround for bug report 27629. On WinXP, // both bidi and complex script (e.g., Thai) languages must be installed // at the same time. Since the bidi platform calls do not support // double byte characters, there is no way to run Eclipse using the // complex script languages on XP, so constrain this test to answer true // only if a bidi input language is defined. Doing so will allow complex // script languages to work (e.g., one can install bidi and complex script // languages, but only install the Thai keyboard). if (!isKeyboardBidi()) return false; Callback callback = null; try { callback = new Callback (Class.forName (CLASS_NAME), "EnumSystemLanguageGroupsProc", 5); int lpEnumSystemLanguageGroupsProc = callback.getAddress (); if (lpEnumSystemLanguageGroupsProc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); OS.EnumSystemLanguageGroups(lpEnumSystemLanguageGroupsProc, OS.LGRPID_INSTALLED, 0); callback.dispose (); } catch (ClassNotFoundException e) { if (callback != null) callback.dispose(); } if (isBidiPlatform == 1) return true; // need to look at system code page for NT & 98 platforms since EnumSystemLanguageGroups is // not supported for these platforms String codePage = String.valueOf(OS.GetACP()); if (CD_PG_ARABIC.equals(codePage) || CD_PG_HEBREW.equals(codePage)) { isBidiPlatform = 1; } return isBidiPlatform == 1;}/** * Return whether or not the keyboard supports input of a bidi language. Determine this * by looking at the languages that are installed for the keyboard. * <p> * * @return true if bidi is supported, false otherwise. */public static boolean isKeyboardBidi() { int[] list = getKeyboardLanguageList(); for (int i=0; i<list.length; i++) { int id = list[i] & 0x000000FF; if ((id == LANG_ARABIC) || (id == LANG_HEBREW)) { return true; } } return false;}/** * Removes the specified language listener. * <p> * * @param hwnd the handle of the Control that is listening for keyboard language changes */public static void removeLanguageListener (int hwnd) { languageMap.remove(new Integer(hwnd)); unsubclass(hwnd);} /** * Switch the keyboard language to the specified language type. We do * not distinguish between mulitple bidi or multiple non-bidi languages, so * set the keyboard to the first language of the given type. * <p> * * @param language integer representing language. One of * KEYBOARD_BIDI, KEYBOARD_NON_BIDI. */public static void setKeyboardLanguage(int language) { // don't switch the keyboard if it doesn't need to be if (language == getKeyboardLanguage()) return; if (language == KEYBOARD_BIDI) { // get the list of active languages int[] list = getKeyboardLanguageList(); // set to first bidi language for (int i=0; i<list.length; i++) { int id = list[i] & 0x000000FF; if ((id == LANG_ARABIC) || (id == LANG_HEBREW)) { OS.ActivateKeyboardLayout(list[i], 0); return; } } } else { // get the list of active languages int[] list = getKeyboardLanguageList(); // set to the first non-bidi language (anything not // hebrew or arabic) for (int i=0; i<list.length; i++) { int id = list[i] & 0x000000FF; if ((id != LANG_HEBREW) && (id != LANG_ARABIC)) { OS.ActivateKeyboardLayout(list[i], 0); return; } } }}/** * Sets the orientation (writing order) of the specified control. Text will * be right aligned for right to left writing order. * <p> * * @param hwnd the handle of the Control to change the orientation of * @param orientation one of SWT.RIGHT_TO_LEFT or SWT.LEFT_TO_RIGHT * @return true if the orientation was changed, false if the orientation * could not be changed */public static boolean setOrientation (int hwnd, int orientation) { if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) return false; int bits = OS.GetWindowLong (hwnd, OS.GWL_EXSTYLE); if ((orientation & SWT.RIGHT_TO_LEFT) != 0) { bits |= OS.WS_EX_LAYOUTRTL; } else { bits &= ~OS.WS_EX_LAYOUTRTL; } OS.SetWindowLong (hwnd, OS.GWL_EXSTYLE, bits); return true;}/** * Override the window proc. * * @param hwnd control to override the window proc of */static void subclass(int hwnd) { Integer key = new Integer(hwnd); if (oldProcMap.get(key) == null) { int oldProc = OS.GetWindowLong(hwnd, OS.GWL_WNDPROC); oldProcMap.put(key, new Integer(oldProc)); OS.SetWindowLong(hwnd, OS.GWL_WNDPROC, callback.getAddress()); }}/** * Reverse the character array. Used for right orientation. * * @param charArray character array to reverse */static void reverse(char[] charArray) { int length = charArray.length; for (int i = 0; i <= (length - 1) / 2; i++) { char tmp = charArray[i]; charArray[i] = charArray[length - 1 - i]; charArray[length - 1 - i] = tmp; }} /** * Reverse the integer array. Used for right orientation. * * @param intArray integer array to reverse */static void reverse(int[] intArray) { int length = intArray.length; for (int i = 0; i <= (length - 1) / 2; i++) { int tmp = intArray[i]; intArray[i] = intArray[length - 1 - i]; intArray[length - 1 - i] = tmp; }} /** * Adjust the order array so that it is relative to the start of the line. Also reverse the order array if the orientation * is to the right. * * @param orderArray integer array of order values to translate * @param glyphCount number of glyphs that have been processed for the current line * @param isRightOriented flag indicating whether or not current orientation is to the right*/static void translateOrder(int[] orderArray, int glyphCount, boolean isRightOriented) { int maxOrder = 0; int length = orderArray.length; if (isRightOriented) { for (int i=0; i<length; i++) { maxOrder = Math.max(maxOrder, orderArray[i]); } } for (int i=0; i<length; i++) { if (isRightOriented) orderArray[i] = maxOrder - orderArray[i]; orderArray [i] += glyphCount; }}/** * Remove the overridden the window proc. * * @param hwnd control to remove the window proc override for */static void unsubclass(int hwnd) { Integer key = new Integer(hwnd); if (languageMap.get(key) == null && keyMap.get(key) == null) { Integer proc = (Integer) oldProcMap.remove(key); if (proc == null) return; OS.SetWindowLong(hwnd, OS.GWL_WNDPROC, proc.intValue()); } }/** * Window proc to intercept keyboard language switch event (WS_INPUTLANGCHANGE) * and widget orientation changes. * Run the Control's registered runnable when the keyboard language is switched. * * @param hwnd handle of the control that is listening for the keyboard language * change event * @param msg window message */static int windowProc (int hwnd, int msg, int wParam, int lParam) { Integer key = new Integer (hwnd); switch (msg) { case 0x51 /*OS.WM_INPUTLANGCHANGE*/: Runnable runnable = (Runnable) languageMap.get (key); if (runnable != null) runnable.run (); break; } Integer oldProc = (Integer)oldProcMap.get(key); return OS.CallWindowProc (oldProc.intValue(), hwnd, msg, wParam, lParam);}}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -