Esempio n. 1
0
bool Hyphenator::loadDict(const QString& name)
{
	if (LanguageManager::instance()->getHyphFilename(name).isEmpty())
		return false;
		
	if (m_language != name)
	{
		m_language = name;

		QFile file(LanguageManager::instance()->getHyphFilename(m_language));
		
		if (m_hdict != nullptr)
			hnj_hyphen_free(m_hdict);

		if (file.open(QIODevice::ReadOnly))
		{
			m_codec = QTextCodec::codecForName(file.readLine());
			m_hdict = hnj_hyphen_load(file.fileName().toLocal8Bit().data());
			file.close();
			return true;
		}
		m_hdict = nullptr;
		return false;
	}

	return (m_codec != nullptr && m_hdict != nullptr);
}
Esempio n. 2
0
nsHyphenator::nsHyphenator(nsIURI *aURI)
  : mDict(nullptr)
{
  nsCString uriSpec;
  nsresult rv = aURI->GetSpec(uriSpec);
  if (NS_FAILED(rv)) {
    return;
  }
  mDict = hnj_hyphen_load(uriSpec.get());
#ifdef DEBUG
  if (mDict) {
    printf("loaded hyphenation patterns from %s\n", uriSpec.get());
  }
#endif
}
Esempio n. 3
0
nsHyphenator::nsHyphenator(nsIFile *aFile)
  : mDict(nsnull)
{
  nsCString path;
  aFile->GetNativePath(path);
  mDict = hnj_hyphen_load(path.get());
#ifdef DEBUG
  if (mDict) {
    printf("loaded hyphenation patterns from %s\n", path.get());
  }
#endif
  nsresult rv;
  mCategories =
    do_GetService(NS_UNICHARCATEGORY_CONTRACTID, &rv);
  NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get category service");
}
Esempio n. 4
0
nsHyphenator::nsHyphenator(nsIFile *aFile)
  : mDict(nsnull)
{
  nsCString urlSpec;
  nsresult rv = NS_GetURLSpecFromFile(aFile, urlSpec);
  if (NS_FAILED(rv)) {
    return;
  }
  mDict = hnj_hyphen_load(urlSpec.get());
#ifdef DEBUG
  if (mDict) {
    printf("loaded hyphenation patterns from %s\n", urlSpec.get());
  }
#endif
  mCategories = do_GetService(NS_UNICHARCATEGORY_CONTRACTID, &rv);
  NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get category service");
}
Esempio n. 5
0
Hyphenator::Hyphenator(QWidget* parent, ScribusDoc *dok) : QObject( parent ),
	m_doc(dok),
	m_hdict(0),
	m_usable(false),
	m_codec(0),
	MinWordLen(m_doc->hyphMinimumWordLength()),
	HyCount(m_doc->hyphConsecutiveLines()),
	Automatic(m_doc->hyphAutomatic()),
	AutoCheck(m_doc->hyphAutoCheck())
{
	//FIXME:av pick up language from charstyle
	LanguageManager * lmgr(LanguageManager::instance());
	if (!lmgr->getHyphFilename(m_doc->hyphLanguage()).isEmpty() )
		Language = m_doc->hyphLanguage();
	else
	{
		Language = PrefsManager::instance()->appPrefs.hyphPrefs.Language;
		m_doc->setHyphLanguage(Language);
	}
	QString pfad = lmgr->getHyphFilename(m_doc->hyphLanguage());
	QFile f(pfad);
	if (f.open(QIODevice::ReadOnly))
	{
		QTextStream st(&f);
    	QString line;
    	line = st.readLine();
		m_codec = QTextCodec::codecForName(line.toUtf8());
		f.close();
	}
	else
	{
		m_usable = false;
		m_hdict = NULL;
		return;
	}
	QByteArray fn = pfad.toLocal8Bit();
	const char * filename = fn.data();
	m_hdict = hnj_hyphen_load(filename);
	m_usable = m_hdict == NULL ? false : true;
	rememberedWords.clear();
/* Add reading these special lists from prefs or doc here */
	ignoredWords.clear();
	specialWords.clear();
}
Esempio n. 6
0
void Hyphenator::NewDict(const QString& name)
{
// 	if (!ScCore->primaryMainWindow()->Sprachen.contains(name))
// 		return;
	if( LanguageManager::instance()->getHyphFilename(name).isEmpty() )
		return;
		
	if (Language != name) 
	{
		Language = name;

		char *filename = NULL;
		QString pfad = LanguageManager::instance()->getHyphFilename(Language);
		
		if (m_hdict != NULL)
			hnj_hyphen_free(m_hdict);

		QFile f(pfad);
		if (f.open(QIODevice::ReadOnly))
		{
			QTextStream st(&f);
			QString line;
			line = st.readLine();
			m_codec = QTextCodec::codecForName(line.toUtf8());
			f.close();
		}
		else
		{
			m_usable = false;
			m_hdict = NULL;
			return;
		}
		QByteArray fn = pfad.toLocal8Bit();
		filename = fn.data();
		m_hdict = hnj_hyphen_load(filename);
		m_usable = m_hdict == NULL ? false : true;
	}
}
Esempio n. 7
0
 HyphenationDictionary(const CString& dictPath)
     : m_libhyphenDictionary(HyphenDictUniquePtr(hnj_hyphen_load(dictPath.data()), hnj_hyphen_free))
 {
 }