Changeset 2488

Show
Ignore:
Timestamp:
02/13/08 21:22:21 (1 year ago)
Author:
hhubner
Message:

Fixes for templater and toplevel, BOS templates now work a bit better.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/trunk-reorg/bknr/web/src/images/imageproc-handler.lisp

    r2430 r2488  
    1717(defun apply-imageproc-operation (operation-name args image) 
    1818  (apply (or (gethash (make-keyword-from-string operation-name) *imageproc-operations*) 
    19             (error "invalid imageproc operation name ~A" operation-name)) 
    20         image args)) 
     19             (error "invalid imageproc operation name ~A" operation-name)) 
     20        image args)) 
    2121 
    2222(defun imageproc (image operations) 
     
    2525    (let ((working-image input-image)) 
    2626      (dolist (operation operations) 
    27        (destructuring-bind (operation-name &rest args) (substitute nil "" (split "," operation) :test #'equal) 
    28          (let ((returned-image (apply-imageproc-operation operation-name args working-image))) 
    29            (unless (not returned-image) 
    30              (unless (or (eq working-image returned-image) 
    31                          (eq working-image input-image)) 
    32                (destroy-image working-image)) 
    33              (setf working-image returned-image))))) 
     27        (destructuring-bind (operation-name &rest args) (substitute nil "" (split "," operation) :test #'equal) 
     28          (let ((returned-image (apply-imageproc-operation operation-name args working-image))) 
     29            (unless (not returned-image) 
     30              (unless (or (eq working-image returned-image) 
     31                          (eq working-image input-image)) 
     32                (destroy-image working-image)) 
     33              (setf working-image returned-image))))) 
    3434      (when (and (true-color-p working-image) 
    35                 (not (true-color-p input-image))) 
    36        (true-color-to-palette :dither t :image working-image :colors-wanted 256)) 
     35                (not (true-color-p input-image))) 
     36        (true-color-to-palette :dither t :image working-image :colors-wanted 256)) 
    3737      (let ((stream (send-headers))) 
    38        (setf (flex:flexi-stream-element-type stream) 'flex:octet) 
    39        (write-image-to-stream stream (image-type-keyword image) :image working-image)) 
     38        (setf (flex:flexi-stream-element-type stream) 'flex:octet) 
     39        (write-image-to-stream stream (image-type-keyword image) :image working-image)) 
    4040      (unless (eq working-image input-image) 
    41        (destroy-image working-image))))) 
     41        (destroy-image working-image))))) 
    4242 
    4343#+(or) 
     
    4545  (when (true-color-p input-image) 
    4646    (true-color-to-palette :dither t :image input-image 
    47                       :colors-wanted 256))) 
     47                           :colors-wanted 256))) 
    4848 
    4949(defparameter *cell-border-width* 5) 
     
    5555  (setq border-width (if border-width (parse-integer border-width) *cell-border-width*)) 
    5656  (let* ((width (image-width input-image)) 
    57         (height (image-height input-image)) 
    58         (ratio (max (/ width (- cell-width (* border-width 2))) 
    59                     (/ height (- cell-height (* border-width 2))))) 
    60         (thumbnail-width (min width (round (/ width ratio)))) 
    61         (thumbnail-height (min height (round (/ height ratio)))) 
    62         (x-offset (round (/ (- cell-width thumbnail-width) 2))) 
    63         (y-offset (round (/ (- cell-height thumbnail-height) 2))) 
    64         (cell (create-image cell-width cell-height t))) 
     57        (height (image-height input-image)) 
     58        (ratio (max (/ width (- cell-width (* border-width 2))) 
     59                     (/ height (- cell-height (* border-width 2))))) 
     60        (thumbnail-width (min width (round (/ width ratio)))) 
     61        (thumbnail-height (min height (round (/ height ratio)))) 
     62        (x-offset (round (/ (- cell-width thumbnail-width) 2))) 
     63        (y-offset (round (/ (- cell-height thumbnail-height) 2))) 
     64        (cell (create-image cell-width cell-height t))) 
    6565    (with-default-image (cell) 
    6666      (let ((color (if bgcolor 
    67                       (parse-color bgcolor) 
    68                       (allocate-color 255 255 255)))) 
    69        (fill-image 0 0 :color color) 
    70        (copy-image input-image cell 
    71                    0 0 
    72                    x-offset 
    73                    y-offset 
    74                    width height 
    75                    :resize t :resample t 
    76                    :dest-width thumbnail-width :dest-height thumbnail-height) 
    77        (unless bgcolor 
    78          (setf (transparent-color) color) 
    79          (let ((cr (ldb (byte 8 16) color)) 
    80                (cg (ldb (byte 8 8) color)) 
    81                (cb (ldb (byte 8 0) color))) 
    82            (flet ((color-distance (c) 
    83                     (+ (abs (- (ldb (byte 8 16) c) cr)) 
    84                        (abs (- (ldb (byte 8 8) c) cg)) 
    85                        (abs (- (ldb (byte 8 0) c) cb))))) 
    86              (do-pixels () 
    87                (when (< (color-distance (raw-pixel)) 6) 
    88                  (setf (raw-pixel) color)))))))) 
     67                       (parse-color bgcolor) 
     68                       (allocate-color 255 255 255)))) 
     69        (fill-image 0 0 :color color) 
     70        (copy-image input-image cell 
     71                    0 0 
     72                    x-offset 
     73                    y-offset 
     74                    width height 
     75                    :resize t :resample t 
     76                    :dest-width thumbnail-width :dest-height thumbnail-height) 
     77        (unless bgcolor 
     78          (setf (transparent-color) color) 
     79          (let ((cr (ldb (byte 8 16) color)) 
     80                (cg (ldb (byte 8 8) color)) 
     81                (cb (ldb (byte 8 0) color))) 
     82            (flet ((color-distance (c) 
     83                     (+ (abs (- (ldb (byte 8 16) c) cr)) 
     84                        (abs (- (ldb (byte 8 8) c) cg)) 
     85                        (abs (- (ldb (byte 8 0) c) cb))))) 
     86              (do-pixels () 
     87                (when (< (color-distance (raw-pixel)) 6) 
     88                  (setf (raw-pixel) color)))))))) 
    8989    cell)) 
    9090   
     
    9494  (setf max-height (if max-height (parse-integer max-height) *thumbnail-max-height*)) 
    9595  (let ((width (image-width input-image)) 
    96        (height (image-height input-image))) 
     96        (height (image-height input-image))) 
    9797    (when (or (< max-width width) 
    98              (< max-height height)) 
     98              (< max-height height)) 
    9999      (let* ((ratio (max (/ width max-width) 
    100                         (/ height max-height))) 
    101             (thumbnail-width (round (/ width ratio))) 
    102             (thumbnail-height (round (/ height ratio))) 
    103             (thumbnail (create-image thumbnail-width 
    104                                      thumbnail-height 
    105                                      t))) 
    106        (with-default-image (thumbnail) 
    107          (fill-image 0 0 :color (parse-color bgcolor)) 
    108          (copy-image input-image thumbnail 
    109                      0 0 0 0 
    110                      width height 
    111                      :resize t :resample t 
    112                      :dest-width thumbnail-width :dest-height thumbnail-height)) 
    113        thumbnail)))) 
     100                        (/ height max-height))) 
     101             (thumbnail-width (round (/ width ratio))) 
     102             (thumbnail-height (round (/ height ratio))) 
     103             (thumbnail (create-image thumbnail-width 
     104                                      thumbnail-height 
     105                                      t))) 
     106        (with-default-image (thumbnail) 
     107          (fill-image 0 0 :color (parse-color bgcolor)) 
     108          (copy-image input-image thumbnail 
     109                      0 0 0 0 
     110                      width height 
     111                      :resize t :resample t 
     112                      :dest-width thumbnail-width :dest-height thumbnail-height)) 
     113        thumbnail)))) 
    114114 
    115115(define-imageproc-handler double (input-image &optional (times "2")) 
    116116  (let* ((width (image-width input-image)) 
    117         (height (image-height input-image)) 
    118         (ratio (/ 1 (parse-integer times))) 
    119         (double-image-width (round (/ width ratio))) 
    120         (double-image-height (round (/ height ratio))) 
    121         (double-image (create-image double-image-width double-image-height nil))) 
     117        (height (image-height input-image)) 
     118        (ratio (/ 1 (parse-integer times))) 
     119        (double-image-width (round (/ width ratio))) 
     120        (double-image-height (round (/ height ratio))) 
     121        (double-image (create-image double-image-width double-image-height nil))) 
    122122    (with-default-image (double-image) 
    123123      (setf (transparent-color double-image) 
    124            (find-color-from-image (transparent-color input-image) input-image :alpha t :resolve t)) 
     124            (find-color-from-image (transparent-color input-image) input-image :alpha t :resolve t)) 
    125125      (fill-image 0 0 :color (transparent-color double-image)) 
    126126      (copy-image input-image double-image 
    127                  0 0 0 0 width height 
    128                  :resize t 
    129                  :dest-width double-image-width :dest-height double-image-height)) 
     127                  0 0 0 0 width height 
     128                  :resize t 
     129                  :dest-width double-image-width :dest-height double-image-height)) 
    130130    double-image)) 
    131131 
     
    133133  (with-default-image (input-image) 
    134134    (let ((colors (loop for (old new) on color-mappings by #'cddr 
    135                        collect (cons (parse-color old) (parse-color new))))) 
     135                        collect (cons (parse-color old) (parse-color new))))) 
    136136      (do-pixels (input-image) 
    137        (let ((new-color (assoc (ldb (byte 24 0) (raw-pixel)) colors))) 
    138          (when (cdr new-color) 
    139            (setf (raw-pixel) (cdr new-color))))))) 
     137        (let ((new-color (assoc (ldb (byte 24 0) (raw-pixel)) colors))) 
     138          (when (cdr new-color) 
     139            (setf (raw-pixel) (cdr new-color))))))) 
    140140  input-image) 
    141141 
     
    147147      (transparent-color image) 
    148148      (let ((components (multiple-value-bind (match strings) 
    149                            (scan-to-strings "^#?(..)(..)(..)?$" color-string) 
    150                          (if match 
    151                              (mapcar #'(lambda (string) (when string (parse-integer string :radix 16))) 
    152                                      (coerce strings 'list)) 
    153                              (progn 
    154                                (warn "can't parse color spec ~a" color-string) 
    155                                '(0 0 0)))))) 
    156        (let ((color (find-color (first components) (second components) (third components) 
    157                                 :exact t :image image))) 
    158          (unless color 
    159            (setf color (find-color (first components) (second components) (third components) 
    160                                    :exact nil :resolve t :image image))) 
    161          color)))) 
     149                            (scan-to-strings "^#?(..)(..)(..)?$" color-string) 
     150                          (if match 
     151                              (mapcar #'(lambda (string) (when string (parse-integer string :radix 16))) 
     152                                      (coerce strings 'list)) 
     153                              (progn 
     154                                (warn "can't parse color spec ~a" color-string) 
     155                                '(0 0 0)))))) 
     156        (let ((color (find-color (first components) (second components) (third components) 
     157                                :exact t :image image))) 
     158          (unless color 
     159            (setf color (find-color (first components) (second components) (third components) 
     160                                    :exact nil :resolve t :image image))) 
     161          color)))) 
    162162 
    163163(defclass imageproc-handler (image-handler) 
     
    175175  (with-http-response (:content-type (image-content-type (image-type-keyword image))) 
    176176    (let ((ims (header-in :if-modified-since)) 
    177          (changed-time (blob-timestamp image))) 
     177          (changed-time (blob-timestamp image))) 
    178178      (setf (header-out :last-modified) (rfc-1123-date changed-time)) 
    179        (if (and ims 
    180                 (<= changed-time (date-to-universal-time ims))) 
    181            (progn 
    182              (setf (return-code) +http-not-modified+) 
    183              (format t "; image ~A not changed~%" image) 
    184              (with-http-body ())) 
    185            (with-http-body () 
    186              (imageproc image (cdr (decoded-handler-path page-handler)))))))) 
     179      (if (and ims 
     180              (<= changed-time (date-to-universal-time ims))) 
     181          (progn 
     182            (setf (return-code) +http-not-modified+) 
     183            (format t "; image ~A not changed~%" image) 
     184            (with-http-body ())) 
     185          (with-http-body () 
     186            (imageproc image (cdr (decoded-handler-path page-handler)))))))) 
    187187     
  • branches/trunk-reorg/bknr/web/src/web/tags.lisp

    r2438 r2488  
    55(defvar *toplevel-children*) 
    66 
    7 (define-bknr-tag toplevel (&key children title (template "toplevel")) 
     7(define-bknr-tag toplevel (&key title (template "toplevel")) 
    88  (setf (get-template-var :title) title) 
    99  (when (and (not (scan "^/" template)) 
     
    1515         (pathname (find-template-pathname expander template)) 
    1616         (toplevel (get-cached-template pathname expander)) 
    17          (*toplevel-children* children)) 
    18     (emit-template-node toplevel))) 
     17         (*toplevel-children* *tag-children*)) 
     18    (emit-template-node *template-expander* toplevel))) 
    1919 
    2020(define-bknr-tag tag-body () 
  • branches/trunk-reorg/projects/bos/web/webserver.lisp

    r2484 r2488  
    196196  (setf *worldpay-test-mode* worldpay-test-mode) 
    197197  (setf bknr.web:*upload-file-size-limit* 20000000) 
     198  (setf hunchentoot::*hunchentoot-default-external-format* (flex:make-external-format :utf-8 :eol-style :lf)) 
    198199 
    199200  (make-instance 'bos-website 
  • branches/trunk-reorg/projects/quickhoney/src/imageproc.lisp

    r1415 r2488  
    55(define-imageproc-handler cutout-button (input-image &optional keyword (background-color "ffffff")) 
    66  (let ((button-image (create-image *button-size* *button-size* t)) 
    7        (square-size (min (image-width input-image) (image-height input-image))) 
    8        (x-offset (if (> (image-width input-image) (image-height input-image)) 
    9                      (round (/ (- (image-width input-image) (image-height input-image)) 2)) 
    10                      0))) 
     7        (square-size (min (image-width input-image) (image-height input-image))) 
     8        (x-offset (if (> (image-width input-image) (image-height input-image)) 
     9                      (round (/ (- (image-width input-image) (image-height input-image)) 2)) 
     10                      0))) 
    1111    (copy-image input-image button-image 
    12                x-offset 0 
    13                0 0 
    14                square-size square-size 
    15                :resize t :resample t 
    16                :dest-width *button-size* :dest-height *button-size*) 
     12                x-offset 0 
     13                0 0 
     14                square-size square-size 
     15                :resize t :resample t 
     16                :dest-width *button-size* :dest-height *button-size*) 
    1717    (when keyword 
    1818      (let ((type-store-image (store-image-with-name (format nil "type-~(~A~)" keyword)))) 
    19        (unless type-store-image 
    20          (error "can't find type image for keyword ~A" keyword)) 
    21        (with-store-image (type-image type-store-image) 
    22          (copy-image type-image button-image 
    23                      0 0 
    24                      0 0 
    25                      (image-width type-image) (image-height type-image))))) 
     19        (unless type-store-image 
     20          (error "can't find type image for keyword ~A" keyword)) 
     21        (with-store-image (type-image type-store-image) 
     22          (copy-image type-image button-image 
     23                      0 0 
     24                      0 0 
     25                      (image-width type-image) (image-height type-image))))) 
    2626    (with-store-image (mask-image (store-image-with-name "button-mask")) 
    27       #-(or) ;; notyet 
    2827      (let ((color (parse-color background-color :image mask-image)) 
    29            (white (parse-color "ffffff" :image mask-image))) 
    30        (do-pixels (mask-image) 
    31          (if (eql (ldb (byte 24 0) (raw-pixel)) white) 
    32              (setf (raw-pixel) color)))) 
     28            (white (parse-color "ffffff" :image mask-image))) 
     29        (do-pixels (mask-image) 
     30          (when t (eql (ldb (byte 24 0) (raw-pixel)) white) 
     31              (setf (raw-pixel) color)))) 
    3332      (copy-image mask-image button-image 
    34                  0 0 
    35                  0 0 
    36                  *button-size* *button-size*)) 
     33                  0 0 
     34                  0 0 
     35                  *button-size* *button-size*)) 
    3736    button-image)) 
    3837 
  • branches/trunk-reorg/projects/quickhoney/src/tags.lisp

    r2438 r2488  
    33(define-bknr-tag version-and-last-change (&rest args) 
    44  (format *debug-io* "hello world: ~A~%" args) 
    5   (html "v1.1 | updated " (:princ-safe (string-downcase 
    6                                         (substitute #\Space #\- 
    7                                                     (format-date-time (last-image-upload-timestamp) :vms-style t :show-time nil)))))) 
     5  (html "v1.1 | updated " 
     6        (:princ-safe (string-downcase 
     7                      (substitute #\Space #\- 
     8                                  (format-date-time (last-image-upload-timestamp) 
     9                                                    :vms-style t :show-time nil)))))) 
  • branches/trunk-reorg/xhtmlgen/xhtmlgen.lisp

    r2480 r2488  
    130130(defun emit-without-quoting (str) 
    131131  ;; das ist fuer WPDISPLAY 
     132  (format t "emit-without-quoting does not work~%") 
     133  #+(or) 
    132134  (let ((s (cxml::chained-handler *html-sink*))) 
    133135    (cxml::maybe-close-tag s)