fix too small line-height
This commit is contained in:
parent
823df7253a
commit
50f11dc2a4
@ -1,5 +1,3 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Inkycal custom-functions for ease-of-use
|
||||
|
||||
@ -11,7 +9,7 @@ import time
|
||||
import traceback
|
||||
|
||||
import requests
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from PIL import ImageFont
|
||||
|
||||
logs = logging.getLogger(__name__)
|
||||
logs.setLevel(level=logging.INFO)
|
||||
@ -101,12 +99,12 @@ def auto_fontsize(font, max_height):
|
||||
A PIL font object with modified height.
|
||||
"""
|
||||
text_bbox = font.getbbox("hg")
|
||||
text_height = text_bbox[3] - text_bbox[1]
|
||||
text_height = text_bbox[3]
|
||||
fontsize = text_height
|
||||
while text_height <= (max_height * 0.80):
|
||||
fontsize += 1
|
||||
font = ImageFont.truetype(font.path, fontsize)
|
||||
text_height = text_bbox[3] - text_bbox[1]
|
||||
text_height = text_bbox[3]
|
||||
return font
|
||||
|
||||
|
||||
@ -279,6 +277,7 @@ def internet_available():
|
||||
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
|
||||
def draw_dotted_line(draw, start, end, colour, thickness):
|
||||
"""Draws a dotted line between start and end points using dots."""
|
||||
delta_x = end[0] - start[0]
|
||||
@ -292,7 +291,8 @@ def draw_dotted_line(draw, start, end, colour, thickness):
|
||||
# Drawing a circle at each dot position to create a dotted effect
|
||||
draw.ellipse([(dot_position[0] - thickness, dot_position[1] - thickness),
|
||||
(dot_position[0] + thickness, dot_position[1] + thickness)],
|
||||
fill=colour)
|
||||
fill=colour)
|
||||
|
||||
|
||||
def draw_dashed_line(draw, start, end, colour, thickness):
|
||||
"""Draws a dashed line between start and end points."""
|
||||
@ -309,6 +309,7 @@ def draw_dashed_line(draw, start, end, colour, thickness):
|
||||
segment_start[1] + (step_size * delta_y / distance))
|
||||
draw.line((segment_start, segment_end), fill=colour, width=thickness)
|
||||
|
||||
|
||||
def draw_border(image, xy, size, radius=5, thickness=1, shrinkage=(0.1, 0.1), style='solid'):
|
||||
"""
|
||||
Draws a border at given coordinates with specified styles (solid, dotted, dashed).
|
||||
|
@ -1,5 +1,3 @@
|
||||
#!python3
|
||||
|
||||
"""
|
||||
Inkycal Agenda Module
|
||||
Copyright by aceinnolab
|
||||
@ -100,7 +98,7 @@ class Agenda(inkycal_module):
|
||||
line_spacing = 1
|
||||
|
||||
text_bbox_height = self.font.getbbox("hg")
|
||||
line_height = text_bbox_height[3] - text_bbox_height[1] + line_spacing
|
||||
line_height = text_bbox_height[3] + line_spacing
|
||||
line_width = im_width
|
||||
max_lines = im_height // line_height
|
||||
logger.debug(f'max lines: {max_lines}')
|
||||
@ -111,9 +109,11 @@ class Agenda(inkycal_module):
|
||||
|
||||
# Create a list of dates for the next days
|
||||
agenda_events = [
|
||||
{'begin': today.shift(days=+_),
|
||||
'title': today.shift(days=+_).format(
|
||||
self.date_format, locale=self.language)}
|
||||
{
|
||||
'begin': today.shift(days=+_),
|
||||
'title': today.shift(days=+_).format(
|
||||
self.date_format, locale=self.language)
|
||||
}
|
||||
for _ in range(max_lines)]
|
||||
|
||||
# Load icalendar from config
|
||||
@ -137,7 +137,7 @@ class Agenda(inkycal_module):
|
||||
# Set the width for date, time and event titles
|
||||
date_width = int(max([self.font.getlength(
|
||||
dates['begin'].format(self.date_format, locale=self.language))
|
||||
for dates in agenda_events]) * 1.2)
|
||||
for dates in agenda_events]) * 1.2)
|
||||
logger.debug(f'date_width: {date_width}')
|
||||
|
||||
# Calculate positions for each line
|
||||
@ -152,7 +152,7 @@ class Agenda(inkycal_module):
|
||||
|
||||
time_width = int(max([self.font.getlength(
|
||||
events['begin'].format(self.time_format, locale=self.language))
|
||||
for events in upcoming_events]) * 1.2)
|
||||
for events in upcoming_events]) * 1.2)
|
||||
logger.debug(f'time_width: {time_width}')
|
||||
|
||||
# Calculate x-pos for time
|
||||
@ -227,7 +227,3 @@ class Agenda(inkycal_module):
|
||||
|
||||
# return the images ready for the display
|
||||
return im_black, im_colour
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {__name__} in standalone mode')
|
||||
|
@ -1,5 +1,3 @@
|
||||
#!python3
|
||||
|
||||
"""
|
||||
Inkycal Calendar Module
|
||||
Copyright by aceinnolab
|
||||
@ -267,7 +265,7 @@ class Calendar(inkycal_module):
|
||||
# find out how many lines can fit at max in the event section
|
||||
line_spacing = 2
|
||||
text_bbox_height = self.font.getbbox("hg")
|
||||
line_height = text_bbox_height[3] - text_bbox_height[1] + line_spacing
|
||||
line_height = text_bbox_height[3] + line_spacing
|
||||
max_event_lines = events_height // (line_height + line_spacing)
|
||||
|
||||
# generate list of coordinates for each line
|
||||
@ -356,7 +354,7 @@ class Calendar(inkycal_module):
|
||||
)
|
||||
|
||||
text_bbox_height = self.font.getbbox("hg")
|
||||
line_height = text_bbox_height[3] - text_bbox_height[1] + line_spacing
|
||||
line_height = text_bbox_height[3] + line_spacing
|
||||
|
||||
event_width_s = im_width - date_width - time_width
|
||||
event_width_l = im_width - date_width
|
||||
@ -433,7 +431,3 @@ class Calendar(inkycal_module):
|
||||
|
||||
# return the images ready for the display
|
||||
return im_black, im_colour
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {__name__} in standalone mode')
|
||||
|
@ -1,5 +1,3 @@
|
||||
#!python3
|
||||
|
||||
"""
|
||||
Feeds module for InkyCal Project
|
||||
Copyright by aceinnolab
|
||||
@ -94,7 +92,7 @@ class Feeds(inkycal_module):
|
||||
|
||||
line_width = im_width
|
||||
text_bbox_height = self.font.getbbox("hg")
|
||||
line_height = text_bbox_height[3] - text_bbox_height[1] + line_spacing
|
||||
line_height = text_bbox_height[3] + line_spacing
|
||||
max_lines = (im_height // (line_height + line_spacing))
|
||||
|
||||
# Calculate padding from top so the lines look centralised
|
||||
@ -151,7 +149,3 @@ class Feeds(inkycal_module):
|
||||
|
||||
# return images
|
||||
return im_black, im_colour
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {__name__} in standalone/debug mode')
|
||||
|
@ -1,5 +1,3 @@
|
||||
#!python3
|
||||
|
||||
"""
|
||||
iCanHazDadJoke module for InkyCal Project
|
||||
Special thanks to Erik Fredericks (@efredericks) for the template!
|
||||
@ -56,7 +54,7 @@ class Jokes(inkycal_module):
|
||||
# Set some parameters for formatting feeds
|
||||
line_spacing = 5
|
||||
text_bbox = self.font.getbbox("hg")
|
||||
line_height = text_bbox[3] - text_bbox[1] + line_spacing
|
||||
line_height = text_bbox[3] + line_spacing
|
||||
line_width = im_width
|
||||
max_lines = (im_height // (line_height + line_spacing))
|
||||
|
||||
@ -98,7 +96,3 @@ class Jokes(inkycal_module):
|
||||
|
||||
# Return images for black and colour channels
|
||||
return im_black, im_colour
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {__name__} in standalone/debug mode')
|
||||
|
@ -1,4 +1,3 @@
|
||||
#!python3
|
||||
"""
|
||||
Textfile module for InkyCal Project
|
||||
|
||||
@ -68,7 +67,7 @@ class TextToDisplay(inkycal_module):
|
||||
# Set some parameters for formatting feeds
|
||||
line_spacing = 4
|
||||
text_bbox_height = self.font.getbbox("hg")
|
||||
line_height = text_bbox_height[3] - text_bbox_height[1] + line_spacing
|
||||
line_height = text_bbox_height[3] + line_spacing
|
||||
line_width = im_width
|
||||
max_lines = im_height // line_height
|
||||
|
||||
@ -110,7 +109,3 @@ class TextToDisplay(inkycal_module):
|
||||
|
||||
# return images
|
||||
return im_black, im_colour
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {__name__} in standalone/debug mode')
|
||||
|
@ -1,5 +1,3 @@
|
||||
#!python3
|
||||
|
||||
"""
|
||||
Inkycal Todoist Module
|
||||
Copyright by aceinnolab
|
||||
@ -87,7 +85,7 @@ class Todoist(inkycal_module):
|
||||
# Set some parameters for formatting todos
|
||||
line_spacing = 1
|
||||
text_bbox_height = self.font.getbbox("hg")
|
||||
line_height = text_bbox_height[3] - text_bbox_height[1] + line_spacing
|
||||
line_height = text_bbox_height[3] + line_spacing
|
||||
line_width = im_width
|
||||
max_lines = im_height // line_height
|
||||
|
||||
@ -198,7 +196,3 @@ class Todoist(inkycal_module):
|
||||
|
||||
# return the images ready for the display
|
||||
return im_black, im_colour
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {__name__} in standalone/debug mode')
|
||||
|
Loading…
Reference in New Issue
Block a user