I just updated the repo with separated snippets for SublimeText.
Hugo Jourdan
@Hugo Jourdan
Best posts made by Hugo Jourdan
-
RE: DrawBot Auto-completion Snippet
-
Rounded Rectangle
Snippet do draw rectangle with rounded corner:
def rectRounded(x,y,w,h,radius): path = BezierPath() sR=0.5*radius w=w-radius h=h-radius path.rect(x,y+sR,w+radius,h) path.rect(x+sR,y,w,h+radius) path.oval(x,y,radius,radius) path.oval(x+w,y,radius,radius) path.oval(x,y+h,radius,radius) path.oval(x+w,y+h,radius,radius) path.removeOverlap() drawPath(path)
It is possible to manually add it in drawBot module ?
Latest posts made by Hugo Jourdan
-
Drawbot and PIL
Hi,
Is it possible to convert a Drawbot drawing to a PIL format without saving it as an image and then opening/converting it with PIL?
Currently, I'm trying to process all glyphs from a font file with PIL, and I'm using Drawbot to generate images to process with PIL.
-
RE: Auto-Resize FormattedString
I hadn't thought about this solution!
Thanks, @frederik!newPage("A4Landscape") box_w, box_h = width()-100, height()-100 box_x, box_y = 50, 50 txt = FormattedString() txt.fontSize(90) txt.align("center") txt.append("LOOOOOOOOOOOOOOONG STRING\n"*30) txt_w = textSize(txt)[0] txt_h = textSize(txt)[1] width_ratio = box_w/txt_w height_ratio = box_h/txt_h sf = min(width_ratio , height_ratio, 1) scale(sf) textBox(txt, (box_x/sf, box_y/sf, box_w/sf, box_h/sf))
-
Auto-Resize FormattedString
Hi,
I'm looking for a solution to find the maximum value of FontSize that can be set to allow a FormattedString() to occupy all the available space in a TextBox.
For TextBox using a simple string, I have already coded this snippet that returns the maximum fontSize value:
def get_max_fontSize_textBox(font, text, box, align=None, fS=200): font(FONT) fontSize(fS) hyphenation(False) overflow = textOverflow(text, box, align) while overflow: font(FONT) fS -= 1 fontSize(fS) overflow = textOverflow(text, box, align) return fS
I would like to achieve exactly the same thing, but using FormattedString() instead of a str.
The problem is how to build again the FormattedString() in the while overflow loop.
-
Snippet : drawOnCurvePoints
This snippet allow to draw points of a BezierPath ignoring quadratic added nodes when exporting a font.
def drawOnCurvePoints(bezierPath, size): for c in bezierPath: for p in c.points: i = c.points.index(p) try: nextPoint = c.points[i+1] except: nextPoint = c.points[0] previousPoint = c.points[i-1] if nextPoint in bezierPath.onCurvePoints and previousPoint in bezierPath.onCurvePoints : oval(p[0]-size/2,p[1]-size/2, size ,size) if nextPoint[0] == p[0] and p in bezierPath.onCurvePoints: oval(p[0]-size/2,p[1]-size/2, size ,size) if previousPoint[0] == p[0] and p in bezierPath.onCurvePoints: oval(p[0]-size/2,p[1]-size/2, size ,size) if nextPoint[1] == p[1] and p in bezierPath.onCurvePoints: oval(p[0]-size/2,p[1]-size/2, size ,size) if previousPoint[1] == p[1] and p in bezierPath.onCurvePoints: oval(p[0]-size/2,p[1]-size/2, size ,size)
-
listNamedInstances is broken ?
Hi,
I tried to use
listNamedInstances(fontPath)
It seem to list the first instance (depending if variable font contain italic).
I test it with several Google Font and some of mine mine and the problem persists.
I check with FontTableViewer and all instances are present in [name] and [fvar] table.
-
RE: Mute DrawBot warning ?
I'm looking to not print :
*** DrawBot warning: [...] ***
-
Mute DrawBot warning ?
Hi,
There is a way to not show DrawBot warning ?
-
RE: BezierPath offset problem.
@frederik Thanks for this clarification !
-
BezierPath offset problem.
Hi,
I would like to translate a BezierPath, without changing it's bounds.Here is code where you can see my problem.
newPage(2000,2000) # Grey Rectangle path0 = BezierPath() path0.rect(1000,10,200,1990) with savedState(): fill(0, 0.1) drawPath(path0) # Green Rectangle path1 = BezierPath() path1.text("1", fontSize=200) with savedState(): fill(0,1,0) rect(*path1.bounds()) drawPath(path1) # Red Rectangle path2 = BezierPath() path2.text("2", fontSize=200, offset=(200,300)) with savedState(): fill(1,0,0) rect(*path2.bounds()) drawPath(path2) # Yellow Rectangle path3 = BezierPath() path3.text("3", fontSize=200) path3.translate(100,800) with savedState(): fill(1,1,0) rect(*path3.bounds()) drawPath(path3) # Magenta Rectangle translate(900,800) path4 = BezierPath() path4.text("4", fontSize=200) with savedState(): fill(1,0,1) rect(*path4.bounds()) drawPath(path4)
I tested 3 solution:
-
use offset in path.text
Change BezierPath bounds -
use path.translate
Change BezierPath bounds -
use translate
Don't change BezierPath bounds
But this is annoying, because I don't want to translate all my canvas just for that.
So what is the solution ?
-