Page 6 of 6

Re: TextOut y value

Posted: 12 Feb 2012, 22:05
by afanofosc
You can use #import without anything after the filename as described here:

http://bricxcc.sourceforge.net/nbc/nxcd ... mport.html

In that case the variable name for the Tiny_6 font would be Tiny_6 and the variable name for the Sans_10 font would be Sans_10. That might help avoid this problem. The optional value after the filename is a format specified which defaults to %s where the filename without an extension is what is passed into the format specifier. So you could use fnt_%s following the Filename and the variable would be named fnt_Tiny_6 and fnt_Sans_10 respectively.

John Hansen

Re: TextOut y value

Posted: 13 Feb 2012, 08:55
by HaWe
thank you very much!
that would mean

#import "Tiny_6.ric"

would be further processed like

__gFont = "Tiny_6.ric";
LoadFont( Tiny_6, __gFont );

Re: TextOut y value

Posted: 13 Feb 2012, 19:28
by HaWe
yes, just killed another bug ;)
now finally it works!

Code: Select all

// importFont.nxc

string __gFont;

unsigned int LoadFont( byte &arr[], string filename ){
   byte handle;
   unsigned int size = ArrayLen( arr );
   unsigned int result = CreateFileLinear( filename, size, handle );
   if( result == LDR_SUCCESS ){
      result = Write( handle, arr );
      CloseFile( handle );
   }
   ArrayInit( arr, 0, 0 );
   return result;
}

unsigned int UnloadFont( string filename ){
  return DeleteFile( filename );
}

#import "Tiny_6.ric"
#import "Sans_10.ric"

task main() {

  LoadFont( Tiny_6,  "Tiny_6.ric"  );
  LoadFont( Sans_10, "Sans_10.ric" );

  __gFont = "Sans_10.ric";
  FontTextOut(0,45,__gFont, "y=45 "+ __gFont);  //

  __gFont = "Tiny_6.ric";
  FontTextOut(0,30,__gFont, "y=30 "+ __gFont);  //
  
  __gFont = "Sans_10.ric";
  FontTextOut(0,15,__gFont, "y=15 "+ __gFont);  //
  
  __gFont = "Tiny_6.ric";
  FontTextOut(0, 0,__gFont, "y=0 "+ __gFont);  //
  
  
  while(1);
}

Re: TextOut y value

Posted: 13 Feb 2012, 20:47
by spillerrec
Yeah, I accidentally hardcoded the filename instead of using the "filename" parameter I originally intended to use. I was starting to wonder when you would notice it xD

Re: TextOut y value

Posted: 15 Feb 2012, 03:40
by afanofosc
I've uploaded a new build of the enhanced NBC/NXC firmware to the test_releases folder. It implements the faster text drawing code from Nicolas and support for FontTextOut with either a RIC font filename or a RIC font array. The firmware assumes it is a filename if it has <= 20 bytes in the array and otherwise it assumes it is an array containing the font data.

Code: Select all

  FontTextOut(0,LCD_LINE3,"tahoma8.ric", "Cicero scripsit:");
  FontTextOut(0,LCD_LINE5,"", "Cicero scripsit:"); // uses TextOut if empty string
  TextOut(0,LCD_LINE6,"Cicero scripsit:");
  FontTextOut(0,LCD_LINE8,Tiny_6, "Cicero scripsit:");
John Hansen

Re: TextOut y value

Posted: 15 Feb 2012, 03:43
by mattallen37
Got it, thanks!

BTW, it's upload dated for about 5 hours from now :P

Re: TextOut y value

Posted: 15 Feb 2012, 04:03
by afanofosc
I think sourceforge is showing a UTC time - equivalent to about 9:20pm CST.

John Hansen

Re: TextOut y value

Posted: 15 Feb 2012, 05:51
by mspall
Using the code from my previous post
http://sourceforge.net/apps/phpbb/mindb ... =10#p12142
I compared the latest firmware to the firmware from Jan 7 before the TextOut changes. This time I paid attention to compiler optimization level. I tested using optimization levels 1, 2, and 3. These are the average timings in ticks (n = 5):
lms_arm_nbcnxc_131_20111019_1659.rfw 5507 5103 4675
lms_arm_nbcnxc_132_20120214_2114.rfw 6843 6424 5933
The latest firmware with optimization levels 1, 2, and 3 has an increase of 24%, 26%, and 27% respectively over the earlier firmware. Thank you John and Nicolas.