diff options
Diffstat (limited to '')
-rw-r--r-- | module/output/color.scm | 22 | ||||
-rw-r--r-- | module/vcomponent/vdir/save-delete.scm (renamed from module/output/vdir.scm) | 2 |
2 files changed, 23 insertions, 1 deletions
diff --git a/module/output/color.scm b/module/output/color.scm new file mode 100644 index 00000000..123d0ba2 --- /dev/null +++ b/module/output/color.scm @@ -0,0 +1,22 @@ +(define-module (output color) + ) + +;; Returns a color with good contrast to the given background color. +;; https://stackoverflow.com/questions/1855884/determine-font-color-based-on-background-color/1855903#1855903 +(define-public (calculate-fg-color c) + (catch #t + (lambda () + (define (str->num c n) (string->number (substring/shared c n (+ n 2)) 16)) + ;; (format (current-error-port) "COLOR = ~s~%" c) + (let ((r (str->num c 1)) + (g (str->num c 3)) + (b (str->num c 5))) + (if (< 1/2 (/ (+ (* 0.299 r) + (* 0.587 g) + (* 0.114 b)) + #xFF)) + "#000000" "#FFFFFF"))) + (lambda args + (format (current-error-port) "Error calculating foreground color?~%~s~%" args) + "#FF0000" + ))) diff --git a/module/output/vdir.scm b/module/vcomponent/vdir/save-delete.scm index 2541f0f9..02db9d7a 100644 --- a/module/output/vdir.scm +++ b/module/vcomponent/vdir/save-delete.scm @@ -9,7 +9,7 @@ ;;; Code: -(define-module (output vdir) +(define-module (vcomponent vdir save-delete) :use-module (util) :use-module (vcomponent ical output) :use-module (vcomponent) |