CLIM mail archive

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

text-style to font mapping algorithm



   X-External-Networks: yes
   Reply-To: meir@watson.ibm.com
   Date: Fri, 04 Dec 92 12:30:14 -0500
   From: "Meir Laker" <meir@watson.ibm.com>

   I have not yet received a reply to the following from Lucid.  So, I am
   submitting it also to the CLIM mailing list for help.  The question I
   pose regarding the CLIM algorithm for mapping text-styles to fonts is
   germane to all platforms and should be of interest to all readers.

Sorry for the delay.  It took me a while to get back up to speed on
all the font hair from JDI et. al.

   I have 2 questions / bugs:

   1. The text style '(:sans-serif :roman :normal) maps to:

      -linotype-helvetica-medium-r-normal--16-120-100-100-p-86-iso8859-2

   rather than to:

      -adobe-helvetica-medium-r-normal--14-140-75-75-p-77-iso8859-1

   even though the adobe font precedes the linotype font in the font path.

   This seems to indicate that somehow CLIM believes the linotype font to
   be a better mapping than the adobe font.  Could it be that the pixel
   size of 16 is "preferred" over 14 for :normal text-size?  What exactly
   is the algorithm used to map text styles to fonts in Lucid CLIM?

The order in which the fonts are found turns out to be irrelevant.
The code is trying to find the "best" font for a given style, by which
it means the one that it thinks comes closest to the size you
specified.  It does this by looking at each font that matches the text
style family (that is, all the "*-helvetica-*" fonts in your whole
search path) and calculating the actual screen size for the font.  The
calculation is based on the value of xlib:screen-height-in-millimeters
and the sizing and resolution information built into the font name.

Without knowing the screen-height-in-millimeters for your display I
can't run the calculation, but my theory is that the linotype font is
calculating out to be closer to 12 (the defined size for :NORMAL) than
the adobe font in your environment.

You can check that with the following code.  Give it a CLIM window and
an X font name and it returns the "pixel height" of the font.

(defun font-screen-size (win font)
  (let* ((disp (xlib:drawable-display (slot-value win 'clim::window)))
	 (screen (xlib:display-default-screen disp))
	 (screen-height (xlib:screen-height screen))
	 ;; Use a float value so formula below will be accurate.
	 (screen-pixels-per-inch
	  (* 25.4 (/ screen-height
		     (xlib:screen-height-in-millimeters screen)))))
    (let ((tokens (clim::disassemble-x-font-name font)))
      (when (> (length tokens) 10)
	(let* ((italic (member (fifth tokens) '("i" "o") :test #'equalp))
	       (bold (equalp (fourth tokens) "Bold"))
	       (face (if italic
			 (if bold '(:bold :italic) :italic)
			 (if bold :bold :roman)))
	       (designed-point-size (parse-integer (ninth tokens)))
	       (designed-y-resolution (parse-integer (nth 10 tokens)))
	       (point-size (* (float designed-point-size)
			      (/ designed-y-resolution
				 screen-pixels-per-inch)))
	       (size (/ point-size 10)))
	  size)))))

On my Sparc I get the following:
> (font-screen-size win "-linotype-helvetica-medium-r-normal--16-120-100-100-p-86-iso8859-2")
13.333333333333334
> (font-screen-size win "-adobe-helvetica-medium-r-normal--14-140-75-75-p-77-iso8859-1")
11.666666666666668
>

which appears to favor the adobe font for size :NORMAL.

I assume that the linotype fonts are new with the new AIX release, as
you weren't seeing them before.  Perhaps you could remove that font
directory from your font search path entirely?

Failing that, you will probably have to assert the font mappings that
you want explicitly, overriding the heuristic.

   2. According to the CLIM documentation, the :text-size attribute can
   be specified in "printer's points".  If so, the following would seem
   to be errors:

      A. '(:sans-serif :roman 14) maps to
	  -adobe-helvetica-medium-r-normal--18-180-75-75-p-98-iso8859-1
	  which is a point size of 180

That is the font that it thinks is closest to 14 pixels high on your
screen.  The "180" is the "designed point size" and the 75 is the
"designed resolution".

[I guess that I can calculate from that that your pixels-per-inch
value must be around 96, giving a pixel height of 12.4 for the
linotype font from bug 1 above and 10.8 for the adobe font]

      B. '(:sans-serif :roman 140) maps to
	  -adobe-courier-medium-r-normal--12-120-75-75-m-70-iso8859-1
	  which is a point size of 120.

   The latter case certainly seems wrong as it is seriffed.

The latter case is just returning you the "emergency backup font" it
uses when it can't satisfy your request.  Not only is it serif, it is
fixed-width.  This was deemed better than having end-user applications
blow out due to font lookup failures.

0,,

References:

Main Index | Thread Index