1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
|
/*--------------------------------------------------------------------*//*:Ignore this sentence.
Copyright (C) 1999, 2001 SIL International. All rights reserved.
Distributable under the terms of either the Common Public License or the
GNU Lesser General Public License, as specified in the LICENSING.txt file.
File: GdlGlyphClass.h
Responsibility: Sharon Correll
Last reviewed: Not yet.
Description:
Definitions of classes of glyphs.
-------------------------------------------------------------------------------*//*:End Ignore*/
#ifdef _MSC_VER
#pragma once
#endif
#ifndef CLASSES_INCLUDED
#define CLASSES_INCLUDED
class GdlGlyphDefn;
//class PseudoLess;
//typedef std::set<GdlGlyphDefn *, PseudoLess> PseudoSet; // PseudoLess isn't implemented adquately yet
typedef std::set<GdlGlyphDefn *> PseudoSet;
//class ReplClassLess;
//typedef std::set<GdlGlyphClassDefn *, ReplClassLess> ReplacementClassSet;
/*----------------------------------------------------------------------------------------------
Class: GdlGlyphAttrSetting
Description: The setting of a glyph attribute--attribute name and expression indicating
the value.
Hungarian: glfa
----------------------------------------------------------------------------------------------*/
class GdlGlyphAttrSetting : public GdlObject
{
friend class GdlGlyphClassDefn;
public:
// Constructors & destructors:
GdlGlyphAttrSetting(Symbol psym, GdlAssignment * pasgn)
: m_psym(psym),
m_pasgn(pasgn)
{
SetLineAndFile(pasgn->LineAndFile());
}
~GdlGlyphAttrSetting()
{
Assert(m_pasgn);
delete m_pasgn;
}
Symbol GlyphSymbol() { return m_psym; }
GdlAssignment * Assignment() { return m_pasgn; }
GdlExpression * Expression() { return m_pasgn->Expression(); }
protected:
// Instance variables:
Symbol m_psym;
GdlAssignment * m_pasgn;
};
/*----------------------------------------------------------------------------------------------
Class: GdlGlyphClassMember
Description: Abstract class subsuming GdlGlyphClassDefn and GdlGlyphDefn, ie, an element
of a class.
Hungarian: glfd
----------------------------------------------------------------------------------------------*/
class GdlGlyphClassMember : public GdlDefn
{
public:
virtual ~GdlGlyphClassMember()
{
};
// Pre-compiler:
virtual void ExplicitPseudos(PseudoSet & setpglf) = 0;
virtual int ActualForPseudo(utf16 wPseudo) = 0;
virtual int GlyphIDCount() = 0;
virtual unsigned int FirstGlyphInClass(bool * pfMoreThanOne) = 0;
virtual void AssignGlyphIDsToClassMember(GrcFont *, utf16 wGlyphIDLim,
std::map<utf16, utf16> & hmActualForPseudo,
bool fLookUpPseudo = true) = 0;
virtual void AssignGlyphAttrsToClassMembers(GrcGlyphAttrMatrix * pgax,
GdlRenderer * prndr, GrcLigComponentList * plclist,
std::vector<GdlGlyphAttrSetting *> & vpglfaAttrs, int cgid, int & igid) = 0;
virtual void CheckExistenceOfGlyphAttr(GdlObject * pgdlAvsOrExp,
GrcSymbolTable * psymtbl, GrcGlyphAttrMatrix * pgax, Symbol psymGlyphAttr) = 0;
virtual void CheckCompleteAttachmentPoint(GdlObject * pgdlAvsOrExp,
GrcSymbolTable * psymtbl, GrcGlyphAttrMatrix * pgax, Symbol psymGlyphAttr,
bool * pfXY, bool * pfGpoint) = 0;
virtual void CheckCompBox(GdlObject * pritset,
GrcSymbolTable * psymtbl, GrcGlyphAttrMatrix * pgax, Symbol psymCompRef) = 0;
virtual void StorePseudoToActualAsGlyphAttr(GrcGlyphAttrMatrix * pgax, int nAttrID,
std::vector<GdlExpression *> & vpexpExtra) = 0;
virtual bool IncludesGlyph(utf16) = 0;
virtual bool HasOverlapWith(GdlGlyphClassMember * glfd, GrcFont * pfont) = 0;
virtual bool HasBadGlyph() = 0;
virtual bool WarnAboutBadGlyphs(bool fTop) = 0;
virtual bool DeleteBadGlyphs() = 0;
virtual void FlattenGlyphList(std::vector<utf16> & vgidFlattened) = 0;
public:
// Compiler:
virtual void RecordInclusionInClass(GdlPass * ppass, GdlGlyphClassDefn * pglfc) = 0;
virtual void GetMachineClasses(FsmMachineClass ** ppfsmcAssignments,
FsmMachineClassSet & setpfsmc) = 0;
// Output:
virtual void AddGlyphsToUnsortedList(std::vector<utf16> & vwGlyphs) = 0;
virtual void AddGlyphsToSortedList(std::vector<utf16> & vwGlyphs, std::vector<int> & vnIndices) = 0;
// debuggers
virtual void DebugCmapForMember(GrcFont * pfont,
utf16 * rgchwUniToGlyphID, unsigned int * rgnGlyphIDToUni) = 0;
virtual void DebugXmlClassMembers(std::ofstream & strmOut,
GdlGlyphClassDefn * pglfdParent, GrpLineAndFile lnf, int & cwGlyphIDs) = 0;
};
/*----------------------------------------------------------------------------------------------
Class: GdlGlyphClassDefn
Description: A class of glyphs and glyph attribute settings.
Hungarian: glfc
----------------------------------------------------------------------------------------------*/
class GdlGlyphClassDefn : public GdlGlyphClassMember
{
friend class GdlGlyphDefn;
friend class ReplClassLess;
public:
// Constructors & destructors:
GdlGlyphClassDefn()
{
m_fReplcmtIn = false;
m_fReplcmtOut = false;
m_nReplcmtInID = -1;
m_nReplcmtOutID = -1;
m_fHasFlatList = false;
}
~GdlGlyphClassDefn();
void DeleteGlyphDefns();
// Getters:
std::string Name() { return m_staName; }
// Setters:
void SetName(std::string sta) { m_staName = sta; }
void AddMember(GdlGlyphClassMember * pglfd, GrpLineAndFile const& lnf);
void AddGlyphAttr(Symbol, GdlAssignment * pasgn);
void AddComponent(Symbol, GdlAssignment * pasgn);
static std::string Undefined()
{
return "*GCUndefined*";
}
// Parser:
GdlGlyphClassMember * AddGlyphToClass(GrpLineAndFile const& lnf,
GlyphType glft, int nFirst);
GdlGlyphClassMember * AddGlyphToClass(GrpLineAndFile const& lnf,
GlyphType glft, int nFirst, int nLast);
GdlGlyphClassMember * AddGlyphToClass(GrpLineAndFile const& lnf,
GlyphType glft, int nFirst, int nLast, utf16 wCodePage);
GdlGlyphClassMember * AddGlyphToClass(GrpLineAndFile const& lnf,
GlyphType glft, std::string staPostscript);
GdlGlyphClassMember * AddGlyphToClass(GrpLineAndFile const& lnf,
GlyphType glft, std::string staCodepoints, utf16 wCodePage);
GdlGlyphClassMember * AddGlyphToClass(GrpLineAndFile const& lnf,
GlyphType glft, GdlGlyphDefn * pglfOutput, utf16 nPseudoInput);
GdlGlyphClassMember * AddGlyphToClass(GrpLineAndFile const& lnf,
GlyphType glft, GdlGlyphDefn * pglfOutput);
GdlGlyphClassMember * AddClassToClass(GrpLineAndFile const& lnf,
GdlGlyphClassDefn * pglfcMember);
// Pre-compiler:
virtual void ExplicitPseudos(PseudoSet & setpglf);
virtual int ActualForPseudo(utf16 wPseudo);
void AssignGlyphIDs(GrcFont *, utf16 wGlyphIDLim,
std::map<utf16, utf16> & hmActualForPseudos);
virtual void AssignGlyphIDsToClassMember(GrcFont *, utf16 wGlyphIDLim,
std::map<utf16, utf16> & hmActualForPseudo,
bool fLookUpPseudo = true);
virtual int GlyphIDCount();
void MaxJustificationLevel(int * pnJLevel);
virtual unsigned int FirstGlyphInClass(bool * pfMoreThanOne);
void AssignGlyphAttrsToClassMembers(GrcGlyphAttrMatrix * pgax,
GdlRenderer * prndr, GrcLigComponentList * plclist);
virtual void AssignGlyphAttrsToClassMembers(GrcGlyphAttrMatrix * pgax,
GdlRenderer * prndr, GrcLigComponentList * plclist,
std::vector<GdlGlyphAttrSetting *> & vpglfaAttrs, int cgid, int & igid);
virtual void CheckExistenceOfGlyphAttr(GdlObject * pgdlAvsOrExp,
GrcSymbolTable * psymtbl, GrcGlyphAttrMatrix * pgax, Symbol psymGlyphAttr);
virtual void CheckCompleteAttachmentPoint(GdlObject * pgdlAvsOrExp,
GrcSymbolTable * psymtbl, GrcGlyphAttrMatrix * pgax, Symbol psymGlyphAttr,
bool * pfXY, bool * pfGpoint);
virtual void CheckCompBox(GdlObject * pritset,
GrcSymbolTable * psymtbl, GrcGlyphAttrMatrix * pgax, Symbol psymCompRef);
virtual void StorePseudoToActualAsGlyphAttr(GrcGlyphAttrMatrix * pgax, int nAttrID,
std::vector<GdlExpression *> & vpexpExtra);
void MarkFsmClass(int nPassID, int nClassID);
bool IsFsmClass(int ipass)
{
if (ipass >= signed(m_vfFsm.size()))
return false;
return m_vfFsm[ipass];
}
int FsmID(int ipass)
{
return m_vnFsmID[ipass];
}
virtual bool IncludesGlyph(utf16);
void MarkReplcmtInputClass() { m_fReplcmtIn = true; }
void MarkReplcmtOutputClass() { m_fReplcmtOut = true; }
void SetReplcmtInputID(int nID) { m_nReplcmtInID = nID; }
void SetReplcmtOutputID(int nID) { m_nReplcmtOutID = nID; }
bool ReplcmtInputClass() { return m_fReplcmtIn; }
bool ReplcmtOutputClass() { return m_fReplcmtOut; }
int ReplcmtInputID() { return m_nReplcmtInID; }
int ReplcmtOutputID() { return m_nReplcmtOutID; }
bool CompatibleWithVersion(int fxdVersion, int * pfxdNeeded, int * pfxdCpilrNeeded);
virtual bool HasOverlapWith(GdlGlyphClassMember * glfd, GrcFont * pfont);
virtual bool HasBadGlyph();
virtual bool WarnAboutBadGlyphs(bool fTop);
virtual bool DeleteBadGlyphs();
public:
// Compiler:
void RecordInclusionInClass(GdlPass * ppass);
virtual void RecordInclusionInClass(GdlPass * ppass, GdlGlyphClassDefn * pglfc);
virtual void GetMachineClasses(FsmMachineClass ** ppfsmcAssignments,
FsmMachineClassSet & setpfsmc);
// Output
void GenerateOutputGlyphList(std::vector<utf16> & vwGlyphs);
void GenerateInputGlyphList(std::vector<utf16> & vwGlyphs, std::vector<int> & vnIndices);
void AddGlyphsToUnsortedList(std::vector<utf16> & vwGlyphs);
void AddGlyphsToSortedList(std::vector<utf16> & vwGlyphs, std::vector<int> & vnIndices);
// debuggers
void DebugCmap(GrcFont * pfont,
utf16 * rgchwUniToGlyphID, unsigned int * rgnGlyphIDToUni);
virtual void DebugCmapForMember(GrcFont * pfont,
utf16 * rgchwUniToGlyphID, unsigned int * rgnGlyphIDToUni);
void DebugXmlClasses(std::ofstream & strmOut, int & cwGlyphIDs);
virtual void DebugXmlClassMembers(std::ofstream & strmOut,
GdlGlyphClassDefn * pglfdParent, GrpLineAndFile lnf, int & cwGlyphIDs);
void RecordSingleMemberClasses(std::vector<std::string> & vstaSingleMemberClasses);
void FlattenMyGlyphList()
{
if (!m_fHasFlatList)
{
for (size_t i = 0; i < m_vpglfdMembers.size(); i++)
m_vpglfdMembers[i]->FlattenGlyphList(m_vgidFlattened);
m_fHasFlatList = true;
}
}
virtual void FlattenGlyphList(std::vector<utf16> & vgidFlattened);
GrpLineAndFile & LineAndFileForMember(int iglfd)
{
return m_vlnfMembers[iglfd];
}
protected:
// Instance variables:
std::string m_staName;
std::vector<GdlGlyphClassMember*> m_vpglfdMembers;
std::vector<GrpLineAndFile> m_vlnfMembers; // where each member was added, for debugger file
std::vector<GdlGlyphAttrSetting*> m_vpglfaAttrs;
// Flat list of included glyph ids; needed to generate a key for a replacement-class set.
std::vector<utf16> m_vgidFlattened;
bool m_fHasFlatList;
// std::vector<GdlGlyphAttrSetting*> m_vpglfaComponents;
// std::vector<std::string> m_vstaComponentNames; // redundant with what is in components
// list, but more accessible
// GdlExpression * m_pexpDirection;
// int m_nDirStmtNo;
// GdlExpression * m_pexpBreakweight;
// int m_nBwStmtNo;
// for compiler use:
std::vector<bool> m_vfFsm; // needs to be matched by the FSM, one flag for each pass
std::vector<int> m_vnFsmID; // FSM class ID, one for each pass
bool m_fReplcmtIn; // serves as an input class for replacement
bool m_fReplcmtOut; // serves as an output class for replacement
int m_nReplcmtInID; // internal ID when serving as replacement input class
int m_nReplcmtOutID; // internal ID when serving as replacement output class
// Comparing two class definitions for insertion in a set; this assumes they are used as
// replacement classes and therefore the order of the items is signficant.
bool ReplClassLessThan(const GdlGlyphClassDefn * pglfc) const
{
//if (!this->m_fHasFlatList)
// this->FlattenMyGlyphList();
//if (!pglfc->m_fHasFlatList)
// pglfc->FlattenMyGlyphList();
Assert(this->m_fHasFlatList); // obsolete
Assert(pglfc->m_fHasFlatList);
if (this == pglfc)
return false;
//for (int igid = 0; igid < signed(m_vgidFlattened.size()); igid++)
//{
// if (signed(pglfc->m_vgidFlattened.size()) < igid - 1)
// return false;
// if (this->m_vgidFlattened[igid] < pglfc->m_vgidFlattened[igid])
// return true;
// if (this->m_vgidFlattened[igid] > pglfc->m_vgidFlattened[igid])
// return false;
//}
//// At this point either the two classes are exactly the same, or pglfc is longer.
//if (pglfc->m_vgidFlattened.size() > this->m_vgidFlattened.size())
// return true;
// The contents of the two classes are the same; compare the names.
return (strcmp(this->m_staName.c_str(), pglfc->m_staName.c_str()) < 0);
}
}; // end of class GdlGlyphClassDefn
// Functor class for set manipulation.
class ReplClassLess
{
friend class GdlGlyphClassDefn;
public:
bool operator()(const GdlGlyphClassDefn * pglfc1, const GdlGlyphClassDefn * pglfc2) const
{
return (pglfc1->ReplClassLessThan(pglfc2));
}
};
#endif // CLASSES_INCLUDED
|