@@ -160,10 +160,13 @@ ;; add obj to comp ;; (define (vg:add-objs-to-comp comp . objs) (vg:comp-objs-set! comp (append (vg:comp-objs comp) objs))) +(define (vg:add-obj-to-comp comp obj) + (vg:comp-objs-set! comp (cons obj (vg:comp-objs comp)))) + ;; use the struct. leave this here to remind of this! ;; ;; (define (vg:comp-get-objs comp) ;; (vg:comp-objs comp)) @@ -396,14 +399,15 @@ (if text (let* ((prev-font (canvas-font cnv)) (font-changed (and font (not (equal? font prev-font))))) (if font-changed (canvas-font-set! cnv font)) (canvas-text! cnv (+ 2 llx)(+ 2 lly) text) - (let-values (((xmax ymax)(canvas-text-size cnv text))) - (set! text-xmax xmax)(set! text-ymax ymax)) + (if (eq? draw 'get-extents) + (let-values (((xmax ymax)(canvas-text-size cnv text))) + (set! text-xmax xmax)(set! text-ymax ymax))) (if font-changed (canvas-font-set! cnv prev-font)))))) - (print "text-xmax: " text-xmax " text-ymax: " text-ymax) + ;; (print "text-xmax: " text-xmax " text-ymax: " text-ymax) (if (vg:obj-extents obj) (vg:obj-extents obj) (if (not text) pts (if (and text-xmax text-ymax) @@ -411,17 +415,18 @@ (max ulx (+ llx text-xmax)) (max uly (+ lly text-ymax))))) (vg:obj-extents-set! obj xt) xt) (if cnv - (let-values (((xmax ymax)(canvas-text-size cnv text))) - (let ((xt (list llx lly - (max ulx (+ llx xmax)) - (max uly (+ lly ymax))))) - (vg:obj-extents-set! obj xt) - xt)) - pts)))))) ;; return extents + (if (eq? draw 'get-extents) + (let-values (((xmax ymax)(canvas-text-size cnv text))) + (let ((xt (list llx lly + (max ulx (+ llx xmax)) + (max uly (+ lly ymax))))) + (vg:obj-extents-set! obj xt) + xt)) + pts))))))) ;; return extents ;; given a rect obj draw it on the canvas applying first the drawing ;; scale and offset ;; (define (vg:draw-line drawing obj #!key (draw #t)) @@ -563,12 +568,14 @@ (if font-changed (canvas-font-set! cnv font)) (canvas-text! cnv llx lly text) ;; NOTE: we do not set the font back!! (canvas-foreground-set! cnv prev-foreground-color))) (if cnv - (let-values (((xmax ymax)(canvas-text-size cnv text))) - (append pts (list (+ llx xmax)(+ lly ymax)))) ;; will be wrong if text is rotated? + (if (eq? draw 'get-extents) + (let-values (((xmax ymax)(canvas-text-size cnv text))) + (append pts (list (+ llx xmax)(+ lly ymax)))) ;; will be wrong if text is rotated? + (append pts pts)) (append pts pts)))) (define (vg:draw drawing draw-mode . instnames) (let ((insts (vg:drawing-insts drawing)) (res '()))