File: GrcGlyphAttrMatrix.cpp

package info (click to toggle)
grcompiler 5.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 24,020 kB
  • sloc: cpp: 48,200; ansic: 7,670; sh: 4,427; makefile: 197; xml: 190; perl: 127; sed: 21
file content (238 lines) | stat: -rw-r--r-- 9,012 bytes parent folder | download | duplicates (2)
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
/*--------------------------------------------------------------------*//*: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: GrcGlyphAttrMatrix.cpp
Responsibility: Sharon Correll
Last reviewed: Not yet.

Description:
    Implementation of classes that hold the glyph attribute assignments and ligature
	component assignments.
-------------------------------------------------------------------------------*//*: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
***********************************************************************************************/

/***********************************************************************************************
	Methods: GrcGlyphAttrMatrix
***********************************************************************************************/

/*----------------------------------------------------------------------------------------------
	Get the attribute setter information for the given glyph and attribute.
----------------------------------------------------------------------------------------------*/
void GrcGlyphAttrMatrix::Get(gid16 wGlyphID, int nAttrID, int nStyle,
	GdlExpression ** ppexp, int * pnPR, int * pmPrUnits, bool * pfOverride, bool * pfShadow,
	GrpLineAndFile * plnf)
{
	GrcAssignment * pasgnx = m_prgasgnx + Index(wGlyphID, nAttrID, nStyle);
	*ppexp = pasgnx->m_pexp;
	*pnPR = pasgnx->m_nPointRadius;
	*pmPrUnits = pasgnx->m_mPrUnits;
	*pfOverride = pasgnx->m_fOverride;
	*pfShadow = pasgnx->m_fShadow;
	*plnf = pasgnx->m_lnf;
}


/*----------------------------------------------------------------------------------------------
	Get the expression for the given glyph and attribute.
----------------------------------------------------------------------------------------------*/
GdlExpression * GrcGlyphAttrMatrix::GetExpression(gid16 wGlyphID, int nAttrID, int nStyle)
{
	GrcAssignment * pasgnx = m_prgasgnx + Index(wGlyphID, nAttrID, nStyle);
	return pasgnx->m_pexp;
}


/*----------------------------------------------------------------------------------------------
	Set the attribute setter information for the given glyph and attribute.
----------------------------------------------------------------------------------------------*/
void GrcGlyphAttrMatrix::Set(gid16 wGlyphID, int nAttrID, int nStyle,
	GdlExpression * pexp, int nPR, int mPrUnits, bool fOverride, bool fShadow,
	GrpLineAndFile const& lnf)
{
	GrcAssignment * pasgnx = m_prgasgnx + Index(wGlyphID, nAttrID, nStyle);

	pasgnx->m_pexp = pexp;
	pasgnx->m_nPointRadius = nPR;
	pasgnx->m_mPrUnits = mPrUnits;
	pasgnx->m_fOverride = fOverride;
	pasgnx->m_fShadow = fShadow;
	pasgnx->m_lnf = lnf;
}


/*----------------------------------------------------------------------------------------------
	Clear a superfluous attribute for the given glyph (eg, gpoint, when x and y are defined).
----------------------------------------------------------------------------------------------*/
void GrcGlyphAttrMatrix::Clear(gid16 wGlyphID, int nAttrID, int nStyle)
{
	GrcAssignment * pasgnx = m_prgasgnx + Index(wGlyphID, nAttrID, nStyle);

	pasgnx->m_pexp = NULL;
}


