Skip to content

RFont.copy() links sub-objects in info, rather than copying them #758

@ryanbugden

Description

@ryanbugden

Issue:

I ran into a situation in which changing data on a copy of a font was affecting the data on the source font.

f1 = NewFont()
f1.info.postscriptBlueValues = [-10, 0, 50, 60]

f2 = f1.copy()
f2.info.postscriptBlueValues[0] = -2
f2.openInterface()

print(f1.info.postscriptBlueValues)
print(f2.info.postscriptBlueValues)

Output:

[-2, 0, 50, 60]
[-2, 0, 50, 60]

Workaround:

The only workaround I was able to find was copying the list data itself. Should this be necessary?
I'm also reassigning rather than editing directly (that part is just me correcting bad practice above).

f1 = NewFont()
f1.info.postscriptBlueValues = [-10, 0, 50, 60]

f2 = f1.copy()
values = f1.info.postscriptBlueValues.copy()
values[0] = -2
f2.info.postscriptBlueValues = values
f2.openInterface()

print(f1.info.postscriptBlueValues)
print(f2.info.postscriptBlueValues)

Output:

[-10, 0, 50, 60]
[-2, 0, 50, 60]

cc @typesupply

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions