mirror of
https://github.com/mirkobrombin/raven.git
synced 2026-10-26 21:17:40 +00:00
54 lines
2.8 KiB
Python
54 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Write the method tables of the DirectWrite interfaces that Raven's dwrite component implements.
|
|
|
|
Every interface starts as a table of stubs, one per method in the order of the public headers, so an object can be completed one method
|
|
at a time and a call to a method nobody wrote shows up by name. The output holds, for each interface, an enumeration of the method
|
|
positions, the stubs that report themselves, and the default table.
|
|
|
|
usage: generate-dwrite-tables.py INCLUDE_DIRECTORY OUTPUT.h
|
|
"""
|
|
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
INTERFACES = [
|
|
("dwrite.h", "IDWriteFactory"), ("dwrite_1.h", "IDWriteFactory1"), ("dwrite_2.h", "IDWriteFactory2"), ("dwrite_3.h", "IDWriteFactory3"),
|
|
("dwrite.h", "IDWriteFontCollection"), ("dwrite.h", "IDWriteFontList"), ("dwrite.h", "IDWriteFontFamily"),
|
|
("dwrite.h", "IDWriteFont"), ("dwrite_1.h", "IDWriteFont1"), ("dwrite.h", "IDWriteFontFace"), ("dwrite_1.h", "IDWriteFontFace1"),
|
|
("dwrite.h", "IDWriteFontFile"), ("dwrite.h", "IDWriteLocalizedStrings"), ("dwrite.h", "IDWriteRenderingParams"),
|
|
("dwrite_1.h", "IDWriteRenderingParams1"), ("dwrite_2.h", "IDWriteRenderingParams2"), ("dwrite.h", "IDWriteGlyphRunAnalysis"), ("dwrite.h", "IDWriteGdiInterop"),
|
|
("dwrite_2.h", "IDWriteFontFallback"), ("dwrite.h", "IDWriteTextFormat"), ("dwrite.h", "IDWriteTextLayout"),
|
|
("dwrite.h", "IDWriteBitmapRenderTarget"), ("dwrite.h", "IDWriteFontFileStream"),
|
|
]
|
|
|
|
|
|
def methods(header, name):
|
|
text = (header).read_text()
|
|
found = re.search(r"typedef struct %sVtbl \{(.*?)\} %sVtbl;" % (name, name), text, re.S)
|
|
if not found:
|
|
raise SystemExit(f"no method table for {name}")
|
|
return [member[1] for member in re.findall(r"\n\s*(?:BEGIN_INTERFACE\s*)?([A-Za-z_0-9 \*]+?)\s*\(STDMETHODCALLTYPE\s*\*(\w+)\)\((.*?)\);", found.group(1), re.S)]
|
|
|
|
|
|
def main():
|
|
include = Path(sys.argv[1])
|
|
out = ["/* Generated by scripts/generate-dwrite-tables.py from the DirectWrite headers. Do not edit. */\n",
|
|
"/* The stubs return E_NOTIMPL and say which method was called; a table starts as all stubs. */\n"]
|
|
for header, name in INTERFACES:
|
|
names = methods(include / header, name)
|
|
out.append(f"\nenum {{\n")
|
|
for index, method in enumerate(names):
|
|
out.append(f"\t{name}_{method} = {index},\n")
|
|
out.append(f"\t{name}_methods = {len(names)}\n}};\n")
|
|
for index, method in enumerate(names):
|
|
out.append(f'static HRESULT STDMETHODCALLTYPE {name}_stub_{index}(void *self) {{ return unimplemented("{name}", "{method}"); }}\n')
|
|
out.append(f"static void *{name}_table[{len(names)}] = {{\n")
|
|
for index in range(len(names)):
|
|
out.append(f"\t(void *){name}_stub_{index},\n")
|
|
out.append("};\n")
|
|
Path(sys.argv[2]).write_text("".join(out))
|
|
|
|
|
|
main()
|