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
Formatted string origin with different alignment #106
Comments
Yeah, that behavior makes little sense for multi-line strings. We should reconsider in favor of AI's point-text behavior. |
there is idd something strange... Did some small test and this should work (have to commit the changes): the blue is a and maybe and there is already |
Should it be based on the first line? |
So the H in your example should be on the given point? |
Yes. I don't think the original DrawBot intentionally supported multiple lines to begin with... You couldn't even set line distance. |
this should do it: 2234409 the result is now the same for for alignment in ['left', 'center', 'right']:
for myString in ['AA\nAAAA', 'AAAA\nAA']:
newPage(1000, 1000)
translate(500, 500)
stroke(1, 0, 0)
line((0, -500), (0, 500))
stroke(None)
fs = FormattedString(myString, align=alignment, fontSize=160, fill=(0, .5))
b = BezierPath()
b.text(fs, align=alignment)
translate(0, 200)
fill(0, 1, 0)
oval(-10, -10, 20, 20)
fill(0, 0, 1)
translate(0, 0)
drawPath(b)
translate(0, -450)
fill(0, 1, 0)
oval(-10, -10, 20, 20)
text(fs, (0, 0), align=alignment) |
It's very close now. There's some confustion between FormattedStrings's align and text() align, it seems: fs = FormattedString()
fs.align("right")
fs.fontSize(80)
fs += "Hello\nHelllooo"
text(fs, (500, 500)) # no align, but the "block" is still aligned left of the point |
It could raise an error when both align is provided and the text is an formattedString object A formattedString could have multiple alignments for different lines of text |
Can I just take this opportunity to say how awesome you both are! In case this is helpful, one thought for multiple alignments within a Here is a quick example of what i mean made using 3.88 (before your recent commit). The green box shows a related behavior with
|
in that case it would be beter to add an argument: |
I think that text()'s align argument should just be ignored if the FormattedString has it, just like eg. fontSize() is simply overruled by fs.fontSize(). |
I don't see the concept of a bounding box making much sense in the context of |
Yeah that makes sense. |
when a formattedString is provided the alignment is doing only the positioning relative to the given point, it does not overrule the alignment in the formattedString.
|
Perhaps text() should grow a box kw arg and |
text() draws all text while textBox() draws inside the box and returns the clipped text BezierPath.textBox() will be the winner ;) |
done see 94a182e |
Super, thanks! @djrrb, can you verify it and close the issue? Note the behavior of |
Sorry for the delay...having trouble building from source with Otherwise I will continue to troubleshoot on my end and you can feel free to close the issue (I will reopen if I have anything else to say). Thanks again...this is very cool! |
py2app is not always precise with their tracebacks. Do you have all required packages installed? See https://github.com/typemytype/drawbot/blob/master/README.md It works for me, so I guess I can push a release later on the weekend |
This issue should be fixed, I'm closing the issue. Reopen if this is still problematic. |
I am using
FormattedString()
with"right"
and"center"
alignments for multiline strings, and noticed thattext()
will draw it the origin as the bottom left corner of the final line of the text. This means that for right and centered text, I cannot easily predict the position of the text relative to the origin point, because it is dependent on the length of the content in the last line.A demo:
I'm not sure if there's actually an issue to be solved here, but I am curious if there a way to get them placed consistently?
Of course this is not an issue when using
textBox()
instead oftext()
, but unfortunately I am trying to use this in conjunctionBezierPath()
which does not have atextBox()
method.Have you considered making the origin for center-aligned text at the bottom center, and for right-aligned at the bottom right? (this is similar to what happens to alignments of basic text fields in Illustrator). I understand that a
FormattedString
can have more than one alignment, so maybe that’s not a perfect solution either.I think I might be able to work around this by calculating the final line of the string, making a separate
FormattedString
object, getting thetextSize()[0]
of that, and then offsetting the text object by that amount. Just wondering if there’s a more straightforward way before I go that route.As always, many many thanks!
The text was updated successfully, but these errors were encountered: