Skip to content
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

Open
jwiese opened this issue Sep 21, 2012 · 4 comments
Open

WordCram Fails in "Android" mode #9

jwiese opened this issue Sep 21, 2012 · 4 comments

Comments

@jwiese
Copy link

jwiese commented Sep 21, 2012

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?

@danbernier
Copy link
Owner

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.

@jwiese
Copy link
Author

jwiese commented Sep 24, 2012

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.

@danbernier
Copy link
Owner

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! 😄

@jwiese
Copy link
Author

jwiese commented Oct 9, 2012

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 :

Using createFont() (instead of loadFont()) can help improve text quality, particularly with 2D rendering. Use PFont.list() to get a list of available fonts on the system, and select one of those, or include a .ttf or .otf file in the data directory of your sketch.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants