Skip to content

Color object is not equal with the assignet value #236

Description

@Eigi

Hello,
I try to work with named colors as used in HTML/CSS. My problem ist best shown in the following sample script:

from defcon.objects.glyph import Glyph
from fontParts.world import RGlyph

azure = 0xF0FFFF

def rgb_int_to_tuple(rgb_int, alpha=1):
    r = ((rgb_int >> 16) & 255) / 255
    g = ((rgb_int >> 8) & 255) / 255
    b = (rgb_int & 255) / 255
    return (r, g, b, alpha)

azure_tuple = rgb_int_to_tuple(azure)
print("azure_tuple : ", azure_tuple)

# > azure_tuple :  (0.9411764705882353, 1.0, 1.0, 1)


# Test with defcon glyph =======================================================
glyph = Glyph()
glyph.markColor = azure_tuple
print("glyph.markColor : ", glyph.markColor)
print("tuple(glyph.markColor) : ", tuple(glyph.markColor))
print("tuple(glyph.markColor) == azure_tuple : ", tuple(glyph.markColor) == azure_tuple)

# > glyph.markColor :  0.94118,1,1,1
# > tuple(glyph.markColor) :  (0.94118, 1, 1, 1)
# > tuple(glyph.markColor) == azure_tuple :  False


#Test with fontParts glyph =====================================================
rglyph = RGlyph()
rglyph.markColor = azure_tuple
print("rglyph.markColor : ", rglyph.markColor)
print("rglyph.markColor == azure_tuple : ", rglyph.markColor == azure_tuple)

# > rglyph.markColor :  (0.94118, 1.0, 1.0, 1.0)
# > rglyph.markColor == azure_tuple :  False

I want to mark glyphs with a specific color and later I want to find the glyphs which are marked with that color. But as illustrated above, this does not work as expected. I suspect the root of the problem is in the "stringification" of the defcon Color object, which rounds the color components to 5 decimal places. Therefore the assigned value does not equal the value which stored in the object and equality test with the assigned value fails.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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