"fixed" image generationfor large instruction texts

This commit is contained in:
weckyy702
2021-02-09 16:59:52 +01:00
parent 45ee7012f3
commit 354733fc6d
3 changed files with 19 additions and 14 deletions

View File

@@ -32,10 +32,10 @@ class Iinstruction(metaclass=ABCMeta):
pass pass
def _getblkheight(self) -> float: def _getblkheight(self) -> float:
return cti.get_text_size(self.instruction_text)[1] + 5#padding return cti.get_text_size(self.instruction_text)[1] + cti.PADDING_Y #padding
def _getblkwidth(self) -> float: def _getblkwidth(self) -> float:
return cti.get_text_size(self.instruction_text)[0]+50 #padding return cti.get_text_size(self.instruction_text)[0] + cti.PADDING_X #padding
class generic_instruction(Iinstruction): class generic_instruction(Iinstruction):

View File

@@ -8,6 +8,9 @@ from typing import Iterable
from PIL import Image, ImageDraw, ImageFont from PIL import Image, ImageDraw, ImageFont
import os import os
PADDING_X = 100
PADDING_Y = 5
datei_endung = ".png" datei_endung = ".png"
img = None img = None
@@ -65,9 +68,11 @@ def draw_if_statement(condition: str, x: int, y: int, true_w: int, false_w: int,
if not output_img: if not output_img:
raise Exception("Output image was not initialized! Make sure to call NSD_init first") raise Exception("Output image was not initialized! Make sure to call NSD_init first")
text_h = font.getsize(condition)[1] + 5 text_sz = font.getsize(condition)
text_h = text_sz[1] + PADDING_Y
text_w = text_sz[0] + PADDING_X
box_w = true_w + false_w box_w = max(text_w, true_w + false_w)
output_img.line((x,y) + (x + box_w/2, y + text_h), fill=(0)) output_img.line((x,y) + (x + box_w/2, y + text_h), fill=(0))
output_img.line((x + box_w, y) + (x + box_w/2, y + text_h), fill=(0)) output_img.line((x + box_w, y) + (x + box_w/2, y + text_h), fill=(0))

View File

@@ -335,21 +335,21 @@ class Testing {
public void test_function() { public void test_function() {
int rot = getRotation(); int rot = getRotation();
if (richtung=="vorne" && rot==0 || richtung=="rechts" && rot==270 || richtung=="links" && rot==90) //if (richtung=="vorne" && rot==0 || richtung=="rechts" && rot==270 || richtung=="links" && rot==90)
{ //{
if(getOneObjectAtOffset(1,0,Huegel.class)!=null && ((Huegel)getOneObjectAtOffset(1,0,Huegel.class)).getSteigung() >30) if(getOneObjectAtOffset(1,0,Huegel.class)!=null && ((Huegel)getOneObjectAtOffset(1,0,Huegel.class)).getSteigung() >30)
{ {
return true; return true;
} }
} //}
if (richtung=="vorne" && rot==180 || richtung=="rechts" && rot==90 || richtung=="links" && rot==270) //if (richtung=="vorne" && rot==180 || richtung=="rechts" && rot==90 || richtung=="links" && rot==270)
{ //{
if(getOneObjectAtOffset(-1,0,Huegel.class)!=null && ((Huegel)getOneObjectAtOffset(-1,0,Huegel.class)).getSteigung() >30) // if(getOneObjectAtOffset(-1,0,Huegel.class)!=null && ((Huegel)getOneObjectAtOffset(-1,0,Huegel.class)).getSteigung() >30)
{ // {
return true; // return true;
} // }
} //}
// if (richtung=="vorne" && rot==90 || richtung=="rechts" && rot==0 || richtung=="links" && rot==180) // if (richtung=="vorne" && rot==90 || richtung=="rechts" && rot==0 || richtung=="links" && rot==180)
// { // {