Convert topic name to Unicode

pull/1558/head
Andrei Kortunov 7 years ago
parent f0ca3eabd3
commit ba91cd658b

@ -6,10 +6,10 @@
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include <components/fontloader/fontloader.hpp> #include <components/fontloader/fontloader.hpp>
#include <components/misc/utf8stream.hpp>
#include "textcolours.hpp" #include "textcolours.hpp"
namespace namespace
{ {
struct AddContent struct AddContent
@ -242,11 +242,17 @@ BookTypesetter::Ptr JournalBooks::createLatinJournalIndex ()
sprintf (buffer, "( %c )", ch); sprintf (buffer, "( %c )", ch);
char buffer2 [32];
sprintf(buffer2, "%c", ch);
const char * c = buffer2;
Utf8Stream stream ((unsigned char*) c,(unsigned char*) c + strlen(c));
uint32_t first = stream.peek();
// TODO: find a way to store a multibyte character in the InteractiveId (this is a intptr_t) // TODO: find a way to store a multibyte character in the InteractiveId (this is a intptr_t)
const MWGui::TextColours& textColours = MWBase::Environment::get().getWindowManager()->getTextColours(); const MWGui::TextColours& textColours = MWBase::Environment::get().getWindowManager()->getTextColours();
BookTypesetter::Style* style = typesetter->createHotStyle (body, textColours.journalTopic, BookTypesetter::Style* style = typesetter->createHotStyle (body, textColours.journalTopic,
textColours.journalTopicOver, textColours.journalTopicOver,
textColours.journalTopicPressed, i+1); textColours.journalTopicPressed, first);
if (i == 13) if (i == 13)
typesetter->sectionBreak (); typesetter->sectionBreak ();
@ -271,11 +277,16 @@ BookTypesetter::Ptr JournalBooks::createCyrillicJournalIndex ()
sprintf(buffer, "( %c%c )", 0xd0, 0x90 + i); // CYRILLIC CAPITAL A is a 0xd090 in UTF-8 sprintf(buffer, "( %c%c )", 0xd0, 0x90 + i); // CYRILLIC CAPITAL A is a 0xd090 in UTF-8
// TODO: find a way to store a multibyte character in the InteractiveId (this is a intptr_t) char buffer2 [32];
sprintf(buffer2, "%c%c", 0xd0, 0x90 + i);
const char * c = buffer2;
Utf8Stream stream ((unsigned char*) c,(unsigned char*) c + strlen(c));
uint32_t first = stream.peek();
const MWGui::TextColours& textColours = MWBase::Environment::get().getWindowManager()->getTextColours(); const MWGui::TextColours& textColours = MWBase::Environment::get().getWindowManager()->getTextColours();
BookTypesetter::Style* style = typesetter->createHotStyle (body, textColours.journalTopic, BookTypesetter::Style* style = typesetter->createHotStyle (body, textColours.journalTopic,
textColours.journalTopicOver, textColours.journalTopicOver,
textColours.journalTopicPressed, i+1); textColours.journalTopicPressed, first);
// Words can not be started with these characters // Words can not be started with these characters
if (i == 26 || i == 28) if (i == 26 || i == 28)

@ -6,6 +6,8 @@
#include <MyGUI_LanguageManager.h> #include <MyGUI_LanguageManager.h>
#include <components/translation/translation.hpp> #include <components/translation/translation.hpp>
#include <components/misc/stringops.hpp>
#include <components/misc/utf8stream.hpp>
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwbase/journal.hpp" #include "../mwbase/journal.hpp"
@ -305,45 +307,20 @@ struct JournalViewModelImpl : JournalViewModel
visitor (toUtf8Span (topic.getName())); visitor (toUtf8Span (topic.getName()));
} }
void visitTopicNamesStartingWith (int index, std::function < void (const std::string&) > visitor) const void visitTopicNamesStartingWith (uint32_t character, std::function < void (const std::string&) > visitor) const
{ {
MWBase::Journal * journal = MWBase::Environment::get().getJournal(); MWBase::Journal * journal = MWBase::Environment::get().getJournal();
for (MWBase::Journal::TTopicIter i = journal->topicBegin (); i != journal->topicEnd (); ++i) for (MWBase::Journal::TTopicIter i = journal->topicBegin (); i != journal->topicEnd (); ++i)
{ {
unsigned char byte1 = i->first[0]; const char * c = i->first.c_str();
// First, check for two-byte UTF-8 symbols, e.g. Cyrillic ones Utf8Stream stream ((unsigned char*) c,(unsigned char*) c + strlen(c));
// TODO: check which language journal index is using uint32_t first = Misc::StringUtils::toUpper(stream.peek());
if ((byte1 == 0xd0 || byte1 == 0xd1) && i->first.length() >= 2)
{
unsigned char byte2 = i->first[1];
std::pair<unsigned char, unsigned char> symbol = Misc::StringUtils::toLower(byte1, byte2);
// CYRILLIC LETTER A - CYRILLIC LETTER PE
// index from 1 to 16
if (symbol.first == 0xd0 && symbol.second >= (0xaf + index) && symbol.second < (0xbf + index) && symbol.second == (0xaf + index))
{
visitor (i->second.getName());
continue;
}
// CYRILLIC LETTERL R - CYRILLIC LETTER YA if (first != character)
// index from 17 to 32 continue;
if (symbol.first == 0xd1 && symbol.second >= (0x6f + index) && symbol.second < (0x7f + index) && symbol.second == (0x6f + index))
{
visitor (i->second.getName());
continue;
}
}
else
{
// Otherwise check for regular Latin symbols, 0x61 = 'a'
if (i->first [0] != 0x60 + index)
continue;
visitor (i->second.getName()); visitor (i->second.getName());
}
} }
} }

