2323#include " util.h"
2424#include " globals.h"
2525#include " osspec.h"
26+ #include " variable.h"
2627
2728#include " prefix.h"
2829
3233#import < ApplicationServices/ApplicationServices.h>
3334#endif
3435
36+ #ifdef TARGET_SUBPLATFORM_IPHONE
37+ // Stored as a global variable
38+ static MCVariableArray *s_font_map = nil;
39+
40+ // Populate the VariableArray s_font_map
41+ // from the input mapping list (<mapped name>=<PostScript name>).
42+ // Each <PostScript name> is storred keyed as <mapped name>
43+ void add_ios_fontmap (const char *p_mapping)
44+ {
45+ if (s_font_map == nil)
46+ {
47+ s_font_map = new MCVariableArray;
48+ if (s_font_map == nil)
49+ return ;
50+ s_font_map -> presethash (8 );
51+ }
52+
53+ const char *t_separator;
54+ t_separator = strchr (p_mapping, ' =' );
55+ if (t_separator == nil)
56+ return ;
57+
58+ MCString t_from, t_to;
59+ t_from . set (p_mapping, (uint4)(t_separator - p_mapping));
60+
61+ // Make sure we make the 'to' string a C-string (including the NUL terminator
62+ // in the size of the MCString).
63+ t_to . set (t_separator + 1 , (uint4)strlen (t_separator + 1 ) + 1 );
64+
65+ MCHashentry *t_entry;
66+ t_entry = s_font_map -> lookuphash (t_from, False, True);
67+ if (t_entry == nil)
68+ return ;
69+
70+ t_entry -> value . assign_string (t_to);
71+ }
72+
73+ void ios_clear_font_mapping (void )
74+ {
75+ if (s_font_map != nil)
76+ {
77+ s_font_map -> freehash ();
78+ delete s_font_map;
79+ }
80+ }
81+ #endif
82+
3583static void *coretext_font_create_with_name_and_size (const char *p_name, uint32_t p_size)
3684{
3785 /* CFStringRef t_name;
@@ -50,12 +98,32 @@ static void *coretext_font_create_with_name_and_size(const char *p_name, uint32_
5098
5199 bool t_success;
52100 t_success = true ;
101+
102+ // SN-2015-02-16: [[ iOS Font mapping ]] On iOS, try to fetch the mapped
103+ // if one exists.
104+ // Defaults to the given name if no one matches, or on MacOS
105+ const char *t_mapped_name;
106+ t_mapped_name = p_name;
107+
108+ #ifdef TARGET_SUBPLATFORM_IPHONE
109+ if (t_success && s_font_map != nil)
110+ {
111+ MCHashentry *t_entry;
112+ t_entry = s_font_map -> lookuphash (p_name, False, False);
113+
114+ // We have constructed the s_font_map so that the values are C-strings,
115+ // thus we are okay to just used the 'getstring()' ptr here.
116+ if (t_entry != NULL )
117+ t_mapped_name = t_entry -> value . get_string () . getstring ();
118+ }
119+ #endif
53120
54121 CFStringRef t_name;
55122 t_name = NULL ;
56123 if (t_success)
57124 {
58- t_name = CFStringCreateWithCString (NULL , p_name, kCFStringEncodingMacRoman );
125+ // SN-2015-02-16: [[ iOS Font mapping ]] Use the (maybe) mapped font name
126+ t_name = CFStringCreateWithCString (NULL , t_mapped_name, kCFStringEncodingMacRoman );
59127 t_success = t_name != NULL ;
60128 }
61129
@@ -77,9 +145,9 @@ static void *coretext_font_create_with_name_and_size(const char *p_name, uint32_
77145// kCTFontFamilyNameAttribute,
78146 };
79147 CFTypeRef t_values[] = {
148+ // t_name,
80149 t_name,
81- t_name,
82- t_name,
150+ // t_name,
83151 };
84152 t_attributes = CFDictionaryCreate (NULL ,
85153 (const void **)&t_keys, (const void **)&t_values,
@@ -95,14 +163,12 @@ static void *coretext_font_create_with_name_and_size(const char *p_name, uint32_
95163 t_descriptor = CTFontDescriptorCreateWithAttributes (t_attributes);
96164 t_success = t_descriptor != NULL ;
97165 }
98-
166+
99167 CTFontRef t_font;
100168 t_font = NULL ;
101169 if (t_success)
102170 t_font = CTFontCreateWithFontDescriptor (t_descriptor, p_size, NULL );
103-
104- CFStringRef t_font_name = CTFontCopyFullName (t_font);
105-
171+
106172 if (t_descriptor != NULL )
107173 CFRelease (t_descriptor);
108174 if (t_attributes != NULL )
0 commit comments