Skip to content

Commit

Permalink
AddFont now lets you add multiple fonts (one at a time)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed May 28, 2014
1 parent 99a11ac commit 7349bb5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 21 deletions.
31 changes: 16 additions & 15 deletions doc.cpp
Expand Up @@ -7659,12 +7659,12 @@ long CMUSHclientDoc::AddSpecialFont (LPCTSTR PathName)
return eNoSuchCommand;


// same one again - just leave well enough alone
if (m_strSpecialFontName == PathName)
ci_set::const_iterator iter = m_strSpecialFontName.find (PathName);

// same one as earlier - just leave well enough alone
if (iter != m_strSpecialFontName.end ())
return eOK;

// get rid of old one, if any
RemoveSpecialFont ();


void * pbFont = NULL;
Expand All @@ -7678,25 +7678,26 @@ long CMUSHclientDoc::AddSpecialFont (LPCTSTR PathName)
if (cFonts == 0)
return eFileNotFound;

m_strSpecialFontName = PathName; // remember, so we can remove it
m_strSpecialFontName.insert (PathName); // remember, so we can remove it
return eOK;
} // end of CMUSHclientDoc::AddSpecialFont

void CMUSHclientDoc::RemoveSpecialFont (void)
void CMUSHclientDoc::RemoveSpecialFonts (void)
{
if (m_strSpecialFontName.IsEmpty ())
return;

if (pRemoveFontResourceEx == NULL)
return;

void * pbFont = NULL;
for (ci_set::const_iterator iter = m_strSpecialFontName.begin (); iter != m_strSpecialFontName.end (); iter++)
{

pRemoveFontResourceEx (m_strSpecialFontName, // original file name
FR_PRIVATE, // flags
pbFont); // Reserved. Must be 0.

m_strSpecialFontName.Empty ();
void * pbFont = NULL;

pRemoveFontResourceEx (iter->c_str (), // original file name
FR_PRIVATE, // flags
pbFont); // Reserved. Must be 0.
}

m_strSpecialFontName.clear ();
}


Expand Down
30 changes: 27 additions & 3 deletions doc.h
Expand Up @@ -450,6 +450,31 @@ typedef struct
typedef map<string, tDatabase *> tDatabaseMap;
typedef tDatabaseMap::iterator tDatabaseMapIterator;

// case-independent (ci) string less_than
// returns true if s1 < s2
struct ci_less : binary_function<string, string, bool>
{

// case-independent (ci) compare_less binary function
struct nocase_compare : public binary_function<unsigned char,unsigned char,bool>
{
bool operator() (const unsigned char& c1, const unsigned char& c2) const
{ return tolower (c1) < tolower (c2); }
};

bool operator() (const string & s1, const string & s2) const
{

return lexicographical_compare
(s1.begin (), s1.end (), // source range
s2.begin (), s2.end (), // dest range
nocase_compare ()); // comparison
}
}; // end of ci_less


typedef set<string, ci_less> ci_set;

class ScriptItem
{
public:
Expand Down Expand Up @@ -1294,11 +1319,10 @@ class CMUSHclientDoc : public CDocument
deque<string> m_sRecentLines; // for multi-line triggers


CString m_strSpecialFontName;
HANDLE m_hSpecialFontHandle;
ci_set m_strSpecialFontName; // all the special fonts we loaded (could be none)

long AddSpecialFont (LPCTSTR PathName);
void RemoveSpecialFont (void);
void RemoveSpecialFonts (void);

// background image
CString m_strBackgroundImageName;
Expand Down
3 changes: 1 addition & 2 deletions doc_construct.cpp
Expand Up @@ -63,7 +63,6 @@ int i;
m_nBytesIn = 0;
m_nBytesOut = 0;
m_bTabCompleteFunctions = true;
m_hSpecialFontHandle = 0;

m_iTriggersEvaluatedCount = 0;
m_iTriggersMatchedCount = 0;
Expand Down Expand Up @@ -625,7 +624,7 @@ int i;
DestroyAcceleratorTable (m_accelerator);

// if they loaded a special font, get rid of it
RemoveSpecialFont ();
RemoveSpecialFonts ();

#ifdef PANE

Expand Down
11 changes: 10 additions & 1 deletion scripting/methods/methods_info.cpp
Expand Up @@ -523,7 +523,16 @@ VARIANT CMUSHclientDoc::GetInfo(long InfoType)
case 73: SetUpVariantString (vaResult, __DATE__ " " __TIME__); break;
case 74: SetUpVariantString (vaResult, ExtractDirectory (App.m_strMUSHclientFileName) + "sounds\\"); break;
case 75: SetUpVariantString (vaResult, m_IAC_subnegotiation_data.c_str ()); break;
case 76: SetUpVariantString (vaResult, m_strSpecialFontName); break;
case 76:
{
// for backwards compatibility, return the first special font
ci_set::const_iterator iter = m_strSpecialFontName.begin ();
if (iter != m_strSpecialFontName.end ())
SetUpVariantString (vaResult, iter->c_str ());
else
SetUpVariantString (vaResult, "");
break;
}
case 77: SetUpVariantString (vaResult, os_version.szCSDVersion); break;

case 78: SetUpVariantString (vaResult, m_strForegroundImageName); break;
Expand Down

0 comments on commit 7349bb5

Please sign in to comment.