Post Reply 
Custom Text Formatting (Previously: Getting long results in a program)
03-18-2024, 08:37 PM (This post was last modified: 04-16-2024 01:08 PM by matalog.)
Post: #1
Custom Text Formatting (Previously: Getting long results in a program)
(Subject edited to suit the progression of the thread)

I have this little program
Code:
EXPORT unitex()
BEGIN
LOCAL KEYS:={"","","","","","","","","","","","","","","","","","","","","","","i","","","^2","m","n",",","","p","7","8","9","/","Ans(","4","5","6","*","","1","2","3","-","","0","."," ","+"};
LOCAL SKEYS:={"","","","","","","","","","","","","","a","b","c","d","e","","f","g","h","i","j","k","l","m","n","o","","p","q","r","s","t","","u","v","w","x","","y","z","#","-","","0","."," ","+"};
LOCAL Result:={"exa","peta","tera","giga","mega","kilo","","milli","micro","nano","pico","femto","atto"};
LOCAL K;
LOCAL F:=0;
LOCAL X:=0;
LOCAL Y:=222;
LOCAL C:="";
LOCAL oC:="";
LOCAL tC:="";
LOCAL Z:=0; 
LOCAL flo:=0;
LOCAL stc:=0;
LOCAL lis:=0;
LOCAL mult:=0;
LOCAL SHIFT:=0;
LOCAL num:=5;

  RECT_P(16777215);
RECT_P(0,0,320,12,0,0);
TEXTOUT_P("UNIT EXPANDER",103,0,0,16777215);

REPEAT
oC:=C;
K:=-1;
WAIT(-1);
FOR F FROM 0 TO 50 DO
IF ISKEYDOWN(F) THEN K:=F END;
END;
 IF K ≥ 0 THEN
  IF SHIFT=1 THEN
   C:=C+SKEYS(K);
   ELSE
    C:=C+KEYS(K);
  END;
  RECT_P(0,227,320,240,16777215,16777215);
    TEXTOUT_P(C,2,228,0,0);
  IF size(C)>17 THEN
    C:=oC;
  END;
  mult:=0;
IF size(C)>1 THEN
  IF C(size(C))>57 THEN
    IF C(size(C),1)="m" THEN
     mult:=-3;
    END;
    IF C(size(C),1)="u" THEN
     mult:=-6;
    END;
    IF C(size(C),1)="n" THEN
     mult:=-9;
    END;
    IF C(size(C),1)="p" THEN
     mult:=-12;
    END;
   num:=EXPR(LEFT(C,size(C)-1));
   ELSE
   num:=EXPR(C);
  END;
END;

 num:=num*10^mult;


     IF K=19 THEN    //  DELETE
     IF size(C)<2 THEN
     C:="";
     END;
          IF size(C)>1 THEN
            C:=LEFT(C,size(C)-1);
           END;

  RECT_P(0,227,320,240,16777215,16777215);
    TEXTOUT_P(C,2,228,0,0);
     END;
    X:=size(C)*7;



  IF K=30 THEN    //  ENTER
   IF C≠"" THEN
   tC:=C;
   RECT_P(0,13,320,240,16777215,16777215);


  FOR lis FROM 1 TO 13 DO
   TEXTOUT_P(string(num*(10^((lis-7)*3)))+" "+Result(lis) ,2,lis*13,0,0);
  END;
  RECT_P(0,227,320,240,16777215,16777215);
    TEXTOUT_P(C,2,228,0,0);
   END;
  END;

  IF K=41 THEN
   SHIFT:=NOT SHIFT;
  END;

 END;
UNTIL K == 4;
END;

And I would like it to output as many zeroes as it has to to avoid E type results on screen.

I guess I would have to use CAS to get those results?

