* Rasterize the glyphs of <code>text</code>.
* @returns <code>(width<<32)|height</code>
*/
- public long rasterizeGlyphs(String text, PixelBuffer pb, int textcolor, int x, int y, int cx1, int cy1, int cx2, int cy2) {
- return rasterizeGlyphs(text, pb, textcolor, x, y, cx1, cy1, cx2, cy2, 0); }
- public long rasterizeGlyphs(String text, PixelBuffer pb, int textcolor, int x, int y,
- int cx1, int cy1, int cx2, int cy2, int bg) {
+ public String rasterizeGlyphs(String text) {
+ StringBuffer path = new StringBuffer(text.length() * 50);
+ for(int i=0; i<text.length(); i++) {
+ final char c = text.charAt(i);
+ Glyph g = glyphs[c];
+ if (g == null) glyphs[c] = g = Platform.createGlyph(this, c);
+ g.render();
+ path.append(g.path);
+ }
+ return path.toString();
+ }
+ public long rasterizeGlyphs(String text, PixelBuffer pb, Affine a, Mesh h, int fg, int bg) {
int width = 0, height = 0;
if (!latinCharsPreloaded) { // preload the Latin-1 charset with low priority (we'll probably want it)
for(int i=48; i<57; i++) if(glyphs[i]==null) toBeRasterized.append(glyphs[i]=Platform.createGlyph(this, (char)i));
for(int i=57; i<128; i++) if(glyphs[i]==null) toBeRasterized.append(glyphs[i]=Platform.createGlyph(this, (char)i));
latinCharsPreloaded = true;
}
+ a = a==null ? null : a.copy();
for(int i=0; i<text.length(); i++) {
final char c = text.charAt(i);
Glyph g = glyphs[c];
if (g == null) glyphs[c] = g = Platform.createGlyph(this, c);
g.render();
- if (pb != null) pb.drawGlyph(g,
- x + width,
- y + g.font.max_ascent - g.baseline,
- x+width,
- cy1,
- x+width+g.advance,
- cy2,
- textcolor, bg);
+ if (a!=null) a.premultiply(Affine.translate(0, g.font.max_ascent - g.baseline));
+ if (pb != null) pb.drawGlyph(g, a, h, fg, bg);
+ if (a!=null) a.premultiply(Affine.translate(0, -1 * (g.font.max_ascent - g.baseline)));
width += g.advance;
+ if (a!=null) a.premultiply(Affine.translate(g.advance, 0));
height = java.lang.Math.max(height, max_ascent + max_descent);
}
return ((((long)width) << 32) | (long)(height & 0xffffffffL));
public long textsize(String s) {
Long l = (Long)sizeCache.get(s);
if (l != null) return ((Long)l).longValue();
- long ret = rasterizeGlyphs(s, null, 0, 0, 0, 0, 0, 0, 0);
+ long ret = rasterizeGlyphs(s, null, null, null, 0, 0);
sizeCache.put(s, new Long(ret));
return ret;
}
public Glyph getGlyph(char c) {
- rasterizeGlyphs(c+"", null, 0, 0, 0, 0, 0, 0, 0);
+ rasterizeGlyphs(c+"", null, null, null, 0, 0);
Glyph g = glyphs[c];
g.render();
return g;
public interface PixelBuffer {
public abstract void drawLine(int x1, int y1, int x2, int y2, int color);
public abstract void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color);
- public abstract void drawPicture(Picture p, int x, int y, int x1, int y1, int w, int h); // names may be wrong
- public abstract void drawGlyph(Font.Glyph source, int dx1, int dy1, int cx1, int cy1, int cx2, int cy2, int rgb, int bg);
+ public abstract void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int color);
+ public abstract void drawPicture(Picture p, Affine a, Mesh h);
+ public abstract void drawGlyph(Font.Glyph source, Affine a, Mesh h, int rgb, int bg);
public abstract void stroke(Polygon p, int color);
public abstract void fill(Polygon p, Paint paint);
}
if (y+h > root.height) h = root.height - y;
if (w <= 0 || h <= 0) continue;
- root.render(x, y, x + w, y + h, this.getPixelBuffer(), identity);
- getPixelBuffer().drawPicture(scarImage, 0, root.height - scarImage.height, x, y, x+w, y+h);
+ // FIXME: set clip to -- x, y, x + w, y + h,
+ root.render(this.getPixelBuffer(), identity);
+ //getPixelBuffer().drawPicture(scarImage, 0, root.height - scarImage.height, x, y, x+w, y+h);
if (abort) {
// x,y,w,h is only partially reconstructed, so we must be careful not to re-blit it
DirtyList screenDirtyRegions = new DirtyList();
public PixelBuffer getPixelBuffer() { return this; }
+ public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int argb) {
+ backbuffer.fillTriangle(x1, y1, x2, y2, x3, y3, argb);
+ }
+ public void drawPicture(Picture p, Affine a, Mesh h) {
+ throw new Error("drawPicture() not implemented");
+ }
+ public void drawGlyph(Font.Glyph source,Affine a,Mesh h,int rgb,int bg) {
+ //screenDirtyRegions.dirty(cx1, cy1, cx2 - cx1, cy2 - cy1);
+ backbuffer.drawGlyph(source, a, h, rgb, bg);
+ }
+ /*
public void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) {
screenDirtyRegions.dirty(cx1, cy1, cx2 - cx1, cy2 - cy1);
backbuffer.drawPicture(source, dx, dy, cx1, cy1, cx2, cy2);
}
public void drawGlyph(Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int argb, int bc) {
- screenDirtyRegions.dirty(cx1, cy1, cx2 - cx1, cy2 - cy1);
- backbuffer.drawGlyph(source, dx, dy, cx1, cy1, cx2, cy2, argb, bc);
}
-
+ */
public void stroke(Polygon p, int color) {
// FIXME
}
protected void postInit() {
if (Log.on) Log.diag(Platform.class, " color depth = " +
- Toolkit.getDefaultToolkit().getColorModel().getPixelSize() + "bpp");
- }
+ Toolkit.getDefaultToolkit().getColorModel().getPixelSize() + "bpp"); }
protected void _criticalAbort(String message) {
if (Log.on) Log.info(this, message);
protected static class AWTPixelBuffer implements PixelBuffer {
+ private int[] xpoints = new int[3];
+ private int[] ypoints = new int[3];
+ public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int argb) {
+ xpoints[0] = x1;
+ xpoints[1] = x2;
+ xpoints[2] = x3;
+ ypoints[0] = y1;
+ ypoints[1] = y2;
+ ypoints[2] = y3;
+ Graphics g = getGraphics();
+ g.setColor(new java.awt.Color((argb & 0x00ff0000) >> 16,
+ (argb & 0x0000ff00) >> 8,
+ argb & 0x000000ff/*,
+ (argb & 0xff000000) >> 24*/));
+ g.fillPolygon(xpoints, ypoints, 3);
+ }
+
+ public void drawPicture(Picture p, Affine a, Mesh h) { throw new Error("drawPicture() not implemented"); }
protected Image i = null;
protected Graphics g = null;
protected AWTSurface surface = null;
}
// this doens't seem to work on Windows
- public void drawGlyph(org.ibex.graphics.Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2,
- int rgb, int argb) {
+ public void drawGlyph(org.ibex.graphics.Font.Glyph source,Affine a,Mesh h,int rgb,int bg) {
+ //throw new Error("drawGlyph() not implemented");
+ /*
Image i = ((AWTGlyph)source).getImage();
if (((AWTGlyph)source).i2 == null)
((AWTGlyph)source).i2 = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB);
g.fillRect(dx+i2.getWidth(null), cy1, cx2 - (dx+i2.getWidth(null)), cy2 - cy1);
g.fillRect(cx1, dy+i2.getHeight(null), cx2 - cx1, cy2 - (dy+i2.getHeight(null)));
g.setClip(0, 0, 1000, 1000);
+ */
}
}
private static GeneralPath gp = new GeneralPath();
// this doens't seem to work on Windows
- public void drawGlyph(org.ibex.graphics.Font.Glyph source, Affine a, Hull h, int rgb, int bg) {
+ public void drawGlyph(org.ibex.graphics.Font.Glyph source, Affine a, Mesh h, int rgb, int bg) {
Image i = ((AWTGlyph)source).getImage();
Image i2 = ((AWTGlyph)source).i2;
if (((AWTGlyph)source).i2 == null) {
public static abstract class GLPixelBuffer implements PixelBuffer {
protected int width;
protected int height;
+ public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int argb) { throw new Error("not implemented"); }
+ public void drawPicture(Picture p, Affine a, Mesh h) { throw new Error("drawPicture() not implemented"); }
+ public void drawGlyph(Font.Glyph source,Affine a,Mesh h,int rgb,int bg) { throw new Error("drawGlyph() not implemented"); }
public int getWidth() { return width; }
public int getHeight() { return height; }
// Win32PixelBuffer //////////////////////////////////////////////////////////////////////////
public static class Win32PixelBuffer implements PixelBuffer {
+ public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int argb) { throw new Error("not implemented"); }
+
+ public void drawPicture(Picture p, Affine a, Mesh h) { throw new Error("drawPicture() not implemented"); }
+ public void drawGlyph(Font.Glyph source,Affine a,Mesh h,int rgb,int bg) { throw new Error("drawGlyph() not implemented"); }
public void drawLine(int x1, int y1, int x2, int y2, int color) { }
public void drawGlyph(Font.Glyph source, int dx1, int dy1, int cx1, int cy1, int cx2, int cy2, int rgb, int pc){}
* (since they are only written to once.
*/
public static class X11PixelBuffer implements PixelBuffer {
+ public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int argb) { throw new Error("not implemented"); }
+
+ public void drawPicture(Picture p, Affine a, Mesh h) { throw new Error("drawPicture() not implemented"); }
+ public void drawGlyph(Font.Glyph source,Affine a,Mesh h,int rgb,int bg) { throw new Error("drawGlyph() not implemented"); }
public void drawLine(int x1, int y1, int x2, int y2, int color) { }
public void drawGlyph(Font.Glyph source, int dx1, int dy1, int cx1, int cy1, int cx2, int cy2, int rgb, int pc){}