Post Reply 
Fixed width font for terminal emulator
05-05-2021, 10:58 PM
Post: #1
Fixed width font for terminal emulator
It looks like it might now be possible to build a VT52 or better terminal emulator on the Prime now that we have USB I/O - thanks Cyrille!

But is there a fixed width font? Unless I’m mistaken they are all variable width.
Find all posts by this user
Quote this message in a reply
05-06-2021, 05:35 AM
Post: #2
RE: Fixed width font for terminal emulator
Hello,

Correct the font are variable width.
There is, I think, a way to print monospace using the extended form of TEXTOUT.
Unfortunately, looking at the online help, I notice that I have NOT updated said help... so you could not know about it...

Here is the updated help: Notice flag bit 10 which should allow to print monospaced...
Honestly, I have not tested it, so I am not sure it works!
But basically with this version of TEXTOUT, you, as a user, now has full access to the underlying C textout function with all the options, bells and whistles...

Cyrille

Syntax:
TEXTOUT_P(text, [G], x, y, [font], [textColor], [width], [backgroundColor])
TEXTOUT_P(text, [G], x, y, {["2D"], [{print flags as in the STRING command}], [font], [textColor], [width], [backgroundColor],flags})

Draws text on graphic G at position (x, y) using font and textColor. Paints the background before drawing the text using color backgroundColor. If width is specified, does not draw text more than width pixels wide. If backgroundColor is not specified, the background is not erased.

The sizes for font are:

0=current font (default)
1=font 10
2=font 12 (Small)
3=font 14 (Medium)
4=font 16 (Large)
5=font 18
6=font 20
7=font 22

The 2nd form allows you to print in 2D if you add the "2D" string. It also allows you to control how numbers are transformed into a string (see the STRING command for more info on this. The format is the same as the arguements after the "expression").
Finally, it allows you to select a number of "display" options with flags:
flags is a 1 bit, one function set of 12 options with the following bits controling the following options
bit 0(1): elipsis
bit 1(2): NoPadding
bit 2(4): ClipLastChar
bit 3(8): centered
bit 4(16): rightaligned
bit 5(32): PointIsNotTopLeft
bit 6(64): Underline
bit 7(128): StrikeThrough
bit 8(256): Bold
bit 9(512): italic
bit 10(1024): mono
bit 11(2048): EraseFullWidth

Returns the X coordinate at which the next character of the string should be drawn if the string had more characters

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
05-06-2021, 05:49 PM (This post was last modified: 05-07-2021 02:03 PM by Oulan.)
Post: #3
RE: Fixed width font for terminal emulator
Hello,

Nice functionalities for HPPL.
Is there a way to use this kind of functionalities with python.

Ie. it seems that python only have : hpprime.textout(G,x,y,text,fgcolor) so we need to use hpprime.fillrect() to erase background as alpha blend seems always on.

Is there a way to have more options ?

Some remarks:

In HELP tree : Main/HP apps/Python app/Python all_modules/ there is no graphic module.

With the last Development kit, it is rather difficult to transferts back and forth python scripts. Regularly the prime reboots when updating files.

The best method seems to delete the file from the calc then adding again the file.

Another question is what is the difference between 'files' and 'program' in the python app as seen in the windows app?

It seems easier to modify 'program' from the windows app, but I can not find it and edit if from the calc ...

As other people, I am very pleased with such an evolution on the prime firmware. Thanks again.

Just doing some tests on a G2:
in HPPL an HP41 emulator was 1/3 of the speed of a real HP41,
in python you got a x4 speed HP41 Smile very nice and this prove that the implemented micro python is quite robust
(ps is there a way to have more function in utime(q) ? ie wait_ms to wait a bit)
Find all posts by this user
Quote this message in a reply
04-08-2022, 08:36 PM
Post: #4
RE: Fixed width font for terminal emulator
Does this second form of TEXTOUT_P currently work in HPPPL on a HP Prime calculator?
Find all posts by this user
Quote this message in a reply
04-08-2022, 09:53 PM
Post: #5
RE: Fixed width font for terminal emulator
(05-06-2021 05:49 PM)Oulan Wrote:  Hello,

Nice functionalities for HPPL.
Is there a way to use this kind of functionalities with python.

Ie. it seems that python only have : hpprime.textout(G,x,y,text,fgcolor) so we need to use hpprime.fillrect() to erase background as alpha blend seems always on.
Hi Olivier

