Author Topic: Extending font files  (Read 415 times)

0 Members and 1 Guest are viewing this topic.

Offline ZvikaZ

Extending font files
« on: May 06, 2020, 10:44:37 AM »
Another SQ3-translation-to-Hebrew-project question:
The original SQ3 fonts are 128 letters.
For Hebrew, we need 255 letters.

If we take a font from another game, and just plug it in, it works well, so it shouldn't be interpreters issue here...
(that what we've done so far, but the English letters look too different, of course)

The question is - is there a way to extend an existing font with some of the tools?
Couldn't find in SCICompanion and SCIStudio.

Again, I can take the information from http://sci.sierrahelp.com/Documentation/SCISpecifications/15-SCIFontResource.html and do that myself, but, why waste resources if it has already been done?



Offline ZvikaZ

Re: Extending font files
« Reply #1 on: May 06, 2020, 11:34:02 AM »
Well, sometimes I'm impatient  ;)

Here's a small tool that does it:
Code: [Select]
# SQ3 original fonts had only 128 characters
# for Hebrew translation, we need 255 characters in a font

# reference: http://sci.sierrahelp.com/Documentation/SCISpecifications/15-SCIFontResource.html
# note: there are 2 font file signature (?) bytes at the beginning, not mentioned in that doc

import pathlib

INPUT_FILE = r"C:\Zvika\Games\sq3ega.hebrew\sq3ega\font.000.orig"
OUTPUT_FILE = r"C:\Zvika\Games\sq3ega.hebrew\sq3ega\font.000"

font = list(pathlib.Path(INPUT_FILE).read_bytes())
additional_chars = 255 - 128

font[4] = 128 + additional_chars      # Number of characters
height = font[6]

# update existing pointers
index = 8       # start of pointers table
for i in range(128):
    offset = font[index] + font[index+1]*256
    print("index: ", hex(index), "orig offset: ", hex(offset), end='')
    offset += 2 * additional_chars
    print(", changed to: ", hex(offset))
    font[index] = offset % 256
    font[index+1] = offset // 256
    index += 2

# insert additional_chars pointers at the end of the original pointer list table
# we increase it by the the number of additional characters
# each empty char takes 10 bytes (2 for height and width info, 8 for bitmask: HEIGHT * round_up(WIDTH / 8))

offset = len(font) + additional_chars * 2
pointers = []
for i in range(additional_chars):
    print("new offset: ", hex(offset))
    pointers.extend(list(offset.to_bytes(2, byteorder="little")))
    offset += 10

font[index:index] = pointers

for i in range(additional_chars):
    # define as 8*8
    font.append(8)
    font.append(8)
    # empty bitmask
    for j in range(8):
        font.append(0)

with open(OUTPUT_FILE, "wb") as out_file:
    out_file.write(bytes(font))

« Last Edit: May 06, 2020, 11:49:27 AM by ZvikaZ »

Offline Kawa

Re: Extending font files
« Reply #2 on: May 06, 2020, 06:39:48 PM »
You can change the size of an SCI font to anything up to 256 in regular builds, via the sidebar, and I have personally confirm that even KQ4 1988 can handle 8-bit character codes ("lööps" lol).

Mine goes up to 65535 because SCI11+ has UTF-8.

Offline ZvikaZ

Re: Extending font files
« Reply #3 on: May 07, 2020, 10:35:49 AM »
You can change the size of an SCI font to anything up to 256 in regular builds, via the sidebar, and I have personally confirm that even KQ4 1988 can handle 8-bit character codes ("lööps" lol).

Mine goes up to 65535 because SCI11+ has UTF-8.

Are we talking about `Char count` field, in the left?
Strangely, that's working for SQ4 (which my partner found that has similar fonts to SQ3, and increased them for SQ3), but not for original SQ3 fonts  ::)

Offline Kawa

Re: Extending font files
« Reply #4 on: May 07, 2020, 01:20:17 PM »
Strange indeed if I could extend the font for the very first SCI game and use the new stuff. The font format, I think, hasn't changed from KQ4 to the very last SCI game.


SMF 2.0.14 | SMF © 2017, Simple Machines
Simple Audio Video Embedder

Page created in 0.093 seconds with 24 queries.