BOOL ovd_get_comment_from_file(LPCTSTR pszFile, ovd_comment* comment) { if (!ovd_test_file(pszFile)) return FALSE; FILE* fp = _tfopen(pszFile, _T("rb")); if (!fp) return FALSE; OggVorbis_File vf; if (ov_open(fp, &vf, NULL, 0) < 0) { fclose(fp); return FALSE; } memset(comment, 0, sizeof(ovd_comment)); vorbis_comment* p = ov_comment(&vf, -1); for (int i = 0; i < p->comments; i++) { LPTSTR psz = NULL; char* s = strchr(p->user_comments[i], '='); if (s) { *s = NULL; ovd_strupr(p->user_comments[i]); if (strcmp(p->user_comments[i], OVD_COMMENT_DATE) == 0) psz = comment->szDate; else if (strcmp(p->user_comments[i], OVD_COMMENT_TRACKNUM) == 0) psz = comment->szTrackNum; else if (strcmp(p->user_comments[i], OVD_COMMENT_TITLE) == 0) psz = comment->szTitle; else if (strcmp(p->user_comments[i], OVD_COMMENT_ARTIST) == 0) psz = comment->szArtist; else if (strcmp(p->user_comments[i], OVD_COMMENT_ALBUM) == 0) psz = comment->szAlbum; else if (strcmp(p->user_comments[i], OVD_COMMENT_GENRE) == 0) psz = comment->szGenre; else if (strcmp(p->user_comments[i], OVD_COMMENT_COMMENT) == 0) psz = comment->szComment; if (psz) { #ifdef _UNICODE UTF8toUCS2(s + 1, psz, OVD_COMMENT_LEN); #else WCHAR sz[OVD_COMMENT_LEN]; UTF8toUCS2(s + 1, sz, OVD_COMMENT_LEN); WideCharToMultiByte(CP_ACP, 0, sz, -1, psz, OVD_COMMENT_LEN, 0, 0); #endif } } } fclose(fp); return TRUE; }
BOOL ovd_get_comment(HANDLE hov, ovd_comment* comment) { LIBOV_STRUCT* lov = (LIBOV_STRUCT*)hov; if (!lov) return FALSE; memset(comment, 0, sizeof(ovd_comment)); vorbis_comment* p = ov_comment(&lov->vf, -1); for (int i = 0; i < p->comments; i++) { LPTSTR psz = NULL; char* s = strchr(p->user_comments[i], '='); if (s) { *s = NULL; ovd_strupr(p->user_comments[i]); if (strcmp(p->user_comments[i], OVD_COMMENT_DATE) == 0) psz = comment->szDate; else if (strcmp(p->user_comments[i], OVD_COMMENT_TRACKNUM) == 0) psz = comment->szTrackNum; else if (strcmp(p->user_comments[i], OVD_COMMENT_TITLE) == 0) psz = comment->szTitle; else if (strcmp(p->user_comments[i], OVD_COMMENT_ARTIST) == 0) psz = comment->szArtist; else if (strcmp(p->user_comments[i], OVD_COMMENT_ALBUM) == 0) psz = comment->szAlbum; else if (strcmp(p->user_comments[i], OVD_COMMENT_GENRE) == 0) psz = comment->szGenre; else if (strcmp(p->user_comments[i], OVD_COMMENT_COMMENT) == 0) psz = comment->szComment; if (psz) { #ifdef _UNICODE UTF8toUCS2(s + 1, psz, OVD_COMMENT_LEN); #else WCHAR sz[OVD_COMMENT_LEN]; UTF8toUCS2(s + 1, sz, OVD_COMMENT_LEN); WideCharToMultiByte(CP_ACP, 0, sz, -1, psz, OVD_COMMENT_LEN, 0, 0); #endif } } } return TRUE; }
BOOL ovd_get_stream_comment(ovd_stream_buf* buf, ovd_comment* comment) { ovd_handle* handle = (ovd_handle*)buf->handle; memset(comment, 0, sizeof(ovd_comment)); for (int i = 0; i < handle->vc.comments; i++) { LPTSTR psz = NULL; char* s = strchr(handle->vc.user_comments[i], '='); if (s) { *s = NULL; ovd_strupr(handle->vc.user_comments[i]); if (strcmp(handle->vc.user_comments[i], OVD_COMMENT_DATE) == 0) psz = comment->szDate; else if (strcmp(handle->vc.user_comments[i], OVD_COMMENT_TRACKNUM) == 0) psz = comment->szTrackNum; else if (strcmp(handle->vc.user_comments[i], OVD_COMMENT_TITLE) == 0) psz = comment->szTitle; else if (strcmp(handle->vc.user_comments[i], OVD_COMMENT_ARTIST) == 0) psz = comment->szArtist; else if (strcmp(handle->vc.user_comments[i], OVD_COMMENT_ALBUM) == 0) psz = comment->szAlbum; else if (strcmp(handle->vc.user_comments[i], OVD_COMMENT_GENRE) == 0) psz = comment->szGenre; else if (strcmp(handle->vc.user_comments[i], OVD_COMMENT_COMMENT) == 0) psz = comment->szComment; if (psz) { #ifdef _UNICODE UTF8toUCS2(s + 1, psz, OVD_COMMENT_LEN); #else WCHAR sz[OVD_COMMENT_LEN]; UTF8toUCS2(s + 1, sz, OVD_COMMENT_LEN); WideCharToMultiByte(CP_ACP, 0, sz, -1, psz, OVD_COMMENT_LEN, 0, 0); #endif } } } return TRUE; }
void drawString_utf8(const char *utf8string,unsigned x ,unsigned int y){ unsigned short ucs2; unsigned char charoffset = 0; unsigned char signelcharlen = 0; GUI_Context.DispPosX = x; while (1) { signelcharlen = UTF8toUCS2(utf8string + charoffset, &ucs2); charoffset += signelcharlen; if (0 == signelcharlen) { break; } DrawCharUcs2(ucs2, GUI_Context.DispPosX, y); } }
int getStringMetricWidthEx(const TEXTCHAR *string,unsigned int len){ const TEXTCHAR *index = string; unsigned int widthtotle = 0,width, w = 0,w1 = 0; unsigned short ucs2; while (1) { #if (CHARACTER_DIS_CODEC==UTF8_CODEC) w = UTF8toUCS2(index + w1, &ucs2); w1 += w; if ((0 == w)||(len==0)) { break; } len--; width = GUI_Context.pAFont->pfGetCharDistX(ucs2); if (0==width) { width = GUI_Context.pAFont->pfGetCharDistX('?'); } #elif (CHARACTER_DIS_CODEC==UCS16_CODEC) STATIC_ASSERT(sizeof(TEXTCHAR) == 2); if ((*string == 0)||(len==0)) { break; } len--; width = GUI_Context.pAFont->pfGetCharDistX(*string++); if (0 == width) { width = GUI_Context.pAFont->pfGetCharDistX('?'); } #elif (CHARACTER_DIS_CODEC==ASCII_CODEC) STATIC_ASSERT(sizeof(TEXTCHAR) == 1); if ((*string == 0)||(len==0)) { break; } len--; width = GUI_Context.pAFont->pfGetCharDistX(*string++); if (0 == width) { width = GUI_Context.pAFont->pfGetCharDistX('?'); } #endif widthtotle += width; } return widthtotle; }