/** * Loads the font specified by a file. The font will be present in the list of fonts available to * the application. * * @param path the font file path * @return whether the font was successfully loaded * @exception SWTException * <ul> * <li>ERROR_NULL_ARGUMENT - if path is null * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed * </ul> * * @see Font * @since 3.3 */ public boolean loadFont(String path) { checkDevice(); if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); int length = path.length(); char[] buffer = new char[length + 1]; path.getChars(0, length, buffer, 0); int str = OS.gcnew_String(buffer); int uri = OS.gcnew_Uri(str, OS.UriKind_RelativeOrAbsolute); int list = OS.Fonts_GetTypefaces(uri); int count = OS.TypefaceCollection_Count(list); OS.GCHandle_Free(list); OS.GCHandle_Free(uri); OS.GCHandle_Free(str); return count != 0; }
/** * Throws an <code>SWTException</code> if the receiver can not be accessed by the caller. This may * include both checks on the state of the receiver and more generally on the entire execution * context. This method <em>should</em> be called by device implementors to enforce the standard * SWT invariants. * * <p>Currently, it is an error to invoke any method (other than <code>isDisposed()</code> and * <code>dispose()</code>) on a device that has had its <code>dispose()</code> method called. * * <p>In future releases of SWT, there may be more or fewer error checks and exceptions may be * thrown for different reasons. * * <p> * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * </ul> */ protected void checkDevice() { if (disposed) SWT.error(SWT.ERROR_DEVICE_DISPOSED); }