Calculate string CPI (length of string in pixel)

Word-wrap position is at the moment done in SAP via length of string (count of letters) via function u201CRKD_WORD_WRAPu201D. But this is counting number of char, this give the problem that different font type and size give different word-wrap position ! -> We need to calculate if possible the word-wrap position via the relative length of text u2013 I tried to find some on SDN and Internet, the only thing I can find is some functionality in JAVA u2026
Can any one help me how to calculate the length of a string using font type and hight of font... as we use truetype font as arial the length of letter "i" is not the same as 'X' ...
Best regards Jørgen Jensen

My problem is not to do the wordwrap, my problem is to find the right position as the length of 'i' is not the same length of 'X'
example:
iiiiiiiiii (10)
XXXXXXXXXX(10)
must be something like this:
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii(wordwrap position 35)
XXXXXXXXXX(Wordwrap position 10)
I need a way to find the length of a charactor in a given font and size.
Best regards Jørgen Jensen

Similar Messages

  • Getiing length of String in pixels.

    I need to set up legth of combobox depending on length of strings in it. Can I get length of String in pixels?

    You should use the getFontMetrics() method of the Graphics object used by the painting methods of the combo.
    Then the stringWidth(String) method of the given font metrics should give you the needed width.
    Just take care of the fact that the combo must be realized (set visible or packed) for this to work.

  • Find the length of a string in pixels

    Hello all,
    Wondering if there's a way in PowerShell to find the length of a given string in pixels?

    That would depend on the font used to draw it, including size, bold / italic, etc.  Assuming you know those things, there's a TextRenderer.MeasureText method in the Windows Forms library:
    $string = 'This is my string. There are many like it, but this one is mine.'
    $font = New-Object System.Drawing.Font('Arial', 12, [System.Drawing.FontStyle]'Bold, Italic')
    $size = [System.Windows.Forms.TextRenderer]::MeasureText($string, $font)
    $size.Width

  • Width of a string in pixels

    is it possible to get the width of a given string in pixels, if so how to do it ??

    Yes, and you can get the FontMetrics from java.awt.Component (i.e. from all the awt and swing components) with getFontMetrics()

  • Length of text in pixels?

    hi, is there any function that gives you the length of a string in pixels? For example, an "i" is a lot smaller than a "m". I currently have a statement like this...
    g.drawString(stringVariable,50-(stringVariable.length()*3),50)
    that gives aproximately centered text... But if I were to type 10 "i"s then it would be way off to the left of 50,50 and if I typed 10 "m"s it would be way off to the right of 50,50, somebody please help on this.

    Hm, I did a little looking up about fontMetrics, and I found my answer, thanks.

  • Text on path: How can I calculate the text length?

    Hi
    I have a text on path (spline item). Now I need the length of this text and the length of the spline item.
    I try to calculate the text length using IWaxLine::GetWidth(), but this is always 0.
    - How can I calculate the length of this text?
    - How can I calculate the length of the spline item?
    Thanks
    Hans

    It would be interesting if you could describe the purpose of your "length", but I don't have an answer anyway. Would the bounding box be sufficient?
    Considering that TOP may be combined with arbitrary spline paths, this could become an exercise in higher math. I haven't yet encountered a function that returns the mathematical length of such a spline.
    Otherwise it could be solved if you iterate and sum up the relevant points of the bounding box (ascender, descender, baseline?) of individual glyphs.
    Be warned that the whole TOP looks alien, as if it were a transplant from a different program. Experience also shows that documented and actually used interfaces / commands are completely different animals ...
    Dirk

  • Length of a string in pixel

    Hello,
    I am programming a servlet which produces html pages. The page contains a table with more than one column. The columns have a static width of 200 pixel. Now, I want to put some strings into the cells of the table. Depending on the width in pixel, there shall be one ore more cells in a row reserved for one string. How do I know the width of a string in the browser in pixel?
    My idea was, to create a Label within the java-servlet with the right font and fontsize. Then I can get the length in pixel:
    pixellength = testLabel.getFontMetrics(theFont).stringWidth("string to measure");
    That works very well, if the Server has a GUI. If not, the following exception occurs:
    java.lang.NoClassDefFoundError at
    java.lang.Class.forName0(Native Method) at
    java.lang.Class.forName(Class.java:130) at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62) at
    java.awt.Font.initializeFont(Font.java:310) at
    java.awt.Font.(Font.java:346) at
    The servlet should work on non-GUI servers as well! What can I do now? Any ideas?

    Hi!
    I don't really know if I'm right on this, but:
    If U use nonproportional fonts (like courier) can't U calculate it by multipling the fontsize (which is in pixels) by the stringsize (number of characters)? i.e.: "Teststring" in fontsize 15 would be 150 pixels wide?
    Thomas.

  • Class to calculate string length

    Hi All,
    is there any class having a method to calculate the string length.
    Thanks

    Hi Ravi,
    You can use the FM SWA_STRINGLENGTH_GET
    data: lv_length type SWAEXPDEF-ELEMLENGTH,
                     lv_string type string.
          CALL FUNCTION 'SWA_STRINGLENGTH_GET'
            EXPORTING
              expression                 =   lv_string
    *         CONDENSE_NO_GAPS           =
    *         CONDENSE                   =
    *         WITH_LEADING_BLANKS        =
    *       IMPORTING
             LENGTH                     = lv_length
    *         EX_MODIFY_EXPRESSION       =
    hope it helps you
    Regards!

  • Function to calculate string

    Hi,
    I am looking for a function that you can insert: '5+(8*3)-2' and it will give you the value.
    something like a calculator function but for a text string.
    Did any of you guys have seen something like this before?
    thanks,
    Itay

    Hi,
    You have to do it dynamically, the input parameters are values (for example in your case
    ( 5, 8, 3, 2) operation (* + / -) are formulas...
    R001 = 5, R002 = 8, R003 = 3, R004 = 2
    1. Create parameter 100 char length.
    2. Get the formula from the user (for example  5+ ( 8 * 3 ) - 2 into the parameter field {like (R001 + (R002 * R003 ) - R004}
    3. Use Key word "SPLIT" amd move the values into a internal table (each value will be in a row...
    4. Now get the value of R001,R002,R003,R004  & operators....
    5. Create a progam dynamically (take the help of dynamic program)
    6. Create variables in the program (these variables should be created based on the values in SPLIT commanded used internal table.... with one addition variable for the RESULT, all the varibales declared should be of data type "F".
    7. use the   SYNTAX-CHECK FOR <program> to check the program syntax is correct.
    8. if subrc eq 0 then Submit the dynamic program
    9. WRITE the result....
    You will get the result...take the below code help
      DATA: BEGIN OF fm_split_formula OCCURS 0,
              text(10) TYPE c,
            END OF fm_split_formula,
            BEGIN OF fm_repo OCCURS 0,
              line(72),
            END OF fm_repo.
      DATA: fm_f_check(240),
            fm_h_check(72) ,
            fm_g_check TYPE  i,
            fm_offset1 TYPE i,
            fm_offset2 TYPE i,
            fm_subrc   LIKE sy-subrc,
            fm_mtext1.
      DATA: BEGIN OF fm_func,
              f1(7) VALUE 'STRLEN(',
              f2(7) VALUE 'SQRT(  ',
              f3(7) VALUE 'MOD    ',
              f4(7) VALUE 'DIV    ',
              f5(7) VALUE 'COS(   ',
              f6(7) VALUE 'SIN(   ',
              f7(7) VALUE 'LOG(   ',
              f8(7) VALUE 'EXP(   ',
            END OF fm_func.
      DATA: fm_loc_index LIKE sy-index,
            fm_repo_cnt TYPE i,
            fm_cnt_lp TYPE i,
            fm_name(10) VALUE 'FORMEL'.
      CONSTANTS:  fm_operand(8)  VALUE ' =()+-*/',
                  fm_numbers(12) VALUE ' 1234567890.',
                  fm_result(4)   VALUE 'R1 =',
    *- Start of insert for # DR1K900907 by Prabhu Rajesh
                  fm_result1(3)  VALUE 'R =',
    *- End of insert for # DR1K900907 by Prabhu Rajesh
                  fm_res(1)      VALUE 'R'.
      CLEAR : fm_split_formula, fm_repo,fm_repo_cnt.
      REFRESH: fm_split_formula, fm_repo.
      SPLIT fm_formula AT ' ' INTO TABLE fm_split_formula.
      LOOP AT fm_split_formula.
        IF NOT ( fm_split_formula-text = fm_func-f1 OR
                 fm_split_formula-text = fm_func-f2 OR
                 fm_split_formula-text = fm_func-f3 OR
                 fm_split_formula-text = fm_func-f4 OR
                 fm_split_formula-text = fm_func-f5 OR
                 fm_split_formula-text = fm_func-f6 OR
                 fm_split_formula-text = fm_func-f7 OR
                 fm_split_formula-text = fm_func-f8 OR
                 fm_split_formula-text CO fm_numbers OR
                 fm_split_formula-text CO fm_operand ).
          fm_repo = fm_split_formula-text.
          APPEND fm_repo.
        ENDIF.
      ENDLOOP.
    If the hint is useful… Say thanks by reward….
    Regards,
    Prabhu Rajesh

  • GrabFrame() to return a string of pixel information?

    Hi everyone,
    Basically what im looking for is creating a 2d array of values(but id be happy with a string) corrosponding to each of the 320*240 pixels of my camera. At the moment i can get back an awt image using:
    Buffer buf = frameGrabber.grabFrame();
    Image img = (new BufferToImage((VideoFormat) buf.getFormat()).createImage(buf));
    I would of thought that i should meerly use the toString() method. But if i toString() buf i get:
    javax.media.Buffer@22c95b
    and if i toString() img i get:
    BufferedImage@22c95b: type = 1 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0 IntegerInterleavedRaster: width = 320 height = 240 #Bands = 3 xOff = 0 yOff = 0 dataOffset[0] 0
    If anyone could help, and point me in the direction of the right method to use, i would be greatly appreciative.
    Thanks.

    You will need integer values from an image to do anything meaningful with the data. Something like this -
    int redValues = new int[imageWidth * imageHeight];
    int greenValues  = new int[imageWidth * imageHeight];
    int blueValues  = new int[imageWidth * imageHeight];
    int alphaValues  = new int[imageWidth * imageHeight];
    int counter = 0;
    public void grabEveryPixelInThe Image(Image img, int x, int y, int w, int h) {
            int[] pixels = new int[w * h];
            PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
            try {
                pg.grabPixels();
            } catch (InterruptedException e) {
                System.err.println("interrupted waiting for pixels!");
                return;
            if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
                System.err.println("image fetch aborted or errored");
                return;
            for (int j = 0; j < h; j++) {
                for (int i = 0; i < w; i++) {
                    doOnePixel(pixels[j * w + i]);
    public void doOnePixel( int pixel) {
            int alpha = (pixel >> 24) & 0xff;
            int red   = (pixel >> 16) & 0xff;
            int green = (pixel >>  8) & 0xff;
            int blue  = (pixel      ) & 0xff;
           redValues[ counter] = red ;
           greenValues [ counter] = green ;
           blueValues  [ counter] = blue ;
           AlphaValues [ counter ] = alpha ;
           counter++;
    }regards

  • Calculate String Width

    Is it possible to calculate the width of a String in a certain font without needing a Graphics object? I need to calculate this before a component is displayed in order to adjust the sizes of the components. getGraphics() is returning null at this point.

    Didn't my original post answer that question?
    My control is being wrapped in a JScrollPane. I need to set the preferred size of the scroll pane based on the width of a String. If I try to do that during initialization before it is displayed, getGraphics() returns null so I get a NullPointerException.

  • How to calculate the total  length of a Line

    Hi,
    We are using Mapviewer for representing for spatial data in form of a Image .
    We are using Mapviwer.addLinearFeaure for drawing lines on the Image( browser)
    Thsese lines are drawn .
    Now our requirement is we need to calculate the length of the lines in our Image .Please tell me how to do this .
    Thanks in advance
    Edited by: user672373773 on Nov 11, 2009 9:11 AM

    You can do this by two ways.
    1) create SDO_GEOMETRY from your coordinates and use SDO_GEOM.SDO_LENGTH to get length of the line.
    Or
    2) iterate your line points coordinate array and calculate distance between points add it to final length.
    Here is snippet to calculate length of line (not tested)
    length = 0;
    for( i=0; i<coordpts.length-2; i++) {
    length = length + getDistance(coordpts[0], coordpts[1]);
    to calculate distance between 2 points use below code (getDistance() source code)
    double dblDistance = Math.sqrt(Math.pow((dblPt2[0] - dblPt1[0]), 2) + Math.pow((dblPt2[1] - dblPt1[1]), 2));
    In both case you need to convert screen coordinate to map coordinate.
    Sujnan

  • How can I calculate total path length of a Binary Search Tree?

    I have been trying to learn binary search trees, but I can't figure out a way to calculate the total path length and the number of leaves in a BST. I will utilize a linked list for the nodes in the tree. I will be using an innerClass for the nodes; each node will have a variable for an element and links for the left and right. Does anyone have any idea on how to calculate this? Thanks in advance.:)

    By the way, all of the elements are comparable objects.

  • Calculate A Fixed Length Future Date Based On User Provided Date

    Does anyone know how I would (using date field) have a user choose a date (call it Field1) and have it calculate 30 days from whatever date is chosen in Field1) and auto populate it in another filed (call it Field2). Ideally user would not have to 'click' in Field2 to have information populated...
    So user picks January 1st in Field 1 + 30 days = January 30th in Field 2

    Well for the life of me I can't figure this out. Given the code:
    DateTimeField2.rawValue = Num2Date(Date2Num(xfa.event.newText, "M/D/YYYY")+30,"MM/DD/YYYY");
    It should add 30 days to the chosen date. But some reason it's off by a day. If I choose 6-1-2010 it picks 7-1-2010, if I pick 7-1-2010 it picks 7-31-2010. I'm really stumped where it's picking up the extra day?

  • Calculating string length

    hi experts,
    How to calculate string length from driver program. Is there any function module to do it. Please help me. In my application, i will get the input from user and calculate string length and process it. Please help me.

    Hi,
    <<removed>>
    Umang Mehta
    Edited by: kishan P on Oct 9, 2010 3:42 PM

Maybe you are looking for