Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 64867 Details for
Bug 181166
There should be an api to check if a character is defined in a font
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some code to check if a glyph exists for a given char
Main.java (text/plain), 4.86 KB, created by
Rob McKay
on 2007-04-25 09:55:42 EDT
(
hide
)
Description:
Some code to check if a glyph exists for a given char
Filename:
MIME Type:
Creator:
Rob McKay
Created:
2007-04-25 09:55:42 EDT
Size:
4.86 KB
patch
obsolete
>package checkIfCharExistsInFont; > >/** > * Test code for windows Font.canDisplay(char c) > * > * @author Rob McKay > */ > >import org.eclipse.swt.SWT; >import org.eclipse.swt.graphics.Font; >import org.eclipse.swt.graphics.GC; >import org.eclipse.swt.internal.win32.OS; >import org.eclipse.swt.internal.win32.SCRIPT_ANALYSIS; >import org.eclipse.swt.internal.win32.SCRIPT_CONTROL; >import org.eclipse.swt.internal.win32.SCRIPT_FONTPROPERTIES; >import org.eclipse.swt.internal.win32.SCRIPT_ITEM; >import org.eclipse.swt.internal.win32.SCRIPT_STATE; >import org.eclipse.swt.layout.RowLayout; >import org.eclipse.swt.widgets.Display; >import org.eclipse.swt.widgets.Label; >import org.eclipse.swt.widgets.Shell; > > >public class Main >{ > >private static final int maxGlyphs = 10; > >/** > * Checks if this <code>Font</code> has a glyph for the specified character. > * > * @param font - the font to check > * @param c - the character for which a glyph is needed > * @return <code>true</code> if this Font has a glyph for this character; <code>false</code> otherwise. > */ > >static boolean canDisplay(Font font, char c) >{ > GC gc = new GC(Display.getCurrent()); > > OS.SelectObject(gc.handle, font.handle); > > SCRIPT_CONTROL control = new SCRIPT_CONTROL(); > SCRIPT_STATE state = new SCRIPT_STATE(); > > state.uBidiLevel = 0; > state.fOverrideDirection = true; > state.fInhibitSymSwap = true; > > int hHeap = OS.GetProcessHeap(); > int psc = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, 4); > > SCRIPT_FONTPROPERTIES sfp = new SCRIPT_FONTPROPERTIES(); > sfp.cBytes = SCRIPT_FONTPROPERTIES.sizeof; > > int result = OS.ScriptGetFontProperties(gc.handle, psc, sfp); > > if (result != OS.S_OK) > return false; > > int pItems = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * SCRIPT_ITEM.sizeof); > int[] pcItems = new int[1]; > char[] chars = new char[1]; > chars[0] = c; > pcItems[0] = 0; > > result = OS.ScriptItemize(chars, chars.length, maxGlyphs, control, state, pItems, pcItems); > > if (result != OS.S_OK || pcItems[0] < 1) > { > OS.HeapFree(hHeap, 0, pItems); > OS.ScriptFreeCache(psc); > OS.HeapFree(hHeap, 0, psc); > gc.dispose(); > return false; > } > > SCRIPT_ITEM scriptItem = new SCRIPT_ITEM(); > scriptItem.a = new SCRIPT_ANALYSIS(); > > OS.MoveMemory(scriptItem, pItems, SCRIPT_ITEM.sizeof); > OS.HeapFree(hHeap, 0, pItems); > > int glyphs = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * 2); > int clusters = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * 2); > int visAttrs = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * 2); > int[] buffer = new int[1]; > > result = OS.ScriptShape(gc.handle, psc, chars, chars.length, maxGlyphs, scriptItem.a, glyphs, clusters, visAttrs, buffer); > > OS.ScriptFreeCache(psc); > > short i[] = new short[1]; > OS.MoveMemory(i, glyphs, 2); > > OS.HeapFree(hHeap, 0, glyphs); > OS.HeapFree(hHeap, 0, clusters); > OS.HeapFree(hHeap, 0, visAttrs); > OS.HeapFree(hHeap, 0, psc); > > gc.dispose(); > > if (buffer[0] == 0) > return false; > > if (result != OS.S_OK) > return false; > > return i[0] != sfp.wgDefault; >} > >static void addLabels(Shell shell, Font f1) >{ > boolean isSpcDefined = canDisplay(f1, ' '); > boolean isSup9Defined = canDisplay(f1, '\u2079'); > boolean is3dAngleDefined = canDisplay(f1, '\u27c0'); > > Label l = new Label(shell, SWT.NONE); > l.setText(f1.getFontData()[0].getName()); > l.setFont(f1); > > for (char a = 'a'; a <= 'c'; a++) > { > l = new Label(shell, SWT.NONE); > l.setText("" + a + " = " + canDisplay(f1, a)); > l.setFont(f1); > } > l = new Label(shell, SWT.NONE); > l.setText("<spc> = " + isSpcDefined); > l.setFont(f1); > l = new Label(shell, SWT.NONE); > l.setText("<sup>9 (\u2079) = " + isSup9Defined); > l.setFont(f1); > l = new Label(shell, SWT.NONE); > l.setText("<3D Angle> (\u27c0) = " + is3dAngleDefined); > l.setFont(f1); > > l = new Label(shell, SWT.NONE); > l.setText("<divide> (\u00f7) = " + canDisplay(f1, '\u00f7')); > l.setFont(f1); > > l = new Label(shell, SWT.NONE); > l.setText("<lte> (\u2264) = " + canDisplay(f1, '\u2264')); > l.setFont(f1); > > l = new Label(shell, SWT.NONE); >} > >/** > * @param args > */ >public static void main(String[] args) >{ > Display.setAppName("Font test"); > Display display = new Display(); > > Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED); > shell.setText("Font character test"); > shell.setLayout(new RowLayout(SWT.VERTICAL)); > > Font f1 = display.getSystemFont(); //new Font(display, "Arial", 12, SWT.NORMAL); > addLabels(shell,f1); > > f1 = new Font(display, "Arial", 10, SWT.NORMAL); > addLabels(shell,f1); > > f1 = new Font(display, "Arial Unicode MS", 10, SWT.NORMAL); > addLabels(shell,f1); > > f1 = new Font(display, "Lucida Sans Unicode", 10, SWT.NORMAL); > addLabels(shell,f1); > > shell.open(); > while (!shell.isDisposed()) > { > if (!display.readAndDispatch()) > display.sleep(); > } > display.dispose(); > System.exit(0); > >} > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 181166
: 64867