JK:

I also ran into similar issues when trying to cut off the overflow in a
cell.  I eventually abandoned the idea and put in hyphenation to get around
our issue.

However, below is an overflow workaround I was toying with that was never
implemented, but may be of some use:

1.  Find the largest character on your PDF output (may entail printing all
of the characters and then measuring).  You only need to do this once
(unless you change your face).
2.  Now, during your processing, multiply the number of characters in your
string by the largest character width from #1.  If it is larger than your
context size, you need to truncate the string.  I was writing a "size
truncater" that would find the max characters by the following method:
            a.  Cut the string in half.
            b.  Measure the first half.  If it is less than your max,
subtract from your max to get what space is left.
            c.  Do an integer divide of what space is left by your largest
character width from #1.  Add this many characters to a.

3.  The resulting string from #2 is now your cell data.

OK, it may not be the best method or even totally foolproof, but it was a
direction I was looking into.

Hope it helps even a little.
-Lou



                                                                                
                                                                   
                      [EMAIL PROTECTED]                                         
                                                                    
                      ampf.de                  To:      
[email protected]                                                
           
                                               cc:                              
                                                                   
                      05/19/2005 04:45         Subject: Calculate text width    
                                                                   
                      Please respond                                            
                                                                   
                      to fop-users                                              
                                                                   
                                                                                
                                                                   
                                                                                
                                                                   




I want to avoid a line break in a table cell.

So my Idea is to calculate the String width of a cell and cut the String
even if its longer.

so it works for my like this  :

   PDFGraphics2D pdfgrafics2d = new PDFGraphics2D(false);
    fontmetrics = pdfgrafics2d.getFontMetrics(new
Font(FOPTelefonTable.FONT_FAMILY ,Font.PLAIN,new
Integer(FOPTelefonTable.FONT_SIZE_PT).intValue()));

    private String cutName(FontMetrics fontmetrics,String source) {
        String result = source;
        if (fontmetrics.stringWidth(result) <= MAX_NAME_WIDTH_PX) return
result;
        while (fontmetrics.stringWidth(result) > MAX_NAME_WIDTH_PX) {
            result = result.substring(0,result.length()-1);
        }
        return result;
    }


But it seems so that the calculatet width from

fontmetrics.stringWidth

ist not the width that i can see in the generatet PDF


Have someone a better Idea to calculate the width ?


Thanks JK





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]







---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to