-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WordCram Fails in "Android" mode #9
Comments
Interesting, I haven't tried running it on Android yet. Time to roll up my sleeves! It's been a while since I tried to remove Processing from WordCram, but as I remember it, the places I couldn't (easily) remove Processing were pretty essential. Re: Android, I assumed WordCram would run on it, since I'd read all the good news about Processing on Android, but there are some old AWT bits in there. |
Thanks for the quick reply! If I can be helpful in getting this to run on Android, please let me know how I can help. |
I just started looking into this. It might be tougher than I thought. WordCram turns each word into a java.awt.Shape, so it can create a bounding-box tree for collision detection. (It used to not use java.awt.*, but that was godawful slow - if I rememeber right, it was rendering the font to a bitmap & looking at the pixels.) To turn a String-and-a-Font into a Shape, it uses the FontRenderContext - look at WordShaper.java for the details. FontRenderContext, and apparently java.awt.* in general, aren't supported on Android. So I'm kind of back to the drawing board for supporting Android. It looks like I'm not the only one: http://stackoverflow.com/questions/11516543/how-to-draw-the-glyph-on-canvas-from-ttf-file Having no Android expertise myself, if you know how to do this, that'd be a tremendous help! 😄 |
Yep, this is part of why I asked about removing processing from wordcram. In Android, I think the way to do it is using android.graphics.Rect, so the general solution is probably to have a Shape-like class in WordCram source that we can initialize from android.graphics.Rect or awt.Shape depending on the platform. Another issue is the font options in Android. From http://wiki.processing.org/w/Android :
method for retrieving the bounding box: http://developer.android.com/reference/android/graphics/Paint.html#getTextBounds(java.lang.String, int, int, android.graphics.Rect). Paint p = new Paint();
p.setTypeface(Typeface.DEFAULT); //not fully reliable what fonts are installed on a phone, but can include .ttf/.otf files
p.setSize(fontSize);
Rect r = new Rect();
p.getTextBounds(word, 0,0, r);
return new WCShape(r); //WCShape represents the WordCram Shape object that I mentioned above Is this helpful? |
When running the Hello World in "java" mode, no problems at all, but the following exception is thrown for "android" mode, probably because java.awt.font.FontRenderContext isn't included in Android.
FATAL EXCEPTION: Animation Thread
java.lang.NoClassDefFoundError: java.awt.font.FontRenderContext
at wordcram.WordShaper.(WordShaper.java:29)
at wordcram.WordCram.getWordCramEngine(WordCram.java:740)
at wordcram.WordCram.drawAll(WordCram.java:781)
at processing.test.helloworld.helloworld.setup(helloworld.java:40)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:856)
Not knowing much about the structure of WordCram, how much of the code would be reusable for a standalone (non-processing-based) Android word cloud library?
The text was updated successfully, but these errors were encountered: