Over the past several months I have been working on my first web app, and it has been coming along nicely, until I noticed something today. I just deployed the app via Xojo Cloud to do some live testing and went in to find an oddity occurring. I have a couple of places where I need a canvas to grow in height, depending on the amount of text present, such as in the screenshots below for a multiple choice feature. In the deployed app, it seems as though the calculations and adjusting the canvas heights is being ignored. Do I need to add a timer or something to adjust the canvas sizes after XX milliseconds?
I’d like to know if there is some sort of workaround or something else to do to get this to work in the meantime. This is a huge deal breaker as I need this functionality in several areas of the app. I tried it with a timer set at 3,000 ms, but this did not change anything. I don’t think the font is an issue. Looking for other ideas as I am so close to launching. @Ricardo_Cruz any hacks you can think of?
I added some comments to the Issue per my investigation and your mention of the TextHeight result
Still looking for a hack in the interim. I suppose I could calculate the number of characters and determine the height that way, but many of the text that is to be used also includes returns, which I don’t think a character count would work
Many moons ago, using other language, I wrote a graphics COM Object to render graphics and charts in MS Web servers. All tests were ok, and we used it extensively. One day, people told me “the component is not working anymore, the charts are blank” and I made a test and it worked in my local web server. Then I inspected the specific remote web server looking for problems. What I got different? That web server had no graphics card. Doing local tests I discovered that the graphic lib I was using, all in memory, depended in some way of the presence of graphics hardware. Techs reached the server and installed a cheap graphics card and the component started to work. Maybe something like this, currently, in some order, occurs in virtual web servers installed in text mode? Graphic subsystems missing some graphics capabilities needing installation of some kind of graphics driver/lib? Or just a Xojo bug? Why I remembered that? Because some readings I got without a graphics card were 0 (zero) too.
So I made up my own hack for this issue since I would like to get this app launched sooner than any fix (if any) will be implemented
I made a new MySQL table to hold the text heights
In the debug-mode app (the one that works with the TextHeight calculations and getting the canvases and labels to grow), I saved to the text height table the different heights of the various fields I need to calculate the heights. Ran the app and saved to this table
I modified the app and removed the instances of relying on the Graphics.TextHeight calculation and changed this to the call to the new table to get the height of each field that needs calculating. Set the labels and canvases to this height, deployed and tested, and it works
While this is A LOT more work (and I only tested in one instance out of many), and is not the most elegant, it will get the job done for the planned launch by the end of July
I am hoping this will get fixed in Xojo. While this is working now, it is now another table I will need to manage with any changes to my content db
There’s nothing for Xojo to fix. The problem is that the font you are using doesn’t exist on the server where it’s deployed. If this is xojo cloud, connect to your server using SFTP and put a copy of the TrueType font file into the supplied fonts directory.
See the issue is that the drawing code is on the server whereas the actual canvas is on the user’s browser so the measurements like this have to be done ahead of time using a rasterized version using a picture. If the font doesn’t exist, TextHeight returns 0 and your calculations are all wrong.
That is interesting Greg. Thanks for the info. I will test it out tomorrow
For my own understanding, since web is a new avenue for me, is the server without any fonts from the get go? I would have assumed a “standard” font would be there. For this app, I am just using the standard built-in font (not specifically setting one for this canvas piece or anywhere else for that matter), but it sounds like that not even that is present on a new server?
This was talked about for a long time when it was first decided. The problem is that the server OSes rarely come with the fonts because there is no UI to render them. The fonts that you would most likely want to use require acknowledgement of a license agreement by the end user and it was impractical to do at the time. Even Adobe’s base 13 fonts used in PDF files everywhere have a licensing fee and the onus of not abusing that right is passed on to you when you click “I agree” on the OS license agreement.
Anyway, the end result is that Xojo Cloud does not include any fonts. It’s up to you to license and place the ones you want to use on your server.
Hi Ivan. Thanks for your comments and suggestions. Yes, using a canvas + a label seems like overkill, but I have several reasons for doing this over using a scrollable label
I need the ability for the user to click anywhere in the text’s area to make a selection. When they make a selection, the border changes color to show their selection. A .Pressed event is not available for a label, at least I don’t think it is
I purposely place the label with the text behind the canvas for the purposes of being able to make a selection but also for preventing the ease of selecting the text and copy/paste. This app is a study guide app with a lot of content. In our industry, it is very common for students to copy/paste content and post it publicly. I’ve found that placing a canvas on top of a label prevents the selection of the text. I know, I know, there is nothing stopping someone from typing out the material and posting it. They still do, and I handle these on a case-by-case basis. This at least does not make it easy
Long ago, in my desktop version of this study guide app, I used a fixed sized TextArea to hold the text, and the student would need to scroll through it to read it all. The feedback I received over the years is that the students hated having to do this. Hence, I moved to using a growable canvas. For the desktop app, I do not also need to include the label to hold the text since desktop graphics does work with wrapping. Unfortunately as I’ve found, WebGraphics is missing the one parameter to make this happen