| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3848,7 +3848,7 @@ public PFont createFont(String name, float size, | |||
| 3848 | 3848 | AssetManager assets = getBaseContext().getAssets(); | |
| 3849 | 3849 | baseFont = Typeface.createFromAsset(assets, name); | |
| 3850 | 3850 | } else { | |
| 3851 | - baseFont = PFont.findTypeface(name); | ||
| 3851 | + baseFont = (Typeface) PFont.findNative(name); | ||
| 3852 | 3852 | } | |
| 3853 | 3853 | return new PFont(baseFont, round(size), smooth, charset); | |
| 3854 | 3854 | } | |
@@ -8976,8 +8976,8 @@ public boolean isGL() { | |||
| 8976 | 8976 | } | |
| 8977 | 8977 | ||
| 8978 | 8978 | ||
| 8979 | - public Bitmap getBitmap() { | ||
| 8980 | - return g.getBitmap(); | ||
| 8979 | + public Object getNative() { | ||
| 8980 | + return g.getNative(); | ||
| 8981 | 8981 | } | |
| 8982 | 8982 | ||
| 8983 | 8983 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -118,10 +118,10 @@ public class PFont implements PConstants { | |||
| 118 | 118 | /** | |
| 119 | 119 | * True if this font should return 'null' for getFont(), so that the native | |
| 120 | 120 | * font will be used to create a subset, but the native version of the font | |
| 121 | - * will not be used. | ||
| 121 | + * will not be used. | ||
| 122 | 122 | */ | |
| 123 | - protected boolean subsetting; | ||
| 124 | - | ||
| 123 | + protected boolean subsetting; | ||
| 124 | + | ||
| 125 | 125 | /** | |
| 126 | 126 | * True if we've already tried to find the native version of this font. | |
| 127 | 127 | */ | |
@@ -133,18 +133,18 @@ public class PFont implements PConstants { | |||
| 133 | 133 | * bug that they can't be bothered to fix. | |
| 134 | 134 | */ | |
| 135 | 135 | static protected Typeface[] typefaces; | |
| 136 | - | ||
| 136 | + | ||
| 137 | 137 | // objects to handle creation of font characters only as they're needed | |
| 138 | 138 | Bitmap lazyBitmap; | |
| 139 | 139 | Canvas lazyCanvas; | |
| 140 | 140 | Paint lazyPaint; | |
| 141 | 141 | // FontMetrics lazyMetrics; | |
| 142 | 142 | int[] lazySamples; | |
| 143 | - | ||
| 143 | + | ||
| 144 | 144 | /** for subclasses that need to store metadata about the font */ | |
| 145 | - protected HashMap<PGraphics, Object> cacheMap; | ||
| 146 | - | ||
| 147 | - | ||
| 145 | + protected HashMap<PGraphics, Object> cacheMap; | ||
| 146 | + | ||
| 147 | + | ||
| 148 | 148 | public PFont() { } // for subclasses | |
| 149 | 149 | ||
| 150 | 150 | ||
@@ -212,7 +212,7 @@ public PFont(Typeface font, int size, boolean smooth, char charset[]) { | |||
| 212 | 212 | ||
| 213 | 213 | if (charset == null) { | |
| 214 | 214 | lazy = true; | |
| 215 | - | ||
| 215 | + | ||
| 216 | 216 | } else { | |
| 217 | 217 | // charset needs to be sorted to make index lookup run more quickly | |
| 218 | 218 | // http://dev.processing.org/bugs/show_bug.cgi?id=494 | |
@@ -317,7 +317,7 @@ public PFont(InputStream input) throws IOException { | |||
| 317 | 317 | } | |
| 318 | 318 | } | |
| 319 | 319 | ||
| 320 | - | ||
| 320 | + | ||
| 321 | 321 | /** | |
| 322 | 322 | * Write this PFont to an OutputStream. | |
| 323 | 323 | * <p> | |
@@ -408,20 +408,20 @@ public String getName() { | |||
| 408 | 408 | return name; | |
| 409 | 409 | } | |
| 410 | 410 | ||
| 411 | - | ||
| 411 | + | ||
| 412 | 412 | /** | |
| 413 | 413 | * Return size of this font. | |
| 414 | 414 | */ | |
| 415 | 415 | public int getSize() { | |
| 416 | 416 | return size; | |
| 417 | 417 | } | |
| 418 | - | ||
| 418 | + | ||
| 419 | 419 | ||
| 420 | 420 | public void setSubsetting() { | |
| 421 | 421 | subsetting = true; | |
| 422 | 422 | } | |
| 423 | 423 | ||
| 424 | - | ||
| 424 | + | ||
| 425 | 425 | public String getPostScriptName() { | |
| 426 | 426 | return psname; | |
| 427 | 427 | } | |
@@ -430,15 +430,15 @@ public String getPostScriptName() { | |||
| 430 | 430 | /** | |
| 431 | 431 | * Set the native complement of this font. | |
| 432 | 432 | */ | |
| 433 | - public void setTypeface(Typeface typeface) { | ||
| 434 | - this.typeface = typeface; | ||
| 433 | + public void setNative(Object typeface) { | ||
| 434 | + this.typeface = (Typeface) typeface; | ||
| 435 | 435 | } | |
| 436 | 436 | ||
| 437 | 437 | ||
| 438 | 438 | /** | |
| 439 | 439 | * Return the native Typeface object associated with this PFont (if any). | |
| 440 | 440 | */ | |
| 441 | - public Typeface getTypeface() { | ||
| 441 | + public Typeface getNative() { | ||
| 442 | 442 | if (subsetting) { | |
| 443 | 443 | return null; | |
| 444 | 444 | } | |
@@ -450,7 +450,7 @@ public Typeface getTypeface() { | |||
| 450 | 450 | * Attempt to find the native version of this font. | |
| 451 | 451 | * (Public so that it can be used by OpenGL or other renderers.) | |
| 452 | 452 | */ | |
| 453 | - static public Typeface findTypeface(String name) { | ||
| 453 | + static public Object findNative(String name) { | ||
| 454 | 454 | loadTypefaces(); | |
| 455 | 455 | return typefaceMap.get(name); | |
| 456 | 456 | } | |
@@ -564,14 +564,14 @@ public float width(char c) { | |||
| 564 | 564 | ////////////////////////////////////////////////////////////// | |
| 565 | 565 | ||
| 566 | 566 | // METADATA REQUIRED BY THE RENDERERS | |
| 567 | - | ||
| 567 | + | ||
| 568 | 568 | ||
| 569 | 569 | /** | |
| 570 | 570 | * Store data of some kind for a renderer that requires extra metadata of | |
| 571 | 571 | * some kind. Usually this is a renderer-specific representation of the | |
| 572 | 572 | * font data, for instance a custom OpenGL texture for PGraphicsOpenGL2. | |
| 573 | 573 | * @param renderer The PGraphics renderer associated to the font | |
| 574 | - * @param storage The metadata required by the renderer | ||
| 574 | + * @param storage The metadata required by the renderer | ||
| 575 | 575 | */ | |
| 576 | 576 | public void setCache(PGraphics renderer, Object storage) { | |
| 577 | 577 | if (cacheMap == null) cacheMap = new HashMap<PGraphics, Object>(); | |
@@ -601,22 +601,22 @@ public void removeCache(PGraphics renderer) { | |||
| 601 | 601 | if (cacheMap != null) { | |
| 602 | 602 | cacheMap.remove(renderer); | |
| 603 | 603 | } | |
| 604 | - } | ||
| 605 | - | ||
| 606 | - | ||
| 607 | - ////////////////////////////////////////////////////////////// | ||
| 608 | - | ||
| 604 | + } | ||
| 605 | + | ||
| 606 | + | ||
| 607 | + ////////////////////////////////////////////////////////////// | ||
| 608 | + | ||
| 609 | 609 | public int getGlyphCount() { | |
| 610 | 610 | return glyphCount; | |
| 611 | 611 | } | |
| 612 | - | ||
| 612 | + | ||
| 613 | 613 | public Glyph getGlyph(int i) { | |
| 614 | - return glyphs[i]; | ||
| 615 | - } | ||
| 616 | - | ||
| 614 | + return glyphs[i]; | ||
| 615 | + } | ||
| 616 | + | ||
| 617 | 617 | ////////////////////////////////////////////////////////////// | |
| 618 | 618 | ||
| 619 | - | ||
| 619 | + | ||
| 620 | 620 | static final char[] EXTRA_CHARS = { | |
| 621 | 621 | 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, | |
| 622 | 622 | 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, | |
@@ -725,7 +725,7 @@ static public void loadTypefaces() { | |||
| 725 | 725 | } | |
| 726 | 726 | } | |
| 727 | 727 | ||
| 728 | - | ||
| 728 | + | ||
| 729 | 729 | ///////////////////////////////////////////////////////////// | |
| 730 | 730 | ||
| 731 | 731 | /** | |
@@ -736,7 +736,7 @@ public class Glyph { | |||
| 736 | 736 | public int value; | |
| 737 | 737 | public int height; | |
| 738 | 738 | public int width; | |
| 739 | - public int index; | ||
| 739 | + public int index; | ||
| 740 | 740 | public int setWidth; | |
| 741 | 741 | public int topExtent; | |
| 742 | 742 | public int leftExtent; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1120,7 +1120,7 @@ public PShape loadShape(String filename) { | |||
| 1120 | 1120 | @Override | |
| 1121 | 1121 | public void textFont(PFont which) { | |
| 1122 | 1122 | super.textFont(which); | |
| 1123 | - fillPaint.setTypeface(which.getTypeface()); | ||
| 1123 | + fillPaint.setTypeface(which.getNative()); | ||
| 1124 | 1124 | } | |
| 1125 | 1125 | ||
| 1126 | 1126 | ||
@@ -1151,7 +1151,7 @@ public void textSize(float size) { | |||
| 1151 | 1151 | defaultFontOrDeath("textSize", size); | |
| 1152 | 1152 | } | |
| 1153 | 1153 | ||
| 1154 | - Typeface font = textFont.getTypeface(); | ||
| 1154 | + Typeface font = textFont.getNative(); | ||
| 1155 | 1155 | if (font != null) { | |
| 1156 | 1156 | fillPaint.setTextSize(size); | |
| 1157 | 1157 | } | |
@@ -1184,7 +1184,7 @@ protected void endTextScreenMode() { | |||
| 1184 | 1184 | @Override | |
| 1185 | 1185 | protected float textWidthImpl(char buffer[], int start, int stop) { | |
| 1186 | 1186 | // Font font = textFont.getFont(); | |
| 1187 | - Typeface font = textFont.getTypeface(); | ||
| 1187 | + Typeface font = textFont.getNative(); | ||
| 1188 | 1188 | if (font == null) { | |
| 1189 | 1189 | return super.textWidthImpl(buffer, start, stop); | |
| 1190 | 1190 | } | |
@@ -1217,7 +1217,7 @@ protected float textWidthImpl(char buffer[], int start, int stop) { | |||
| 1217 | 1217 | @Override | |
| 1218 | 1218 | protected void textLineImpl(char buffer[], int start, int stop, | |
| 1219 | 1219 | float x, float y) { | |
| 1220 | - Typeface font = textFont.getTypeface(); | ||
| 1220 | + Typeface font = textFont.getNative(); | ||
| 1221 | 1221 | if (font == null) { | |
| 1222 | 1222 | showWarning("Inefficient font rendering: use createFont() with a TTF/OTF instead of loadFont()."); | |
| 1223 | 1223 | //new Exception().printStackTrace(System.out); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -168,28 +168,20 @@ protected void checkAlpha() { | |||
| 168 | 168 | * Construct a new PImage from an Android bitmap. The pixels[] array is not | |
| 169 | 169 | * initialized, nor is data copied to it, until loadPixels() is called. | |
| 170 | 170 | */ | |
| 171 | - public PImage(Bitmap image) { | ||
| 172 | - this.bitmap = image; | ||
| 173 | - this.width = image.getWidth(); | ||
| 174 | - this.height = image.getHeight(); | ||
| 171 | + public PImage(Object nativeObject) { | ||
| 172 | + Bitmap bitmap = (Bitmap) nativeObject; | ||
| 173 | + this.bitmap = bitmap; | ||
| 174 | + this.width = bitmap.getWidth(); | ||
| 175 | + this.height = bitmap.getHeight(); | ||
| 175 | 176 | this.pixels = null; | |
| 176 | - this.format = image.hasAlpha() ? ARGB : RGB; | ||
| 177 | + this.format = bitmap.hasAlpha() ? ARGB : RGB; | ||
| 177 | 178 | } | |
| 178 | 179 | ||
| 179 | 180 | ||
| 180 | 181 | /** | |
| 181 | - * Returns a BufferedImage from this PImage. | ||
| 182 | + * Returns the native Bitmap object for this PImage. | ||
| 182 | 183 | */ | |
| 183 | - // public java.awt.Image getImage() { | ||
| 184 | - // loadPixels(); | ||
| 185 | - // int type = (format == RGB) ? | ||
| 186 | - // BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB; | ||
| 187 | - // BufferedImage image = new BufferedImage(width, height, type); | ||
| 188 | - // WritableRaster wr = image.getRaster(); | ||
| 189 | - // wr.setDataElements(0, 0, width, height, pixels); | ||
| 190 | - // return image; | ||
| 191 | - // } | ||
| 192 | - public Bitmap getBitmap() { | ||
| 184 | + public Object getNative() { | ||
| 193 | 185 | return bitmap; | |
| 194 | 186 | } | |
| 195 | 187 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,7 +46,7 @@ | |||
| 46 | 46 | * over several textures. | |
| 47 | 47 | * @author Andres Colubri | |
| 48 | 48 | */ | |
| 49 | - class PFontTexture implements PConstants { | ||
| 49 | + class FontTexture implements PConstants { | ||
| 50 | 50 | protected PApplet parent; | |
| 51 | 51 | protected PGraphicsOpenGL pg; | |
| 52 | 52 | protected PGL pgl; | |
@@ -65,7 +65,7 @@ class PFontTexture implements PConstants { | |||
| 65 | 65 | protected TextureInfo[] glyphTexinfos; | |
| 66 | 66 | protected HashMap<PFont.Glyph, TextureInfo> texinfoMap; | |
| 67 | 67 | ||
| 68 | - public PFontTexture(PApplet parent, PFont font, int maxw, int maxh, | ||
| 68 | + public FontTexture(PApplet parent, PFont font, int maxw, int maxh, | ||
| 69 | 69 | boolean is3D) { | |
| 70 | 70 | this.parent = parent; | |
| 71 | 71 | this.font = font; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,6 +43,10 @@ public class PGraphicsOpenGL extends PGraphics { | |||
| 43 | 43 | /** The renderer currently in use. */ | |
| 44 | 44 | protected static PGraphicsOpenGL pgCurrent = null; | |
| 45 | 45 | ||
| 46 | + /** Font cache for texture objects. */ | ||
| 47 | + protected WeakHashMap<PFont, FontTexture> fontMap = | ||
| 48 | + new WeakHashMap<PFont, FontTexture>(); | ||
| 49 | + | ||
| 46 | 50 | /** Additional image parameters not covered by the cache. */ | |
| 47 | 51 | protected WeakHashMap<PImage, Object> paramMap = | |
| 48 | 52 | new WeakHashMap<PImage, Object>(); | |
@@ -353,7 +357,7 @@ public class PGraphicsOpenGL extends PGraphics { | |||
| 353 | 357 | // Text: | |
| 354 | 358 | ||
| 355 | 359 | /** Font texture of currently selected font. */ | |
| 356 | - PFontTexture textTex; | ||
| 360 | + FontTexture textTex; | ||
| 357 | 361 | ||
| 358 | 362 | // ....................................................... | |
| 359 | 363 | ||
@@ -610,6 +614,24 @@ protected void setFlushMode(int mode) { | |||
| 610 | 614 | } | |
| 611 | 615 | ||
| 612 | 616 | ||
| 617 | + ////////////////////////////////////////////////////////////// | ||
| 618 | + | ||
| 619 | + | ||
| 620 | + protected void setFontTexture(PFont font, FontTexture fontTexture) { | ||
| 621 | + fontMap.put(font, fontTexture); | ||
| 622 | + } | ||
| 623 | + | ||
| 624 | + | ||
| 625 | + protected FontTexture getFontTexture(PFont font) { | ||
| 626 | + return fontMap.get(font); | ||
| 627 | + } | ||
| 628 | + | ||
| 629 | + | ||
| 630 | + protected void removeFontTexture(PFont font) { | ||
| 631 | + fontMap.remove(font); | ||
| 632 | + } | ||
| 633 | + | ||
| 634 | + | ||
| 613 | 635 | ////////////////////////////////////////////////////////////// | |
| 614 | 636 | ||
| 615 | 637 | /** | |
@@ -1654,8 +1676,8 @@ public void beginDraw() { | |||
| 1654 | 1676 | if (texture != null) { | |
| 1655 | 1677 | // The screen texture should be deleted because it | |
| 1656 | 1678 | // corresponds to the old window size. | |
| 1657 | - removeCache(pgPrimary); | ||
| 1658 | - removeParams(pgPrimary); | ||
| 1679 | + pgPrimary.removeCache(this); | ||
| 1680 | + pgPrimary.removeParams(this); | ||
| 1659 | 1681 | texture = null; | |
| 1660 | 1682 | loadTexture(); | |
| 1661 | 1683 | } | |
@@ -3507,17 +3529,17 @@ protected boolean textModeCheck(int mode) { | |||
| 3507 | 3529 | @Override | |
| 3508 | 3530 | protected void textLineImpl(char buffer[], int start, int stop, | |
| 3509 | 3531 | float x, float y) { | |
| 3510 | - textTex = (PFontTexture)textFont.getCache(pgPrimary); | ||
| 3532 | + textTex = pgPrimary.getFontTexture(textFont); | ||
| 3511 | 3533 | if (textTex == null) { | |
| 3512 | - textTex = new PFontTexture(parent, textFont, maxTextureSize, | ||
| 3534 | + textTex = new FontTexture(parent, textFont, maxTextureSize, | ||
| 3513 | 3535 | maxTextureSize, is3D()); | |
| 3514 | - textFont.setCache(pgPrimary, textTex); | ||
| 3536 | + pgPrimary.setFontTexture(textFont, textTex); | ||
| 3515 | 3537 | } else { | |
| 3516 | 3538 | if (textTex.contextIsOutdated()) { | |
| 3517 | - textTex = new PFontTexture(parent, textFont, | ||
| 3539 | + textTex = new FontTexture(parent, textFont, | ||
| 3518 | 3540 | PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize), | |
| 3519 | 3541 | PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize), is3D()); | |
| 3520 | - textFont.setCache(pgPrimary, textTex); | ||
| 3542 | + pgPrimary.setFontTexture(textFont, textTex); | ||
| 3521 | 3543 | } | |
| 3522 | 3544 | } | |
| 3523 | 3545 | textTex.begin(); | |
@@ -3569,7 +3591,7 @@ protected void textCharImpl(char ch, float x, float y) { | |||
| 3569 | 3591 | PFont.Glyph glyph = textFont.getGlyph(ch); | |
| 3570 | 3592 | ||
| 3571 | 3593 | if (glyph != null) { | |
| 3572 | - PFontTexture.TextureInfo tinfo = textTex.getTexInfo(glyph); | ||
| 3594 | + FontTexture.TextureInfo tinfo = textTex.getTexInfo(glyph); | ||
| 3573 | 3595 | ||
| 3574 | 3596 | if (tinfo == null) { | |
| 3575 | 3597 | // Adding new glyph to the font texture. | |
@@ -3593,7 +3615,7 @@ protected void textCharImpl(char ch, float x, float y) { | |||
| 3593 | 3615 | } | |
| 3594 | 3616 | ||
| 3595 | 3617 | ||
| 3596 | - protected void textCharModelImpl(PFontTexture.TextureInfo info, | ||
| 3618 | + protected void textCharModelImpl(FontTexture.TextureInfo info, | ||
| 3597 | 3619 | float x0, float y0, | |
| 3598 | 3620 | float x1, float y1) { | |
| 3599 | 3621 | if (textTex.currentTex != info.texIndex) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,6 @@ | |||
| 1 | 1 | 0209 android | |
| 2 | + A GL android sketch stops running after rotation | ||
| 3 | + A http://code.google.com/p/processing/issues/detail?id=1146 | ||
| 2 | 4 | ||
| 3 | 5 | ||
| 4 | 6 | _ inside AndroidPreprocessor | |
| Back | FazBrowse Home | New Git URL |
0 commit comments