[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to determine whether a char can be displayed or not

From: Kenichi Handa
Subject: Re: how to determine whether a char can be displayed or not
Date: Wed, 11 Oct 2000 14:17:43 +0900 (JST)

Dave Love <address@hidden> writes:
> "Eli Zaretskii" <address@hidden> writes:
>>  This should return non-nil for an ASCII font on all systems.  Also,
>>  calling fontset-font unconditionally will signal an error on systems
>>  which don't support fontsets (e.g., MS-DOS); 

> Shouldn't it just return nil, as on ttys?

On ttys, I think we should check terminal coding system.  I
attach my version of char-displayable-p at the tail.

>>  > - shouldn't this be implemented in C instead, reusing the existing
>>  >   font selection code, so as to be 100% sure of the answer ?

> I'd think so.

I think my code simulates what C code does fairly

>>  Is x-list-fonts slow?

> It presumably can be, depending on what it's matching, if it works
> like xlsfonts -- that can really thrash the X server.  It should
> probably limit itself to s single match in this application; I missed
> that.

As x-list-fonts uses XLoadQueryFonts, it is slow expecially
for two-byte character sets.  But, x-list-fonts stores the
result of each call in a cache, thus it won't be that slow
if called repeatedly with chars of the same charset.  If we
want to make it work fast even for the first call, we must
make another function, say font-exists-p, which does nothing
other than calling XListFonts.

Ken'ichi HANDA

(defun char-displayable-p (char)
  (cond ((< char 256)
         ;; Single byte characters are always displayable.
         ;; On a window system, a character is displayable if we have
         ;; a font for that character in the default face of the
         ;; currently selected frame.
         (let ((fontset (frame-parameter (selected-frame) 'font))
           (if (query-fontset fontset)
               (setq font-pattern (fontset-font fontset char)))
           (or font-pattern
               (setq font-pattern (fontset-font "fontset-default" char)))
           (if font-pattern
                 ;; Now FONT-PATTERN is a string or a cons of family
                 ;; field pattern and registry filed pattern.
                 (or (stringp font-pattern)
                     (setq font-pattern (concat (or (car font-pattern) "*")
                                                (cdr font-pattern))))
                 (x-list-fonts font-pattern 'default (selected-frame) 1)))))
         (let ((coding (terminal-coding-system)))
           (if coding
               (let ((safe-chars (coding-system-get coding 'safe-chars))
                     (safe-charsets (coding-system-get coding 'safe-charsets)))
                 (or (and safe-chars
                          (aref safe-chars char))
                     (and safe-charsets
                          (memq (char-charset char) safe-charsets)))))))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]