Post Reply 
TEXTOUT_P()
04-29-2022, 11:38 AM
Post: #1
TEXTOUT_P()
Using this to Return the X coordinate at which the next character of the string should be drawn at, doesn't seem to be working correctly with a different font size.

The way I am using it, it is fine at font 0, but not fine at font 3.
Find all posts by this user
Quote this message in a reply
04-29-2022, 07:59 PM (This post was last modified: 04-29-2022 09:38 PM by matalog.)
Post: #2
RE: TEXTOUT_P()
This little program highlights the problem:

Code:
EXPORT textest()
BEGIN
LOCAL ab:=0;
LOCAL cd:=0;
LOCAL str:="abcdefg";
rect();
ab:=TEXTOUT_P(str,G8,0,0,0);
cd:=TEXTOUT_P(str,G8,0,60,4);
TEXTOUT_P(string(ab)+" VS "+string(cd),120,120,0);
WAIT(-1);
FREEZE;
END;

This results in the same number being printed twice - 42 VS 42.

Now, I realise that TEXTOUT_P here is not being used to refer to the current screen G0, but this is the only way I could see to return the number of pixels to the end of the string without having to print the numbers to the screen.

If I put the TEXTOUT_P's on G0 instead of G8, then the numbers are different 42 VS 56.

This should work the same whether the TEXTOUT_P is on G0 or G8, this is a bug.
Find all posts by this user
Quote this message in a reply
04-30-2022, 05:14 PM (This post was last modified: 04-30-2022 05:18 PM by Guenter Schink.)
Post: #3
RE: TEXTOUT_P()
A GROB 8 needs to be defined beforehand.

inserting the line e.g.:
DIMGROB_P(G8,80,100)
would return the correct values.

Here are my findings.

1. you know font(0) refers to the system font, don't you? (small(2), medium(3) or large(4))
2. seems the GROB needs to be wide enough to hold the string
3. at least one pixel on the vertical axis of the GROB needs to be in the string
4. if not it defaults to the system font
5. unless the selected font is smaller than the system font, then it provides the correct value

examples:
1.
system font set to large
DIMGROB_P(G8,1,1) // yes only one pixel
ab:=TEXTOUT_P(str,G8,0,0,1);
cd:=TEXTOUT_P(str,G8,0,60,7);

returns 35 VS 56. 35 because font(1) is smaller than the system font, and 56 because font(7) is larger than the system font, therefor it defaults to the system font (large is equivalent to font(4))

2.
system font set to arbitrary size
DIMGROB_P(G8,320,61) \\ Yes, just one pixel more on the y-axis works
ab:=TEXTOUT_P(str,G8,0,0,1);
cd:=TEXTOUT_P(str,G8,0,60,7);
returns 35 VS 78

Conclusion: If you wish to utilize GROB 8 to keep track of the x-position where the next character would be printed, create GROB 8 with width of expected length of the string e.g 320 by a vertical size of at least 1 pixel.

example.
system font set to arbitrary size
DIMGROB_P(G8,320,1) \\ Yes, only one pixel on the y-axis works
ab:=TEXTOUT_P(str,G8,0,0,1);
cd:=TEXTOUT_P(str,G8,0,0,7);

returns 35 VS 78

HTH,
G√ľnter
Find all posts by this user
Quote this message in a reply
05-01-2022, 02:53 PM
Post: #4
RE: TEXTOUT_P()
Thanks, that works, great.
Find all posts by this user
Quote this message in a reply
Post Reply 




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