Fixed block rendering issues
Fixed issues where graphic blocks had horizontal stripes in them
This commit is contained in:
34
src/teletext/renderer.py
Normal file → Executable file
34
src/teletext/renderer.py
Normal file → Executable file
@@ -4,7 +4,7 @@ from PyQt6.QtGui import QPainter, QColor, QFont, QImage, QBrush, QPen
|
||||
from PyQt6.QtCore import Qt, QRect, QSize, pyqtSignal
|
||||
|
||||
from .models import Page, Packet
|
||||
from .charsets import get_char
|
||||
from .charsets import get_char, get_byte_from_char
|
||||
|
||||
# Helper to create a blank packet
|
||||
def create_blank_packet(magazine: int, row: int) -> Packet:
|
||||
@@ -168,7 +168,8 @@ class TeletextCanvas(QWidget):
|
||||
|
||||
# Check if text is a single char
|
||||
if len(text) == 1:
|
||||
byte_val = ord(text)
|
||||
byte_val = get_byte_from_char(text, self.subset_idx)
|
||||
|
||||
# Simple filter
|
||||
if byte_val > 255: byte_val = 0x3F # ?
|
||||
|
||||
@@ -188,7 +189,7 @@ class TeletextCanvas(QWidget):
|
||||
# But for sanity, let's just append.
|
||||
|
||||
# Write the char
|
||||
byte_val = ord(text)
|
||||
byte_val = get_byte_from_char(text, self.subset_idx)
|
||||
if byte_val > 255: byte_val = 0x3F
|
||||
new_packet.data[self.cursor_x] = byte_val
|
||||
|
||||
@@ -365,7 +366,12 @@ class TeletextCanvas(QWidget):
|
||||
if val >= 0x20:
|
||||
bits = val - 0x20
|
||||
|
||||
blocks = [
|
||||
# Grid definitions for 2x3 grid
|
||||
x_splits = [0, int(self.cell_w / 2), self.cell_w]
|
||||
y_splits = [0, int(self.cell_h / 3), int(2 * self.cell_h / 3), self.cell_h]
|
||||
|
||||
# Block indices (col, row) for the 6 bits
|
||||
block_indices = [
|
||||
(0, 0), (1, 0), # Top
|
||||
(0, 1), (1, 1), # Mid
|
||||
(0, 2), (1, 2) # Bot
|
||||
@@ -373,24 +379,26 @@ class TeletextCanvas(QWidget):
|
||||
|
||||
bit_mask = [1, 2, 4, 8, 16, 64] # 64 is bit 6
|
||||
|
||||
bw = self.cell_w / 2
|
||||
bh = self.cell_h / 3
|
||||
|
||||
if not contiguous:
|
||||
bw -= 1
|
||||
bh -= 1
|
||||
|
||||
painter.setPen(Qt.PenStyle.NoPen)
|
||||
painter.setBrush(QBrush(color))
|
||||
|
||||
for i in range(6):
|
||||
if bits & bit_mask[i]:
|
||||
bx = x + blocks[i][0] * (self.cell_w / 2)
|
||||
by = y + blocks[i][1] * (self.cell_h / 3)
|
||||
c, r = block_indices[i]
|
||||
|
||||
bx_local = x_splits[c]
|
||||
by_local = y_splits[r]
|
||||
bw = x_splits[c+1] - x_splits[c]
|
||||
bh = y_splits[r+1] - y_splits[r]
|
||||
|
||||
bx = x + bx_local
|
||||
by = y + by_local
|
||||
|
||||
if not contiguous:
|
||||
bx += 1
|
||||
by += 1
|
||||
bw -= 1
|
||||
bh -= 1
|
||||
|
||||
painter.drawRect(QRect(int(bx), int(by), int(bw), int(bh)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user