PDF Precise checking location letters with different ascents and descents

20 hours ago 1
ARTICLE AD BOX

My question is I am trying to check a letters precise x, y so I can find if it's getting too close to a border I drew on the PDF.

Code is below good for most cases, but some fonts have ascents and descents that gets way too close to the top and bottom lines.

Ascent and Descent description picture:

Ascent and Descent description picture

You can see it here. This is what it looks like with 200% zoom. Even with this you can see that it looks it's cutting very close.

Looks nearly touching the line:

Looks nearly touching the line

Only when you zoom in 1600% you can see there is enough gap. Because these PDF's will be printed and might scale up or down.

But with zoom enough space:

But with zoom enough space

I want to check and adjust according to that. I need to be this precise because these letters will be used in invoices might have bigger/smaller fonts, changing line heights and all that will wreak havoc on its look.

Currently I am using the code below to do so:

public bool FitsToTheLine(PdfRectangle textLineRectangle, PdfRectangle overAllRectangle, double lineHeight) { double lineBottom = textLineRectangle.TopLeft.Y - lineHeight; double lineTop = textLineRectangle.TopLeft.Y; double lineLeft = textLineRectangle.BottomLeft.X; double lineRight = textLineRectangle.BottomRight.X; double bottomYLimit = overAllRectangle.BottomLeft.Y; double topYLimit = overAllRectangle.TopLeft.Y; double xStartLimit = overAllRectangle.BottomLeft.X; double xFinishLimit = overAllRectangle.BottomRight.X; bool tooLow = lineBottom < bottomYLimit; bool tooHigh = lineTop > topYLimit; bool tooLeft = lineLeft < xStartLimit; bool tooRight = lineRight > xFinishLimit; if (tooLow || tooHigh || tooLeft || tooRight) { return false; } return true; }
Read Entire Article