I tried to have a more versatile Textout with some options using the hpprime.eval() Look here It makes it easier to to put the strings together, but it works for me. You also could have a look my MandelbrotExplorer where I use it myself.

BTW. I've also tentatively made some superficial add on to your Py41, yet not mature to be published. <SHIFT> <VIEW> prints two list of the key mappings to both sides of the print area. That makes life easier.

And with the help of the hpprime.eval() function I was also able to make good use of the extended INPUT of the HOME environment. Here is an example:
Code:
from hpprime import *

def string(arg): return '"' + str(arg) +'"'
def RGB(r,g,b): return (r*256+g)*256+b
def strip(arg): return str(arg)[1:-1]

def TxtOut(t,x,y,f,c,*args):
    if len(args)>2:
       raise(SyntaxError("too many arguments"))
    if True in [isinstance(i,list) for i in t]:
       raise(TypeError("can't convert 'list' object to str implicitly")) 
    parms=(int(x),int(y),int(f),int(c))
    if len(args)>0:parms+=(int(args[0]),)
    if len(args)>1:parms+=(int(args[1]),)
    return eval('TEXTOUT_P('+string(t)+','+strip(parms)+')')

def ClearMouseBuffer():
    mm=mouse()
    while mm!=((),()): mm=mouse()

def ClearKeyboardBuffer():
    keyCode=keyboard()
    while keyCode: keyCode=keyboard()

def init():
   avars0=eval("AVars")
   avars=["Day","Month","Year","Hour","Minute","Second","Latitude","NorthSouth","EastWest","Longitude"]
   for avar in avars: 
     if not avar in avars0:
        eval('AVars('+string(avar)+'):=0')

def wait(): eval('WAIT()')

def Inp(Title="Date, Time and Location"):
    dig=eval('HSeparator')
    eval('HSeparator:=3')
    Vars = '{'
    Vars +='{Day,        [0],{25,10,1}}'
    Vars +=',{Month,     [0],{55,10,1}}'
    Vars +=',{Year,      [0],{80,20,1}}'
    Vars +=',{Hour,  [0],{25,10,2}}'
    Vars +=',{Minute,  [0],{55,10,2}}'
    Vars +=',{Second,  [0],{80,10,2}}'
    Vars +=',{Latitude,  [0],{25,30,4}}'
    Vars +=',{NorthSouth,{"N","S"},{70,10,4}}'
    Vars +=',{Longitude, [0],{25,30,5}}'
    Vars +=',{EastWest,{"E","W"},{70,10,5}}'
    Vars += '}'
    Labels = '{"Day","Month","Year","UTC-Hour","Min","Sec","Latitude","N/S","Longitude","E/W"}'
    Helps ='{"Day of Month", "Month of Year","Year",\
    "Hour: Universal Time Coordinated","Minute of the Hour","Second of the Hour",\
    "Sexagesimal d°m’ s” or decimal d.d----d°","North or South Latitude",\
    "Sexagesimal d°m’ s” or decimal d.d----d°","East or West Longitude"}' 
    eval('print')
#    print(Vars)
    y=eval('INPUT('+Vars+','+string(Title)+','+Labels+','+Helps+')')
    eval('HSeparator:='+str(dig))
#    wait()
#    print(int(eval('Day'))) - ‘ - ’  ’  “  “  ”
#    print(y) 
init() 
Inp()

Copy this into the PYTHON app of the emulator and have a look. I'm convinced something like this could be useful for e.g. configuration of the Py41.

Perhaps this gives you some ideas. I'd be happy to answer any questions you may have on this subject.

Günter
Find all posts by this user
Quote this message in a reply
04-09-2022, 01:18 PM
Post: #6
RE: Fixed width font for terminal emulator
Does anyone know if I should expect this form mentioned by Cyrille above:

TEXTOUT_P(text, [G], x, y, {["2D"], [{print flags as in the STRING command}], [font], [textColor], [width], [backgroundColor],flags})

To be working in the current HP Prime in HPPPL - up to date with software and G2?

I had a little try last night, and couldn't any version of the command to work, but that wouldn't be the first time that I had problems with these advanced versions of commands needing brackets etc.
Find all posts by this user
Quote this message in a reply
04-09-2022, 03:03 PM (This post was last modified: 04-09-2022 03:11 PM by Thomas_Sch.)
Post: #7
RE: Fixed width font for terminal emulator
(04-09-2022 01:18 PM)matalog Wrote:  Does anyone know if I should expect this form mentioned by Cyrille above:

