Skip to content

Commit a984752

Browse files
committed
Optimized glyph application operation...
1 parent 341f761 commit a984752

8 files changed

+129
-149
lines changed

Source/SFGlyphManipulation.c

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ typedef struct {
4949

5050
typedef SFBoolean (*_SFGlyphAssessment)(_SFGlyphAgent *glyphAgent);
5151

52-
static SFBoolean _SFApplyRuleSetTable(SFTextProcessorRef textProcessor, SFFeatureKind featureKind,
52+
static SFBoolean _SFApplyRuleSetTable(SFTextProcessorRef textProcessor,
5353
SFData ruleSetTable, _SFGlyphAssessment glyphAsessment, void *helperPtr);
54-
static SFBoolean _SFApplyRuleTable(SFTextProcessorRef textProcessor, SFFeatureKind featureKind,
54+
static SFBoolean _SFApplyRuleTable(SFTextProcessorRef textProcessor,
5555
SFData ruleTable, SFBoolean includeFirst, _SFGlyphAssessment glyphAsessment, void *helperPtr);
5656

57-
static SFBoolean _SFApplyChainRuleSetTable(SFTextProcessorRef textProcessor, SFFeatureKind featureKind,
57+
static SFBoolean _SFApplyChainRuleSetTable(SFTextProcessorRef textProcessor,
5858
SFData chainRuleSetTable, _SFGlyphAssessment glyphAsessment, void *helperPtr);
59-
static SFBoolean _SFApplyChainRuleTable(SFTextProcessorRef textProcessor, SFFeatureKind featureKind,
59+
static SFBoolean _SFApplyChainRuleTable(SFTextProcessorRef textProcessor,
6060
SFData chainRuleTable, SFBoolean includeFirst, _SFGlyphAssessment glyphAsessment, void *helperPtr);
6161

62-
static SFBoolean _SFApplyContextLookups(SFTextProcessorRef textProcessor, SFFeatureKind featureKind,
62+
static SFBoolean _SFApplyContextLookups(SFTextProcessorRef textProcessor,
6363
SFData lookupArray, SFUInteger lookupCount, SFUInteger contextStart, SFUInteger contextEnd);
6464

6565
static SFBoolean _SFAssessGlyphByEquality(_SFGlyphAgent *glyphAgent)
@@ -209,7 +209,7 @@ static SFBoolean _SFAssessLookaheadGlyphs(SFTextProcessorRef textProcessor,
209209
return SFTrue;
210210
}
211211

212-
SF_PRIVATE SFBoolean _SFApplyContextSubtable(SFTextProcessorRef processor, SFFeatureKind featureKind, SFData contextSubtable)
212+
SF_PRIVATE SFBoolean _SFApplyContextSubtable(SFTextProcessorRef processor, SFData contextSubtable)
213213
{
214214
SFAlbumRef album = processor->_album;
215215
SFLocatorRef locator = &processor->_locator;
@@ -233,7 +233,7 @@ SF_PRIVATE SFBoolean _SFApplyContextSubtable(SFTextProcessorRef processor, SFFea
233233
SFOffset ruleSetOffset = SFContextF1_RuleSetOffset(contextSubtable, coverageIndex);
234234
SFData ruleSetTable = SFData_Subdata(contextSubtable, ruleSetOffset);
235235

236-
return _SFApplyRuleSetTable(processor, featureKind, ruleSetTable, _SFAssessGlyphByEquality, NULL);
236+
return _SFApplyRuleSetTable(processor, ruleSetTable, _SFAssessGlyphByEquality, NULL);
237237
}
238238
}
239239
break;
@@ -261,22 +261,22 @@ SF_PRIVATE SFBoolean _SFApplyContextSubtable(SFTextProcessorRef processor, SFFea
261261

262262
helperTables[0] = classDefTable;
263263

264-
return _SFApplyRuleSetTable(processor, featureKind, ruleSetTable, _SFAssessGlyphByClass, helperTables);
264+
return _SFApplyRuleSetTable(processor, ruleSetTable, _SFAssessGlyphByClass, helperTables);
265265
}
266266
}
267267
break;
268268
}
269269

270270
case 3: {
271271
SFData ruleTable = SFContextF3_Rule(contextSubtable);
272-
return _SFApplyRuleTable(processor, featureKind, ruleTable, SFTrue, _SFAssessGlyphByCoverage, (void *)contextSubtable);
272+
return _SFApplyRuleTable(processor, ruleTable, SFTrue, _SFAssessGlyphByCoverage, (void *)contextSubtable);
273273
}
274274
}
275275

276276
return SFFalse;
277277
}
278278

279-
static SFBoolean _SFApplyRuleSetTable(SFTextProcessorRef textProcessor, SFFeatureKind featureKind,
279+
static SFBoolean _SFApplyRuleSetTable(SFTextProcessorRef textProcessor,
280280
SFData ruleSetTable, _SFGlyphAssessment glyphAsessment, void *helperPtr)
281281
{
282282
SFUInt16 ruleCount = SFRuleSet_RuleCount(ruleSetTable);
@@ -289,7 +289,7 @@ static SFBoolean _SFApplyRuleSetTable(SFTextProcessorRef textProcessor, SFFeatur
289289
if (ruleOffset) {
290290
SFData ruleTable = SFData_Subdata(ruleSetTable, ruleOffset);
291291

292-
if (_SFApplyRuleTable(textProcessor, featureKind, ruleTable, SFFalse, glyphAsessment, helperPtr)) {
292+
if (_SFApplyRuleTable(textProcessor, ruleTable, SFFalse, glyphAsessment, helperPtr)) {
293293
return SFTrue;
294294
}
295295
}
@@ -298,7 +298,7 @@ static SFBoolean _SFApplyRuleSetTable(SFTextProcessorRef textProcessor, SFFeatur
298298
return SFFalse;
299299
}
300300

301-
static SFBoolean _SFApplyRuleTable(SFTextProcessorRef textProcessor, SFFeatureKind featureKind,
301+
static SFBoolean _SFApplyRuleTable(SFTextProcessorRef textProcessor,
302302
SFData ruleTable, SFBoolean includeFirst, _SFGlyphAssessment glyphAsessment, void *helperPtr)
303303
{
304304
SFUInt16 glyphCount = SFRule_GlyphCount(ruleTable);
@@ -312,14 +312,14 @@ static SFBoolean _SFApplyRuleTable(SFTextProcessorRef textProcessor, SFFeatureKi
312312
SFUInteger contextEnd;
313313

314314
return (_SFAssessInputGlyphs(textProcessor, valueArray, glyphCount, includeFirst, glyphAsessment, helperPtr, &contextEnd)
315-
&& _SFApplyContextLookups(textProcessor, featureKind, lookupArray, lookupCount, contextStart, contextEnd));
315+
&& _SFApplyContextLookups(textProcessor, lookupArray, lookupCount, contextStart, contextEnd));
316316
}
317317

318318
return SFFalse;
319319
}
320320

321321
SF_PRIVATE SFBoolean _SFApplyChainContextSubtable(SFTextProcessorRef textProcessor,
322-
SFFeatureKind featureKind, SFData chainContextSubtable)
322+
SFData chainContextSubtable)
323323
{
324324
SFGlyphID inputGlyph = SFAlbumGetGlyph(textProcessor->_album, textProcessor->_locator.index);
325325
SFUInt16 format;
@@ -341,7 +341,7 @@ SF_PRIVATE SFBoolean _SFApplyChainContextSubtable(SFTextProcessorRef textProcess
341341
SFOffset chainRuleSetOffset = SFChainContextF1_ChainRuleSetOffset(chainContextSubtable, coverageIndex);
342342
SFData chainRuleSetTable = SFData_Subdata(chainContextSubtable, chainRuleSetOffset);
343343

344-
return _SFApplyChainRuleSetTable(textProcessor, featureKind, chainRuleSetTable, _SFAssessGlyphByEquality, NULL);
344+
return _SFApplyChainRuleSetTable(textProcessor, chainRuleSetTable, _SFAssessGlyphByEquality, NULL);
345345
}
346346
}
347347
break;
@@ -375,22 +375,22 @@ SF_PRIVATE SFBoolean _SFApplyChainContextSubtable(SFTextProcessorRef textProcess
375375
helperTables[1] = backtrackClassDefTable;
376376
helperTables[2] = lookaheadClassDefTable;
377377

378-
return _SFApplyChainRuleSetTable(textProcessor, featureKind, chainRuleSetTable, _SFAssessGlyphByClass, helperTables);
378+
return _SFApplyChainRuleSetTable(textProcessor, chainRuleSetTable, _SFAssessGlyphByClass, helperTables);
379379
}
380380
}
381381
break;
382382
}
383383

384384
case 3: {
385385
SFData chainRuleTable = SFChainContextF3_ChainRule(chainContextSubtable);
386-
return _SFApplyChainRuleTable(textProcessor, featureKind, chainRuleTable, SFTrue, _SFAssessGlyphByCoverage, (void *)chainContextSubtable);
386+
return _SFApplyChainRuleTable(textProcessor, chainRuleTable, SFTrue, _SFAssessGlyphByCoverage, (void *)chainContextSubtable);
387387
}
388388
}
389389

390390
return SFFalse;
391391
}
392392

393-
static SFBoolean _SFApplyChainRuleSetTable(SFTextProcessorRef textProcessor, SFFeatureKind featureKind,
393+
static SFBoolean _SFApplyChainRuleSetTable(SFTextProcessorRef textProcessor,
394394
SFData chainRuleSetTable, _SFGlyphAssessment glyphAsessment, void *helperPtr)
395395
{
396396
SFUInt16 chainRuleCount = SFChainRuleSet_ChainRuleCount(chainRuleSetTable);
@@ -401,15 +401,15 @@ static SFBoolean _SFApplyChainRuleSetTable(SFTextProcessorRef textProcessor, SFF
401401
SFOffset chainRuleOffset = SFChainRuleSet_ChainRuleOffset(chainRuleSetTable, chainRuleIndex);
402402
SFData chainRuleTable = SFData_Subdata(chainRuleSetTable, chainRuleOffset);
403403

404-
if (_SFApplyChainRuleTable(textProcessor, featureKind, chainRuleTable, SFFalse, glyphAsessment, helperPtr)) {
404+
if (_SFApplyChainRuleTable(textProcessor, chainRuleTable, SFFalse, glyphAsessment, helperPtr)) {
405405
return SFTrue;
406406
}
407407
}
408408

409409
return SFFalse;
410410
}
411411

412-
static SFBoolean _SFApplyChainRuleTable(SFTextProcessorRef textProcessor, SFFeatureKind featureKind,
412+
static SFBoolean _SFApplyChainRuleTable(SFTextProcessorRef textProcessor,
413413
SFData chainRuleTable, SFBoolean includeFirst, _SFGlyphAssessment glyphAsessment, void *helperPtr)
414414
{
415415
SFData backtrackRecord = SFChainRule_BacktrackRecord(chainRuleTable);
@@ -433,13 +433,13 @@ static SFBoolean _SFApplyChainRuleTable(SFTextProcessorRef textProcessor, SFFeat
433433
return (_SFAssessInputGlyphs(textProcessor, inputArray, inputCount, includeFirst, glyphAsessment, helperPtr, &contextEnd)
434434
&& _SFAssessBacktrackGlyphs(textProcessor, backtrackArray, backtrackCount,glyphAsessment, helperPtr)
435435
&& _SFAssessLookaheadGlyphs(textProcessor, lookaheadArray, lookaheadCount, glyphAsessment, helperPtr, contextEnd)
436-
&& _SFApplyContextLookups(textProcessor, featureKind, lookupArray, lookupCount, contextStart, contextEnd));
436+
&& _SFApplyContextLookups(textProcessor, lookupArray, lookupCount, contextStart, contextEnd));
437437
}
438438

439439
return SFFalse;
440440
}
441441

442-
static SFBoolean _SFApplyContextLookups(SFTextProcessorRef textProcessor, SFFeatureKind featureKind,
442+
static SFBoolean _SFApplyContextLookups(SFTextProcessorRef textProcessor,
443443
SFData lookupArray, SFUInteger lookupCount, SFUInteger contextStart, SFUInteger contextEnd)
444444
{
445445
SFLocatorRef contextLocator = &textProcessor->_locator;
@@ -461,7 +461,7 @@ static SFBoolean _SFApplyContextLookups(SFTextProcessorRef textProcessor, SFFeat
461461
if (SFLocatorMoveNext(contextLocator)) {
462462
/* Skip the glyphs till sequence index and apply the lookup. */
463463
if (SFLocatorSkip(contextLocator, sequenceIndex)) {
464-
_SFApplyLookup(textProcessor, featureKind, lookupListIndex);
464+
_SFApplyLookup(textProcessor, lookupListIndex);
465465
}
466466
}
467467
}
@@ -475,7 +475,7 @@ static SFBoolean _SFApplyContextLookups(SFTextProcessorRef textProcessor, SFFeat
475475
}
476476

477477
SF_PRIVATE SFBoolean _SFApplyExtensionSubtable(SFTextProcessorRef textProcessor,
478-
SFFeatureKind featureKind, SFData extensionSubtable)
478+
SFData extensionSubtable)
479479
{
480480
SFUInt16 format = SFExtension_Format(extensionSubtable);
481481

@@ -485,14 +485,7 @@ SF_PRIVATE SFBoolean _SFApplyExtensionSubtable(SFTextProcessorRef textProcessor,
485485
SFUInt32 extensionOffset = SFExtensionF1_ExtensionOffset(extensionSubtable);
486486
SFData innerSubtable = SFData_Subdata(extensionSubtable, extensionOffset);
487487

488-
switch (featureKind) {
489-
case SFFeatureKindSubstitution:
490-
return _SFApplySubstitutionSubtable(textProcessor, lookupType, innerSubtable);
491-
492-
case SFFeatureKindPositioning:
493-
return _SFApplyPositioningSubtable(textProcessor, lookupType, innerSubtable);
494-
}
495-
break;
488+
return textProcessor->_lookupOperation(textProcessor, lookupType, innerSubtable);
496489
}
497490
}
498491

Source/SFGlyphManipulation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include "SFPattern.h"
2424
#include "SFTextProcessor.h"
2525

26-
SF_PRIVATE SFBoolean _SFApplyContextSubtable(SFTextProcessorRef textProcessor, SFFeatureKind featureKind, SFData contextSubtable);
27-
SF_PRIVATE SFBoolean _SFApplyChainContextSubtable(SFTextProcessorRef textProcessor, SFFeatureKind featureKind, SFData chainContextSubtable);
28-
SF_PRIVATE SFBoolean _SFApplyExtensionSubtable(SFTextProcessorRef textProcessor, SFFeatureKind featureKind, SFData extensionSubtable);
26+
SF_PRIVATE SFBoolean _SFApplyContextSubtable(SFTextProcessorRef textProcessor, SFData contextSubtable);
27+
SF_PRIVATE SFBoolean _SFApplyChainContextSubtable(SFTextProcessorRef textProcessor, SFData chainContextSubtable);
28+
SF_PRIVATE SFBoolean _SFApplyExtensionSubtable(SFTextProcessorRef textProcessor, SFData extensionSubtable);
2929

3030
#endif

Source/SFGlyphPositioning.c

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,35 +67,6 @@ static void _SFResolveRightCursiveSegment(SFTextProcessorRef textProcessor, SFUI
6767
static void _SFResolveCursivePositions(SFTextProcessorRef textProcessor, SFLocatorRef locator);
6868
static void _SFResolveMarkPositions(SFTextProcessorRef textProcessor, SFLocatorRef locator);
6969

70-
SF_PRIVATE void _SFApplyPositioningLookup(SFTextProcessorRef textProcessor, SFData lookupTable)
71-
{
72-
SFLookupType lookupType = SFLookup_LookupType(lookupTable);
73-
SFLookupFlag lookupFlag = SFLookup_LookupFlag(lookupTable);
74-
SFUInt16 subtableCount = SFLookup_SubtableCount(lookupTable);
75-
SFUInteger subtableIndex;
76-
77-
SFLocatorSetLookupFlag(&textProcessor->_locator, lookupFlag);
78-
79-
if (lookupFlag & SFLookupFlagUseMarkFilteringSet) {
80-
SFUInt16 markFilteringSet = SFLookup_MarkFilteringSet(lookupTable, subtableCount);
81-
SFLocatorSetMarkFilteringSet(&textProcessor->_locator, markFilteringSet);
82-
}
83-
84-
/* Apply subtables in order until one of them performs positioning. */
85-
for (subtableIndex = 0; subtableIndex < subtableCount; subtableIndex++) {
86-
SFOffset subtableOffset = SFLookup_SubtableOffset(lookupTable, subtableIndex);
87-
SFData subtable = SFData_Subdata(lookupTable, subtableOffset);
88-
SFBoolean didPosition;
89-
90-
didPosition = _SFApplyPositioningSubtable(textProcessor, lookupType, subtable);
91-
92-
/* A subtable has performed positioning, so break the loop. */
93-
if (didPosition) {
94-
break;
95-
}
96-
}
97-
}
98-
9970
SF_PRIVATE SFBoolean _SFApplyPositioningSubtable(SFTextProcessorRef textProcessor, SFLookupType lookupType, SFData subtable)
10071
{
10172
switch (lookupType) {
@@ -118,13 +89,13 @@ SF_PRIVATE SFBoolean _SFApplyPositioningSubtable(SFTextProcessorRef textProcesso
11889
return _SFApplyMarkToMarkPos(textProcessor, subtable);
11990

12091
case SFLookupTypeContextPositioning:
121-
return _SFApplyContextSubtable(textProcessor, SFFeatureKindPositioning, subtable);
92+
return _SFApplyContextSubtable(textProcessor, subtable);
12293

12394
case SFLookupTypeChainedContextPositioning:
124-
return _SFApplyChainContextSubtable(textProcessor, SFFeatureKindPositioning, subtable);
95+
return _SFApplyChainContextSubtable(textProcessor, subtable);
12596

12697
case SFLookupTypeExtensionPositioning:
127-
return _SFApplyExtensionSubtable(textProcessor, SFFeatureKindPositioning, subtable);
98+
return _SFApplyExtensionSubtable(textProcessor, subtable);
12899
}
129100

130101
return SFFalse;

Source/SFGlyphPositioning.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
#include <SFConfig.h>
2121

2222
#include "SFBase.h"
23+
#include "SFCommon.h"
2324
#include "SFData.h"
2425
#include "SFTextProcessor.h"
2526

26-
SF_PRIVATE void _SFApplyPositioningLookup(SFTextProcessorRef textProcessor, SFData lookupTable);
2727
SF_PRIVATE SFBoolean _SFApplyPositioningSubtable(SFTextProcessorRef textProcessor, SFLookupType lookupType, SFData subtable);
28-
2928
SF_PRIVATE void _SFResolveAttachments(SFTextProcessorRef textProcessor);
3029

3130
#endif

Source/SFGlyphSubstitution.c

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,6 @@ static SFBoolean _SFApplySequenceTable(SFTextProcessorRef textProcessor, SFData
3737
static SFBoolean _SFApplyLigatureSubst(SFTextProcessorRef textProcessor, SFData subtable);
3838
static SFBoolean _SFApplyLigatureSetTable(SFTextProcessorRef textProcessor, SFData ligatureSetTable);
3939

40-
SF_PRIVATE void _SFApplySubstitutionLookup(SFTextProcessorRef textProcessor, SFData lookupTable)
41-
{
42-
SFLookupType lookupType = SFLookup_LookupType(lookupTable);
43-
SFLookupFlag lookupFlag = SFLookup_LookupFlag(lookupTable);
44-
SFUInt16 subtableCount = SFLookup_SubtableCount(lookupTable);
45-
SFUInt16 subtableIndex;
46-
47-
SFLocatorSetLookupFlag(&textProcessor->_locator, lookupFlag);
48-
49-
if (lookupFlag & SFLookupFlagUseMarkFilteringSet) {
50-
SFUInt16 markFilteringSet = SFLookup_MarkFilteringSet(lookupTable, subtableCount);
51-
SFLocatorSetMarkFilteringSet(&textProcessor->_locator, markFilteringSet);
52-
}
53-
54-
/* Apply subtables in order until one of them performs substitution. */
55-
for (subtableIndex = 0; subtableIndex < subtableCount; subtableIndex++) {
56-
SFOffset offset = SFLookup_SubtableOffset(lookupTable, subtableIndex);
57-
SFData subtable = SFData_Subdata(lookupTable, offset);
58-
SFBoolean didSubstitute;
59-
60-
didSubstitute = _SFApplySubstitutionSubtable(textProcessor, lookupType, subtable);
61-
62-
/* A subtable has performed substition, so break the loop. */
63-
if (didSubstitute) {
64-
break;
65-
}
66-
}
67-
}
68-
6940
SF_PRIVATE SFBoolean _SFApplySubstitutionSubtable(SFTextProcessorRef textProcessor, SFLookupType lookupType, SFData subtable)
7041
{
7142
switch (lookupType) {
@@ -82,13 +53,13 @@ SF_PRIVATE SFBoolean _SFApplySubstitutionSubtable(SFTextProcessorRef textProcess
8253
return _SFApplyLigatureSubst(textProcessor, subtable);
8354

8455
case SFLookupTypeContext:
85-
return _SFApplyContextSubtable(textProcessor, SFFeatureKindSubstitution, subtable);
56+
return _SFApplyContextSubtable(textProcessor, subtable);
8657

8758
case SFLookupTypeChainingContext:
88-
return _SFApplyChainContextSubtable(textProcessor, SFFeatureKindSubstitution, subtable);
59+
return _SFApplyChainContextSubtable(textProcessor, subtable);
8960

9061
case SFLookupTypeExtension:
91-
return _SFApplyExtensionSubtable(textProcessor, SFFeatureKindSubstitution, subtable);
62+
return _SFApplyExtensionSubtable(textProcessor, subtable);
9263

9364
case SFLookupTypeReverseChainingContext:
9465
break;

Source/SFGlyphSubstitution.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#include <SFConfig.h>
2121

2222
#include "SFBase.h"
23+
#include "SFCommon.h"
2324
#include "SFData.h"
2425
#include "SFTextProcessor.h"
2526

26-
SF_PRIVATE void _SFApplySubstitutionLookup(SFTextProcessorRef textProcessor, SFData lookupTable);
2727
SF_PRIVATE SFBoolean _SFApplySubstitutionSubtable(SFTextProcessorRef textProcessor, SFLookupType lookupType, SFData subtable);
2828

2929
#endif

0 commit comments

Comments
 (0)