annotate src/nsfont.m @ 99075:3172ff476053

(font_match_p): Fix for the case that a vector of characters is in script-representative-chars.
author Kenichi Handa <handa@m17n.org>
date Thu, 23 Oct 2008 07:49:15 +0000
parents db015b441c0c
children ba4876d944bc
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)
98451
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
124 traits |= (n > STYLE_REF) ? NSBoldFontMask
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
125 : (n < STYLE_REF) ? NSUnboldFontMask : 0;
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
126
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
127 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
128 if (n != -1)
98451
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
129 traits |= (n > STYLE_REF) ? NSItalicFontMask
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
130 : (n < STYLE_REF) ? NSUnitalicFontMask : 0;
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
131
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
132 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
133 if (n > -1)
98451
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
134 traits |= (n > STYLE_REF + 10) ? NSExpandedFontMask
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
135 : (n < STYLE_REF - 10) ? NSExpandedFontMask : 0;
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
136
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
137 /*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
138 return traits;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
139 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
140
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 /* 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
143 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
144 static Lisp_Object
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
145 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
146 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
147 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
148 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
149 /* 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
150 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
151 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
152
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
153 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
154 [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
155 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
156
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
157 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
158 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
159 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
160 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
161 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
162
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
163 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
164 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
165 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
166 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
167 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
168 traits & NSCondensedFontMask ? Qcondensed :
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
169 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
170
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
171 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
172 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
173 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
174
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
175 if (NSFONT_TRACE)
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 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
178 debug_print (font_entity);
98399
6b3b02fd9846 * nsfont.m (nsfont_trait_distance): Fix bug. (nsfont_list): Return a list rather than a vector (syncs with Handa changes of 2008-05-14). (nsfont_open): Improve logging.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98371
diff changeset
179 }
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
180
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
181 [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
182 free (escapedFamily);
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
183 return font_entity;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
184 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
185
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 /* 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
188 static int
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
189 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
190 {
98399
6b3b02fd9846 * nsfont.m (nsfont_trait_distance): Fix bug. (nsfont_list): Return a list rather than a vector (syncs with Handa changes of 2008-05-14). (nsfont_open): Improve logging.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98371
diff changeset
191 int i, d = 0;
6b3b02fd9846 * nsfont.m (nsfont_trait_distance): Fix bug. (nsfont_list): Return a list rather than a vector (syncs with Handa changes of 2008-05-14). (nsfont_open): Improve logging.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98371
diff changeset
192 for (i = 0; i < sizeof (unsigned int) * 8; i++)
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
193 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
194 d += (traits1 & 0x1) ^ (traits2 & 0x1);
98399
6b3b02fd9846 * nsfont.m (nsfont_trait_distance): Fix bug. (nsfont_list): Return a list rather than a vector (syncs with Handa changes of 2008-05-14). (nsfont_open): Improve logging.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98371
diff changeset
195 traits1 >>= 1;
6b3b02fd9846 * nsfont.m (nsfont_trait_distance): Fix bug. (nsfont_list): Return a list rather than a vector (syncs with Handa changes of 2008-05-14). (nsfont_open): Improve logging.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98371
diff changeset
196 traits2 >>= 1;
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
197 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
198 return d;
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
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 /* 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
203 static Lisp_Object
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
204 nsfont_fallback_entity ()
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
205 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
206 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
207 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
208 [NSNumber numberWithUnsignedInt: 5],
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
209 [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
210 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
211 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
212
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 Font driver implementation
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 ========================================================================== */
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 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
221 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
222 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
223 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
224 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
225 int pixel_size);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
226 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
227 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
228 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
229 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
230 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
231 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
232 int with_background);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
233
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
234 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
235 {
96759
1e2f7aab70ba * Makefile.in: Undef LIB_STANDARD before defining it to silence warning
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96692
diff changeset
236 0, /* Qns */
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
237 1, /* case sensitive */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
238 nsfont_get_cache,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
239 nsfont_list,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
240 nsfont_match,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
241 nsfont_list_family,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
242 NULL, /*free_entity */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
243 nsfont_open,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
244 nsfont_close,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
245 NULL, /* prepare_face */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
246 NULL, /* done_face */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
247 nsfont_has_char,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
248 nsfont_encode_char,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
249 nsfont_text_extents,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
250 nsfont_draw,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
251 /* 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
252 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
253 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
254 };
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
255
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 /* 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
258 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
259 static Lisp_Object
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
260 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
261 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
262 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
263 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
264 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
265
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 /* List fonts exactly matching with FONT_SPEC on FRAME. The value
98399
6b3b02fd9846 * nsfont.m (nsfont_trait_distance): Fix bug. (nsfont_list): Return a list rather than a vector (syncs with Handa changes of 2008-05-14). (nsfont_open): Improve logging.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98371
diff changeset
268 is a **list** of font-entities. This is the sole API that
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
269 allocates font-entities. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
270 static Lisp_Object
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
271 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
272 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
273 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
274 Lisp_Object tem;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
275 NSString *family;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
276 NSArray *families;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
277 NSEnumerator *famEnum;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
278 NSFontManager *fontMgr;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
279 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
280
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
281 if (NSFONT_TRACE)
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 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
284 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
285 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
286
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
287 /* 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
288 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
289 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
290 return Qnil;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
291
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
292 fontMgr = [NSFontManager sharedFontManager];
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 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
295
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
296 if (family != nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
297 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
298 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
299 families = [fontMgr availableFontFamilies];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
300
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
301 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
302 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
303 NSEnumerator *fm;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
304 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
305 unsigned int mtraits;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
306 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
307 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
308 #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
309 /* 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
310 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
311 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
312 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
313 @"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
314 [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
315 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
316 #endif
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 /* 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
319 fm = [famMembers objectEnumerator];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
320 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
321 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
322 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
323 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
324 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
325 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
326 if (mtraits & NSItalicFontMask)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
327 foundItal = YES;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
328 if (firstMember == nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
329 firstMember = fmember;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
330 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
331 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
332 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
333 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
334 /* 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
335 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
336 [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
337 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
338 mtraits |= NSItalicFontMask;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
339 [smember replaceObjectAtIndex: 3
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
340 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
341 /*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
342 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
343 [smember release];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
344 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
345 }
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 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
348 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
349
98399
6b3b02fd9846 * nsfont.m (nsfont_trait_distance): Fix bug. (nsfont_list): Return a list rather than a vector (syncs with Handa changes of 2008-05-14). (nsfont_open): Improve logging.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98371
diff changeset
350 return list;
96676
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
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 /* 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
355 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
356 `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
357 static Lisp_Object
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
358 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
359 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
360 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
361 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
362 NSString *family;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
363 Lisp_Object tem;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
364
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
365 if (NSFONT_TRACE)
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 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
368 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
369 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
370
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
371 /* 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
372 #if 0
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
373 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
374 if (!NILP (tem))
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
375 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
376 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
377 tem = AREF (font_spec, FONT_REGISTRY_INDEX);
98451
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
378 if (!NILP (tem) && !EQ (tem, Qiso10646_1) && !EQ (tem, Qunicode_bmp))
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
379 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
380
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
381 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
382
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
383 if (family != nil)
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 /* 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
386 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
387 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
388 NSArray *fmember;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
389 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
390 int bestMatchIdx = -1;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
391 int i;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
392
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
393 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
394 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
395 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
396 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
397 if (dist < minDist)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
398 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
399 bestMatchIdx = i;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
400 minDist = dist;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
401 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
402 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
403 if (bestMatchIdx != -1)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
404 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
405 (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
406 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
407
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
408 /* 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
409 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
410 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
411 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
412 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
413 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
414 /* 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
415 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
416 if (font != nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
417 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
418 /* 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
419 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
420 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
421 objectEnumerator];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
422 NSArray *fmember;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
423 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
424 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
425 unsigned int mtraits =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
426 [[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
427 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
428 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
429 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
430 }
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 /* 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
435 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
436 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
437
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
438 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
439 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
440
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 /* 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
443 (symbols). */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
444 static Lisp_Object
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
445 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
446 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
447 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
448 NSEnumerator *families =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
449 [[[NSFontManager sharedFontManager] availableFontFamilies]
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
450 objectEnumerator];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
451 NSString *family;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
452 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
453 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
454 /* 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
455
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
456 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
457 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
458 XINT (Flength (list)));
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
459
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
460 return 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
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 /* 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
465 static float
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
466 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
467 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
468 float w;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
469 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
470 #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
471 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
472 if (glyph)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
473 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
474 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
475 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
476 return w;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
477 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
478 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
479 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
480 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
481 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
482
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 /* 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
485 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
486 static Lisp_Object
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
487 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
488 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
489 BOOL synthItal;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
490 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
491 struct font *font;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
492 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
493 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
494 NSString *family;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
495 NSFont *nsfont, *sfont;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
496 Lisp_Object tem;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
497 NSRect brect;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
498 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
499 int i;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
500 int fixLeopardBug;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
501 static NSMutableDictionary *fontCache = nil;
98451
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
502 NSNumber *cached;
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
503
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
504 /* 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
505 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
506 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
507 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
508 for the same NSFont object.
98451
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
509 2008/06/01: This is still an issue after font backend refactoring. */
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
510 if (fontCache == nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
511 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
512
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
513 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
514 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
515 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
516 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
517 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
518
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
519 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
520 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
521 /* 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
522 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
523 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
524 }
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 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
527 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
528 9);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
529 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
530 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
531 {
98399
6b3b02fd9846 * nsfont.m (nsfont_trait_distance): Fix bug. (nsfont_list): Return a list rather than a vector (syncs with Handa changes of 2008-05-14). (nsfont_open): Improve logging.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98371
diff changeset
532 fprintf (stderr, "family: '%s'\ttraits = %ld\tbold = %d\titalic = %d\n",
6b3b02fd9846 * nsfont.m (nsfont_trait_distance): Fix bug. (nsfont_list): Return a list rather than a vector (syncs with Handa changes of 2008-05-14). (nsfont_open): Improve logging.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98371
diff changeset
533 [family UTF8String], traits, traits & NSBoldFontMask,
6b3b02fd9846 * nsfont.m (nsfont_trait_distance): Fix bug. (nsfont_list): Return a list rather than a vector (syncs with Handa changes of 2008-05-14). (nsfont_open): Improve logging.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98371
diff changeset
534 traits & NSItalicFontMask);
96676
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 /* 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
538 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
539 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
540 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
541 size: pixel_size];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
542 /* 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
543 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
544 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
545 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
546 traits: traits & ~NSItalicFontMask
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
547 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
548 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
549 #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
550 /* 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
551 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
552 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
553 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
554 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
555 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
556
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
557 if (nsfont == nil)
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 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
560 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
561 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
562 if (!nsfont)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
563 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
564 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
565 return Qnil;
96676
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 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
568
98451
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
569 if (NSFONT_TRACE)
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
570 NSLog (@"%@\n", nsfont);
98399
6b3b02fd9846 * nsfont.m (nsfont_trait_distance): Fix bug. (nsfont_list): Return a list rather than a vector (syncs with Handa changes of 2008-05-14). (nsfont_open): Improve logging.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98371
diff changeset
571
98451
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
572 /* Check the cache */
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
573 cached = [fontCache objectForKey: nsfont];
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
574 if (cached != nil && !synthItal)
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
575 {
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
576 if (NSFONT_TRACE)
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
577 fprintf(stderr, "*** nsfont_open CACHE HIT!\n");
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
578 return (Lisp_Object)[cached unsignedLongValue];
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
579 }
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
580 else
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
581 {
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
582 font_object = font_make_object (VECSIZE (struct nsfont_info),
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
583 font_entity, pixel_size);
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
584 if (!synthItal)
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
585 [fontCache
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
586 setObject: [NSNumber numberWithUnsignedLong:
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
587 (unsigned long)font_object]
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
588 forKey: nsfont];
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
589 }
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
590
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
591 font_info = (struct nsfont_info *) XFONT_OBJECT (font_object);
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
592 font = (struct font *)font_info;
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
593 if (!font)
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
594 return Qnil; /* FIXME: other terms do, but return Qnil causes segfault */
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
595
97198
cf43f4e3ecc8 clear warnings and clean up NS port
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96892
diff changeset
596 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
597 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
598 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
599 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
600 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
601 return Qnil;
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
602 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
603 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
604
98451
db015b441c0c * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98399
diff changeset
605 BLOCK_INPUT;
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
606
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
607 /* for metrics */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
608 sfont = [nsfont screenFont];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
609 if (sfont == nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
610 sfont = nsfont;
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 /* 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
613 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
614 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
615 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
616 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
617 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
618 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
619 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
620 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
621 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
622 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
623 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
624
96892
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
625 /* 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
626 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
627 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
628
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
629 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
630 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
631 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
632 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
633 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
634
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
635 #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
636 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
637 #else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
638 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
639 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
640 [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
641
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
642 /* 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
643 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
644 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
645 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
646 font_info->ital =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
647 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
648
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
649 /* 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
650 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
651 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
652 [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
653
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
654 brect = [sfont boundingRectForFont];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
655 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
656 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
657 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
658
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
659 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
660 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
661
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
662 /* 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
663 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
664
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
665 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
666 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
667 shrink = 1 + expand;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
668 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
669 expand = 0.0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
670 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
671 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
672 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
673
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
674 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
675 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
676 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
677 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
678
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
679 /* max bounds */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
680 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
681 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
682 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
683 -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
684 font_info->height =
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 + 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
686 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
687 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
688 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
689 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
690 /*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
691
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
692 #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
693 /* 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
694 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
695 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
696 ATSFontRef atsFont = ATSFontFindFromPostScriptName
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
697 ((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
698
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
699 if (atsFont == kATSFontRefUnspecified)
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 /* 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
702 atsFont = ATSFontFindFromPostScriptName ((CFStringRef)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
703 [[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
704 fontName], kATSOptionFlagsDefault);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
705 if (atsFont != kATSFontRefUnspecified)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
706 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
707 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
708 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
709 /* last resort fallback */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
710 atsFont = ATSFontFindFromPostScriptName
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
711 ((CFStringRef)@"Monaco", kATSOptionFlagsDefault);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
712 }
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 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
715 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
716 #endif
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 /* 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
719 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
720 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
721 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
722 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
723 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
724 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
725 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
726 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
727 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
728
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
729 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
730 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
731 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
732 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
733 UNBLOCK_INPUT;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
734
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
735 return font_object;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
736 }
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
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
739 /* 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
740 static void
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
741 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
742 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
743 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
744 int i;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
745
96892
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
746 /* 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
747 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
748 (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
749 if (!font_info)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
750 return;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
751
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
752 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
753 {
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->glyphs[i])
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
755 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
756 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
757 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
758 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
759 [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
760 #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
761 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
762 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
763 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
764 xfree (font_info);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
765 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
766
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
767
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
768 /* 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
769 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
770 it, return -1. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
771 static int
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
772 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
773 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
774 return -1;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
775 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
776
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
777
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
778 /* 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
779 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
780 static unsigned int
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
781 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
782 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
783 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
784 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
785 unsigned short g;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
786
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
787 if (c > 0xFFFF)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
788 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
789
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
790 /* 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
791 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
792 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
793
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
794 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
795 /*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
796 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
797 }
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
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
800 /* 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
801 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
802 CODE (length NGLYPHS). */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
803 static int
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
804 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
805 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
806 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
807 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
808 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
809 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
810 int totalWidth = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
811 int i;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
812
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
813 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
814
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
815 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
816 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
817 /* 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
818 /* 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
819 (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
820 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
821 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
822 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
823 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
824 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
825
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
826 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
827 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
828 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
829 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
830 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
831 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
832 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
833 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
834
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
835 totalWidth += pcm->width;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
836 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
837
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
838 metrics->width = totalWidth;
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 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
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
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
844 /* 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
845 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
846 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
847 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
848 static int
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
849 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
850 int with_background)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
851 /* 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
852 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
853 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
854 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
855 char *c = cbuf;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
856 #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
857 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
858 float *adv = advances;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
859 #else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
860 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
861 CGSize *adv = advances;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
862 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
863 struct face *face;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
864 NSRect r;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
865 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
866 NSColor *col, *bgCol;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
867 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
868 int i, len;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
869
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
870 /* 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
871 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
872 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
873 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
874 face = s->face;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
875 break;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
876 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
877 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
878 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
879 if (!face)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
880 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
881 break;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
882 default:
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
883 face = s->face;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
884 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
885
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
886 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
887 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
888 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
889
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
890 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
891 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
892
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
893 /* 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
894 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
895 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
896 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
897 XCharStruct *cs;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
898 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
899 int hi, lo;
98371
713cc05ca791 * nsfont.m (nsfont_draw): Fix up composition rendering.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98073
diff changeset
900 char isComposite = 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
901 /* FIXME: composition: no vertical displacement is considered. */
98371
713cc05ca791 * nsfont.m (nsfont_draw): Fix up composition rendering.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98073
diff changeset
902 t += s->cmp_from; /* advance into composition */
713cc05ca791 * nsfont.m (nsfont_draw): Fix up composition rendering.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98073
diff changeset
903 for (i = s->cmp_from; i < s->nchars; i++, t++)
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
904 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
905 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
906 lo = *t & 0x00FF;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
907 if (isComposite)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
908 {
98371
713cc05ca791 * nsfont.m (nsfont_draw): Fix up composition rendering.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 98073
diff changeset
909 cwidth = s->cmp->offsets[i * 2] /* (H offset) */ - twidth;
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
910 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
911 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
912 {
96892
4aec559b9f05 NS cleanup: change 'PENDING' to 'FIXME'/'TODO'/'XXX'
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96817
diff changeset
913 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
914 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
915 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
916 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
917 twidth += cwidth;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
918 #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
919 *adv++ = cwidth;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
920 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
921 #else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
922 (*adv++).width = cwidth;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
923 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
924 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
925 len = adv - advances;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
926 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
927 *c = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
928 }
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 /* 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
931 if (with_background)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
932 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
933 NSRect br = r;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
934 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
935 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
936
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
937 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
938 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
939 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
940 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
941 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
942 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
943 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
944 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
945 <= fibw+1)
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 += fibw;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
947 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
948 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
949 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
950 /* 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
951 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
952 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
953 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
954 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
955 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
956 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
957 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
958 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
959 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
960 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
961 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
962 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
963 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
964 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
965
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
966 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
967 [(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
968 ? 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
969 : 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
970 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
971 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
972 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
973 [[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
974 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
975 NSRectFill (br);
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
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
978
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
979 /* 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
980 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
981
97198
cf43f4e3ecc8 clear warnings and clean up NS port
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96892
diff changeset
982 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
983 ? 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
984 : 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
985 /* 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
986 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
987 : (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
988 ? 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
989 : 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
990
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
991 /* 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
992 #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
993 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
994 NSGraphicsContext *context = GSCurrentContext ();
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 DPSgsave (context);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
997 [font->nsfont set];
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 /* 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
1000 if (bgCol != nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1001 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1002 [bgCol set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1003 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
1004 /*[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
1005 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
1006 DPSstroke (context);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1007 [col set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1008 /*[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
1009 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1010
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1011 /* do underline */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1012 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
1013 {
97584
06f7d5858c5a * nsfns.m (ns-read-file-name): Add casts to avoid warning. (ns-convert-utf8-nfd-to-nfc): Warn if cannot execute correctly. * nsfont.m (nsfont_draw): Compare indexed colors to 0, not nil. * nsterm.h (EmacsView-unlockFocusNeedsFlush:): Add declaration. (EmacsApp-cursor_blink_handler): Remove declaration. * nsterm.m (ns_draw_glyph_string): Update first conditional body to match 01 Feb 2008 changes in xterm.c. (ns_read_socket): Add cast to avoid warning. (EmacsApp-application:openFiles:): Don't call replyToOpenOrPrint: on GNUstep.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 97198
diff changeset
1014 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
1015 [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
1016 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1017 [col set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1018 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
1019 DPSlineto (context, r.origin.x+r.size.width, r.origin.y+font->underpos);
97584
06f7d5858c5a * nsfns.m (ns-read-file-name): Add casts to avoid warning. (ns-convert-utf8-nfd-to-nfc): Warn if cannot execute correctly. * nsfont.m (nsfont_draw): Compare indexed colors to 0, not nil. * nsterm.h (EmacsView-unlockFocusNeedsFlush:): Add declaration. (EmacsApp-cursor_blink_handler): Remove declaration. * nsterm.m (ns_draw_glyph_string): Update first conditional body to match 01 Feb 2008 changes in xterm.c. (ns_read_socket): Add cast to avoid warning. (EmacsApp-application:openFiles:): Don't call replyToOpenOrPrint: on GNUstep.
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 97198
diff changeset
1020 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
1021 [col set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1022 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1023 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1024 [col set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1025
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1026 /* draw with DPSxshow () */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1027 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
1028 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
1029 DPSstroke (context);
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 DPSgrestore (context);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1032 return to-from;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1033 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1034
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1035 #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
1036 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1037 CGContextRef gcontext =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1038 [[NSGraphicsContext currentContext] graphicsPort];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1039 static CGAffineTransform fliptf;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1040 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
1041
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1042 if (firstTime)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1043 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1044 firstTime = NO;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1045 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
1046 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1047
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1048 CGContextSaveGState (gcontext);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1049
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1050 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
1051
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1052 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
1053 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
1054 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
1055 CGContextSetShouldAntialias (gcontext, 0);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1056 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1057 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
1058 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
1059 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
1060
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1061 CGContextSetTextMatrix (gcontext, fliptf);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1062
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1063 if (bgCol != nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1064 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1065 /* 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
1066 [bgCol set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1067 CGContextSetTextDrawingMode (gcontext, kCGTextFillStroke);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1068 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
1069 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
1070 CGContextSetTextDrawingMode (gcontext, kCGTextFill);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1071 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1072
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1073 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
1074 {
97198
cf43f4e3ecc8 clear warnings and clean up NS port
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96892
diff changeset
1075 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
1076 [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
1077 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1078 [col set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1079 CGContextBeginPath (gcontext);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1080 CGContextMoveToPoint (gcontext,
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1081 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
1082 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
1083 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
1084 CGContextStrokePath (gcontext);
97198
cf43f4e3ecc8 clear warnings and clean up NS port
Adrian Robert <Adrian.B.Robert@gmail.com>
parents: 96892
diff changeset
1085 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
1086 [col set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1087 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1088 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1089 [col set];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1090
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1091 CGContextSetTextPosition (gcontext, r.origin.x, r.origin.y);
98073
e77a63e6f983 * nsfont.m (nsfont_draw): Fix the references to missing gidx data
Teodor Zlatanov <tzz@lifelogs.com>
parents: 97584
diff changeset
1092 CGContextShowGlyphsWithAdvances (gcontext, s->char2b + s->cmp_from,
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1093 advances, len);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1094
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1095 if (face->overstrike)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1096 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1097 CGContextSetTextPosition (gcontext, r.origin.x+0.5, r.origin.y);
98073
e77a63e6f983 * nsfont.m (nsfont_draw): Fix the references to missing gidx data
Teodor Zlatanov <tzz@lifelogs.com>
parents: 97584
diff changeset
1098 CGContextShowGlyphsWithAdvances (gcontext, s->char2b + s->cmp_from,
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1099 advances, len);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1100 }
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 CGContextRestoreGState (gcontext);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1103 return;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1104 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1105 #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
1106
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1107 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1108
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 /* 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
1111 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
1112 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
1113 in range. */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1114 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
1115 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1116 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
1117 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
1118 (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
1119
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1120 /* 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
1121 static NSTextStorage *store;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1122 static NSLayoutManager *layout;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1123 static NSRange range;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1124 static NSMutableDictionary *attribs;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1125 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
1126 static int nscripts;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1127 static int *scriptsNchars;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1128 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
1129 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
1130 int i, j;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1131
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1132 if (firstTime == YES)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1133 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1134 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
1135 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
1136 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
1137 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
1138 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
1139
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1140 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
1141
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1142 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
1143 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1144 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
1145 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
1146 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
1147 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
1148
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1149 while (CONSP (chars))
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1150 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1151 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
1152 chars = XCDR (chars);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1153 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
1154 c++;
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 scriptsNchars[i] = c;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1157
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1158 scriptsChars = XCDR (scriptsChars);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1159 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1160 *tpos = '\0';
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1161
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1162 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
1163 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
1164 [store addLayoutManager: layout];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1165 [layout release];
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 beginEditing];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1168 [[store mutableString] appendString:
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1169 [NSString stringWithUTF8String: buf]];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1170 [store endEditing];
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 free (buf);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1173 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
1174
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1175 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
1176 firstTime = NO;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1177 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1178
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1179 /* set the fonts */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1180 [store beginEditing];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1181 [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
1182 [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
1183 [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
1184 [store endEditing];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1185
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1186 /* read them out */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1187 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1188 NSMutableDictionary *map =
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1189 [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
1190 NSEnumerator *fonts;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1191 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
1192 NSNumber *n;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1193 int idx = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1194 int max;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1195 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
1196 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1197 [map removeAllObjects];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1198 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
1199 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1200 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
1201 effectiveRange: NULL];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1202 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
1203 if (n == nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1204 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
1205 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1206 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
1207 [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
1208 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1209
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1210 /* majority rules */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1211 max = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1212 fonts = [map keyEnumerator];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1213 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
1214 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1215 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
1216 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
1217 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1218 cfont = tfont;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1219 max = [n intValue];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1220 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1221 }
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 if (cfont != nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1224 {
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
1225 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
1226 Lisp_Object famAndReg;
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 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
1229 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
1230
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1231 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1232 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
1233 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
1234 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
1235
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1236 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
1237 free (family);
96676
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1238 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1239 else
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 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
1242 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
1243 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1244 } /* for i = script */
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 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1247
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
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 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
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 /* 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
1257 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
1258 static void
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1259 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
1260 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1261 #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
1262 static EmacsGlyphStorage *glyphStorage;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1263 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
1264 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1265 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
1266 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
1267 unsigned short *glyphs;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1268
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1269 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1270 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
1271 font_info, block);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1272
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1273 BLOCK_INPUT;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1274
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1275 #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
1276 if (firstTime)
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 firstTime = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1279 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
1280 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1281 #endif
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 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
1284 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
1285 abort ();
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1286
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1287 /* 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
1288 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
1289 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
1290 unichars[i] = idx;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1291 else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1292 unichars[i] = 0xFEFF;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1293 unichars[0x100] = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1294
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1295 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1296 #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
1297 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
1298 initWithCharactersNoCopy: unichars
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1299 length: 0x100
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1300 freeWhenDone: NO];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1301 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
1302 /*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
1303 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
1304 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
1305
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1306 [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
1307 [glyphGenerator generateGlyphsForGlyphStorage: glyphStorage
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1308 desiredNumberOfCharacters: glyphStorage->maxChar
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1309 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
1310 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1311 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
1312 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
1313 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1314 #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
1315 g = unichars[i];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1316 #else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1317 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
1318 /* 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
1319 if (g > numGlyphs)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1320 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
1321 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1322 *glyphs = g;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1323 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1324
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1325 #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
1326 [allChars release];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1327 #endif
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 UNBLOCK_INPUT;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1331 xfree (unichars);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1332 }
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 /* 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
1336 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
1337 static void
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1338 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
1339 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1340 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
1341 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
1342 NSFont *sfont;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1343 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
1344
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1345 if (NSFONT_TRACE)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1346 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
1347 font_info, block);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1348
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1349 #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
1350 /* 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
1351 if (numGlyphs == 0)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1352 numGlyphs = 0x10000;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1353 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1354
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1355 BLOCK_INPUT;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1356 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
1357
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1358 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
1359 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
1360 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
1361 abort ();
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 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
1364 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
1365 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1366 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
1367 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
1368
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1369 #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
1370 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1371 /* lord help us */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1372 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
1373 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
1374 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1375 #else
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1376 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
1377 #endif
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1378 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
1379 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
1380
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1381 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
1382 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
1383 if (lb < 0)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1384 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
1385 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
1386 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
1387 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
1388
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1389 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
1390 /*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
1391 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
1392 /*-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
1393 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1394 UNBLOCK_INPUT;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1395 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1396
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1397
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1398 #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
1399 /* 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
1400 @implementation EmacsGlyphStorage
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 - init
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1403 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1404 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
1405 }
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 - 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
1408 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1409 self = [super init];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1410 maxChar = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1411 maxGlyph = 0;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1412 dict = [NSMutableDictionary new];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1413 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
1414 return self;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1415 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1416
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1417 - (void) dealloc
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1418 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1419 if (attrStr != nil)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1420 [attrStr release];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1421 [dict release];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1422 xfree (cglyphs);
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1423 [super dealloc];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1424 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1425
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1426 - (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
1427 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1428 [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
1429 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
1430 maxChar = [str length];
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1431 maxGlyph = 0;
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
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1434 /* NSGlyphStorage protocol */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1435 - (unsigned int)layoutOptions
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1436 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1437 return 0;
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
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1440 - (NSAttributedString *)attributedString
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 attrStr;
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 - (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
1446 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
1447 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
1448 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1449 len = glyphIndex+length;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1450 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
1451 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
1452 if (len > maxGlyph)
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1453 maxGlyph = len;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1454 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1455
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1456 - (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
1457 forGlyphAtIndex: (unsigned)glyphIndex
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1458 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1459 return;
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
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1462 @end
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1463 #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
1464
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 /* Debugging */
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1467 void
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1468 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
1469 {
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1470 int i;
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1471
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1472 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
1473 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
1474 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
1475 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
1476 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
1477 fprintf (stderr, "\n");
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1478 }
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1479
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1480
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1481
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1482 void
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1483 syms_of_nsfont ()
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 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
1486 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
1487 DEFSYM (Qapple, "apple");
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1488 DEFSYM (Qroman, "roman");
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1489 DEFSYM (Qmedium, "medium");
336d4f3f5eca adding forgotten file src/nsfont.m for emacs.app merge
Adrian Robert <Adrian.B.Robert@gmail.com>
parents:
diff changeset
1490 }
96685
e869d0172660 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 96676
diff changeset
1491
96689
f34c4d928d39 Use nicer comment syntax for arch taglines in Objective-C files
Miles Bader <miles@gnu.org>
parents: 96685
diff changeset
1492 // arch-tag: d6c3c6f0-62de-4978-8b1e-b7966fe02cae