diff --git a/render.py b/render.py
index d62d510..ec886a7 100644
--- a/render.py
+++ b/render.py
@@ -1,15 +1,14 @@
-import json
+
import math
import os
-import StringIO
+import io
import subprocess
-import tempfile
import time
-import cairo
+import cairocffi as cairo
import flask
-import pango
-import pangocairo
+import pangocffi as pango
+import pangocairocffi as pangocairo
class App(flask.Flask):
def __init__(self, *args, **kwargs):
@@ -50,26 +49,27 @@ class Renderer(object):
if y != -1:
self.context.translate(x, y)
- pangocairo_context = pangocairo.CairoContext(self.context)
- pangocairo_context.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
- layout = pangocairo_context.create_layout()
- layout.set_width(self.width*pango.SCALE)
- layout.set_alignment(pango.ALIGN_CENTER)
+ self.context.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
+ layout = pangocairo.create_layout(self.context)
+ layout.width = pango.units_from_double(self.width)
+ layout.alignment = pango.Alignment.CENTER
if html:
# Absolutely horrifying hack to fix broken text wrapping
- layout.set_markup('%s' % (fontname, text))
+ layout.apply_markup('%s' % (fontname, text))
else:
- font = pango.FontDescription(fontname)
- layout.set_font_description(font)
- layout.set_text(text)
+ font = pango.FontDescription()
+ font.family = "Sans"
+ font.size = 65
+ layout.font_description = font
+ layout.text = text
if y == -1:
- self.context.translate(0, (self.height - layout.get_size()[1]/pango.SCALE)/2)
+ self.context.translate(0, (self.height - pango.units_to_double(layout.get_size()[1]))/2)
self.context.set_source_rgb(0, 0, 0)
- pangocairo_context.update_layout(layout)
- pangocairo_context.show_layout(layout)
+ pangocairo.update_layout(self.context, layout)
+ pangocairo.show_layout(self.context, layout)
self.context.restore()
@@ -99,10 +99,12 @@ def healthcheck():
return False, line
mark = False
-@app.route('/health')
-def health():
- ok, details = healthcheck()
- return json.dumps({'ok': ok, 'details': details})
+# TODO: Uncomment and fix this
+
+# @app.route('/health')
+# def health():
+# ok, details = healthcheck()
+# return json.dumps({'ok': ok, 'details': details})
@app.route('/stuff/preview//')
def stuff_preview(size):
@@ -111,7 +113,7 @@ def stuff_preview(size):
r = Renderer()
r.render_text(text, 'Sans {}'.format(size), 0, -1, html)
- sio = StringIO.StringIO()
+ sio = io.BytesIO()
r.surface.write_to_png(sio)
sio.seek(0)
return flask.send_file(sio, mimetype='image/png')
@@ -122,7 +124,7 @@ def stuff_print(size):
if not healthcheck()[0]:
return 'Printer is down.'
last = app.last
- print last, time.time() - last
+ print(last, time.time() - last)
if time.time() - last < DELAY:
return 'Please wait {} more seconds before next print.'.format(int(DELAY - (time.time() - last)))
text = flask.request.args.get('text')