[Scummvm-git-logs] scummvm master -> 42cd8ba9ce72b9e81ff4eb49df1d74bc40d1d176

sev- noreply at scummvm.org
Tue Jul 12 14:19:41 UTC 2022


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
42cd8ba9ce DEVTOOLS: COMPANION: Finish integrating create_classicmacfonts as createmacfonts


Commit: 42cd8ba9ce72b9e81ff4eb49df1d74bc40d1d176
    https://github.com/scummvm/scummvm/commit/42cd8ba9ce72b9e81ff4eb49df1d74bc40d1d176
Author: eientei (einstein95 at users.noreply.github.com)
Date: 2022-07-12T16:19:37+02:00

Commit Message:
DEVTOOLS: COMPANION: Finish integrating create_classicmacfonts as createmacfonts

Changed paths:
  R devtools/create_classicmacfonts.sh
  R devtools/decompress-diskcopy-image.py
    devtools/dumper-companion.py


diff --git a/devtools/create_classicmacfonts.sh b/devtools/create_classicmacfonts.sh
deleted file mode 100755
index 32b47cc893c..00000000000
--- a/devtools/create_classicmacfonts.sh
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/bin/bash
-#
-# This script downloads System 7.0.1 image from Apple and extracts fonts
-# from it. Mac only, unfortunately.
-#
-# On Windows you perhaps can perform the extraction manually with use of
-# HFSxplorer: http://www.catacombae.org/hfsexplorer/
-#
-# More information could be found in the vMac documentation: http://www.gryphel.com/c/image/
-#
-# Alternatively you may use vMac instructions for extracting these disk images:
-#   http://www.gryphel.com/c/minivmac/recipes/sys7inst/
-#
-# Based on instructions posted at
-# http://apple.stackexchange.com/questions/58243/can-i-get-the-original-mac-font-chicago-on-a-mountain-lion-mac
-
-echo_n() {
-	printf "$@"
-}
-
-if test `uname` != "Darwin"; then
-	echo This script is macOS-only
-	exit
-fi
-
-echo_n "Downloading System 7.0.1 image..."
-if test ! -f System_7.0.1.smi.bin; then
-	curl -s https://download.info.apple.com/Apple_Support_Area/Apple_Software_Updates/English-North_American/Macintosh/System/Older_System/System_7.0.x/System_7.0.1.smi.bin -o System_7.0.1.smi.bin
-fi
-
-if test ! -f System_7.0.1.smi.bin; then
-	echo "Cannot download System_7.0.1.smi.bin"
-	exit
-fi
-
-echo done
-
-echo_n "Decompressing System 7.0.1 image..."
-
-macbinary decode System_7.0.1.smi.bin
-rm System_7.0.1.smi.bin
-./decompress-diskcopy-image.py System\ 7.0.1.smi sys.img
-
-echo done
-
-echo "Dumping floppy images..."
-
-./dumper-companion.py iso sys.img .
-
-echo Done
-
-echo_n "Cutting Fonts.image..."
-mv Fonts.image Fonts.image.bin
-macbinary decode Fonts.image.bin
-
-tail -c +85 Fonts.image | head -c 1474048 >Fonts1.image
-
-echo done
-
-echo "Extracting fonts..."
-
-./dumper-companion.py iso Fonts1.image .
-
-rm Fonts.image.bin
-
-echo done
-
-echo_n "Copying fonts..."
-
-for i in Athens Cairo Chicago Courier Geneva Helvetica London "Los Angeles" Monaco "New York" Palatino "San Francisco" Symbol Times Venice
-do
-	mv "$i" "$i.bin"
-done
-
-echo ...done
-
-zip -9 classicmacfonts *.bin
-mv classicmacfonts.zip classicmacfonts.dat
-
-echo_n "Cleaning up..."
-rm *.bin
-rm *.smi
-rm *.image
-echo done
-
-ls -l classicmacfonts.dat
diff --git a/devtools/decompress-diskcopy-image.py b/devtools/decompress-diskcopy-image.py
deleted file mode 100755
index ea9261f8f02..00000000000
--- a/devtools/decompress-diskcopy-image.py
+++ /dev/null
@@ -1,166 +0,0 @@
-#!/usr/bin/env python3
-import sys
-import itertools
-import io
-
-hfs_block_size = 512
-window_size = 65536
-
-class DecompressionError(Exception):
-	pass
-
-def block_copy(dest, dest_offset, src, src_offset, size):
-	if size == 0:
-		return
-	dest[dest_offset:dest_offset+size] = src[src_offset:src_offset+size]
-
-
-# Inserts bytes into sliding window ring buffer, returns new window position
-def insert_sl(sl, sl_pos, bytes_to_insert, insert_src_offset, size):
-	available = window_size - sl_pos
-	if available < size:
-		block_copy(sl, sl_pos, bytes_to_insert, insert_src_offset, available)
-		sl_pos = 0
-		sl_pos = insert_sl(sl, sl_pos, bytes_to_insert, insert_src_offset + available, size - available)
-	else:
-		block_copy(sl, sl_pos, bytes_to_insert, insert_src_offset, size)
-		sl_pos = sl_pos + size
-
-	return sl_pos
-
-# Reads bytes from sliding window ring buffer
-def read_sl(sl, sl_pos, out_buf, out_buf_pos, size):
-	available = window_size - sl_pos
-	if available < size:
-		block_copy(out_buf, out_buf_pos, sl, sl_pos, available)
-		read_sl(sl, 0, out_buf, out_buf_pos + available, size - available)
-	else:
-		block_copy(out_buf, out_buf_pos, sl, sl_pos, size)
-
-def read_lz(sl, sl_pos, out_buf, out_buf_pos, coded_offset, length):
-	actual_offset = coded_offset + 1
-
-	read_pos = (sl_pos + window_size - actual_offset) % window_size;
-
-	while actual_offset < length:
-		# Repeating sequence
-		read_sl(sl, read_pos, out_buf, out_buf_pos, actual_offset)
-		out_buf_pos += actual_offset
-		length -= actual_offset
-
-	# Copy
-	read_sl(sl, read_pos, out_buf, out_buf_pos, length)
-
-def decompress(in_f, out_f, compressed_data_size):
-	sl = bytearray(window_size)
-	lz_bytes = bytearray(128)
-	sl_pos = 0
-	chunk_size = 0
-	output_data = 0
-
-	while compressed_data_size > 0:
-		code_byte_0 = in_f.read(1)[0]
-
-		compressed_data_size -= 1
-
-		if (code_byte_0 & 0x80):
-			# Literal
-			chunk_size = (code_byte_0 & 0x7f) + 1
-
-			if chunk_size > compressed_data_size:
-				raise DecompressionError()
-
-			output_data = in_f.read(chunk_size)
-
-			compressed_data_size -= chunk_size
-		elif (code_byte_0 & 0x40):
-			# Large offset
-			if compressed_data_size < 2:
-				raise DecompressionError()
-
-			code_bytes_12 = in_f.read(2)
-
-			compressed_data_size -= 2
-
-			chunk_size = (code_byte_0 & 0x3f) + 4
-			coded_offset = (code_bytes_12[0] << 8) + code_bytes_12[1]
-
-			read_lz(sl, sl_pos, lz_bytes, 0, coded_offset, chunk_size)
-			output_data = lz_bytes
-		else:
-			# Small offset
-			if compressed_data_size < 1:
-				raise DecompressionError()
-
-			code_byte_1 = in_f.read(1)[0]
-
-			compressed_data_size -= 1
-
-			chunk_size = ((code_byte_0 & 0x3c) >> 2) + 3
-			coded_offset = ((code_byte_0 & 0x3) << 8) + code_byte_1
-
-			read_lz(sl, sl_pos, lz_bytes, 0, coded_offset, chunk_size)
-			output_data = lz_bytes
-
-		out_f.write(output_data[0:chunk_size])
-		new_offset = out_f.tell()
-
-		sl_pos = insert_sl(sl, sl_pos, output_data, 0, chunk_size)
-
-def bulk_copy(in_f, out_f, amount):
-	chunk_size = 4096
-	while (amount > 0):
-		block_amount = chunk_size
-		if (block_amount > amount):
-			block_amount = amount
-
-		block = in_f.read(block_amount)
-		out_f.write(block)
-
-		amount -= block_amount
-
-
-
-def main(argv):
-	if (len(argv) != 3):
-		print("decompress-image.py: Converts an ADC-compressed Disk Copy 6 image to an uncompressed image")
-		print("Usage: decompress-image.py <input> <output>")
-		return -1
-
-	in_f = io.open(argv[1], "rb")
-
-	in_f.seek(-hfs_block_size, 2)
-
-	alt_mdb_loc = in_f.tell()
-
-	block_buffer = in_f.read(hfs_block_size)
-
-	if (block_buffer[0] != 66 or block_buffer[1] != 68):
-		print("The specified file doesn't look like a disk image")
-		return -1
-
-	num_allocation_blocks = (block_buffer[18] << 8) + block_buffer[19]
-	allocation_block_size = (block_buffer[20] << 24) + (block_buffer[21] << 16) + (block_buffer[22] << 8) + block_buffer[23]
-	first_allocation_block = (block_buffer[28] << 8) + block_buffer[29]
-
-	compressed_data_start = first_allocation_block * allocation_block_size
-	compressed_data_end = alt_mdb_loc	# ???
-
-	in_f.seek(0)
-
-	out_f = io.open(argv[2], "wb")
-
-	bulk_copy(in_f, out_f, compressed_data_start)
-
-	compressed_amount = compressed_data_end - compressed_data_start
-
-	decompress(in_f, out_f, compressed_amount)
-
-	in_f.seek(alt_mdb_loc)
-	bulk_copy(in_f, out_f, hfs_block_size)
-
-	in_f.close()
-	out_f.close()
-
-
-main(sys.argv)
diff --git a/devtools/dumper-companion.py b/devtools/dumper-companion.py
index ebf3b9160e2..06db43d0895 100755
--- a/devtools/dumper-companion.py
+++ b/devtools/dumper-companion.py
@@ -15,16 +15,17 @@
 # Code is formatted with `black`
 
 import argparse
