當前位置: 首頁>>代碼示例>>Java>>正文


Java Context2d.fillText方法代碼示例

本文整理匯總了Java中com.google.gwt.canvas.dom.client.Context2d.fillText方法的典型用法代碼示例。如果您正苦於以下問題:Java Context2d.fillText方法的具體用法?Java Context2d.fillText怎麽用?Java Context2d.fillText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.gwt.canvas.dom.client.Context2d的用法示例。


在下文中一共展示了Context2d.fillText方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: drawText

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
@Override
public void drawText(String string, float x, float y, Paint fill, Paint stroke) {
	if (bitmap == null) {
		//log.debug("no bitmap set");
		return;
	}

	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));
	}
}
 
開發者ID:opensciencemap,項目名稱:vtm,代碼行數:25,代碼來源:GwtCanvas.java

示例2: drawTics

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
public void drawTics(int count, int len, long factor, String unit) {
	Context2d context = canvas.getContext2d();

	context.setFillStyle(color);
	context.setStrokeStyle(color);

	for (int i = 1; i <= count; i++) {
		context.beginPath();
		context.moveTo(len * i, 0);
		context.lineTo(len * i, 15);
		context.closePath();
		context.stroke();

		context.fillText((i * factor) + unit, len * i, 25, 20);
	}
}
 
開發者ID:metafora-project,項目名稱:ReflectionTool,代碼行數:17,代碼來源:Timeline.java

示例3: measureHeight

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
private static int measureHeight(Font font, String text) {
  Canvas canvas = canvas();
  Context2d ctx = canvas.getContext2d();

  ctx.setFont(getFontString(font));
  ctx.setFillStyle("rgb(255, 0, 0)");

  int width = (int) ctx.measureText(text).getWidth();
  int canvasHeight = font.getSize() * 2;
  canvas.setHeight(canvasHeight + "px");
  canvas.setHeight(font.getSize() * 2 + "px");
  canvas.setWidth(width + "px");

  ctx.fillText(text, 0, font.getSize());
  ImageData data = ctx.getImageData(0, 0, width, canvasHeight);
  int firstY = canvasHeight - 1;
  int lastY = 0;
  for (int x = 0; x < width; x++) {
    for (int y = 0; y < canvasHeight; y++) {
      int red = data.getRedAt(x, y);
      if (red != 0) {
        if (firstY > y) {
          firstY = y;
        }
        if (lastY < y) {
          lastY = y;
        }
      }
    }
  }
  return lastY - firstY;
}
 
開發者ID:JetBrains,項目名稱:jetpad-projectional-open-source,代碼行數:33,代碼來源:TextMetricsCalculator.java

示例4: draw

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
@Override
public void draw(Context2d context, DisplayArea area, OnDrawnCallback cb) {
    double zoom = area.zoom();
    context.save();

    context.translate(-area.viewportLeft(), -area.viewportTop());
    context.scale(zoom, zoom);

    // outline
    int[][] coords = el.coordinates();

    context.beginPath();
    context.moveTo(coords[0][0], coords[0][1]);

    for (int i = 1; i < coords.length; i++) {
        context.lineTo(coords[i][0], coords[i][1]);
    }

    context.setLineWidth(6);
    context.stroke();
    
    context.setGlobalAlpha(0.3);
    context.setFillStyle("white");
    context.fill();
    context.setGlobalAlpha(1.0);
    
    context.closePath();

    // text
    context.setFillStyle("black");
    context.setFont("bold 60px sans-serif");
    context.setTextBaseline("top");
    context.fillText(el.text(), el.baseLeft(), el.baseTop(), el.baseWidth());

    context.restore();
    
    cb.onDrawn();
}
 
開發者ID:jhu-digital-manuscripts,項目名稱:rosa,代碼行數:39,代碼來源:TextDrawable.java

示例5: renderText

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
private void renderText(Context2d g) {
  if (null != text) {
    g.setTextAlign(TextAlign.LEFT);
    g.setTextBaseline(TextBaseline.MIDDLE);
    g.setFont("bold 18px sans-serif");
    g.setFillStyle("#000");
    g.fillText(text, 10, height / 2);
  }
}
 
