Parser for RISC OS Font control characters in Python

Related tags

Miscellaneous riscos
Overview

RISC OS Font control parsing in Python

This repository contains a class (FontControlParser) for parsing font control codes from a byte squence, in Python.

It is part of the RISC OS Pyromaniac font system, and provides support for the SWIs which operate on the font strings:

  • Font_Paint - uses the controls to determine what should be rendered.
  • Font_ScanString - uses the controls to determine the size or break points of a string.

And all the other calls which call on to Font_ScanString:

  • Font_StringWidth - reads the width of a string.
  • Font_StringBBox - reads the coverage of a string.
  • Font_FindCaret - finds the position of the caret within a string.
  • Font_FindCaretJ - a variant of the Font_FindCaret call.

The FontContext provides information which allows the operation of the following calls:

  • Font_CurrentFont - reads the current font.
  • Font_FutureFont - reads what the font would be after one of the sizing calls.
  • Font_CurrentRGB - reads the current colour.
  • Font_FutureRGB - reads what the colour would be after one of the sizing calls.

Usage

Inside RISC OS Pyromaniac...

  • The FontControlParser is subclassed to allow the memory access to occur within the emulated memory, not using the bytes.
  • The FontSpacing is subclassed to create spacing from the memory blocks.
  • The FontContext is subclassed to allow the GCOL/RGB operations, font lookups, sizing and rendering operations to be performed on the RISC OS graphics system.

A font context is created on initialisation, and will be updated by different operations:

self.context = FontContextPyromaniac(self.ro, self.fonts)

The font parser is constructed and supplied the memory buffers to parse:

memstring = self.ro.memory[regs[1]]
fc = FontControlParserPyromaniac(self.ro)
fc.debug_enable = self.debug_fontparser
fc.parse(memstring, string_length)

Once the other parameters for Font_Paint have been decoded and spacing and transformed written to the FontContext, the paint operation is called.

self.context.x = xmilli
self.context.y = ymilli
self.context.transform = transform

with self.ro.kernel.graphics.vducursor.disable():
    self.context.paint(fc.sequence, spacing)

    # Update OS_ChangedBox
    x0 = int(self.context.bounds.x0 / riscos.graphics.font.FontConstants.Font_OSUnit) >> xeig
    y0 = int(self.context.bounds.y0 / riscos.graphics.font.FontConstants.Font_OSUnit) >> xeig
    x1 = int(self.context.bounds.x1 / riscos.graphics.font.FontConstants.Font_OSUnit) >> yeig
    y1 = int(self.context.bounds.y1 / riscos.graphics.font.FontConstants.Font_OSUnit) >> yeig
    self.ro.kernel.graphics.changedbox_update(x0, y0, x1, y1)

Font_ScanString is similar, but instead of operating on the current context, the future context is updated:

self.context.copy(to=self.future_context)
...
memstring = self.ro.memory[regs[1]]
fc = FontControlParserPyromaniac(self.ro)
fc.debug_enable = self.debug_fontparser
fc.parse(memstring, string_length)
...
(split_offset, splits) = self.future_context.size(fc.sequence, spacing=spacing, limits=(xmilli, ymilli),
                                                  split_char=split_char)

This allows all the Font_Future* calls to query the self.future_context

Tests

Tests exist to show that the module is working properly, intended for use on GitLab. Code coverage is reported as well.

To test, use:

make tests PYTHON=python2

Tests don't work on Python 3 yet, due to some problems with the processing of byte sequences.

To run coverage, use:

make coverage
You might also like...
:snake: Complete C99 parser in pure Python

pycparser v2.20 Contents 1 Introduction 1.1 What is pycparser? 1.2 What is it good for? 1.3 Which version of C does pycparser support? 1.4 What gramma

A Gura parser implementation for Python

Gura parser This repository contains the implementation of a Gura format parser in Python. Installation pip install gura-parser Usage import gura gur

A python library for writing parser-based interactive fiction.

About IntFicPy A python library for writing parser-based interactive fiction. Currently in early development. IntFicPy Docs Parser-based interactive f

Neogex is a human readable parser standard, being implemented in Python

Neogex (New Expressions) Parsing Standard Much like Regex, Neogex allows for string parsing and validation based on a set of requirements. Unlike Rege

Ergonomic option parser on top of dataclasses, inspired by structopt.
Ergonomic option parser on top of dataclasses, inspired by structopt.

oppapī Ergonomic option parser on top of dataclasses, inspired by structopt. Usage from typing import Optional from oppapi import from_args, oppapi @

Parser for air tickets' price

Air-ticket-price-parser Parser for air tickets' price How to Install Firefox If geckodriver.exe is not compatible with your Firefox version, download

A simple string parser based on CLR to check whether a string is acceptable or not for a given grammar.

A simple string parser based on CLR to check whether a string is acceptable or not for a given grammar.

A parser of Windows Defender's DetectionHistory forensic artifact, containing substantial info about quarantined files and executables.

A parser of Windows Defender's DetectionHistory forensic artifact, containing substantial info about quarantined files and executables.

The parser of a timetable of tennis matches for Flashscore website

FlashscoreParser The parser of a timetable of tennis matches for Flashscore website. The program collects the schedule of tennis matches for two days

Owner
Charles Ferguson
Software Engineer. I like making stuff that makes other stuff easier.
Charles Ferguson
Fix Eitaa Messenger's Font Problem on Linux

Fix Eitaa Messenger's Font Problem on Linux

null 6 Oct 15, 2022
Gba-free-fonts - Free font resources for GBA game development

gba-free-fonts Free font resources for GBA game development This repo contains m

null 28 Dec 30, 2022
A python API act as Control Center to control your Clevo Laptop via wmi on windows.

ClevoPyControlCenter A python API act as Control Center to control your Clevo Laptop via wmi on windows. Usage # pip3 install pymi from clevo_wmi impo

null 3 Sep 19, 2022
TurtleBot Control App - TurtleBot Control App With Python

TURTLEBOT CONTROL APP INDEX: 1. Introduction 2. Environments 2.1. Simulated Envi

Rafanton 4 Aug 3, 2022
List of short Codeforces problems with a statement of 1000 characters or less. Python script and data files included.

Shortest problems on Codeforces List of Codeforces problems with a short problem statement of 1000 characters or less. Sorted for each rating level. B

null 32 Dec 24, 2022
💘 Write any Python with 9 Characters: e,x,c,h,r,(,+,1,)

?? PyFuck exchr(+1) PyFuck is a strange playful code. It uses only nine different characters to write Python3 code. Inspired by aemkei/jsfuck Example

Satoki 10 Dec 25, 2022
Control System Packer is a lightweight, low-level program to transform energy equations into the compact libraries for control systems.

Control System Packer is a lightweight, low-level program to transform energy equations into the compact libraries for control systems. Packer supports Python ?? , C ?? and C++ ?? libraries.

mirnanoukari 31 Sep 15, 2022
Inverted-pendulum-with-fuzzy-control - Inverted pendulum with fuzzy control

Fuzzy Inverted Pendulum Basically, this project consists of an inverted pendulum

Mahan Ahmadvand 1 Aug 25, 2022
A dot matrix rendered using braille characters.

⣿ dotmatrix A dot matrix rendered using braille characters. Description This library provides class called Matrix which represents a dot matrix that c

Tim Fischer 25 Dec 12, 2022
Analisador de strings feito em Python // String parser made in Python

Este é um analisador feito em Python, neste programa, estou estudando funções e a sua junção com "if's" e dados colocados pelo usuário. Neste código,

Dev Nasser 1 Nov 3, 2021