@ -75,8 +75,8 @@ namespace MWGui
/// provides the name of the topic specified by its id /// provides the name of the topic specified by its id
virtual void visitTopicName (TopicId topicId, std::function <void (Utf8Span)> visitor) const = 0; virtual void visitTopicName (TopicId topicId, std::function <void (Utf8Span)> visitor) const = 0;
/// walks over the topics whose names start with the character, specified by its index in the alphabet, providing the topics name /// walks over the topics whose names start with the character
virtual void visitTopicNamesStartingWith (int index, std::function < void (const std::string&) > visitor) const = 0; virtual void visitTopicNamesStartingWith (uint32_t character, std::function < void (const std::string&) > visitor) const = 0;
/// walks over the topic entries for the topic specified by its identifier /// walks over the topic entries for the topic specified by its identifier
virtual void visitTopicEntries (TopicId topicId, std::function <void (TopicEntry const &)> visitor) const = 0; virtual void visitTopicEntries (TopicId topicId, std::function <void (TopicEntry const &)> visitor) const = 0;

@ -56,34 +56,21 @@ public:
}; };
} }
static std::pair<char, char> toLower(unsigned char byte1, unsigned char byte2) static uint32_t toUpper(uint32_t ch)
{ {
std::pair<unsigned char, unsigned char> symbol = std::make_pair(byte1, byte2); // Russian alphabete
// CYRILLIC CAPITAL IO if (ch >= 0x0430 && ch < 0x0450)
if (symbol.first == 0xd0 && symbol.second == 0x01) ch -= 0x20;
{
symbol.first++; // Cyrillic YO character
symbol.second = 0x91; if (ch == 0x0451)
} ch -= 0x50;
// CYRILLIC CAPITAL A - CYRILLIC CAPITAL PE
else if (symbol.first == 0xd0 && symbol.second >= 0x90 && symbol.second < 0xa0) // Latin alphabete
{ if (ch >= 0x61 && ch < 0x80)
symbol.second += 0x20; ch -= 0x20;
}
// CYRILLIC CAPITAL R - CYRILLIC CAPITAL YA
else if (symbol.first == 0xd0 && symbol.second >= 0xa0 && symbol.second < 0xb0)
{
symbol.first++;
symbol.second -= 0x20;
}
// Other symbols
else
{
symbol.first = toLower(symbol.first);
symbol.second = toLower(symbol.second);
}
return symbol; return ch;
} }
static bool ciLess(const std::string &x, const std::string &y) { static bool ciLess(const std::string &x, const std::string &y) {

Loading…
Cancel
Save