annotate src/nsfont.m @ 97430:d76aacb7f6e4

(c-emacs-features): Check beginning-of-defun-raw instead of beginning-of-defun, and avoid moving point during the test.
author Chong Yidong <cyd@stupidchicken.com>
date Mon, 11 Aug 2008 21:38:04 +0000
parents cf43f4e3ecc8
children 06f7d5858c5a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1 /* Font back-end driver for the NeXT/Open/GNUstep and MacOSX window system.
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
2 See font.h
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
3 Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
4
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
5 This file is part of GNU Emacs.
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
6
96692
6fad3f85eab7 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 96689
diff changeset
7 GNU Emacs is free software: you can redistribute it and/or modify
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
96692
6fad3f85eab7 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 96689
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
6fad3f85eab7 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 96689
diff changeset
10 (at your option) any later version.
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
11
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
12 GNU Emacs is distributed in the hope that it will be useful,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
15 GNU General Public License for more details.
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
16
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
96692
6fad3f85eab7 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 96689
diff changeset
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
19
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
20 Author: Adrian Robert (arobert@cogsci.ucsd.edu)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
21 */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
22
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
23 #include "config.h"
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
24
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
25 #include "lisp.h"
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
26 #include "dispextern.h"
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
27 #include "composite.h"
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
28 #include "blockinput.h"
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
29 #include "charset.h"
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
30 #include "frame.h"
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
31 #include "window.h"
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
32 #include "fontset.h"
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
33 #include "nsterm.h"
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
34 #include "frame.h"
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
35 #include "character.h"
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
36 #include "font.h"
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
37
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
38 #define NSFONT_TRACE 0
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
39
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
40 extern Lisp_Object Qns;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
41 extern Lisp_Object Qnormal, Qbold, Qitalic, Qcondensed, Qexpanded;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
42 static Lisp_Object Qapple, Qroman, Qmedium;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
43 extern Lisp_Object ns_expand_space;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
44 extern Lisp_Object Qappend;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
45 extern int ns_antialias_text, ns_use_qd_smoothing;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
46 extern float ns_antialias_threshold;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
47 extern int ns_tmp_flags;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
48 extern struct nsfont_info *ns_tmp_font;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
49
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
50 /* font glyph and metrics caching functions, implemented at end */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
51 static void ns_uni_to_glyphs (struct nsfont_info *font_info,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
52 unsigned char block);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
53 static void ns_glyph_metrics (struct nsfont_info *font_info,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
54 unsigned char block);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
55
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
56
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
57 /* ==========================================================================
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
58
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
59 Utilities
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
60
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
61 ========================================================================== */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
62
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
63
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
64 /* Replace spaces w/another character so emacs core font parsing routines
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
65 aren't thrown off. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
66 static void
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
67 nsfont_escape_name (char *name)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
68 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
69 int i =0, len =strlen (name);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
70 for ( ; i<len; i++)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
71 if (name[i] == ' ')
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
72 name[i] = '_';
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
73 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
74
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
75
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
76 /* Reconstruct spaces in a font family name passed through emacs. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
77 static void
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
78 nsfont_unescape_name (char *name)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
79 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
80 int i =0, len =strlen (name);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
81 for ( ; i<len; i++)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
82 if (name[i] == '_')
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
83 name[i] = ' ';
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
84 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
85
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
86
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
87 /* Extract family name from a font spec. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
88 static NSString *
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
89 nsfont_get_family (Lisp_Object font_spec)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
90 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
91 Lisp_Object tem = AREF (font_spec, FONT_FAMILY_INDEX);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
92 if (NILP (tem))
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
93 return nil;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
94 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
95 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
96 char *tmp = strdup (SDATA (SYMBOL_NAME (tem)));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
97 NSString *family;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
98 nsfont_unescape_name (tmp);
96892
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
99 /* TODO: this seems to be needed only for font names that are
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
100 hard-coded into emacs, like 'helvetica' for splash screen */
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
101 if (tmp)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
102 tmp[0] = toupper (tmp[0]);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
103 family = [NSString stringWithUTF8String: tmp];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
104 free (tmp);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
105 return family;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
106 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
107 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
108
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
109
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
110 /* Converts FONT_WEIGHT, FONT_SLANT, FONT_WIDTH to NSFont traits. */
96892
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
111 /* TODO (20080601): The font backend's strategy for handling font
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
112 styles continues to evolve. When/if this stabilizes, we
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
113 can change the code here to be more sophisticated and accurate.
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
114 For now, we rely on "normal/plain" style being numeric 100. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
115 #define STYLE_REF 100
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
116 static unsigned int
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
117 nsfont_spec_to_traits (Lisp_Object font_spec)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
118 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
119 unsigned int traits = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
120 int n;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
121
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
122 n = FONT_WEIGHT_NUMERIC (font_spec);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
123 if (n != -1)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
124 traits |= (n > STYLE_REF) ? NSBoldFontMask : NSUnboldFontMask;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
125
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
126 n = FONT_SLANT_NUMERIC (font_spec);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
127 if (n != -1)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
128 traits |= (n > STYLE_REF) ? NSItalicFontMask : NSUnitalicFontMask;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
129
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
130 n = FONT_WIDTH_NUMERIC (font_spec);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
131 if (n > -1)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
132 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
133 if (n < STYLE_REF - 10)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
134 traits |= NSCondensedFontMask;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
135 else if (n > STYLE_REF + 10)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
136 traits |= NSExpandedFontMask;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
137 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
138
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
139 /*fprintf (stderr, " returning traits = %u\n", traits); */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
140 return traits;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
141 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
142
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
143
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
144 /* Converts NSArray of PS name, non-family part, weight, and traits to a
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
145 font backend font-entity. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
146 static Lisp_Object
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
147 nsfont_fmember_to_entity (NSString *family, NSArray *famMember)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
148 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
149 Lisp_Object font_entity = font_make_entity ();
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
150 unsigned int traits = [[famMember objectAtIndex: 3] unsignedIntValue];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
151 /* NSString *psName = [famMember objectAtIndex: 0]; */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
152 NSMutableString *suffix = [[famMember objectAtIndex: 1] mutableCopy];
96813
ece3c792fb2e nsfont.m: duplicate UTF8Strings before modifying with nsfont_escape_family_name - patch due to Seiji Zenitani
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96812
diff changeset
153 char *escapedFamily = strdup ([family UTF8String]);
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
154
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
155 nsfont_escape_name (escapedFamily);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
156 [suffix replaceOccurrencesOfString: @" " withString: @"" options: 0
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
157 range: NSMakeRange (0, [suffix length])];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
158
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
159 ASET (font_entity, FONT_TYPE_INDEX, Qns);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
160 ASET (font_entity, FONT_FOUNDRY_INDEX, Qapple);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
161 ASET (font_entity, FONT_FAMILY_INDEX, intern (escapedFamily));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
162 ASET (font_entity, FONT_ADSTYLE_INDEX, intern ([suffix UTF8String]));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
163 ASET (font_entity, FONT_REGISTRY_INDEX, Qiso10646_1);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
164
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
165 FONT_SET_STYLE (font_entity, FONT_WEIGHT_INDEX,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
166 traits & NSBoldFontMask ? Qbold : Qmedium);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
167 FONT_SET_STYLE (font_entity, FONT_SLANT_INDEX,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
168 traits & NSItalicFontMask ? Qitalic : Qnormal); /*XXX: should be Qroman */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
169 FONT_SET_STYLE (font_entity, FONT_WIDTH_INDEX,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
170 traits & NSCondensedFontMask ? Qcondensed :
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
171 traits & NSExpandedFontMask ? Qexpanded : Qnormal);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
172
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
173 ASET (font_entity, FONT_SIZE_INDEX, make_number (0));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
174 ASET (font_entity, FONT_EXTRA_INDEX, Qnil);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
175 ASET (font_entity, FONT_OBJLIST_INDEX, Qnil);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
176
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
177 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
178 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
179 fprintf (stderr, "created font_entity:\n ");
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
180 debug_print (font_entity);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
181 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
182
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
183 [suffix release];
96813
ece3c792fb2e nsfont.m: duplicate UTF8Strings before modifying with nsfont_escape_family_name - patch due to Seiji Zenitani
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96812
diff changeset
184 free (escapedFamily);
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
185 return font_entity;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
186 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
187
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
188
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
189 /* Computes Hamming distance btwn two "vectors" of 0's and 1's. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
190 static int
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
191 nsfont_trait_distance (unsigned int traits1, unsigned int traits2)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
192 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
193 int i, d =0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
194 for (i =0; i<sizeof (unsigned int)*8; i++)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
195 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
196 d += (traits1 & 0x1) ^ (traits2 & 0x1);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
197 traits1 >> 1;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
198 traits2 >> 1;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
199 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
200 return d;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
201 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
202
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
203
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
204 /* Default font entity based on Monaco. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
205 static Lisp_Object
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
206 nsfont_fallback_entity ()
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
207 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
208 NSString *family = [[NSFont userFixedPitchFontOfSize: 0] familyName];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
209 NSArray *famMemberSpec = [NSArray arrayWithObjects: family, @"",
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
210 [NSNumber numberWithUnsignedInt: 5],
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
211 [NSNumber numberWithUnsignedInt: 0], nil];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
212 return nsfont_fmember_to_entity (family, famMemberSpec);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
213 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
214
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
215
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
216 /* ==========================================================================
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
217
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
218 Font driver implementation
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
219
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
220 ========================================================================== */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
221
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
222 static Lisp_Object nsfont_get_cache (FRAME_PTR frame);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
223 static Lisp_Object nsfont_list (Lisp_Object frame, Lisp_Object font_spec);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
224 static Lisp_Object nsfont_match (Lisp_Object frame, Lisp_Object font_spec);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
225 static Lisp_Object nsfont_list_family (Lisp_Object frame);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
226 static Lisp_Object nsfont_open (FRAME_PTR f, Lisp_Object font_entity,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
227 int pixel_size);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
228 static void nsfont_close (FRAME_PTR f, struct font *font);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
229 static int nsfont_has_char (Lisp_Object entity, int c);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
230 static unsigned int nsfont_encode_char (struct font *font, int c);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
231 static int nsfont_text_extents (struct font *font, unsigned int *code,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
232 int nglyphs, struct font_metrics *metrics);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
233 static int nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
234 int with_background);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
235
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
236 struct font_driver nsfont_driver =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
237 {
96759
1e2f7aab70ba * Makefile.in: Undef LIB_STANDARD before defining it to silence warning
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96692
diff changeset
238 0, /* Qns */
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
239 1, /* case sensitive */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
240 nsfont_get_cache,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
241 nsfont_list,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
242 nsfont_match,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
243 nsfont_list_family,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
244 NULL, /*free_entity */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
245 nsfont_open,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
246 nsfont_close,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
247 NULL, /* prepare_face */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
248 NULL, /* done_face */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
249 nsfont_has_char,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
250 nsfont_encode_char,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
251 nsfont_text_extents,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
252 nsfont_draw,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
253 /* excluded: get_bitmap, free_bitmap, get_outline, free_outline,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
254 anchor_point, otf_capability, otf_driver,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
255 start_for_frame, end_for_frame, shape */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
256 };
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
257
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
258
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
259 /* Return a cache of font-entities on FRAME. The cache must be a
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
260 cons whose cdr part is the actual cache area. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
261 static Lisp_Object
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
262 nsfont_get_cache (FRAME_PTR frame)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
263 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
264 Display_Info *dpyinfo = FRAME_NS_DISPLAY_INFO (frame);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
265 return (dpyinfo->name_list_element);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
266 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
267
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
268
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
269 /* List fonts exactly matching with FONT_SPEC on FRAME. The value
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
270 is a vector of font-entities. This is the sole API that
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
271 allocates font-entities. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
272 static Lisp_Object
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
273 nsfont_list (Lisp_Object frame, Lisp_Object font_spec)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
274 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
275 Lisp_Object list = Qnil;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
276 Lisp_Object tem;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
277 NSString *family;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
278 NSArray *families;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
279 NSEnumerator *famEnum;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
280 NSFontManager *fontMgr;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
281 unsigned int traits = nsfont_spec_to_traits (font_spec);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
282
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
283 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
284 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
285 fprintf (stderr, "nsfont: list for fontspec:\n ");
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
286 debug_print (font_spec);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
287 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
288
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
289 /* if has non-unicode registry, give up */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
290 tem = AREF (font_spec, FONT_REGISTRY_INDEX);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
291 if (!EQ (tem, Qiso10646_1) && !EQ (tem, Qunicode_bmp))
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
292 return Qnil;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
293
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
294 fontMgr = [NSFontManager sharedFontManager];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
295
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
296 family = nsfont_get_family (font_spec);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
297
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
298 if (family != nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
299 families = [NSArray arrayWithObject: family];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
300 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
301 families = [fontMgr availableFontFamilies];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
302
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
303 for (famEnum = [families objectEnumerator]; family = [famEnum nextObject]; )
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
304 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
305 NSEnumerator *fm;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
306 NSArray *fmember, *firstMember = nil;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
307 unsigned int mtraits;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
308 BOOL foundItal = NO || (traits & NSUnitalicFontMask);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
309 NSArray *famMembers = [fontMgr availableMembersOfFontFamily: family];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
310 #ifdef NS_IMPL_COCOA
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
311 /* LastResort is special: not a family but a font name only */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
312 if ([@"LastResort" isEqualToString: family] && [famMembers count] == 0)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
313 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
314 famMembers = [NSArray arrayWithObject: [NSArray arrayWithObjects:
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
315 @"LastResort", @"", [NSNumber numberWithUnsignedInt: 5],
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
316 [NSNumber numberWithUnsignedInt: 0], nil]];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
317 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
318 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
319
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
320 /* fmember = [postscriptName style weight traits] */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
321 fm = [famMembers objectEnumerator];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
322 while (fmember = [fm nextObject])
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
323 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
324 mtraits = [[fmember objectAtIndex: 3] unsignedIntValue];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
325 if ((mtraits & traits) == traits)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
326 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
327 list = Fcons (nsfont_fmember_to_entity (family, fmember), list);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
328 if (mtraits & NSItalicFontMask)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
329 foundItal = YES;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
330 if (firstMember == nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
331 firstMember = fmember;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
332 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
333 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
334 if (foundItal == NO && firstMember != nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
335 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
336 /* no italic member found; add a synthesized one */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
337 NSMutableArray *smember = [firstMember mutableCopy];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
338 [smember replaceObjectAtIndex: 1 withObject: @"synthItal" ];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
339 mtraits = [[fmember objectAtIndex: 3] unsignedIntValue];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
340 mtraits |= NSItalicFontMask;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
341 [smember replaceObjectAtIndex: 3
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
342 withObject: [NSNumber numberWithUnsignedInt: mtraits]];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
343 /*NSLog (@"-- adding synthItal member: %@", smember); */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
344 list = Fcons (nsfont_fmember_to_entity (family, smember), list);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
345 [smember release];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
346 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
347 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
348
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
349 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
350 fprintf (stderr, " Returning %d entities.\n", XINT (Flength (list)));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
351
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
352 return (NILP (list) ? Qnil : Fvconcat (1, &list));/* Qnil was null_vector */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
353 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
354
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
355
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
356 /* Return a font entity most closely maching with FONT_SPEC on
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
357 FRAME. The closeness is determined by the font backend, thus
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
358 `face-font-selection-order' is ignored here. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
359 static Lisp_Object
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
360 nsfont_match (Lisp_Object frame, Lisp_Object font_spec)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
361 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
362 long traits = nsfont_spec_to_traits (font_spec);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
363 NSFontManager *fontMgr = [NSFontManager sharedFontManager];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
364 NSString *family;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
365 Lisp_Object tem;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
366
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
367 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
368 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
369 fprintf (stderr, "nsfont: match for fontspec:\n ");
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
370 debug_print (font_spec);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
371 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
372
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
373 /* if has non-unicode registry, just return fallback */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
374 #if 0
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
375 tem = AREF (font_spec, FONT_ADSTYLE_INDEX);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
376 if (!NILP (tem))
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
377 fprintf (stderr, "adstyle: '%s'\n", SDATA (tem));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
378 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
379 tem = AREF (font_spec, FONT_REGISTRY_INDEX);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
380 if (!EQ (tem, Qiso10646_1) && !EQ (tem, Qunicode_bmp))
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
381 return nsfont_fallback_entity ();
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
382
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
383 family = nsfont_get_family (font_spec);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
384
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
385 if (family != nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
386 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
387 /* try to find close font in family */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
388 NSArray *famMembers = [fontMgr availableMembersOfFontFamily: family];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
389 NSEnumerator *fm = [famMembers objectEnumerator];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
390 NSArray *fmember;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
391 int minDist = sizeof (unsigned int) * 8 + 1;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
392 int bestMatchIdx = -1;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
393 int i;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
394
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
395 for (i =0; fmember = [fm nextObject]; i++)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
396 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
397 unsigned int mtraits = [[fmember objectAtIndex: 3] unsignedIntValue];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
398 int dist = nsfont_trait_distance ((mtraits & traits), traits);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
399 if (dist < minDist)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
400 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
401 bestMatchIdx = i;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
402 minDist = dist;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
403 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
404 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
405 if (bestMatchIdx != -1)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
406 return nsfont_fmember_to_entity
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
407 (family, [famMembers objectAtIndex: bestMatchIdx]);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
408 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
409
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
410 /* no family that had members was given; find any font matching traits */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
411 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
412 NSArray *fontNames = [fontMgr availableFontNamesWithTraits: traits];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
413 if (fontNames && [fontNames count] > 0)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
414 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
415 NSString *fontName = [fontNames objectAtIndex: 0];
96892
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
416 /* XXX: is there a more efficient way to get family name? */
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
417 NSFont *font = [NSFont fontWithName: fontName size: 0];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
418 if (font != nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
419 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
420 /* now need to get suffix part of name.. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
421 NSString *family = [font familyName];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
422 NSEnumerator *fm = [[fontMgr availableMembersOfFontFamily: family]
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
423 objectEnumerator];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
424 NSArray *fmember;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
425 while (fmember = [fm nextObject])
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
426 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
427 unsigned int mtraits =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
428 [[fmember objectAtIndex: 3] unsignedIntValue];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
429 if (mtraits & traits == traits)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
430 return nsfont_fmember_to_entity (family, fmember);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
431 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
432 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
433 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
434 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
435
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
436 /* if we get here, return the fallback */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
437 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
438 fprintf (stderr, " *** returning fallback\n");
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
439
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
440 return nsfont_fallback_entity ();
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
441 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
442
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
443
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
444 /* List available families. The value is a list of family names
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
445 (symbols). */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
446 static Lisp_Object
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
447 nsfont_list_family (Lisp_Object frame)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
448 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
449 Lisp_Object list = Qnil;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
450 NSEnumerator *families =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
451 [[[NSFontManager sharedFontManager] availableFontFamilies]
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
452 objectEnumerator];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
453 NSString *family;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
454 while (family = [families nextObject])
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
455 list = Fcons (intern ([family UTF8String]), list);
96892
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
456 /* FIXME: escape the name? */
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
457
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
458 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
459 fprintf (stderr, "nsfont: list families returning %d entries\n",
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
460 XINT (Flength (list)));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
461
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
462 return list;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
463 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
464
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
465
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
466 /* utility: get width of a char c in screen font sfont */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
467 static float
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
468 nsfont_char_width (NSFont *sfont, int c)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
469 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
470 float w;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
471 NSString *cstr = [NSString stringWithFormat: @"%c", c];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
472 #ifdef NS_IMPL_COCOA
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
473 NSGlyph glyph = [sfont glyphWithName: cstr];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
474 if (glyph)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
475 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
476 float w = [sfont advancementForGlyph: glyph].width;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
477 if (w >= 1.5)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
478 return w;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
479 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
480 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
481 w = [sfont widthOfString: cstr];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
482 return max (w, 2.0);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
483 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
484
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
485
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
486 /* Open a font specified by FONT_ENTITY on frame F. If the font is
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
487 scalable, open it with PIXEL_SIZE. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
488 static Lisp_Object
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
489 nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
490 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
491 BOOL synthItal;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
492 struct nsfont_info *font_info;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
493 struct font *font;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
494 unsigned int traits = nsfont_spec_to_traits (font_entity);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
495 NSFontManager *fontMgr = [NSFontManager sharedFontManager];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
496 NSString *family;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
497 NSFont *nsfont, *sfont;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
498 Lisp_Object tem;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
499 NSRect brect;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
500 Lisp_Object font_object;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
501 int i;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
502 int fixLeopardBug;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
503 #if 0
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
504 static NSMutableDictionary *fontCache = nil;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
505
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
506 /* 2008/03/08: The same font may end up being requested for different
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
507 entities, due to small differences in numeric values or other issues,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
508 or for different copies of the same entity. Therefore we cache to
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
509 avoid creating multiple struct font objects (with metrics cache, etc.)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
510 for the same NSFont object.
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
511 2008/06/01: This is still an issue, but after font backend refactoring
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
512 caching will be more difficult, needs to be reworked before enabling. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
513 if (fontCache == nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
514 fontCache = [[NSMutableDictionary alloc] init];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
515 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
516
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
517 font_object = font_make_object (VECSIZE (struct nsfont_info), font_entity,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
518 pixel_size);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
519 font_info = (struct nsfont_info *) XFONT_OBJECT (font_object);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
520 font = (struct font *)font_info;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
521 if (!font)
96892
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
522 return Qnil; /* FIXME: this copies w32, but causes a segfault */
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
523
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
524 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
525 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
526 fprintf (stderr, "nsfont: open size %d of fontentity:\n ", pixel_size);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
527 debug_print (font_entity);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
528 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
529
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
530 if (pixel_size <= 0)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
531 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
532 /* try to get it out of frame params */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
533 Lisp_Object tem = get_frame_param (f, Qfontsize);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
534 pixel_size = NILP (tem) ? 0 : XFASTINT (tem);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
535 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
536
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
537 tem = AREF (font_entity, FONT_ADSTYLE_INDEX);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
538 synthItal = !NILP (tem) && !strncmp ("synthItal", SDATA (SYMBOL_NAME (tem)),
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
539 9);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
540 family = nsfont_get_family (font_entity);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
541 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
542 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
543 fprintf (stderr, "family: '%s'\ttraits = %ld\tbold = %d\n",
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
544 [family UTF8String], traits, traits & NSBoldFontMask);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
545 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
546
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
547 /* see http://cocoadev.com/forums/comments.php?DiscussionID =74 */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
548 fixLeopardBug = traits & NSBoldFontMask ? 10 : 5;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
549 nsfont = [fontMgr fontWithFamily: family
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
550 traits: traits weight: fixLeopardBug
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
551 size: pixel_size];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
552 /* if didn't find, try synthetic italic */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
553 if (nsfont == nil && synthItal && (traits & NSItalicFontMask))
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
554 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
555 nsfont = [fontMgr fontWithFamily: family
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
556 traits: traits & ~NSItalicFontMask
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
557 weight: fixLeopardBug size: pixel_size];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
558 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
559 #ifdef NS_IMPL_COCOA
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
560 /* LastResort not really a family */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
561 if (nsfont == nil && [@"LastResort" isEqualToString: family])
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
562 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
563 nsfont = [NSFont fontWithName: @"LastResort" size: pixel_size];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
564 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
565 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
566
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
567 if (nsfont == nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
568 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
569 message_with_string ("*** Warning: font in family '%s' not found",
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
570 build_string ([family UTF8String]), 1);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
571 nsfont = [NSFont userFixedPitchFontOfSize: pixel_size];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
572 if (!nsfont)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
573 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
574 fprintf (stderr, "*** Emacs.app: unable to load backup font\n");
96759
1e2f7aab70ba * Makefile.in: Undef LIB_STANDARD before defining it to silence warning
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96692
diff changeset
575 return Qnil;
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
576 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
577 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
578
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
579 #if 0
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
580 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
581 NSNumber *cached = [fontCache objectForKey: nsfont];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
582 if (cached != nil && !synthItal)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
583 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
584 fprintf (stderr, "*** CACHE HIT!\n");
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
585 struct font_info *existing =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
586 (struct nsfont_info *)[cached unsignedLongValue];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
587 /* ... */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
588 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
589 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
590 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
591 if (!synthItal)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
592 [fontCache
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
593 setObject: [NSNumber numberWithUnsignedLong:
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
594 (unsigned long)font_info]
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
595 forKey: nsfont];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
596 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
597 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
598 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
599
97198
cf43f4e3ecc8 clear warnings and clean up NS port
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96892
diff changeset
600 font_info->glyphs = (unsigned short **)
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
601 xmalloc (0x100 * sizeof (unsigned short *));
97198
cf43f4e3ecc8 clear warnings and clean up NS port
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96892
diff changeset
602 font_info->metrics = (struct font_metrics **)
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
603 xmalloc (0x100 * sizeof (struct font_metrics *));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
604 if (!font_info->glyphs || !font_info->metrics)
96759
1e2f7aab70ba * Makefile.in: Undef LIB_STANDARD before defining it to silence warning
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96692
diff changeset
605 return Qnil;
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
606 bzero (font_info->glyphs, 0x100 * sizeof (unsigned short *));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
607 bzero (font_info->metrics, 0x100 * sizeof (struct font_metrics *));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
608
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
609
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
610 BLOCK_INPUT;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
611
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
612 /* for metrics */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
613 sfont = [nsfont screenFont];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
614 if (sfont == nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
615 sfont = nsfont;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
616
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
617 /* non-metric backend font struct fields */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
618 font = (struct font *) font_info;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
619 font->pixel_size = [sfont pointSize];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
620 font->driver = &nsfont_driver;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
621 font->encoding_type = FONT_ENCODING_NOT_DECIDED;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
622 font->encoding_charset = -1;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
623 font->repertory_charset = -1;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
624 font->default_ascent = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
625 font->vertical_centering = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
626 font->baseline_offset = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
627 font->relative_compose = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
628 font->font_encoder = NULL;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
629
96892
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
630 /* TODO: does anything care about this? */
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
631 font->props[FONT_FORMAT_INDEX] = Qns;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
632 font->props[FONT_FILE_INDEX] = Qnil;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
633
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
634 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
635 double expand, shrink, hshrink;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
636 float full_height, min_height, hd;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
637 const char *fontName = [[nsfont fontName] UTF8String];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
638 int len = strlen (fontName);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
639
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
640 #ifdef NS_IMPL_GNUSTEP
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
641 font_info->nsfont = sfont;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
642 #else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
643 font_info->nsfont = nsfont;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
644 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
645 [font_info->nsfont retain];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
646
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
647 /* set up ns_font (defined in nsgui.h) */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
648 font_info->name = (char *)xmalloc (strlen (fontName)+1);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
649 bcopy (fontName, font_info->name, strlen (fontName)+1);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
650 font_info->bold = [fontMgr traitsOfFont: nsfont] & NSBoldFontMask;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
651 font_info->ital =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
652 synthItal || ([fontMgr traitsOfFont: nsfont] & NSItalicFontMask);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
653
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
654 /* Metrics etc.; some fonts return an unusually large max advance, so we
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
655 only use it for fonts that have wide characters. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
656 font_info->width = ([sfont numberOfGlyphs] > 2000) ?
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
657 [sfont maximumAdvancement].width : nsfont_char_width (sfont, '0');
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
658
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
659 brect = [sfont boundingRectForFont];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
660 full_height = brect.size.height;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
661 min_height = [sfont ascender] - [sfont descender];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
662 hd = full_height - min_height;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
663
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
664 if (!NUMBERP (ns_expand_space))
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
665 error ("No expand space defined");
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
666
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
667 /* ns_expand_space = 0.0 is use standard height; less shrink, more expand */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
668 expand = XFLOATINT (ns_expand_space) + 0.5;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
669
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
670 if (expand < 0.0)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
671 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
672 shrink = 1 + expand;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
673 hshrink = 1 + expand / 2.0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
674 expand = 0.0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
675 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
676 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
677 shrink = hshrink = 1.0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
678
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
679 font_info->underpos = 2; /*[sfont underlinePosition] is often clipped out */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
680 font_info->underwidth = [sfont underlineThickness];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
681 font_info->size = font->pixel_size;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
682 font_info->voffset = lrint (hshrink * [sfont ascender] + expand * hd / 2);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
683
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
684 /* max bounds */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
685 font_info->max_bounds.ascent =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
686 lrint (hshrink * [sfont ascender] + expand * hd/2);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
687 font_info->max_bounds.descent =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
688 -lrint (hshrink* [sfont descender] - expand*hd/2);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
689 font_info->height =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
690 font_info->max_bounds.ascent + font_info->max_bounds.descent;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
691 font_info->max_bounds.width = lrint (font_info->width);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
692 font_info->max_bounds.lbearing = lrint (brect.origin.x);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
693 font_info->max_bounds.rbearing =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
694 lrint (brect.size.width - font_info->width);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
695 /*font_info->width + (font_info->ital ? 0.2 * font_info->height : 0); */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
696
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
697 #ifdef NS_IMPL_COCOA
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
698 /* set up synthItal and the CG font */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
699 font_info->synthItal = synthItal;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
700 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
701 ATSFontRef atsFont = ATSFontFindFromPostScriptName
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
702 ((CFStringRef)[nsfont fontName], kATSOptionFlagsDefault);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
703
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
704 if (atsFont == kATSFontRefUnspecified)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
705 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
706 /* see if we can get it by dropping italic (then synthesizing) */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
707 atsFont = ATSFontFindFromPostScriptName ((CFStringRef)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
708 [[fontMgr convertFont: nsfont toNotHaveTrait: NSItalicFontMask]
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
709 fontName], kATSOptionFlagsDefault);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
710 if (atsFont != kATSFontRefUnspecified)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
711 font_info->synthItal = YES;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
712 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
713 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
714 /* last resort fallback */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
715 atsFont = ATSFontFindFromPostScriptName
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
716 ((CFStringRef)@"Monaco", kATSOptionFlagsDefault);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
717 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
718 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
719 font_info->cgfont = CGFontCreateWithPlatformFont ((void*)&atsFont);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
720 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
721 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
722
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
723 /* set up metrics portion of font struct */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
724 font->ascent = [sfont ascender];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
725 font->descent = -[sfont descender];
96892
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
726 font->min_width = [sfont widthOfString: @"|"]; /* FIXME */
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
727 font->space_width = lrint (nsfont_char_width (sfont, ' '));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
728 font->average_width = lrint (font_info->width);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
729 font->max_width = lrint (font_info->max_bounds.width);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
730 font->height = lrint (font_info->height);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
731 font->underline_position = lrint (font_info->underpos);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
732 font->underline_thickness = lrint (font_info->underwidth);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
733
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
734 font->props[FONT_NAME_INDEX] = Ffont_xlfd_name (font_object, Qnil);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
735 font->props[FONT_FULLNAME_INDEX] =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
736 make_unibyte_string (font_info->name, strlen (font_info->name));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
737 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
738 UNBLOCK_INPUT;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
739
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
740 return font_object;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
741 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
742
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
743
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
744 /* Close FONT on frame F. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
745 static void
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
746 nsfont_close (FRAME_PTR f, struct font *font)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
747 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
748 struct nsfont_info *font_info = (struct nsfont_info *)font;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
749 int i;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
750
96892
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
751 /* FIXME: this occurs apparently due to same failure to detect same font
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
752 that causes need for cache in nsfont_open ()
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
753 (came after unicode-2 -> trunk) */
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
754 if (!font_info)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
755 return;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
756
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
757 for (i =0; i<0x100; i++)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
758 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
759 if (font_info->glyphs[i])
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
760 xfree (font_info->glyphs[i]);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
761 if (font_info->metrics[i])
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
762 xfree (font_info->metrics[i]);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
763 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
764 [font_info->nsfont release];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
765 #ifdef NS_IMPL_COCOA
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
766 CGFontRelease (font_info->cgfont);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
767 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
768 xfree (font_info->name);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
769 xfree (font_info);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
770 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
771
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
772
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
773 /* If FONT_ENTITY has a glyph for character C (Unicode code point),
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
774 return 1. If not, return 0. If a font must be opened to check
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
775 it, return -1. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
776 static int
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
777 nsfont_has_char (Lisp_Object entity, int c)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
778 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
779 return -1;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
780 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
781
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
782
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
783 /* Return a glyph code of FONT for character C (Unicode code point).
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
784 If FONT doesn't have such a glyph, return FONT_INVALID_CODE. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
785 static unsigned int
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
786 nsfont_encode_char (struct font *font, int c)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
787 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
788 struct nsfont_info *font_info = (struct nsfont_info *)font;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
789 unsigned char high = (c & 0xff00) >> 8, low = c & 0x00ff;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
790 unsigned short g;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
791
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
792 if (c > 0xFFFF)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
793 return FONT_INVALID_CODE;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
794
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
795 /* did we already cache this block? */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
796 if (!font_info->glyphs[high])
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
797 ns_uni_to_glyphs (font_info, high);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
798
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
799 g = font_info->glyphs[high][low];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
800 /*fprintf (stderr, "mapping char %d -> %d\n", c, g); */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
801 return g == 0xFFFF ? FONT_INVALID_CODE : g;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
802 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
803
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
804
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
805 /* Perform the size computation of glyphs of FONT and fill in members
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
806 of METRICS. The glyphs are specified by their glyph codes in
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
807 CODE (length NGLYPHS). */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
808 static int
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
809 nsfont_text_extents (struct font *font, unsigned int *code, int nglyphs,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
810 struct font_metrics *metrics)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
811 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
812 struct nsfont_info *font_info = (struct nsfont_info *)font;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
813 struct font_metrics *pcm;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
814 unsigned char high, low;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
815 int totalWidth = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
816 int i;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
817
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
818 bzero (metrics, sizeof (struct font_metrics));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
819
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
820 for (i =0; i<nglyphs; i++)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
821 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
822 /* get metrics for this glyph, filling cache if need be */
96892
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
823 /* TODO: get metrics for whole string from an NSLayoutManager
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
824 (if not too slow) */
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
825 high = (code[i] & 0xFF00) >> 8;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
826 low = code[i] & 0x00FF;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
827 if (!font_info->metrics[high])
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
828 ns_glyph_metrics (font_info, high);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
829 pcm = &(font_info->metrics[high][low]);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
830
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
831 if (metrics->lbearing > totalWidth + pcm->lbearing)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
832 metrics->lbearing = totalWidth + pcm->lbearing;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
833 if (metrics->rbearing < totalWidth + pcm->rbearing)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
834 metrics->rbearing = totalWidth + pcm->rbearing;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
835 if (metrics->ascent < pcm->ascent)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
836 metrics->ascent = pcm->ascent;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
837 if (metrics->descent < pcm->descent)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
838 metrics->descent = pcm->descent;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
839
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
840 totalWidth += pcm->width;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
841 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
842
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
843 metrics->width = totalWidth;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
844
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
845 return totalWidth; /* not specified in doc, but xfont.c does it */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
846 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
847
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
848
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
849 /* Draw glyphs between FROM and TO of S->char2b at (X Y) pixel
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
850 position of frame F with S->FACE and S->GC. If WITH_BACKGROUND
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
851 is nonzero, fill the background in advance. It is assured that
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
852 WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars). */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
853 static int
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
854 nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
855 int with_background)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
856 /* NOTE: focus and clip must be set
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
857 also, currently assumed (true in nsterm.m call) from ==0, to ==nchars */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
858 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
859 static char cbuf[1024];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
860 char *c = cbuf;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
861 #ifdef NS_IMPL_GNUSTEP
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
862 static float advances[1024];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
863 float *adv = advances;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
864 #else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
865 static CGSize advances[1024];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
866 CGSize *adv = advances;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
867 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
868 struct face *face;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
869 NSRect r;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
870 struct nsfont_info *font = ns_tmp_font;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
871 NSColor *col, *bgCol;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
872 unsigned short *t = s->char2b;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
873 int i, len;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
874
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
875 /* Select face based on input flags */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
876 switch (ns_tmp_flags)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
877 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
878 case NS_DUMPGLYPH_CURSOR:
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
879 face = s->face;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
880 break;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
881 case NS_DUMPGLYPH_MOUSEFACE:
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
882 face = FACE_FROM_ID (s->f,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
883 FRAME_NS_DISPLAY_INFO (s->f)->mouse_face_face_id);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
884 if (!face)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
885 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
886 break;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
887 default:
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
888 face = s->face;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
889 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
890
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
891 r.origin.x = s->x;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
892 if (s->face->box != FACE_NO_BOX && s->first_glyph->left_box_line_p)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
893 r.origin.x += abs (s->face->box_line_width);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
894
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
895 r.origin.y = s->y;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
896 r.size.height = FONT_HEIGHT (font);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
897
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
898 /* Convert UTF-16 (?) to UTF-8 and determine advances. Note if we just ask
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
899 NS to render the string, it will come out differently from the individual
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
900 character widths added up because of layout processing. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
901 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
902 XCharStruct *cs;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
903 int cwidth, twidth = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
904 int hi, lo;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
905 char isComposite = 0; /* s->first_glyph->type == COMPOSITE_GLYPH; */
96892
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
906 /* FIXME: composition: no vertical displacement is considered. */
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
907 t+= s->gidx; /* advance into composition */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
908 for (i =0; i<s->nchars - s->gidx; i++, t++)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
909 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
910 hi = (*t & 0xFF00) >> 8;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
911 lo = *t & 0x00FF;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
912 if (isComposite)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
913 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
914 cwidth = s->cmp->offsets[s->gidx++ * 2] - twidth;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
915 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
916 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
917 {
96892
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
918 if (!font->metrics[hi]) /* FIXME: why/how can we need this now? */
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
919 ns_glyph_metrics (font, hi);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
920 cwidth = font->metrics[hi][lo].width;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
921 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
922 twidth += cwidth;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
923 #ifdef NS_IMPL_GNUSTEP
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
924 *adv++ = cwidth;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
925 CHAR_STRING_ADVANCE (*t, c); /* this converts the char to UTF-8 */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
926 #else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
927 (*adv++).width = cwidth;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
928 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
929 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
930 len = adv - advances;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
931 r.size.width = twidth;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
932 *c = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
933 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
934
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
935 /* fill background if requested */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
936 if (with_background)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
937 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
938 NSRect br = r;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
939 int fibw = FRAME_INTERNAL_BORDER_WIDTH (s->f);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
940 int mbox_line_width = max (s->face->box_line_width, 0);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
941
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
942 if (s->row->full_width_p)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
943 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
944 if (br.origin.x <= fibw + 1 + mbox_line_width)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
945 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
946 br.size.width += br.origin.x - mbox_line_width;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
947 br.origin.x = mbox_line_width;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
948 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
949 if (FRAME_PIXEL_WIDTH (s->f) - (br.origin.x + br.size.width)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
950 <= fibw+1)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
951 br.size.width += fibw;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
952 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
953 if (s->face->box == FACE_NO_BOX)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
954 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
955 /* expand unboxed top row over internal border */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
956 if (br.origin.y <= fibw + 1 + mbox_line_width)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
957 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
958 br.size.height += br.origin.y;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
959 br.origin.y = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
960 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
961 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
962 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
963 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
964 int correction = abs (s->face->box_line_width)+1;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
965 br.origin.y += correction;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
966 br.size.height -= 2*correction;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
967 br.origin.x += correction;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
968 br.size.width -= 2*correction;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
969 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
970
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
971 if (!s->face->stipple)
96812
eb46d3216494 apply fix from Chong Yidong to NS port ns_set_background_color(), and clean up comparison use of result from NS_FACE_BACKGROUND
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96759
diff changeset
972 [(NS_FACE_BACKGROUND (face) != 0
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
973 ? ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
974 : FRAME_BACKGROUND_COLOR (s->f)) set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
975 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
976 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
977 struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (s->f);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
978 [[dpyinfo->bitmaps[face->stipple-1].img stippleMask] set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
979 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
980 NSRectFill (br);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
981 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
982
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
983
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
984 /* set up for character rendering */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
985 r.origin.y += font->voffset + (s->height - font->height)/2;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
986
97198
cf43f4e3ecc8 clear warnings and clean up NS port
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96892
diff changeset
987 col = (NS_FACE_FOREGROUND (face) != 0
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
988 ? ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
989 : FRAME_FOREGROUND_COLOR (s->f));
96892
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
990 /* FIXME: find another way to pass this */
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
991 bgCol = (ns_tmp_flags != NS_DUMPGLYPH_FOREGROUND ? nil
96812
eb46d3216494 apply fix from Chong Yidong to NS port ns_set_background_color(), and clean up comparison use of result from NS_FACE_BACKGROUND
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96759
diff changeset
992 : (NS_FACE_BACKGROUND (face) != 0
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
993 ? ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
994 : FRAME_BACKGROUND_COLOR (s->f)));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
995
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
996 /* render under GNUstep using DPS */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
997 #ifdef NS_IMPL_GNUSTEP
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
998 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
999 NSGraphicsContext *context = GSCurrentContext ();
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1000
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1001 DPSgsave (context);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1002 [font->nsfont set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1003
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1004 /* do erase if "foreground" mode */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1005 if (bgCol != nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1006 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1007 [bgCol set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1008 DPSmoveto (context, r.origin.x, r.origin.y);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1009 /*[context GSSetTextDrawingMode: GSTextFillStroke]; /// not implemented yet */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1010 DPSxshow (context, cbuf, advances, len);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1011 DPSstroke (context);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1012 [col set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1013 /*[context GSSetTextDrawingMode: GSTextFill]; /// not implemented yet */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1014 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1015
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1016 /* do underline */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1017 if (face->underline_p)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1018 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1019 if (face->underline_color != nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1020 [ns_lookup_indexed_color (face->underline_color, s->f) set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1021 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1022 [col set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1023 DPSmoveto (context, r.origin.x, r.origin.y + font->underpos);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1024 DPSlineto (context, r.origin.x+r.size.width, r.origin.y+font->underpos);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1025 if (face->underline_color != nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1026 [col set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1027 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1028 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1029 [col set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1030
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1031 /* draw with DPSxshow () */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1032 DPSmoveto (context, r.origin.x, r.origin.y);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1033 DPSxshow (context, cbuf, advances, len);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1034 DPSstroke (context);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1035
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1036 DPSgrestore (context);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1037 return to-from;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1038 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1039
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1040 #else /* NS_IMPL_COCOA */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1041 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1042 CGContextRef gcontext =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1043 [[NSGraphicsContext currentContext] graphicsPort];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1044 static CGAffineTransform fliptf;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1045 static BOOL firstTime = YES;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1046
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1047 if (firstTime)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1048 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1049 firstTime = NO;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1050 fliptf = CGAffineTransformMakeScale (1.0, -1.0);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1051 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1052
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1053 CGContextSaveGState (gcontext);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1054
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1055 fliptf.c = font->synthItal ? Fix2X (kATSItalicQDSkew) : 0.0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1056
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1057 CGContextSetFont (gcontext, font->cgfont);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1058 CGContextSetFontSize (gcontext, font->size);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1059 if (ns_antialias_text == NO || font->size <= ns_antialias_threshold)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1060 CGContextSetShouldAntialias (gcontext, 0);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1061 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1062 CGContextSetShouldAntialias (gcontext, 1);
96817
6b7bbb1d9eb1 fix bug with quickdraw smoothing; also, in Makefile, clean out ns_appdir in 'clean' target
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96813
diff changeset
1063 if (EQ (ns_use_qd_smoothing, Qt))
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1064 CGContextSetFontRenderingMode (gcontext, 2); /* 0 is Cocoa, 2 is QD */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1065
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1066 CGContextSetTextMatrix (gcontext, fliptf);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1067
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1068 if (bgCol != nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1069 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1070 /* foreground drawing; erase first to avoid overstrike */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1071 [bgCol set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1072 CGContextSetTextDrawingMode (gcontext, kCGTextFillStroke);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1073 CGContextSetTextPosition (gcontext, r.origin.x, r.origin.y);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1074 CGContextShowGlyphsWithAdvances (gcontext, s->char2b, advances, len);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1075 CGContextSetTextDrawingMode (gcontext, kCGTextFill);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1076 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1077
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1078 if (face->underline_p)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1079 {
97198
cf43f4e3ecc8 clear warnings and clean up NS port
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96892
diff changeset
1080 if (face->underline_color != 0)
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1081 [ns_lookup_indexed_color (face->underline_color, s->f) set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1082 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1083 [col set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1084 CGContextBeginPath (gcontext);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1085 CGContextMoveToPoint (gcontext,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1086 r.origin.x, r.origin.y + font->underpos);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1087 CGContextAddLineToPoint (gcontext, r.origin.x + r.size.width,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1088 r.origin.y + font->underpos);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1089 CGContextStrokePath (gcontext);
97198
cf43f4e3ecc8 clear warnings and clean up NS port
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96892
diff changeset
1090 if (face->underline_color != 0)
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1091 [col set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1092 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1093 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1094 [col set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1095
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1096 CGContextSetTextPosition (gcontext, r.origin.x, r.origin.y);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1097 CGContextShowGlyphsWithAdvances (gcontext, s->char2b + s->gidx,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1098 advances, len);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1099
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1100 if (face->overstrike)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1101 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1102 CGContextSetTextPosition (gcontext, r.origin.x+0.5, r.origin.y);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1103 CGContextShowGlyphsWithAdvances (gcontext, s->char2b + s->gidx,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1104 advances, len);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1105 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1106
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1107 CGContextRestoreGState (gcontext);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1108 return;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1109 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1110 #endif /* NS_IMPL_COCOA */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1111
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1112 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1113
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1114
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1115 /* Auto-creates a fontset built around the font in font_object,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1116 by creating an attributed string with characters from each
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1117 script, then requesting the NS text system to fix attributes
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1118 in range. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1119 void nsfont_make_fontset_for_font (Lisp_Object name, Lisp_Object font_object)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1120 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1121 Lisp_Object script, famAndReg;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1122 struct nsfont_info *font_info =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1123 (struct nsfont_info *)XFONT_OBJECT (font_object);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1124
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1125 /* NS text system (and char buf) init */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1126 static NSTextStorage *store;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1127 static NSLayoutManager *layout;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1128 static NSRange range;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1129 static NSMutableDictionary *attribs;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1130 static Lisp_Object *scripts;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1131 static int nscripts;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1132 static int *scriptsNchars;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1133 static BOOL firstTime = YES;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1134 Lisp_Object regString = build_string ("iso10646-1");
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1135 int i, j;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1136
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1137 if (firstTime == YES)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1138 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1139 nscripts = XINT (Flength (Vscript_representative_chars));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1140 scriptsNchars = (int *) malloc (nscripts * sizeof (int));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1141 unsigned char *buf = malloc (4*nscripts*sizeof (char));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1142 Lisp_Object scriptsChars = Vscript_representative_chars;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1143 unsigned char *tpos = buf;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1144
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1145 scripts = (Lisp_Object *) malloc (nscripts * sizeof (Lisp_Object));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1146
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1147 for (i =0; i<nscripts; i++)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1148 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1149 Lisp_Object sChars = XCAR (scriptsChars);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1150 Lisp_Object chars = XCDR (sChars);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1151 unsigned int ch, c =0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1152 scripts[i] = XCAR (sChars);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1153
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1154 while (CONSP (chars))
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1155 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1156 ch = XUINT (XCAR (chars));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1157 chars = XCDR (chars);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1158 CHAR_STRING_ADVANCE (ch, tpos);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1159 c++;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1160 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1161 scriptsNchars[i] = c;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1162
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1163 scriptsChars = XCDR (scriptsChars);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1164 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1165 *tpos = '\0';
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1166
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1167 store = [[NSTextStorage alloc] init];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1168 layout = [[NSLayoutManager alloc] init];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1169 [store addLayoutManager: layout];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1170 [layout release];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1171
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1172 [store beginEditing];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1173 [[store mutableString] appendString:
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1174 [NSString stringWithUTF8String: buf]];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1175 [store endEditing];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1176
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1177 free (buf);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1178 range = NSMakeRange (0, [store length]);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1179
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1180 attribs = [[NSMutableDictionary alloc] init];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1181 firstTime = NO;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1182 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1183
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1184 /* set the fonts */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1185 [store beginEditing];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1186 [store removeAttribute: NSFontAttributeName range: range];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1187 [attribs setObject: font_info->nsfont forKey: NSFontAttributeName];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1188 [store addAttributes: attribs range: range];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1189 [store endEditing];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1190
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1191 /* read them out */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1192 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1193 NSMutableDictionary *map =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1194 [NSMutableDictionary dictionaryWithCapacity: nscripts * 4];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1195 NSEnumerator *fonts;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1196 NSFont *cfont = nil, *tfont;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1197 NSNumber *n;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1198 int idx = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1199 int max;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1200 for (i =0; i<nscripts; i++)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1201 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1202 [map removeAllObjects];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1203 for (j =0; j<scriptsNchars[i]; j++)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1204 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1205 cfont = [store attribute: NSFontAttributeName atIndex: idx++
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1206 effectiveRange: NULL];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1207 n = [map objectForKey: cfont];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1208 if (n == nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1209 n = [NSNumber numberWithInt: 1];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1210 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1211 n = [NSNumber numberWithInt: [n intValue] + 1];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1212 [map setObject: n forKey: cfont];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1213 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1214
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1215 /* majority rules */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1216 max = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1217 fonts = [map keyEnumerator];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1218 while (tfont = [fonts nextObject])
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1219 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1220 n = [map objectForKey: tfont];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1221 if ([n intValue] > max)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1222 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1223 cfont = tfont;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1224 max = [n intValue];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1225 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1226 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1227
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1228 if (cfont != nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1229 {
96813
ece3c792fb2e nsfont.m: duplicate UTF8Strings before modifying with nsfont_escape_family_name - patch due to Seiji Zenitani
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96812
diff changeset
1230 char *family = strdup([[cfont familyName] UTF8String]);
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1231 Lisp_Object famAndReg;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1232
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1233 nsfont_escape_name (family);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1234 famAndReg = Fcons (build_string (family), regString);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1235
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1236 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1237 fprintf (stderr, "%s fontset: use '%s' for script '%s'\n",
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1238 font_info->name, family,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1239 SDATA (SYMBOL_NAME (scripts[i])));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1240
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1241 Fset_fontset_font (name, scripts[i], famAndReg, Qnil, Qnil);
96813
ece3c792fb2e nsfont.m: duplicate UTF8Strings before modifying with nsfont_escape_family_name - patch due to Seiji Zenitani
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96812
diff changeset
1242 free (family);
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1243 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1244 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1245 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1246 fprintf (stderr, "%s fontset: none found for script '%s'\n",
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1247 font_info->name, SDATA (SYMBOL_NAME (scripts[i])));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1248 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1249 } /* for i = script */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1250 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1251 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1252
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1253
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1254
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1255 /* ==========================================================================
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1256
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1257 Font glyph and metrics caching functions
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1258
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1259 ========================================================================== */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1260
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1261 /* Find and cache corresponding glyph codes for unicode values in given
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1262 hi-byte block of 256. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1263 static void
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1264 ns_uni_to_glyphs (struct nsfont_info *font_info, unsigned char block)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1265 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1266 #ifdef NS_IMPL_COCOA
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1267 static EmacsGlyphStorage *glyphStorage;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1268 static char firstTime = 1;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1269 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1270 unichar *unichars = xmalloc (0x101 * sizeof (unichar));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1271 unsigned int i, g, idx;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1272 unsigned short *glyphs;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1273
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1274 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1275 fprintf (stderr, "%p\tFinding glyphs for glyphs in block %d\n",
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1276 font_info, block);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1277
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1278 BLOCK_INPUT;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1279
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1280 #ifdef NS_IMPL_COCOA
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1281 if (firstTime)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1282 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1283 firstTime = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1284 glyphStorage = [[EmacsGlyphStorage alloc] initWithCapacity: 0x100];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1285 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1286 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1287
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1288 font_info->glyphs[block] = xmalloc (0x100 * sizeof (unsigned short));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1289 if (!unichars || !(font_info->glyphs[block]))
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1290 abort ();
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1291
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1292 /* create a string containing all unicode characters in this block */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1293 for (idx = block<<8, i =0; i<0x100; idx++, i++)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1294 if (idx < 0xD800 || idx > 0xDFFF)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1295 unichars[i] = idx;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1296 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1297 unichars[i] = 0xFEFF;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1298 unichars[0x100] = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1299
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1300 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1301 #ifdef NS_IMPL_COCOA
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1302 NSString *allChars = [[NSString alloc]
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1303 initWithCharactersNoCopy: unichars
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1304 length: 0x100
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1305 freeWhenDone: NO];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1306 NSGlyphGenerator *glyphGenerator = [NSGlyphGenerator sharedGlyphGenerator];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1307 /*NSCharacterSet *coveredChars = [nsfont coveredCharacterSet]; */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1308 unsigned int numGlyphs = [font_info->nsfont numberOfGlyphs];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1309 unsigned int gInd =0, cInd =0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1310
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1311 [glyphStorage setString: allChars font: font_info->nsfont];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1312 [glyphGenerator generateGlyphsForGlyphStorage: glyphStorage
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1313 desiredNumberOfCharacters: glyphStorage->maxChar
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1314 glyphIndex: &gInd characterIndex: &cInd];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1315 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1316 glyphs = font_info->glyphs[block];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1317 for (i =0; i<0x100; i++, glyphs++)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1318 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1319 #ifdef NS_IMPL_GNUSTEP
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1320 g = unichars[i];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1321 #else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1322 g = glyphStorage->cglyphs[i];
96892
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
1323 /* TODO: is this a good check? maybe need to use coveredChars.. */
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1324 if (g > numGlyphs)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1325 g = 0xFFFF; /* hopefully unused... */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1326 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1327 *glyphs = g;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1328 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1329
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1330 #ifdef NS_IMPL_COCOA
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1331 [allChars release];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1332 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1333 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1334
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1335 UNBLOCK_INPUT;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1336 xfree (unichars);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1337 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1338
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1339
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1340 /* Determine and cache metrics for corresponding glyph codes in given
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1341 hi-byte block of 256. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1342 static void
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1343 ns_glyph_metrics (struct nsfont_info *font_info, unsigned char block)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1344 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1345 unsigned int i, g;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1346 unsigned int numGlyphs = [font_info->nsfont numberOfGlyphs];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1347 NSFont *sfont;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1348 struct font_metrics *metrics;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1349
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1350 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1351 fprintf (stderr, "%p\tComputing metrics for glyphs in block %d\n",
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1352 font_info, block);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1353
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1354 #ifdef NS_IMPL_GNUSTEP
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1355 /* not implemented yet (as of startup 0.18), so punt */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1356 if (numGlyphs == 0)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1357 numGlyphs = 0x10000;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1358 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1359
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1360 BLOCK_INPUT;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1361 sfont = [font_info->nsfont screenFont];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1362
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1363 font_info->metrics[block] = xmalloc (0x100 * sizeof (struct font_metrics));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1364 bzero (font_info->metrics[block], 0x100 * sizeof (struct font_metrics));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1365 if (!(font_info->metrics[block]))
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1366 abort ();
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1367
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1368 metrics = font_info->metrics[block];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1369 for (g = block<<8, i =0; i<0x100 && g < numGlyphs; g++, i++, metrics++)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1370 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1371 float w, lb, rb;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1372 NSRect r = [sfont boundingRectForGlyph: g];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1373
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1374 #ifdef NS_IMPL_GNUSTEP
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1375 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1376 /* lord help us */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1377 NSString *s = [NSString stringWithFormat: @"%c", g];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1378 w = [sfont widthOfString: s];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1379 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1380 #else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1381 w = [sfont advancementForGlyph: g].width;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1382 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1383 w = max (w, 2.0);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1384 metrics->width = lrint (w);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1385
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1386 lb = r.origin.x;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1387 rb = r.size.width - w;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1388 if (lb < 0)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1389 metrics->lbearing = round (lb);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1390 if (font_info->ital)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1391 rb += 0.22 * font_info->height;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1392 metrics->rbearing = lrint (w + rb);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1393
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1394 metrics->descent = r.origin.y < 0 ? -r.origin.y : 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1395 /*lrint (hshrink * [sfont ascender] + expand * hd/2); */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1396 metrics->ascent = r.size.height - metrics->descent;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1397 /*-lrint (hshrink* [sfont descender] - expand * hd/2); */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1398 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1399 UNBLOCK_INPUT;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1400 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1401
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1402
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1403 #ifdef NS_IMPL_COCOA
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1404 /* helper for font glyph setup */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1405 @implementation EmacsGlyphStorage
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1406
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1407 - init
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1408 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1409 return [self initWithCapacity: 1024];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1410 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1411
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1412 - initWithCapacity: (unsigned long) c
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1413 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1414 self = [super init];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1415 maxChar = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1416 maxGlyph = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1417 dict = [NSMutableDictionary new];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1418 cglyphs = (CGGlyph *)xmalloc (c * sizeof (CGGlyph));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1419 return self;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1420 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1421
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1422 - (void) dealloc
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1423 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1424 if (attrStr != nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1425 [attrStr release];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1426 [dict release];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1427 xfree (cglyphs);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1428 [super dealloc];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1429 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1430
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1431 - (void) setString: (NSString *)str font: (NSFont *)font
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1432 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1433 [dict setObject: font forKey: NSFontAttributeName];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1434 attrStr = [[NSAttributedString alloc] initWithString: str attributes: dict];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1435 maxChar = [str length];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1436 maxGlyph = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1437 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1438
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1439 /* NSGlyphStorage protocol */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1440 - (unsigned int)layoutOptions
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1441 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1442 return 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1443 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1444
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1445 - (NSAttributedString *)attributedString
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1446 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1447 return attrStr;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1448 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1449
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1450 - (void)insertGlyphs: (const NSGlyph *)glyphs length: (unsigned int)length
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1451 forStartingGlyphAtIndex: (unsigned int)glyphIndex
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1452 characterIndex: (unsigned int)charIndex
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1453 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1454 len = glyphIndex+length;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1455 for (i =glyphIndex; i<len; i++)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1456 cglyphs[i] = glyphs[i-glyphIndex];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1457 if (len > maxGlyph)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1458 maxGlyph = len;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1459 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1460
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1461 - (void)setIntAttribute: (int)attributeTag value: (int)val
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1462 forGlyphAtIndex: (unsigned)glyphIndex
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1463 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1464 return;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1465 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1466
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1467 @end
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1468 #endif /* NS_IMPL_COCOA */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1469
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1470
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1471 /* Debugging */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1472 void
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1473 dump_glyphstring (struct glyph_string *s)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1474 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1475 int i;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1476
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1477 fprintf (stderr, "Glyph string len = %d at (%d, %d) overhang (%d, %d), overlap = %d, bg_filled = %d:",
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1478 s->nchars, s->x, s->y, s->left_overhang, s->right_overhang,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1479 s->row->overlapping_p, s->background_filled_p);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1480 for (i =0; i<s->nchars; i++)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1481 fprintf (stderr, "%c", s->first_glyph[i].u.ch);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1482 fprintf (stderr, "\n");
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1483 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1484
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1485
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1486
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1487 void
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1488 syms_of_nsfont ()
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1489 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1490 nsfont_driver.type = Qns;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1491 register_font_driver (&nsfont_driver, NULL);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1492 DEFSYM (Qapple, "apple");
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1493 DEFSYM (Qroman, "roman");
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1494 DEFSYM (Qmedium, "medium");
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1495 }
96685
e869d0172660 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 96676
diff changeset
1496
96689
f34c4d928d39 Use nicer comment syntax for arch taglines in Objective-C files
Miles Bader <miles@gnu.org>
parents: 96685
diff changeset
1497 // arch-tag: d6c3c6f0-62de-4978-8b1e-b7966fe02cae