1
0
Fork 0

Compare commits

...

5 Commits

3 changed files with 20 additions and 14 deletions

View File

@ -27,6 +27,9 @@ RUN apt-get update && apt-get upgrade -y \
libpq-dev \
libpango-1.0.0 \
libpangocairo-1.0.0 \
# Installing Japaneese fonts (because it's fun)
fonts-noto-cjk \
fonts-vlgothic \
# Installing `poetry`:
&& curl -sSL 'https://install.python-poetry.org' | python - \

View File

@ -48,8 +48,8 @@ class Renderer(object):
context.paint()
return new_surface.write_to_png()
def render_text(self, text, fontname, x, y, html=False):
print("Fontname:", fontname)
def render_text(self, text, fontname, size, x, y, html=False):
print(f"Fontname: {fontname} {size}")
self.context.save()
if y != -1:
self.context.translate(x, y)
@ -59,10 +59,10 @@ class Renderer(object):
layout._set_alignment(pango.Alignment.CENTER)
if html:
# Absolutely horrifying hack to fix broken text wrapping
layout.apply_markup('<span font_desc="%s">%s</span>' % (fontname, text))
layout.apply_markup('<span font_desc="%s %s">%s</span>' % (fontname, size, text))
else:
self.font.family = fontname.split()[0]
self.font.size = pango.units_from_double(int(fontname.split()[1]))
self.font.family = fontname
self.font.size = pango.units_from_double(size)
layout.font_description = self.font
layout.text = text
@ -84,7 +84,7 @@ def stuff_preview(size):
text = flask.request.args.get('text')
html = flask.request.args.get('html') == '1'
renderer = Renderer()
renderer.render_text(text, 'Sans {}'.format(size), 0, -1, html)
renderer.render_text(text, 'Noto Sans CJK JP', size, 0, -1, html)
preview = renderer.get_preview()
return flask.Response(preview, mimetype='image/png')
@ -95,7 +95,7 @@ def stuff_print(size):
text = flask.request.args.get('text')
html = flask.request.args.get('html') == '1'
renderer = Renderer()
renderer.render_text(text, 'Sans {}'.format(size), 0, -1, html)
renderer.render_text(text, 'Noto Sans CJK JP', size, 0, -1, html)
data = renderer.surface.write_to_png()
response = requests.post(

View File

@ -4,7 +4,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hackerspace Printing System For Printing</title>
<title>Hackerspace Labelmaker</title>
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
<style type="text/css">
html {
@ -42,20 +42,19 @@
<h4 class="modal-title">Are you sure you want to print this?</h4>
</div>
<div class="modal-body">
<p>These labels cost money. Don't be an asshole, and only print stuff that is really needed.</p>
<p>Please don't abuse the label printer, it aint for memes</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Nevermind</button>
<button type="button" id="btnconfirm" class="btn btn-primary">Yes please</button>
<button type="button" id="btnconfirm" class="btn btn-primary">Print</button>
</div>
</div>
</div>
</div>
<div class="container">
<div class="page-header">
<h1>Hackerspace Printing System For Printing Labels</h1>
<h1>Hackerspace Labelmaker</h1>
</div>
<h3>Box 'o Stuff Label <small>For SAMLA boxes with common equipment</small></h3>
<div>
<h4>Preview</h4>
<img id="preview" src="/api/preview/70/?text=dupa" class="img-responsive" alt="Label preview" /><br />
@ -88,13 +87,17 @@
$ curl http://label.hackerspace.pl/api/preview/60/?text=foobar&amp;html=0 | feh -
$ # To print the label
$ curl -d "" http://label.hackerspace.pl/api/print/60/?text=foobar&amp;html=0</pre>
<p>
<b>See also:</b><br>
<a href="https://vector.label.hackerspace.pl">Vector Labelmaker</a><br>
<a href="https://pixel.label.hackerspace.pl">Pixel Labelmaker</a>
</p>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<p class="text-muted" style="margin: 20px 0;">Cobbled together by <a href="https://q3k.org/">q3k</a> and updated by etorameth. Sauce
on <a href="https://code.hackerspace.pl/hswaw/labelmaker">code.hackerspace.pl/hswaw/labelmaker</a></p>
<p class="text-muted" style="margin: 20px 0;">By HSWAW contributors. Source: <a href="https://code.hackerspace.pl/hswaw/labelmaker">code.hackerspace.pl/hswaw/labelmaker</a></p>
</div>
</footer>
<script src="/static/js/jquery-2.1.4.min.js"></script>