fmscan.py 2.06 KB
Newer Older
1 2
# Scan an Apple header file, generating a Python file of generator calls.

3 4 5 6
import sys
import os
BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
sys.path.append(BGENDIR)
7
from scantools import Scanner
8
from bgenlocations import TOOLBOXDIR
9 10

LONG = "Fonts"
11
SHORT = "fm"
12 13 14 15

def main():
	input = "Fonts.h"
	output = SHORT + "gen.py"
16
	defsoutput = TOOLBOXDIR + LONG + ".py"
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
	scanner = MyScanner(input, output, defsoutput)
	scanner.scan()
	scanner.close()
	print "=== Done scanning and generating, now importing the generated code... ==="
	exec "import " + SHORT + "support"
	print "=== Done.  It's up to you to compile it now! ==="

class MyScanner(Scanner):

	def destination(self, type, name, arglist):
		classname = "Function"
		listname = "functions"
		return classname, listname

	def makeblacklistnames(self):
		return [
			"OutlineMetrics",	# Too complicated
34 35 36 37 38
			"AntiTextIsAntiAliased",	# XXXX Missing from library...
			"AntiTextGetEnabled",
			"AntiTextSetEnabled",
			"AntiTextGetApplicationAware",
			"AntiTextSetApplicationAware",
39 40 41 42 43
			# These are tricky: they're not Carbon dependent or anything, but they
			# exist only on 8.6 or later (both in Carbon and Classic).
			# Disabling them is the easiest path.
			'SetAntiAliasedTextEnabled',
			'IsAntiAliasedTextEnabled',
44 45
			]

46 47
	def makegreylist(self):
		return [
48
			('#if !TARGET_API_MAC_CARBON', [
49 50 51 52
				'InitFonts',
				'SetFontLock',
				'FlushFonts',
			])]
53 54 55 56
	def makeblacklisttypes(self):
		return [
			"FMInput_ptr",	# Not needed for now
			"FMOutPtr",		# Ditto
57
##			"void_ptr",		# Don't know how to do this right now
58
			"FontInfo",		# Ditto
59 60 61 62 63 64
			]

	def makerepairinstructions(self):
		return [
			([('Str255', '*', 'InMode')], [('Str255', '*', 'OutMode')]),
			([('FMetricRecPtr', 'theMetrics', 'InMode')], [('FMetricRecPtr', 'theMetrics', 'OutMode')]),
65 66
			([('short', 'byteCount', 'InMode'), ('void_ptr', 'textAddr', 'InMode'),],
			 [('TextBuffer', 'inText', 'InMode')]),
67 68
			]
			
Jack Jansen's avatar
Jack Jansen committed
69 70 71 72
	def writeinitialdefs(self):
		self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
		self.defsfile.write("kNilOptions = 0\n")

73 74
if __name__ == "__main__":
	main()