Post Reply 
HP 48GX - Center Text in the Display Area
08-27-2023, 08:41 PM (This post was last modified: 08-27-2023 09:44 PM by Giuseppe Donnini.)
Post: #2
RE: HP 48GX - Center Text in the Display Area
If you use string objects, the finest granularity you can achieve is indeed a single character’s width. If you want pixel-granularity, you have to use graphics objects instead, that is, you have to convert your text strings into separate graphics objects and then paste them into the graphics screen (i.e. PICT; System RPL would allow you to use the text display, too.)

The \->GROB command exists for this very purpose. It takes two arguments:
  • in level 2, a character string to be transformed into a graphics object;
  • in level 1, a real integer from 0 to 3 specifying the font size to be used.
    • 1 represents the small font (variable width [ranging from 2 to 6 pixels] x 6 pixels, the bottom row being always left blank since the small font has no descenders).
    • 2 represents the medium font (6 pixels wide x 8 pixels high).
    • 3 represents the large font (6 pixels wide x 10 pixels high).
      (Note that in all three cases, the width includes a blank column at the right edge that separates successive characters.)
    • 0 is intended for mathematical expressions. It uses all three fonts, if necessary, and produces an EquationWriter-like image of the input. The size of the resulting graphics object will be at least 131 x 56 pixels, even if the expression does not fill the entire display.

Here is a little demo to get you started:
Code:

\<< PICT DUP PURGE   @ Clear graphics screen, keep copy.
  "Test String"      @ Use arbitrary text string for test purposes.
  2 \->GROB          @ Convert input text to grob using medium font.
  DUP SIZE DROP      @ Get size of grob; drop height, keep width.
  #131d SWAP - 2 /   @ Compute #x-coordinate so that grob will be horizontally centered.
  #0                 @ Use arbitrary #y-coordinate for test purposes (0 = top row).
  2 \->LIST          @ Build pixel coordinate pair.
  SWAP REPL          @ Paste grob into graphics screen (automatically resized to 131 x 64).
  {} PVIEW           @ Show result.
\>>
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP 48GX - Center Text in the Display Area - Giuseppe Donnini - 08-27-2023 08:41 PM



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