Measuring the length of a piece of text

Hi,
I'm trying to take a piece of a longer text and display it so
that it is exactly 4 lines long and 200 pixels wide. If I use the
regular text string functions (right, left, mid, etc.) I can create
4 lines with a certain number of characters, but depending on the
text, sometimes they are too long or so short that I could have fit
another word on the line. Is there a function that takes into
account the actual linear length in pixels of a line of text
formatted in the current style? Also the original text could have
HTML codes in it, so I would want to ignore these when selecting
the text so that I don't count non-displaying characters or leave
open ended HTML in my page.
If I have the wrong approach, any guidance would be
appreciated.

check these out:
http://www.bennadel.com/blog/1150-GetTextDimensions-For-Finding-ColdFusion-Image-Text-Dime nsions.htm
http://www.bennadel.com/blog/977-ColdFusion-8-ImageDrawTextArea-Inspired-By-Barney-Boisver t-.htm
http://imageutils.riaforge.org/
(both of the above functions are
included in this great cfc by Ray & Ben)
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/

Similar Messages

  • Getting the Physical Length of a Piece of Text (in mm etc.) in Javascript

    I'm trying to write a script in Indesign CS5 (Windows) that can measure the physical, 'rendered' length of two pieces of text of similar length (in mm etc.), calculate the average length of the two, and adjust the tracking/horizontal scale of one or both of the pieces of text so that the physical length of both texts are the same.
    I need a script because this task must be done thousands of time in a long document.
    I'm struggling to find a way to access the 'rendered' length of a piece of text in Javascript.
    I know among the attributes of a text box is whether the text has overrun. So I could copy the text to a special text-box, and use a for loop to reduce the dimentions of the text box, 1mm at a time, until the text box overruns, thus determining the length..
    I could also get the length of a rendered string using python with it's built in GUI toolkit Tkinter:
    http://stackoverflow.com/questions/2922295/calculating-the-pixel-size-of-a-string-with-pyt hon
    And then have an indesign script that takes some data from the python script and sets the tracking/horizontal in Indesign with some fudge factors.
    Both ideas seem like real kludges.
    Any other suggestions?
    Many thanks
    David

    You can simply iterate through each line in text to get the widest line. Something like this:
    Main();
    function Main() {
        var text = app.selection[0],
        minLength, maxLength, start, end;
        for (var i = 0; i < text.lines.length; i++) {
            start = text.lines[i].characters[0].horizontalOffset,
            end = text.lines[i].characters[text.lines[i].characters.length-1].horizontalOffset;
            if (minLength == undefined || start < minLength) {
                minLength = start;
            if (maxLength == undefined || end > maxLength) {
                maxLength = end;
        var length = maxLength - minLength;
        $.writeln(length);
    But this approach seems to be a little less precise than creating outlines since (I guess) it measures up to the beginning of the last character; discretionary hyphens, line brakes, etc. are not included into the measurement.

  • How to determine the length of a line of text in a multi line text control

    I am working on a simple widget to compare two snippets of text.  The string controls are side by side with a colum of square bools in between
    the two string controls.
    The Bools line up with the lines of text in each string control.  The Bools are used as a quick indicator that at that line point there is a difference
    between the two string controls.
     There is a slider that allows the user to scroll up and down,  the slider scrolls both string controls simutaneously.
    As the string controls are scrolled I will be comparing the left and right lines of text and reflecting the match status in the Bool Colum.
    The reason I need to know the length of the line of text is so each line can be compared against one another.  It is not as simple as counting the
    col width of the string control and parsing the text because if there is a line return the text will word wrap before before it extends all the way accross the string control, which will cause parsing discrepencies.
    Any suggestions on obtaining the multi line string control text character length would be much appreciated.
    Best Regards
    Tim C. 
    1:30 Seconds ARRRGHHH!!!! I want my popcorn NOW! Isn't there anything faster than a microwave!

    Front panel of widget....
    1:30 Seconds ARRRGHHH!!!! I want my popcorn NOW! Isn't there anything faster than a microwave!
    Attachments:
    One.vi ‏27 KB

  • How can I measure the length of a 2D array?

    The grades [] [] is a 2D array and i want to return the length of the second dimension, that is 8.
    And grades[].length doesn't work, so what's the problem?
    Thanks!!!!!!!!
      static String [] [] grades={{"A","B","B","D","D","C","A","F"},                         
                                                   {"F","B","C","B","A","D","B","B"},
                                                   {"C","C","E","E","F","C","B","A"},
                                                   {"C","D","E","D","B","C","D","E"}};
         static int marks [] []=new int[grades.length] [grades[].length];  // why doesn't it work??

    static String [] [] grades={{"A","B","B","D","D","C","A","F"},                         
                                                   {"F","B","C","B","A","D","B","B"},
                                                   {"C","C","E","E","F","C","B","A"},
                                                   {"C","D","E","D","B","C","D","E"}};
    static int[][] integer_grades=convertToInt(grades);
    static int[][] convertToInt(String[][] grades)
    int[][] grade_ints = new int[grades.length][];
    for (int j=0; j<grades.length;j++)
           grade_ints[j]=new int[grades[j].length];
           for (int k=0; k<grades[j].length; k++)
                    grade_ints[j][k]=convertToInt(grades[j][k]);
    return grade_ints;
    static int convertToInt(String s)
       if (s.equals("A")) {return 5;}
       else if (s.equals("B")){return 4;}
       else if (s.equals("C")){return 3;}
       else if (s.equals("D")) {return 2;}
       else if (s.equals("F")) {return 1;}
       return 0;
    }Should work--didn't test it though..wrote it in a hurry...

  • How does one select the language of a piece of text in Pages 5

    I often work with multipel language in one document. In the pre version 5 Pages one could select the text and go in inspector and change the language. Not very handy, MS Word is always been much better at this. Even WordPerfect 1.0 was better. But in version 5 I can't find this function.

    If you live in the world outside the USA, you will find that there are a lot of different language. If like me, and this is the case for a lot of people in Europe you have to make document in several languages Pages 4 was already a user un-friendly program. The detection you manhunt will not work:
    If you take languages that are of the same family like Flemish/Dutch, English, German, enz… a lot of the words are similar but differ non the less.
    Languages tends to take on words from other languages, in the past a lot of French has gotten into English. Flemish/Dutch has taken on a lot of English words in the last several decennia.
    Hens Pages 5 has become a wast of HD space. There is something very wrong @ Apple.

  • How to get the length in bytes of a string

    My string has both latin (1 byte) and chinese (2 bytes).
    My program is in unicode system.
    How to measure the length in bytes of the string?
    the xlen function does not work.

    Hello,
    parameters : p_str type string.
    data : len type i.
    len = strlen( p_str ).
    write : / len.
    With Regards,
    BVS
    Hi BSV, your code return the number of characters not bytes.
    Remember chinese character in US are encoded with 2 bytes.
    And my string contain both latin and chinese characters.
    thanks

  • I accidently cut a piece of text out of a mail message

    I accidently cut a piece of text out of a mail message the copied a different piece of text with out thinking is thee any way to get the first piece of cut text back?

    Welcome to Apple Discussions!
    Mail supports multiple undos. Keep on undoing from the Edit menu! Not sure how far back that undo buffer is, but keep on trying. If it doesn't work, test it so you know for the future.

  • How to use multiple counters in the 6602 to measure cycle length, calculate delay and generate triggered pulse.

    Hi,
    I need to measure the cycle length of a pulse, calculate a delay based on this value, and then generate a triggered pulse with that delay value. The input and output pulses will be continuous. The best case would be to use the cycle length from one pulse in the calculated delay for the next pulse. One of my biggest problems has been getting the calculated delay value into the pulse specs.vi for the triggered output.
    This output pulse will be used to trigger an IMAQ video acquisition; therefore, the solution to this problem will be part of a larger video acquisition application. This has posed a problem, in that accessing the counters has interfe
    red with the triggered video acquisition.
    Any suggestion will be welcome.
    Thanks
    Dave

    Filipe,
    The overhead is the problem I'm trying to get around.
    Specifically, what I need to do is to generate an output pulse after a trigger pulse, which is a given percentage of the cycle length. The input pulse is from heart rate, so it will have some variance, and the output pulse will be at a stationary point in the cardiac cycle. For example, for an input pulse of 2 Hz (500 ms) the user would likely request the output pulse be delayed by 75%. Therefore, the generated pulse will have a 375ms delay after the trigger.
    In the past I have had hardware built to do this, but I am hoping I can accomplish the same thing with multiple counters on the 6602. I have been able to accomplish this with 3 counters (2 to measure period and 1 for output
    ) but the overhead prevents adequate triggering of the IMAQ video acquisition. I am hoping another method would solve this problem.
    Thanks
    Dave

  • Is there a way to change the master text length in FCP? The default length is 10 seconds, which is too long. I can easily adjust the length but I don't want to do it each time, and I don't want to adjust one and then have to copy and paste this length.

    Is there a way to change the master text length in FCP? The default length is 10 seconds, which is too long. I can easily adjust the length but I don't want to do it each time, and I don't want to adjust a text clip and then have to copy and paste this each time. Ideally, there should be something in User Preferences but there is not. Thanks.

    Maybe some one else can pipe up with a solution, but this would literally take 2 seconds to do for a new project.  And you can create a "template project" that includes this "text" clip.  Save this project and then to a get info and check "stationary pad."  When you double click on this file, fcp will open with a copy of this project and you just need to do a save as. 
    I've been working with computer editing systems for longer than i can remember and at a certain point you just have to adapt your workflow to the limitations of the software.  

  • If we can increase the length of the Short Text field in a purchase order?

    Hi Experts,
    Please suggest if we can increase the length of the Short Text field in a purchase order?
    If yes, How? and what will be the impact?
    Thanks
    Gavar

    Dear Arpit,
    You can use PO Text field for long description of the material.
    Regards,
    Manish Jain

  • How to limit the length of editable text in CL_GUI_TEXTEDIT ?

    Hi;
    I have used an instance of CL_GUI_TEXTEDIT on a container. But I want to limit the length of text that can be entered in the text edit ? The method LIMIT_TEXT is protected so I can not call it in the abap source code.
    Is there any other way to limit the length of text in Text Edit Control ?
    Kind Regards.
    Erkan.

    Hi,
    Protected methods are essentially for inherited classes only. To access a protected method, inherit a class from this class and then create and instance of the child class and then using the instance object, call the protected method.
    Hopefully it should work.
    Thanks,
    Chandra

  • How to automate the length of a rectangle solid to a text layer ?!

    How can I automate the length of a rectangle to be larger/smaller as a text layer is made longer or shorter.
    Example = https://www.dropbox.com/s/0lqu7iff5bnlzd1/Capture%20d%27%C3%A9cran%202014-04-04%2015.00.23 .png

    There are two events that can be used to check the text length,
    The first is the action event for the text field, which is called when the field loses focus, it's a dialog object member with the same name as the item_id.  This event could also be used to update another field on the dialog that shows the number of characters, you could even have a little alert image that becomes visible to make it obvious that there is a problem.
    The other event, as already mentioned, is the validate event.  Use this to block exiting the dialog and display an alert popup to the user.
    You'll find some examples of dialogs here:
    http://www.pdfscripting.com/public/65.cfm
    Take a look at the dialog for the resize pages tool.  It'll give you some ideas of what can be done.
    There is an Acrobat plug-in for creating dialogs here:
    http://www.windjack.com/products/acrodialogs.html
    It's a visual drag and drop editor.  You can download and use it for free for 10 days.
    Thom Parker
    The source for PDF Scripting Info
    pdfscripting.com
    The Acrobat JavaScript Reference, Use it Early and Often
    http://www.adobe.com/devnet/acrobat/javascript.html
    Then most important JavaScript Development tool in Acrobat
    The Console Window (Video tutorial)
    The Console Window(article)

  • How to limit the length of text in a column

    Hello All,
    I have a report built from direct database request.
    I have a comments column , for some of ID's the comment lines are more than 10. For soem rows it is 1 line and for some rows it is having 10 lines.
    Even though in properties if i select wrap text not helping me.
    I want it to show a single line and remaining 9 lines like a link if user wants to see detailed comment he can click on it.
    Can anyone please help me how to achieve this.
    Thansk in advance.
    SR

    Hi SR,
    Which OBIEE version are you using?
    In obiee 11.1.1.7 the column will be extended up to the length of the data(horizontally and vertically)
    Thanks,
    Pavani

  • [svn:fx-trunk] 8531: If using an embedded font, need to measure the text with it so that if auto-sizing, the correct amount of space is allocated.

    Revision: 8531
    Author:   [email protected]
    Date:     2009-07-13 12:25:57 -0700 (Mon, 13 Jul 2009)
    Log Message:
    If using an embedded font, need to measure the text with it so that if auto-sizing, the correct amount of space is allocated.
    QA Notes:
    Doc Notes: SDK-22205.
    Reviewers: will be Gordon
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-22205
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/primitives/RichEditableText.as

    Revision: 8531
    Author:   [email protected]
    Date:     2009-07-13 12:25:57 -0700 (Mon, 13 Jul 2009)
    Log Message:
    If using an embedded font, need to measure the text with it so that if auto-sizing, the correct amount of space is allocated.
    QA Notes:
    Doc Notes: SDK-22205.
    Reviewers: will be Gordon
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-22205
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/primitives/RichEditableText.as

  • Display instantly the length of the text entered in the rich text editor

    Hi everybody,
    I'm developing an apex application with apex 4.1.1 and Oracle 11.2.
    I have a page in which I have a form that allows to create a new message on the database.
    A message has a title, description, text and date.
    For the text I use the item "rich editor text". The problem is that item doesn't show the length of characters entered (character counter for the textarea). In the database the corresponding column is varchar2(2000). What I do is a validation after submit that checks if the limit 2000 was exceeded or not.
    But what I want to do more is to display instantly the length of the text entered in the editor. I have tried to do that through a dynamic action. But the event "onChange" for the item "rich text editor" didn't work.
    Has anyone any idea about that issue?
    Thanks for helping.
    Kind regards,
    Edited by: Khadija Khalfallah on Apr 25, 2013 4:06 AM

    sorry about that, I missed that tidbit in your OP... well I think there is a good reason why there isn't a count character option -- due to the hidden "html" characters responsible for the "richness" (bold/color, etc) applied to the text would be difficult to count true characters.. if I was bent on doing this, I'd continue using the item you are using, but have a HIDDEN text area that is updated via javascript onkeyup for each keystroke (again, keeping in mind you'd have to filter certain keys) and then that intelligence could be used. I would probably dig through the javascript responsible for the rich text editor (is it still fckeditor??) -- there might already be code in there that isn't clearly visible to you that does this already.. alas, I see now the validity of your challenge.

Maybe you are looking for

  • TS1538 help, my ipad is not being recognized in itunes and I have gone through all the troubleshooitng above with no success.

    I need to update my ipad and I have not synced in quite some time.  When I attempted to sync it does not appear in itunes.  I have gone through all the suggestions posted on your website and still have no luck

  • Weblogs for different message mapping needed

    Hi, I want to do scenarios using XSLT mapping, ABAP mapping, Java mapping. Can you suggest me some weblogs... Thanks, Ram

  • Oracle Date in SQL Statement.

    Hello,     We are having performance issues with some reports using conditions on date fields in the Record Selection Formula. Our application does not use the time portion of the date fields very often. When Crystal Reports builds the SQL statement

  • Puchases Order item No's Problem

    Dear  all ,   when i create PO  with 3 items material as item 1,2 and 3, when i tried to delete the second item i found that the item  number for item 3 cannot change to No. 2. When i change to No.2 and save it. Once i reopen the PO again the no. wil

  • Self Service Web Applications

    Hi, In Fusion APplications, we dont find Forms based Applications...only Self Service Web Applications...i have read some where about this.... Forms ----> Jdeveloper Reports ---> XML Publishser what does it mean...Self Service...any meaning for that.