# Simple Vector (Stroke) Font Engine with THICKNESS support # Format: [x1,y1, x2,y2, x3,y3...] (-1 = Pen Lift) FONT = { 'A': [0,10, 5,0, 10,10, -1,-1, 2,7, 8,7], 'B': [0,10, 0,0, 7,0, 7,5, 0,5, -1,-1, 0,5, 8,5, 8,10, 0,10], 'C': [10,2, 8,0, 2,0, 0,2, 0,8, 2,10, 8,10, 10,8], 'D': [0,10, 0,0, 6,0, 9,3, 9,7, 6,10, 0,10], 'E': [10,0, 0,0, 0,10, 10,10, -1,-1, 0,5, 8,5], 'F': [0,10, 0,0, 9,0, -1,-1, 0,5, 8,5], 'G': [10,2, 8,0, 2,0, 0,2, 0,8, 2,10, 8,10, 10,8, 10,5, 6,5], 'H': [0,0, 0,10, -1,-1, 10,0, 10,10, -1,-1, 0,5, 10,5], 'I': [5,0, 5,10, -1,-1, 2,0, 8,0, -1,-1, 2,10, 8,10], 'J': [8,0, 8,8, 6,10, 2,10, 0,8], 'K': [0,0, 0,10, -1,-1, 9,0, 0,5, 9,10], 'L': [0,0, 0,10, 9,10], 'M': [0,10, 0,0, 5,5, 10,0, 10,10], 'N': [0,10, 0,0, 10,10, 10,0], 'O': [5,0, 10,2, 10,8, 5,10, 0,8, 0,2, 5,0], 'P': [0,10, 0,0, 8,0, 8,5, 0,5], 'Q': [5,0, 10,2, 10,8, 5,10, 0,8, 0,2, 5,0, -1,-1, 6,6, 10,10], 'R': [0,10, 0,0, 8,0, 8,5, 0,5, -1,-1, 4,5, 9,10], 'S': [9,2, 5,0, 1,2, 1,4, 5,5, 9,6, 9,8, 5,10, 1,8], 'T': [5,0, 5,10, -1,-1, 0,0, 10,0], 'U': [0,0, 0,8, 2,10, 8,10, 10,8, 10,0], 'V': [0,0, 5,10, 10,0], 'W': [0,0, 2,10, 5,6, 8,10, 10,0], 'X': [0,0, 10,10, -1,-1, 10,0, 0,10], 'Y': [0,0, 5,5, 10,0, -1,-1, 5,5, 5,10], 'Z': [0,0, 10,0, 0,10, 10,10], '0': [5,0, 10,2, 10,8, 5,10, 0,8, 0,2, 5,0, -1,-1, 0,10, 10,0], '1': [2,2, 5,0, 5,10, -1,-1, 2,10, 8,10], '2': [0,2, 5,0, 10,2, 10,5, 0,10, 10,10], '3': [0,2, 5,0, 10,2, 10,4, 6,5, 10,6, 10,8, 5,10, 0,8], '4': [7,10, 7,0, -1,-1, 0,0, 0,5, 10,5], '5': [9,0, 1,0, 1,4, 5,3, 9,4, 9,8, 5,10, 1,8], '6': [9,0, 1,4, 1,8, 5,10, 9,8, 9,5, 1,5], '7': [0,0, 10,0, 4,10], '8': [5,0, 10,2, 10,4, 5,5, 10,6, 10,8, 5,10, 0,8, 0,6, 5,5, 0,4, 0,2, 5,0], '9': [1,10, 9,6, 9,2, 5,0, 1,2, 1,5, 9,5], '.': [4,10, 6,10, 6,8, 4,8, 4,10], ':': [4,2, 4,4, 5,4, 5,2, 6,2, 6,4, -1,-1, 4,8, 4,10, 5,10, 5,8, 6,8, 6,10], '-': [1,5, 9,5], ' ': [] } def draw(display, text, x, y, scale=1, c=1, thickness=1): start_x = x char_width = 12 * scale for char in text: char = char.upper() if char == '\n': y += 15 * scale x = start_x continue if char == ' ': x += char_width continue if char in FONT: strokes = FONT[char] if len(strokes) > 1: curr_x = strokes[0] curr_y = strokes[1] i = 2 while i < len(strokes): next_x = strokes[i] next_y = strokes[i+1] if next_x == -1: # Pen Lift i += 2 if i < len(strokes): curr_x = strokes[i] curr_y = strokes[i+1] i += 2 continue # Calculate scaled coordinates x1 = int(x + curr_x * scale) y1 = int(y + curr_y * scale) x2 = int(x + next_x * scale) y2 = int(y + next_y * scale) # Draw Main Line display.line(x1, y1, x2, y2, c) # Draw Thick Lines (Offset by 1px) if thickness > 1: # Draw parallel line X+1 display.line(x1+1, y1, x2+1, y2, c) if thickness > 2: # Draw parallel line Y+1 display.line(x1, y1+1, x2, y2+1, c) if thickness > 3: # Draw parallel line X+1, Y+1 display.line(x1+1, y1+1, x2+1, y2+1, c) curr_x = next_x curr_y = next_y i += 2 x += char_width