Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drawing with fill or stroke=None produces black fill/stroke #44

Closed
zpincus opened this issue Sep 8, 2017 · 4 comments
Closed

drawing with fill or stroke=None produces black fill/stroke #44

zpincus opened this issue Sep 8, 2017 · 4 comments

Comments

@zpincus
Copy link

zpincus commented Sep 8, 2017

Is it a bug or a feature that using draw_shape() with fill=None or stroke=None will produce an image with a black fill or stroke? I had assumed that passing None would result in no fill or stroke. Simple example follows:

import celiagg
import freeimage
import numpy

state = celiagg.GraphicsState()
fill = celiagg.SolidPaint(1,1,1)
#stroke = celiagg.SolidPaint(0,0,0,0) # this produces the desired no-stroke outcome.
stroke = None
transform = celiagg.Transform()

image = numpy.zeros((100, 100), dtype=numpy.uint8)
image += 255
canvas = celiagg.CanvasG8(image)
path = celiagg.Path()
path.rect(25, 25, 50, 50)
canvas.draw_shape(path, transform, state, fill=fill, stroke=stroke)
freeimage.write(image, 'test.png')
@jwiggins
Copy link
Member

Thanks for the report! It's a good question whether this is a bug or a feature. It's certainly confusing, so I would lean towards bug. Looking at the C++ code clarified things a bit for me.

Basically, passing None is not the way to achieve the result you want. Rather, you should set state.drawing_mode = celiagg.DrawingMode.DrawFill or state.drawing_mode = celiagg.DrawingMode.DrawStroke. It just so happens that DrawingMode.DrawFillStroke is the default, and passing None for fill or stroke results in celiagg.SolidPaint(0,0,0) being passed through to the underlying C++ code.

Do you think a descriptive exception would help here if the drawing mode is "incompatible" with the given stroke/fill paint?

@zpincus
Copy link
Author

zpincus commented Sep 11, 2017

Alternately, perhaps the default could be celiagg.SolidPaint(0,0,0) instead of None? That might clarify thing. (An addition to the docstring mentioning the use of DrawingMode to disable fill / stroke would also be helpful.)

Or is there a reason that None is necessary instead of a specific paint default?

@jwiggins
Copy link
Member

I've updated the documentation. The docstrings now reflect better what is happening internally.

@zpincus
Copy link
Author

zpincus commented Sep 26, 2017

Looks very clear now! Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants