Tuesday, November 27, 2012

Fonts Revisited

Fonts are were a painful subject in Codename One, historically devices supported a very limited set of fonts and we were bound by said limitations. However, devices moved forward and finally we too can move forward to more reasonable font support.

The new font API is limited to Android & iOS, we were considering RIM support too but it seems that the font support on RIM is too limited for our needs (feel free to correct me if I'm wrong here), on the other platforms a standard system font will be used where fonts aren't supported.

In order to use a font just add the ttf file into the src directory, notice that the file must have the ".ttf" extension otherwise the build server won't be able to recognize the file as a font and set it up accordingly (devices need fonts to be defined in very specific ways). Once you do that you can use the font from code or from the theme.

In the theme section of the Codename One designer you now have the option to define the font like this:

The system font will be used where True Type fonts aren't supported, the size of the font can be one of 5 options.
Small, medium & large correspond to the 3 system font sizes and occupy the exact same sizes of the system fonts.
Millimeters & pixels will size the fonts appropriately using the numeric field.

To use fonts from code just use:
        if(Font.isTrueTypeFileSupported()) {
            Font myFont = Font.createTrueTypeFont(fontName, fontFileName);
            myFont = myFont.derive(sizeInPixels, Font.STYLE_PLAIN);
            // do something with the font
        }
Notice that in code only pixel sizes are supported so its up to you to decide how to convert that. You also need to derive the font with the proper size unless you want a 0 sized font which probably isn't very useful.
The font name is the difficult bit, iOS requires the name of the font which doesn't always correlate to the file name in order to load the font, its sometimes viewable within a font viewer but isn't always intuitive so be sure to test that on the device to make sure you got it right.

Thursday, November 15, 2012

Cloud Storage, Cloud Bind(tm), iPhone 5 simulator, barcodes and much more

We just made a major update including a pile of fixes and features. One of the biggest things we are launching right now is an early preview of our new Cloud Storage and Cloud Bind (tm) solutions.

Cloud Storage allows you to effectively use our cloud as a big object database, similar to other big data solutions as a sort of key/value pair lookup engine that allows you to share/sync between devices.
The Cloud Bind (tm) solution allows you to seamlessly bind components such as lists, text components etc. to the cloud where changes automatically persist to the Cloud Storage and data is automatically fetched from there.

These are currently limited only to pro users mostly because we haven't yet figured out the free quotas we want to allocate for free/basic users. We will publish more tutorials and information when we have this fleshed out.

We also added an iPhone 5 simulator skin allowing you to generate iPhone 5 resolution screenshots.

And we finally added a bar code/qr code reader API. However, this wasn't as easy as one would suspect. The problem is that ZXing our API of choice for the QR code in the demo, doesn't do barcodes on iOS... So we had to use a different implementation on iOS which might not be as good as ZXing with QR codes. So the old native approach will still work if you want it too, but you don't have to because we have a much simpler API.


There is allot more coming in the next couple of months... Stay tuned.