開發者ID:cjmalloy,項目名稱:GwtGameUi,代碼行數:10,代碼來源:DefaultDragButtonSkin.java

示例6: render

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
@Override
public void render(Context2d g, double timestamp) {
  g.save();
  {
    if (textClip == TextClip.HIDDEN) {
      g.beginPath();
      g.rect(0, 0, width, height);
      g.clip();
    }
    setTextAlign(g, textAlign, width);
    setTextBaseline(g, textBaseline, height);
    g.setFont(font);
    g.setTextAlign(textAlign);
    g.setTextBaseline(textBaseline);
    g.setFillStyle(color);

    String text = this.text;
    if (textClip == TextClip.ELLIPSE) {
      text = fitEllipse(g, text, width);
    }
    if (textClip == TextClip.FIT) {
      g.fillText(text, 0, 0, width);
    } else {
      g.fillText(text, 0, 0);
    }
  }
  g.restore();
}
 
開發者ID:cjmalloy,項目名稱:GwtGameUi,代碼行數:29,代碼來源:TextRenderer.java

示例7: fill

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
void fill(Context2d ctx, float x, float y) {
  configContext(ctx, format);
  ctx.fillText(text, x, y);
}
 
開發者ID:playn,項目名稱:playn,代碼行數:5,代碼來源:HtmlTextLayout.java

示例8: drawString

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
private void drawString(Context2d ctx,String theString, double x, double y)
{
    ctx.setTextAlign(Context2d.TextAlign.CENTER);
    ctx.setTextBaseline(Context2d.TextBaseline.MIDDLE);
    ctx.fillText(theString, x, y);
}
 
開發者ID:cheminfo,項目名稱:openchemlib-js,代碼行數:7,代碼來源:MoleculeDrawDepictor.java

示例9: draw

import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
@Override
public void draw(Context2d context, DisplayArea area, OnDrawnCallback cb) {
	double zoom = area.zoom();
	context.save();
	
	context.translate(-area.viewportLeft(), -area.viewportTop());
	context.scale(zoom, zoom);
	
	// Draw outline
	int[][] coords = el.coordinates();
	
	context.beginPath();
	context.moveTo(coords[0][0], coords[0][1]);
	
	for (int i = 1; i < coords.length; i++) {
		context.lineTo(coords[i][0], coords[i][1]);
	}
	
	context.setLineWidth(6);
	context.stroke();
	
	context.setGlobalAlpha(0.3);
	context.setFillStyle("white");
	context.fill();
	context.setGlobalAlpha(1.0);
	
	context.closePath();
	
	// Write text
	context.setFillStyle("black");
	context.setFont("bold 60px sans-serif");
	context.setTextBaseline("top");
	
	if (el.text().contains("<") && el.text().contains(">")) {
		context.fillText(el.label() + "...", el.baseLeft(), el.baseTop(), el.baseWidth());
		el.neverShowPopup(false);
	} else {
		String[] words = el.text().split(" ");
		String line = "";
		
		int y = el.baseTop();
		
		for (int i = 0; i < words.length; i++) {
			String test_line = line + words[i] + " ";
			
			if (context.measureText(test_line).getWidth() > el.baseWidth() && i > 0
					|| words[i].contains("\n")) {
				context.fillText(line, el.baseLeft(), y);
				y += step;
				line = words[i] + " ";
				
				if (y + step > el.baseTop() + el.baseHeight()) {
    				context.restore();
    				el.neverShowPopup(false);
    				cb.onDrawn();
    				return;
    			}
			} else {
				line = test_line;
			}
		}
		context.fillText(line, el.baseLeft(), y);
		el.neverShowPopup(true);
	}
	context.restore();
	
	cb.onDrawn();
}
 
開發者ID:jhu-digital-manuscripts,項目名稱:rosa,代碼行數:69,代碼來源:MultiLineTextDrawable.java


注:本文中的com.google.gwt.canvas.dom.client.Context2d.fillText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。