2011-07-14 18 views
0

我有一個字符串比它必須顯示的地方的寬度更長。我想要做的是在2或3行顯示字符串。如何在iOS上使用libharu在2/3行中顯示字符串?

我的代碼如下:

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 getCalcString] cStringUsingEncoding:NSWindowsCP1252StringEncoding]); 
    HPDF_Page_TextOut(_currentPage, [self alignRightNumberX:fileClaim.totalPrice:483], posY, [[NSString stringWithFormat:@"%.2f €",fileClaim.totalPrice] cStringUsingEncoding:NSWindowsCP1252StringEncoding]); 
} 

而且這裏我把我的文字部分:

HPDF_Page_TextOut(_currentPage, PDF_BASE_DATA_LABELS_START_X+15, posY, [fileClaim.name cStringUsingEncoding:NSWindowsCP1252StringEncoding]); 

現在,這已經來2條或3線,而不是1,我可以不知道該怎麼做。

由於提前,

Lewion

回答

3

我一直在使用LibHaru了幾天,現在,我遇到了同樣的問題就來了。我走進書面方式我自己的C函數來處理換行符和多線支持;然後今天我發現HPDF_Page_TextRect()實際上可以爲你做這項工作! :)

它會自動將多行上的單詞包裝在由矩形定義的區域中,並且還會返回寫入的字符數...

相關問題