Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 1 | # Scan an Apple header file, generating a Python file of generator calls. |
| 2 | |
Jack Jansen | 0c4d947 | 1998-04-17 14:07:56 +0000 | [diff] [blame] | 3 | import sys |
| 4 | import os |
Jack Jansen | aaebdd6 | 2002-08-05 15:39:30 +0000 | [diff] [blame^] | 5 | from bgenlocations import TOOLBOXDIR, BGENDIR |
Jack Jansen | 0c4d947 | 1998-04-17 14:07:56 +0000 | [diff] [blame] | 6 | sys.path.append(BGENDIR) |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 7 | from scantools import Scanner |
| 8 | |
| 9 | LONG = "Fonts" |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 10 | SHORT = "fm" |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 11 | |
| 12 | def main(): |
| 13 | input = "Fonts.h" |
| 14 | output = SHORT + "gen.py" |
Jack Jansen | 46d9e79 | 1996-04-12 16:29:23 +0000 | [diff] [blame] | 15 | defsoutput = TOOLBOXDIR + LONG + ".py" |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 16 | scanner = MyScanner(input, output, defsoutput) |
| 17 | scanner.scan() |
| 18 | scanner.close() |
| 19 | print "=== Done scanning and generating, now importing the generated code... ===" |
| 20 | exec "import " + SHORT + "support" |
| 21 | print "=== Done. It's up to you to compile it now! ===" |
| 22 | |
| 23 | class MyScanner(Scanner): |
| 24 | |
| 25 | def destination(self, type, name, arglist): |
| 26 | classname = "Function" |
| 27 | listname = "functions" |
| 28 | return classname, listname |
| 29 | |
| 30 | def makeblacklistnames(self): |
| 31 | return [ |
| 32 | "OutlineMetrics", # Too complicated |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 33 | "AntiTextIsAntiAliased", # XXXX Missing from library... |
| 34 | "AntiTextGetEnabled", |
| 35 | "AntiTextSetEnabled", |
| 36 | "AntiTextGetApplicationAware", |
| 37 | "AntiTextSetApplicationAware", |
Jack Jansen | 82bcbd0 | 2001-06-20 21:29:19 +0000 | [diff] [blame] | 38 | # These are tricky: they're not Carbon dependent or anything, but they |
| 39 | # exist only on 8.6 or later (both in Carbon and Classic). |
| 40 | # Disabling them is the easiest path. |
| 41 | 'SetAntiAliasedTextEnabled', |
| 42 | 'IsAntiAliasedTextEnabled', |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 43 | ] |
| 44 | |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 45 | def makegreylist(self): |
| 46 | return [ |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 47 | ('#if !TARGET_API_MAC_CARBON', [ |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 48 | 'InitFonts', |
| 49 | 'SetFontLock', |
| 50 | 'FlushFonts', |
| 51 | ])] |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 52 | def makeblacklisttypes(self): |
| 53 | return [ |
| 54 | "FMInput_ptr", # Not needed for now |
| 55 | "FMOutPtr", # Ditto |
Just van Rossum | ca3b2ff | 2002-01-07 14:15:02 +0000 | [diff] [blame] | 56 | ## "void_ptr", # Don't know how to do this right now |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 57 | "FontInfo", # Ditto |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 58 | ] |
| 59 | |
| 60 | def makerepairinstructions(self): |
| 61 | return [ |
| 62 | ([('Str255', '*', 'InMode')], [('Str255', '*', 'OutMode')]), |
| 63 | ([('FMetricRecPtr', 'theMetrics', 'InMode')], [('FMetricRecPtr', 'theMetrics', 'OutMode')]), |
Just van Rossum | ca3b2ff | 2002-01-07 14:15:02 +0000 | [diff] [blame] | 64 | ([('short', 'byteCount', 'InMode'), ('void_ptr', 'textAddr', 'InMode'),], |
| 65 | [('TextBuffer', 'inText', 'InMode')]), |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 66 | ] |
| 67 | |
Jack Jansen | b55e5f1 | 2001-01-03 16:44:27 +0000 | [diff] [blame] | 68 | def writeinitialdefs(self): |
| 69 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
| 70 | self.defsfile.write("kNilOptions = 0\n") |
| 71 | |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 72 | if __name__ == "__main__": |
| 73 | main() |