[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice-devel
Subject: [PATCH] KSpread/HTML second patch
From: Nicolas Goutte <nicog () snafu ! de>
Date: 2001-07-31 14:45:34
[Download RAW message or body]
Okay, here is the second part for KSpread's HTML export filter.
This time the local encoding is given as <meta> tag, at least if the local
charset has a IANA charset name.
This patch goes over the previous one, which I have not yet commited.
Please test, in particular if you are using a non-ISO-8859-1 encoding or even
better a non-ISO-8859 one.
Thank you in advance.
Have a nice day/evening/night!
["diff2.txt" (text/plain)]
--- htmlexport.cc.org Mon Jul 30 23:54:44 2001
+++ htmlexport.cc Tue Jul 31 16:26:11 2001
@@ -52,6 +52,104 @@
}
};
+// getIANAChartsetName
+//
+// For IANA Charset Names
+// see http://www.iana.org/assignments/character-sets
+//
+// The values of mibEnum used here are only those used by QT 2.3.1
+//
+QString getIANACharsetName(const int mibEnum)
+{
+ switch(mibEnum)
+ {
+ case 4:
+ return "ISO-8859-1";
+ case 5:
+ return "ISO-8859-2";
+ case 6:
+ return "ISO-8859-3";
+ case 7:
+ return "ISO-8859-4";
+ case 8:
+ return "ISO-8859-5";
+ case 9:
+ return "ISO-8859-6";
+ case 10:
+ return "ISO-8859-7";
+ case 11:
+ return "ISO-8859-8";
+ case 12:
+ return "ISO-8859-9";
+ case 13:
+ return "ISO-8859-10";
+ case 16:
+ return "JIS_Encoding";
+ case 17:
+ return "Shift_JIS";
+ case 18:
+ return "EUC-JP";
+ case 38:
+ return "EUC-KR";
+ case 57:
+ return "GB_2312-80";
+ case 82:
+ return "ISO-8859-6-I";
+ case 85:
+ return "ISO-8859-8-I";
+ case 106:
+ return "UTF-8";
+ case 109:
+ return "ISO-8859-13";
+ case 110:
+ return "ISO-8859-14";
+ case 111:
+ return "ISO-8859-15";
+ case 1000:
+ return "ISO-10646-UCS-2";
+ case 2026:
+ return "Big5";
+ case 2084:
+ return "KOI8-R";
+ case 2088:
+ return "KOI8-U";
+ case 2250:
+ return "windows-1250";
+ case 2251:
+ return "windows-1251";
+ case 2252:
+ return "windows-1252";
+ case 2253:
+ return "windows-1253";
+ case 2254:
+ return "windows-1254";
+ case 2255:
+ return "windows-1255";
+ case 2256:
+ return "windows-1256";
+ case 2257:
+ return "windows-1257";
+ case 2258:
+ return "windows-1258";
+ case 2259:
+ return "TIS-620"; // Same as ISO 8859-11
+ case 2027: // GBK is not part of IANA (despite that QT 2.3.1has a number for it!)
+ case 2028: // TSCII is not part of IANA (despite that QT 2.3.1 has a number for it!)
+ case 0:
+ {
+ kdWarning(30501) << "Non-IANA character set!" << endl;
+ return QString::null;
+ }
+ default:
+ {
+ kdDebug(30501) << "Unknown MIBenum charset found! " << mibEnum << endl;
+ break;
+ }
+ }
+ return QString::null;
+}
+
+
HTMLExport::HTMLExport(KoFilter *parent, const char *name) :
KoFilter(parent, name) {
@@ -133,20 +231,36 @@
str += "<html>\n";
str += "<head>\n";
// TODO: possibility of choosing other encodings
+
+ //
+ // Find IANA charset name for the chosen encoding.
+ //
+ QString strCharset;
if (utf8)
{
- str += "<meta http-equiv=\"Content-Type\" ";
- str += "content=\"text/html; charset=UTF-8\">\n";
+ strCharset="UTF-8";
}
else
{
- // TODO: find a way to retrieve the CORRECT name of the used local charset
- // (see http://www.iana.org/assignments/character-sets)
- // For now, just give as comment the encoding used (PROVISORY!)
+ strCharset=getIANACharsetName(QTextCodec::codecForLocale()->mibEnum());
+ }
+ kdDebug(30501) << "Charset used: " << strCharset << endl;
+ if (strCharset.isEmpty())
+ {
+ // We have no valid IANA charset name, so we put QT's codec name in a comment
str += "<!-- Encoding: ";
str += QTextCodec::codecForLocale()->name();
str += " -->\n";
}
+ else
+ {
+ // We have a valid IANA charset name, so issue a <meta> tag
+ str += "<meta http-equiv=\"Content-Type\" ";
+ str += "content=\"text/html; charset=";
+ str += strCharset;
+ str += "\">\n";
+ }
+
str += "<meta name=\"Generator\" ";
str += "content=\"KSpread HTML Export Filter Version = 0.2\">\n";
// I have no idea where to get the document name from :-( table->tableName()
@@ -159,7 +273,7 @@
// It's great to have parametrable filters... IIRC even MSOffice doesn't have that)
// Ok, for now we'll use the first table - my document has only one table anyway ;-)))
KSpreadTable * table = ksdoc->map()->firstTable();
-
+
while (table != 0)
{
_______________________________________________
Koffice-devel mailing list
Koffice-devel@master.kde.org
http://master.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic