Hi all, (Johan, I'm CC'ing you because you actively worked in this area a while ago)
I'd like to use the temporary canvas item machinery to display some "info" related to LPEs. This info can consist of helper paths or perhaps even text (e.g., for LPEs measuring path lengths or areas). I've played a bit with it but I think I'm not using it in the correct/recommended/ easiest way, which sometimes even results in crashes.
So my questions are:
- How can I create a temporary canvas item to display a helper path having a given shape?
- How can I display text using this mechanism?
- If I want to make either the helper path or the text permanent (i.e., convert them into a non-temporary item and save them in the document), how can I achieve this?
Thanks for any help, Max
Hi Max,
- How can I create a temporary canvas item to display a helper path having a given shape?
For this, you should have a look at the path flash code in function "sp_node_context_flash_path". Keep in mind that you should *not* keep a reference to the SPCanvasItem. The tempitem code deletes the object for you. The only valid use of the TemporaryItem* that you get from add_temporary_canvasitem is when you want to prematurely remove the item from the canvas, by calling " desktop->remove_temporary_canvasitem(tempitem); " .
- How can I display text using this mechanism?
Don't know if this is easy to do. The temp canvas item machinery only works with SPCanvasItem. Perhaps it is good to create an SPCanvasItem that renders text, because it can be used for many other things.
- If I want to make either the helper path or the text
permanent (i.e., convert them into a non-temporary item and save them in the document), how can I achieve this?
You can't convert an SPCanvasItem to SVG. So you have to manually do this, writing an svg:path or whatever to SVG.
Hope this helps, Johan
-----Original Message----- From: Maximilian Albert [mailto:Anhalter42@...173...] Sent: woensdag 18 juni 2008 3:22 To: inkscape Cc: Engelen, J.B.C. (Johan) Subject: Temporary canvas items
Hi all, (Johan, I'm CC'ing you because you actively worked in this area a while ago)
I'd like to use the temporary canvas item machinery to display some "info" related to LPEs. This info can consist of helper paths or perhaps even text (e.g., for LPEs measuring path lengths or areas). I've played a bit with it but I think I'm not using it in the correct/recommended/ easiest way, which sometimes even results in crashes.
So my questions are:
How can I create a temporary canvas item to display a helper path having a given shape?
How can I display text using this mechanism?
If I want to make either the helper path or the text
permanent (i.e., convert them into a non-temporary item and save them in the document), how can I achieve this?
Thanks for any help, Max
J.B.C.Engelen@...1578... schrieb:
Hi Max,
- How can I create a temporary canvas item to display a helper path having a given shape?
For this, you should have a look at the path flash code in function "sp_node_context_flash_path".
Thanks. I had seen this function, but it simply takes an *existing* item and converts it to a temporary path. This is not so difficult since in this case we can extract the existing SPCurve information from the item. So my question should have been more precise: What's the recommended way to create temporary path "from scratch" (i.e., without necessarily an item existing that has the required path information)?
Can I easily construct the required SPCurve directly? Or should I create a BPath first which is converted to a curve (if so, how would I do this)? Or must I create a separate SPItem from the desired path data and pass this on to sp_nodepath_generate_helperpath()? I gues my question boils down to this: Which of these things is lowest in the hierarchy and still has convenient creation functions?
BTW, how is SPCanvasItem related to SPCurve/SPItem etc.? How do I "correctly" create an SPCanvasItem from given path data? In particular, what do I specify as the parent SPCanvasGroup?
- How can I display text using this mechanism?
Don't know if this is easy to do. The temp canvas item machinery only works with SPCanvasItem. Perhaps it is good to create an SPCanvasItem that renders text, because it can be used for many other things.
Yes. My question is how the "... that renders text" part would work.
Wow, lots of questions. Thanks for your (and everyone's) help! Max
-----Original Message----- From: Maximilian Albert [mailto:Anhalter42@...173...] Sent: woensdag 18 juni 2008 12:45 To: Engelen, J.B.C. (Johan) Cc: inkscape-devel@lists.sourceforge.net Subject: Re: Temporary canvas items
J.B.C.Engelen@...1578... schrieb:
Hi Max,
- How can I create a temporary canvas item to display a helper path having a given shape?
For this, you should have a look at the path flash code in
function > "sp_node_context_flash_path".
Thanks. I had seen this function, but it simply takes an *existing* item and converts it to a temporary path. This is not so difficult since in this case we can extract the existing SPCurve information from the item. So my question should have been more precise: What's the recommended way to create temporary path "from scratch" (i.e., without necessarily an item existing that has the required path information)?
Can I easily construct the required SPCurve directly? Or should I create a BPath first which is converted to a curve (if so, how would I do this)? Or must I create a separate SPItem from the desired path data and pass this on to sp_nodepath_generate_helperpath()? I gues my question boils down to this: Which of these things is lowest in the hierarchy and still has convenient creation functions?
Go with sp_canvas_bpath_new (look up sp_nodepath_generate_helperpath). Generating an SPCurve is/should be easy; there are two ways: 1. create Geom::PathVector and then construct SPCurve with it. (I'd take this route, but it might not be so obvious to do for the first time, have a look at display/curve.cpp's moveto, lineto, curveto, closepath. Ignore all code about NArtBpath, so only look at _pathv) 2. construct empty SPCurve and then create the path using curve->moveto, lineto and/or curveto. Have a look at display/curve.h ; documentation per function can be found in curve.cpp.
BTW, how is SPCanvasItem related to SPCurve/SPItem etc.? How do I "correctly" create an SPCanvasItem from given path data? In particular, what do I specify as the parent SPCanvasGroup?
For bpaths on canvas: SPCanvasItem is created from SPCurve and keeps a reference to the SPCurve after that. When sp_canvas_item_request_update is called on the canvasitem, it re-reads the SPCurve data and puts that on screen. SPDesktop has a number of SPCanvasGroups, pick one :P For temp items, I take sp_desktop_tempgroup(desktop). I think there is also a group for "scratchpad" things that you might want to use.
- How can I display text using this mechanism?
Don't know if this is easy to do. The temp canvas item
machinery only > works with SPCanvasItem. Perhaps it is good to create an SPCanvasItem > that renders text, because it can be used for many other things.
Yes. My question is how the "... that renders text" part would work.
Maybe Cairo can help you out there... (such for outline rendering code, that uses cairo for rendering shapes)
-johan
On Wed, Jun 18, 2008 at 6:45 AM, Maximilian Albert <Anhalter42@...173...> wrote:
Yes. My question is how the "... that renders text" part would work.
Since you don't need to worry about exact font, kerning, etc., which all may be tricky, cairo is the natural choice for this. Each canvas item has a render method which is passed the SPCanvasBuf; you can just deconstruct it to access the actual memory buffer, create a temporary cairo surface and context in the render method of your text canvas item, and draw text to it using cairo's show_text.
But that would be wasteful and hacky, although acceptable as a temporary solution. The proper solution that would take us one step closer to total cairofication is to create a common cairo context in sp-canvas, associated with SPCanvasBuf, and pass it down to all canvas buffer so they could draw to it using cairo at once. That is what needs to be done, the biggest obstacle being that most canvasitems are drawn with direct bit-flipping in the buffer and they assume 3 bytes per pixel and fixed RGB order, neither of which is true for cairo which only has 4 bytes whose order depends on endianness. So all of canvas items must be switched to cairo (or at least to 4 bytes) at once, this cannot be done incrementally. This is what I'll have to do as soon as I have some time to devote to it (unless someone comes to my rescue :)
participants (3)
-
unknown@example.com
-
bulia byak
-
Maximilian Albert