DSSSL Library Reference: Part of the Modular DocBook Stylesheet distribution
Prev |  | Next

# measurement-to-length

## Name

measurement-to-length -- Convert a measurement to a length

## Synopsis

    (measurement-to-length measure)

## Description

Given a string containing a measurement, return that measurement as a length.

## Example

`"2.5cm"` returns 2.5cm as a length. `"3.4barleycorn"` returns 6.8pi.

## Author

Norman Walsh, <ndw@nwalsh.com>

## Source Code

    (define (measurement-to-length measure)
      ;; Convert a measurement to a length
      (let* ((pm (car (parse-measurement measure)))
    	 (pu (car (cdr (parse-measurement measure))))
    	 (magnitude (if pm pm "1"))
    	 (units     (if pu pu (if pm "pt" "default")))
    	 (unitconv  (assoc units unit-conversion-alist))
    	 (factor    (if unitconv (car (cdr unitconv)) 1pt)))
        (* (string->number magnitude) factor)))

Prev | Home | Next
unit-conversion-alist | Up | dingbat