Formatted text in a window
Chris Mahoney (1684) 2165 posts |
Hi all, Can anyone advise the easiest/recommended way to display formatted text in a window? I’m not looking to do anything hugely complicated, but I would like to be able to have, say, a paragraph with a few words made bold or italic. I’m using C and the Toolbox, and while you can set the font of a Display Field it doesn’t seem like this can be done on a per-word basis. Do I need to use something a bit lower-level? I’m aware of Font_Paint but I’m not sure whether it’s the ‘best’ option (and I haven’t written any code yet so I’m happy to look at something completely different). Any suggestions? |
Chris Mahoney (1684) 2165 posts |
Thinking about this a bit more… could I push the text into a DrawFile using the text formatting codes (\F0 etc.) and then DrawFile_Render the result into my window? Is that likely to be the easiest solution or am I overthinking this? |
Bryan (8467) 468 posts |
Could you use Netsurf to display the text? |
Chris Mahoney (1684) 2165 posts |
I hadn’t even considered that, but it might not only work, but actually greatly simplify things. I might have to have a play. Thanks :) Edit: But then the question is “how do I replace/update the text?” If I just ‘launch’ a new HTML file then NetSurf will presumably open a new window instead of replacing the current one. |
John WILLIAMS (8368) 493 posts |
Effectively press the reload button by sending it ^F5? Will be a bit slow, but may be fast enough. I use a NetSurf window to display reminders or prompts for thing like “Have you taken your tablets?” and “There’s a new test ROM available”, but they don’t need updating. CSS is a useful way of differentiating between events, though, and could be used to alert the user to changes in the text as well/instead! I added the day of the week to that message to match with the day on the lid of my tablet holder! |
John WILLIAMS (8368) 493 posts |
Or you could simplify the programming effort even further and use Druck’s WindOpen module to simulate clicking the window’s menu item “Navigate > Reload this page”. |
Chris Mahoney (1684) 2165 posts |
Automating NetSurf didn’t sit right with me, so despite the advice of everyone in this thread I chose to continue with my original plan. I’ve written some code that takes a string, slaps a Draw header onto it, and uses However, I’m stuck. I can get everything working when my window is in the bottom-left corner of the screen, but I’m not sure how to get
That puts the bottom-left corner of the drawing at 512 OS units from the left and bottom edges of the screen. My question is how to do the same from C. This renders correctly at 0,0:
And I would expect this to render at 512,512:
However, it doesn’t render anything. No error is raised (e is null) but nothing gets rendered. What am I doing wrong? |
Rick Murray (539) 13840 posts |
Don’t take any of this as useful given that it is ~4am 1, but… I think you’re missing the fixed point behaviour of the transformation matrix.
1 Had to get up at 3.30 to be at work for 5 yesterday. And today…. 😪 |
Chris Mahoney (1684) 2165 posts |
No luck, I’m afraid. Still no output.
:( |
Rick Murray (539) 13840 posts |
How exactly are you doing this? Just a clear screen and plot as a single tasking app, or in a Wimp app? I ask because the latter case comes with complications. The first being a clipping rectangle so anything outside of what the Wimp wants redrawn will not be touched, and the second being that the Y coordinate counts backwards from zero. Or something. I’m still shattered. :(
Yup. It’s the peak period run up to Christmas 1. So an extra half hour a day and then alternate Saturdays. I don’t think it’s so bad for the production line team as they start at 5am anyway, but when your regular wake up time is 7am, a 5am start (3.30am wake up) really messes things up. 1 It’s kind of stupid that our primary “holiday” is in the middle of freaking winter. |
Chris Hall (132) 3554 posts |
The Winter solstice is on 21 December so that is when Winter starts. The peak period run up to Christmas is some way away. |
Rick Murray (539) 13840 posts |
Winter starts when the weather patterns decide winter starts.
Clearly you don’t work in manufacturing. Stuff needs made, then it needs distribution, including overseas. Then it needs putting into shop freezers. And here’s the important part – to be available to consumers before they decide to buy a competitor’s product. The Christmas rush begins in mid September and we’re already shipping, and stuff will turn up in some places in a week or two when everybody prepares for their big “Christmas stuff”. I expect the supermarket will have colour coded toy aisles again (hello kitty pink for the girls and blues and reds for the boys) in a couple of weeks. Yes, early October. Before flipping Samhain (Halloween). It’s stupid capitalist bollocks, but it’s stupid capitalist bollocks that pays my wages… ;) |
Steve Pampling (1551) 8170 posts |
The “Halloween” themed clothing beat the Xmas clothing into the shops by about a fortnight. |
Chris Mahoney (1684) 2165 posts |
Wimp. However, plotting without a transform works fine and just appears in the wrong place, so I’d be surprised if a transformed plot is getting overwritten. However I confess that I haven’t messed with bounding boxes yet because I wanted to tackle one thing at a time. Edit: As a bit of a hack I just passed in a bounding box of the entire screen. With no transform it still plots correctly, but the moment I add the transform I’m back to no output.
I can imagine! Daylight saving started here yesterday, and just a 1-hour difference is enough to make everything feel ‘weird’. 3.5 hours must be horrible! The only time I’m ever up that early is when an international flight is involved, and I haven’t had one of those for a while. |
Stuart Swales (8827) 1357 posts |
This is the relevant bit from PRM 3, Chris: The matrix is passed as pointer to a six word block, in the order a, b, c, d, e, and f as described earlier. That is: Offset Value Common use(s) 0 a x scale factor, or cos(θ) to rotate 4 b sin(θ) to rotate 8 c –sin(θ) to rotate 12 d y scale factor, or cos(θ) to rotate 16 e x translation 20 f y translation If the pointer is zero, then the identity matrix is assumed – no transformation takes place. Remember that a - d are in Transform units, while e and f are in internal Draw units; for example plotting with a scale factor of 1 – which is &1000 Transform units – and with a translation of (64, 32) – which are respectively &4000 and &2000 internal Draw units – would use the values [&1000, 0, 0, &1000, &4000, &2000]. Fireworkz always uses the matrix to plot Draw files (and paths), but I never faff with toolbox structs, using my own that simply defines |
Chris Mahoney (1684) 2165 posts |
Bingo! I made my own struct and it worked straight away. Thank you very much! :) Edit: Actually, this is working too:
According to my notes I’d already tried that and it hadn’t worked, so I guess I’d made a typo somewhere along the line and then gone on a wild goose chase :( Anyway, it’s working now, so thanks again! |
Stuart Swales (8827) 1357 posts |
Too much abstraction, huh? |
Clive Semmens (2335) 3276 posts |
That’s a description of a subset of what such a matrix transformation can do. It’s easy enough to apply its more general application (which also covers shears and rotated shears) to paths. This subset can also be applied to text for FontManager to render – but I don’t know how to apply the more general version to text, other than by converting it to paths first. Does drawfile_render handle text in drawfiles in a general way, or would it bork at rotated condensed text (by way of example)? I could try it myself, I suppose…but maybe someone already knows? |
Jean-Michel BRUCK (3009) 359 posts |
There are also the Skew in X and Y possible with the matrices. I use it for Svg2Draw decoding. |
Clive Semmens (2335) 3276 posts |
Absolutely – but do they work with text that hasn’t been converted to path? I don’t know whether *render drawfile applies the matrix to text properly; it’s not obvious how to do it in BASIC since we don’t have the X and Y co-ordinates of every point in the text until it’s convered to path. My helpfile already tells you not to have multiple spaces (or commas) between values 8~) – or initial spaces, but I guess you haven’t tried that. I could make the matrix input PROC even more tolerant of variation if necessary, but I hope I don’t need to… |
Jean-Michel BRUCK (3009) 359 posts |
Sorry I mixed the Threads, back to Draw Render in a draw file Indeed text pose a problem. There is no function yet to convert text to path without using Draw? |
Steve Drain (222) 1620 posts |
In the other thread I said:
I imagine that means it uses the transform on individual items as it displays them. You cannot do this to the DrawFile objects themselves. I do not think it has to convert text to a path. It is interesting that it does this for TextAreas as well. |
Clive Semmens (2335) 3276 posts |
Thanks, Steve – I’d missed that. |