Mark McDonnell wrote:
> Does any one know how to check when a single line of text has been rendered
> on two lines?

I have one really ugly suggestion.  If this is an essential
requirement, and not something that can be handled with CSS's ":first-
line" pseudo-selector, then you might want to try this.  But it's
definitely not something I would enjoy trying.

The technique assumes that you have your line of text wrapped in an
element.  For a first pass, prepend the content of the element with an
empty SPAN, and record the y-position of that SPAN.  Then move the
span one character at a time to the right, until you get to the end or
until the SPAN has a greater y-position than it started with.
Presumably the preceding character would be the first one on the new
line.  Obviously you could increase performance by moving word-by-
word, and still more for longer strings by doing a binary search for
the correct position.

Thus,

    <span id="x">My very seriously long sentence here  (y-pos: 372)
    M<span id="x">y very seriously long sentence here  (y-pos: 372)
    My<span id="x"> very seriously long sentence here  (y-pos: 372)
    ...
    My very seriously long <span id="x">sentence here  (y-pos: 372)
    My very seriously long s<span id="x">entence here  (y-pos: 388)

The first split would be between "My very seriously long " and
"sentence here".

If these are long strings, a binary search would clearly perform
better, but would be even uglier to implement.

Of course you would have to redo this on any reflow of the element.

What is the use-case for this?

  -- Scott

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to