Any tips on converting this program to get the results I want?
Find all posts by this user
Quote this message in a reply
03-19-2024, 12:59 PM (This post was last modified: 03-19-2024 01:02 PM by komame.)
Post: #2
RE: Getting long results in Program
CAS could help with large integers, but for small floating-point values, E notation would also appear (for floating-point calculations, CAS internally operates with precision up to the 15th decimal place, but presents a maximum of 12). In such a case, this can be handled manually without CAS by first converting the given value to text, and then adding the appropriate number of zeros to the front or back and adjusting the decimal point accordingly.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
03-19-2024, 01:19 PM
Post: #3
RE: Getting long results in Program
(03-19-2024 12:59 PM)komame Wrote:  CAS could help with large integers, but for small floating-point values, E notation would also appear (for floating-point calculations, CAS internally operates with precision up to the 15th decimal place, but presents a maximum of 12). In such a case, this can be handled manually without CAS by first converting the given value to text, and then adding the appropriate number of zeros to the front or back and adjusting the decimal point accordingly.

Yes, that's what I was thinking, it is all only powers of ten, and the number is stored as a string anyway.
Find all posts by this user
Quote this message in a reply
03-19-2024, 02:04 PM
Post: #4
RE: Getting long results in Program
Can I display all of the string numbers, without having to display the quotation marks for each string?
Find all posts by this user
Quote this message in a reply
03-19-2024, 07:24 PM
Post: #5
RE: Getting long results in Program
(03-19-2024 02:04 PM)matalog Wrote:  Can I display all of the string numbers, without having to display the quotation marks for each string?
I'm not sure if I understand your question correctly. In your program, you also convert numerical values to strings:
Code:
TEXTOUT_P(string(num*(10^((lis-7)*3)))+" "+Result(lis) ,2,lis*13,0,0);
and display them on the screen using TEXTOUT_P - as you can see, there are no quotation marks.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
03-23-2024, 09:06 AM
Post: #6
RE: Getting long results in Program
(03-19-2024 07:24 PM)komame Wrote:  
(03-19-2024 02:04 PM)matalog Wrote:  Can I display all of the string numbers, without having to display the quotation marks for each string?
I'm not sure if I understand your question correctly. In your program, you also convert numerical values to strings:
Code:
TEXTOUT_P(string(num*(10^((lis-7)*3)))+" "+Result(lis) ,2,lis*13,0,0);
and display them on the screen using TEXTOUT_P - as you can see, there are no quotation marks.

Yeah, I am pretty sure I had the problem before where results I sent to screen were in quotes.
Find all posts by this user
Quote this message in a reply
03-23-2024, 11:29 AM
Post: #7
RE: Getting long results in Program
(03-23-2024 09:06 AM)matalog Wrote:  Yeah, I am pretty sure I had the problem before where results I sent to screen were in quotes.

It's quite possible that you tried to display strings using TEXTOUT_P in "2D" mode, e.g.
TEXTOUT_P("ABC",50,50,{"2D"});
In this mode, TEXTOUT_P works correctly when displaying expressions, but has a bug that adds quotation marks in the case of strings.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
03-24-2024, 09:11 AM
Post: #8
RE: Getting long results in Program
Bonjour
D'après un petit fichier texte nommé Bétanotes écris par Cyrille, il est possible dans TEXTOUT et TEXTOUT_P d'utiliser des flags pour donner des attributs au texte ('Gras', 'Soulignés', 'Italique' etc...)
Je me demande si quelqu'un est arrivé à un résultat probant avec ceci ?

Hello
According to a small text file called Betanotes written by Cyrille, it is possible in TEXTOUT and TEXTOUT_P to use flags to give attributes to text ('Bold', 'Underlined', 'Italic' etc...).
I wonder if anyone has achieved a convincing result with this?

Sorry for my english
Find all posts by this user
Quote this message in a reply
03-24-2024, 10:26 AM
Post: #9
RE: Getting long results in Program
(03-24-2024 09:11 AM)Tyann Wrote:  According to a small text file called Betanotes written by Cyrille, it is possible in TEXTOUT and TEXTOUT_P to use flags to give attributes to text ('Bold', 'Underlined', 'Italic' etc...).
I wonder if anyone has achieved a convincing result with this?

