Permalink
Browse files

DEVTOOLS: Script code cleanup

All scripts got better info and debug messages.

Also improved the --trace switch for all scripts and fixed some code formatting issues.
  • Loading branch information...
antoniou79 authored and sev- committed Jan 2, 2019
1 parent c9ddbed commit fa64a064a1c583d75e1f64dabbe4cda83aa02c5b
@@ -13,7 +13,7 @@ https://docs.google.com/spreadsheets/d/17ew0YyhSwqcqZg6bXrIgz0GkA62dhgViHN15lOu5
4. Create a configureFontsTranslation.txt in the sampleInput folder. A configuration file for the MIX file creation. A sample is provided in the sampleInput folder and documentation about this is below in this document (see "text configuration file" in mixResourceCreator).
5. From the ScummVM root folder run:
```
make devtools/create_bladerunner/subtitles
make devtools/create_bladerunner/subtitles
```
6. Copy the output file "SUBTITLES.MIX", created in the ScummVM root folder, into your Blade Runner game directory.
7. Launch the Blade Runner game using ScummVM.
@@ -10,31 +10,31 @@
try:
import shutil
except ImportError:
print "Error:: Shutil python library is required to be installed!"
print "[Error] Shutil python library is required to be installed!"
else:
shutilLibFound = True

try:
import struct
except ImportError:
print "Error:: struct python library is required to be installed!"
print "[Error] struct python library is required to be installed!"
else:
structLibFound = True

try:
import Image
except ImportError:
print "Error:: Image python library (PIL) is required to be installed!"
print "[Error] Image python library (PIL) is required to be installed!"
else:
imagePilLibFound = True

if (not shutilLibFound) or (not structLibFound) or (not imagePilLibFound):
sys.stdout.write("Error:: Errors were found when trying to import required python libraries\n")
sys.stdout.write("[Error] Errors were found when trying to import required python libraries\n")
sys.exit(1)

from struct import *

my_module_version = "0.50"
my_module_version = "0.80"
my_module_name = "fonFileLib"


@@ -51,26 +51,29 @@ def __init__(self):
class fonFile:
m_header = FonHeader()

simpleFontFileName = "GENERIC.FON"
simpleFontFileName = 'GENERIC.FON'
realNumOfCharactersInImageSegment = 0 # this is used for the workaround for the corrupted TAHOME18.FON
nonEmptyCharacters = 0

glyphDetailEntriesLst = [] # list of 5-value tuples. Tuple values are (X-offset, Y-offset, Width, Height, Offset in Graphics segment)
glyphPixelData = None # buffer of pixel data for glyphs

def __init__(self):
m_traceModeEnabled = False

# traceModeEnabled is bool to enable more printed debug messages
def __init__(self, traceModeEnabled = True):
del self.glyphDetailEntriesLst[:]
self.glyphPixelData = None # buffer of pixel data for glyphs
self.simpleFontFileName = "GENERIC.FON"
self.simpleFontFileName = 'GENERIC.FON'
self.realNumOfCharactersInImageSegment = 0 # this is used for the workaround for the corrupted TAHOME18.FON
self.nonEmptyCharacters = 0
self.m_traceModeEnabled = traceModeEnabled

return

def loadFonFile(self, fonBytesBuff, maxLength, fonFileName):
self.simpleFontFileName = fonFileName


offsInFonFile = 0
localLstOfDataOffsets = []
del localLstOfDataOffsets[:]
@@ -84,7 +87,8 @@ def loadFonFile(self, fonBytesBuff, maxLength, fonFileName):

if self.simpleFontFileName == 'TAHOMA18.FON': # deal with corrupted original 'TAHOMA18.FON' file
self.realNumOfCharactersInImageSegment = 176
print "SPECIAL CASE. WORKAROUND FOR CORRUPTED %s FILE. Only %d characters supported!" % (self.simpleFontFileName, self.realNumOfCharactersInImageSegment)
if self.m_traceModeEnabled:
print "[Debug] SPECIAL CASE. WORKAROUND FOR CORRUPTED %s FILE. Only %d characters supported!" % (self.simpleFontFileName, self.realNumOfCharactersInImageSegment)
else:
self.realNumOfCharactersInImageSegment = self.header().maxEntriesInTableOfDetails

