Render Intelligent-only components; fonts follow the display direction

- SLText, TextSelect, DataRecord, FileBrowser pixel-exact against the Intelligent simulator;
  ComboBox and Switch with approximate anti-aliased edges; media/file components draw nothing
- fonts: header byte 3 = 0x0A + direction, glyphs in the direction's pixel order, Intelligent
  glyph data 4-byte aligned -- reproduces the Editor's own font conversion byte for byte
- Intelligent 3D frames: left edge drawn over the bottom edge

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-11-16 00:26:27 +01:00
1 parent 56062e1a3e
commit 49fee337d7
10 files changed
+334 -32

No files matched your search

+47
View File
@@ -126,6 +126,53 @@ class Render(unittest.TestCase):
self.assertEqual(img.getpixel((0, 0)), (194, 0, 92))
self.assertEqual(img.getpixel((1, 0)), (255, 0, 41))
def _intelligent(self, font_px=16):
from nxhmi import fonts, project
from nxhmi.page import Page
h = project.new_project("NX8048P050_011")
fid = project.add_font(h, fonts.from_ttf(None, font_px))
p = Page.parse(h.read("0.pa"))
p.components[0].set("bco", 0x001F)
return h, p, fid
def test_text_select(self):
# measured in the Intelligent simulator (see RENDER.md)
from nxhmi.render import Renderer
h, p, fid = self._intelligent()
C.add(p, "text_select", x=0, y=0, w=90, h=200, font=fid, hig=42, pco1=0x07E0)
C.add(p, "text_select", x=100, y=0, w=100, h=230, font=fid, hig=55, style=1, borderw=3)
h.write("0.pa", p.pack())
img = Renderer(h).render("page0")
self.assertEqual(img.getpixel((5, 79)), (0, 255, 0)) # lines at (h-hig)//2 ...
self.assertEqual(img.getpixel((5, 120)), (0, 255, 0)) # ... and mirrored at the bottom
self.assertEqual(img.getpixel((105, 87)), (0, 0, 255)) # inside the border, odd gap
self.assertEqual(img.getpixel((105, 142)), (0, 0, 255))
top_row = {img.getpixel((x, 12)) for x in range(90)} - {(255, 255, 255)}
self.assertEqual(top_row, {(182, 182, 182)}) # faded: alpha (127 // 42) * 12
def test_data_record_columns(self):
from nxhmi.render import Renderer
h, p, fid = self._intelligent()
C.add(p, "data_record", x=0, y=0, w=187, h=150, font=fid, dir="h0^h1", dez=4, hig=20, style=0)
h.write("0.pa", p.pack())
img = Renderer(h).render("page0")
grid = [x for x in range(187) if img.getpixel((x, 5)) == (197, 194, 197)]
self.assertEqual(grid, [0, 46, 92, 139, 186]) # last columns take the remainder
def test_switch_and_combobox_structure(self):
from nxhmi.render import Renderer
h, p, fid = self._intelligent()
C.add(p, "switch", x=0, y=0, w=120, h=40, val=1, dis=0, font=fid, txt="Off/On",
bco=0xF800, pco=0x07E0, bco2=0xFFE0, pco2=0xF81F, pco1=0)
C.add(p, "combobox", x=200, y=0, w=60, h=30, dis=5, font=fid)
h.write("0.pa", p.pack())
img = Renderer(h).render("page0")
self.assertEqual(img.getpixel((0, 0)), (255, 255, 0)) # on: bco2 track, square corners
self.assertEqual(img.getpixel((100, 19)), (255, 0, 255)) # knob on the right in pco2
ink = [x for x in range(80) if img.getpixel((x, 20)) == (0, 0, 0)]
self.assertEqual(min(ink), 32) # "On" centred in [0, w-h)
self.assertEqual(img.getpixel((200, 0)), (255, 255, 255)) # radius 30*5//200 < 3: square
def test_demo_pages_render(self):
from nxhmi.render import Renderer
r = Renderer(HMIFile.load(FIXTURE))