Unfortunately, this is one of those cases that were implemented but did not work correctly from the beginning. In this extended form of TEXTOUT_P, the flags parameter (the last parameter) is ignored, and even the basic functionality of displaying text does not work correctly because quotation marks are added, and there is no way to bypass this. Therefore, it can only be used for expressions or numerical values (but without this advanced formatting).
The programmer even admits [here] that they did not test this...

However, this formatting works correctly in PRINT2D (albeit in a slightly truncated form, for example, there is no italics), so if you have static texts that you can display on the terminal during program startup and then buffer them as graphic slices (retrieved from G0) for later use, it may be useful in some situations.

For example, bold undercored text:
PRINT2D("ABC",7,255,3)

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
03-24-2024, 04:28 PM
Post: #10
RE: Getting long results in Program
Bonjour Komame

Merci pour ces précisions, je connaissais PRINT2.
Pour palier à ceci j'ai travaillé sur 2 fonctions : DEFTEXT et TEXT_P
qui permettent de définir des attributs et ainsi afficher du texte en gras, relief
souligné et barré.
Je pourrai publier cela si ça intéresse quelqu'un; par contre je ne sais pas comment
programmer un affichage italique.

Hello Komame

Thank you for these details, I knew PRINT2D.
To overcome this, I worked on 2 functions: DEFTEXT and TEXT_P
which allow you to define attributes and thus display text in bold, raised, underlined and strikethrough.
I could publish this if anyone is interested; however, I don't know how to
program an italic display.

Sorry for my english
Find all posts by this user
Quote this message in a reply
03-26-2024, 07:03 AM (This post was last modified: 03-26-2024 07:07 AM by komame.)
Post: #11
RE: Getting long results in Program
(03-24-2024 04:28 PM)Tyann Wrote:  Hello Komame

Thank you for these details, I knew PRINT2D.
To overcome this, I worked on 2 functions: DEFTEXT and TEXT_P
which allow you to define attributes and thus display text in bold, raised, underlined and strikethrough.
I could publish this if anyone is interested; however, I don't know how to
program an italic display.

Hi Tyann,

To display text written in italics, you first need to buffer the text, for example in G9, and then move it to the target area (G0?) using BLIT_P in groups of a few lines (to avoid too steep an angle), shifting them by one pixel to the right.
Let's assume that in variables sx and sy, you have the dimensions of the text (obtained using TEXTSIZE), and in G9 at position (0, 0), you have your text displayed using TEXTOUT_P. You start from the bottom, and you directly move the last 3 lines from G9 to G0 at (x, y+sy), then the next 3 lines to (x+1, y+sy-3), the next 3 to (x+2, y+sy-6), and so on. Because HP Prime applies antialiasing during text rendering, it's important to consider whether the text will also be displayed on other objects. If the background under the text doesn't need to be preserved (e.g., when the background under the text is of a uniform color), the matter is simple. But if you want to preserve it, you must additionally copy a portion of the target area from G0 to G9, on which you will display the text, moving it in groups of lines one pixel in the other direction (i.e., to the left), even before displaying the text on G9 using TEXTOUT_P, because otherwise, color distortions will appear on the edges of the text or distortions of the background.

Hah, before I finished writing this description, I realized that in the time I spent on it, I could have already completed the implementation of this solution Big Grin

If you need help, let me know, because it's already working in my head... Wink

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
03-26-2024, 11:12 AM
Post: #12
RE: Getting long results in Program
Bonjour Komame

Ha oui je vois le principe, merci beaucoup.
Je vais faire quelques essais, je reviendrai vers vous si j'ai des difficultés.
Toujours un plaisir d'échanger avec vous.


Hello Komame

Oh yes, I can see the principle, thank you very much.
I'm going to give it a try, and I'll come back to you if I have any problems.
It's always a pleasure to talk to you.

Sorry for my english
Find all posts by this user
Quote this message in a reply
03-27-2024, 09:33 PM
Post: #13
RE: Getting long results in Program
Bonjour

