Symbian 字符串自动换行
2010-05-31 20:22:00 来源:WEB开发网// ----------------------自动折行=========================//
加入头文件
#include
#include
和estlib.lib 库
// ----------------------自动折行=========================//
typedef TBuf<60> TBufCH;
CArrayFixFlat
{
if(abuf&&abuf->Length()>0)
{
CArrayFixFlat
if(lineTxts)
{
CleanupStack::PushL(lineTxts);
TInt wids=0;
TBool wrap=EFalse;
TInt index0=0;
TInt index1=0;
const TUint16* strs=abuf->Ptr();
TInt len=abuf->Length();
TInt subLen;
while(true)
{
wids=0;
wrap=EFalse;
for(index0=index1;index1
{
if(strs[index1]==' ')
{
wrap=ETrue;
index1++;
break;
}
wids+=aFt.CharWidthInPixels(strs[index1]);
if(wids>aMaxWid)
{
break;
}
}
if(wrap)
{
subLen=index1-index0-2;
TUint16* NLStr=(TUint16*)malloc(subLen*sizeof(TUint16)+1);
for(int i=0;i
NLStr[i]=strs[index0+i];
NLStr[subLen]=0;
TPtrC str(NLStr);
lineTxts->AppendL(str);
free(NLStr);
}
else
{
subLen=index1-index0;
TUint16* NLStr=(TUint16*)malloc(subLen*sizeof(TUint16)+1);
// memset(NLStr,'0',subLen*sizeof(TUint16)+1);
for(int i=0;i
NLStr[i]=strs[index0+i];
NLStr[subLen]=0;
TPtrC str(NLStr);
lineTxts->AppendL(str);
free(NLStr);
}
if(index1>=len)
break;
}
CleanupStack::Pop(lineTxts);
}
return lineTxts;
}
return NULL;
}
更多精彩
赞助商链接