diff --git a/Source/SFCodepoints.c b/Source/SFCodepoints.c index 52f177e..d1b4632 100644 --- a/Source/SFCodepoints.c +++ b/Source/SFCodepoints.c @@ -14,30 +14,48 @@ * limitations under the License. */ +#include +#include #include -#include #include "SFAssert.h" #include "SFBase.h" #include "SFCodepoints.h" +SF_INTERNAL SFCodepoint SFCodepointsGetMirror(SFCodepoint codepoint) +{ + SFCodepoint mirror = SBCodepointGetMirror(codepoint); + if (!mirror) { + return codepoint; + } + + return mirror; +} + SF_INTERNAL void SFCodepointsInitialize(SFCodepointsRef codepoints, const SBCodepointSequence *referral, SFBoolean backward) { - codepoints->referral = referral; + codepoints->_referral = referral; + codepoints->_token = SFInvalidIndex; codepoints->index = SFInvalidIndex; codepoints->backward = backward; } SF_INTERNAL void SFCodepointsReset(SFCodepointsRef codepoints) { - codepoints->index = (!codepoints->backward ? 0 : codepoints->referral->stringLength); + codepoints->_token = (!codepoints->backward ? 0 : codepoints->_referral->stringLength); } SF_INTERNAL SFCodepoint SFCodepointsNext(SFCodepointsRef codepoints) { + SFCodepoint current; + if (!codepoints->backward) { - return SBCodepointSequenceGetCodepointAt(codepoints->referral, &codepoints->index); + codepoints->index = codepoints->_token; + current = SBCodepointSequenceGetCodepointAt(codepoints->_referral, &codepoints->_token); + } else { + current = SBCodepointSequenceGetCodepointBefore(codepoints->_referral, &codepoints->_token); + codepoints->index = codepoints->_token; } - return SBCodepointSequenceGetCodepointBefore(codepoints->referral, &codepoints->index); + return current; } diff --git a/Source/SFCodepoints.h b/Source/SFCodepoints.h index fef45b6..e85b3bf 100644 --- a/Source/SFCodepoints.h +++ b/Source/SFCodepoints.h @@ -17,17 +17,20 @@ #ifndef _SF_INTERNAL_CODEPOINTS_H #define _SF_INTERNAL_CODEPOINTS_H -#include #include +#include #include "SFBase.h" typedef struct _SFCodepoints { - const SBCodepointSequence *referral; + const SBCodepointSequence *_referral; + SFUInteger _token; SFUInteger index; SFBoolean backward; } SFCodepoints, *SFCodepointsRef; +SF_INTERNAL SFCodepoint SFCodepointsGetMirror(SFCodepoint codepoint); + SF_INTERNAL void SFCodepointsInitialize(SFCodepointsRef codepoints, const SBCodepointSequence *referral, SFBoolean backward); SF_INTERNAL void SFCodepointsReset(SFCodepointsRef codepoints); SF_INTERNAL SFCodepoint SFCodepointsNext(SFCodepointsRef codepoints); diff --git a/Source/SFGlyphDiscovery.c b/Source/SFGlyphDiscovery.c index e5768c6..2f5d380 100644 --- a/Source/SFGlyphDiscovery.c +++ b/Source/SFGlyphDiscovery.c @@ -63,26 +63,15 @@ SF_INTERNAL void _SFDiscoverGlyphs(SFTextProcessorRef processor) SFCodepointsReset(album->codepoints); switch (processor->_textMode) { - case SFTextModeForward: { - SFUInteger initialIndex = codepoints->index; - SFCodepoint current; - - while ((current = SFCodepointsNext(codepoints)) != SFCodepointInvalid) { - SFGlyphID glyph = SFFontGetGlyphIDForCodepoint(font, current); - SFGlyphTraits traits = _SFGetGlyphTraits(processor, glyph); - SFAlbumAddGlyph(album, glyph, traits, initialIndex); - - initialIndex = codepoints->index; - } - break; - } - + case SFTextModeForward: case SFTextModeBackward: { SFCodepoint current; while ((current = SFCodepointsNext(codepoints)) != SFCodepointInvalid) { - SFGlyphID glyph = SFFontGetGlyphIDForCodepoint(font, current); + SFCodepoint mirror = SFCodepointsGetMirror(current); + SFGlyphID glyph = SFFontGetGlyphIDForCodepoint(font, mirror); SFGlyphTraits traits = _SFGetGlyphTraits(processor, glyph); + SFAlbumAddGlyph(album, glyph, traits, codepoints->index); } break;