TEXTOUT_P(text, [G], x, y, {["2D"], [{print flags as in the STRING command}], [font], [textColor], [width], [backgroundColor],flags})

To be working in the current HP Prime in HPPPL - up to date with software and G2?

I had a little try last night, and couldn't any version of the command to work, but that wouldn't be the first time that I had problems with these advanced versions of commands needing brackets etc.

Within syntax descriptions parameters in brackets are optional parameters.
That means, these parameters are not mandatory. But you never have to write the brackets themselve.

Using the build-in help there are examples for the commands.
e.g. TEXTOUT_P("Hello HP Prime",100,100,4,RGB(255,0,0),200,RGB(0,255,255));
Find all posts by this user
Quote this message in a reply
04-09-2022, 05:35 PM
Post: #8
RE: Fixed width font for terminal emulator
(04-09-2022 03:03 PM)Thomas_Sch Wrote:  
(04-09-2022 01:18 PM)matalog Wrote:  Does anyone know if I should expect this form mentioned by Cyrille above:

TEXTOUT_P(text, [G], x, y, {["2D"], [{print flags as in the STRING command}], [font], [textColor], [width], [backgroundColor],flags})

To be working in the current HP Prime in HPPPL - up to date with software and G2?

I had a little try last night, and couldn't any version of the command to work, but that wouldn't be the first time that I had problems with these advanced versions of commands needing brackets etc.

Within syntax descriptions parameters in brackets are optional parameters.
That means, these parameters are not mandatory. But you never have to write the brackets themselve.

Using the build-in help there are examples for the commands.
e.g. TEXTOUT_P("Hello HP Prime",100,100,4,RGB(255,0,0),200,RGB(0,255,255));

Thanks, as the second post in this thread states the advanced usage of this command is currently undocumented in the manual, and assumably the calculator's built in help.

It is the advanced form that I want to use, and I do suspect that it will actually require the usage of the brackets, the {} to work properly. I specifically would like to use the final parameter, flags, as that seems to allow the usage of a monospaced font, or something to the same effect.

If anyone knows that that particular form of the command is usable iin the latest release of the Prime's software, please let us know here.
Find all posts by this user
Quote this message in a reply
04-09-2022, 08:37 PM
Post: #9
RE: Fixed width font for terminal emulator
(04-09-2022 05:35 PM)matalog Wrote:  It is the advanced form that I want to use, and I do suspect that it will actually require the usage of the brackets, the {} to work properly. I specifically would like to use the final parameter, flags, as that seems to allow the usage of a monospaced font, or something to the same effect.

The advanced form works partially, but not completely as advertised. Obviously Tim and Cyrille where not given the time to complete that satisfactorily. Here is a sample however that at least works in certain aspects.
Code:
EXPORT Tst1()
BEGIN
RECT_P();
// the simple TEXTOUT_P obviously works as described
TEXTOUT_P("My Text",20,20,3,RGB(0,0,0),100,RGB(128,128,0));

