#include <break_lines.h>
#ifdef HAVE_THAI_BREAKS
#include "ThBreakIterator.h"
static const QChar *cached = 0;
static QCString *cachedString = 0;
static ThBreakIterator *thaiIt = 0;
#endif
#if APPLE_CHANGES
#include <CoreServices/CoreServices.h>
#endif
void cleanupLineBreaker()
{
#ifdef HAVE_THAI_BREAKS
if ( cachedString )
delete cachedString;
if ( thaiIt )
delete thaiIt;
cached = 0;
#endif
}
namespace khtml {
bool isBreakable(const QChar *s, int pos, int len, bool breakNBSP)
{
#if !APPLE_CHANGES
const QChar *c = s+pos;
unsigned short ch = c->unicode();
if ( ch > 0xff ) {
unsigned char row = c->row();
if ( row == 0x0e ) {
if ( c->cell() < 0x80 ) {
#ifdef HAVE_THAI_BREAKS
if( s != cached ) {
QTextCodec *thaiCodec = QTextCodec::codecForMib(2259);
if ( !cachedString )
cachedString = new QCString;
if ( !thaiIt )
thaiIt = ThBreakIterator::createWordInstance();
*cachedString = thaiCodec->fromUnicode( QConstString( (QChar *)s, len ).string() );
}
thaiIt->setText((tchar *)cachedString->data());
for(int i = thaiIt->first(); i != thaiIt->DONE; i = thaiIt->next() ) {
if( i == pos )
return true;
if( i > pos )
return false;
}
return false;
#else
return true;
#endif
} else
return false;
}
if ( row > 0x2d && row < 0xfb || row == 0x11 )
return true;
else return c->isSpace();
} else {
if ( ch == ' ' || ch == '\n' )
return true;
}
return false;
#else
OSStatus status = 0, findStatus = 0;
static TextBreakLocatorRef breakLocator = 0;
UniCharArrayOffset end;
const QChar *c = s+pos;
unsigned short ch = c->unicode();
if (ch == '\n' || ch == ' ' || (breakNBSP && ch == 0xa0))
return true;
unsigned short lastCh = pos > 0 ? (s+pos-1)->unicode() : 0;
if ((ch > 0x7f && ch != 0xa0) || (lastCh > 0x7f && lastCh != 0xa0)) {
if (!breakLocator)
status = UCCreateTextBreakLocator(NULL, 0, kUCTextBreakLineMask, &breakLocator);
if (status == 0)
findStatus = UCFindTextBreak(breakLocator, kUCTextBreakLineMask, 0, (const UniChar *)s, len, pos, &end);
if (findStatus == 0)
return ((int)end == pos) ? true : false;
}
if (lastCh == '-' || lastCh == '?')
return true;
return c->direction() == QChar::DirWS;
#endif
}
};