How can I show a string in 2/3 lines with libharu on iOS?
I have a string which is longer than the width of the place where it has to show up. What I want to do is show the string on 2 or 3 lines.
My code is as follows:
for (int i=0; i<claimsCount; i++)
{
File_Claim *fileClaim = [claimsArray objectAtIndex:i];
[self checkCreateNewPage:font:10.0];
///////////////////////////////////////////////////////////////////////////////////////
// if the current category is the same as the previous one then don't write it again
///////////////////////////////////////////////////////////////////////////////////////
if ([subcategory isEqualToString:fileClaim.subCategoryName])
{
}
else
{
// hold the old category to check if it is the same
subcategory = fileClaim.subCategoryName;
//HPDF_Page_SetRGBFill (_currentPage, 0, 0, 1);
posY -= PDF_SPACER_Y;
HPDF_Page_TextOut(_currentPage, PDF_BASE_DATA_LABELS_START_X, posY, [fileClaim.subCategoryName cStringUsingEncoding:NSWindowsCP1252StringEncoding]);
}
//HPDF_Page_SetRGBFill (_currentPage, 0, 0, 0);
posY -= PDF_SPACER_Y;
HPDF_Page_TextOut(_currentPage, PDF_BASE_DATA_LABELS_START_X+15, posY, [fileClaim.name cStringUsingEncoding:NSWindowsCP1252StringEncoding]);
HPDF_Page_TextOut(_currentPage, [self alignRightNumberX:fileClaim.unitPrice:260], posY, [[NSString stringWithFormat:@"%.2f €",fileClaim.unitPrice] cStringUsingEncoding:NSWindowsCP1252StringEncoding]);
HPDF_Page_TextOut(_currentPage, 320, posY, [[fileClaim getCalcSt开发者_StackOverflowring] cStringUsingEncoding:NSWindowsCP1252StringEncoding]);
HPDF_Page_TextOut(_currentPage, [self alignRightNumberX:fileClaim.totalPrice:483], posY, [[NSString stringWithFormat:@"%.2f €",fileClaim.totalPrice] cStringUsingEncoding:NSWindowsCP1252StringEncoding]);
}
And the part where I put my text:
HPDF_Page_TextOut(_currentPage, PDF_BASE_DATA_LABELS_START_X+15, posY, [fileClaim.name cStringUsingEncoding:NSWindowsCP1252StringEncoding]);
Now this has to come on 2 or 3 lines instead of 1. And I can't figure out how to do this.
Thanks in advance,
Lewion
I've been using LibHaru for few days now, and I came across the same question.. I went into writting my own C function to deal with line breaks and multiline support ; and then today I found out that HPDF_Page_TextRect()
can actually do the job for you! :)
It will automatically wrap up words on multilines in a area defined by a Rectangle and it also returns the number of characters written...
精彩评论