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 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
|
/*--------------------------------------------------------------------*//*: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.cpp
Responsibility: Sharon Correll
Last reviewed: Not yet.
Description:
Implements definitions of classes of glyphs..
-------------------------------------------------------------------------------*//*:End Ignore*/
/***********************************************************************************************
Include files
***********************************************************************************************/
#include "main.h"
#ifdef _MSC_VER
#pragma hdrstop
#endif
#undef THIS_FILE
DEFINE_THIS_FILE
/***********************************************************************************************
Forward declarations
***********************************************************************************************/
/***********************************************************************************************
Local Constants and static variables
***********************************************************************************************/
// None
/***********************************************************************************************
Methods: Destruction
***********************************************************************************************/
GdlGlyphClassDefn::~GdlGlyphClassDefn()
{
for (size_t i = 0; i < m_vpglfaAttrs.size(); ++i)
delete m_vpglfaAttrs[i];
}
void GdlGlyphClassDefn::DeleteGlyphDefns()
{
for (size_t i = 0; i < m_vpglfdMembers.size(); ++i)
{
if (dynamic_cast<GdlGlyphDefn * >(m_vpglfdMembers[i]))
delete m_vpglfdMembers[i];
}
}
void GdlGlyphIntersectionClassDefn::DeleteGlyphDefns()
{
GdlGlyphClassDefn::DeleteGlyphDefns();
for (size_t i = 0; i < m_vpglfdSets.size(); ++i)
{
if (dynamic_cast<GdlGlyphDefn * >(m_vpglfdSets[i]))
delete m_vpglfdSets[i];
}
}
void GdlGlyphDifferenceClassDefn::DeleteGlyphDefns()
{
GdlGlyphClassDefn::DeleteGlyphDefns();
if (dynamic_cast<GdlGlyphDefn * >(m_pglfdMinuend))
delete m_pglfdMinuend;
if (dynamic_cast<GdlGlyphDefn * >(m_pglfdSubtrahend))
delete m_pglfdSubtrahend;
}
/***********************************************************************************************
Methods: Post-parser
***********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Add a simple glyph to the class.
----------------------------------------------------------------------------------------------*/
GdlGlyphClassMember * GdlGlyphClassDefn::AddGlyphToClass(GrpLineAndFile const& lnf,
GlyphType glft, int nFirst)
{
GdlGlyphDefn * pglf = new GdlGlyphDefn(glft, nFirst);
pglf->SetLineAndFile(lnf);
AddMember(pglf, lnf);
return pglf;
}
GdlGlyphClassMember * GdlGlyphClassDefn::AddGlyphToClass(GrpLineAndFile const& lnf,
GlyphType glft, int nFirst, int nLast)
{
GdlGlyphDefn * pglf = new GdlGlyphDefn(glft, nFirst, nLast);
pglf->SetLineAndFile(lnf);
AddMember(pglf, lnf);
return pglf;
}
GdlGlyphClassMember * GdlGlyphClassDefn::AddGlyphToClass(GrpLineAndFile const& lnf,
GlyphType glft, int nFirst, int nLast, utf16 wCodePage)
{
GdlGlyphDefn * pglf = new GdlGlyphDefn(glft, nFirst, nLast, wCodePage);
pglf->SetLineAndFile(lnf);
AddMember(pglf, lnf);
return pglf;
}
GdlGlyphClassMember * GdlGlyphClassDefn::AddGlyphToClass(GrpLineAndFile const& lnf,
GlyphType glft, std::string staPostscript)
{
GdlGlyphDefn * pglf = new GdlGlyphDefn(glft, staPostscript);
pglf->SetLineAndFile(lnf);
AddMember(pglf, lnf);
return pglf;
}
GdlGlyphClassMember * GdlGlyphClassDefn::AddGlyphToClass(GrpLineAndFile const& lnf,
GlyphType glft, std::string staCodepoints, utf16 wCodePage)
{
GdlGlyphDefn * pglf = new GdlGlyphDefn(glft, staCodepoints, wCodePage);
pglf->SetLineAndFile(lnf);
AddMember(pglf, lnf);
return pglf;
}
GdlGlyphClassMember * GdlGlyphClassDefn::AddGlyphToClass(GrpLineAndFile const& lnf,
GlyphType glft, GdlGlyphDefn * pglfOutput, utf16 wPseudoInput)
{
GdlGlyphDefn * pglf = new GdlGlyphDefn(glft, pglfOutput, (int)wPseudoInput);
pglf->SetLineAndFile(lnf);
AddMember(pglf, lnf);
return pglf;
}
GdlGlyphClassMember * GdlGlyphClassDefn::AddGlyphToClass(GrpLineAndFile const& lnf,
GlyphType glft, GdlGlyphDefn * pglfOutput)
{
GdlGlyphDefn * pglf = new GdlGlyphDefn(glft, pglfOutput);
pglf->SetLineAndFile(lnf);
AddMember(pglf, lnf);
return pglf;
}
GdlGlyphClassMember * GdlGlyphClassDefn::AddClassToClass(GrpLineAndFile const& lnf,
GdlGlyphClassDefn * pglfcMember)
{
AddMember(pglfcMember, lnf);
return pglfcMember;
}
/*----------------------------------------------------------------------------------------------
Add an element to the class.
----------------------------------------------------------------------------------------------*/
void GdlGlyphClassDefn::AddElement(GdlGlyphClassMember * pglfdElement, GrpLineAndFile const& lnf,
GlyphClassType glfct, GrcManager * pcman)
{
GdlGlyphIntersectionClassDefn * pglfci = dynamic_cast<GdlGlyphIntersectionClassDefn *>(this);
GdlGlyphDifferenceClassDefn * pglfcd = dynamic_cast<GdlGlyphDifferenceClassDefn *>(this);
switch (glfct)
{
case kglfctUnion:
AddMember(pglfdElement, lnf);
break;
case kglfctIntersect:
Assert(pglfci);
pglfci->AddSet(pglfdElement, lnf);
break;
case kglfctDifference:
Assert(pglfcd);
Assert(pglfcd->HasMinuend()); // because we only support -= right now
if (pglfcd->HasMinuend())
{
if (!pglfcd->HasSubtrahend())
{
// Create an anonymous class to hold the subtrahends.
Symbol psymClassAnon = pcman->SymbolTable()->AddAnonymousClassSymbol(lnf);
std::string staClassNameAnon = psymClassAnon->FullName();
GdlGlyphClassDefn * pglfcSubtra = psymClassAnon->GlyphClassDefnData();
Assert(pglfcSubtra);
pglfcSubtra->SetName(staClassNameAnon);
pglfcd->SetSubtrahend(pglfcSubtra, lnf);
}
pglfcd->AddToSubtrahend(pglfdElement, lnf);
}
else
{
GdlGlyphClassDefn * pglfd = dynamic_cast<GdlGlyphClassDefn *>(pglfdElement);
Assert(pglfd); // because we only support class -= ... right now
pglfcd->SetMinuend(pglfd, lnf);
}
break;
default:
Assert(false);
break;
}
}
/*----------------------------------------------------------------------------------------------
Add a member to a "union" class (the standard kind).
----------------------------------------------------------------------------------------------*/
void GdlGlyphClassDefn::AddMember(GdlGlyphClassMember * pglfd, GrpLineAndFile const& lnf)
{
Assert(m_vpglfdMembers.size() == m_vlnfMembers.size());
m_vpglfdMembers.push_back(pglfd);
m_vlnfMembers.push_back(lnf);
}
/*----------------------------------------------------------------------------------------------
Add a set to an intersection class.
----------------------------------------------------------------------------------------------*/
void GdlGlyphIntersectionClassDefn::AddSet(GdlGlyphClassMember * pglfd, GrpLineAndFile const& lnf)
{
Assert(m_vpglfdSets.size() == m_vlnfSets.size());
m_vpglfdSets.push_back(pglfd);
m_vlnfSets.push_back(lnf);
}
/*----------------------------------------------------------------------------------------------
Add an element to a difference class.
----------------------------------------------------------------------------------------------*/
void GdlGlyphDifferenceClassDefn::SetMinuend(GdlGlyphClassDefn * pglfd,
GrpLineAndFile const& lnf)
{
m_pglfdMinuend = pglfd;
m_lnfMinuend = lnf;
}
void GdlGlyphDifferenceClassDefn::SetSubtrahend(GdlGlyphClassDefn * pglfd,
GrpLineAndFile const& lnf)
{
m_pglfdSubtrahend = pglfd;
m_lnfSubtrahend = lnf;
}
void GdlGlyphDifferenceClassDefn::AddToSubtrahend(GdlGlyphClassMember * pglfd,
GrpLineAndFile const& lnf)
{
Assert(m_pglfdSubtrahend);
m_pglfdSubtrahend->AddMember(pglfd, lnf);
}
/*----------------------------------------------------------------------------------------------
Add a user-defined glyph attribute to the list. Note that we shouldn't have to check
for duplicates, due to the way the master glyph attribute list is managed (see
GrcMasterTable::AddItem(...)).
----------------------------------------------------------------------------------------------*/
void GdlGlyphClassDefn::AddGlyphAttr(Symbol psym, GdlAssignment * pasgn)
{
GdlGlyphAttrSetting * pglfa = new GdlGlyphAttrSetting(psym, pasgn);
pglfa->SetLineAndFile(pasgn->LineAndFile());
m_vpglfaAttrs.push_back(pglfa);
}
/*----------------------------------------------------------------------------------------------
Add an attribute of the form component.<compname>.<corner>. Note that we shouldn't have
to check for duplicates, due to the way the master glyph attribute list is managed
(see GrcMasterTable::AddItem(...)).
----------------------------------------------------------------------------------------------*/
void GdlGlyphClassDefn::AddComponent(Symbol psym, GdlAssignment * pasgn)
{
AddGlyphAttr(psym, pasgn);
// Add this component to the list.
// std::string staCompName = psym->FieldAt(2);
// m_vstaComponentNames.Push(staCompName);
// GdlGlyphAttrSetting * pglfa = new RldGlyphAttrSetting(psym, pasgn);
// m_vglfaComponents.Push(pglfa);
}
/*----------------------------------------------------------------------------------------------
Return true if the given glyph is a member of the class.
----------------------------------------------------------------------------------------------*/
bool GdlGlyphClassDefn::IncludesGlyph(utf16 w)
{
for (size_t iglfd = 0; iglfd < m_vpglfdMembers.size(); iglfd++)
{
if (m_vpglfdMembers[iglfd]->IncludesGlyph(w))
return true;
}
return false;
}
/*----------------------------------------------------------------------------------------------
Return true if the class include a bad glyph definition
----------------------------------------------------------------------------------------------*/
bool GdlGlyphClassDefn::HasBadGlyph()
{
for (size_t iglfd = 0; iglfd < m_vpglfdMembers.size(); iglfd++)
{
if (m_vpglfdMembers[iglfd]->HasBadGlyph())
return true;
}
return false;
}
/*----------------------------------------------------------------------------------------------
Add this glyph's list of glyphs to the flat list.
Assumes method is called after list of glyphs is complete.
----------------------------------------------------------------------------------------------*/
void GdlGlyphClassDefn::FlattenGlyphList(std::vector<utf16> & vgidFlattened)
{
if (!m_fHasFlatList)
FlattenMyGlyphList();
for (size_t igid = 0; igid < m_vgidFlattened.size(); igid++)
{
vgidFlattened.push_back(m_vgidFlattened[igid]);
}
}
/*----------------------------------------------------------------------------------------------
Return true if there are duplicate glyphs in the class.
----------------------------------------------------------------------------------------------*/
bool GdlGlyphClassDefn::HasDuplicateGlyphs(utf16 * pgid) {
std::vector<utf16> vgidFlattened;
this->FlattenGlyphList(vgidFlattened);
for (size_t i = 0; i < vgidFlattened.size() - 1; i++)
{
for (size_t j = i+1; j < vgidFlattened.size(); j++)
{
if (vgidFlattened[i] == vgidFlattened[j])
{
*pgid = vgidFlattened[i];
return true;
}
}
}
//std::set<utf16> setgidNoDup;
//for (size_t i = 0; i < vgidFlattened.size(); i++) {
// setgidNoDup.insert(vgidFlattened[i]);
//}
//return (setgidNoDup.size() < vgidFlattened.size());
return false;
}
#if 0
/*----------------------------------------------------------------------------------------------
Set the directionality attribute.
----------------------------------------------------------------------------------------------*/
void GdlGlyphClassDefn::SetDirection(GdlExpression * pglfaDir, int nStmtNo, bool fAttrOverride)
{
if (m_pglfaDirection == NULL ||
(fAttrOverride && nStmtNo > m_pglfaDirection->LineNumber()))
{
m_pexpDirection = pglfaDir;
}
}
/*----------------------------------------------------------------------------------------------
Set the breakweight attribute.
----------------------------------------------------------------------------------------------*/
void GdlGlyphClassDefn::SetBreakweight(GdlExpression * pexpBw, int nStmtNo, bool fAttrOverride)
{
if (m_pexpBreakweight == NULL || (fAttrOverride && nStmtNo > m_nBwStmtNo))
m_pexpBreakweight = pexpBw;
}
#endif // 0
|