DrawGen
nemo (145) 2546 posts |
Jolly good. I confess I got distracted by DrawBasic/DrawScript and I’ve not been paying attention. Sorry Jim. |
jim lesurf (2082) 1438 posts |
No worries. :-) The most basic (sorry but puns seem unavoidable!) question which I’d pose is: Does it make more sense to try and add things to the existing ABC BASIC code for the DrawGen module, or to replicate what it does using ‘C’ to create a new module? I’m now not capable of doing either, so its a starter question for those who want to try and carry this forward. I can see the advantages of it using ‘C’ for the future, but it means a complete re-write, whereas to add a few features whilst keeping to the ABC BASIC would be a shorter task for someone who knows the ABC BASIC. I had a furtle and I think ‘ve found a number of example ’C’ programs that use the module. I’ve even found some ancient FORTRAN ones, which at least indicate DrawGen being ‘language agnostic’! Another advantage which I was made re-aware of today when writing the graphics program that prompted this is that the module approach means any floating point stuff can be done by the specific program and then just passes ‘instructions’ on to the module once that is done. I have, however, also posted on the thread that was mentioned about the DDE to see if the new !ABC compiler is still available that way. BTW anyone looking at the ‘C’ examples using DrawGen may find it handy to note that if you simply omit the DG_make() at the end you get left with the ‘script’ file in ram that DrawGen reads to actually build the DrawFile. So you can check what you’re generating for it. FWIW I’ve now bodged a way past the limitation that prompted my deciding this should become ‘open’.(1) But I still hope people think it a worthwhile idea to develop DrawGen, and could see the point of it being able to do things like include sprites, etc, and offer more features than at present. (1) if interested, you can see my ‘vertical text’ bodge here http://jcgl.orpheusweb.co.uk/temp/vtext But genuine 90 deg written text would be better in many cases. |
Chris Johnson (125) 825 posts |
OK, Jim, looks like I am the only volunteer. I’ll get in touch later for a quick discussion on things to do. |
Steve Drain (222) 1620 posts |
I was intrigued by the problem and I have done something already. The intermediate data format seems to be only integers, so angled text is not feasible as it stands, but rightangle rotations are. I have compiled it with ABC 4.18, the first time I have used ABC in a quarter of a century. Wow! Is it sloooow? Over 7 minutes for a 16k program on my mini.m. There is a new command “textr” which takes two additional parameters after x and y. The first is the number of rightangles anti-clockwise, from 0 to 3. The second is the flags – bit 0 for kerning, bit 1 for reversed text, so usually 0. I will tidy up and document this tomorrow, and upload it to my site. |
nemo (145) 2546 posts |
Having never used ABC I’m surprised to learn that it can produce modules. (Surprised and horrified ;-) I understand the format now. Can I suggest a “matrix” command that would apply thereafter – this would allow transformed text to be produced easily. Steve, I presume you are centring the characters when plotting them vertically? |
Steve Drain (222) 1620 posts |
This is a quick and easy implementation of transformed text objects with the restriction to rightangle rotation. A little more thought should make a whole number of degrees a possibility, but Jim particularly wanted this text feature. I used the transform matrix method you suggest in DrawIt. I originally bought ABC with idea of producing modules. It does it, but is very inefficient with memory and in those days that mattered. Soon after I ‘mastered’ assembler. |
Clive Semmens (2335) 3276 posts |
I mastered assembler purely for speed back in the day – and I think I can fairly say I did master it, given that ARM employed me later to write their Assembler Guides – but I’ve never written a module, and although I surely mastered assembler in 26-bit days and understood later versions well enough to write the guides, I’ve not written more recent versions of assembler more than just enough to test that I’ve actually understood it. So I don’t know whether I’ll ever really write a module at all. |
Rick Murray (539) 13840 posts |
Something is horribly wrong. I just built it with v4.14 (I guess I’ve neglected to update it, must fix that) and it took about six seconds on an original Pi2. Edit: Found ABC 4.19 and installed it. It’s quicker. Maybe four seconds.
If I remember correctly, it has no “entry points”, so it can do commands or it can do SWIs, but not both. I guess it was seen as a way to allow those who only understood BASIC to be able to make modules, though the main reason I write modules is for interacting with service calls, events, etc. Can ABC do this?
Do you have the DDE? https://heyrick.eu/blog/index.php?diary=20150323 |
Chris Johnson (125) 825 posts |
Just as well I held fire then 8) |
Chris Hall (132) 3554 posts |
The tricky thing with rotated text (apart from the easy 90, 180 and 270 degree rotations) is getting the bounding box correct. |
Clive Semmens (2335) 3276 posts |
Properly correct – yes, very tricky. Guaranteed big enough (almost certain to be somewhat bigger than necessary) by putting a box round the original bounding box, rotated – quite easy, and good enough really. It’s hard to imagine a situation in which that isn’t good enough: you can’t, after all, have a bounding box that’s a rectangle at an angle, so you’re (almost) always going to have a substantially bigger bounding box anyway. |
Steve Drain (222) 1620 posts |
An accurate bounding box is not necessary to produce a working DrawFile here, so you can just have the maximum possible size. This is what DrawGen does and I did with DrawIt. Other systems may do likewise, and I might have got the idea from one of them. Where a bounding box is necessary the calculation can be tricky indeed. |
jim lesurf (2082) 1438 posts |
I may well have not understood it, and that was why I failed to make it work. However IIUC the object 12 type (rotated text) lets you specify the text angle in a form of a 4-byte value which is essentially scales so the integer value 2*16 is then scaled to give ‘1’ in the transform matrix. Thus enabling (fairly) arbitrary rotations. However since I was unable to make it work, maybe this was my error! :-) FWIW Here the existing module code compiles in just a few seconds using my ancient copy of !ABC on ARMX6. |
nemo (145) 2546 posts |
Font_ScanString with R2b18. |
Chris Hall (132) 3554 posts |
I’m sure someone will pick holes in my method:
|
David Feugey (2125) 2709 posts |
It is. |
Steve Drain (222) 1620 posts |
I have how upload my modified DrawGen module. I have not included source, because I am not sure how Jim wants to play this.
Yes it is. I tried it on a Pi and it did compile in seconds. What is up with my mini.m? Unfortunately, all my work is there and transfering back and forth is a bit of a pain. ;-(
Sorry, Chris. I had already done it by the time you posted. Should a collaboration be needed the I am in, if I can sort out what is up with ABC. ;-) |
Steve Drain (222) 1620 posts |
I lied. I have checked and I used Font_ScanString, but that must have been quite late in the development. |
jim lesurf (2082) 1438 posts |
From my POV I’m happy for people to co-operate and do this in whatever way suits them all. Discussion / communication via the forum seems OK to me. But if something else is more convenient, just say and I’ll follow on. When someone puts up something like a provisional new version of the DrawGen module/code my main interest is to know what I’d need to write as a ‘way in’ as a new ‘C’ proc for the DG library I have thus far, so it can accessed with that ‘h’ library via a simple call to a proceedure. I only have to glance at Chris’s code above to see that the actual code others can produce is way above my ‘pay grade’ to comment on. 8-) I can make tea, but I’m a bit far away.. (Have some nice single estate FF darjeeling, though…) |
jim lesurf (2082) 1438 posts |
FWIW just tried Steve’s version ‘textr’ and it worked nicely via a DG_lib.h proc. :-) One suggestion: When putting up a modified version, it would be good to alter the text printed by ‘DrawGen help’ to show what version it is, who modified it, and a date, perhaps. Make it easier to keep track of which version is being tried/used. By all means remove the stuff I put there which no longer applies! If nothing else, I ‘retired’ in about 2005! |
nemo (145) 2546 posts |
Yes, me. Don’t use StringBBox, use ScanString like I said an hour earlier. StringBBox has been deprecated since RISC OS 2.50 and cannot, due to rounding errors, be relied upon to cover every pixel. And also, almost everything else you’ve written is unnecessary too. Just create the matrix, get the parameters for ScanString right, and it’ll return the bounding box which you then scale to draw units (*256/400) and that’s it. It’s about four lines of Basic. |
Chris Johnson (125) 825 posts |
OK, no worries. I will wait a day or so and then liase with Jim to see what else could be done, and whether more could be added. I have plenty to do on updates to some of my own apps in the meantime. |
jim lesurf (2082) 1438 posts |
The only specific thing I wanted for my own use was the ability to generate the ‘vertical’ (i.e. 90 rotated) text strings. Which Steve’s module now provides. However.. 1) If arb rotation angle text is practical, it makes sense to me to include it for when someone needs it. 2) The one thing that people have asked me to add in the past has been the ability to include sprites and/or jpegs in the created drawfile. This isn’t something I’ve ever needed, but looks useful. Indeed, having written (2) I recall a while ago when I produced an animated graphic by starting off with a set of drawfiles it might have been useful to be able to include a sprite/jpeg. Didn’t occur to me at the time as I’ve been used to not having the option! However it isn’t something I really need for myself, but suspect other users might. The bigger question is the one I raised early on. Would it make more sense for the longer term for the module to be based on ‘C’ and not depend on the continuing availability of an ABC compiler that can be run as the OS and hardware develops and changes? |
Chris Hall (132) 3554 posts |
Don’t use StringBBox, use ScanString like I said an hour earlier I corrected the routines to calculate the bounding box of text sometime between 1992 and 1995 and it was originally intended to be compatible with RISC OS 2. It works well enough so I have left it alone. The one thing that people have asked me to add in the past has been the ability to include sprites and/or jpegs MakeDraw now allows the following:
|
jim lesurf (2082) 1438 posts |
From my POV I’d say that, in terms of strategy, it probably makes most sense to: 1) try to keep all need for calculations that benefit from floating point to the calling program that constructs the file which DrawGen then reads, interprets, and uses to build the DrawFile. e.g. when a transformation matrix is needed, allow the calculation of the six 4-byte values to be done by the calling routine and then have it poke the relevant series of values into the file DrawGen reads. Thus not needing any complicated calculations in the module. 2) In the long term, I suspect developing and maintaining DrawGen would benefit from it being re-written in ‘C’. Otherwise it will always be tied to requring the !ABC system and someone who can write the ABC BASIC required. (My main worry there is ensuring that !ABC was developed to continue to work on ever-newer hardware and OS versions.) More tactically/personally, I’m quite happy to see additions provided I can work out how to write a ‘C’ proc for the h library that I or others can then use. And appreciate any help with developing or maintaining. It is now ‘open’ so I don’t think my opinions carry more weight than anyone elses from this time on. :-) |