Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 112

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:112)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:112)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:112)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:112)
OrbWorks Community Forum • View topic - Custom font solution (alpha)

Custom font solution (alpha)

Discuss and publish sample code and applications written in OrbC (OrbForms Designer or PocketC Architect)

Postby Bitmonkey on Tue Aug 29, 2006 9:24 pm

Warning! This is an ugly solution!

Okay, I've been using Architect for about a week now and I got fed up with it's inability to use a certain custom font (4x6, so I could draw 80x24 chars onscreen), so I made this sort of hackney'd solution. Like I said, this isn't pretty, but it works acceptably fast for what I need (1600 chars in about 3.5 secs).

...I'll post the code and then explain.

<u><b>memo #1:</b></u>
Code: Select all
//CFDrawTest.ocp

void nullfunc(int x, int y){ }

int ccount;

#include "CFBmps.oc"
#include "LongString.oc"
#include "CFFuncs.oc"
#include "CFArray.oc"

@app myApp {
  creator = "BB03"; // creator id
  name = "CFDrawTest"; // display name
  dbname = "CFDrawTest"; // name of .prc database
}

@form myForm {
  id = 1000
text = "CFDraw"
  x = 0, y = 0, w = 160, h = 160

  button UIButton Beginbtn {
    id = 101
    x = 110, y =140, w = 40, h = 12
    text = "Begin"
  }
}

handler myApp.onstart() {
  myForm.load();
  CFDraw.attachForm(myForm);
}

handler Beginbtn.onselect() {
  CFDraw.nbegin();
  //CFDraw.bitmap(bm64,10,10);
  for(ccount=0; ccount<strlen(longtest); ccount++){
  CFArray[longtest[ccount]-1]((ccount%80)*4, 0+(8*(ccount/80)));
  }
  CFDraw.end();
}


<u><b>Memo #2:</b></u>
Code: Select all
//CFFuncs.oc

Draw CFDraw;

void CFDraw0(int x, int y){
CFDraw.bitmap(bm0,x,y);
}

void CFDraw1(int x, int y){
CFDraw.bitmap(bm1,x,y);
}

void CFDraw2(int x, int y){
CFDraw.bitmap(bm2,x,y);
}

void CFDraw3(int x, int y){
CFDraw.bitmap(bm3,x,y);
}

<b>//repeat 126 times</b>

void CFDraw125(int x, int y){
CFDraw.bitmap(bm125,x,y);
}



<u><b>memo #3:</b></u>

Code: Select all
//CFBmps.oc

@bitmap bm0 {
id = 4000;
imageres = "SmallFont,Tbmp,1000";
}

@bitmap bm1 {
id = 4001;
imageres = "SmallFont,Tbmp,1001";
}

@bitmap bm2 {
id = 4002;
imageres = "SmallFont,Tbmp,1002";
}

@bitmap bm3 {
id = 4003;
imageres = "SmallFont,Tbmp,1003";
}
<b>//repeat 126 times to bm125 </b>

<u><b>
memo #4:</b></u>

Code: Select all
//CFArray.oc

funcptr cfarray void(int, int);

cfarray CFArray[126]={CFDraw0, CFDraw1, CFDraw2, CFDraw3, CFDraw4,
CFDraw5, CFDraw6, CFDraw7, CFDraw8, CFDraw9, CFDraw10, CFDraw11,
CFDraw12, CFDraw13, CFDraw14, CFDraw15, CFDraw16, CFDraw17, CFDraw18,
CFDraw19, CFDraw20, CFDraw21, CFDraw22, CFDraw23, CFDraw24, CFDraw25,
CFDraw26, CFDraw27, CFDraw28, CFDraw29, CFDraw30, CFDraw31, CFDraw32,
CFDraw33, CFDraw34, CFDraw35, CFDraw36, CFDraw37, CFDraw38, CFDraw39,
CFDraw40, CFDraw41, CFDraw42, CFDraw43, CFDraw44, CFDraw45, CFDraw46,
CFDraw47, CFDraw48, CFDraw49, CFDraw50, CFDraw51, CFDraw52, CFDraw53,
CFDraw54, CFDraw55, CFDraw56, CFDraw57, CFDraw58, CFDraw59, CFDraw60,
CFDraw61, CFDraw62, CFDraw63, CFDraw64, CFDraw65, CFDraw66, CFDraw67,
CFDraw68, CFDraw69, CFDraw70, CFDraw71, CFDraw72, CFDraw73, CFDraw74,
CFDraw75, CFDraw76, CFDraw77, CFDraw78, CFDraw79, CFDraw80, CFDraw81,
CFDraw82, CFDraw83, CFDraw84, CFDraw85, CFDraw86, CFDraw87, CFDraw88,
CFDraw89, CFDraw90, CFDraw91, CFDraw92, CFDraw93, CFDraw94, CFDraw95,
CFDraw96, CFDraw97, CFDraw98, CFDraw99, CFDraw100, CFDraw101,
CFDraw102, CFDraw103, CFDraw104, CFDraw105, CFDraw106, CFDraw107,
CFDraw108, CFDraw109, CFDraw110, CFDraw111, CFDraw112, CFDraw113,
CFDraw114, CFDraw115, CFDraw116, CFDraw117, CFDraw118, CFDraw119,
CFDraw120, CFDraw121, CFDraw122, CFDraw123, CFDraw124, CFDraw125};