@@ -100,15 +104,16 @@ def loadFonFile(self, fonBytesBuff, maxLength, fonFileName):
self.header().graphicSegmentByteSize = tmpTuple[0]
offsInFonFile += 4

print "FON Header Info: "
print "Num of entries: %d\tGlyph max-Width: %d\tGlyph max-Height: %d\tGraphic Segment size %d" % (self.header().maxEntriesInTableOfDetails, self.header().maxGlyphWidth, self.header().maxGlyphHeight, self.header().graphicSegmentByteSize)
#print "Num of entries: %d\tGlyph max-Width: %d\tGlyph max-Height: %d\tGraphic Segment size %d" % (self.realNumOfCharactersInImageSegment, self.header().maxGlyphWidth, self.header().maxGlyphHeight, self.header().graphicSegmentByteSize)
if self.m_traceModeEnabled:
print "[Debug] Font file (FON) Header Info: "
print "[Debug] Number of entries: %d, Glyph max-Width: %d, Glyph max-Height: %d, Graphic Segment size: %d" % (self.header().maxEntriesInTableOfDetails, self.header().maxGlyphWidth, self.header().maxGlyphHeight, self.header().graphicSegmentByteSize)
#
# Glyph details table (each entry is 5 unsigned integers == 5*4 = 20 bytes)
# For most characters, their ASCII value + 1 is the index of their glyph's entry in the details table. The 0 entry of this table is reserved
#
#tmpXOffset, tmpYOffset, tmpWidth, tmpHeight, tmpDataOffset
print "FON glyph details table: "
if self.m_traceModeEnabled:
print "[Debug] Font file (FON) glyph details table: "
for idx in range(0, self.realNumOfCharactersInImageSegment):
tmpTuple = struct.unpack_from('i', fonBytesBuff, offsInFonFile) # unsigned integer 4 bytes
tmpXOffset = tmpTuple[0]
@@ -131,35 +136,40 @@ def loadFonFile(self, fonBytesBuff, maxLength, fonFileName):
offsInFonFile += 4

if tmpWidth == 0 or tmpHeight == 0:
print "Index: %d\t UNUSED *****************************************************************" % (idx)
if self.m_traceModeEnabled:
print "Index: %d\t UNUSED *****************************************************************" % (idx)
else:
self.nonEmptyCharacters += 1
print "Index: %d\txOffs: %d\tyOffs: %d\twidth: %d\theight: %d\tdataOffs: %d" % (idx, tmpXOffset, tmpYOffset, tmpWidth, tmpHeight, tmpDataOffset)
if self.m_traceModeEnabled:
print "Index: %d\txOffs: %d\tyOffs: %d\twidth: %d\theight: %d\tdataOffs: %d" % (idx, tmpXOffset, tmpYOffset, tmpWidth, tmpHeight, tmpDataOffset)
if tmpDataOffset not in localLstOfDataOffsets:
localLstOfDataOffsets.append(tmpDataOffset)
else:
# This never happens in the original files. Offsets are "re-used" but not really because it happens only for empty (height = 0) characters which all seem to point to the next non-empty character
print "Index: %d\t RE-USING ANOTHER GLYPH *****************************************************************" % (idx)
if self.m_traceModeEnabled:
print "Index: %d\t RE-USING ANOTHER GLYPH *****************************************************************" % (idx)

self.glyphDetailEntriesLst.append( ( tmpXOffset, tmpYOffset, tmpWidth, tmpHeight, tmpDataOffset) )

offsInFonFile = (4 * 4) + (self.header().maxEntriesInTableOfDetails * 5 * 4) # we need the total self.header().maxEntriesInTableOfDetails here and not self.realNumOfCharactersInImageSegment
self.glyphPixelData = fonBytesBuff[offsInFonFile:]
return True
except:
print "Loading failure!"
print "[Error] Loading Font file (FON) %s failed!" % (self.simpleFontFileName)
raise
return False

