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

2014-11-24 09:13:54 · 作者: · 浏览: 11
Height()-10;
int cx=0;
int cy=0;
const int lineDistance=5;
const int paragraphDistance=10;

FOREACH(Ptr<ScriptParagraph>, paragraph, document->paragraphs.Wrap())
{
if(cy>=h) break;
FOREACH(Ptr<ScriptLine>, line, paragraph->lines.Wrap())
{
if(line->scriptRuns.Count()==0)
{
// if this line doesn't contains any run, skip and render a blank line
cy+=line->documentFragments[0]->size+lineDistance;
}
else
{
// render this line into linces with auto line wrapping
int startRun=0;
int startRunOffset=0;
int lastRun=0;
int lastRunOffset=0;
int currentWidth=0;

while(startRunscriptRuns.Count())
{
int currentWidth=0;
bool firstRun=true;
// search for a range to fit in the given width
for(int i=startRun;iscriptRuns.Count();i++)
{
int charLength=0;
int charAdvances=0;
ScriptRun* run=line->scriptRuns[i].Obj();
run->SearchForLineBreak(lastRunOffset, w-currentWidth, firstRun, charLength, charAdvances);
firstRun=false;

if(charLength==run->length-lastRunOffset)
{
lastRun=i+1;
lastRunOffset=0;
currentWidth+=charAdvances;
}
else
{
lastRun=i;
lastRunOffset=lastRunOffset+charLength;
break;
}
}

// if the range is empty, than this should be the end of line, ignore it
if(startRun {
// calculate the max line height in this range;
int maxHeight=0;
for(int i=startRun;i<=lastRun && iscriptRuns.Count();i++)
{
int size=line->scriptRuns[i]->documentFragment->size;
if(maxHeight {
maxHeight=size;