TextOut y value

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: TextOut y value

Post by HaWe »

hmm-
I tried this but the grafic font line is not displayed:

Code: Select all

string __gFont;
inline void SetFont(string name) { __gFont = name; }

#import "Tiny_6.ric" fontarr1
#import "Sans_10.ric" fontarr2

task main() {
  TextOut(0,56,"font test");                              // ok !
  SetFont("Tiny_6.ric");
  FontTextOut(0,25,__gFont, "text string "+ __gFont);  // error => blank
  SetFont("Sans_10.ric");
  FontTextOut(0, 0,__gFont, "text string "+ __gFont);  // error => blank
  while(1);
}
Tiny_6.ric and Sans_10.ric are in working directory (same dir as source code) -
what am I missing?
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: TextOut y value

Post by afanofosc »

What you are missing, Doc, is the LoadFont and UnloadFont functions that spillerec posted in his message. As I described, the workaround for the not currently existing DrawFontArray system call (or a modified DrawFont system call that would work with either a string or an RICfont array) is to write the font to a file before you call FontTextOut. Spillerec's code does that without much hassle at all.

Here it is again, in case it was obscured by the font array:

Code: Select all

unsigned int LoadFont( byte &arr[], string filename ){
   byte handle;
   unsigned int size = ArrayLen( arr );
   unsigned int result = CreateFileLinear( FONTNAME, 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 );
}
It might be worth having a #define macro to empty out the font array once it has been saved to a file.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: TextOut y value

Post by HaWe »

ok, thanks, it works!
(1 file was damaged!)

Code: Select all

string __gFont;
inline void SetFont(string name) { __gFont = name; }

unsigned int LoadFont( byte &arr[], string filename ){
   byte handle;
   unsigned int size = ArrayLen( arr );
   unsigned int result = CreateFileLinear( __gFont, 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" fontarr1
#import "Sans_10.ric" fontarr2

task main() {

  TextOut(0,56,"font test");                              // ok !

  SetFont("Sans_10.ric");
  LoadFont( fontarr1,  __gFont );
  FontTextOut(0,25,__gFont, "text string "+ __gFont);  // ok now!

  SetFont("tiny_6.ric");
  LoadFont(  fontarr2,  __gFont );
  FontTextOut(0, 0,__gFont, "text string "+ __gFont);  // error => blank
  while(1);
}
what do you mean by your "#define" ?
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: TextOut y value

Post by afanofosc »

Your code worked fine on my NXT which has very few, if any, files on it. LoadFont returns a value that indicates whether it was able to load the font or not. You should check its return value against LDR_SUCCESS. If it does not equal LDS_SUCCESS you can output the error code to the screen and see what it says went wrong. Probably not enough linear space available (fragmented flash memory) or something like that. LDR_NOLINEARSPACE == 0x8900 == 35072. LDR_NOSPACE == 0x8200 == 33280.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: TextOut y value

Post by HaWe »

no, really strange:
it does NOT display the correct sizes.
Sans_10 is displayed 6-pt,
Tiny_6 is displayed 10-pt.

edit: can't upload screenshot
The image file you tried to attach is invalid.
this code is working correctly:

Code: Select all

string filename;
#download "Tiny_6.ric"
#download "Sans_10.ric"
#download "Serife_10.ric"
#download "Fixed_8.ric"
task main(){
  filename ="Tiny_6.ric";
  FontTextOut(0, 50, filename, filename+"-ABCabc123.45");
  filename ="Sans_10.ric";
  FontTextOut(0, 32, filename, filename+"-ABCabc123.45");
  filename ="Serife_10.ric";
  FontTextOut(0, 20, filename, filename+"-ABCabc123.45");
  filename ="Fixed_8.ric";
  FontTextOut(0, 0, filename, filename+"-ABCabc123.45");
  while(1);
}
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: TextOut y value

Post by afanofosc »

That is not what I see as shown below:

http://www.dropbox.com/gallery/53437658/1/NXT?h=63195b

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: TextOut y value

Post by HaWe »

no, it's quite other way round.
a tiny line Sans_10 in the middle,
and a big line tiny_6 at the bottom.

but strangely I saw it different once when I had tried the "download version" intermediately.

But after having erased all files on the flash and started the import version anew, again the same *wrong* picture (just now in the moment)

again the code to be sure:

Code: Select all

string __gFont;
inline void SetFont(string name) { __gFont = name; }

unsigned int LoadFont( byte &arr[], string filename ){
   byte handle;
   unsigned int size = ArrayLen( arr );
   unsigned int result = CreateFileLinear( __gFont, 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" fontarr1
#import "Sans_10.ric" fontarr2

task main() {

  TextOut(0,56,"font test");                              // ok !

  SetFont("Sans_10.ric");
  LoadFont( fontarr1,  __gFont );
  FontTextOut(0,25,__gFont, "text string "+ __gFont);  //  

  SetFont("tiny_6.ric");
  LoadFont(  fontarr2,  __gFont );
  FontTextOut(0, 0,__gFont, "text string "+ __gFont);  // 
  while(1);
}
Image
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: TextOut y value

Post by HaWe »

is this a fw issue?
I'm still working with the 02.07.2011 version because of compatibility reasons on all of my NXTs.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: TextOut y value

Post by afanofosc »

Doc, please, please just look at your code. You are passing a variable containing the tiny font into the LoadFont routine with __gFont set to a string that is the name of the Sans font and vice versa. That is not the code that you originally posted or that I am executing.

Here is what I copied from your original post (unmodified)

Code: Select all

string __gFont;
inline void SetFont(string name) { __gFont = name; }

unsigned int LoadFont( byte &arr[], string filename ){
   byte handle;
   unsigned int size = ArrayLen( arr );
   unsigned int result = CreateFileLinear( __gFont, 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" fontarr1
#import "Sans_10.ric" fontarr2

task main() {

  TextOut(0,56,"font test");                              // ok !

  SetFont("Tiny_6.ric");
  LoadFont( fontarr1,  __gFont );
  FontTextOut(0,25,__gFont, "text string "+ __gFont);  // ok now!

  SetFont("Sans_10.ric");
  LoadFont(  fontarr2,  __gFont ); 
  FontTextOut(0, 0,__gFont, "text string "+ __gFont);  // error => blank
  while(1);
}
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: TextOut y value

Post by HaWe »

OMG Image
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 6 guests