[dasher: 8/38] Mandarin: fix missing PY labels
- From: Patrick Welche <pwelche src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dasher: 8/38] Mandarin: fix missing PY labels
- Date: Tue, 3 Jan 2012 15:33:20 +0000 (UTC)
commit 160666b3447dca51ca40b1fdc5b76cc0b19ae7a8
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date: Tue Dec 6 21:20:41 2011 +0000
Mandarin: fix missing PY labels
Labels of elided single-child groups were going missing!
Src/DasherCore/AlphabetManager.cpp | 10 ++++++--
Src/DasherCore/AlphabetManager.h | 7 +++++-
Src/DasherCore/MandarinAlphMgr.cpp | 40 ++++++++++++++++++++++-------------
Src/DasherCore/MandarinAlphMgr.h | 7 +++++-
4 files changed, 44 insertions(+), 20 deletions(-)
---
diff --git a/Src/DasherCore/AlphabetManager.cpp b/Src/DasherCore/AlphabetManager.cpp
index 8c11712..5b69851 100644
--- a/Src/DasherCore/AlphabetManager.cpp
+++ b/Src/DasherCore/AlphabetManager.cpp
@@ -64,8 +64,10 @@ CAlphabetManager::CAlphabetManager(CSettingsUser *pCreateFrom, CDasherInterfaceB
}
//else, if all single-octet chars are in alphabet - leave m_sDelim==""
// (and we'll find a delimiter for each context)
+}
- m_vLabels.resize(m_pAlphabet->GetNumberTextSymbols()+1);
+const string &CAlphabetManager::GetLabelText(symbol i) const {
+ return m_pAlphabet->GetDisplayText(i);
}
void CAlphabetManager::CreateLanguageModel() {
@@ -98,6 +100,7 @@ void CAlphabetManager::MakeLabels(CDasherScreen *pScreen) {
for (vector<CDasherScreen::Label *>::iterator it=m_vLabels.begin(); it!=m_vLabels.end(); it++) {
delete (*it); *it = NULL;
}
+ m_vLabels.resize(m_pAlphabet->GetNumberTextSymbols()+1);
m_pFirstGroup = copyGroups(pScreen, 1, m_pAlphabet->GetNumberTextSymbols()+1,m_pAlphabet->m_pBaseGroup);
}
@@ -146,7 +149,8 @@ CAlphabetManager::SGroupInfo *CAlphabetManager::copyGroups(CDasherScreen *pScree
}
pFirstChild = pFirstChild->pNext; //making a symbol, so we've still moved past the outer (elided) group
}
- m_vLabels[i]=pScreen->MakeLabel(strGroupPrefix+m_pAlphabet->GetDisplayText(i));
+ string symLabel = strGroupPrefix + GetLabelText(i);
+ m_vLabels[i]=(symLabel.empty() ? NULL : pScreen->MakeLabel(symLabel));
}
return NULL;
}
@@ -473,7 +477,7 @@ CDasherNode *CAlphabetManager::CreateSymbolNode(CAlphNode *pParent, symbol iSymb
CSymbolNode *pAlphNode = new CSymbolNode(iNewOffset, m_vLabels[iSymbol], this, iSymbol);
// std::stringstream ssLabel;
- // ssLabel << m_pAlphabet->GetDisplayText(iSymbol) << ": " << pNewNode;
+ // ssLabel << GetLabelText(iSymbol) << ": " << pNewNode;
// pDisplayInfo->strDisplayText = ssLabel.str();
diff --git a/Src/DasherCore/AlphabetManager.h b/Src/DasherCore/AlphabetManager.h
index 5fec4fa..2883fd7 100644
--- a/Src/DasherCore/AlphabetManager.h
+++ b/Src/DasherCore/AlphabetManager.h
@@ -81,9 +81,11 @@ namespace Dasher {
int iNumChildNodes;
CDasherScreen::Label *pLabel;
} *m_pFirstGroup;
+
//A label for each symbol, indexed by symbol id (element 0 = null)
std::vector<CDasherScreen::Label *> m_vLabels;
- SGroupInfo *copyGroups(CDasherScreen *pScreen, int iStart, int iEnd, ::SGroupInfo *pFirstChild);
+
+ virtual const std::string &GetLabelText(symbol i) const;
class CAlphNode;
/// Abstract superclass for alphabet manager nodes, provides common implementation
@@ -251,6 +253,9 @@ namespace Dasher {
/// (also leaves space for NCManager::AddExtras to add control node)
/// Returns array of non-cumulative probs. Should this be protected and/or virtual???
void GetProbs(std::vector<unsigned int> *pProbs, CLanguageModel::Context iContext);
+
+ SGroupInfo *copyGroups(CDasherScreen *pScreen, int iStart, int iEnd, ::SGroupInfo *pFirstChild);
+
///Constructs child nodes under the specified parent according to provided group.
/// Nodes are created by calling CreateSymbolNode and CreateGroupNode, unless buildAround is non-null.
/// \param pParentGroup group describing which symbols and/or subgroups should be constructed
diff --git a/Src/DasherCore/MandarinAlphMgr.cpp b/Src/DasherCore/MandarinAlphMgr.cpp
index 0ee1246..cd68513 100644
--- a/Src/DasherCore/MandarinAlphMgr.cpp
+++ b/Src/DasherCore/MandarinAlphMgr.cpp
@@ -113,15 +113,18 @@ CMandarinAlphMgr::CMandarinAlphMgr(CSettingsUser *pCreator, CDasherInterfaceBase
}
void CMandarinAlphMgr::MakeLabels(CDasherScreen *pScreen) {
+ //this makes any labels req'd for conversion roots
+ // (i.e. captions of groups, containing said root, that are elided)
CAlphabetManager::MakeLabels(pScreen);
- //a bit of a waste, that fills m_vLabels with labels for all the pinyin symbols - which we don't use.
- for (vector<CDasherScreen::Label *>::iterator it=m_vLabels.begin(); it!=m_vLabels.end(); it++)
- delete *it;
- m_vLabels.clear();
- //instead, keep the screen to create labels lazily...
+ //also keep the screen to create labels lazily...
m_pScreen = pScreen;
}
+const string &CMandarinAlphMgr::GetLabelText(symbol i) const {
+ static string n="";
+ return n;
+}
+
CMandarinAlphMgr::~CMandarinAlphMgr() {
delete[] m_pConversionsBySymbol;
}
@@ -181,10 +184,14 @@ CDasherNode *CMandarinAlphMgr::CreateSymbolNode(CAlphNode *pParent, symbol iSymb
//For every PY symbol (=syllable+tone, or "punctuation"),
// m_pConversionsBySymbol identifies the possible chinese-alphabet symbols
- // that have that syll+tone (for punctuation, this'll be a singleton: the identical
- // punctuation character in the chinese alphabet). A CConvRoot thus offers a choice between them...
+ // that have that syll+tone; a CConvRoot thus offers the choice between them.
+ //However, for e.g. punctuation, there may be only one such CH symbol, in which
+ // case we can create the symbol directly, bypassing the CConvRoot; EXCEPT,
+ // in cases where the CConvRoot provides a place to put some part of the group
+ // label (specific to that symbol, so kinda redundant, but we want to keep it
+ // for consistency of display).
- if (m_pConversionsBySymbol[iSymbol].size()>1)
+ if (m_pConversionsBySymbol[iSymbol].size()>1 || m_vLabels[iSymbol])
return CreateConvRoot(pParent, iSymbol);
return CreateCHSymbol(pParent,pParent->iContext, *(m_pConversionsBySymbol[iSymbol].begin()), iSymbol);
@@ -202,8 +209,11 @@ CMandarinAlphMgr::CConvRoot *CMandarinAlphMgr::CreateConvRoot(CAlphNode *pParent
}
CMandarinAlphMgr::CConvRoot::CConvRoot(int iOffset, CMandarinAlphMgr *pMgr, symbol pySym)
-: CAlphBase(iOffset, 9, NULL, pMgr), m_pySym(pySym) {
- DASHER_ASSERT(pMgr->m_pConversionsBySymbol[pySym].size()>1);
+: CAlphBase(iOffset, 9, pMgr->m_vLabels[pySym], pMgr), m_pySym(pySym) {
+ //We do sometimes create CConvRoots with only one child, where we
+ // need them to display a label...
+ DASHER_ASSERT(pMgr->m_pConversionsBySymbol[pySym].size()>1
+ || pMgr->m_vLabels[pySym]);
//colour + label from ConversionManager.
}
@@ -348,12 +358,12 @@ void CMandarinAlphMgr::GetConversions(std::vector<pair<symbol,unsigned int> > &v
CDasherScreen::Label *CMandarinAlphMgr::GetLabel(int iCHsym) {
//TODO: LRU cache, keep down to some sensible #labels allocated?
- if (iCHsym>=m_vLabels.size()) {
- m_vLabels.resize(iCHsym+1);
- } else if (m_vLabels[iCHsym]) {
- return m_vLabels[iCHsym];
+ if (iCHsym>=m_vCHLabels.size()) {
+ m_vCHLabels.resize(iCHsym+1);
+ } else if (m_vCHLabels[iCHsym]) {
+ return m_vCHLabels[iCHsym];
}
- return m_vLabels[iCHsym] = m_pScreen->MakeLabel(m_CHdisplayText[iCHsym]);
+ return m_vCHLabels[iCHsym] = m_pScreen->MakeLabel(m_CHdisplayText[iCHsym]);
}
CMandarinAlphMgr::CMandSym::CMandSym(int iOffset, CMandarinAlphMgr *pMgr, symbol iSymbol, symbol pyParent)
diff --git a/Src/DasherCore/MandarinAlphMgr.h b/Src/DasherCore/MandarinAlphMgr.h
index bce3ae2..d7b9dea 100644
--- a/Src/DasherCore/MandarinAlphMgr.h
+++ b/Src/DasherCore/MandarinAlphMgr.h
@@ -80,13 +80,17 @@ namespace Dasher {
protected:
void MakeLabels(CDasherScreen *pScreen);
+ //Remove label on the "symbols" i.e. PY sounds; we use the label
+ // internally to identify a CH group, but for display purposes the symbol is
+ // identified entirely by the PY groups around it.
+ const std::string &GetLabelText(symbol i) const;
class CConvRoot;
///Subclass of CSymbolNode for (converted) chinese-alphabet symbols:
/// these use the chinese alphabet in place of the pinyin one for text to display/enter,
/// and get their colour using GetCHColour rather than GetColour.
class CMandSym : public CSymbolNode {
public:
- CMandarinAlphMgr *mgr() {return static_cast<CMandarinAlphMgr *>(CSymbolNode::mgr());}
+ CMandarinAlphMgr *mgr() const {return static_cast<CMandarinAlphMgr *>(CSymbolNode::mgr());}
///Symbol constructor: display text from CHAlphabet, colour from GetCHColour
CMandSym(int iOffset, CMandarinAlphMgr *pMgr, symbol iSymbol, symbol pyParent);
CDasherNode *RebuildSymbol(CAlphNode *pParent, symbol iSymbol);
@@ -164,6 +168,7 @@ namespace Dasher {
std::vector<int> m_CHcolours;
/// Map from unicode char to index into m_CH{text,displayText}
CAlphabetMap m_CHAlphabetMap;
+ std::vector<CDasherScreen::Label *> m_vCHLabels;
///Indexed by SPY (syll+tone) alphabet symbol number,
// the CHAlphabet symbols it can be converted to, in order
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]