//http://msdn2.microsoft.com/en-us/library/ms970775.aspx void Win32Helper::setFont(const char * fontName) { fontBase = glGenLists(127); HFONT font = CreateFont( -12, 0, 0, // Angle Of Escapement 0, // Orientation Angle FW_BOLD, // Font Weight FALSE, // Italic FALSE, // Underline FALSE, // Strikeout ANSI_CHARSET, // Character Set Identifier OUT_TT_PRECIS, // Output Precision CLIP_DEFAULT_PRECIS, // Clipping Precision ANTIALIASED_QUALITY, // Output Quality FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch L"Courier New" ); HDC hDC = wglGetCurrentDC(); SelectObject(hDC,font); int x = wglUseFontOutlines( hDC, __toascii(' '), // Starting Character __toascii(' ') + 126,// Number Of Display Lists To Build fontBase, // Starting Display Lists 0.0f, // Deviation From The True Outlines 0.2f, // Font Thickness In The Z Direction WGL_FONT_POLYGONS, // Use Polygons, Not Lines NULL ); DeleteObject(font); }
void Win32Helper::writeText(const string & text, float x,float y) { if( fontBase < 0 ) setFont("Arial"); glPushMatrix(); glTranslatef(x,y,0); glScalef(15,15,15); glListBase(fontBase - __toascii(' ')); glColor3f(0,1,0); glCallLists(GLsizei(text.length()), GL_UNSIGNED_BYTE, text.c_str()); glPopMatrix(); }
int toascii(int c) { return __toascii(c); /* locale-independent */ }
int __XL_NPP(toascii)(int c) { return __toascii(c); /* locale-independent */ }
int toascii (int c) { return __toascii (c); }
// strURL: URL to encode. // bEncodeReserved: Encode the reserved characters // for example the ? character, which is used many times // for arguments in URL. // so if we are encoding just a string containing Keywords, // we want to encode the reserved characters. // but if we are encoding a simple URL, we wont. CString CURLEncode::Encode(CString strURL, BOOL bEncodeReserved/*=FALSE*/) { // First encode the % sign, because we are adding lots of it later... strURL.Replace(_T("%"), toHex(__toascii(_T('%')))); // Encdoe the reserved characters, if we choose to if (bEncodeReserved) { for (int i=0; i<m_iReservedLen; i++) { strURL.Replace(CString(m_lpszReservedString[i]), toHex(__toascii(m_lpszReservedString[i]))); } } // Encode 'unsafe' characters // see: http://www.blooberry.com/indexdot/html/topics/urlencoding.htm for (int i=0; i<m_iUnsafeLen; i++) { strURL.Replace(CString(m_lpszUnsafeString[i]), toHex(__toascii(m_lpszUnsafeString[i]))); } // Encode unprintable characters 0x00-0x1F, and 0x7F for (char c=0x00; c<=0x1F; c++) { strURL.Replace(CString(c), toHex(c)); } strURL.Replace(CString((char)0x7F), toHex(0x7F)); // Now encode all other unsafe characters TCHAR tc=0; WORD w=0; CString nc; // In this stage we do not want to convert: // 1. Characters A-Z, a-z, 0-9, because they are safe. // 2. The reserved characteres, we have already dealt with them; // 3. The % character... CString strDoNotReplace(m_lpszReservedString); strDoNotReplace.Append(_T("%")); for (int i=0; i<strURL.GetLength(); i++) { tc=strURL.GetAt(i); if ((tc<_T('a') || tc>_T('z')) && (tc<_T('A') || tc>_T('Z')) && (tc<_T('0') || tc>_T('9')) && strDoNotReplace.Find(tc)<0) { w=toUTF8(tc); nc=toHex(HIBYTE(w)); nc.Append(toHex(LOBYTE(w))); strURL.Replace(CString(tc), nc); // We have added 5 extra characters to the length of the string, // So we can ignore them. i+=5; } } return strURL; }
// strURL: URL to decode. CString CURLEncode::Decode(CString strURL) { int i=strURL.Find(_T('%')); TCHAR tc1=0, tc2=0; BYTE b=0; BOOL bFound=FALSE; while (i>-1) { tc1=strURL.GetAt(i+1); tc2=strURL.GetAt(i+2); if (isHex(tc1) && isHex(tc2)) { b=hexToDec(tc1, tc2); // first deal with 1-byte unprintable characters if (b<0x1F || b==0x7F) { strURL.SetAt(i, b); strURL.Delete(i+1, 2); } else { // Then deal with 1-byte unsafe/reserved characters // We are reading for those static LPCTSTR strings, // so we have nice support for Unicode bFound=FALSE; for (int ii=0; ii<m_iUnsafeLen && !bFound; ii++) { if (__toascii(m_lpszUnsafeString[ii])==b) { strURL.SetAt(i, m_lpszUnsafeString[ii]); strURL.Delete(i+1, 2); bFound=TRUE; } } for (int ii=0; ii<m_iReservedLen && !bFound; ii++) { if (__toascii(m_lpszReservedString[ii])==b) { strURL.SetAt(i, m_lpszReservedString[ii]); strURL.Delete(i+1, 2); bFound=TRUE; } } // Then deal with UTF-8 (2-bytes) characters if (!bFound) { // We need to have 2 bytes for decoding if (strURL.GetAt(i+3)==_T('%')) { tc1=strURL.GetAt(i+4); tc2=strURL.GetAt(i+5); if (isHex(tc1) && isHex(tc2)) { BYTE b2=hexToDec(tc1, tc2); strURL.SetAt(i, fromUTF8(MAKEWORD(b2, b))); strURL.Delete(i+1, 5); } } } } } i=strURL.Find(_T('%'), i+1); } return strURL; }