+ local deco_obj_group = ask_for_decorator(model)
+ if (not deco_obj_group) then return end
+ if (deco_obj_group:type() ~= "group") then
+ report_problem(model, "The decoration must be a group.")
+ return
+ end
+
+ local objects = deco_obj_group:elements()
+ local last_obj = table.remove(objects, #objects)
+ local bbox_source = bbox(last_obj, p)
+ local center = ipe.Vector(bbox_source:left() + 0.5 * bbox_source:width(),
+ bbox_source:bottom() + 0.5 * bbox_source:height())
+
+ if (#objects == 0) then
+ report_problem(model, "The decoration must be a group of at least two elements.")
+ return
+ end
+ for i,deco_obj in ipairs(objects) do
+ if (deco_obj:type() ~= "path") then
+ report_problem(model, "Each decoration object needs to be a path.")
+ return
+ end
+
+ cleanup_matrix(deco_obj)
+ local deco_shape = deco_obj:shape()
+
+ resize_shape(deco_shape, center, bbox_source, bbox_target)
+
+ deco_obj:setShape(deco_shape)
+ end
+
+ local group = ipe.Group(objects)
+
+ model:creation("decoration created", group)
+end
+
+-- Asks the user for a decorator and returns the chosen decorator
+-- object or nil.
+function ask_for_decorator(model)