Skip to content

Commit a178c1a

Browse files
committed
Added support for character level mirroring...
1 parent b96f4a9 commit a178c1a

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

Source/SFCodepoints.c

+23-5
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,48 @@
1414
* limitations under the License.
1515
*/
1616

17+
#include <SBBase.h>
18+
#include <SBCodepointSequence.h>
1719
#include <SFConfig.h>
18-
#include <stddef.h>
1920

2021
#include "SFAssert.h"
2122
#include "SFBase.h"
2223
#include "SFCodepoints.h"
2324

25+
SF_INTERNAL SFCodepoint SFCodepointsGetMirror(SFCodepoint codepoint)
26+
{
27+
SFCodepoint mirror = SBCodepointGetMirror(codepoint);
28+
if (!mirror) {
29+
return codepoint;
30+
}
31+
32+
return mirror;
33+
}
34+
2435
SF_INTERNAL void SFCodepointsInitialize(SFCodepointsRef codepoints, const SBCodepointSequence *referral, SFBoolean backward)
2536
{
26-
codepoints->referral = referral;
37+
codepoints->_referral = referral;
38+
codepoints->_token = SFInvalidIndex;
2739
codepoints->index = SFInvalidIndex;
2840
codepoints->backward = backward;
2941
}
3042

3143
SF_INTERNAL void SFCodepointsReset(SFCodepointsRef codepoints)
3244
{
33-
codepoints->index = (!codepoints->backward ? 0 : codepoints->referral->stringLength);
45+
codepoints->_token = (!codepoints->backward ? 0 : codepoints->_referral->stringLength);
3446
}
3547

3648
SF_INTERNAL SFCodepoint SFCodepointsNext(SFCodepointsRef codepoints)
3749
{
50+
SFCodepoint current;
51+
3852
if (!codepoints->backward) {
39-
return SBCodepointSequenceGetCodepointAt(codepoints->referral, &codepoints->index);
53+
codepoints->index = codepoints->_token;
54+
current = SBCodepointSequenceGetCodepointAt(codepoints->_referral, &codepoints->_token);
55+
} else {
56+
current = SBCodepointSequenceGetCodepointBefore(codepoints->_referral, &codepoints->_token);
57+
codepoints->index = codepoints->_token;
4058
}
4159

42-
return SBCodepointSequenceGetCodepointBefore(codepoints->referral, &codepoints->index);
60+
return current;
4361
}

Source/SFCodepoints.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@
1717
#ifndef _SF_INTERNAL_CODEPOINTS_H
1818
#define _SF_INTERNAL_CODEPOINTS_H
1919

20-
#include <SFConfig.h>
2120
#include <SBCodepointSequence.h>
21+
#include <SFConfig.h>
2222

2323
#include "SFBase.h"
2424

2525
typedef struct _SFCodepoints {
26-
const SBCodepointSequence *referral;
26+
const SBCodepointSequence *_referral;
27+
SFUInteger _token;
2728
SFUInteger index;
2829
SFBoolean backward;
2930
} SFCodepoints, *SFCodepointsRef;
3031

32+
SF_INTERNAL SFCodepoint SFCodepointsGetMirror(SFCodepoint codepoint);
33+
3134
SF_INTERNAL void SFCodepointsInitialize(SFCodepointsRef codepoints, const SBCodepointSequence *referral, SFBoolean backward);
3235
SF_INTERNAL void SFCodepointsReset(SFCodepointsRef codepoints);
3336
SF_INTERNAL SFCodepoint SFCodepointsNext(SFCodepointsRef codepoints);

Source/SFGlyphDiscovery.c

+4-15
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,15 @@ SF_INTERNAL void _SFDiscoverGlyphs(SFTextProcessorRef processor)
6363
SFCodepointsReset(album->codepoints);
6464

6565
switch (processor->_textMode) {
66-
case SFTextModeForward: {
67-
SFUInteger initialIndex = codepoints->index;
68-
SFCodepoint current;
69-
70-
while ((current = SFCodepointsNext(codepoints)) != SFCodepointInvalid) {
71-
SFGlyphID glyph = SFFontGetGlyphIDForCodepoint(font, current);
72-
SFGlyphTraits traits = _SFGetGlyphTraits(processor, glyph);
73-
SFAlbumAddGlyph(album, glyph, traits, initialIndex);
74-
75-
initialIndex = codepoints->index;
76-
}
77-
break;
78-
}
79-
66+
case SFTextModeForward:
8067
case SFTextModeBackward: {
8168
SFCodepoint current;
8269

8370
while ((current = SFCodepointsNext(codepoints)) != SFCodepointInvalid) {
84-
SFGlyphID glyph = SFFontGetGlyphIDForCodepoint(font, current);
71+
SFCodepoint mirror = SFCodepointsGetMirror(current);
72+
SFGlyphID glyph = SFFontGetGlyphIDForCodepoint(font, mirror);
8573
SFGlyphTraits traits = _SFGetGlyphTraits(processor, glyph);
74+
8675
SFAlbumAddGlyph(album, glyph, traits, codepoints->index);
8776
}
8877
break;

0 commit comments

Comments
 (0)