예제 #1
0
void CGUILabelControl::SetCursorPos(int iPos)
{
  CStdString labelUTF8 = m_infoLabel.GetLabel(m_parentID);
  CStdStringW label;
  g_charsetConverter.utf8ToW(labelUTF8, label);
  if (iPos > (int)label.length()) iPos = label.length();
  if (iPos < 0) iPos = 0;

  if (m_iCursorPos != iPos)
    MarkDirtyRegion();

  m_iCursorPos = iPos;
}
예제 #2
0
void TestDocReader::TestTOCFields()
{
	DocReader dr;
	dr.OpenFile(TEST_TOC_DOC);

	CStdStringW sGot = dr.GetMainDocumentText();
	CStdStringW sExp = L"Table of Contents\rTable of Contents\t1\rNote\t4\rAppendix B – Calculation of font (FTC) and language (LID)\t178\r\r";

	for (unsigned int i=0; i<(x64_int_cast)sGot.size(); i++)
	{
		switch (sGot[i])
		{
		case 19:
			OutputDebugString(_T("<start>"));
			break;
		case 20:
			OutputDebugString(_T("<result>"));
			break;
		case 21:
			OutputDebugString(_T("<end>"));
			break;
		default:
			{
				CStdStringW s = sGot.Mid(i,1);
				OutputDebugString(CStdString(s));
			}
		}
	}

	assertTest(sGot.Left(sExp.length()) == sExp);
}
CStdStringW FacadeDocumentProviderImpl::GetDefaultSaveExtensionFromFormatString(const CStdStringW& sAvailableFormats, long lIndex)
{
	if(sAvailableFormats.IsEmpty())
		return _T("wdf");

	int iStartPos = -1;
	int lSkip = (lIndex-1)*2;
	for (int i=0; i<lSkip; i++)
	{
		iStartPos = sAvailableFormats.Find(_T('|'),iStartPos);
	}

	int iFirstDelimeterPos = sAvailableFormats.Find(_T('|'), iStartPos);
	if (iFirstDelimeterPos == iStartPos+1) // we've hit the "||" at the end ...
		iFirstDelimeterPos = sAvailableFormats.Find(_T('|')); // go back to default
	int iNextDelimeterPos = sAvailableFormats.Find(_T('|'),iFirstDelimeterPos);

	CStdStringW sExt = sAvailableFormats.Mid(iFirstDelimeterPos + 1 ,iNextDelimeterPos - iFirstDelimeterPos - 1  );

	int iPeriodPos = sExt.Find(_T('.'));
	sExt = sExt.Mid(iPeriodPos + 1, sExt.length() - iPeriodPos );

	return sExt;

}
예제 #4
0
void CCharsetConverter::utf16BEtoUTF8(const CStdStringW& strSource, CStdStringA &strDest)
{
  if (m_iconvUtf16BEtoUtf8 == (iconv_t) - 1)
    m_iconvUtf16BEtoUtf8 = iconv_open("UTF-8", "UTF-16BE");

  if (m_iconvUtf16BEtoUtf8 != (iconv_t) - 1)
  {
    size_t inBytes  = (strSource.length() + 1) * sizeof(wchar_t);
    size_t outBytes = (strSource.length() + 1) * 4;
    const char *src = (const char*) strSource.c_str();
    char       *dst = strDest.GetBuffer(outBytes);

    if (iconv_const(m_iconvUtf16BEtoUtf8, &src, &inBytes, &dst, &outBytes))
    {
      CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }

    if (iconv(m_iconvUtf16BEtoUtf8, NULL, NULL, &dst, &outBytes))
    {
      CLog::Log(LOGERROR, "%s failed cleanup", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }
    strDest.ReleaseBuffer();
  }
}
예제 #5
0
void TestDocReader::TestTableChanges()
{
	DocReader dr;
	dr.OpenFile(TEST_TABLE_TC_DOC);

	CStdStringW sGot = dr.GetMainDocumentText();
	CStdStringW sExp = L"Some stuff before the table\r\rA\07e\07d\07d\07c\07B\07C";


	assertTest(sGot.Left(sExp.length()) == sExp);
}
예제 #6
0
void CCharsetConverter::ucs2CharsetToStringCharset(const CStdStringW& strSource, CStdStringA& strDest, bool swap)
{
  if (m_iconvUcs2CharsetToStringCharset == (iconv_t) - 1)
  {
    CStdString strCharset=g_langInfo.GetGuiCharSet();
    m_iconvUcs2CharsetToStringCharset = iconv_open(strCharset.c_str(), "UTF-16LE");
  }

  if (m_iconvUcs2CharsetToStringCharset != (iconv_t) - 1)
  {
    CStdStringW strCopy = strSource;
    size_t inBytes  = (strCopy.length() + 1) * sizeof(wchar_t);
    size_t outBytes = (strCopy.length() + 1) * 4;
    const char *src = (const char*)strCopy.c_str();
    char       *dst = strDest.GetBuffer(inBytes);

    if (swap)
    {
      char* s = (char*) src;

      while (*s || *(s + 1))
      {
        char c = *s;
        *s = *(s + 1);
        *(s + 1) = c;

        s++;
        s++;
      }
    }

    if (iconv_const(m_iconvUcs2CharsetToStringCharset, &src, &inBytes, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }

    if (iconv_const(m_iconvUcs2CharsetToStringCharset, NULL, NULL, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed cleanup", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }

    strDest.ReleaseBuffer();
  }
}
예제 #7
0
void CCharsetConverter::utf16LEtoUTF8(const CStdStringW& strSource, CStdStringA &strDest)
{
  if (m_iconvUtf16LEtoUtf8 == (iconv_t) - 1)
    m_iconvUtf16LEtoUtf8 = iconv_open("UTF-8", "UTF-16LE");

  if (m_iconvUtf16LEtoUtf8 != (iconv_t) - 1)
  {
    const char* src = (const char*) strSource.c_str();
    size_t inBytes = (strSource.length() + 1)*sizeof(wchar_t);
    size_t outBytes = (inBytes + 1)*sizeof(wchar_t);  // UTF-8 is up to 4 bytes/character  
    char *dst = strDest.GetBuffer(outBytes);
    if (iconv_const(m_iconvUtf16LEtoUtf8, &src, &inBytes, &dst, &outBytes))
    { // failed :(
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }
    strDest.ReleaseBuffer();
  }
}
예제 #8
0
void CCharsetConverter::ucs2CharsetToStringCharset(const CStdStringW& strSource, CStdStringA& strDest, bool swap)
{
  if (m_iconvUcs2CharsetToStringCharset == (iconv_t) - 1)
  {
    CStdString strCharset=g_langInfo.GetGuiCharSet();
    m_iconvUcs2CharsetToStringCharset = iconv_open(strCharset.c_str(), "UTF-16LE");
  }

  if (m_iconvUcs2CharsetToStringCharset != (iconv_t) - 1)
  {
    const char* src = (const char*) strSource.c_str();
    size_t inBytes = (strSource.length() + 1) * sizeof(wchar_t);

    if (swap)
    {
      char* s = (char*) src;

      while (*s || *(s + 1))
      {
        char c = *s;
        *s = *(s + 1);
        *(s + 1) = c;

        s++;
        s++;
      }
    }

    char *dst = strDest.GetBuffer(inBytes);
    size_t outBytes = inBytes;

    if (iconv_const(m_iconvUcs2CharsetToStringCharset, &src, &inBytes, &dst, &outBytes))
    {
      strDest.ReleaseBuffer();
      // For some reason it failed (maybe wrong charset?). Nothing to do but
      // return the original..
      strDest = strSource;
    }
    strDest.ReleaseBuffer();
  }
}
예제 #9
0
void CCharsetConverter::wToUTF8(const CStdStringW& strSource, CStdStringA &strDest)
{
  if (m_iconvWtoUtf8 == (iconv_t) - 1)
    m_iconvWtoUtf8 = iconv_open("UTF-8", WCHAR_CHARSET);

  if (m_iconvWtoUtf8 != (iconv_t) - 1)
  {
    const char* src = (const char*) strSource.c_str();
    size_t inBytes = (strSource.length() + 1) * sizeof(wchar_t);
    size_t outBytes = (inBytes + 1)*sizeof(wchar_t);  // some free for UTF-8 (up to 4 bytes/char)
    char *dst = strDest.GetBuffer(outBytes);
    if (iconv_const(m_iconvWtoUtf8, &src, &inBytes, &dst, &outBytes))
    { // failed :(
      CLog::Log(LOGERROR, "CCharsetConverter::wToUTF8 failed for subtitle.");
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }
    strDest.ReleaseBuffer();
  }
}
예제 #10
0
void CCharsetConverter::ucs2ToUTF8(const CStdStringW& strSource, CStdStringA& strDest)
{
  if (m_iconvUcs2CharsetToUtf8 == (iconv_t) - 1)
    m_iconvUcs2CharsetToUtf8 = iconv_open("UTF-8", "UCS-2LE");

  if (m_iconvUcs2CharsetToUtf8 != (iconv_t) - 1)
  {
    const char* src = (const char*) strSource.c_str();
    size_t inBytes = (strSource.length() + 1)*2;
    size_t outBytes = (inBytes + 1)*2;  // some free for UTF-8 (up to 4 bytes/char)
    char *dst = strDest.GetBuffer(outBytes);
    
    if (iconv_const(m_iconvUcs2CharsetToUtf8, &src, &inBytes, &dst, &outBytes) == (size_t) -1)
    { // failed :(
      CLog::Log(LOGERROR, "CCharsetConverter::ucs2ToUTF8 failed for Python with errno=%d", errno);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }
    strDest.ReleaseBuffer();
  }
}
예제 #11
0
void CMusicInfoTagLoaderWMA::SetTagValueBinary(const CStdString& strFrameName, const unsigned char* pValue, CMusicInfoTag& tag)
{
  if (strFrameName == "WM/Picture")
  {
    WM_PICTURE picture;
    int iPicOffset = 0;

    // Picture types: http://msdn.microsoft.com/library/en-us/wmform/htm/wm_picture.asp
    picture.bPictureType = (BYTE)pValue[iPicOffset];
    iPicOffset += 1;

    picture.dwDataLen = (DWORD)pValue[iPicOffset] + (pValue[iPicOffset + 1] * 0x100) + (pValue[iPicOffset + 2] * 0x10000);
    iPicOffset += 4;

    CStdStringW wString;
    CStdString16 utf16String = (uint16_t*)(pValue+iPicOffset);
    g_charsetConverter.utf16LEtoW(utf16String, wString);
    g_charsetConverter.wToUTF8(wString, picture.pwszMIMEType);
    iPicOffset += (wString.length() * 2);
    iPicOffset += 2;

    utf16String = (uint16_t*)(pValue+iPicOffset);
    g_charsetConverter.utf16LEtoW(utf16String, picture.pwszDescription);
    iPicOffset += (picture.pwszDescription.length() * 2);
    iPicOffset += 2;

    picture.pbData = (BYTE *)(pValue + iPicOffset);

    // many wma's don't have the bPictureType specified.  For now, just take
    // Cover Front (3) or Other (0) as the cover.
    if (picture.bPictureType == 3 || picture.bPictureType == 0) // Cover Front
    {
      CStdString strExtension(picture.pwszMIMEType);
      // if we don't have an album tag, cache with the full file path so that
      // other non-tagged files don't get this album image
      CStdString strCoverArt;
      if (!tag.GetAlbum().IsEmpty() && (!tag.GetAlbumArtist().IsEmpty() || !tag.GetArtist().IsEmpty()))
        strCoverArt = CUtil::GetCachedAlbumThumb(tag.GetAlbum(), tag.GetAlbumArtist().IsEmpty() ? tag.GetArtist() : tag.GetAlbumArtist());
      else
        strCoverArt = CUtil::GetCachedMusicThumb(tag.GetURL());
      if (!CUtil::ThumbExists(strCoverArt))
      {
        int nPos = strExtension.Find('/');
        if (nPos > -1)
          strExtension.Delete(0, nPos + 1);

        if (picture.pbData != NULL && picture.dwDataLen > 0)
        {
          if (CPicture::CreateThumbnailFromMemory(picture.pbData, picture.dwDataLen, strExtension, strCoverArt))
          {
            CUtil::ThumbCacheAdd(strCoverArt, true);
          }
          else
          {
            CUtil::ThumbCacheAdd(strCoverArt, false);
            CLog::Log(LOGERROR, "Tag loader wma: "
                                "Unable to create album art for %s "
                                "(extension=%s, size=%u)",
                      tag.GetURL().c_str(), strExtension.c_str(),
                      picture.dwDataLen);
          }
        }
      }
    }
  }
}