Subject: mailing-list for TeXmacs Users
List archive
From : Jalady Christophe <address@hidden>- To: address@hidden
- Subject: [TeXmacs] A simple "quick postscript-scaler" plugin
- Date: Sun, 26 Oct 2008 19:08:05 +0100
Hi,
I try learning how to hack TeXmacs. So I made a simple plugin in Scheme.
The purpose of this plugin is to give the ability to quickly resize by +/- 10% a bitmap with two key-shortcut: "Ctrl -" and "Ctrl +".
You need to place the cursor just after the bitmap and then press "Ctrl -" or "Ctrl +"; the picture is automatically resized.
To install the plugin (for now), just eval the small scheme script (I will provide later a better packaging, more texmacs-friendly). To do that:
1- type [M-x] ('Alt' or 'Windows-key' with the 'x' key).
2- type "load" [Enter]
3- Enter the full path name to the script: /full/path/name/to/ps-scaler.scm
Enjoy !
Christophe.
(define (inside-postscript-p)
(equal? (tree-label (cursor-tree)) 'postscript))
(texmacs-modes (inside-postscript% (inside-postscript-p)))
; Return true if 'str' si a "magnification": i.e. "[*,/]number"
(define (magnification? str)
(let ((s (string-trim-both str)))
(if (or (string-starts? s "*") (string-starts? s "/"))
(if (number? (string->number (string-tail s 1)))
#t
#f)
#f)))
(define (magnification->number magnstr)
(let ((s (string-trim-both magnstr)))
(cond ((string-starts? s "*")
(if (number? (string->number (string-tail s 1)))
(string->number (string-tail s 1))
#f))
((string-starts? str "/")
(if (number? (string->number (string-tail s 1)))
(/ 1.0 (string->number (string-tail s 1)))
#f))
(#t #f))))
; Return the width of a postscript tree.
(define (postscript-width ps-tree)
(tree->string (tree-ref ps-tree 1)))
; Return the height of a postscript tree.
(define (postscript-height ps-tree)
(tree->string (tree-ref ps-tree 2)))
;set the scale width to 'w' (string) of a postscript tree.
(define (postscript-set-width! ps-tree w)
(tree-set! (tree-ref ps-tree) 1 w))
;set the height to 'h' (string) of a postscript tree.
(define (postscript-set-height! ps-tree h)
(tree-set! (tree-ref ps-tree) 2 h))
;scale the postscript width-scale by 's' (float)
(define (postscript-scale-width! ps-tree s)
(let* ((w (postscript-width ps-tree))
(nv w))
(cond ((equal? w "")
(set! nv (string-concatenate (list "*" (float->string s)))))
((magnification? w)
(set! nv (string-concatenate (list "*" (number->string (* s (magnification->number w)))))))
((length? w)
(set! nv (length-mult s w))))
(postscript-set-width! ps-tree nv)))
; Scale the postscript height-scale by 's' (float)
(define (postscript-scale-height! ps-tree s)
(let* ((h (postscript-height ps-tree))
(nv h))
(cond ((equal? h "")
(set! nv (string-concatenate (list "*" (float->string s)))))
((magnification? h)
(set! nv (string-concatenate (list "*" (number->string (* s (magnification->number h)))))))
((length? h)
(set! nv (length-mult s h))))
(postscript-set-height! ps-tree nv)))
; Scale the postscript height and width by 's' (float)
(define (postscript-scale-size ps-tree s)
(postscript-scale-width! ps-tree s)
(postscript-scale-height! ps-tree s))
(kbd-map (:mode inside-postscript?) ("C--" (postscript-scale-size (cursor-tree) 0.9)))
(kbd-map (:mode inside-postscript?) ("C-+" (postscript-scale-size (cursor-tree) 1.1)))
- [TeXmacs] A simple "quick postscript-scaler" plugin, Jalady Christophe, 10/26/2008
- [TeXmacs] fink, pir2.jv, 10/29/2008
- Re: [TeXmacs] fink, Martin Costabel, 10/29/2008
- [TeXmacs] installer texmacs : facile finalement, el.douwen, 10/31/2008
- Re: [TeXmacs] installer texmacs : facile finalement, Ingolf Schäfer, 10/31/2008
- [TeXmacs] installer texmacs : facile finalement, el.douwen, 10/31/2008
- Re: [TeXmacs] fink, Martin Costabel, 10/29/2008
- [TeXmacs] fink, pir2.jv, 10/29/2008
Archive powered by MHonArc 2.6.19.