mxbi / arckit

Tools for working with the Abstraction & Reasoning Corpus
Apache License 2.0
112 stars 14 forks source link

Issues with Google Font in Python 3.12.4 on Windows #7

Open luiscosio opened 2 weeks ago

luiscosio commented 2 weeks ago

This is the error:

 AttributeError: 'Group' object has no attribute 'embed_google_font'

This is my fix:

import arckit
import drawsvg
import arckit.vis as vis

# Create a subclass of drawsvg.Group with a dummy embed_google_font method
class GroupWithFont(drawsvg.Group):
    def embed_google_font(self, *args, **kwargs):
        pass  # Do nothing

# Monkey-patch drawsvg in the arckit.vis module
vis.drawsvg.Group = GroupWithFont
mxbi commented 2 weeks ago

Hey, thanks for flagging this! Do you have the traceback for the error?

I'm assuming it's probably from here when group=True. If so, we can just only embed the font when group is False, and avoid the monkeypatch!

efi-github commented 1 week ago

Hi, I have the same problem (python 3.10.12, Linux). Yes that seems to be the spot, error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[10], line 2
      1 for i, task in enumerate(train_set[:10]):
----> 2     drawing = arckit.draw_task(task, width=20, height=12, include_test=True)
      3     arckit.output_drawing(drawing, f"task{i}.svg")

`File .../.venv/lib/python3.10/site-packages/arckit/vis.py:170, in draw_task(task, width, height, include_test, label, bordercols, shortdesc)
    166         output_label = f'Output {i+1}'
    168 # input_label, output_label = '', ''
--> 170 input_grid, offset, (input_x, input_y) = draw_grid(input_grid, padding=padding, xmax=allocation[i], ymax=ymax, group=True, label=input_label, extra_bottom_padding=0.5, bordercol=bordercols[0])
    171 output_grid, offset, (output_x, output_y) = draw_grid(output_grid, padding=padding, xmax=allocation[i], ymax=ymax, group=True, label=output_label, extra_bottom_padding=0.5, bordercol=bordercols[1])
    173 drawlist.append(drawsvg.Use(input_grid, x=x_ptr + (allocation[i]+padding-input_x)/2 - offset[0], y=-offset[1]))

File .../.venv/lib/python3.10/site-packages/arckit/vis.py:84, in draw_grid(grid, xmax, ymax, padding, extra_bottom_padding, group, add_size, label, bordercol)
     81 bw = border_width / 3 # slightly more than 2 to avoid white border
     82 drawing.append(drawsvg.Rectangle(-bw, -bw, xsize+bw*2, ysize+bw*2, fill='none', stroke=bordercol, stroke_width=border_width))
---> 84 drawing.embed_google_font('Anuphan:wght@400;600;700', text=set(f'Input Output 0123456789x Test Task ABCDEFGHIJ? abcdefghjklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ'))
     86 # Write size on the bottom right
     87 # drawing.append(drawsvg.Text(text=f'{gridx}x{gridy}', x=-0.05, y=-0.25, font_size=padding/4, fill='black', text_anchor='start'))
     88 fontsize = (padding/2 + extra_bottom_padding)/2

AttributeError: 'Group' object has no attribute 'embed_google_font'