Bug 126192

Summary: passed-in UTF-8 in C binding is converted to Latin1 on saving
Product: [Frameworks and Libraries] taglib Reporter: Derek <bugs>
Component: generalAssignee: Scott Wheeler <wheeler>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:

Description Derek 2006-04-24 19:50:29 UTC
Version:           1.4 (using KDE KDE 3.4.2)
Installed from:    Compiled From Sources
Compiler:          n/a to bug 
OS:                Linux

Per Scott Wheeler:
"The basic issue is that writing ID3v2 tags defaults to ISO-8859-1.  In the C++ API there's a call to change the default and there's no equivalent in the C API."

The id3v2 spec allows for 4 encodings, but as a result, only the first, ISO-8859-1 gets used.  So there is no way to write unicode to a tag using the taglib C binding.

I'm not certain if this issue could occur with other file formats.

As an aside unrelated to the bug, id3lib's id3tag will write utf-8 bytes to a v2 header, but does not properly set the text encoding description byte, so taglib fails to read it.  Setting the byte manually results in proper taglib behaviour (throwing this in in case someone using id3tag complains about reading.  reading works fine - it is writing where the C binding runs into issues).
Comment 1 Scott Wheeler 2006-05-08 22:46:07 UTC
SVN commit 538781 by wheeler:

Add a function to set the default ID3v2 encoding in the C API.

BUG:126192


 M  +2 -0      Makefile.am  
 M  +31 -7     tag_c.cpp  
 M  +19 -1     tag_c.h  


--- trunk/kdesupport/taglib/bindings/c/Makefile.am #538780:538781
@@ -4,8 +4,10 @@
 	-I$(top_srcdir)/taglib/mpeg \
 	-I$(top_srcdir)/taglib/ogg \
 	-I$(top_srcdir)/taglib/ogg/vorbis \
+	-I$(top_srcdir)/taglib/ogg/flac \
 	-I$(top_srcdir)/taglib/flac \
 	-I$(top_srcdir)/taglib/mpc \
+	-I$(top_srcdir)/taglib/mpeg/id3v2 \
 	$(all_includes)
 
 lib_LTLIBRARIES = libtag_c.la
--- trunk/kdesupport/taglib/bindings/c/tag_c.cpp #538780:538781
@@ -26,18 +26,17 @@
 #include <vorbisfile.h>
 #include <mpegfile.h>
 #include <flacfile.h>
+#include <oggflacfile.h>
 #include <mpcfile.h>
 #include <tag.h>
+#include <id3v2framefactory.h>
 
-namespace TagLib
-{
-  static List<char *> strings;
-  static bool unicodeStrings = true;
-  static bool stringManagementEnabled = true;
-}
-
 using namespace TagLib;
 
+static List<char *> strings;
+static bool unicodeStrings = true;
+static bool stringManagementEnabled = true;
+
 void taglib_set_strings_unicode(BOOL unicode)
 {
   unicodeStrings = bool(unicode);
@@ -68,6 +67,8 @@
     return reinterpret_cast<TagLib_File *>(new FLAC::File(filename));
   case TagLib_File_MPC:
     return reinterpret_cast<TagLib_File *>(new MPC::File(filename));
+  case TagLib_File_OggFlac:
+    return reinterpret_cast<TagLib_File *>(new Ogg::FLAC::File(filename));
   }
 
   return 0;
@@ -235,3 +236,26 @@
   const AudioProperties *p = reinterpret_cast<const AudioProperties *>(audioProperties);
   return p->channels();
 }
+
+void taglib_id3v2_set_default_text_encoding(TagLib_ID3v2_Encoding encoding)
+{
+  String::Type type = String::Latin1;
+
+  switch(encoding)
+  {
+  case TagLib_ID3v2_Latin1:
+    type = String::Latin1;
+    break;
+  case TagLib_ID3v2_UTF16:
+    type = String::UTF16;
+    break;
+  case TagLib_ID3v2_UTF16BE:
+    type = String::UTF16BE;
+    break;
+  case TagLib_ID3v2_UTF8:
+    type = String::UTF8;
+    break;
+  }
+
+  ID3v2::FrameFactory::instance()->setDefaultTextEncoding(type);
+}
--- trunk/kdesupport/taglib/bindings/c/tag_c.h #538780:538781
@@ -75,7 +75,8 @@
   TagLib_File_MPEG,
   TagLib_File_OggVorbis,
   TagLib_File_FLAC,
-  TagLib_File_MPC
+  TagLib_File_MPC,
+  TagLib_File_OggFlac,
 } TagLib_File_Type;
 
 /*!
@@ -243,6 +244,23 @@
  */
 int taglib_audioproperties_channels(const TagLib_AudioProperties *audioProperties);
 
+/*******************************************************************************
+ * Special convenience ID3v2 functions
+ *******************************************************************************/
+
+typedef enum {
+	TagLib_ID3v2_Latin1,
+	TagLib_ID3v2_UTF16,
+	TagLib_ID3v2_UTF16BE,
+	TagLib_ID3v2_UTF8
+} TagLib_ID3v2_Encoding;
+
+/*!
+ * This sets the default encoding for ID3v2 frames that are written to tags.
+ */
+
+void taglib_id3v2_set_default_text_encoding(TagLib_ID3v2_Encoding encoding);
+
 #ifdef __cplusplus
 }
 #endif