[justify-demo] Fix for LTR typesetting
diff --git a/src/justify.py b/src/justify.py
index 1078965..deb11d1 100644
--- a/src/justify.py
+++ b/src/justify.py
@@ -116,13 +116,16 @@
         self._glyphs.append(info)
         self._positions.append(pos)
 
-    def draw(self, context, font):
+    def draw(self, context, font, direction):
         for info, pos in zip(self._glyphs, self._positions):
-            context.translate(-pos.x_advance, pos.y_advance)
+            if direction == hb.direction_t.RTL:
+                context.translate(-pos.x_advance, pos.y_advance)
             context.save()
             context.translate(pos.x_offset, pos.y_offset)
             hb.font_paint_glyph(font, info.codepoint, PFUNCS, id(context), 0, 0x0000FF)
             context.restore()
+            if direction != hb.direction_t.RTL:
+                context.translate(+pos.x_advance, pos.y_advance)
 
     @property
     def advance(self):
@@ -199,7 +202,7 @@
 
         return True
 
-    def draw(self, context):
+    def draw(self, context, direction):
         context.save()
         context.move_to(-1600, -200)
         context.set_font_size(130)
@@ -215,9 +218,10 @@
             hb.font_set_variations(self._font, [self._variation])
 
         context.scale(1, -1)
-        context.translate(self._target_advance, 0)
+        if direction == hb.direction_t.RTL:
+            context.translate(self._target_advance, 0)
         for word in self._words:
-            word.draw(context, self._font)
+            word.draw(context, self._font, direction)
 
     @property
     def advance(self):
@@ -258,7 +262,8 @@
 
 
 def makewords(buf, font, text):
-    hb.buffer_reverse(buf)
+    if hb.buffer_get_direction(buf) == hb.direction_t.RTL:
+        hb.buffer_reverse(buf)
     words = [Word(font, text)]
     infos = hb.buffer_get_glyph_infos(buf)
     positions = hb.buffer_get_glyph_positions(buf)
@@ -282,6 +287,7 @@
     target_advance = (conf.width - (margin * 2)) / scale
 
     buf, text = makebuffer(text)
+    direction = hb.buffer_get_direction(buf)
 
     hb.shape(font, buf)
 
@@ -305,11 +311,11 @@
     if lines[-1].advance != target_advance:
         lines[-1].justify()
 
-    return lines, font
+    return lines, font, direction
 
 
 def render(context, conf):
-    lines, font = typeset(conf)
+    lines, font, direction = typeset(conf)
 
     margin = conf.fontsize * 2
     scale = conf.fontsize / hb.face_get_upem(hb.font_get_face(font))
@@ -326,7 +332,7 @@
         context.save()
         context.translate(margin, 0)
         context.scale(scale, scale)
-        line.draw(context)
+        line.draw(context, direction)
         context.restore()
     context.restore()