mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 12:24:59 +00:00
style: Format code with consistent spacing and line breaks
This commit is contained in:
parent
1b0ba71ef0
commit
9cf194b52b
1 changed files with 13 additions and 14 deletions
|
@ -9,6 +9,7 @@ import argparse
|
||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from fontTools.subset import main as subset_main
|
from fontTools.subset import main as subset_main
|
||||||
from fontTools.ttLib import TTFont
|
from fontTools.ttLib import TTFont
|
||||||
|
|
||||||
|
@ -16,21 +17,21 @@ from fontTools.ttLib import TTFont
|
||||||
def subset_font(font_path, text):
|
def subset_font(font_path, text):
|
||||||
"""
|
"""
|
||||||
Create a subset of the font containing only the characters needed for the text.
|
Create a subset of the font containing only the characters needed for the text.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
font_path (str): Path to the TTF font file
|
font_path (str): Path to the TTF font file
|
||||||
text (str): Text for which to extract characters
|
text (str): Text for which to extract characters
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bytes: The subsetted font data
|
bytes: The subsetted font data
|
||||||
"""
|
"""
|
||||||
# Create a temporary file to store the subset font
|
# Create a temporary file to store the subset font
|
||||||
with tempfile.NamedTemporaryFile(suffix=".ttf", delete=False) as tmp_file:
|
with tempfile.NamedTemporaryFile(suffix=".ttf", delete=False) as tmp_file:
|
||||||
tmp_path = tmp_file.name
|
tmp_path = tmp_file.name
|
||||||
|
|
||||||
# Get unique characters from the text
|
# Get unique characters from the text
|
||||||
unique_chars = set(text.lower() + text.upper())
|
unique_chars = set(text.lower() + text.upper())
|
||||||
|
|
||||||
# Create the subsetting command
|
# Create the subsetting command
|
||||||
subset_args = [
|
subset_args = [
|
||||||
font_path,
|
font_path,
|
||||||
|
@ -40,17 +41,17 @@ def subset_font(font_path, text):
|
||||||
"--recalc-bounds",
|
"--recalc-bounds",
|
||||||
"--drop-tables=", # Don't drop any tables by default
|
"--drop-tables=", # Don't drop any tables by default
|
||||||
]
|
]
|
||||||
|
|
||||||
# Run the subsetting
|
# Run the subsetting
|
||||||
subset_main(subset_args)
|
subset_main(subset_args)
|
||||||
|
|
||||||
# Read the subsetted font
|
# Read the subsetted font
|
||||||
with open(tmp_path, "rb") as f:
|
with open(tmp_path, "rb") as f:
|
||||||
font_data = f.read()
|
font_data = f.read()
|
||||||
|
|
||||||
# Clean up the temporary file
|
# Clean up the temporary file
|
||||||
os.unlink(tmp_path)
|
os.unlink(tmp_path)
|
||||||
|
|
||||||
return font_data
|
return font_data
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,9 +139,7 @@ def main():
|
||||||
help="Path to save the SVG file",
|
help="Path to save the SVG file",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--verbose",
|
"--verbose", action="store_true", help="Print additional information about font subsetting"
|
||||||
action="store_true",
|
|
||||||
help="Print additional information about font subsetting"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -159,15 +158,15 @@ def main():
|
||||||
# Generate the SVG
|
# Generate the SVG
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print(f"Subsetting font {args.font} to include only characters for: {args.text}")
|
print(f"Subsetting font {args.font} to include only characters for: {args.text}")
|
||||||
|
|
||||||
svg = generate_svg_with_embedded_font(
|
svg = generate_svg_with_embedded_font(
|
||||||
args.font, text=args.text, color=args.color, output_path=args.output
|
args.font, text=args.text, color=args.color, output_path=args.output
|
||||||
)
|
)
|
||||||
|
|
||||||
if args.verbose and args.output:
|
if args.verbose and args.output:
|
||||||
# Calculate size savings
|
# Calculate size savings
|
||||||
original_size = os.path.getsize(args.font)
|
original_size = os.path.getsize(args.font)
|
||||||
output_size = len(svg.encode('utf-8'))
|
output_size = len(svg.encode("utf-8"))
|
||||||
print(f"Original font size: {original_size/1024:.2f} KB")
|
print(f"Original font size: {original_size/1024:.2f} KB")
|
||||||
print(f"Output SVG size: {output_size/1024:.2f} KB")
|
print(f"Output SVG size: {output_size/1024:.2f} KB")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue