boolean isRightOriented = OS.GetLayout(gc.handle) != 0;
boolean isRightOriented = false; if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) >= (4 << 16 | 10)) { isRightOriented = OS.GetLayout(gc.handle) != 0; }
public static char[] getRenderInfo(GC gc, String text, int[] order, byte[] classBuffer, int[] dx, int flags, int [] offsets) {	int fontLanguageInfo = OS.GetFontLanguageInfo(gc.handle);	int hHeap = OS.GetProcessHeap();	int[] lpCs = new int[8];	int cs = OS.GetTextCharset(gc.handle);	boolean isRightOriented = OS.GetLayout(gc.handle) != 0; 	OS.TranslateCharsetInfo(cs, lpCs, OS.TCI_SRCCHARSET);	TCHAR textBuffer = new TCHAR(lpCs[1], text, false);	int byteCount = textBuffer.length();	boolean linkBefore = (flags & LINKBEFORE) == LINKBEFORE;	boolean linkAfter = (flags & LINKAFTER) == LINKAFTER;	GCP_RESULTS result = new GCP_RESULTS();	result.lStructSize = GCP_RESULTS.sizeof;	result.nGlyphs = byteCount;	int lpOrder = result.lpOrder = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount * 4);	int lpDx = result.lpDx = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount * 4);	int lpClass = result.lpClass = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount);	int lpGlyphs = result.lpGlyphs = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount * 2);	// set required dwFlags	int dwFlags = 0;	int glyphFlags = 0;	// Always reorder.  We assume that if we are calling this function we're	// on a platform that supports bidi.  Fixes 20690.	dwFlags |= GCP_REORDER;	if ((fontLanguageInfo & GCP_LIGATE) == GCP_LIGATE) {		dwFlags |= GCP_LIGATE;		glyphFlags |= 0;	}	if ((fontLanguageInfo & GCP_GLYPHSHAPE) == GCP_GLYPHSHAPE) {		dwFlags |= GCP_GLYPHSHAPE;		if (linkBefore) {			glyphFlags |= GCPGLYPH_LINKBEFORE;		}		if (linkAfter) {			glyphFlags |= GCPGLYPH_LINKAFTER;		}	}	byte[] lpGlyphs2;	if (linkBefore || linkAfter) {		lpGlyphs2 = new byte[2];		lpGlyphs2[0]=(byte)glyphFlags;		lpGlyphs2[1]=(byte)(glyphFlags >> 8);	}	else {		lpGlyphs2 = new byte[] {(byte) glyphFlags};	}	OS.MoveMemory(result.lpGlyphs, lpGlyphs2, lpGlyphs2.length);	if ((flags & CLASSIN) == CLASSIN) {		// set classification values for the substring		dwFlags |= GCP_CLASSIN;		OS.MoveMemory(result.lpClass, classBuffer, classBuffer.length);	}	char[] glyphBuffer = new char[result.nGlyphs];	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 (dx != null) {			int [] dx2 = new int [result.nGlyphs];			OS.MoveMemory(dx2, result.lpDx, dx2.length * 4);			if (isRightOriented) { 				reverse(dx2);			} 			System.arraycopy (dx2, 0, dx, glyphCount, dx2.length);		}		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);		}		char[] glyphBuffer2 = new char[result.nGlyphs];		OS.MoveMemory(glyphBuffer2, result.lpGlyphs, glyphBuffer2.length * 2);		if (isRightOriented) {			reverse(glyphBuffer2);		} 		System.arraycopy (glyphBuffer2, 0, glyphBuffer, glyphCount, glyphBuffer2.length);		glyphCount += glyphBuffer2.length;		// 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.lpDx += length * 4;		result.lpClass += length;		result.lpGlyphs += glyphBuffer2.length * 2;	}	/* Free the memory that was allocated. */	OS.HeapFree(hHeap, 0, lpGlyphs);	OS.HeapFree(hHeap, 0, lpClass);	OS.HeapFree(hHeap, 0, lpDx);	OS.HeapFree(hHeap, 0, lpOrder);	return glyphBuffer;}