Skip to content

Commit

Permalink
Added support for character level mirroring...
Browse files Browse the repository at this point in the history
  • Loading branch information
mta452 committed May 9, 2017
1 parent b96f4a9 commit a178c1a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
28 changes: 23 additions & 5 deletions Source/SFCodepoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,48 @@
* limitations under the License.
*/

#include <SBBase.h>
#include <SBCodepointSequence.h>
#include <SFConfig.h>
#include <stddef.h>

#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;
}
7 changes: 5 additions & 2 deletions Source/SFCodepoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@
#ifndef _SF_INTERNAL_CODEPOINTS_H
#define _SF_INTERNAL_CODEPOINTS_H

#include <SFConfig.h>
#include <SBCodepointSequence.h>
#include <SFConfig.h>

#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);
Expand Down
19 changes: 4 additions & 15 deletions Source/SFGlyphDiscovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a178c1a

Please sign in to comment.