[BASIC] Use of Font_ScanString
François Vanzeveren (2221) 241 posts |
Hello I am struggling with the use of Font_ScanString to find out the extent of a string on the screen. I want the width and the height of a string located at textbuf%. Here is the code snippet I wrote
After the call, the coordinates returnd in c%!20 and onwards are as follow: The result is the same if I REM the line !c%=0:c%!4=0:c%!8=0:c%!12=0:c%!16=-1 Any help would be much appreciate. Regards François |
Chris Johnson (125) 825 posts |
One thing that looks wrong – you are not setting r3 and r4 on entry. I assume basic will set both registers to zero, which will mean stop the scan as soon as x or y exceeds 0, ie. scan will terminate immediately. I would suggest you use a large value, eg. 0×7fffffff for r3 and r4. I have also found that it is best to set the bbox values to zero before entry. I use font_scanstring a lot (from c) and it works fine for ‘simple’ strings. I have only had problems when the string contains vertical shift sequences. |
François Vanzeveren (2221) 241 posts |
Hi Chris Thanks for your answer, this indeed seems to fix my problem! Cheers François |
Colin (478) 2433 posts |
The y0 is relative to the baseline of the string so bounding box y0 is usually negative because of decenders ie the bottom a y is a negative coordinate. You can also get -ve x0 coordinates because the x origin of a character can be inside its bounding box. If you measure the width of a string it may be shorter than the bounding box x1 because character widths can be narrower than a box covering the characters. |