diff --git a/core/PFont.java b/core/PFont.java index af8fea6a2..3883e0114 100644 --- a/core/PFont.java +++ b/core/PFont.java @@ -530,6 +530,8 @@ public class PFont implements PConstants { */ } else { // SCREEN_SPACE + parent.loadPixels(); + int xx = (int) x + leftExtent[glyph];; int yy = (int) y - topExtent[glyph]; @@ -583,6 +585,7 @@ public class PFont implements PConstants { (( a1 * fb + a2 * ( p2 & 0xff)) >> 8)); } } + parent.updatePixels(); } } diff --git a/core/PGraphics.java b/core/PGraphics.java index 621844a56..e78ba826b 100644 --- a/core/PGraphics.java +++ b/core/PGraphics.java @@ -1442,8 +1442,10 @@ public class PGraphics extends PImage implements PConstants { public void textFont(PFont which) { if (which != null) { textFont = which; - //textFont.resetSize(); - //textFont.resetLeading(); + + if (textSpace == SCREEN_SPACE) { + textSize(textFont.mbox); + } } else { throw new RuntimeException("a null PFont was passed to textFont()"); @@ -1451,10 +1453,20 @@ public class PGraphics extends PImage implements PConstants { } + /** + * Sets the text size, also resets the value for the leading. + */ public void textSize(float size) { if (textFont != null) { + if ((textSpace == SCREEN_SPACE) && + (size != textFont.mbox)) { + throw new RuntimeException("can't use textSize() with " + + "textSpace(SCREEN_SPACE)"); + } textSize = size; - textLeadingReset(); + textLeading = textSize * + ((textFont.ascent() + textFont.descent()) * 1.275f); + //textLeadingReset(); } else { throw new RuntimeException("use textFont() before textSize()"); @@ -1462,10 +1474,10 @@ public class PGraphics extends PImage implements PConstants { } - protected void textLeadingReset() { - textLeading = textSize * - ((textFont.ascent() + textFont.descent()) * 1.275f); - } + //protected void textLeadingReset() { + //textLeading = textSize * + // ((textFont.ascent() + textFont.descent()) * 1.275f); + //} public void textLeading(float leading) { @@ -1495,15 +1507,18 @@ public class PGraphics extends PImage implements PConstants { public void textSpace(int space) { - textSpace = space; - /* if (textFont != null) { - textFont.space(space); + textSpace = space; + + // reset the font to its natural size + // (helps with width calculations and all that) + if (textSpace == SCREEN_SPACE) { + textSize(textFont.mbox); + } } else { throw new RuntimeException("use textFont() before textSpace()"); } - */ } @@ -1854,7 +1869,7 @@ public class PGraphics extends PImage implements PConstants { // avoid infinite loop if (Float.isNaN(big) || Float.isInfinite(big)) { - big = 8; // set to something arbitrary + big = 1000000; // set to something arbitrary } int d = 1; diff --git a/core/PGraphics2.java b/core/PGraphics2.java index 703955ccf..05ec2c786 100644 --- a/core/PGraphics2.java +++ b/core/PGraphics2.java @@ -865,7 +865,10 @@ public class PGraphics2 extends PGraphics { //check_image_cache(image); // blit image to the screen //graphics.drawImage((BufferedImage) image.cache, 0, 0, null); + push(); + resetMatrix(); imageImpl(image, 0, 0, width, height, 0, 0, width, height); + pop(); } @@ -904,6 +907,9 @@ public class PGraphics2 extends PGraphics { public void loadPixels() { + if ((pixels == null) || (pixels.length != width * height)) { + pixels = new int[width * height]; + } ((BufferedImage) image).getRGB(0, 0, width, height, pixels, 0, width); } diff --git a/core/PGraphics3.java b/core/PGraphics3.java index 7fc924929..3c175199b 100644 --- a/core/PGraphics3.java +++ b/core/PGraphics3.java @@ -2190,6 +2190,12 @@ public class PGraphics3 extends PGraphics { max(abs(m22), abs(m23))), max(max(abs(m30), abs(m31)), max(abs(m32), abs(m33)))))); + + // avoid infinite loop + if (Float.isNaN(big) || Float.isInfinite(big)) { + big = 1000000; // set to something arbitrary + } + int d = 1; while ((big /= 10) != 0) d++; // cheap log() @@ -2401,6 +2407,12 @@ public class PGraphics3 extends PGraphics { max(abs(p22), abs(p23))), max(max(abs(p30), abs(p31)), max(abs(p32), abs(p33)))))); + + // avoid infinite loop + if (Float.isNaN(big) || Float.isInfinite(big)) { + big = 1000000; // set to something arbitrary + } + int d = 1; while ((big /= 10) != 0) d++; // cheap log() diff --git a/core/todo.txt b/core/todo.txt index 1f9293db3..dbe2dbab0 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -7,6 +7,8 @@ X backwards rects and backwards ellipses weren't properly drawn X code now compensates for negative widths or swapped x1/x2 X fix noLoop() not properly running X also fix redraw() to include interrupt() again +X loadPixels throwing NPEs +X fixes to SCREEN_SPACE text not being sized properly X made loadStrings() and openStream(File) static again _ fix other stuff that's supposed to be static @@ -21,10 +23,12 @@ _ get SCREEN_SPACE text working again _ rewrite library/howto.txt for to get rid of old interface +_ how to shut off rendering to screen when illustrator in use? +_ need size(30000, 20000) for illustrator, problem in papplet + _ problem with flicker may be the lack of synchronization on g _ updatePixels() not setting PApplet.pixels -_ also throwing NPEs _ make loadPixels in PGraphics ignored, and put it in PApplet _ closing window w/o first hitting stop() causes freak out