From: <xs...@ri...> - 2004-01-29 22:30:33
|
Hi! I try to create some reusable graphic elements. The first thing I tried is a text in a box. Here is my first test: from pyx import * def wrap_rect(obj,dist): return path.rect(obj.bbox().left()-dist,obj.bbox().bottom()-dist, obj.bbox().width()+2*dist,obj.bbox().height()+2*dist) c = canvas.canvas() t1 = c.text(0,1.3,"hello",[text.halign.center, text.vshift.middlezero]) t2 = c.text(0,0,"again",[text.halign.center, text.vshift.middlezero]) rect1=wrap_rect(t1,0.1) rect2=wrap_rect(t2,0.1) c.stroke(rect1,[color.rgb.blue]) c.stroke(rect2,[color.rgb.blue]) c.stroke(connector.arc(t1,t2,boxdists=0.15),[deco.earrow.normal]) c.writetofile("textbox") However, there are a few questions left: Is there already a possibility to wrap a text in a box? Is there a better/other (more pyx like) way to achive my goal? I tried to connect the two rects with a connector.arc: c.stroke(connector.arc(rectt1,rect2,boxdists=0.15),[deco.earrow.normal]) But that did not work, because the rect objects do not have the center attribute. What is the prefered way to connect this two rects? Stefan. |
From: Andre W. <wo...@us...> - 2004-02-03 07:52:31
|
Hi Stefan, On 29.01.04, Stefan Reichör wrote: [snip] > Is there already a possibility to wrap a text in a box? > Is there a better/other (more pyx like) way to achive my goal? Beside the fact, that the text itself is already a box, we do not yet have a nice way of performing operations like wrapping boxes into other boxes e.g. extending their size etc. You could use the enhance method of the bounding box, but still, you would need to build up a new rectangular box from that yourself. So in principle, your code is already the best you can do for the moment. And you are right, it is not really PyX-like. ;-) I would like to see boxes becoming a more basic feature in PyX, e.g. they could become *the* (reads the only) way of performing clippings. Then they should be initializable by arbitrary paths etc. ... we'll see how far this idea can be implemented in the future. > But that did not work, because the rect objects do not have the > center attribute. > > What is the prefered way to connect this two rects? Ok, there is a big difference in a rect from the path module and a rect from the box module. The paths are just mathematical objects. They cannot be drawn themselfs (they need a decorator for that, e.g. deco.stroked; those decorators create a decorated path out of that mathematical path object). A box is something very different, although it might be constructed out of a path. A box uses this path as a boundary (the path might even create holes within the box as well). Optionally, a box might have a center (currently there is a _ensurecenter, which was added by Michael, but I'm not totally convinced, we should always ensure a center). As soon as a box has a center, it can be aligned and connectors can be used on that box as well. Thats at least the goal I would like to see in the future ... André -- by _ _ _ Dr. André Wobst / \ \ / ) wo...@us..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript figures with Python & TeX (_/ \_)_/\_/ visit http://pyx.sourceforge.net/ |