I am working for some project development related to PDF generation using LibHaru. I plan to fit some text in a particular region. I used TextRect()
for that but I have some trouble with the text wrapping.
- If the width of the text is more than that of the width of the rectangle, the rectangle goes blank. How do I get rid of that?
- I tried to write my own text wrapping or split string function which adds space after a particular number of characters but even that seems to fail after a particular limit. Any help regarding the text wrapping function.
- How go I calculate the width of the text which will fit inside a particular width of the rectangle?
Here is the code snippet for the split string function:
void SplitString(int iLength, string strInput, string& strOutput)
{
int iSubstringsCnt;
int iAddedCnt;
iSubstringsCnt = strInput.length() / iLength;
iAddedCnt = iSubstringsCnt / iLength;
cout<<iSubstringsCnt<<endl;
cout<<iAddedCnt<<endl;
cout<<strInput.length()<<endl;
for (int iCnt = 0; iCnt <= iSubstringsCnt+ iAddedCnt; iCnt++)
{
if (0 == iCnt)
continue;
strInput.insert((iCnt * iLength)+(iCnt-1) , " ");
}
strOutput= strInput;
}
iLength
: The length after which I want to split.iAddedCnt
: The count of the string after I added space after a few characters.