How to calculate text-height when using PDFContentByte?

View: New views
5 Messages — Rating Filter:   Alert me  

How to calculate text-height when using PDFContentByte?

by pocketom :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm using PDFContentByte to build a function graph object. To generate the x-axis scala I use cb.getEffectiveStringWidth(string, false); which works pretty good here. But to create units for the y-axis I need to know in advance the heigth of a string in advance to calculate how many units I want to print.


Here is a little example I've prepared:

public static void main(String[] args) throws InterruptedException
{
        int fontsize = 12;
   
        try
        {
                BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);

                cb.setFontAndSize(bf, fontsize);
        }
        catch (IOException e)
        {
                e.printStackTrace();
        }
               
        cb.moveTo(250, 600);
        cb.lineTo(250, 600+fontsize); // HOW TO DRAW THE LINE WITH TEH SAME HEIGHT AS MY BASEFONT?
        cb.stroke();
               
        cb.beginText();
        cb.moveText(252, 600);
        cb.showText("HELLO");
        cb.endText();
}


How can I detect the effective height of the text to draw a vertical line with same height as the text when I want to work with the PDFContentbyte?

Re: How to calculate text-height when using PDFContentByte?

by pocketom :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nobody a little hint for me?

Re: How to calculate text-height when using PDFContentByte?

by Paulo Soares-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The question is too vague. You have the height of the font size, the height of the ascender, the height of the descender, the height of small letters, the height of each char (with BaseFont.getCharBBox(). Many heights to choose from.

Paulo

> -----Original Message-----
> From: pocketom [mailto:birnexxx@...]
> Sent: Friday, June 26, 2009 10:45 AM
> To: itext-questions@...
> Subject: Re: [iText-questions] How to calculate text-height
> when using PDFContentByte?
>
>
> Nobody a little hint for me?


Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter informação confidencial ou legalmente protegida. A incorrecta transmissão desta mensagem não significa a perca de confidencialidade. Se esta mensagem for recebida por engano, por favor envie-a de volta para o remetente e apague-a do seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de usar, revelar ou distribuir qualquer parte desta mensagem.

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain confidential or legally protected information. The incorrect transmission of this message does not mean the loss of its confidentiality. If this message is received by mistake, please send it back to the sender and delete it from your system immediately. It is forbidden to any person who is not the intended receiver to use, distribute or copy any part of this message.



------------------------------------------------------------------------------

_______________________________________________
iText-questions mailing list
iText-questions@...
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Re: How to calculate text-height when using PDFContentByte?

by pocketom () :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Paulo,

thank you for your reply. I would be interested in getting the maximum height, e.g. when thinking in uppercase letters only, or like when drawing a box around a word or sentence that tangents at least one character at bottom and the top side without cutting through another char. Hope that makes it more clear...?


<EDIT>
I've managed it:


[code]
public float getTextheight(BaseFont baseFont, float fontSize)
{
                float ascend = basefont.getAscentPoint(text, fontSize);
                float descend = basefont.getDescentPoint(text, fontSize);
                return ascend - descend;
}

[code]

</EDIT>

Parent Message unknown Re: How to calculate text-height when using PDFContentByte?

by Klas Lindbäck :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Uppercase letters are normally as high as the font size.
Lowercase letters can jut down a bit.
I normally use font size * 1.4 between each row when
using manual text positioning.

/Klas

Ämne:
Re: [iText-questions] How to calculate text-height when using PDFContentByte?
Från:
pocketom birnexxx@...
Datum:
Fri, 26 Jun 2009 04:21:26 -0700 (PDT)
Till:
itext-questions@...
Till:
itext-questions@...

Hello Paulo,

thank you for your reply. I would be interested in getting the maximum
height, e.g. when thinking in uppercase letters only, or like when drawing a
box around a word or sentence that tangents at least one character at bottom
and the top side without cutting through another char. Hope that makes it
more clear...

------------------------------------------------------------------------------

_______________________________________________
iText-questions mailing list
iText-questions@...
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/