|
@@ -35,14 +35,27 @@ def eink_quote_qr(args):
|
|
|
url = simpilib.short_url(q["data"]["url"])
|
|
url = simpilib.short_url(q["data"]["url"])
|
|
|
|
|
|
|
|
smalltext = None
|
|
smalltext = None
|
|
|
- if text.find(" - ") > 0:
|
|
|
|
|
- pos = text.rfind("-")
|
|
|
|
|
- text = text[:pos]
|
|
|
|
|
- smalltext = text[pos+1:]
|
|
|
|
|
|
|
+ import re
|
|
|
|
|
+ dashes = r"(.*)[\u002D\u058A\u05BE\u1400\u1806\u2010-\u2015\u2E17\u2E1A\u2E3A\u2E3B\u2E40\u301C\u3030\u30A0\uFE31\uFE32\uFE58\uFE63\uFF0D](.*)"
|
|
|
|
|
+ matches = re.match(dashes, text)
|
|
|
|
|
+ if matches:
|
|
|
|
|
+ groups = matches.groups()
|
|
|
|
|
+ if len(groups[1]) < 30:
|
|
|
|
|
+ text = groups[0]
|
|
|
|
|
+ smalltext = groups[1]
|
|
|
|
|
+
|
|
|
|
|
+ if not smalltext:
|
|
|
|
|
+ qt = r"(.*)\"(.*)\"(.*)"
|
|
|
|
|
+ matches = re.match(qt, text)
|
|
|
|
|
+ if matches:
|
|
|
|
|
+ groups = matches.groups()
|
|
|
|
|
+ if len(groups[0]) < 10 and len(groups[1]) > 10:
|
|
|
|
|
+ text = groups[1]
|
|
|
|
|
+ smalltext = groups[2].strip()
|
|
|
|
|
|
|
|
print(text)
|
|
print(text)
|
|
|
print(smalltext)
|
|
print(smalltext)
|
|
|
- eink_text_qr(q["data"]["title"], url, smalltext)
|
|
|
|
|
|
|
+ eink_text_qr(text, url, smalltext)
|
|
|
|
|
|
|
|
def eink_text_qr(text, qrdata, smalltext=None):
|
|
def eink_text_qr(text, qrdata, smalltext=None):
|
|
|
import simpilib
|
|
import simpilib
|
|
@@ -57,8 +70,8 @@ def eink_text_qr(text, qrdata, smalltext=None):
|
|
|
qr.make()
|
|
qr.make()
|
|
|
pic = qr.make_image().get_image()
|
|
pic = qr.make_image().get_image()
|
|
|
|
|
|
|
|
- text_image = Image.new('1', (base_image.width-pic.width, base_image.height), 0)
|
|
|
|
|
- small_image = Image.new('1', (pic.width, base_image.height-pic.height), 0)
|
|
|
|
|
|
|
+ text_image = (base_image.width-pic.width, base_image.height)
|
|
|
|
|
+ small_image = (pic.width, base_image.height-pic.height)
|
|
|
|
|
|
|
|
base_image.paste(pic, (base_image.width-pic.width,0), pic)
|
|
base_image.paste(pic, (base_image.width-pic.width,0), pic)
|
|
|
draw = ImageDraw.Draw(base_image)
|
|
draw = ImageDraw.Draw(base_image)
|
|
@@ -68,18 +81,16 @@ def eink_text_qr(text, qrdata, smalltext=None):
|
|
|
|
|
|
|
|
epd.init(epd.PART_UPDATE)
|
|
epd.init(epd.PART_UPDATE)
|
|
|
|
|
|
|
|
- text = simpilib.wrapText(text, line_width_factor=4.5)
|
|
|
|
|
- font = simpilib.loadFontSize(text, draw, text_image, fontpath)
|
|
|
|
|
|
|
+ text, font = simpilib.fitText(text_image, fontpath, text)
|
|
|
|
|
|
|
|
- draw.text((0,0), text, align="center", font = font, fill = 255)
|
|
|
|
|
- epd.displayPartial(epd.getbuffer(base_image))
|
|
|
|
|
|
|
+ draw.text((0,0), text, align="center", font = font, fill = 255, spacing=2)
|
|
|
|
|
|
|
|
if smalltext != None and len(smalltext) > 2:
|
|
if smalltext != None and len(smalltext) > 2:
|
|
|
- smalltext = simpilib.wrapText(smalltext, line_width_factor=10)
|
|
|
|
|
- smallfont = simpilib.loadFontSize(text, draw, small_image, fontpath)
|
|
|
|
|
- draw.text((base_image.width-pic.width,0), smalltext, align="center", font = font, fill = 255)
|
|
|
|
|
- epd.displayPartial(epd.getbuffer(base_image))
|
|
|
|
|
|
|
+ smalltext, smallfont = simpilib.fitText(small_image, fontpath, smalltext)
|
|
|
|
|
+
|
|
|
|
|
+ draw.text((base_image.width-pic.width, pic.height), smalltext, align="center", font = font, fill = 255, spacing=2)
|
|
|
|
|
|
|
|
|
|
+ epd.displayPartial(epd.getbuffer(base_image))
|
|
|
epd.sleep()
|
|
epd.sleep()
|
|
|
epd.Dev_exit()
|
|
epd.Dev_exit()
|
|
|
|
|
|
|
@@ -103,8 +114,7 @@ def eink_text(args):
|
|
|
image = Image.new('1', (epd.height, epd.width), 0)
|
|
image = Image.new('1', (epd.height, epd.width), 0)
|
|
|
draw = ImageDraw.Draw(image)
|
|
draw = ImageDraw.Draw(image)
|
|
|
|
|
|
|
|
- text = simpilib.wrapText(args.text, line_width_factor=7)
|
|
|
|
|
- font = simpilib.loadFontSize(text, draw, image, fontpath)
|
|
|
|
|
|
|
+ text, font = simpilib.fitText(image.size, fontpath, args.text)
|
|
|
|
|
|
|
|
w, h = draw.textsize(text, font=font)
|
|
w, h = draw.textsize(text, font=font)
|
|
|
|
|
|
|
@@ -116,7 +126,7 @@ def eink_text(args):
|
|
|
# -3 px to leave some space for low characters
|
|
# -3 px to leave some space for low characters
|
|
|
|
|
|
|
|
print("Drawing:", (w, h), (epd.height, epd.width), center)
|
|
print("Drawing:", (w, h), (epd.height, epd.width), center)
|
|
|
- draw.text(center, text, align="center", font = font, fill = 255)
|
|
|
|
|
|
|
+ draw.text(center, text, align="center", font = font, fill = 255, spacing=2)
|
|
|
|
|
|
|
|
# epd.display(epd.getbuffer(image.rotate(180)))
|
|
# epd.display(epd.getbuffer(image.rotate(180)))
|
|
|
epd.display(epd.getbuffer(image))
|
|
epd.display(epd.getbuffer(image))
|