support unicode symbols for 2.x compatibility

This commit is contained in:
Werner Schweer 2017-05-24 17:01:35 +02:00
parent fff16915af
commit 641ee23ff1
2 changed files with 48 additions and 10 deletions

View file

@ -5844,7 +5844,11 @@ void ScoreFont::computeMetrics(Sym* sym, int code)
sym->setAdvance(face->glyph->linearHoriAdvance * DPI_F/ 655360.0);
}
}
else
qDebug("load glyph failed");
}
// else
// qDebug("no index");
}
//---------------------------------------------------------
@ -5877,11 +5881,11 @@ void ScoreFont::load()
qDebug("codepoint not recognized for glyph %s", qPrintable(i));
if (Sym::lnhash.contains(i)) {
SymId symId = Sym::lnhash.value(i);
Sym* sym = &_symbols[int(symId)];
Sym* sym = &_symbols[int(symId)];
computeMetrics(sym, code);
}
//else
// qDebug("unknown glyph: %s", qPrintable(i));
else
qDebug("unknown glyph: %s", qPrintable(i));
}
QJsonParseError error;
@ -6144,6 +6148,7 @@ void ScoreFont::load()
// add space symbol
Sym* sym = &_symbols[int(SymId::space)];
computeMetrics(sym, 32);
#if 0
//
// check for missing symbols
@ -6350,6 +6355,7 @@ ScoreFont::~ScoreFont()
{
delete cache;
}
}

View file

@ -1065,14 +1065,46 @@ void Text::createLayout()
else if (token == "/sym") {
symState = false;
QString sfn = score()->styleSt(StyleIdx::MusicalTextFont);
cursor.format()->setFontFamily(sfn);
SymId id = Sym::name2id(sym);
const Sym& sym = score()->scoreFont()->sym(id);
int code = sym.code();
if (code & 0xffff0000)
insert(&cursor, QChar(QChar::highSurrogate(code)), QChar(QChar::lowSurrogate(code)));
else
insert(&cursor, QChar(code));
uint code;
if (id == SymId::noSym) {
qDebug("symbol <%s> not known", qPrintable(sym));
// Unicode
struct UnicodeAlternate {
const char* name;
int a;
int b;
}
unicodes[] = {
{ "unicodeNoteDoubleWhole", 0xd834, 0xdd5c },
{ "unicodeNoteWhole", 0xd834, 0xdd5d },
{ "unicodeNoteHalfUp", 0xd834, 0xdd5e },
{ "unicodeNoteQuarterUp", 0xd834, 0xdd5f },
{ "unicodeNote8thUp", 0xd834, 0xdd60 },
{ "unicodeNote16thUp", 0xd834, 0xdd61 },
{ "unicodeNote32ndUp", 0xd834, 0xdd62 },
{ "unicodeNote64thUp", 0xd834, 0xdd63 },
{ "unicodeNote128thUp", 0xd834, 0xdd64 },
{ "unicodeAugmentationDot", 0xd834, 0xdd6D }
};
for (const UnicodeAlternate& unicode : unicodes) {
if (unicode.name == sym) {
code = QChar::surrogateToUcs4(QChar(unicode.a), QChar(unicode.b));
break;
}
}
}
else {
cursor.format()->setFontFamily(sfn);
code = score()->scoreFont()->sym(id).code();
}
if (code) {
if (code & 0xffff0000)
insert(&cursor, QChar(QChar::highSurrogate(code)), QChar(QChar::lowSurrogate(code)));
else
insert(&cursor, QChar(code));
}
}
else if (token.startsWith("font ")) {
token = token.mid(5);