//The more advanced TEXTOUT_P seems to pretend some functionality it doesn't have
// but here is what I found to work.
// sample 1: Print -PIE12 with "2D" options
// The first group within braces indicates with "2D" that the extended format applies
// inside is another nested group within braces{2,4}.
// '2'denotes fixed Format, '4' denotes 4 digits precision
// followed by another group in braces {-1,",F_"}
// -1 indicates system number separation applies (may be 0 through 10)
// use ',' as decimal point use 'F' as exponent indicator use '_' as negative sign
// length limit and background color don't work
// #192d is trying to set flags for underline and strike through, doesn't work
//
TEXTOUT_P(-3.14159265359E12,G0,20,60,
 {"2D",{2,4,{-1,",F_"}},
 5,RGB(0,0,0),10,RGB(128,0,0),#192d});
 
// sample 2: Print Pi with fraction mode 
// The parameter for format is changed from 2 to 9 by adding 7. Thus giving fraction output
TEXTOUT_P(-3.14159265359,G0,20,120,
 {"2D",{9,4,{-1,",F_"}},
 5,RGB(0,0,0),10,RGB(128,0,0),#192d});
 
// sample 3: print a string 
// the printout is enclosed in parentheses 
TEXTOUT_P("My Text",G0,20,180,
 {"2D",{9,4,{-1,",F_"}},
 5,RGB(0,0,0),10,RGB(128,0,0),#192d}); 
WAIT();
 
END;
Conclusion: The advanced TEXTOUT_P is (in a limited way) suitable for expressions not for strings
I'm afraid this doesn't answer your question, but it gives you some examples on what works and what not. Perhaps I've overlooked something obvious, but i doubt it.

Günter
Find all posts by this user
Quote this message in a reply
04-08-2024, 12:09 AM
Post: #10
RE: Fixed width font for terminal emulator
As Guenter Schink pointed out, even with error-free syntax and arguments, there are TEXTOUT_P forms that will not respond to the format flag settings. At least on my Prime G2 with version D firmware, I have found what will consistently work for text formatting with the PRINT2D function. Unfortunately the set of working formats do not include italics and monospace fonts.
I set each bit in turn in a 16-bit flag word as well as found that combined formatting bits will work. In its simplest form, here's what I found for PRINT2D(): just five flag bits are active.

// So, these bits are active only: BITS 4:0
// Bit 0: BOLD Bit 8: -DEAD-
// Bit 1: UNDERLINE Bit 9: -DEAD-
// Bit 2: STRIKETHRU Bit 10: -DEAD-
// Bit 3: CENTER Bit 11: -DEAD-
// Bit 4: RIGHT Bit 12: -DEAD-
// Bit 5: -DEAD- Bit 13: -DEAD-
// Bit 6: -DEAD- Bit 14: -DEAD-
// Bit 7: -DEAD- Bit 15: -DEAD-


For RED font color(#FF0000h) and format flag set to #01h for bold font:
PRINT2D("This is BOLD.", 1, #FF0000h, #01h);


Here dark GREEN font color with a combined bold and strikethru formatting:
PRINT2D("This is bold and strikethru.", 1, #008800h, #05h);

You can apply a bitwise OR function to combine formats:
PRINT2D("Mix flgs BOLD & CENTER", 1, #FF0000h, (BITOR(flg_BOLD, flg_CENTER)));
Where the constant flag values have been defined as,
flg_BOLD:=#01h;
flg_CENTER:=#08h;
The BITOR() functions returns #09h.

I will welcome any help in getting monospace and italics to work. Please post if you've done it!

Barry
Find all posts by this user
Quote this message in a reply
04-08-2024, 11:23 PM
Post: #11
RE: Fixed width font for terminal emulator
Unfortunately, the built-in functions do not correctly support text formatting or only partially support it. Therefore, a project has been created to address most of these issues (there is currently no support for monospace font).
Follow [this thread from post #8]. There is a good chance that a final solution will be available in the coming days. You will also find screenshots of what has already been achieved there.

Best regards,

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
04-09-2024, 04:59 AM
Post: #12
RE: Fixed width font for terminal emulator
(04-08-2024 11:23 PM)komame Wrote:  Unfortunately, the built-in functions do not correctly support text formatting or only partially support it. Therefore, a project has been created to address most of these issues (there is currently no support for monospace font).
Follow [this thread from post #8]. There is a good chance that a final solution will be available in the coming days. You will also find screenshots of what has already been achieved there.

Best regards,

Thank you Piotr for the update. The solution in the link you provided looks like a lot of effort to create italic so I think the community will be glad to see the firmware update roll out for native italic support.

-Barry
Find all posts by this user
Quote this message in a reply
04-09-2024, 07:34 PM (This post was last modified: 04-09-2024 07:48 PM by komame.)
Post: #13
RE: Fixed width font for terminal emulator
(04-09-2024 04:59 AM)BarryW Wrote:  Thank you Piotr for the update. The solution in the link you provided looks like a lot of effort to create italic so I think the community will be glad to see the firmware update roll out for native italic support.

The achievement of italic font in its basic form (on a uniform background) can be obtained by just writing 9 lines of PPL code, so it doesn't require much effort at all. However, the mini-project under the link I provided will allow text formatting in many ways: there will probably be two or three types of bolding, strikethrough, underline, italic, with background, and framed. Eventually, I'll try to make it also support monospace font and maybe semi-transparent font too.

Of course, it would be ideal if the firmware update enabled native support, but I'm afraid it will take a very long time for that to happen. Furthermore, even if we eventually get it, the formatting capabilities probably won't be as extensive as in this emerging solution.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
04-10-2024, 05:14 AM
Post: #14
RE: Fixed width font for terminal emulator
(04-09-2024 07:34 PM)komame Wrote:  Of course, it would be ideal if the firmware update enabled native support, but I'm afraid it will take a very long time for that to happen. Furthermore, even if we eventually get it, the formatting capabilities probably won't be as extensive as in this emerging solution.

Hi komame
I took another look and found your 9 line code. I've implemented it with local variables below.
I also added a FREEZE command after the TEXTOUT_P.
I'm not sure I followed the whole thread on the use of your code.
It works except the font is not italics. Did I miss something?
Also the text color is black on white regardless of the color argument in BLIT_P. Did I miss something on that as well?
Thank you for your help.

-Barry

//-----------------------------------------------------------------------------

//EXPORT DRAWTEXT_P(text,x,y,font,alpha)
EXPORT DRAWTEXT_P()
BEGIN
LOCAL text:="hello folks";
LOCAL x := 20;
LOCAL y := 100;
LOCAL font:= 7; // 0-7.
LOCAL alpha:= 2000; // This is transparency.

LOCAL size=TEXTSIZE(text,font);
RECT_P("buffer");
TEXTOUT_P(text,"buffer",1,1,7); FREEZE;
BLIT_P(x,y,"buffer",1,1,size[1],size[2],#FFFFFF,alpha);
END;

ICON buffer 89504E470D0A1A0A0000000D49484452000001400000001A0100000000EE89B822000000027​4524​E5300010194FDAE0000001D494441547801EDCA31010000008230FA97D60AFEB27B6464341A8​F63​015D3D0C2DD86ED4F60000000049454E44AE426082;
Find all posts by this user
Quote this message in a reply
04-10-2024, 04:31 PM (This post was last modified: 04-12-2024 06:04 PM by komame.)
Post: #15
RE: Fixed width font for terminal emulator
(04-10-2024 05:14 AM)BarryW Wrote:  I took another look and found your 9 line code. I've implemented it with local variables below.
I also added a FREEZE command after the TEXTOUT_P.
I'm not sure I followed the whole thread on the use of your code.
It works except the font is not italics. Did I miss something?
[...]

The code you referred to was written to demonstrate the use of ICON as a graphic buffer. Here is a basic version of the code displaying text in italics:
Code:
ICON buffer 89504E470D0A1A0A0000000D49484452000001400000001E01000000007518FA34000000027​4524E5300010194FDAE0000001E494441547801EDCA310100000C0220FB97DE2A787AC04DAE248AA​2381D1F3A46AB8D6A43110D0000000049454E44AE426082;
EXPORT DIT_P(text,g,x,y,f,c)
BEGIN
  LOCAL size:=TEXTSIZE(text,f)+{1,3}, i, j=0, p=0;
  BLIT_P("buffer",G0,x,y,x+size[1],y+size[2]);
  TEXTOUT_P(text,"buffer",1,2,f,c);
  FOR i:=size[2]-4 DOWNTO 0 STEP 3 DO
    BLIT_P(g,x+j,y+i,"buffer",1,i,size[1],i+4);
    j:=j+1;
  END;
END;

However, this is a very simple solution that only allows displaying text on a uniform background (if the background behind the text is not uniform, it will be distorted). If you need a more advanced version, you'll have to wait until the completion of that mini-project.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
04-11-2024, 04:01 AM
Post: #16
RE: Fixed width font for terminal emulator
(04-10-2024 04:31 PM)komame Wrote:  However, this is a very simple solution that only allows displaying text on a uniform background (if the background behind the text is not uniform, it will be distorted). If you need a more advanced version, you'll have to wait until the completion of that mini-project.

It works! Nice compact solution. Thanks much for your help.

-Barry
Find all posts by this user
Quote this message in a reply
04-27-2024, 05:31 AM
Post: #17
RE: Fixed width font for terminal emulator
If someone needs a solution for printing text using a fixed width font, I can propose a very simple solution in the form of the MPRINT function:

Code:
EXPORT MPRINT(s)
BEGIN
  IF TYPE(s)≠2 THEN STRING(s)▶s; END;
  PRINT(REPLACE(CHAR(ASC(s)+65248),CHAR(65280),"    "));
END;

Its drawback is that it only supports basic characters:
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~
Special characters and accented characters are not handled correctly. Nevertheless, in most cases, this is entirely sufficient, especially for English-language programs.

Unfortunately, the font used has not been adjusted for printing text in monospaced mode, as for example, "W" or "%" are slighty too wide, resulting in all characters being too widely spaced. However, it is certainly suitable for terminal emulation.
A similar approach can be applied to TEXTOUT_P.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)