package ssq; import org.eclipse.swt.internal.motif.*; import org.eclipse.swt.internal.Converter; public class SystemFontTest { public static void main(String[] arguments) { OS.XtToolkitInitialize (); int [] argc = new int [] {0}; int xtContext = OS.XtCreateApplicationContext (); int xDisplay = OS.XtOpenDisplay (xtContext, null, null, null, 0, 0, argc, 0); int widgetClass = OS.TopLevelShellWidgetClass (); int shellHandle = OS.XtAppCreateShell (null, null, widgetClass, xDisplay, null, 0); int widgetHandle = OS.XmCreateLabel (shellHandle, null, null, 0); OS.XtManageChild (widgetHandle); OS.XtSetMappedWhenManaged (shellHandle, false); OS.XtRealizeWidget (shellHandle); int [] argList = {OS.XmNfontList, 0}; OS.XtGetValues (widgetHandle, argList, argList.length / 2); int fontList = OS.XmFontListCopy (argList [1]); OS.XtDestroyWidget (shellHandle); System.out.println("XmLabel*fontList=" + fontList); if (fontList == 0) return; int[] buffer = new int[1]; if (!OS.XmFontListInitFontContext(buffer, fontList)) { System.out.println("BAD 1"); return; } int context = buffer[0]; XFontStruct fontStruct = new XFontStruct(); int fontListEntry; int[] fontStructPtr = new int[1]; int[] fontNamePtr = new int[1]; String[] xlfds = new String[0]; /* Go through each entry in the font list */ while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) { int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer); if (buffer[0] == OS.XmFONT_IS_FONT) { /* FontList contains a single font */ OS.memmove(fontStruct,fontPtr,20 * 4); int propPtr = fontStruct.properties; for (int i = 0; i < fontStruct.n_properties; i++) { /* Reef through properties looking for XAFONT */ int[] prop = new int[2]; OS.memmove(prop, propPtr, 8); if (prop[0] == OS.XA_FONT) { /* Found it, prop[1] points to the string */ int ptr = OS.XmGetAtomName(xDisplay, prop[1]); int length = OS.strlen(ptr); byte[] nameBuf = new byte[length]; OS.memmove(nameBuf, ptr, length); /* Use the character encoding for the default locale */ String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase(); System.out.println("fonttruct xlfd=" + xlfds.length + "->" + xlfd); /* Add the xlfd to the array */ String[] newXlfds = new String[xlfds.length + 1]; System.arraycopy(xlfds, 0, newXlfds, 0, xlfds.length); newXlfds[newXlfds.length - 1] = xlfd; xlfds = newXlfds; OS.XtFree(ptr); break; } propPtr += 8; } } else { /* FontList contains a fontSet */ int nFonts = OS.XFontsOfFontSet(fontPtr,fontStructPtr,fontNamePtr); int [] fontStructs = new int[nFonts]; int [] fontName = new int [1]; OS.memmove(fontStructs,fontStructPtr[0],nFonts * 4); for (int i = 0; i < nFonts; i++) { // Go through each fontStruct in the font set. OS.memmove(fontName, fontNamePtr [0] + (i * 4), 4); OS.memmove(fontStruct,fontStructs[i],20 * 4); if (true) { int ptr = fontName [0]; int length = OS.strlen(ptr); byte[] nameBuf = new byte[length]; OS.memmove(nameBuf, ptr, length); String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase(); System.out.println("fontName-" + i + "=" + xlfd); } int propPtr = fontStruct.properties; for (int j = 0; j < fontStruct.n_properties; j++) { // Reef through properties looking for XAFONT int[] prop = new int[2]; OS.memmove(prop, propPtr, 8); if (prop[0] == OS.XA_FONT) { /* Found it, prop[1] points to the string */ int ptr = OS.XmGetAtomName(xDisplay, prop[1]); int length = OS.strlen(ptr); byte[] nameBuf = new byte[length]; OS.memmove(nameBuf, ptr, length); String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase(); System.out.println("fontset xlfd=" + xlfds.length + "->" + xlfd); /* Add the xlfd to the array */ String[] newXlfds = new String[xlfds.length + 1]; System.arraycopy(xlfds, 0, newXlfds, 0, xlfds.length); newXlfds[newXlfds.length - 1] = xlfd; xlfds = newXlfds; OS.XFree(ptr); break; } propPtr += 8; } } } } OS.XmFontListFreeFontContext(context); OS.XmFontListFree (fontList); System.out.println("length=" + xlfds.length); } }