vandeseer / easytable

Small table drawing library built upon Apache PDFBox
MIT License
239 stars 91 forks source link

PdfUtil.getStringWidth() can return incorrect results for multi-line strings #131

Open asdf00000 opened 2 years ago

asdf00000 commented 2 years ago

The method PdfUtil.getStringWidth() should calculate the length of every line, not just the line that contains the longest string. The width of the individual letters can be very different so a string with less characters can be wider than a string with more characters. For instance, a single w is wider then three times i.

Example:

String line1 = "iii";
String line2 = "www"; float w1 = PdfUtil.getStringWidth( line1 + "\n" + line2, PDType1Font.HELVETICA, 10); float w2 = PdfUtil.getStringWidth( line2 + "\n" + line1, PDType1Font.HELVETICA, 10);
result: w1 = 6.66 w2 = 21.66 both should return 21.66