I am having problems finding the width of a string of text in a UITextField object. I know there are various methods documented to ostensibly do this, but they simply do not work. There is one and only one method that produces a correct value, but requires the use of the textField property of an mx.controls.Text object. If that textField is used, then getCharBoundaries works correctly, and you can just add up the returned widths from a series of calls to it to get the width of a string of text.
However, if you just call getCharBoundaries on a stand-alone TextField or UITextField (i.e. one that is not a property of MX:Text) then getCharBoundaries returns some entirely different value that is substantially less than if called on the textField property of an Mx:Text object. It is in fact about 25% smaller than the correct value, but that is not even consistent, because change the font size and the discrepancy seems to vary non-linearly. So what getCharBoundaries is actually returning in the case of a stand-alone UITextField, I have no idea.
But actually, call any other method for determining text width of a TextField (other than getCharBoundaries within an MX:Text object) , and you'll get the same erroneous value: TextField.getUITextFormat().measureHTMLText(...).width (or measureText), and TextField.getLineMetrics(...).width all return this same erroneous value. And you might say, "Well they're probably just returning the width from left most pixel in the text to righmost pixel", except as I said to begin with, in one instance getCharBoundaries is actually returning the total cell width of the text, which is what I want, (and then when called from a stand-alone Textfield some completely different value.)
But my problem first appeared when I tried to change an MX:Text object (within which I could call getCharBoundaries successfully) to a UITextField. So now neither getCharBoundaries or anything else works correctly for determining text width. (Note: I'm not actually displaying the UITextfield, but rather am using it for text processing purposes behind the scenes, as it is significantly faster than MX:Text. I set UITextField.htmlText to a value, then make a series of calls to getTextFormat, setTextFormat, and replaceText. And it all works as before with the Mx:Text object, except much faster. Only problem is there is now apparently no way to determine text width for a string of text, even though Adobe documents all these methods that are supposed to do that.
And so my question is, I get on google, and there is very little commentary on this, and no work around at all that I have seen documented anywhere. I did see one thread on actionscript.org from a couple of years ago, where someone else also said that all these width methods simply do not work. There was confirmation of this by someone, but no resolution provided. (Note: this poster noted that the error seemed to escalate with increasing font sizes and was not as noticeable at small font sizes, which I suppose may explain why it doesn't seemed to have been noticed.)
But I downloaded Flex 4 here a while ago, and the problem is still there. So just wondering if I am truly the only person who is cognizant of this, or has encountered it, or possibly someone point out what I'm missing. I guess the Flex Bug tracking system would be an option for me, but that would probably be a Black Hole.
So anyway, just wondering if anyone's encountered this or found a work around.
OK, I've solved my problem. I apologize for the rant against Adobe but then again I might not have solved this otherwise.
The problem was rather obscure and almost certainly not relevant to others, but here it is:
I was trying to find the text width of a prefix that contains some characters in a special nonstandard utility font I created with very nonstandard attributes. Mx:Text.textfield.getCharBoundaries had no problem with it, but every other width method did, evidently. Of course, Mx.Text.textField is not actually a TextField or a UITextField, but rather an IUITextField, meaning it just implements the interface. Evidently its implementation may have nothing in common with the implementation of TextField and UITextField which are both directly related.
As far as this nonstandard font, I had not had any problem with it in the past, so failed to identify it as the culprit. Its character widths are identical to another font's, so that solves my problem.
I have to provide an update here. The problem wasn't the font I was using, but rather that it was not a Windows System Font. measureText, measureHTMLText, etc. won't work unless a font is installed on a user's own system previously. It makes no difference if the font is embedded in the Flex Application, the end user has to already have that font installed on his own system for those width methods to work. MX:Text.textField.getCharBoundaries is the only one that doesn't care whether or not its a systemFont. (UITextField.getCharBoundaries also requires it to be a system font.)
Related
I can share the code if needed but it felt like a lot to share to start, so I'll try to explain narratively. I am creating an interface to display network data (as you might have guessed from the title). My first issue has been going on for a few days where visIgraphLayout is not laying out my visual correctly. Regardless of using "full" or "square" as the "type", the network map extends beyond the edge of the display space. When I resize the interface window, then the map will snap to full. Why won't it simply resize automatically? If it matters, I do have the output space in a box element. Also, I have the layout styles working off radiobuttons, and when I switch between styles the map goes beyond the edges again.
Part 2 begins. While the above problem is annoying, it was livable. However, a new wrinkle popped up. I added some font size control to my visNodes code - i.e., radiobuttons set to switch between off (0), small (5), standard (14), and large (40) font size options. Once I implemented this code, when I resize the interface window, now the network map disappears completely after initial load. If I select a new label option, it will redraw but beyond the edges of the space.
All the issues resolve themselves if I ditch the visIgraphLayout, but then I lose the layout functionality which I really like.
I hope this is clear enough. I really appreciate any insights the community might provide. Be well.
I think I have figured out an answer. Long story short, certain pieces didn't work and play well with others. Went through and build it again, and all it good.
Cheers.
I am having an issue with a specific mac that is not displaying a certain website I have built correctly. Every other mac and pc I have tested displays the website correctly but this one specific mac in all browsers on it is displaying incorrectly the issue I am getting is inline block elements are not next to each other, I have all the 'hacks' in place and like mentioned this displays correctly on every other computer.
This question here is the exact same issue but it doesnt seem to have been resolved.
https://discussions.apple.com/thread/6650689?start=0&tstart=0
I know I could try floats but I would rather find the route of this cause, does anyone know of any reason this might be happening?
If browser renderings vary only on a single or a few machines, fonts are a possible culprit. Make sure all computers use the same fonts to render your page, actually even that the same version of the font is used.
A lot of fonts get slightly modified over time, often the kerning (space between two characters) or the hinting (how the curves that describe fonts should be mapped to pixels on the screen) might change, resulting in very minor differences in the width some text consumes when being displayed.
If indeed the font version is the culprit: Remember that visitors of your page might also have this "bad" version of the font. So it is advisable to try to improve your HTML layout.
I've often observed that leaving a few percentages empty helps to deal with such font issues. For example: having a div (width=100%) that contains two elements in each "row", the first one a label of about 1/3rd the width, and the second one being some control, taking up the rest of the space. Having them defined with width:33% and width:67% often results in the case that the second part is laid out below the first part instead next to each other. Changing the widths to something like width:32% and width:65% often fixes this, as it allows for some rounding errors in the browsers when laying out the elements.
I'm developing a BlackBerry 10 mobile application using the Momentics IDE (native SDK).
I have a Label which has fixed width. If a Text does not fit in this Label, I want it to be ellipsis (elliding the text with the conventional "..." at the end) in place of a fade effect (just sort of "ghosts" into oblivion) like the Cascades designers have chosen to be in such case like presented in the image below.
Can any one help me on this ?
Since Peter doesn't seem to know how to do this in a straight forward way, the only option left would seem to be the complicated way. You may, of course, create your own control and manage the text rendering in the way you would like using an ellipsis instead of the fade. That would seem to be a great deal of work for what in the end will really only result in your program being unconventional on the platform.
Edit:
Since you think it is worth a bounty I will add the following thought.
Using the ellipsis method, instead of the fade method, may impose a performance penalty on your application. Elliding text requires the computation of how many characters may be displayed int the available area and still leave room for the ellipsis. This is not a trivial mater with variable width type faces or different character sets. The fade, on the other hand, is a simple transparency operation. Since UI graphics operations in Cascades are all done in hardware the fade is quite efficient and independent of the size of the string, text area, type face, etc.
Which version of QML? QML element Text has elide property and this is what you want.
I'm using http://code.google.com/p/flex-iframe/ for showing html in an flex application. To set this up I need to set vmode=opaque. But doing this messes with keyboardinput (at least a swedish charlayout) in Firefox. For example a press on the array key resolves in two arrow chars/steps. If I remove vmode=opaque it works again.
There have historically been lots of issues with setting wmode to opaque. I've had similar issues in the past and had to resort to removing this wmode setting. However, if you're so inclined you could hackishly detect the presence of two keyboard input events within a relatively short time period and suppress one of them. It's not a really elegant solution but if you cannot get rid of wmode, it might be a viable workaround until the bug is fixed by adobe.
I have an < mx:Label > tag that has a set width, which is usually large enough to display the text it needs to show. Every once in a while though the text is a little too long and gets chopped off and "..." gets appended. Instead of this happening I would like to decrease the font-size just low enough to show the whole text.
Does anyone know of a nice way to do that?
Thanks
Fonts are a complicated beast. For a given text, you can find the string length and calculate the maximum allowable font-size very simply using the following approximate formula:
var max_allowable_size:int = yourLabel.width / yourLabel.text.length;
This could lead to serious issues for some fonts, namely:
Remember not all fonts are equal i.e. they cannot all be resized gracefully.
Anti-aliasing may break
Fonts may not look good/text may become illegible
The above naive formula will probably break when applied to non-roman characters
Also, this is an inefficient way.
I would rather suggest that you define two different styles, one regular and another fallback one with font-size set to the smallest, which you switch to when you encounter longer label texts. You can calculate the threshold limit to switch by using the default font-size on the above mentioned formula. Of course, some experimentation is in order, if you have to support localization/multiple languages.
Finally, always embed the fonts if you are going to use anything other than the most common fonts.
There is a measureText function. Check out:
http://frankieloscavio.blogspot.com/2008/01/flex-use-measuretexttxt-to-calculate.html
http://livedocs.adobe.com/flex/3/langref/mx/core/UITextFormat.html#measureText()
You can probably use measureText and decrease the font size till it fits.