def outputFonToPNG(self):
print "[Info] Exporting font file (FON) to PNG: %s" % (self.simpleFontFileName + ".PNG")

targWidth = 0
targHeight = 0
paddingFromTopY = 2
paddingBetweenGlyphsX = 10


if len(self.glyphDetailEntriesLst) == 0 or (len(self.glyphDetailEntriesLst) != self.realNumOfCharactersInImageSegment and len(self.glyphDetailEntriesLst) != self.header().maxEntriesInTableOfDetails) :
print "Error. Fon file load process did not complete correctly. Missing important data in structures. Cannot output image!"
print "[Error] Font file (FON) loading process did not complete correctly. Missing important data in structures. Cannot output image!"
return

# TODO asdf refine this code here. the dimensions calculation is very crude for now
@@ -202,7 +212,7 @@ def outputFonToPNG(self):
glyphDataOffs += 2

# if pixelColor > 0x8000:
# print "WEIRD CASE" # NEVER HAPPENS - TRANSPARENCY IS ON/OFF. There's no grades of transparency
# print "[Debug] WEIRD CASE" # NEVER HAPPENS - TRANSPARENCY IS ON/OFF. There's no grades of transparency
rgbacolour = (0,0,0,0)
if pixelColor == 0x8000:
rgbacolour = (0,0,0,0) # alpha: 0.0 fully transparent
@@ -219,17 +229,19 @@ def outputFonToPNG(self):

imTargetGameFont.putpixel(( (drawIdx + 1) * (self.header().maxGlyphWidth + paddingBetweenGlyphsX ) + currX, paddingFromTopY + glyphYoffs + currY), rgbacolour)
currX += 1

imTargetGameFont.save(os.path.join('.', self.simpleFontFileName + ".PNG"), "PNG")

try:
imTargetGameFont.save(os.path.join('.', self.simpleFontFileName + ".PNG"), "PNG")
except Exception as e:
print '[Error] Unable to write to output PNG file. ' + str(e)

def header(self):
return self.m_header
#
#
#
if __name__ == '__main__':
# main()
print "Running %s as main module" % (my_module_name)
print "[Debug] Running %s as main module" % (my_module_name)
# assumes a file of name TAHOMA24.FON in same directory
inFONFile = None
#inFONFileName = 'TAHOMA24.FON' # USED IN CREDIT END-TITLES and SCORERS BOARD AT POLICE STATION
@@ -240,22 +252,22 @@ def header(self):

errorFound = False
try:
print "Opening %s" % (inFONFileName)
print "[Info] Opening %s" % (inFONFileName)
inFONFile = open(os.path.join('.',inFONFileName), 'rb')
except:
errorFound = True
print "Unexpected error:", sys.exc_info()[0]
print "[Error] Unexpected event:", sys.exc_info()[0]
raise
if not errorFound:
allOfFonFileInBuffer = inFONFile.read()
fonFileInstance = fonFile()
if (fonFileInstance.loadFonFile(allOfFonFileInBuffer, len(allOfFonFileInBuffer), inFONFileName)):
print "FON file loaded successfully!"
print "[Info] Font file (FON) was loaded successfully!"
fonFileInstance.outputFonToPNG()
else:
print "Error while loading FON file!"
print "[Error] Error while loading Font file (FON)!"
inFONFile.close()
else:
#debug
#print "Running %s imported from another module" % (my_module_name)
#print "[Debug] Running %s imported from another module" % (my_module_name)
pass
@@ -2,7 +2,7 @@
# -*- coding: UTF-8 -*-
import sys
if not (sys.version_info[0] == 2 and sys.version_info[1] == 7):
sys.stdout.write("Error:: Blade Runner Font Creator script requires Python 2.7\n")
sys.stdout.write("[Error] Blade Runner Font Creator script requires Python 2.7\n")
sys.exit(1)

import grabberFromPNG17BR
Oops, something went wrong.

0 comments on commit fa64a06

Please sign in to comment.