Skip to content

Commit

Permalink
Merge pull request #1739 from funk443/zero-width
Browse files Browse the repository at this point in the history
Lem SDL2 can now properly display zero-width characters.
  • Loading branch information
cxxxr authored Jan 9, 2025
2 parents 8d4c9be + 1e42f96 commit 0d2ce9f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
12 changes: 6 additions & 6 deletions frontends/sdl2/display.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@
((eq type :braille)
(display-braille-font display))
(bold
(if (eq type :latin)
(display-latin-bold-font display)
(display-cjk-bold-font display)))
(case type
((:latin :zero-width) (display-latin-bold-font display))
(otherwise (display-cjk-bold-font display))))
(t
(if (eq type :latin)
(display-latin-font display)
(display-cjk-normal-font display)))))
(case type
((:latin :zero-width) (display-latin-font display))
(otherwise (display-cjk-normal-font display))))))

(defmethod scaled-char-width ((display display) x)
(let ((scale-x (round (first (display-scale display)))))
Expand Down
7 changes: 5 additions & 2 deletions src/attribute.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
:background (or (attribute-background over)
(attribute-background under))
:bold (or (attribute-bold over)
(attribute-bold under))
(attribute-bold under))
:reverse (or (attribute-reverse over)
(attribute-reverse under))
(attribute-reverse under))
:underline (or (attribute-underline over)
(attribute-underline under))
:plist (append (attribute-plist over)
Expand Down Expand Up @@ -196,6 +196,9 @@

(define-attribute truncate-attribute)

(define-attribute special-char-attribute
(t :foreground "red"))

(define-attribute compiler-note-attribute
(t :underline "red"))

Expand Down
7 changes: 6 additions & 1 deletion src/display/char-type.lisp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(in-package :lem-core)

(deftype char-type ()
'(member :latin :cjk :braille :emoji :icon :control))
'(member :latin :cjk :braille :emoji :icon :control :zero-width))

(defun cjk-char-code-p (code)
(or (<= #x4E00 code #x9FFF)
Expand All @@ -27,6 +27,9 @@
(defun icon-char-code-p (code)
(icon-value code :font))

(defun zero-width-char-code-p (code)
(or (<= #x200B code #x200D) (= code #xFEFF)))

(defun char-type (char)
(let ((code (char-code char)))
(cond ((control-char char)
Expand All @@ -47,5 +50,7 @@
:emoji)
((icon-code-p code)
:latin)
((zero-width-char-code-p code)
:zero-width)
(t
:cjk))))
17 changes: 13 additions & 4 deletions src/display/physical-line.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,19 @@
(:emoji 'emoji-object)
(:control 'control-character-object)
(otherwise 'text-object))
:string (if (eq type :control)
(control-char (char string 0))
string)
:attribute attribute
:string (case type
(:control
(control-char (char string 0)))
(:zero-width
(make-string (length string) :initial-element #\·))
(otherwise
string))
:attribute (case type
((:control :zero-width)
(merge-attribute attribute
(ensure-attribute 'special-char-attribute nil)))
(otherwise
attribute))
:type type
:within-cursor (and attribute
(cursor-attribute-p attribute)))))
Expand Down

0 comments on commit 0d2ce9f

Please sign in to comment.