and <u><b>Memo #5</b></u>, really just a long test string of 1600 chars:

Code: Select all
//LongString.oc

string longtest="ONCE UPON A TIME IN A GALAXY FAR AWAY LIVED A LITTLE
FISH   A VIOLENT CUMCUAT RULED THE STARS WITH AN IRON VINE   VARIABLE
WITH HOMOGENY SAYS THE DWARF   NAPALMONCE UPON A TIME IN A GALAXY FAR
AWAY LIVED A LITTLE FISH   A VIOLENT CUMCUAT RULED THE STARS WITH AN
IRON VINE   VARIABLE WITH HOMOGENY SAYS THE DWARF   NAPALMONCE UPON A
TIME IN A GALAXY FAR AWAY LIVED A LITTLE FISH   A VIOLENT CUMCUAT
RULED THE STARS WITH AN IRON VINE   VARIABLE WITH HOMOGENY SAYS THE
DWARF   NAPALMONCE UPON A TIME IN A GALAXY FAR AWAY LIVED A LITTLE
FISH   A VIOLENT CUMCUAT RULED THE STARS WITH AN IRON VINE   VARIABLE
WITH HOMOGENY SAYS THE DWARF   NAPALMONCE UPON A TIME IN A GALAXY FAR
AWAY LIVED A LITTLE FISH   A VIOLENT CUMCUAT RULED THE STARS WITH AN
IRON VINE   VARIABLE WITH HOMOGENY SAYS THE DWARF   NAPALMONCE UPON A
TIME IN A GALAXY FAR AWAY LIVED A LITTLE FISH   A VIOLENT CUMCUAT
RULED THE STARS WITH AN IRON VINE   VARIABLE WITH HOMOGENY SAYS THE
DWARF   NAPALMONCE UPON A TIME IN A GALAXY FAR AWAY LIVED A LITTLE
FISH   A VIOLENT CUMCUAT RULED THE STARS WITH AN IRON VINE   VARIABLE
WITH HOMOGENY SAYS THE DWARF   NAPALMONCE UPON A TIME IN A GALAXY FAR
AWAY LIVED A LITTLE FISH   A VIOLENT CUMCUAT RULED THE STARS WITH AN
IRON VINE   VARIABLE WITH HOMOGENY SAYS THE DWARF   NAPALMONCE UPON A
TIME IN A GALAXY FAR AWAY LIVED A LITTLE FISH   A VIOLENT CUMCUAT
RULED THE STARS WITH AN IRON VINE   VARIABLE WITH HOMOGENY SAYS THE
DWARF   NAPALMONCE UPON A TIME IN A GALAXY FAR AWAY LIVED A LITTLE
FISH   A VIOLENT CUMCUAT RULED THE STARS WITH AN IRON VINE   VARIABLE
WITH HOMOGENY SAYS THE DWARF   NAPALMONCE UPON A TIME IN A GALAXY FAR
AWAY LIVED A LITTLE FISH   A VIOLENT CUMCUAT RULED THE STARS WITH AN
IRON VINE   VARIABLE WITH HOMOGENY SAYS THE DWARF   NAPALMONCE UPON A
TIME IN A GALAXY FAR AWAY LIVED A LITTLE FISH   A VIOLENT CUMCUAT
RULED THE STARS WITH AN IRON VINE   VARIABLE WITH HOMOGENY SAYS THE
DWARF   NAPALM";

------------------------------------------------------------------
Okay, first reason this is an ugly solution: It uses a font set up as a bitmap database with 256 records called "SmallFont". This is because I don't know how to rip the data out of a font resource DB.

Second reason: It only supports ASCII 0-125 because if you try to compile it with 256 bitmaps and functions, you get an "out of memory" error from Architect.

But, the fact is that it works for what I want.

Here is how it works:

rather than use a big, slow switch statement to find which bitmap to draw depending on the current character in the passed string, the program casts the character into an int and calls the function to draw that character, which is stored in a function array (cfarray). The position of each function in the function array is the same as that character's ASCII value -1. So, while there is a whole lot of code overhead, the <b>switch</b> statement draws 1600 chars in about <b>a minute</b>, while this does it in <b>under 4 seconds</b>.

Things I need to do:
1. Figure out how to read in a font resource so that I don't have to spend hours building bitmap databases.
2. Figure out how to compile it with all 256 ASCII draw functions and not run out of memory.
3. Put it in a library, because I understand that will make it faster...

hmm... what do you think? Useful? Confusing? Is there a better way? Got suggestions? Please post!
Bitmonkey
 
Posts: 1
Joined: Tue Aug 29, 2006 8:54 pm

Return to OrbC User Samples

Who is online

Users browsing this forum: No registered users and 2 guests

cron