The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the
Comments (0) Share September 30 — Topics: Developing with the webOS SDK, Plug-in Development Kit (PDK) — unwiredben
It feels like it was only five months ago that we published part 2 of this series. Sorry for the long wait!
This time, we’re taking our BadFont sample and going in two directions. First, we’ll add some TrueType font display code using the SDL_TTF library. Second, we’ll talk about packaging up your PDK app for installing on the device and submitting it to the Palm webOS App Catalog. As a bonus, we’ll also provide a makefile you can use on Windows for all of this.
Here’s what it will look like when we’re done:

All webOS devices ship with a set of TrueType fonts in /usr/share/fonts. The main system font on webOS is called Prelude and we include these fonts:
Prelude-Bold.ttfPrelude-BoldOblique.ttfPrelude-Medium.ttfPrelude-MediumOblique.ttfPreludeCondensed-Bold.ttfPreludeCondensed-Medium.ttfThe Oblique forms are what you get when you italicize text. The Condensed version is an alternate form that has thinner letters.
The SDL_TTF library is documented on the SDL Wiki site. The key ideas here are that you load a font file into memory, then create a new graphics surface that is rendered as a string of text of a specified size. You can then blit that surface to an SDL or OpenGL surface for display. The bitmap surface produced by the TTF_RenderText_Blended call is created with the proper alpha channel information so it can be blitted on top of your existing surface without disturbing the background.
Here’s the code from our updated sample for opening and drawing with the Prelude Medium font; this isn’t all the code, just the new parts I added from part 2. Be sure to free your text surfaces after use or you’ll leak memory.
#define PRELUDE_FONT_PATH "/usr/share/fonts/Prelude-Medium.ttf"static void freeFont() { TTF_CloseFont(gFont); }static void setup() { ... TTF_Init(); atexit(TTF_Quit); gFont = TTF_OpenFont(PRELUDE_FONT_PATH, 20); if (!gFont) EXIT(1); atexit(freeFont); ...}static void display(){ ... SDL_Color yellow = { 255, 255, 0 }; SDL_Surface *textSurface = TTF_RenderText_Blended(gFont, "Comic Sans Forever", yellow); if (textSurface) { // now center it horizontally and position it just below the logo SDL_Rect textDestRect; textDestRect.x = (gScreen->w - textSurface->w) / 2; textDestRect.y = (logoDestRect.y + logoDestRect.h + 8); textDestRect.w = textSurface->w; textDestRect.h = textSurface->h; SDL_BlitSurface(textSurface, NULL, gScreen, &textDestRect); SDL_FreeSurface(textSurface); } ...}To properly install your application to the device, you need to package it into an IPK file. The tool to do this is called palm-package. To use this tool, you create an appinfo.json file and a package.properties file. The first identifies key information about your PDK app to the system, while the second tells the packager how to properly set the executable bit on your ARM application so it can run when installed on the device.
To make sure that only the files I want are packaged, I usually have my build script make a STAGING directory, copy only the files I want packaged to that location, and then run palm-package on that folder instead of using the default folder. Here’s the appinfo.json that we’re using for Bad Font:
{ "title": "Bad Font", "type": "pdk", "main": "badfont", "id": "com.palmdts.app.badfont", "version": "0.3.0", "vendor": "Palm, Inc.", "requiredMemory": 15}When you write a JSON file like this, a good practice is to run it through the JSONLint.com website. This will check your syntax and help you find simple errors like missing commas before the palm-package script complains. For a PDK full-screen app, you want to make sure the app’s type is set to “pdk” and that you’ve got a requiredMemory field. The number for that field is in megabytes, and the system uses that as a guide to know if it can launch your app without running out of memory, so try to be accurate.
There’s another file that’s just used by palm-package called package.properties. This is used to tell palm-package what the file permissions are for files in your app. For JS/HTML apps, this doesn’t matter, as the standard properties are fine. However, when you’ve got real executables, you need to mark them with the Unix executable flag. This file looks like:
filemode.755=badfontSince this is so short, in our scripts and makefile, we just write that out as part of the packaging process instead of saving it in the filesystem.
Up to now, we’ve been using batch files on Windows to build our app. This works OK for a single file application, but as your program grows larger, you may want a more sophisticated build tool. The BadFont3.zip archive includes both a Makefile for use with Microsoft NMake and a GNUmakefile for use with GNU Make. They do the same thing, but the syntax of the two tools differs slightly. If you want to see some more examples of makefiles for building PDK projects, this thread on the developer forum has a bunch of examples.
Here’s our makefile for NMake:
# This is a Windows makefile for use with Microsoft NMakePRE=0PIXI=1DESKTOP=0DEBUG=0!if $(DEBUG)DEVICEOPTS=-g!elseDEVICEOPTS=!endif!if $(PRE)DEVICEOPTS=$(DEVICEOPTS) -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp!elseif $(PIXI)DEVICEOPTS=$(DEVICEOPTS) -mcpu=arm1136jf-s -mfpu=vfp -mfloat-abi=softfp!else!error Must set either PRE or PIXI variable to 1 to build!endifINC="-I%PalmPDK%\include" "-I%PalmPDK%\include\SDL" CC=arm-none-linux-gnueabi-gccCFLAGS=$(INC) $(DEVICEOPTS)CPP=arm-none-linux-gnueabi-g++CPPFLAGS=$(CFLAGS)LIBS=-lSDL -lSDL_image -lSDL_ttf -lpdlLDFLAGS="-L%PalmPDK%\device\lib" $(LIBS) -Wl,--allow-shlib-undefined.cpp.o:: $(CPP) $(CPPFLAGS) -c $<.c.o:: $(CC) $(CFLAGS) -c $And here’s the very similar makefile for GNU Make. There are a bunch of small differences. You have to call batch files like palm-package.bat by directly using CMD.EXE, since GNU Make doesn’t know how to search for .BAT files in the path. Path separators have to be changed from backslash to forward slash. Conditionals have to be changed to remove the leading exclamation marks. Commands for rules have to have leading TAB characters instead of just leading spaces. Implicit rules that show how to turn .c or .cpp files into .o files have to be reworked.
# This is a Windows makefile for use with GNU MakePRE=0PIXI=1DESKTOP=0DEBUG=0ifeq (1,$(DEBUG))DEVICEOPTS=-gelseDEVICEOPTS=endififeq (1,$(PRE))DEVICEOPTS += -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfpelse ifeq (1,$(PIXI))DEVICEOPTS += -mcpu=arm1136jf-s -mfpu=vfp -mfloat-abi=softfpelse$(error Must set either PRE or PIXI variable to 1 to build)endifINC="-I$(PalmPDK)\include" "-I$(PalmPDK)\include\SDL" CC=arm-none-linux-gnueabi-gccCFLAGS=$(INC) $(DEVICEOPTS)CPP=arm-none-linux-gnueabi-g++CPPFLAGS=$(CFLAGS)LIBS=-lSDL -lSDL_image -lSDL_ttf -lpdlLDFLAGS="-L$(PalmPDK)\device\lib" $(LIBS) -Wl,--allow-shlib-undefined%.o : %.cpp $(CPP) $(CPPFLAGS) -c $<%.o : %.c $(CC) $(CFLAGS) -c $I’ve attached the ZIP file for this sample code, including working makefiles as well as the old batch files as BadFont-Part3.zip. Be aware that this code won’t run as-is on a Palm Pixi device with webOS 1.4.5, as those don’t support SDL-only apps, but it should work fine on a Palm Pre. If you’re on Mac OS X, you can use the GNUmakefile, but you’ll need to modify it a bit to handle the different shell commands and that palm-package is a shell script, not a batch file.
No comments:
Post a Comment