基本セット
inkex.py
simplestyle.py
formatStyle(attr)
- 引数
属性値の辞書
- 戻り値
文字列
- サンプル
-
import simplestyle ... attr = {'stroke':'none','fill':'#000000',...} obj.set('style', simplestyle.formatStyle(attr))
<svg> ... <path 'style'='stroke:none;fill:#000000;...' .../>
属性値が少ない場合は直接設定できますが、多い場合や変数が混ざっている場合はこれを使う方が良いでしょう。
simplepath.py
parsePath(d)
- 引数
pathのd属性
- 戻り値
[[command, [座標リスト]],...]
- 参考
-
cubicsuperpath.parsePath()メソッドで使用されている。
座標データが欲しいだけならそちらの方が良い。
cubicsuperpath.py
parsePath(d)
- 引数
-
pathのd属性
- 戻り値
-
[[[[入る側ハンドルのX座標, Y座標],[ノードのX座標, Y座標],[出る側ハンドルのX座標, Y座標]],...],[あれば合成パスのデータが続く],...]
- 使用例
-
import cubicsuperpath ... for id, path in self.selected.iteritems(): for pathData in cubicsuperpath.parsePath(path.get('d')): for pointData in pathData: handleIn = pointData[0] node = pointData[1] handleOut = pointData[2] ... attr = { inkex.addNS('cx', 'sodipodi'): str(node[0]), inkex.addNS('cy', 'sodipodi'): str(node[1]), ... }
simpletransform.py
fuseTransform(path)
指定パスに適用されているtransform属性をd属性に適用してtransform属性を削除します。
- 引数
- node(svg:path)
- 戻り値
- ---
- 使用例
-
import simpletransform ... for id, path in self.selected.iteritems(): simpletransform.fuseTransform(path)
- 補足
roughBBox(cubicPath)
cubicPathデータ内で最大最小の座標を返します。
- 引数
- cubicPath(cubicsuperpath.parsePath(d)の戻り値)
- 戻り値
- [minX, maxX, minY, maxY]
- 使用例
-
import simpletransform, cubicsuperpath ... bbox = simpletansform.roughBBox(cubicsuperpath.parsePath(path.get('d')))
refinedBBox(cubicPath)
cubicPathデータで描かれるパスのバウンディングボックスの座標を返します。
- 引数
- cubicPath(cubicsuperpath.parsePath(d)の戻り値)
- 戻り値
- [minX, maxX, minY, maxY]
- 使用例
-
import simpletransform, cubicsuperpath ... bbox = simpletansform.refinedBBox(cubicsuperpath.parsePath(path.get('d')))
※roughBBox()とrefinedBBox()の違い
computeBBox(pathlist)
複数パス(Font除く)全体のバウンディングボックスの座標を返します。
- 引数
- pathlist
- 戻り値
- [minX, maxX, minY, maxY]
- 使用例
-
import simpletransform ... alist = [] for id, path in self.selected.iteritems(): alist.append(path) bbox = simpletransform.computeBBox(alist)
引数はパスリストのみを受け付けるので、idが入っているとエラーが返ってきます。
選択アイテムのバウンディングボックスを取得する場合は上のようにリストの作りなおしをする必要があります。
- その他
- d属性を持たないオブジェクトのバウンディングボックス(Font除く)も取得でき、パスの変換も必要ないので、refinedBBox()より使い勝手が良いかもしれません。
Links