panel.getElement().getStyle().setVisibility(Visibility.HIDDEN);
panel.getElement().getStyle().setOverflow(Overflow.SCROLL);
RootPanel.get().add(panel, -2000, -2000);
// add a canvas element to the div and get the 2d drawing context
final Canvas canvas = Canvas.createIfSupported();
canvas.setWidth("512px");
canvas.setHeight("64px");
canvas.getElement().getStyle().setLeft(400, Unit.PX);
canvas.getElement().getStyle().setBackgroundColor("#ffe");
panel.add(canvas);
final Context2d ctx = canvas.getContext2d();
ctx.setFillStyle("#000000");
// closure to generate a hash for a font
class HashGenerator {
public String getHash(String fontName)
{
ctx.setFont("57px " + fontName + ", " + defaultFontName);
int width = canvas.getOffsetWidth();
int height = canvas.getOffsetHeight();
ctx.clearRect(0, 0, width, height);
ctx.fillText("TheQuickBrownFox", 2, 50);
return canvas.toDataUrl();
}};
// get hashes and compare them
HashGenerator hashGenerator = new HashGenerator();
String defaultHash = hashGenerator.getHash(defaultFontName);