Fixed block rendering issues
Fixed issues where graphic blocks had horizontal stripes in them
This commit is contained in:
@@ -15,10 +15,10 @@ ENGLISH = {
|
||||
|
||||
# Swedish/Finnish/Hungarian - Option 010 (2)
|
||||
SWEDISH_FINNISH = {
|
||||
0x23: '#', 0x24: '¤', 0x40: 'É',
|
||||
0x5B: 'Ä', 0x5C: 'Ö', 0x5D: 'Å', 0x5E: 'Ü',
|
||||
0x5F: '_', 0x60: 'é',
|
||||
0x7B: 'ä', 0x7C: 'ö', 0x7D: 'å', 0x7E: 'ü'
|
||||
0x23: '#', 0x24: '\u00A4', 0x40: '\u00C9',
|
||||
0x5B: '\u00C4', 0x5C: '\u00D6', 0x5D: '\u00C5', 0x5E: '\u00DC',
|
||||
0x5F: '_', 0x60: '\u00E9',
|
||||
0x7B: '\u00E4', 0x7C: '\u00F6', 0x7D: '\u00E5', 0x7E: '\u00FC'
|
||||
}
|
||||
|
||||
# German - Option 001 (1)
|
||||
@@ -58,3 +58,22 @@ def get_char(byte_val, subset_idx):
|
||||
return mapping[valid_byte]
|
||||
|
||||
return chr(valid_byte)
|
||||
|
||||
import unicodedata
|
||||
|
||||
def get_byte_from_char(char, subset_idx):
|
||||
if len(char) != 1: return 0
|
||||
|
||||
# Normalize input to NFC to match our map keys (if they are NFC, which python literals usually are)
|
||||
char = unicodedata.normalize('NFC', char)
|
||||
|
||||
if subset_idx < 0 or subset_idx >= len(SETS):
|
||||
subset_idx = 0
|
||||
|
||||
mapping = SETS[subset_idx]
|
||||
|
||||
for code, mapped_char in mapping.items():
|
||||
if mapped_char == char:
|
||||
return code
|
||||
|
||||
return ord(char)
|
||||
|
||||
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