2011年8月21日星期日

6. How to Support more languages


6. How to Support more languages

As mentioned before, we use Enchant to support more languages. So we have five backend to support more language. Take ISpell and mySpell for example.

In the folder “abiword\msvc2008\Debug\” there are the folder for hyphenation: Spell and mySpell. And there is two folder for their dictionary

User interface to manage hyphenation


User interface to manage hyphenation

Doing now, user can enable or disable hyphenation function in user interface (GUI).
Ø  I have finished GUI in Windows, Linux, and Cocoa.
Ø  Most languages have been translated for the globalization.
Take Windows GUI for example, user can check the checkbox for enable or disable hyphenation function.
Linux and Cocoa need more tests.
C:\Documents and Settings\Administrator\桌面\Simple Checkbox for Hyphenation GUI.bmp

4 Code Re-factor and debug


4 Code Re-factor and debug

I have finish the code re-factor both in Enchant and Abiword. Code Re-factor works:
1 deal with some ugly code
2 deal with the exception

3 Simple Implementation of Chinese Spell-Check in Enchant


3 Simple Implementation of Chinese Spell-Check in Enchant

After GSoc2011, I would like to add Chinese Spell-Check in Enchant. Chinese Spell-Check is also a very important issue in Word-Processor. I found some lib to support; I just build a simple framework since time is limit.
The main function:

2 Call the Hyphenation function in Abiword.


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);
}
}
}
}

1.8 Test in Linux

I have test the Enchant module in RedHat.  It works fine for me.

1.7 Deploy of enchant in Abiword


I just copy the buliding result of enchant to the right place in Abiword:
enchant\bin\Debug\libenchant_myspell.dll ---->abiword\msvc2008\Debug\lib\enchant\libenchant_myspell.dll
enchant\bin\Debug\libenchant_ispell.dll ---->abiword\msvc2008\Debug\lib\enchant\libenchant_ispell.dll
enchant\bin\Debug\libenchant.dll---->
abiword\msvc2008\Debug\bin\ibenchant.dll