Example usage for com.google.gwt.canvas.dom.client Context2d fillText

List of usage examples for com.google.gwt.canvas.dom.client Context2d fillText

Introduction

In this page you can find the example usage for com.google.gwt.canvas.dom.client Context2d fillText.

Prototype

public final native void fillText(String text, double x, double y) ;

Source Link

Document

Draws filled text.

Usage

From source file:org.catrobat.html5player.client.Scene.java

License:Open Source License

/**
 *
 * @param text//  ww w .ja  va 2  s.  c o  m
 * @param x
 * @param y
 */
public void write(String text, double x, double y) {
    Context2d context = sceneCanvas.getContext2d();
    context.fillText(text, x, y);
}

From source file:org.catrobat.html5player.client.Scene.java

License:Open Source License

/**
 *
 * @param text/*from w  w  w  . j a  v  a 2s  .  c  o  m*/
 * @param x
 * @param y
 * @param align
 */
public void write(String text, double x, double y, String align) {
    Context2d context = sceneCanvas.getContext2d();
    context.setTextAlign(align);
    context.fillText(text, x, y);
}

From source file:org.oscim.gdx.client.GwtCanvas.java

License:Open Source License

@Override
public void drawText(String string, float x, float y, Paint fill, Paint stroke) {
    if (bitmap == null) {
        //log.debug("no bitmap set");
        return;/*w  w  w .  ja v a  2s. c o m*/
    }

    GwtPaint p = (GwtPaint) fill;

    if (p.stroke && GwtGdxGraphics.NO_STROKE_TEXT)
        return;

    Context2d ctx = bitmap.pixmap.getContext();
    ctx.setFont(p.font);

    if (p.stroke) {
        ctx.setLineWidth(p.strokeWidth);
        ctx.setStrokeStyle(p.color);
        ctx.strokeText(string, (int) (x + 1), (int) (y + 1));
    } else {
        ctx.setFillStyle(p.color);
        ctx.fillText(string, (int) (x + 1), (int) (y + 1));
    }
}

From source file:org.rstudio.core.client.widget.FontDetector.java

License:Open Source License

public static boolean isFontSupported(String fontName) {
    SimplePanel panel = null;//from   w w  w .  j  a v  a  2 s .  c  o m
    try {
        // default font name as a reference point
        final String defaultFontName = "Arial";
        if (defaultFontName.equals(fontName))
            return true;

        // make sure canvas is supported
        if (!Canvas.isSupported())
            return false;

        // add a temporary div to the dom
        panel = new SimplePanel();
        panel.setHeight("200px");
        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);
        String fontHash = hashGenerator.getHash(fontName);
        return !defaultHash.equals(fontHash);
    } catch (Exception ex) {
        Debug.log(ex.toString());
        return false;
    } finally {
        if (panel != null)
            RootPanel.get().remove(panel);
    }
}

From source file:playn.html.HtmlTextLayout.java

License:Apache License

void fill(Context2d ctx, float x, float y) {
    configContext(ctx);//  www . j  ava 2s  .  c  om
    float ypos = 0;
    for (Line line : lines) {
        ctx.fillText(line.text, x + format.align.getX(line.width, width), y + ypos);
        ypos += metrics.height;
    }
}

From source file:playn.html.OldHtmlTextLayout.java

License:Apache License

public void fill(Context2d ctx, float x, float y) {
    configContext(ctx);//from w ww . j ava 2s.  com
    float ypos = 0;
    for (Line line : lines) {
        ctx.fillText(line.text, x + format.align.getX(line.width, width), y + ypos);
        ypos += metrics.height;
    }
}

From source file:stroom.pipeline.structure.client.view.PipelineElementRenderer.java

License:Apache License

private void drawText(final Context2d ctx, final double x, final double y, final PipelineElement element) {
    final CssColor fill = CssColor.make(textColor);

    ctx.setFont(font);/*from ww  w .  j a  v a  2  s . c  o m*/
    ctx.setTextAlign(TextAlign.LEFT);
    ctx.setFillStyle(fill);
    ctx.fillText(element.getId(), x, y);
}

From source file:stroom.widget.htree.client.TextCellRenderer.java

License:Apache License

private void drawText(final Context2d ctx, final Bounds bounds, final String text) {
    final CssColor fill = CssColor.make(textColor);

    ctx.setFont(font);//ww w. ja  v a2s .c o m
    ctx.setTextAlign(TextAlign.LEFT);
    ctx.setFillStyle(fill);
    ctx.fillText(text, bounds.getX() + textPadding, bounds.getY() + textPadding + textSize - 1);
}