Carbon / reported font width wrong?

2005-11-11 Thread David Reitter
In the Carbon port (current CVS), fontset-info or frame-char-width  
report wrong pixel widths for fonts.
In the example below, two fontsets are created. The I set the frame  
font (to load the font) and compare reported character width with  
(frame-char-width).


From my understanding of the documentation, the two should be the  
same - but they differ.


Please correct me if my understanding is wrong and this is not a bug.  
In that case it'd be helpful to know how to determine the height and  
normal width of characters in a fontset before the fontset is  
actually loaded. The reason why I'd like to do this is to change the  
font of a given frame without changing its pixel size (or at least  
with only minimal changes in pixel size). For this, I need to  
calculate the new (character-based) width and height using the old  
ones and the old and new font character dimensions.


Thanks
D

---

(defun create-aquamacs-fontset (maker name weight variety style  
sizes  optional fontsetname)
  Create a mac fontset with the given properties (leave nil to  
under-specify).
SIZES is a list of integers, indicating the desired font sizes in  
points.
Errors are signalled with ``signal-font-error'', unless ''ignore-font- 
errors''

is non-nil. (This function is part of Aquamacs and subject to change.)
  (message (concat Defining fontset:  (or fontsetname name)))
  (condition-case e
  (dolist (size sizes)

(create-fontset-from-mac-roman-font
 (format -%s-%s-%s-%s-%s-*-%s-*-*-*-*-*-mac-roman
 (or maker *)
 (or name *)
 (or weight *)
 (or variety *)
 (or style *)
 size
 )
 nil
 (concat (or fontsetname name) (int-to-string size))
 )
)
(error (signal-font-error e)))

)

(create-aquamacs-fontset
apple lucida grande* medium r normal '(9 10 11 12 13 14 16  
18) lucida )

(create-aquamacs-fontset
apple monaco* medium r normal '(9 10 11 12 13 14 16 18)  
monaco )



(set-frame-font fontset-lucida13)
(fontset-info fontset-lucida13)
;; SIZE is the maximum bound width of ASCII font in the fontset,
;; first element of vector is 15 (width in pixels)
(frame-char-width)


(set-frame-font fontset-monaco12)
(fontset-info fontset-monaco12)
;; width reported is 8
(frame-char-width)
;; real width is 7


___
Emacs-pretest-bug mailing list
Emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: Carbon / reported font width wrong?

2005-11-11 Thread YAMAMOTO Mitsuharu
 On Fri, 11 Nov 2005 15:50:14 +, David Reitter [EMAIL PROTECTED] 
 said:

 In the Carbon port (current CVS), fontset-info or frame-char-width
 report wrong pixel widths for fonts.  In the example below, two
 fontsets are created. The I set the frame font (to load the font)
 and compare reported character width with (frame-char-width).

  From my understanding of the documentation, the two should be the
 same - but they differ.

They are not necessarily the same: the former is the maximum width,
and the latter is the average width.

The reason why they are not the same even in a fixed-width font is
that the maximum metrics are confused by characters missing in the
font.  One way to avoid this is to define maximum/minimum metrics as
those among ASCII characters.  This is what ATSUI support code is
doing.

 YAMAMOTO Mitsuharu
[EMAIL PROTECTED]

Index: src/macterm.c
===
RCS file: /cvsroot/emacs/emacs/src/macterm.c,v
retrieving revision 1.142
diff -c -r1.142 macterm.c
*** src/macterm.c   11 Nov 2005 16:33:44 -  1.142
--- src/macterm.c   12 Nov 2005 05:31:57 -
***
*** 7572,7577 
--- 7572,7584 
  SetRect (max_bounds, 0, 0, 0, 0);
  for (c = 0x20; c = 0xff; c++)
{
+ if (c == 0x7f)
+   {
+ STORE_XCHARSTRUCT (font-min_bounds, min_width, min_bounds);
+ STORE_XCHARSTRUCT (font-max_bounds, max_width, max_bounds);
+ continue;
+   }
+ 
  ch = c;
  char_width = CharWidth (ch);
  QDTextBounds (1, ch, char_bounds);
***
*** 7594,7601 
  UnionRect (max_bounds, char_bounds, max_bounds);
}
}
- STORE_XCHARSTRUCT (font-min_bounds, min_width, min_bounds);
- STORE_XCHARSTRUCT (font-max_bounds, max_width, max_bounds);
  if (min_width == max_width
   max_bounds.left = 0  max_bounds.right = max_width)
{
--- 7601,7606 


___
Emacs-pretest-bug mailing list
Emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug