A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: ludicrous htmlText offset issue

  1. #1
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136

    ludicrous htmlText offset issue

    Hey all,

    so I'm working on an app requiring me to lay some simple HTML as multicolumn text, and hacking around w/ g.skinner's old regexp method of reflowing as3 TextFields. I'll be happy to share this code if I can get it working. No desire to get into screwing with text.engine at this point, and this has to be back compatible to FP9 anyway.

    So I'm back-and-forth parsing from likely break points to determine if we're in a tag here, and jump ahead to the end of it if we are.

    The ridiculous issue I'm up against is simply that there doesn't seem to be a TextField method for getting the htmlText offset -- NOT the visible text offset -- of a character. Is there a way to do that?

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    What exactly do you mean? I don't understand quite the problem.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    Okay. Let's say I've got htmlText in a TextField. The htmlText is:
    PHP Code:
    Hello <b>world</bline oneHello line two
    And let's say that it word wraps in between those two sentences.

    Now, I want to find out the first character on the second line of that TextField, so I can chop it off from there and send the second half into another TextField over to the right (for dynamic multi-column text).

    To do that without any HTML tags in the text, I would say:
    Code:
    myTextfield.getLineOffset(myTextField.bottomScrollV);
    The problem is, getLineOffset -- and all the other offset checks -- don't count the characters inside the html tags. They give the plain text offset -- 22 in this case, instead of 29. If I split the htmlText at offset #22, it would split like this:
    PHP Code:
    Hello <b>world</blin
    e one
    Hello line two
    To put it another way, I need to find out the htmlText character count -- not the visible text character count -- up to a certain line in a TextField. And it looks as if there's no way to do it.

  4. #4
    Senior Member
    Join Date
    May 2004
    Posts
    226
    Why not make things easy on yourself with something like:
    PHP Code:
    var htmlText:String "Plain text. <b>This is bold, <i>this is bold and italic,</i></b><u><i> This is italic and underlined.</i> Underlined text here.</u> More plain text";
    field1.htmlText htmlText;
    field2.htmlText htmlText;

    var 
    breakIndex:int field1.getLineOffsetfield1.bottomScrollV -) + field1.getLineLengthfield1.bottomScrollV -);
    field1.replaceTextbreakIndexfield1.length"" );
    field2.replaceText0breakIndex"" ); 
    It is not the most elegant but very simple and seems to work, plus no regexp to muck with and fewer lines of code to maintain.

  5. #5
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    Thank you, v5000.
    That's definitely an improvement on what I'm doing...and it seems like that would actually do a better job at preventing the cut from taking place in the dead center of a tag itself...

    but it still leaves me unable to determine the prior encapsulating tag so I can replicate it at the start of the second text field. Say I made the chop in the middle of the bold and italic tags, and I want the second field to start with those... if I knew the index of the cut point in the .htmlText string, I could just search back and figure out what tags were open and replicate them. But knowing the breakIndex in your example doesn't tell me where I am in the htmlText...i.e. where I need to search back from to find any encapsulating tags. The method I'm using right now to determine this, with mixed success is tantamount to:

    Code:
    var htmlBreakPoint:int = -1;
    var c:int = 10;
    while (htmlBreakPoint==-1) {
     htmlBreakPoint = htmlText.getIndex(field2.text.substr(0,c));
     c--;
    }
    But it's pretty bad; the more tags there are, the shorter plaintext strings it has to look for, and therefore the more false positives, especially if those plaintext strings are repetitious ("is", "are", etc.)...

    Somewhere deep inside of TextField, I'm convinced, there's a counter that tells it how much .htmlText has been parsed away up to a given point; that's what I need to get at...

  6. #6
    Senior Member
    Join Date
    May 2004
    Posts
    226
    Quote Originally Posted by joshstrike View Post
    but it still leaves me unable to determine the prior encapsulating tag so I can replicate it at the start of the second text field. Say I made the chop in the middle of the bold and italic tags, and I want the second field to start with those...
    You don't need know anything about the htmlText tags with the method above, it is automatically taken care of by the textField itself. It doesn't matter if the breakIndex is in the middle of bold italic, field2 will preserve the formatting.

    Here check it out in the attached file:
    Attached Files Attached Files
    Last edited by v5000; 08-05-2009 at 04:16 PM.

  7. #7
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    Holy hell...! Thank you! I had no idea it had that capability! Problem solved. Thank you very, very much, v5000... right on the money!

  8. #8
    Senior Member
    Join Date
    May 2004
    Posts
    226
    no prob, been working a lot with the htmlText prop lately.

  9. #9
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    Okay, one more question sir:
    I'm using a defaultTextFormat on these fields w/ Gill Sans as the embedded font. When I set .htmlText into the field, Flash places automatic tags in the text like:
    PHP Code:
    <P ALIGN="JUSTIFY"><FONT FACE="Gill Sans" SIZE="15" COLOR="#000000" LETTERSPACING="1.1" KERNING="1"
    Strange but true, once I run replaceText on the field, those tags are removed and replaced with:
    PHP Code:
    <P ALIGN="LEFT"><FONT FACE="Times Roman" SIZE="12" COLOR="#000000" LETTERSPACING="1.1" KERNING="0"
    Which then causes the text to - poof - vanish, because Times Roman isn't an embedded font. Any thoughts on this? Just a bug?

    *Edit: And setting the textFormat after the fact doesn't appear to change the tags...

    * Edit #2: Particularly ridiculous: I went as far as to try replacing those bad tags in the htmlText after the fact; turns out they just get reset when you set the htmlText on the field again... Oy.
    Last edited by joshstrike; 08-05-2009 at 05:45 PM.

  10. #10
    Senior Member
    Join Date
    May 2004
    Posts
    226
    Yep, htmlText is a wild little beasty, best to stay out of the weeds and never even look at it... there in madness lies!

    Try setting the defaultTextFormat before setting the htmlText, then use field1.htmlText to set field2.htmlText to ensure they are identical.

    PHP Code:
    var htmlText:String "Plain text. <b>This is bold, <i>this is bold and italic,</i></b><u><i> This is italic and underlined.</i> Underlined text here.</u> More plain text";
    field1.defaultTextFormat = new TextFormat"Gill Sans MT" );
    field1.htmlText htmlText;
    field2.htmlText field1.htmlText

  11. #11
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    Alright... I've written millions of lines of AS3 code and never come across anything this balled up. Here's what I discovered:

    That only works if I set the textformat again afterwards, and then turn embedding on; BUT, doing so also strips out all existing html tags besides the ones it put in itself.

    Back where I started...good grief. I'll try to post an example, but I feel like I'm trying to build a telephone out of string and putty.

  12. #12
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    So the end result is, after much hacking and to-do, it does kind of sort of work; but it massively screws up the reported height and textHeight of the field (returns 1) -- even getBounds.bottom returns 1 after we're through with this. The getCharBoundaries(0) hack doesn't work. Hopeless problems w/ maxScrollV and bottomScrollV. Flash completely useless at rendering HTML text across multiple columns; worse, dare say, than even Firefox is. Bloody terrible. This is something I'll never try again.

    Thanks for the help. After two days completely wasted on this, I'm going back to the client with a big "CAN NOT BE DONE". I've done whole sites in the time this took to strike out on...

  13. #13
    Junior Member
    Join Date
    Jun 2010
    Posts
    1

    css

    you can use css instead of textformat + font embedding to prevent the format loss

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center