| 1 |
;; |
| 2 |
;; pl2ovp.scm |
| 3 |
;; (c) Norbert Preining 1997 |
| 4 |
;; This file is part of the otibet-package. |
| 5 |
;; |
| 6 |
;; Converting pl to ovp file with a certain shift amount. |
| 7 |
;; The FontDesignSize of the ovp-file can be given, also |
| 8 |
;; the FONTAT value of the FONTMAP entry |
| 9 |
;; |
| 10 |
;; IMPORTANT: LIGTABLE will be deleted (at the moment)!!!!!! |
| 11 |
;; |
| 12 |
;; Provides: |
| 13 |
;; (pl->ovp pl-filename ovp-filename shift ovp-designsize pl-at) |
| 14 |
;; |
| 15 |
;; pl-filename The name (with or without extansion) of the input |
| 16 |
;; ovp-filename The name (with or without extension) of the output |
| 17 |
;; shift The value a character in pl-filename will be shifted |
| 18 |
;; e.g.: in pl: (CHARACTER H 23 ...) |
| 19 |
;; shift = (hex->dec "1000") |
| 20 |
;; -> in ovp (CHARACTER H 1023 ... SETCHAR H 23 ...) |
| 21 |
;; ovp-designsize (DESIGNSIZE ...) |
| 22 |
;; pl-at (MAPFONT D 0 ...(FONTAT ...)) |
| 23 |
;; |
| 24 |
(load 'convnum.scm) |
| 25 |
|
| 26 |
(define (convert-to-dec number mode) |
| 27 |
(let ((num (if (number? number) |
| 28 |
(number->string number) |
| 29 |
(symbol->string number)))) |
| 30 |
(case (string-ref mode 0) |
| 31 |
(#\H (hex->dec num)) |
| 32 |
(#\O (oct->dec num)) |
| 33 |
(#\C (char->integer (string-ref num 0)))))) |
| 34 |
|
| 35 |
(define (list->sentence low) |
| 36 |
(if (= (length low) 1) |
| 37 |
(if (number? (car low)) |
| 38 |
(number->string (car low)) |
| 39 |
(symbol->string (car low))) |
| 40 |
(string-append (if (number? (car low)) |
| 41 |
(number->string (car low)) |
| 42 |
(symbol->string (car low))) |
| 43 |
" " |
| 44 |
(list->sentence (cdr low))))) |
| 45 |
|
| 46 |
(define nextitem '()) |
| 47 |
(define pl-fontdsize "") |
| 48 |
|
| 49 |
;; |
| 50 |
;; pl-read-header |
| 51 |
;; |
| 52 |
;; liest den pl-file header bis zum ersten CHARACTER ein |
| 53 |
;; LIGTABLE wird geloescht!!! |
| 54 |
(define (pl-read-header inf outf designsize) |
| 55 |
(let ((ni (if (= (length nextitem) 0) |
| 56 |
(let ((tmp (read inf))) |
| 57 |
(if (eof-object? tmp) |
| 58 |
(error 'pl-read-header "Cannot read from Infile") |
| 59 |
tmp)) |
| 60 |
nextitem))) |
| 61 |
(let ((tag (symbol->string (car ni)))) |
| 62 |
(cond |
| 63 |
((or (string=? tag "FAMILY") |
| 64 |
(string=? tag "COMMENT")) |
| 65 |
(format outf "~a~%" ni) |
| 66 |
(set! nextitem '()) |
| 67 |
(pl-read-header inf outf designsize)) |
| 68 |
((string=? tag "FONTDIMEN") |
| 69 |
(set! nextitem '()) |
| 70 |
(format outf "(FONTDIMEN~%~a )~%" |
| 71 |
(list-entries->string (cdr ni) " ")) |
| 72 |
(pl-read-header inf outf designsize)) |
| 73 |
((string=? tag "DESIGNSIZE") |
| 74 |
(set! nextitem '()) |
| 75 |
(set! pl-fontdsize (number->string (caddr ni))) |
| 76 |
(format outf "(DESIGNSIZE R ~a)~%" designsize) |
| 77 |
(pl-read-header inf outf designsize)) |
| 78 |
((string=? tag "CODINGSCHEME") |
| 79 |
(format outf "(CODINGSCHEME SHIFTED ~a)~%" (list->sentence (cdr ni))) |
| 80 |
(set! nextitem '()) |
| 81 |
(pl-read-header inf outf designsize)) |
| 82 |
((string=? tag "CHARACTER") |
| 83 |
(set! nextitem ni)) |
| 84 |
(else |
| 85 |
(set! nextitem '()) |
| 86 |
(pl-read-header inf outf designsize)))))) |
| 87 |
|
| 88 |
|
| 89 |
(define (ovp-write-font-mapping outf fontname fontat fontdsize) |
| 90 |
(format outf "(MAPFONT D 0~% (FONTNAME ~a)~% (FONTAT R ~a)~% (FONTDSIZE R ~a)~% )~%" fontname fontat fontdsize)) |
| 91 |
|
| 92 |
(define (list-entries->string lst head) |
| 93 |
(if (= (length lst) 0) |
| 94 |
"" |
| 95 |
(string-append (format #f "~a~a~%" head (car lst)) |
| 96 |
(list-entries->string (cdr lst) head)))) |
| 97 |
|
| 98 |
(define (pl-read-character inf outf shift) |
| 99 |
(let ((ni (if (= (length nextitem) 0) |
| 100 |
(read inf) |
| 101 |
nextitem))) |
| 102 |
(if (eof-object? ni) |
| 103 |
#t |
| 104 |
(letrec ((tag (symbol->string (car ni))) |
| 105 |
(mode (symbol->string (cadr ni))) |
| 106 |
(val (caddr ni)) |
| 107 |
(decval (convert-to-dec val mode)) |
| 108 |
(rs (if (number? shift) shift |
| 109 |
(let ((tmp (string->number shift))) |
| 110 |
(if (integer? tmp) tmp |
| 111 |
(error 'pl-read-character "Shift not an integer: ~a." shift))))) |
| 112 |
(restlst (cdddr ni))) |
| 113 |
(if (not (string=? tag "CHARACTER")) |
| 114 |
(error 'pl-read-character "Tag ~a wrong, not CHARACTER." tag) |
| 115 |
(begin |
| 116 |
(format outf |
| 117 |
"(~a H ~a~%~a (MAP~% (SELECTFONT D 0)~% (SETCHAR ~a ~a)~% )~% )~%" |
| 118 |
tag |
| 119 |
(dec->hex (+ decval rs)) |
| 120 |
(list-entries->string restlst " ") |
| 121 |
mode |
| 122 |
val) |
| 123 |
(set! nextitem '()) |
| 124 |
(pl-read-character inf outf shift))))))) |
| 125 |
|
| 126 |
(define (basename file ext) |
| 127 |
(letrec ((fl (string-length file)) |
| 128 |
(el (string-length ext)) |
| 129 |
(bi (- fl el)) |
| 130 |
(ei fl)) |
| 131 |
(begin |
| 132 |
(if (string=? (substring file bi ei) ext) |
| 133 |
(substring file 0 bi) |
| 134 |
file)))) |
| 135 |
|
| 136 |
;; |
| 137 |
;; MAIN FUNCTION |
| 138 |
;; |
| 139 |
;; pl->ovp pl-filename ovp-filename shift ovp-designsize pl-at |
| 140 |
;; |
| 141 |
;; pl-filename The name (with or without extansion) of the input |
| 142 |
;; ovp-filename The name (with or without extension) of the output |
| 143 |
;; shift The value a character in pl-filename will be shifted |
| 144 |
;; e.g.: in pl: (CHARACTER H 23 ...) |
| 145 |
;; shift = (hex->dec "1000") |
| 146 |
;; -> in ovp (CHARACTER H 1023 ... SETCHAR H 23 ...) |
| 147 |
;; ovp-designsize (DESIGNSIZE ...) |
| 148 |
;; pl-at (MAPFONT D 0 ...(FONTAT ...)) |
| 149 |
;; |
| 150 |
(define (pl->ovp pl-filename ovp-filename shift ovp-designsize pl-at) |
| 151 |
(letrec ((ifnb (basename pl-filename ".pl")) |
| 152 |
(ofnb (basename ovp-filename ".ovp")) |
| 153 |
(ifn (string-append ifnb ".pl")) |
| 154 |
(ofn (string-append ofnb ".ovp")) |
| 155 |
(inf (open-input-file ifn)) |
| 156 |
(outf (open-output-file ofn))) |
| 157 |
(pl-read-header inf outf ovp-designsize) |
| 158 |
(ovp-write-font-mapping outf |
| 159 |
ifnb |
| 160 |
pl-at |
| 161 |
pl-fontdsize) |
| 162 |
(pl-read-character inf outf shift) |
| 163 |
(close-input-port inf) |
| 164 |
(close-output-port outf))) |
| 165 |
|
| 166 |
; eof |