C++使用Uniscribe进行文字自动换行的计算和渲染(八)

2014-11-24 09:13:54 · 作者: · 浏览: 10
nt scriptItemCount=0;
HRESULT hr=ScriptItemize(
lineText.Buffer(),
lineText.Length(),
scriptItems.Count()-1,
NULL,
NULL,
&scriptItems[0],
&scriptItemCount
);
if(hr!=0)
{
goto BUILD_UNISCRIBE_DATA_FAILED;
}
scriptItems.Resize(scriptItemCount+1);
}
{
// use item and document fragment information to produce runs
// one item is constructed by one or more runs
// characters in each run contains the same style
int fragmentIndex=0;
int fragmentStart=0;
for(int i=0;i {
SCRIPT_ITEM* scriptItem=&scriptItems[i];
int start=scriptItem[0].iCharPos;
int length=scriptItem[1].iCharPos-scriptItem[0].iCharPos;
int currentStart=start;

while(currentStart {
DocumentFragment* fragment=0;
int itemRemainLength=length-(currentStart-start);
int fragmentRemainLength=0;
while(true)
{

fragment=documentFragments[fragmentIndex].Obj();
fragmentRemainLength=fragment->text.Length()-(currentStart-fragmentStart);
if(fragmentRemainLength<=0)
{
fragmentStart+=fragment->text.Length();
fragmentIndex++;
}
else
{
break;
}
}
int shortLength=itemRemainLength

Ptr<ScriptRun> run=new ScriptRun;
run->documentFragment=fragment;
run->scriptItem=scriptItem;
run->start=currentStart;
run->length=shortLength;
run->runText=lineText.Buffer()+currentStart;
scriptRuns.Add(run);
currentStart+=shortLength;
}
}

// for each run, generate shape information
FOREACH(Ptr<ScriptRun>, run, scriptRuns.Wrap())
{
if(!run->BuildUniscribeData(dc))
{
goto BUILD_UNISCRIBE_DATA_FAILED;
}
}
}
}
return true;
BUILD_UNISCRIBE_DATA_FAILED:
CLearUnisc