Dear old RiscOS - anyone remember that? - had a system call which justified any text you gave it. I like it and used it a lot. I have been rather disappointed that there does not appear to be a native justification routine in either Windows or (which might be a bit much to expect) BB4W.
I have bodged something which counts the number of space in a line, calculates the length of the line, subtracts that from the desired length, divides the remainder by the number of spaces, and then prints each word in turn, advancing the required distance at each space. It works pretty well, but if anyone knows of a better routine, I'd be grateful.
Justifying text
-
- Posts: 60
- Joined: Tue 03 Apr 2018, 19:34
Re: Justifying text
Any help from the manual, 'Aligning proportional-spaced text' ?
Svein
Svein
-
- Posts: 327
- Joined: Wed 04 Apr 2018, 06:36
Re: Justifying text
Thanks. As I said, I already calculate the line length and to do that I use the GetTextExtentPoint32 call referred to in the Help. Actually, in theory the WIDTH command in the latest version of BB4W should provide the same answer, but whether I am doing something wrong, it doesn't. It works most of the time and then falls over when I'm least expecting it. At least the SYS call is reliable.
Re: Justifying text
In fact the WIDTH() function does quite a lot more than the Windows API (as well as having the advantage of being cross-platform, of course):
- WIDTH() takes account of whether BBC BASIC is running in ANSI or Unicode (UTF-8) mode, and will return the correct result in either state.
- WIDTH() knows about VDU codes, which the API doesn't. So for example if a string has an embedded colour-change sequence WIDTH() should return the correct value whereas the API will not.