Skip to content

Commit

Permalink
Implemented #200 (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
akopachov committed Sep 13, 2023
1 parent 890e0b4 commit 582509d
Show file tree
Hide file tree
Showing 44 changed files with 300 additions and 10,743 deletions.
37 changes: 27 additions & 10 deletions generate-font.ps1
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
# Font file format generator script.

param (
[Parameter(Mandatory)][string]$inputFile
[Parameter(Mandatory)][string]$inputFile,
[Parameter(Mandatory)][string]$outputFile
)

function Get-UInt16AsBytes() {
[OutputType([Array])]
param (
[Parameter(Mandatory)][uint16]$Value
)

$hi = ($Value -shr 8) -band 0xFF
$lo = $Value -band 0xFF

return [Array]@($lo, $hi)
}

$inputFileContent = Get-Content -Path $inputFile -Raw

$fontFile = New-Item -Name "$inputFile.font" -ItemType File -Force
$fontFile = New-Item -Name $outputFile -ItemType File -Force
$fileStream = $fontFile.OpenWrite()
try {
# Font info
if ($inputFileContent -match "FontInfo\s*=\s*{\s*(\d+).*\s*('.').*\s*('.').*\s*(\d+)") {
$fileStream.WriteByte([Byte]$Matches[1]) # Character height
$fileStream.WriteByte([Byte][Char]$Matches[2][1]) # Start character
$fileStream.WriteByte([Byte][Char]$Matches[3][1]) # End character
$fileStream.WriteByte([Byte]$Matches[4]) # Width, in pixels, of space character
if ($inputFileContent -match "FontInfo\s*=\s*{\s*`"(.+)`",\s*(\d+).*\s*('.').*\s*('.').*\s*(\d+)") {
$fileStream.WriteByte([Byte]$Matches[1].Length) # Font name length
$fileStream.Write([System.Text.Encoding]::ASCII.GetBytes($Matches[1]), 0, $Matches[1].Length) # Font name
$fileStream.WriteByte([Byte]$Matches[2]) # Character height
$fileStream.WriteByte([Byte][Char]$Matches[3][1]) # Start character
$fileStream.WriteByte([Byte][Char]$Matches[4][1]) # End character
$fileStream.WriteByte([Byte]$Matches[5]) # Width, in pixels, of space character
} else {
throw "Unable to find FontInfo data"
}
Expand All @@ -24,8 +39,9 @@ try {
$bitmapsRaw = $Matches[1];
$bitmapsMatch = $bitmapsRaw | Select-String -Pattern '0x[0-9a-zA-Z]{2}' -AllMatches
$bitmapBytes = $bitmapsMatch.Matches.Value | ForEach({ [byte]$_ })
$fileStream.Write([System.BitConverter]::GetBytes([Int16]$bitmapBytes.Length), 0, 2) # Bitmap array length
$fileStream.Write($bitmapBytes, 0, $bitmapBytes.Length) # Bitmap data
$length = [uint16]$bitmapBytes.Length
$fileStream.Write((Get-UInt16AsBytes -Value $length), 0, 2) # Bitmap array length
$fileStream.Write($bitmapBytes, 0, $length) # Bitmap data
} else {
throw "Unable to find Bitmap data"
}
Expand All @@ -37,7 +53,8 @@ try {
$fileStream.WriteByte([Byte]$descriptorsMatch.Matches.Length) # Descriptors array length
foreach ($match in $descriptorsMatch.Matches) {
$fileStream.WriteByte([Byte]$match.Groups[1].Value) # Character width
$fileStream.Write([System.BitConverter]::GetBytes([Int16]$match.Groups[2].Value), 0, 2) # Character offset
$offset = [uint16]$match.Groups[2].Value
$fileStream.Write((Get-UInt16AsBytes -Value $offset), 0, 2) # Character offset
}
} else {
throw "Unable to find Descriptors data"
Expand Down
3 changes: 0 additions & 3 deletions totp/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ App(
Lib(
name="roll_value",
),
Lib(
name="fonts",
),
Lib(
name="wolfssl",
sources=[
Expand Down
Binary file added totp/assets/fonts/00.font
Binary file not shown.
Binary file added totp/assets/fonts/01.font
Binary file not shown.
Binary file added totp/assets/fonts/02.font
Binary file not shown.
Binary file added totp/assets/fonts/03.font
Binary file not shown.
Binary file added totp/assets/fonts/04.font
Binary file not shown.
Binary file added totp/assets/fonts/05.font
Binary file not shown.
Binary file added totp/assets/fonts/06.font
Binary file not shown.
Binary file added totp/assets/fonts/07.font
Binary file not shown.
Binary file added totp/assets/fonts/08.font
Binary file not shown.
Binary file added totp/assets/fonts/09.font
Binary file not shown.
Loading

0 comments on commit 582509d

Please sign in to comment.