Example #1
0
bool
XFace::CreateFromData(const char *idata)
{
#ifndef  HAVE_COMPFACE_H
   return false;
#else
   if(data)  delete [] data;
   data = strutil_strdup(idata);
   if(xface) delete [] xface;

   xface = new char[2500];
   strncpy(xface, data, 2500);
   if(compface(xface) < 0)
   {
      delete [] xface;
      delete [] data;
      xface = data = NULL;
      return false;
   }
   //convert it:
   String out = strutil_enforceCRLF(wxString::FromAscii(xface));
   delete [] xface;
   xface = strutil_strdup(out.ToAscii());
   initialised = true;
   return true;
#endif
}
Example #2
0
bool
XFace::CreateFromFile(const String& filename)
{
   wxImage img = GetXFaceImg(filename);
   String datastring = ConvertImgToXFaceData(img);
   return CreateFromData(datastring.ToAscii());
}
Example #3
0
bool
XFace::CreateFromXFace(const char *xfacedata)
{
#ifndef HAVE_COMPFACE_H
   return false;
#else
   if(data) delete [] data;
   if(xface) delete [] xface;
   initialised = false;

   xface = new char [2500];
   strncpy(xface, xfacedata, 2500);
   data = new char [5000];
   strncpy(data, xface, 5000);
   if(uncompface(data) < 0)
   {
      delete [] data;
      delete [] xface;
      data = xface = NULL;
      return false;
   }
   String out = strutil_enforceCRLF(wxString::FromAscii(xface));
   delete [] xface;
   xface = strutil_strdup(out.ToAscii());
   initialised = true;
   return true;
#endif
}
Example #4
0
bool
XFace::CreateXpm(char ***xpm)
{
#ifndef HAVE_COMPFACE_H
   return false;
#else
   int
      l,c,q;
   char
      *ptr, *buf, *token;
   int
      line = 0;
   String
      tmp;

   *xpm = (char **) malloc(sizeof(char *)*52);

   buf = strutil_strdup(data);
   ptr = buf;

   (*xpm)[line++] = strutil_strdup(" 48 48 2 1");
   (*xpm)[line++] = strutil_strdup("# c #000000");
   (*xpm)[line++] = strutil_strdup(". c #ffffff");
   for(l = 0; l < 48; l++)
   {
      tmp = wxEmptyString;
      for(c = 0; c < 3; c++)
      {
         token = strutil_strsep(&ptr,",\n\r");
         if(strlen(token) == 0)
            token = strutil_strsep(&ptr, ",\n\r");  // skip end of line
         if(token)
         {
            token += 2;  // skip  0x
            for(q = 0; q < 4; q++)
            {
               switch(token[q])
               {
                  case '0':
                     tmp += _T("...."); break;
                  case '1':
                     tmp += _T("...#"); break;
                  case '2':
                     tmp += _T("..#."); break;
                  case '3':
                     tmp += _T("..##"); break;
                  case '4':
                     tmp += _T(".#.."); break;
                  case '5':
                     tmp += _T(".#.#"); break;
                  case '6':
                     tmp += _T(".##."); break;
                  case '7':
                     tmp += _T(".###"); break;
                  case '8':
                     tmp += _T("#..."); break;
                  case '9':
                     tmp += _T("#..#"); break;
                  case 'a': case 'A':
                     tmp += _T("#.#."); break;
                  case 'b': case 'B':
                     tmp += _T("#.##"); break;
                  case 'c': case 'C':
                     tmp += _T("##.."); break;
                  case 'd': case 'D':
                     tmp += _T("##.#"); break;
                  case 'e': case 'E':
                     tmp += _T("###."); break;
                  case 'f': case 'F':
                     tmp += _T("####"); break;
                  default:
                     break;
               }
            }

         }
      }
      (*xpm)[line++] = strutil_strdup(tmp.ToAscii());
   }
   delete [] buf;
   (*xpm)[line++] = NULL;
   return true;
#endif
}
Example #5
0
wxCharBuffer MIME::EncodeHeader(const String& in, wxFontEncoding enc)
{
   if ( !NeedsEncoding(in) )
      return in.ToAscii();

   // decide about the encoding to use if none specified
   if ( enc == wxFONTENCODING_SYSTEM )
   {
      // try to use the user current encoding first
      enc = wxLocale::GetSystemEncoding();
   }

   if ( wxCSConv(enc).FromWChar(NULL, 0, in.wc_str(wxConvLibc)) == wxCONV_FAILED )
   {
      // but if we can't encode with it, fall back to UTF-8 as it never fails
      enc = wxFONTENCODING_UTF8;
   }

   // get the encoding in RFC 2047 sense
   MIME::Encoding enc2047 = MIME::GetEncodingForFontEncoding(enc);

   if ( enc2047 == MIME::Encoding_Unknown )
   {
      FAIL_MSG( _T("should have valid MIME encoding") );

      enc2047 = MIME::Encoding_QuotedPrintable;
   }

   // get the name of the charset to use
   String csName = MIME::GetCharsetForFontEncoding(enc);
   if ( csName.empty() )
   {
      FAIL_MSG( _T("should have a valid charset name!") );

      csName = _T("UNKNOWN");
   }


   String headerEnc;
   headerEnc.reserve(2*in.length());

   // for QP we encode each header word separately as some might not need being
   // encoded at all and the header remains more readable if we don't encode
   // them unnecessarily, but for Base64 it's useless to do this as it's
   // unreadable anyhow so we just encode everything at once
   if ( enc2047 == MIME::Encoding_QuotedPrintable )
   {
      // encode each word of the header if necessary, taking into account one
      // added complication: white space between 2 consecutive encoded words is
      // ignored during decoding, so we must encode 2 consecutive words both of
      // which need encoding as one single encoded word or the space between
      // them would be lost
      bool lastWordEncoded = false;
      const wxArrayString words(wxStringTokenize(in));
      const size_t count = words.size();
      for ( size_t n = 0; n < count; ++n )
      {
         const wxString& word = words[n];
         if ( NeedsEncoding(word) )
         {
            const String wordEnc = EncodeText(word, enc, enc2047, csName);

            if ( lastWordEncoded )
            {
               // we need to merge the 2 consecutive encoded words together: we
               // do it by removing "?=" suffix from the previous word, adding
               // a space and remove the "=?charset?Q?" prefix from this word
               ASSERT_MSG( headerEnc.length() > 7, "bad QP-encoded last word" );
               headerEnc.RemoveLast(2); // "?="

               headerEnc += '_'; // space can be represented like this in QP

               const size_t posText = wordEnc.find("?Q?");
               ASSERT_MSG( posText != String::npos, "bad QP-encoded word" );
               headerEnc += wordEnc.substr(posText + 3);
            }
            else // last word not encoded, just append this one
            {
               if ( !headerEnc.empty() )
                  headerEnc += ' ';

               headerEnc += wordEnc;
            }

            lastWordEncoded = true;
         }
         else // this word doesn't need to be encoded, simply append it
         {
            if ( !headerEnc.empty() )
               headerEnc += ' ';

            headerEnc += word;

            lastWordEncoded = false;
         }
      }
   }
   else // MIME::Encoding_Base64
   {
      headerEnc = EncodeText(in, enc, enc2047, csName);
   }

   return headerEnc.ToAscii();
}