KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Generate banner picture from banner command in Mac OSX
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac
Published On: April 13, 2018

In Mac OSX, the banner command in terminal can generate a banner of text from the character "#". The following method can export that banner text to a SVG picture:

// -----------------------------------------------------------------
// Name: GENERATE_BANNER_PICTURE
// Description: Generates a SVG picture from the banner
// command in Mac OSX terminal.
//
// Input Parameters:
// $1 (TEXT) - Text
// $2 (LONGINT) - Height size in characters
//
// Output:
// $0 (PICTURE) - SVG picture generated from the Text input
// ------------------------------------------------------------------
C_TEXT($1;$input_text;$cmd;$input;$output;$error)
C_LONGINT($2;$textWidth;$i;$j;$k;$newLineCtr;$lengthLine;$lengthLineCtr)
C_PICTURE($0;$picOutput)

If (Count parameters=2)

  $input_text:=$1
  $textWidth:=$2
  $cmd:="banner -w "+String($textWidth)+" "+$input_text
  $input:=""

  LAUNCH EXTERNAL PROCESS($cmd;$input;$output;$error)

  $newLineCtr:=0
  $lengthLine:=0
  $lengthLineCtr:=0

  For ($i;1;Length($output))
   $lengthLineCtr:=$lengthLineCtr+1

   If ($output[[$i]]=char(Line feed))
     $newLineCtr:=$newLineCtr+1

     If ($lengthLineCtr>$lengthLine)
      $lengthLine:=$lengthLineCtr
     End if
     $lengthLineCtr:=0
    End if
   End for

   vID_SVG:=SVG_New (num($newLineCtr*5.5);$lengthLine*6)
   SVG_SET_OPACITY (vID_SVG;100;0) //Set the background to white

   $j:=0
   $k:=0

   For ($i;1;Length($output))
    $j:=$j+5
    If ($output[[$i]]="\n")
     $j:=0
     $k:=$k+5
    Else
     $textID:=SVG_New_text (vID_SVG;$output[[$i]];$j;$k;"";10;0;0;"black";270)
    End if
   End for

   SVG_SET_TRANSFORM_ROTATE (vID_SVG;270;$textWidth*2.5;$textWidth*2.5)
   SVG EXPORT TO PICTURE(vID_SVG;$0;Copy XML data source)
End if


Here is an example of creating a banner of 4D:

C_PICTURE(pic)

pic:=GENERATE_BANNER_PICTURE("4D";50)


Here is the result in of the picture:




Another example of more text:

C_PICTURE(pic)

pic:=GENERATE_BANNER_PICTURE("Banner";30)