2 Call the Hyphenation function in Abiword.
Ø Split run to split word and keep the format
Ø Find split info
Ø Deal with user's operation(select, delete, cut, paste)
Main Goal: call hyphenation module of enchant to display the hyphenation result in abiword. After user's operation, refresh the hyphenation-result accordingly include user adding new word, delete word, copy word, cut word
The main code is adding in the format function in LineBreaker.h(cpp)
// find the split point
while (pRunToBump && pLine->getNumRunsInLine() && (pLine->getLastRun() != m_pLastRunToKeep))
{
UT_ASSERT(pRunToBump->getLine() == pLine);
if(!pLine->removeRun(pRunToBump))
{
pRunToBump->setLine(NULL);
}
UT_ASSERT(pLine->getLastRun()->getType() != FPRUN_ENDOFPARAGRAPH);
if(pLine->getLastRun()->getType() == FPRUN_ENDOFPARAGRAPH)
{
fp_Run * pNuke = pLine->getLastRun();
pLine->removeRun(pNuke);
}
pRunToBump->printText(); //trace out debug message & run two time
pNextLine->insertRun(pRunToBump); //called when create new line
// to get the split word
if (!(pRunToBump->getPrevRun() && pLine->getNumRunsInLine() && (pLine->getLastRun() != m_pLastRunToKeep)))
{
pRunToSplit=pRunToBump;
PD_StruxIterator text(pRunToBump->getBlock()->getStruxDocHandle(),
pRunToBump->getBlockOffset() + fl_BLOCK_STRUX_OFFSET);
text.setUpperLimit(text.getPosition() + pRunToBump->getLength() - 1);
UT_ASSERT_HARMLESS( text.getStatus() == UTIter_OK );
UT_UTF8String sTmp;
while(text.getStatus() == UTIter_OK)
{
UT_UCS4Char c = text.getChar();
UT_DEBUGMSG(("| %d |",c));
if(c >= ' ' && c <128)
sTmp += static_cast<char>(c);
++text;
}
UT_DEBUGMSG(("The Split Text |%s| \n",sTmp.utf8_str()));
if(sTmp.utf8_str()!=0)
{
pWordToSplit=sTmp;
UT_DEBUGMSG(("wordToSplit |%s| \n",pWordToSplit.utf8_str()));
}
}
pRunToBump = pRunToBump->getPrevRun();
UT_DEBUGMSG(("Next runToBump %x \n",pRunToBump));
}
}
//modify src/text/fmt/xp/fb_LineBreaker.cpp to place hypernation points
//spit the word
if(pWordToSplit.length()!=NULL)
{
pWordHyphenationResult=pBlock->_hyphenateWord(pWordToSplit.ucs4_str().ucs4_str(),0,0);
int tickLeft=pLine->getAvailableWidth();
if (pWordHyphenationResult && *pWordHyphenationResult){
gchar *c = g_ucs4_to_utf8(pWordHyphenationResult, -1, NULL, NULL, NULL);
for(int index=g_utf8_strlen(c,NULL);index>=0;--index)
{
if(pWordHyphenationResult[index]=='-'&&index<tickLeft)
{
pBreakPoint=index;
fp_TextRun* textout=static_cast<fp_TextRun*>(pRunToSplit);
textout->split(pBreakPoint);
}
}
}
}