/*----------------------------------------------------------------------------------------------
	Test whether a 'gpoint' attribute as a legitmate value. Should only be called for
	gpoint attributes.
	Currently not really needed, because we're using 0 as the "unset" value just like all
	the other attributes.
----------------------------------------------------------------------------------------------*/
bool GrcGlyphAttrMatrix::GpointDefined(gid16 wGlyphID, int nAttrID, int nStyle)
{
	// This is a bit of a kludge. When OffsetAttrs() is off, the superfluous attributes like
	// gpoint and xoffset and yoffset don't get assigned attribute IDs. But in an obscure case,
	// the symbol may exist and there is an attempt to read it, which crashes because the
	// ID is invalid. (This can happen when xyz.gpoint is defined on one class and xyz.x/y
	// are defined on another.) So we set the index to a recognizable invalid value.
	// See AssignInternalGlyphAttrIDs().
	if (nAttrID == kInvalid)
		return false;

	return Defined(wGlyphID, nAttrID, nStyle);

//	if (!Defined(wGlyphID, nAttrID, nStyle))
//		return false;
//	GrcAssignment * pasgnx = m_prgasgnx + Index(wGlyphID, nAttrID, nStyle);
//	GdlExpression * pexp = pasgnx->Expression();
//	if (pexp == NULL)
//		return false;
//	int n;
//	if (!pexp->ResolveToInteger(&n, false))
//		return true;
//	if (n == kGpointNotSet)
//		return false;
//	return true;

}		


/***********************************************************************************************
	Methods: GrcLigComponentList
***********************************************************************************************/

/*----------------------------------------------------------------------------------------------
	Constructor.
----------------------------------------------------------------------------------------------*/
GrcLigComponentList::GrcLigComponentList(size_t cvGlyphIDs)
: m_vgplcmap(cvGlyphIDs)
{
}


/*----------------------------------------------------------------------------------------------
	Destructor.
----------------------------------------------------------------------------------------------*/
GrcLigComponentList::~GrcLigComponentList()
{
	for (auto plcmgap: m_vgplcmap)
		delete plcmgap;
}


/*----------------------------------------------------------------------------------------------
	Add a ligature component to the glyph's list, if it is not already there.
	Return the internal ID.
----------------------------------------------------------------------------------------------*/
int GrcLigComponentList::AddComponentFor(gid16 wGlyphID, Symbol psymComponent,
	GdlRenderer * prndr)
{
	Assert(psymComponent->IsGeneric());

	int nID = psymComponent->InternalID();

	if (FindComponentFor(wGlyphID, nID)) // creates a LigCompMap if necessary
		// already defined for this ligature
		return nID;

	//	Add the internal ID to the list of components for this glyph.
	LigCompMap * plcmap = m_vgplcmap[wGlyphID];
	plcmap->m_vinIDs.push_back(nID);

	int cComp = signed(plcmap->m_vinIDs.size());
	prndr->SetNumLigComponents(cComp);

	return nID;
}


/*----------------------------------------------------------------------------------------------
	If the ligature component with the given ID has been defined for the given glyph,
	return true. Ensure that a LigCompMap is in place for the given glyph.
----------------------------------------------------------------------------------------------*/
bool GrcLigComponentList::FindComponentFor(gid16 wGlyphID, int nID)
{
	LigCompMap * plcmap = m_vgplcmap[wGlyphID];
	if (!plcmap)
	{
		plcmap = new LigCompMap();
		m_vgplcmap[wGlyphID] = plcmap;
	}

	for (size_t in = 0; in < plcmap->m_vinIDs.size(); in++)
	{
		if (plcmap->m_vinIDs[in] == nID)
			return true;
	}

	return false;
}


//	Methods below are OBSOLETE--the defined-components list is now part of the
//	glyph attribute list.

/*----------------------------------------------------------------------------------------------
	Add the given symbol to the global list of defined ligature components, if it is
	not already there. Return the internal ID.
----------------------------------------------------------------------------------------------*/
//int GrcLigComponentList::AddComponent(Symbol psymComponent)
//{
//	Assert(psymComponent->IsGeneric());
//	int nID = FindComponentID(psymComponent);
//	if (nID == -1)
//	{
//		nID = m_vpsymDefinedComponents.Size();
//		m_vpsymDefinedComponents.Push(psymComponent);
//	}
//	return nID;
//}


/*----------------------------------------------------------------------------------------------
	Return the internal ID for the given ligature component, or -1 if it is
	not present (has never been defined for any glyph).
----------------------------------------------------------------------------------------------*/
//int GrcLigComponentList::FindComponentID(Symbol psymComponent)
//{
//	Assert(psymComponent->IsGeneric());
//	for (int inID = 0;
//		inID < m_vpsymDefinedComponents.Size();
//		inID++)
//	{
//		if (m_vpsymDefinedComponents[inID] == psymComponent)
//			return inID;
//	}
//	return -1;
//}