J'ai réussi à programmer un affichage en italic grâce aux excellents conseils de komame.
Je peux afficher en recouvrement ou en transparence et combiner avec du gras, du sous ligné etc...
je n'ai plus qu'a intégrer cela avec mes 2 instructions DEFTEXT et TEXT_P et je publierai cela ici.
Super.


Hello

I've managed to program an italic display thanks to komame's excellent advice.
I can display in overlay or transparency and combine with bold, underline etc...
all I have to do is integrate this with my 2 DEFTEXT and TEXT_P instructions and I'll publish it here.
Great stuff.

Sorry for my english
Find all posts by this user
Quote this message in a reply
03-28-2024, 07:13 AM
Post: #14
RE: Getting long results in Program
(03-27-2024 09:33 PM)Tyann Wrote:  I've managed to program an italic display thanks to komame's excellent advice.
I can display in overlay or transparency and combine with bold, underline etc...
all I have to do is integrate this with my 2 DEFTEXT and TEXT_P instructions and I'll publish it here.
Great stuff.

I'm glad I could help Smile
I'm looking forward to seeing the final result of your solution.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
03-29-2024, 06:09 AM (This post was last modified: 03-29-2024 06:10 AM by Tyann.)
Post: #15
RE: Getting long results in Program
Quote:I'm glad I could help Smile
I'm looking forward to seeing the final result of your solution.

Bonjour Komame
Qu'en pensez-vous ?

Hello Komame
What do you think?


[/quote]    

Sorry for my english
Find all posts by this user
Quote this message in a reply
03-29-2024, 09:44 AM (This post was last modified: 03-29-2024 11:45 AM by komame.)
Post: #16
RE: Getting long results in Program
(03-29-2024 06:09 AM)Tyann Wrote:  What do you think?

Very nice Smile

However, I have one small suggestion.
For the best effect, the first three lines at the base of the letters should be aligned evenly.
Compared to what you have now, if you're starting from the bottom, try to begin one pixel lower. I've made a quick implementation (without handling non-uniform background) to compare the results with yours, and I achieved this effect:

   

Do you see the difference?

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
03-29-2024, 10:50 AM
Post: #17
RE: Getting long results in Program
Do you see the difference?
[/quote]

Pas vraiment, effectivement je commence par le bas et j'ai déjà ajouté 1 à la valeur de la hauteur renvoyée par TEXTSIZE, car je trouvais qu'il me manquait un pixel sur les jambages des minuscules.
Devrais-je ajouter 2 ?

Not really, in fact I'm starting at the bottom and I've already added 1 to the height value returned by TEXTSIZE, because I thought I was missing a pixel on the lower case legs.
Should I add 2?

Sorry for my english
Find all posts by this user
Quote this message in a reply
03-29-2024, 11:19 AM (This post was last modified: 03-29-2024 11:29 AM by komame.)
Post: #18
RE: Getting long results in Program
(03-29-2024 10:50 AM)Tyann Wrote:  Not really, in fact I'm starting at the bottom and I've already added 1 to the height value returned by TEXTSIZE, because I thought I was missing a pixel on the lower case legs.
Should I add 2?

If you don't see a difference, it means it's not worth worrying about Smile
What I meant is noticeable (e.g.) at the base of the letters "m" and "n" (with larger fonts). It just caught my attention while implementing my solution. However, now I know that it's an insignificant detail, and your solution can remain as it is now.

Great job, Tyann!

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
03-29-2024, 11:29 AM (This post was last modified: 03-29-2024 11:34 AM by Tyann.)
Post: #19
RE: Getting long results in Program
En fait en mettant un fond uni, je vois la différence et vôtre résultat est ce que
j'obtiens sans ajouter 1 à la hauteur .
Mais j'ai l'impression d'un jambage tronqué sur les 'q' et les 'p'.

In fact, by using a plain background, I can see the difference and your result is what I get without adding 1 to the height.
But I get the impression of a truncated jamb on the 'q' and 'p'.

Sorry for my english
Find all posts by this user
Quote this message in a reply
03-29-2024, 07:59 PM
Post: #20
RE: Getting long results in Program
What method did you use to generate bold text?

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




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