-import io
+import logging
 import os
 import sys
-import logging
+import unicodedata
+import urllib.request
+import zipfile
 from binascii import crc_hqx
+from io import BytesIO, StringIO
 from pathlib import Path
 from struct import pack, unpack
 from typing import Any, ByteString, List, Tuple
-import unicodedata
-import urllib.request
 
 import machfs
 
@@ -191,11 +192,9 @@ def file_to_macbin(f: machfs.File, name: ByteString) -> bytes:
     return macbin
 
 def macbin_get_datafork(f: bytes) -> bytes:
-    header = unpack(">x64p4s4sBxHHHBxIIIIHB14xIHBB", f[0:124])
-
-    print("Data len is:", header[8])
-
-    return f[128:128 + header[8]]
+    datalen, = unpack(">I", f[0x53:0x57])
+    print("Data len is:", datalen)
+    return f[0x80:0x80 + datalen]
 
 
 def escape_string(s: str) -> str:
@@ -558,6 +557,76 @@ def collect_forks(args: argparse.Namespace) -> int:
     return 0
 
 
+def block_copy(dest, dest_offset, src, src_offset, size):
+    if size == 0:
+        return
+    dest[dest_offset:dest_offset+size] = src[src_offset:src_offset+size]
+
+# Inserts bytes into sliding window ring buffer, returns new window position
+def insert_sl(sl, sl_pos, bytes_to_insert, insert_src_offset, size):
+    available = 0x10000 - sl_pos
+    if available < size:
+        block_copy(sl, sl_pos, bytes_to_insert, insert_src_offset, available)
+        sl_pos = 0
+        sl_pos = insert_sl(sl, sl_pos, bytes_to_insert, insert_src_offset + available, size - available)
+    else:
+        block_copy(sl, sl_pos, bytes_to_insert, insert_src_offset, size)
+        sl_pos = sl_pos + size
+    return sl_pos
+
+# Reads bytes from sliding window ring buffer
+def read_sl(sl, sl_pos, out_buf, out_buf_pos, size):
+    available = 0x10000 - sl_pos
+    if available < size:
+        block_copy(out_buf, out_buf_pos, sl, sl_pos, available)
+        read_sl(sl, 0, out_buf, out_buf_pos + available, size - available)
+    else:
+        block_copy(out_buf, out_buf_pos, sl, sl_pos, size)
+
+def read_lz(sl, sl_pos, out_buf, out_buf_pos, coded_offset, length):
+    actual_offset = coded_offset + 1
+    read_pos = (sl_pos + 0x10000 - actual_offset) % 0x10000;
+    while actual_offset < length:
+        # Repeating sequence
+        read_sl(sl, read_pos, out_buf, out_buf_pos, actual_offset)
+        out_buf_pos += actual_offset
+        length -= actual_offset
+    # Copy
+    read_sl(sl, read_pos, out_buf, out_buf_pos, length)
+
+def decompress(in_f, out_f, compressed_data_size):
+    sl = bytearray(0x10000)
+    lz_bytes = bytearray(128)
+    sl_pos = 0
+    chunk_size = 0
+    output_data = 0
+    while compressed_data_size > 0:
+        code_byte_0 = in_f.read(1)[0]
+        compressed_data_size -= 1
+        if (code_byte_0 & 0x80):
+            # Literal
+            chunk_size = (code_byte_0 & 0x7f) + 1
+            output_data = in_f.read(chunk_size)
+            compressed_data_size -= chunk_size
+        elif (code_byte_0 & 0x40):
+            # Large offset
+            code_bytes_12 = in_f.read(2)
+            compressed_data_size -= 2
+            chunk_size = (code_byte_0 & 0x3f) + 4
+            coded_offset = (code_bytes_12[0] << 8) + code_bytes_12[1]
+            read_lz(sl, sl_pos, lz_bytes, 0, coded_offset, chunk_size)
+            output_data = lz_bytes
+        else:
+            # Small offset
+            code_byte_1 = in_f.read(1)[0]
+            compressed_data_size -= 1
+            chunk_size = ((code_byte_0 & 0x3c) >> 2) + 3
+            coded_offset = ((code_byte_0 & 0x3) << 8) + code_byte_1
+            read_lz(sl, sl_pos, lz_bytes, 0, coded_offset, chunk_size)
+            output_data = lz_bytes
+        out_f.write(output_data[0:chunk_size])
+        sl_pos = insert_sl(sl, sl_pos, output_data, 0, chunk_size)
+
 def create_macfonts(args: argparse.Namespace) -> int:
     """
     Downloads System 7 image, extracts fonts from it and packs them
@@ -568,8 +637,40 @@ def create_macfonts(args: argparse.Namespace) -> int:
         output = file.read()
         print('done')
 
-    datafork = macbin_get_datafork(output)
+    datafork = BytesIO(macbin_get_datafork(output))
+    print('Decompressing...', end="")
+    datafork.seek(-0x200, 2)
+    alt_mdb_loc = datafork.tell()
+    datafork.seek(-(0x200 - 0x12), 2)
+    num_allocation_blocks, allocation_block_size, first_allocation_block = unpack('>HI4xH', datafork.read(12))
+    compressed_data_start = first_allocation_block * allocation_block_size
+    compressed_data_end = alt_mdb_loc   # ???
+    datafork.seek(0)
+    decdatafork = BytesIO()
+    decdatafork.write(datafork.read(compressed_data_start))
+    compressed_amount = compressed_data_end - compressed_data_start
+    decompress(datafork, decdatafork, compressed_amount)
+    datafork.seek(alt_mdb_loc)
+    decdatafork.write(datafork.read(0x200))
+    print('done')
+
+    decdatafork.seek(0)
+    vol = machfs.Volume()
+    vol.read(decdatafork.read())
+    for hpath, obj in vol.iter_paths():
+        if hpath == ('Fonts.image',):
+            fontsvol = obj.data[0x54:]
+            break
+
+    print('Reading Fonts.image...')
+    vol = machfs.Volume()
+    vol.read(fontsvol)
+    with zipfile.ZipFile('classicmacfonts.dat', mode='w', compression=zipfile.ZIP_DEFLATED, compresslevel=9) as fontzip:
+        for hpath, obj in vol.iter_paths():
+            print(f'Compressing {hpath[-1]}...')
+            fontzip.writestr(f'{hpath[-1]}.bin', file_to_macbin(obj, hpath[-1].encode("mac_roman")))
 
+    print('Done')
     return 0
 
 
@@ -700,7 +801,7 @@ def test_encode_string(capsys):
 
 
 def test_encode_stdin(capsys, monkeypatch):
-    monkeypatch.setattr("sys.stdin", io.StringIO("Icon\r"))
+    monkeypatch.setattr("sys.stdin", StringIO("Icon\r"))
     call_test_parser(["str", "--stdin"])
     captured = capsys.readouterr()
     assert captured.out == "xn--Icon-ja6e\n"




More information about the Scummvm-git-logs mailing list