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

2014-11-24 09:13:54 · 作者: · 浏览: 2

tempGlyph.ClearUniscribeData(wholeGlyph.glyphs.Count(), length);
advance=wholeGlyph.runAbc.abcA+wholeGlyph.runAbc.abcB+wholeGlyph.runAbc.abcC;

return true;
BUILD_UNISCRIBE_DATA_FAILED:
ClearUniscribeData();
return false;
}

int SumWidth(int charStart, int charLength)
{
int cluster=wholeGlyph.charCluster[charStart];
int nextCluster
=charStart+charLength==length
wholeGlyph.glyphs.Count()
:wholeGlyph.charCluster[charStart+charLength];
int width=0;
for(int i=cluster;i {
width+=wholeGlyph.glyphAdvances[i];
}
return width;
}

void SearchForLineBreak(int tempStart, int maxWidth, bool firstRun, int& charLength, int& charAdvances)
{
int width=0;
charLength=0;
charAdvances=0;
for(int i=tempStart;i<=length;)
{
if(i==length || charLogattrs[i].fSoftBreak==TRUE)
{
if(width<=maxWidth || (firstRun && charLength==0))
{
charLength=i-tempStart;
charAdvances=width;
}
else
{
return;
}
}
if(i==length) break;

int cluster=wholeGlyph.charCluster[i];
int clusterLength=1;
while(i+clusterLength {
if(wholeGlyph.charCluster[i+clusterLength]==cluster)
{
clusterLength++;
}
else
{
break;
}
}

int nextCluster
=i+clusterLength==length
wholeGlyph.glyphs.Count()
:wholeGlyph.charCluster[i+clusterLength];
for(int j=cluster;j {
width+=wholeGlyph.glyphAdvances[j];
}
i+=clusterLength;
}
}

bool BuildUniscribeDataTemp(WinDC* dc, int tempStart, int tempLength)
{
return tempGlyph.BuildUniscribeData(dc, documentFragment, scriptItem, scriptCache, runText+tempStart, tempLength);
}
};

class ScriptLine : public Object
{
public:
List> documentFragments;
WString lineText;

Array<SCRIPT_ITEM> scriptItems;
List> scriptRuns;

void CLearUniscribeData()
{
scriptItems.Resize(0);
scriptRuns.Clear();
}

bool BuildUniscribeData(WinDC* dc)
{
lineText=L"";
CLearUniscribeData();

FOREACH(Ptr, fragment, documentFragments.Wrap())
{
lineText+=fragment->text;
}

if(lineText!=L"")
{
{
// itemize a line
scriptItems.Resize(lineText.Length()+2);
i