[Libreoffice-commits] .: 3 commits - svtools/source tools/inc tools/prj tools/source
Caolán McNamara
caolan at kemper.freedesktop.org
Wed Dec 15 00:58:10 PST 2010
svtools/source/filter.vcl/wmf/wmfwr.cxx | 32 -----
tools/inc/tools/tenccvt.hxx | 11 +
tools/prj/build.lst | 3
tools/source/reversemap/bestreversemap.cxx | 174 +++++++++++++++++++++++++++++
tools/source/reversemap/makefile.mk | 47 +++++++
tools/source/string/makefile.mk | 8 +
tools/source/string/reversemap.cxx | 6 +
7 files changed, 250 insertions(+), 31 deletions(-)
New commits:
commit c1c5a0664e51e24acc0ddd52db4e00687fd77a83
Author: Caolán McNamara <caolanm at redhat.com>
Date: Tue Dec 14 20:50:35 2010 +0000
add file
diff --git a/tools/source/string/reversemap.cxx b/tools/source/string/reversemap.cxx
new file mode 100644
index 0000000..bff45a2
--- /dev/null
+++ b/tools/source/string/reversemap.cxx
@@ -0,0 +1,6 @@
+#include <rtl/textenc.h>
+#include <tools/tenccvt.hxx>
+
+//Use reverse map generated at buildtime via bestreversemap
+
+#include "reversemap.hxx"
commit 82ba2089427326678422de8b52e2140f18268fb9
Author: Caolán McNamara <caolanm at redhat.com>
Date: Tue Dec 14 16:01:39 2010 +0000
Resolves: #i101057#/#i97332# A better converter to multiple legacy codepages
diff --git a/tools/inc/tools/tenccvt.hxx b/tools/inc/tools/tenccvt.hxx
index c38f00d..92774b1 100644
--- a/tools/inc/tools/tenccvt.hxx
+++ b/tools/inc/tools/tenccvt.hxx
@@ -54,6 +54,17 @@ TOOLS_DLLPUBLIC rtl_TextEncoding GetOneByteTextEncoding( rtl_TextEncoding eEncod
TOOLS_DLLPUBLIC rtl_TextEncoding GetSOLoadTextEncoding( rtl_TextEncoding eEncoding, USHORT nVersion = SOFFICE_FILEFORMAT_50 );
TOOLS_DLLPUBLIC rtl_TextEncoding GetSOStoreTextEncoding( rtl_TextEncoding eEncoding, USHORT nVersion = SOFFICE_FILEFORMAT_50 );
+/*
+ * Given a Unicode character, return a legacy Microsoft Encoding which
+ * supports it. Returns RTL_TEXTENCODING_DONTKNOW if there is
+ * no encoding which could support the character
+ *
+ * Useful as a utility to categorize unicode characters into the best fit
+ * windows charset range for exporting to ww6 & wmf or as a hint to non \u
+ * unicode token aware rtf readers
+ */
+TOOLS_DLLPUBLIC rtl_TextEncoding getBestMSEncodingByChar(sal_Unicode c);
+
#endif // _TOOLS_TENCCVT_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/tools/prj/build.lst b/tools/prj/build.lst
index f28d3a3..0c602a1 100644
--- a/tools/prj/build.lst
+++ b/tools/prj/build.lst
@@ -19,7 +19,8 @@ tl tools\source\fsys nmake - all tl_fsys tl_inc NULL
tl tools\source\zcodec nmake - all tl_zco tl_fsys tl_inc NULL
tl tools\source\communi nmake - all tl_com tl_fsys tl_inc NULL
tl tools\source\inet nmake - all tl_inet tl_fsys tl_inc NULL
-tl tools\source\string nmake - all tl_string tl_fsys tl_inc NULL
+tl tools\source\reversemap nmake - all tl_reversemap NULL
+tl tools\source\string nmake - all tl_string tl_reversemap tl_fsys tl_inc NULL
tl tools\source\misc nmake - all tl_misc tl_inc NULL
tl tools\win\source\dll nmake - w tl_dllw tl_inc NULL
tl tools\os2\source\dll nmake - p tl_dllp tl_inc NULL
diff --git a/tools/source/reversemap/bestreversemap.cxx b/tools/source/reversemap/bestreversemap.cxx
new file mode 100644
index 0000000..2391c69
--- /dev/null
+++ b/tools/source/reversemap/bestreversemap.cxx
@@ -0,0 +1,174 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ * Caolán McNamara <caolanm at redhat.com> (Red Hat, Inc.)
+ * Portions created by the Initial Developer are Copyright (C) 2010 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s): Caolán McNamara <caolanm at redhat.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include "sal/config.h"
+#include "rtl/textcvt.h"
+#include "sal/main.h"
+
+#include <stdio.h>
+
+struct Encoder
+{
+ rtl_UnicodeToTextConverter m_aConverter;
+ bool m_bCapable;
+ rtl_TextEncoding m_nEncoding;
+ const char *m_pEncoding;
+ Encoder(rtl_TextEncoding nEncoding, const char *pEncoding)
+ : m_bCapable(true)
+ , m_nEncoding(nEncoding)
+ , m_pEncoding(pEncoding)
+ {
+ m_aConverter = rtl_createUnicodeToTextConverter(m_nEncoding);
+ }
+ ~Encoder()
+ {
+ rtl_destroyUnicodeToTextConverter(m_aConverter);
+ }
+ void checkSupports(sal_Unicode c)
+ {
+ sal_Char aTempArray[8];
+ sal_Size nTempSize;
+ sal_uInt32 nCvtInfo;
+
+ sal_Size nChars = rtl_convertUnicodeToText(m_aConverter,
+ NULL, &c, 1, aTempArray, sizeof(aTempArray),
+ RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR,
+ &nCvtInfo, &nTempSize);
+ m_bCapable = nChars > 0;
+ }
+ void reset()
+ {
+ m_bCapable = true;
+ }
+ bool isOK() const
+ {
+ return m_bCapable;
+ }
+ const char* getName() const
+ {
+ return m_pEncoding;
+ }
+
+};
+
+
+SAL_IMPLEMENT_MAIN()
+{
+# define EXP(x) Encoder(x, #x)
+
+ Encoder aConverters[15] =
+ {
+ EXP(RTL_TEXTENCODING_MS_1361),
+ EXP(RTL_TEXTENCODING_MS_950),
+ EXP(RTL_TEXTENCODING_MS_949),
+ EXP(RTL_TEXTENCODING_MS_936),
+ EXP(RTL_TEXTENCODING_MS_932),
+ EXP(RTL_TEXTENCODING_MS_874),
+ EXP(RTL_TEXTENCODING_MS_1258),
+ EXP(RTL_TEXTENCODING_MS_1257),
+ EXP(RTL_TEXTENCODING_MS_1256),
+ EXP(RTL_TEXTENCODING_MS_1255),
+ EXP(RTL_TEXTENCODING_MS_1254),
+ EXP(RTL_TEXTENCODING_MS_1253),
+ EXP(RTL_TEXTENCODING_MS_1251),
+ EXP(RTL_TEXTENCODING_MS_1250),
+ EXP(RTL_TEXTENCODING_MS_1252)
+ };
+
+ printf("//Do not edit manually, generated from bestreversemap.cxx\n");
+ printf("rtl_TextEncoding getBestMSEncodingByChar(sal_Unicode c)\n");
+ printf("{\n");
+
+ bool bFirstOutput = true;
+
+ sal_Unicode c = 0;
+ while (c < 0xFFFF)
+ {
+ for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
+ aConverters[i].reset();
+
+ int nMostCapable = -1;
+
+ while(c < 0xFFFF)
+ {
+ bool bSomethingCapable = false;
+ for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
+ {
+ if (aConverters[i].isOK())
+ aConverters[i].checkSupports(c);
+ if (aConverters[i].isOK())
+ {
+ bSomethingCapable = true;
+ nMostCapable = i;
+ }
+ }
+ if (!bSomethingCapable)
+ break;
+ ++c;
+ }
+ sal_Unicode cEnd = c;
+ if (bFirstOutput)
+ printf(" if (c < 0x%x)\n", c);
+ else
+ printf(" else if (c < 0x%x)\n", c);
+ printf(" return %s;\n", aConverters[nMostCapable].getName());
+ bFirstOutput = false;
+ while(c < 0xFFFF)
+ {
+ bool bNothingCapable = true;
+ for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
+ {
+ aConverters[i].checkSupports(c);
+ if (aConverters[i].isOK())
+ {
+ bNothingCapable = false;
+ break;
+ }
+ }
+ if (!bNothingCapable)
+ break;
+ ++c;
+ }
+ if (cEnd != c)
+ {
+ if (c < 0xFFFF)
+ {
+ printf(" else if (c < 0x%x)\n", c);
+ printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
+ }
+ else
+ printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
+ }
+ }
+
+ printf("}\n");
+
+ return EXIT_SUCCESS;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/tools/source/reversemap/makefile.mk b/tools/source/reversemap/makefile.mk
new file mode 100644
index 0000000..bfd3400
--- /dev/null
+++ b/tools/source/reversemap/makefile.mk
@@ -0,0 +1,47 @@
+#*************************************************************************
+#
+#
+# Version: MPL 1.1 / GPLv3+ / LGPLv3+
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# The Initial Developer of the Original Code is
+# Caolán McNamara <caolanm at redhat.com> (Red Hat, Inc.)
+# Portions created by the Initial Developer are Copyright (C) 2010 the
+# Initial Developer. All Rights Reserved.
+#
+# Contributor(s): Caolán McNamara <caolanm at redhat.com>
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+# instead of those above.
+#
+#*************************************************************************
+
+PRJ = ../..
+PRJNAME = tl
+TARGET = bestreversemap
+LIBTARGET = NO
+TARGETTYPE = CUI
+ENABLE_EXCEPTIONS=TRUE
+
+.INCLUDE: settings.mk
+
+OBJFILES = \
+ $(OBJ)$/bestreversemap.obj
+
+APP1TARGET = bestreversemap
+APP1OBJS = $(OBJ)$/bestreversemap.obj
+APP1STDLIBS = $(SALLIB)
+
+.INCLUDE: target.mk
diff --git a/tools/source/string/makefile.mk b/tools/source/string/makefile.mk
index 255feac..d99ef7b 100644
--- a/tools/source/string/makefile.mk
+++ b/tools/source/string/makefile.mk
@@ -48,11 +48,13 @@ ALWAYSDBGTARGET=do_it_alwaysdebug
SLOFILES= $(SLO)$/tstring.obj \
$(SLO)$/tustring.obj \
$(SLO)$/tenccvt.obj \
+ $(SLO)$/reversemap.obj \
$(SLO)$/debugprint.obj
OBJFILES= $(OBJ)$/tstring.obj \
$(OBJ)$/tustring.obj \
$(OBJ)$/tenccvt.obj \
+ $(OBJ)$/reversemap.obj \
$(OBJ)$/debugprint.obj
# --- Targets ------------------------------------------------------
@@ -63,6 +65,12 @@ TARGETDEPS+=$(ALWAYSDBGTARGET)
.INCLUDE : target.mk
+$(INCCOM)$/reversemap.hxx: $(BIN)$/bestreversemap
+ $(AUGMENT_LIBRARY_PATH) $(BIN)$/bestreversemap > $@
+
+$(SLO)$/reversemap.obj: $(INCCOM)$/reversemap.hxx
+$(OBJ)$/reversemap.obj: $(INCCOM)$/reversemap.hxx
+
.IF "$(ALWAYSDBGTARGET)" != ""
.IF "$(ALWAYSDBG_FLAG)" == ""
# --------------------------------------------------
commit 73e44a0566c2b106d892015e9ec6a3a465bfb890
Author: Caolán McNamara <caolanm at redhat.com>
Date: Tue Dec 14 15:54:55 2010 +0000
Resolves: #i101057# Merge WMF and WW6 code page export logic
diff --git a/svtools/source/filter.vcl/wmf/wmfwr.cxx b/svtools/source/filter.vcl/wmf/wmfwr.cxx
index d5c926d..6ea6743 100644
--- a/svtools/source/filter.vcl/wmf/wmfwr.cxx
+++ b/svtools/source/filter.vcl/wmf/wmfwr.cxx
@@ -246,34 +246,6 @@
#define PRIVATE_ESCAPE_UNICODE 2
-/// copied from writerwordglue.cxx
-
-/*
- Utility to categorize unicode characters into the best fit windows charset
- range for exporting to ww6, or as a hint to non \u unicode token aware rtf
- readers
-*/
-rtl_TextEncoding getScriptClass(sal_Unicode cChar)
-{
- using namespace com::sun::star::i18n;
-
- static ScriptTypeList aScripts[] =
- {
- { UnicodeScript_kBasicLatin, UnicodeScript_kBasicLatin, RTL_TEXTENCODING_MS_1252},
- { UnicodeScript_kLatin1Supplement, UnicodeScript_kLatin1Supplement, RTL_TEXTENCODING_MS_1252},
- { UnicodeScript_kLatinExtendedA, UnicodeScript_kLatinExtendedA, RTL_TEXTENCODING_MS_1250},
- { UnicodeScript_kLatinExtendedB, UnicodeScript_kLatinExtendedB, RTL_TEXTENCODING_MS_1257},
- { UnicodeScript_kGreek, UnicodeScript_kGreek, RTL_TEXTENCODING_MS_1253},
- { UnicodeScript_kCyrillic, UnicodeScript_kCyrillic, RTL_TEXTENCODING_MS_1251},
- { UnicodeScript_kHebrew, UnicodeScript_kHebrew, RTL_TEXTENCODING_MS_1255},
- { UnicodeScript_kArabic, UnicodeScript_kArabic, RTL_TEXTENCODING_MS_1256},
- { UnicodeScript_kThai, UnicodeScript_kThai, RTL_TEXTENCODING_MS_1258},
- { UnicodeScript_kScriptCount, UnicodeScript_kScriptCount, RTL_TEXTENCODING_MS_1252}
- };
- return unicode::getUnicodeScriptType(cChar, aScripts,
- RTL_TEXTENCODING_MS_1252);
-}
-
//========================== Methoden von WMFWriter ==========================
void WMFWriter::MayCallback()
@@ -598,13 +570,13 @@ sal_Bool WMFWriter::WMFRecord_Escape_Unicode( const Point& rPoint, const String&
{ // try again, with determining a better charset from unicode char
pBuf = rUniStr.GetBuffer();
const sal_Unicode* pCheckChar = pBuf;
- rtl_TextEncoding aTextEncoding = getScriptClass (*pCheckChar); // try the first character
+ rtl_TextEncoding aTextEncoding = getBestMSEncodingByChar(*pCheckChar); // try the first character
for ( i = 1; i < nStringLen; i++)
{
if (aTextEncoding != aTextEncodingOrg) // found something
break;
pCheckChar++;
- aTextEncoding = getScriptClass (*pCheckChar); // try the next character
+ aTextEncoding = getBestMSEncodingByChar(*pCheckChar); // try the next character
}
aByteStr = ByteString ( rUniStr, aTextEncoding );
More information about the Libreoffice-commits
mailing list