[OpenFontFormat] Use OpenFont.py in table-order/tables.py
This commit is contained in:
		
							parent
							
								
									f3c3749c94
								
							
						
					
					
						commit
						acacae70ff
					
				@ -6,13 +6,23 @@ from subprocess import check_output as run_and_read
 | 
			
		||||
import sys
 | 
			
		||||
from typing import Dict, Set
 | 
			
		||||
 | 
			
		||||
from OpenFont import parse_font_directory
 | 
			
		||||
 | 
			
		||||
def get_vendor(file: str) -> str:
 | 
			
		||||
	command = f"otfinfo -i {file} | grep 'Vendor ID' | awk '{{print $3}}'"
 | 
			
		||||
	return run_and_read(command, shell=True).decode(encoding='ascii').rstrip('\n')
 | 
			
		||||
 | 
			
		||||
def get_tables(file: str) -> list[str]:
 | 
			
		||||
	command = f"otfinfo -t {file} | awk '{{print $2}}'"
 | 
			
		||||
	return run_and_read(command, shell=True).decode(encoding='ascii').rstrip('\n').split('\n')
 | 
			
		||||
	USE_OFTINFO = '--no-otfinfo' not in sys.argv
 | 
			
		||||
	if USE_OFTINFO:
 | 
			
		||||
		command = f"otfinfo -t {file} | awk '{{print $2}}'"
 | 
			
		||||
		return run_and_read(command, shell=True).decode(encoding='ascii').rstrip('\n').split('\n')
 | 
			
		||||
	else:
 | 
			
		||||
		with open(file, 'rb') as f:
 | 
			
		||||
			font_directory = parse_font_directory(f) # Since the font directory is always at the start of the file
 | 
			
		||||
			sorted_entries = sorted(font_directory.table_directory, key=lambda entry: entry.offset)
 | 
			
		||||
			return [entry.tableTag._value_ for entry in sorted_entries]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
FILENAME = os.path.join(os.path.dirname(__file__), "tables")
 | 
			
		||||
 | 
			
		||||
@ -52,7 +62,7 @@ if not sys.stdin.isatty():
 | 
			
		||||
	with open(f"{FILENAME}.txt", 'w') as f:
 | 
			
		||||
		f.write(f"mode: {MODE}\n")
 | 
			
		||||
		for (tag1, tag2) in accumulator:
 | 
			
		||||
			f.write(f"'{tag1:<4}', '{tag2:<4}', {accumulator[(tag1, tag2)]}\n")
 | 
			
		||||
			f.write(f"'{tag1:<4}', '{tag2:<4}', {accumulator[(tag1, tag2)]}, {accumulator.get((tag2, tag1), 0)}\n")
 | 
			
		||||
 | 
			
		||||
	for (tag1, tag2) in accumulator: add_edge(tag1, tag2)
 | 
			
		||||
 | 
			
		||||
@ -67,7 +77,7 @@ else:
 | 
			
		||||
assert MODE, "Unreachable"
 | 
			
		||||
 | 
			
		||||
UNTRANSITIVITY = '--untrans' in sys.argv
 | 
			
		||||
def untransitivity():
 | 
			
		||||
def untransitivity() -> None:
 | 
			
		||||
	to_remove: Dict[str, Set[str]] = {tag: set() for tag in graph}
 | 
			
		||||
	for tag1 in graph:
 | 
			
		||||
		for tag2 in graph[tag1]:
 | 
			
		||||
@ -93,7 +103,9 @@ def generate_svg() -> int:
 | 
			
		||||
 | 
			
		||||
	with open(f"{FILENAME}.dot", 'w') as f:
 | 
			
		||||
		f.write("digraph {\n")
 | 
			
		||||
		f.write(f"\tlayout=dot\n")
 | 
			
		||||
		for node in graph:
 | 
			
		||||
			f.write(f"\t{node_name(node)}\n")
 | 
			
		||||
			for neighbour in graph[node]:
 | 
			
		||||
				f.write(f"\t{node_name(node)} -> {node_name(neighbour)};\n")
 | 
			
		||||
		f.write("}")
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user