You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Jo...@kampf.de on 2005/05/19 10:45:19 UTC

Calculate text width

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: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Calculate text width

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Joern.Karthaus@kampf.de wrote:
> But it seems so that the calculatet width from
> 
> fontmetrics.stringWidth
> 
> ist not the width that i can see in the generatet PDF

FOP doesn't take kerning into account, while Acrobat Reader
does.

> Have someone a better Idea to calculate the width ?

Use a fixed width font :-)

J.Pietschmann

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org