From e3db95da66da9c4c23d764e9fd3e830c3d76ab53 Mon Sep 17 00:00:00 2001
From: Arun Isaac
Date: Mon, 28 Aug 2023 22:11:54 +0100
Subject: html: Implement font using CSS.

The <font> tag is deprecated in HTML5.

* src/guile/skribilo/engine/html.scm (font): Implement using CSS only.
---
 src/guile/skribilo/engine/html.scm | 59 +++++++++++++++++++++-----------------
 1 file changed, 33 insertions(+), 26 deletions(-)

(limited to 'src')

diff --git a/src/guile/skribilo/engine/html.scm b/src/guile/skribilo/engine/html.scm
index 0425cab..5072f4a 100644
--- a/src/guile/skribilo/engine/html.scm
+++ b/src/guile/skribilo/engine/html.scm
@@ -1646,34 +1646,41 @@ ignored, return #f."
 (markup-writer 'font
    :options '(:size :face)
    :before (lambda (node engine)
-	      (let ((size (markup-option node :size))
-		    (face (markup-option node :face)))
-		 (when (and (number? size) (inexact? size))
-		    (let ((s (if (> size 0) 'big 'small))
-			  (d (if (> size 0) 1 -1)))
-		       (do ((i (inexact->exact size) (- i d)))
-			   ((= i 0))
-                           (html-open s))))
-		 (when (or (and (number? size) (exact? size)) face)
-                   (html-open 'font
-                              `((class . ,(markup-class node))
-                                (size . ,(and (number? size)
-                                              (exact? size)
-                                              (not (zero? size))
-                                              size))
-                                (face . ,face))))))
-   :after (lambda (node engine)
 	     (let ((size (markup-option node :size))
 		   (face (markup-option node :face)))
-		(when (or (and (number? size) (exact? size) (not (= size 0)))
-			  face)
-                  (html-close 'font))
-		(when (and (number? size) (inexact? size))
-		   (let ((s (if (> size 0) 'big 'small))
-			 (d (if (> size 0) 1 -1)))
-		      (do ((i (inexact->exact size) (- i d)))
-			  ((= i 0))
-                          (html-close s)))))))
+               ;; Set font face and size if absolute.
+               (html-open 'span
+                          `((class . ,(markup-class node))
+                            (style . ,(style-declaration
+                                       `((font-family . ,face)
+                                         (font-size . ,(and size
+                                                            (positive? size)
+                                                            (exact? size)
+                                                            (string-append (number->string size)
+                                                                           "px"))))))))
+               ;; If size is relative, add a number of <span> tags
+               ;; with larger/smaller font-size styles.
+               (when (and size
+                          (or (and (positive? size)
+                                   (inexact? size))
+                              (negative? size)))
+                 (for-each (lambda _
+                             (html-open 'span
+                                        `((style . ,(style-declaration
+                                                     `((font-size . ,(if (positive? size)
+                                                                         "larger"
+                                                                         "smaller"))))))))
+                           (iota (abs (inexact->exact size)))))))
+   :after (lambda (node engine)
+	    (let ((size (markup-option node :size)))
+              (when (and size
+                         (or (and (positive? size)
+                                  (inexact? size))
+                             (negative? size)))
+                (for-each (lambda _
+                            (html-close 'span))
+                          (iota (abs (inexact->exact size)))))
+              (html-close 'span))))
 
 ;*---------------------------------------------------------------------*/
 ;*    flush ...                                                        */
-- 
cgit 1.4.1