My favorites | Sign in
Project Home Downloads Issues Source
Project Information
Members

Provide the ability of drawing text using GWTCanvas.

The jars are compatible with GWT 2.0 and 2.1 (and probably with 1.6)

Add the following into your gwt.xml project file:

	<inherits name='com.google.gwt.widgetideas.GWTCanvas'/>
	<inherits name='com.swtoolbox.canvasfont.SWTBCanvasFont'/>
	<inherits name='com.swtb.font.SWTBFont'/>

Do not forget to add the following jars in the build path:

The supplied font called Simplex has been created from the font of the same name you can find at URL: http://local.wasp.uwa.edu.au/~pbourke/dataformats/hershey/ We shall thank the creator and contributors to have released these fonts in the public domain.

Example:

package com.swtb.fontexample.client;

import com.google.gwt.core.client.EntryPoint;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class SWTBFontExample implements EntryPoint {
	
	Simplex simplex = new Simplex();
	
	public void onModuleLoad() {
		RootPanel rootPanel = RootPanel.get();

		SWTBCanvasText canvas = new SWTBCanvasText(800, 600);
		rootPanel.add(canvas);
		
		canvas.setFont(simplex);
		
		canvas.saveContext();
		canvas.beginPath();
		canvas.textTo("Hello world!", 20.0, 380.0, 0.0, 2.0);
		canvas.stroke();
		canvas.restoreContext();
		
		canvas.saveContext();
		canvas.setLineWidth(2.0);
		canvas.beginPath();
		canvas.textTo("This should be in bold", 20.0, 60.0, 0.0, 1.0);
		canvas.stroke();
		canvas.restoreContext();
		
		canvas.saveContext();
		canvas.setItalic(true);
		canvas.beginPath();
		canvas.textTo("This should be in italic", 20.0, 100.0, 0.0, 1.0);
		canvas.stroke();
		canvas.restoreContext();
		
		canvas.saveContext();
		canvas.setItalic(true);
		canvas.setLineWidth(2.0);
		canvas.beginPath();
		canvas.textTo("This should be in bold and italic", 20, 140, 0.0, 1.0);
		canvas.stroke();
		canvas.restoreContext();
		
		canvas.saveContext();
		canvas.beginPath();
		canvas.moveTo(20, 180);
		canvas.textTo("This should be normal", 20, 180, 0.0, 1.0);
		canvas.stroke();
		canvas.restoreContext();
		
		canvas.saveContext();
		canvas.setItalic(true);
		canvas.setLineWidth(1.25);
		canvas.beginPath();
		canvas.textTo("Diagonal going up", 50, 580, Math.toRadians(30), 0.75);
		canvas.stroke();
		canvas.restoreContext();
		
		canvas.saveContext();
		canvas.setItalic(true);
		canvas.setLineWidth(1.25);
		canvas.beginPath();
		canvas.textTo("Diagonal going down", 50, 220, Math.toRadians(-30), 0.75);
		canvas.stroke();
		canvas.restoreContext();
		
	}
}

The above code will produce the following image:

----

For further information see the Javadoc included into swtbcanvasfont-0.2.jar

Powered by Google Project Hosting