Skip to content

Commit 5a8a8ec

Browse files
committed
Removed global for storing fonts in use. started refactoring based on runrevmark suggestions.
1 parent 34712ca commit 5a8a8ec

12 files changed

Lines changed: 75 additions & 101 deletions

File tree

engine/src/cmdse.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,7 +1976,7 @@ Exec_stat MCStart::exec(MCExecPoint &ep)
19761976
// TODO: If font is already in use then stop using.
19771977
// TODO: throw error if system doesn't support loading font globally.
19781978

1979-
t_error = MCscreen->loadfont(t_resolved_path, is_globally);
1979+
// t_error = MCscreen->loadfont(t_resolved_path, is_globally);
19801980
if (t_error != EE_UNDEFINED)
19811981
{
19821982
MCeerror->add(t_error, line, pos);
@@ -2290,7 +2290,7 @@ Exec_stat MCStop::exec(MCExecPoint &ep)
22902290
//if (ep . getboolean(t_new_value, 0, 0, EE_PROPERTY_NAB) != ES_NORMAL)
22912291
//return false;
22922292

2293-
t_error = MCscreen->unloadfont(t_resolved_path, t_load_globally);
2293+
//t_error = MCscreen->unloadfont(t_resolved_path, t_load_globally);
22942294
if (t_error != EE_UNDEFINED)
22952295
{
22962296
MCeerror->add(t_error, line, pos);

engine/src/font.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ uint16_t MCFontStyleToTextStyle(MCFontStyle p_font_style)
183183
return t_style;
184184
}
185185

186+
187+
// TD-2013-07-02: [[ DynamicFonts ]]
188+
Exec_stat MCFontLoad(MCExecPoint& ep, const char *p_path, bool p_globally)
189+
{
190+
// TODO
191+
}
192+
Exec_stat MCFontUnload(MCExecPoint& ep, const char *p_path)
193+
{
194+
// TODO
195+
}
196+
Exec_stat MCFontListLoaded(MCExecPoint& ep)
197+
{
198+
// TODO
199+
}
200+
186201
////////////////////////////////////////////////////////////////////////////////
187202

188203
static const char *weightstrings[] =

engine/src/font.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ uint2 MCLogicalFontTableMap(MCNameRef p_textfont, uint2 p_textstyle, uint2 p_tex
8383
// Lookup the given index in the logical font table, and return its attrs.
8484
void MCLogicalFontTableLookup(uint2 index, MCNameRef& r_textfont, uint2& r_textstyle, uint2& r_textsize, bool& r_unicode);
8585

86+
87+
// TD-2013-07-01: [[ DynamicFonts ]]
88+
struct MCLoadedFont
89+
{
90+
MCLoadedFont *next;
91+
char *path;
92+
bool is_global;
93+
void *handle;
94+
};
95+
96+
Exec_stat MCFontLoad(MCExecPoint& ep, const char *p_path, bool p_globally);
97+
Exec_stat MCFontUnload(MCExecPoint& ep, const char *p_path);
98+
Exec_stat MCFontListLoaded(MCExecPoint& ep);
99+
86100
////////////////////////////////////////////////////////////////////////////////
87101

88102
enum Font_weight {

engine/src/globals.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,6 @@ uint2 MCiconicstacks;
230230
uint2 MCwaitdepth;
231231
uint4 MCrecursionlimit = 400000; // actual max is about 480K on OSX
232232

233-
// TD-2013-06-20: [[ DynamicFonts ]] list of font files in use.
234-
MCVariableValue *MCfontsusing;
235-
236233
MCClipboardData *MCclipboarddata;
237234
MCSelectionData *MCselectiondata;
238235

@@ -811,9 +808,6 @@ void X_clear_globals(void)
811808
MCtruemcstring = MCtruestring;
812809
MCfalsemcstring = MCfalsestring;
813810
MCnullmcstring = NULL;
814-
815-
// TD-2013-06-20: [[ DynamicFonts ]] list of font files in use.
816-
MCfontsusing = NULL;
817811

818812
// MW-2013-03-11: [[ Bug 10713 ]] Make sure we reset the regex cache globals to nil.
819813
for(uindex_t i = 0; i < PATTERN_CACHE_SIZE; i++)

engine/src/globals.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ extern uint2 MCiconicstacks;
155155
extern uint2 MCwaitdepth;
156156
extern uint4 MCrecursionlimit;
157157

158-
// TD-2013-06-20: [[ DynamicFonts ]] list of font files in use.
159-
extern MCVariableValue *MCfontsusing;
160-
161158

162159
extern Boolean MCownselection;
163160
extern MCUndolist *MCundos;

engine/src/osxdc.cpp

Lines changed: 13 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -226,90 +226,45 @@ int4 MCScreenDC::textwidth(MCFontStruct *f, const char *s, uint2 len, bool p_uni
226226
}
227227
}
228228

229-
// TD-2013-05-29 [[ DynamicFonts ]]
230-
MCVariableValue *s_font_array;
231-
232-
// p_path is a fully resolved path
233-
Exec_errors MCScreenDC::loadfont(const char *p_path, bool p_load_globally)
229+
// TD-2013-07-01 [[ DynamicFonts ]]
230+
bool MCScreenDC::loadfont(const char *p_path, bool p_globally, void*& r_loaded_font_handle)
234231
{
235232
FSRef t_ref;
236233
FSSpec t_fsspec;
237234
OSErr t_os_error;
238235

239236
t_os_error = MCS_pathtoref(p_path, &t_ref); // resolves and converts to UTF8.
240237
if (t_os_error != noErr)
241-
return EE_FONT_BADFILEEXP;
238+
return false; //EE_FONT_BADFILEEXP;
242239

243240
t_os_error = MCS_fsref_to_fsspec(&t_ref, &t_fsspec);
244241
if (t_os_error != noErr)
245-
return EE_FONT_BADFILEEXP;
242+
return false; //EE_FONT_BADFILEEXP;
246243

247244
ATSFontContext t_context = kATSFontContextLocal;
248-
if (p_load_globally)
245+
if (p_globally)
249246
t_context = kATSFontContextGlobal;
250247

251-
// create array to store container.
252-
if (s_font_array == NULL)
253-
{
254-
s_font_array = new MCVariableValue;
255-
if (s_font_array == NULL)
256-
return EE_FONT_CANTLOAD;
257-
}
258-
259248
ATSFontContainerRef t_container = NULL;
260-
249+
261250
// Note: ATSFontActivateFromFileReference should be used from 10.5 onward.
262251
// ATSFontActivateFromFileSpecification deprecated in 10.5.
263252
t_os_error = ATSFontActivateFromFileSpecification(&t_fsspec, t_context, kATSFontFormatUnspecified, NULL, kATSOptionFlagsDefault, &t_container);
264253
if (t_os_error != noErr)
265-
return EE_FONT_CANTLOAD;
266-
267-
// Add font to list of fonts
268-
MCVariableValue *t_font;
269-
uint32_t index = 1;
270-
if (s_font_array -> is_array())
271-
index = s_font_array -> get_array() -> getnfilled() + 1;
272-
273-
MCExecPoint *t_ep = new MCExecPoint();
274-
275-
s_font_array -> lookup_index(*t_ep, index, t_font);
254+
return false; //EE_FONT_CANTLOAD;
276255

277-
t_ep -> setcstring(p_path);
278-
t_font -> store_element(*t_ep, "name");
256+
// TODO: store t_container in r_loaded_font_handle
279257

280-
// s_font_map . insert(make_pair(std::string(t_resolved_path), t_container));
281-
282-
return EE_UNDEFINED;
258+
return true;
283259
}
284260

285261

286-
Exec_errors MCScreenDC::unloadfont(const char *p_path, bool p_load_globally)
262+
bool MCScreenDC::unloadfont(const char *p_path, bool p_globally, void *r_loaded_font_handle)
287263
{
288-
/* const char *t_error;
289-
t_error = NULL;
290-
291-
// Get resolved path for storage in t_container (should this be UTF8 version of path?)
292-
char *t_resolved_path;
293-
t_resolved_path = MCS_resolvepath(p_filename);
294-
295-
ATSFontContainerRef t_container;
296-
t_container = NULL;
264+
OSStatus t_status;
265+
t_status = ATSFontDeactivate((ATSFontContainerRef)r_loaded_font_handle, NULL, kATSOptionFlagsDefault);
297266

298-
if (t_error == NULL)
299-
{
300-
t_container = s_font_map[t_resolved_path];
301-
if (t_container == NULL)
302-
t_error = "couldn't unload font";
303-
}
304-
305-
if (t_error == NULL)
306-
{
307-
OSStatus t_status;
308-
t_status = ATSFontDeactivate(t_container, NULL, kATSOptionFlagsDefault);
309-
s_font_map . erase(t_resolved_path);
310-
}
311-
*/
312-
return EE_UNDEFINED;
267+
return (t_status == noErr);
313268
}
314269

315270
//

engine/src/osxdc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,9 @@ class MCScreenDC : public MCUIDC
409409
virtual bool setclipboard(MCPasteboard *p_pasteboard);
410410
virtual MCPasteboard *getclipboard(void);
411411

412-
// TD-2013-05-29: [[ DynamicFonts ]]
413-
virtual Exec_errors loadfont(const char *p_pathbool, bool p_load_globally);
414-
virtual Exec_errors unloadfont(const char *p_path, bool p_load_globally);
412+
// TD-2013-07-01: [[ DynamicFonts ]]
413+
virtual bool loadfont(const char *p_path, bool p_globally, void*& r_loaded_font_handle);
414+
virtual bool unloadfont(const char *p_path, bool p_globally, void *r_loaded_font_handle);
415415

416416
//
417417

engine/src/property.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,7 +3582,9 @@ Exec_stat MCProperty::eval(MCExecPoint &ep)
35823582
// TD-2013-06-20: [[ DynamicFonts ]] global property for list of font files
35833583
case P_FONTFILES_IN_USE:
35843584
ep.clear();
3585-
if (MCfontsusing -> is_array())
3585+
/*
3586+
ORIGINAL IMPLEMENTATION
3587+
if (MCfontsusing -> is_array())
35863588
{
35873589
for(uint32_t i = 1; i <= MCfontsusing -> get_array() -> getnfilled(); i++)
35883590
{
@@ -3597,7 +3599,7 @@ Exec_stat MCProperty::eval(MCExecPoint &ep)
35973599
35983600
ep.concatmcstring(ep2.getcstring(), EC_RETURN, i == 1);
35993601
}
3600-
}
3602+
}*/
36013603
break;
36023604

36033605
case P_RELAYER_GROUPED_CONTROLS:

engine/src/uidc.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,16 +1992,15 @@ bool MCUIDC::setclipboard(MCPasteboard *p_pasteboard)
19921992
}
19931993

19941994

1995-
// TD-2013-05-29 [[ DynamicFonts ]]
1996-
1997-
Exec_errors MCUIDC::loadfont(const char *p_path, bool p_load_globally)
1995+
// TD-2013-07-01: [[ DynamicFonts ]]
1996+
bool MCUIDC::loadfont(const char *p_path, bool p_globally, void*& r_loaded_font_handle)
19981997
{
1999-
return EE_UNDEFINED;
1998+
return false;
20001999
}
20012000

2002-
Exec_errors MCUIDC::unloadfont(const char *p_path, bool p_load_globally)
2001+
bool MCUIDC::unloadfont(const char *p_path, bool p_globally, void *r_loaded_font_handle)
20032002
{
2004-
return EE_UNDEFINED;
2003+
return NULL;
20052004
}
20062005

20072006
//

engine/src/uidc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,8 @@ class MCUIDC
525525
//
526526

527527
// TD-2013-05-29: [[ DynamicFonts ]]
528-
virtual Exec_errors loadfont(const char *p_path, bool p_load_globally);
529-
virtual Exec_errors unloadfont(const char *p_path, bool p_load_globally);
528+
virtual bool loadfont(const char *p_path, bool p_globally, void*& r_loaded_font_handle);
529+
virtual bool unloadfont(const char *p_path, bool p_globally, void *r_loaded_font_handle);
530530

531531
//
532532

0 commit comments

Comments
 (0)