in reply to Estimating height of TEXTAREA from content

How can you know what font and font size and line spacing the browser is using? I think you're going to have to redefine your needs before you have a satisfactory solution.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

  • Comment on Re: Estimating height of TEXTAREA from content

Replies are listed 'Best First'.
Re^2: Estimating height of TEXTAREA from content
by tomazos (Deacon) on Jul 25, 2005 at 02:43 UTC
    The width and height of a TEXTAREA is specified in characters, not pixels.

    Plus, I set the font size to monospace 10pt with CSS, so its guaranteed to be monospace (which is the default anyway).

    (You can see it in action here if you are curious.)

    Anyway, let me restate: Given an 80-character soft-wrapping of a multi-paragraph scalar of English words in a monospace font ($content), what will the height of it be in characters ($rows)?

    -Andrew.


    Andrew Tomazos  |  andrew@tomazos.com  |  www.tomazos.com
      Given an 80-character soft-wrapping of a multi-paragraph scalar of English words in a monospace font ($content), what will the height of it be in characters ($rows)?

      Wrap it yourself and count the lines:

      use Text::Wrap; my $rows = split("\n", fill('','', $content););

        Nice! In a fit of jealousy for not having thought of this myself I'll point out that the default column width for Text::Wrap is 76 characters. So an amended line if the stated 80 is the real case.

        use Text::Wrap; $Text::Wrap::columns = 80; # and continue as above...
        Thanks. FYI: Use of implicit split to @_ deprecated.

        my @rows = split("\n", fill('','', $content)); my $rows = $#rows + 1;

        Maybe?

        -Andrew.


        Andrew Tomazos  |  andrew@tomazos.com  |  www.tomazos.com
        I think you're confusing this for an optional layout problem that could be left to the user agent.

        I am all for the seperation of content from presentation, I just don't know how to do that in this case. I want to present my visitor an editable article, I have to put something in the character width and character height of the TEXTAREA. Tell me how not to fight it.

        -Andrew.


        Andrew Tomazos  |  andrew@tomazos.com  |  www.tomazos.com