Compare commits

..

28 Commits

Author SHA1 Message Date
0a1c718cc0 Refactoring 2020-03-13 17:49:15 +03:00
fb5da5e4ff Extend event types for native 2020-03-11 11:37:54 +03:00
61a157a3c4 Update gitignore 2020-03-11 09:23:06 +03:00
a7ba4c471e [x2t] For bug 44756
Fixed opening docx with special tblpPr values
2020-03-10 14:42:50 +03:00
8c18843b58 [android][se] fix find oEncodindId 2020-03-05 16:31:15 +03:00
04d796d760 [x2t] For bug 44689
Fix DurableId generation. Numbers greater than 0x7FFFFFFE cause MS Office errors(ST_LongHexNumber by spec)
2020-03-05 13:24:22 +03:00
12c427b11e Merge branch 'hotfix/v5.5.1' of github.com:ONLYOFFICE/core into hotfix/v5.5.1 2020-03-05 12:05:12 +03:00
9415983797 Merge feature/pre5.5.1 into hotfix/v5.5.1 2020-03-05 12:04:10 +03:00
e82ea1bc5c Merge pull request #227 from ONLYOFFICE/feature/pre5.5.1
Feature/pre5.5.1
2020-03-05 11:23:06 +03:00
49f4bdb933 v5.5.0 2020-03-04 18:09:03 +03:00
a577378a1e Merge pull request #225 from ONLYOFFICE/feature/pre_hotfix5.5.1
Hide openssl symbols
2020-03-04 10:14:56 +03:00
997bf0b887 Hide openssl symbols 2020-03-03 19:10:03 +03:00
51c1b7d21a Fix common apps (#224) 2020-02-27 15:09:14 +03:00
4b0ce196e8 [x2t] Fxi bug 44611 (#223) 2020-02-25 22:53:48 +03:00
b96189c213 [android][xt2] Fix overwrite document 2020-02-21 11:45:11 +03:00
987e6b6e76 [android][xt2] Open password odf document 2020-02-21 11:45:11 +03:00
aefef93e21 icu for ios (#221)
Co-authored-by: Alexey.Musinov <alexey.musinov@gmail.com>
2020-02-19 19:05:23 +03:00
2c04e9fb57 Fix windows flags (#220) 2020-02-13 19:41:15 +03:00
e6007815a2 [x2t] Fix bug 44466 (#219)
Move m_oFirstLine, m_oHanging from CTwipsMeasure(unsigned) to CSignedTwipsMeasure
2020-02-07 18:39:20 +03:00
56482f0524 Feature/build ios (#218)
* Fix build on ios in debug mode

* Fix ios build
2020-01-28 14:19:20 +03:00
b901073171 Remove travis build (#216)
This speed up PR process (requested by @K0R0L)
This build is deprecated, since build of project is moved
to another tool - `build_tool` since v5.5.0
And this config is never worked
See:
https://github.com/ONLYOFFICE/core/pull/29#issuecomment-306773327
2020-01-20 14:39:07 +03:00
03404d74a4 Merge pull request #215 from ONLYOFFICE/feature/fixBoost
Feature/fix boost
2020-01-20 14:21:13 +03:00
2154cb1dba Update boost build script for ios 2020-01-20 13:58:57 +03:00
f3fb3f7ca7 Fix build 2020-01-20 12:07:31 +03:00
20090072ae Add new method (#214) 2020-01-16 18:17:27 +03:00
bd85ec1b10 Add functionality to base.pri (#212) 2020-01-15 16:55:09 +03:00
cee502b855 Add CopyDirectory method (#210) 2020-01-15 15:45:18 +03:00
93108c244a v5.4.2 2019-11-27 12:23:13 +03:00
29 changed files with 1311 additions and 593 deletions

2
.gitignore vendored
View File

@ -11,6 +11,8 @@ Common/3dParty/icu/win_32
Common/3dParty/icu/linux_64
Common/3dParty/icu/linux_32
Common/3dParty/icu/mac_64
Common/3dParty/icu/ios
Common/3dParty/icu/mac-build
Common/3dParty/cef/win_64
Common/3dParty/cef/win_32
Common/3dParty/cef/linux_64

View File

@ -1,14 +0,0 @@
language: cpp
compiler: gcc
dist: trusty
addons:
apt:
packages:
- p7zip-full
script:
- exit 0
# Build fails anyway. See explanation in
# https://github.com/ONLYOFFICE/core/pull/29#issuecomment-306773327
- cd Common/3dParty && ./make.sh
- cd ../../
- make

View File

@ -7622,7 +7622,9 @@ void BinaryCommentsTableWriter::WriteComment(CCommentWriteTemp& oComment)
}
else
{
nDurableId = XmlUtils::GenerateInt();
//numbers greater than 0x7FFFFFFE cause MS Office errors(ST_LongHexNumber by spec)
nDurableId = XmlUtils::GenerateInt() & 0x7FFFFFFF;
nDurableId = (0x7FFFFFFF != nDurableId) ? nDurableId : nDurableId - 1;
}
nCurPos = m_oBcw.WriteItemStart(c_oSer_CommentsType::DurableId);
m_oBcw.m_oStream.WriteULONG(nDurableId);

View File

@ -43,7 +43,12 @@ namespace PPTX
{
public:
WritingElement_AdditionConstructors(TextFont)
PPTX_LOGIC_BASE2(TextFont)
TextFont()
{
m_eType = OOX::et_Unknown;
}
virtual ~TextFont() {}
TextFont(const TextFont& oSrc) { *this = oSrc; }
virtual OOX::EElementType getType () const
{

View File

@ -338,5 +338,13 @@ namespace PPTX
return 0; //return 0; - заменить на просмотр настроек по умолчанию
}
void UniColor::SetRGBColor(const BYTE& R, const BYTE& G, const BYTE& B)
{
Logic::SrgbClr* rgbColor = new Logic::SrgbClr();
rgbColor->SetRGB(R, G, B);
Color.reset(rgbColor);
}
} // namespace Logic
} // namespace PPTX

View File

@ -75,6 +75,8 @@ namespace PPTX
return Color->GetRGBColor(_oTheme,_oClrMap, ARGB);
return 0;
}
void SetRGBColor(const BYTE& R, const BYTE& G, const BYTE& B);
virtual std::wstring toXML() const;
virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const

View File

@ -79,6 +79,7 @@ namespace PPTX
node1 = node.ReadNode(_T("a:folHlink"));
lColor.GetColorFrom(node1); Scheme.insert(std::pair<std::wstring,Logic::UniColor>(_T("folHlink"), lColor));
FillWithDefaults();
FillParentPointersForChilds();
}
@ -233,7 +234,85 @@ namespace PPTX
return *this;
}
void FillWithDefaults()
{
Logic::UniColor lColor;
std::map<std::wstring, Logic::UniColor>::iterator it;
it = Scheme.find(L"dk1");
if (Scheme.end() == it || !it->second.is_init())
{
lColor.SetRGBColor(0,0,0);
Scheme[L"dk1"] = lColor;
}
it = Scheme.find(L"lt1");
if (Scheme.end() == it || !it->second.is_init())
{
lColor.SetRGBColor(255,255,255);
Scheme[L"lt1"] = lColor;
}
it = Scheme.find(L"dk2");
if (Scheme.end() == it || !it->second.is_init())
{
lColor.SetRGBColor(0x1F,0x49, 0x7D);
Scheme[L"dk2"] = lColor;
}
it = Scheme.find(L"lt2");
if (Scheme.end() == it || !it->second.is_init())
{
lColor.SetRGBColor(0xEE,0xEC,0xE1);
Scheme[L"lt2"] = lColor;
}
it = Scheme.find(L"accent1");
if (Scheme.end() == it || !it->second.is_init())
{
lColor.SetRGBColor(0x4F, 0x81, 0xBD);
Scheme[L"accent1"] = lColor;
}
it = Scheme.find(L"accent2");
if (Scheme.end() == it || !it->second.is_init())
{
lColor.SetRGBColor(0xC0,0x50,0x4D);
Scheme[L"accent2"] = lColor;
}
it = Scheme.find(L"accent3");
if (Scheme.end() == it || !it->second.is_init())
{
lColor.SetRGBColor(0x9B,0xBB,0x59);
Scheme[L"accent3"] = lColor;
}
it = Scheme.find(L"accent4");
if (Scheme.end() == it || !it->second.is_init())
{
lColor.SetRGBColor(0x80,0x64,0xA2);
Scheme[L"accent4"] = lColor;
}
it = Scheme.find(L"accent5");
if (Scheme.end() == it || !it->second.is_init())
{
lColor.SetRGBColor(0x4B,0xAC,0xC6);
Scheme[L"accent5"] = lColor;
}
it = Scheme.find(L"accent6");
if (Scheme.end() == it || !it->second.is_init())
{
lColor.SetRGBColor(0xF7,0x96,0x46);
Scheme[L"accent6"] = lColor;
}
it = Scheme.find(L"hlink");
if (Scheme.end() == it || !it->second.is_init())
{
lColor.SetRGBColor(0x00,0x00,0xFF);
Scheme[L"hlink"] = lColor;
}
it = Scheme.find(L"folHlink");
if (Scheme.end() == it || !it->second.is_init())
{
lColor.SetRGBColor(0x80, 0x00, 0x80);
Scheme[L"folHlink"] = lColor;
}
FillParentPointersForChilds();
}
protected:
virtual void FillParentPointersForChilds()
{

View File

@ -35,6 +35,7 @@
#include "./../WrapperWritingElement.h"
#include "./../Logic/UniFill.h"
#include "./../Logic/Colors/SchemeClr.h"
#include "./../Logic/Ln.h"
#include "./../Logic/EffectStyle.h"
@ -84,6 +85,7 @@ namespace PPTX
XmlUtils::CXmlNode oNode4 = node.ReadNode(_T("a:bgFillStyleLst"));
XmlMacroLoadArray(oNode4, _T("*"), bgFillStyleLst, Logic::UniFill);
FillWithDefaults();
FillParentPointersForChilds();
}
@ -251,6 +253,113 @@ namespace PPTX
pReader->Seek(_end_rec);
}
void FillWithDefaults()
{
Logic::SolidFill* pSolidFill = NULL;
Logic::SchemeClr* pSchemeClr = NULL;
// -------------- fill styles -------------------------
if (fillStyleLst.size() < 3)
{
fillStyleLst.clear();
pSolidFill = new Logic::SolidFill();
pSolidFill->m_namespace = L"a";
pSchemeClr = new Logic::SchemeClr();
pSchemeClr->val.set(L"phClr");
pSolidFill->Color.Color.reset(pSchemeClr);
fillStyleLst.push_back(Logic::UniFill());
fillStyleLst.back().m_type = Logic::UniFill::solidFill;
fillStyleLst.back().Fill.reset(pSolidFill);
pSolidFill = new Logic::SolidFill();
pSolidFill->m_namespace = L"a";
pSolidFill->Color.SetRGBColor(0,0,0);
fillStyleLst.push_back(Logic::UniFill());
fillStyleLst.back().m_type = Logic::UniFill::solidFill;
fillStyleLst.back().Fill.reset(pSolidFill);
pSolidFill = new Logic::SolidFill();
pSolidFill->m_namespace = L"a";
pSolidFill->Color.SetRGBColor(0,0,0);
fillStyleLst.push_back(Logic::UniFill());
fillStyleLst.back().m_type = Logic::UniFill::solidFill;
fillStyleLst.back().Fill.reset(pSolidFill);
}
// -------------- back styles -------------------------
if (bgFillStyleLst.size() < 3)
{
bgFillStyleLst.clear();
pSolidFill = new Logic::SolidFill();
pSolidFill->m_namespace = L"a";
pSchemeClr = new Logic::SchemeClr();
pSchemeClr->val.set(L"phClr");
pSolidFill->Color.Color.reset(pSchemeClr);
bgFillStyleLst.push_back(Logic::UniFill());
bgFillStyleLst.back().m_type = Logic::UniFill::solidFill;
bgFillStyleLst.back().Fill.reset(pSolidFill);
pSolidFill = new Logic::SolidFill();
pSolidFill->m_namespace = L"a";
pSolidFill->Color.SetRGBColor(0,0,0);
bgFillStyleLst.push_back(Logic::UniFill());
bgFillStyleLst.back().m_type = Logic::UniFill::solidFill;
bgFillStyleLst.back().Fill.reset(pSolidFill);
pSolidFill = new Logic::SolidFill();
pSolidFill->m_namespace = L"a";
pSolidFill->Color.SetRGBColor(0,0,0);
bgFillStyleLst.push_back(Logic::UniFill());
bgFillStyleLst.back().m_type = Logic::UniFill::solidFill;
bgFillStyleLst.back().Fill.reset(pSolidFill);
}
// -------------- line styles -------------------------
if (lnStyleLst.size() < 3)
{
lnStyleLst.clear();
pSolidFill = new Logic::SolidFill();
pSolidFill->m_namespace = L"a";
pSchemeClr = new Logic::SchemeClr();
pSchemeClr->val.set(L"phClr");
pSchemeClr->Modifiers.push_back(Logic::ColorModifier());
pSchemeClr->Modifiers.back().name = L"shade";
pSchemeClr->Modifiers.back().val = 95000;
pSchemeClr->Modifiers.push_back(Logic::ColorModifier());
pSchemeClr->Modifiers.back().name = L"satMod";
pSchemeClr->Modifiers.back().val = 105000;
pSolidFill->Color.Color.reset(pSchemeClr);
lnStyleLst.push_back(Logic::Ln());
lnStyleLst.back().w = 9525;
lnStyleLst.back().Fill.m_type = Logic::UniFill::solidFill;
lnStyleLst.back().Fill.Fill.reset(pSolidFill);
pSolidFill = new Logic::SolidFill();
pSolidFill->m_namespace = L"a";
pSchemeClr = new Logic::SchemeClr();
pSchemeClr->val.set(L"phClr");
pSolidFill->Color.Color.reset(pSchemeClr);
lnStyleLst.push_back(Logic::Ln());
lnStyleLst.back().w = 25400;
lnStyleLst.back().Fill.m_type = Logic::UniFill::solidFill;
lnStyleLst.back().Fill.Fill.reset(pSolidFill);
pSolidFill = new Logic::SolidFill();
pSolidFill->m_namespace = L"a";
pSchemeClr = new Logic::SchemeClr();
pSchemeClr->val.set(L"phClr");
pSolidFill->Color.Color.reset(pSchemeClr);
lnStyleLst.push_back(Logic::Ln());
lnStyleLst.back().w = 38100;
lnStyleLst.back().Fill.m_type = Logic::UniFill::solidFill;
lnStyleLst.back().Fill.Fill.reset(pSolidFill);
}
FillParentPointersForChilds();
}
public:
std::wstring name;
std::vector<Logic::UniFill> fillStyleLst;

View File

@ -52,6 +52,7 @@ namespace PPTX
majorFont = node.ReadNode(_T("a:majorFont"));
minorFont = node.ReadNode(_T("a:minorFont"));
FillWithDefaults();
FillParentPointersForChilds();
}
virtual std::wstring toXML() const
@ -133,6 +134,20 @@ namespace PPTX
pReader->Seek(_end_rec);
}
void FillWithDefaults()
{
if (OOX::et_Unknown == majorFont.latin.m_eType)
{
majorFont.latin.m_name = _T("a:latin");
majorFont.latin.typeface = L"Arial";
}
if (OOX::et_Unknown == minorFont.latin.m_eType)
{
minorFont.latin.m_name = _T("a:latin");
minorFont.latin.typeface = L"Arial";
}
FillParentPointersForChilds();
}
std::wstring name;
Logic::FontCollection majorFont;

View File

@ -1,50 +1,16 @@
INCLUDEPATH += $$PWD/boost_1_58_0
MSVC = vc140
CORE_BOOST_LIBS = $$PWD/boost_1_58_0/build/$$CORE_BUILDS_PLATFORM_PREFIX/static
core_boost_libs {
INCLUDEPATH += $$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX/include
CORE_BOOST_LIBS = $$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX/lib
core_windows {
core_debug {
LIBS += -L$$CORE_BOOST_LIBS -llibboost_system-$$MSVC-mt-gd-1_58 -llibboost_filesystem-$$MSVC-mt-gd-1_58
}
core_release {
LIBS += -L$$CORE_BOOST_LIBS -llibboost_system-$$MSVC-mt-1_58 -llibboost_filesystem-$$MSVC-mt-1_58
}
BOOST_POSTFIX = vc140
core_debug:BOOST_POSTFIX=$$BOOST_POSTFIX-mt-gd-1_58
core_release:BOOST_POSTFIX=$$BOOST_POSTFIX-mt-1_58
core_boost_libs:LIBS += -L$$CORE_BOOST_LIBS -llibboost_system-$$BOOST_POSTFIX -llibboost_filesystem-$$BOOST_POSTFIX
core_boost_regex:LIBS += -L$$CORE_BOOST_LIBS -llibboost_regex-$$BOOST_POSTFIX
core_boost_date_time:LIBS += -L$$CORE_BOOST_LIBS -llibboost_date_time-$$BOOST_POSTFIX
} else {
LIBS += -L$$CORE_BOOST_LIBS -lboost_system -lboost_filesystem
}
}
core_boost_regex {
core_windows {
core_debug {
LIBS += -L$$CORE_BOOST_LIBS -llibboost_regex-$$MSVC-mt-gd-1_58
}
core_release {
LIBS += -L$$CORE_BOOST_LIBS -llibboost_regex-$$MSVC-mt-1_58
}
} else {
LIBS += -L$$CORE_BOOST_LIBS -lboost_regex
}
}
core_boost_date_time {
core_windows {
core_debug {
LIBS += -L$$CORE_BOOST_LIBS -llibboost_date_time-$$MSVC-mt-gd-1_58
}
core_release {
LIBS += -L$$CORE_BOOST_LIBS -llibboost_date_time-$$MSVC-mt-1_58
}
} else {
LIBS += -L$$CORE_BOOST_LIBS -lboost_date_time
}
core_boost_libs:LIBS += -L$$CORE_BOOST_LIBS -lboost_system -lboost_filesystem
core_boost_regex:LIBS += -L$$CORE_BOOST_LIBS -lboost_regex
core_boost_date_time:LIBS += -L$$CORE_BOOST_LIBS -lboost_date_time
}

View File

@ -51,7 +51,7 @@ SRCDIR=$TARBALLDIR
BOOST_TARBALL=$TARBALLDIR/boost_$BOOST_VERSION2.tar.bz2
BOOST_SRC=$SRCDIR/boost_${BOOST_VERSION2}
PREFIXDIR=$BOOST_SRC/prefix
PREFIXDIR=$SRCDIR/build/ios
#===============================================================================
# Functions
@ -244,6 +244,7 @@ bootstrapBoost()
BOOST_LIBS_COMMA=$(echo $BOOST_LIBS | sed -e "s/ /,/g")
echo "Bootstrapping (with libs $BOOST_LIBS_COMMA)"
./bootstrap.sh --with-libraries=$BOOST_LIBS_COMMA
./b2 headers
doneSection
}
@ -285,12 +286,13 @@ generateOut()
echo Generate Boost for iPhone
mkdir -p $BOOST_SRC/build/ios/static
for NAME in $BOOST_LIBS; do
rm -f $SRCDIR/build/ios/lib/libboost_${NAME}.a
lipo -create $BOOST_SRC/iphone-build/stage/lib/libboost_${NAME}.a \
$BOOST_SRC/iphonesim-build/stage/lib/libboost_${NAME}.a \
-o $BOOST_SRC/build/ios/static/libboost_${NAME}.a
-o $SRCDIR/build/ios/lib/libboost_${NAME}.a
lipo $BOOST_SRC/build/ios/static/libboost_${NAME}.a -remove i386 -o $BOOST_SRC/build/ios/static/libboost_${NAME}.a
lipo $BOOST_SRC/build/ios/static/libboost_${NAME}.a -remove armv4t -o $BOOST_SRC/build/ios/static/libboost_${NAME}.a
lipo $SRCDIR/build/ios/lib/libboost_${NAME}.a -remove i386 -o $SRCDIR/build/ios/lib/libboost_${NAME}.a
lipo $SRCDIR/build/ios/lib/libboost_${NAME}.a -remove armv4t -o $SRCDIR/build/ios/lib/libboost_${NAME}.a
done
doneSection

View File

@ -11,16 +11,10 @@ PWD_ROOT_DIR = $$PWD
include(../../../../Common/base.pri)
core_linux {
DEFINES -= NDEBUG
}
core_mac {
DEFINES -= MAC
}
core_windows {
DEFINES -= UNICODE _UNICODE
}
core_linux:DEFINES -= NDEBUG
core_mac:DEFINES -= MAC
core_ios:DEFINES -= MAC
core_windows:DEFINES -= UNICODE _UNICODE
DEFINES += CRYPTOPP_DISABLE_ASM

View File

@ -23,3 +23,11 @@ core_mac {
LIBS += $$PWD/$$CORE_BUILDS_PLATFORM_PREFIX/build/libicuuc.$${ICU_MAJOR_VER}.dylib
LIBS += $$PWD/$$CORE_BUILDS_PLATFORM_PREFIX/build/libicudata.$${ICU_MAJOR_VER}.dylib
}
core_ios {
INCLUDEPATH += $$PWD/$$CORE_BUILDS_PLATFORM_PREFIX/build/include
LIBS += $$PWD/$$CORE_BUILDS_PLATFORM_PREFIX/build/libicudata.a
LIBS += $$PWD/$$CORE_BUILDS_PLATFORM_PREFIX/build/libicui18n.a
LIBS += $$PWD/$$CORE_BUILDS_PLATFORM_PREFIX/build/libicuuc.a
}

272
Common/3dParty/icu/icu_ios.sh Executable file
View File

@ -0,0 +1,272 @@
#!/bin/bash
ICU_VERSION="58"
ICU_DIR="$PWD/icu"
ICU_SOURCE="${ICU_DIR}/source"
PREBUILD="$PWD/ios/icu_build"
CONFIG_PREFIX=" --enable-extras=yes \
--enable-tools=yes \
--enable-icuio=yes \
--enable-strict=no \
--enable-static \
--enable-shared=no \
--enable-tests=yes \
--disable-renaming \
--enable-samples=no \
--enable-dyload=no \
--with-data-packaging=static"
CFLAGS="-O3 -D__STDC_INT64__ -fno-exceptions -fno-short-wchar -fno-short-enums -fembed-bitcode"
CXXFLAGS="${CFLAGS} -std=c++11 -fembed-bitcode"
#will set value to 1
defines_config_set_1=(
"UCONFIG_NO_BREAK_ITERATION"
"UCONFIG_NO_FORMATTING"
"UCONFIG_NO_REGULAR_EXPRESSIONS"
"CONFIG_NO_CONVERSION"
"U_DISABLE_RENAMING"
)
#will set value to 0
defines_config_set_0=(
"U_HAVE_NL_LANGINFO_CODESET"
"UCONFIG_NO_TRANSLITERATION"
"U_USING_ICU_NAMESPACE"
)
#will set value to 1
defines_utypes=(
"U_CHARSET_IS_UTF8"
)
function prebuild() {
svn export http://source.icu-project.org/repos/icu/tags/release-${ICU_VERSION}/icu4c/ ${ICU_DIR} --native-eol LF
echo "===== REMOVING data from bundle ====="
#Data bundle reduction
{
echo "GENRB_CLDR_VERSION = 32.0.1"
echo "GENRB_SYNTHETIC_ALIAS = "
echo "GENRB_ALIAS_SOURCE = \$(GENRB_SYNTHETIC_ALIAS) "
echo "GENRB_SOURCE = "
} >"${ICU_SOURCE}/data/locales/reslocal.mk"
{
echo "LANG_CLDR_VERSION = 32.0.1"
echo "LANG_SYNTHETIC_ALIAS = "
echo "LANG_ALIAS_SOURCE = \$(LANG_SYNTHETIC_ALIAS) "
echo "LANG_SOURCE = "
} >"${ICU_SOURCE}/data/lang/reslocal.mk"
{
echo "CURR_CLDR_VERSION = 32.0.1"
echo "CURR_SYNTHETIC_ALIAS = "
echo "CURR_ALIAS_SOURCE = \$(CURR_SYNTHETIC_ALIAS) "
echo "CURR_SOURCE = "
} >"${ICU_SOURCE}/data/curr/reslocal.mk"
{
echo "REGION_CLDR_VERSION = 32.0.1"
echo "REGION_SYNTHETIC_ALIAS = "
echo "REGION_ALIAS_SOURCE = \$(REGION_SYNTHETIC_ALIAS) "
echo "REGION_SOURCE = "
} >"${ICU_SOURCE}/data/region/reslocal.mk"
{
echo "UNIT_CLDR_VERSION = 32.0.1"
echo "UNIT_SYNTHETIC_ALIAS = "
echo "UNIT_ALIAS_SOURCE = \$(UNIT_SYNTHETIC_ALIAS) "
echo "UNIT_SOURCE = "
} >"${ICU_SOURCE}/data/unit/reslocal.mk"
{
echo "ZONE_CLDR_VERSION = 32.0.1"
echo "ZONE_SYNTHETIC_ALIAS = "
echo "ZONE_ALIAS_SOURCE = \$(ZONE_SYNTHETIC_ALIAS) "
echo "ZONE_SOURCE = "
} >"${ICU_SOURCE}/data/zone/reslocal.mk"
#find "${ICU_SOURCES}/data/mappings/" -name '*.mk' ! -name 'ucmcore.mk' -type f -exec rm -f {} +
mv "${ICU_SOURCE}/data/mappings/ucmcore.mk" "${ICU_SOURCE}/data/mappings/ucmcore.not_used" 2>/dev/null
mv "${ICU_SOURCE}/data/mappings/ucmfiles.mk" "${ICU_SOURCE}/data/mappings/ucmfiles.not_used" 2>/dev/null
mv "${ICU_SOURCE}/data/mappings/ucmebcdic.mk" "${ICU_SOURCE}/data/mappings/ucmebcdic.not_used" 2>/dev/null
mv "${ICU_SOURCE}/data/mappings/ucmlocal.mk" "${ICU_SOURCE}/data/mappings/ucmlocal.not_used" 2>/dev/null
echo "===== Modify icu/source/common/unicode/uconfig.h ====="
cp "${ICU_SOURCE}/common/unicode/uconfig" "${ICU_SOURCE}/common/unicode/uconfig.h" 2>/dev/null
cp "${ICU_SOURCE}/common/unicode/uconfig.h" "${ICU_SOURCE}/common/unicode/uconfig" 2>/dev/null
for var in "${defines_config_set_1[@]}"; do
sed "/define __UCONFIG_H__/a \\
#ifndef ${var} \\
#define ${var} 1 \\
#endif \\
" "${ICU_SOURCE}/common/unicode/uconfig.h" >"${ICU_SOURCE}/common/unicode/uconfig.tmp"
mv "${ICU_SOURCE}/common/unicode/uconfig.tmp" "${ICU_SOURCE}/common/unicode/uconfig.h"
done
for var in "${defines_config_set_0[@]}"; do
sed "/define __UCONFIG_H__/a \\
#ifndef ${var} \\
#define ${var} 0 \\
#endif \\
" "${ICU_SOURCE}/common/unicode/uconfig.h" >"${ICU_SOURCE}/common/unicode/uconfig.tmp"
mv "${ICU_SOURCE}/common/unicode/uconfig.tmp" "${ICU_SOURCE}/common/unicode/uconfig.h"
done
echo "===== Modify icu/source/common/unicode/utypes.h ====="
cp "${ICU_SOURCE}/common/unicode/utypes" "${ICU_SOURCE}/common/unicode/utypes.h" 2>/dev/null
cp "${ICU_SOURCE}/common/unicode/utypes.h" "${ICU_SOURCE}/common/unicode/utypes" 2>/dev/null
for var in "${defines_utypes[@]}"; do
sed "/define UTYPES_H/a \\
#ifndef ${var} \\
#define ${var} 1 \\
#endif \\
" "${ICU_SOURCE}/common/unicode/utypes.h" >"${ICU_SOURCE}/common/unicode/utypes.tmp"
mv "${ICU_SOURCE}/common/unicode/utypes.tmp" "${ICU_SOURCE}/common/unicode/utypes.h"
done
echo "===== Patching icu/source/tools/pkgdata/pkgdata.cpp for iOS ====="
cp "${ICU_SOURCE}/tools/pkgdata/pkgdata" "${ICU_SOURCE}/tools/pkgdata/pkgdata.cpp" 2>/dev/null
cp "${ICU_SOURCE}/tools/pkgdata/pkgdata.cpp" "${ICU_SOURCE}/tools/pkgdata/pkgdata" 2>/dev/null
sed "s/int result = system(cmd);/ \\
#if defined(IOS_SYSTEM_FIX) \\
pid_t pid; \\
char * argv[2]; argv[0] = cmd; argv[1] = NULL; \\
posix_spawn(\&pid, argv[0], NULL, NULL, argv, environ); \\
waitpid(pid, NULL, 0); \\
int result = 0; \\
#else \\
int result = system(cmd); \\
#endif \\
/g" "${ICU_SOURCE}/tools/pkgdata/pkgdata.cpp" >"${ICU_SOURCE}/tools/pkgdata/pkgdata.tmp"
sed "/#include <stdlib.h>/a \\
#if defined(IOS_SYSTEM_FIX) \\
#include <spawn.h> \\
extern char **environ; \\
#endif \\
" "${ICU_SOURCE}/tools/pkgdata/pkgdata.tmp" >"${ICU_SOURCE}/tools/pkgdata/pkgdata.cpp"
#mv "${ICU_SOURCE}/tools/pkgdata/pkgdata.tmp" "${ICU_SOURCE}/tools/pkgdata/pkgdata.cpp"
echo "==============================="
echo "===== Run build for MacOS ====="
echo "==============================="
export PLATFORM_PREFIX="${PWD}/mac-build"
export CPPFLAGS=${CFLAGS}
mkdir -p ${PREBUILD}
cd ${PREBUILD}
sh ${ICU_SOURCE}/runConfigureICU MacOSX --prefix=${PLATFORM_PREFIX} ${CONFIG_PREFIX}
make clean
make -j4
make install
cd ..
}
function build() {
unset CXX
unset CC
unset CFLAGS
unset CXXFLAGS
unset LDFLAGS
echo "preparing $1 toolchain"
export BUILD_DIR="${PWD}/build-${2}"
DEVELOPER="$(xcode-select --print-path)"
SDKROOT="$(xcodebuild -version -sdk $4 | grep -E '^Path' | sed 's/Path: //')"
ARCH=$2
ICU_FLAGS="-I$ICU_SOURCE/common/ -I$ICU_SOURCE/tools/tzcode/ "
export ADDITION_FLAG="-DIOS_SYSTEM_FIX"
export CXX="$DEVELOPER/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"
export CC="$DEVELOPER/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
export CFLAGS="-fembed-bitcode -isysroot $SDKROOT -I$SDKROOT/usr/include/ -I./include/ -arch $ARCH -miphoneos-version-min=9.0 $ICU_FLAGS $CFLAGS ${ADDITION_FLAG}"
export CXXFLAGS="${CXXFLAGS} -fembed-bitcode -stdlib=libc++ -isysroot $SDKROOT -I$SDKROOT/usr/include/ -I./include/ -arch $ARCH -miphoneos-version-min=9.0 $ICU_FLAGS ${ADDITION_FLAG}"
export LDFLAGS="-fembed-bitcode -stdlib=libc++ -L$SDKROOT/usr/lib/ -isysroot $SDKROOT -Wl,-dead_strip -miphoneos-version-min=9.0 -lstdc++ ${ADDITION_FLAG}"
mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR}
sh ${ICU_SOURCE}/configure --host=$3 --with-library-suffix=${2} --with-cross-build=${PREBUILD} ${CONFIG_PREFIX}
make clean
make -j4
make install
cd ..
}
prebuild
echo "------------------------------------------------------"
echo " ICU build armv7 libraries"
echo "------------------------------------------------------"
build "armv7" "armv7" "armv7-apple-darwin" "iphoneos"
echo "------------------------------------------------------"
echo " ICU build arm64 libraries"
echo "------------------------------------------------------"
build "arm64" "arm64" "aarch64-apple-darwin" "iphoneos"
echo "------------------------------------------------------"
echo " ICU combining x86_64 libraries"
echo "------------------------------------------------------"
build "x86_64" "x86_64" "x86_64-apple-darwin" "iphonesimulator"
cd ..
echo "------------------------------------------------------"
echo " ICU combining x86_64, armv7 and arm64 libraries"
echo "------------------------------------------------------"
function buildUniversal() {
lipo -create -output "${PWD}/ios/build/$1.a" \
"${PWD}/ios/build-x86_64/lib/$1x86_64.a" \
"${PWD}/ios/build-arm64/lib/$1arm64.a" \
"${PWD}/ios/build-armv7/lib/$1armv7.a"
}
mkdir -p build
mkdir -p ios/build
mkdir -p ios/build/include
mkdir -p ios/build/include/unicode
cp ${ICU_SOURCE}/common/unicode/*.h ios/build/include/unicode
buildUniversal "libicuuc"
buildUniversal "libicui18n"
buildUniversal "libicudata"

View File

@ -2,6 +2,7 @@ core_linux {
INCLUDEPATH += $$PWD/openssl/include
QMAKE_LFLAGS += -fvisibility=hidden
LIBS += $$PWD/openssl/libssl.a
LIBS += $$PWD/openssl/libcrypto.a

View File

@ -391,9 +391,9 @@ namespace ComplexTypes
nullable<SimpleTypes::CSignedTwipsMeasure > m_oEnd;
nullable<SimpleTypes::CDecimalNumber<> > m_oEndChars;
nullable<SimpleTypes::CTwipsMeasure > m_oFirstLine;
nullable<SimpleTypes::CSignedTwipsMeasure > m_oFirstLine;
nullable<SimpleTypes::CDecimalNumber<> > m_oFirstLineChars;
nullable<SimpleTypes::CTwipsMeasure > m_oHanging;
nullable<SimpleTypes::CSignedTwipsMeasure > m_oHanging;
nullable<SimpleTypes::CDecimalNumber<> > m_oHangingChars;
nullable<SimpleTypes::CSignedTwipsMeasure > m_oStart;
nullable<SimpleTypes::CDecimalNumber<> > m_oStartChars;

View File

@ -438,15 +438,87 @@ namespace ComplexTypes
m_oVertAnchor.Init();
m_oVertAnchor->SetValue(SimpleTypes::vanchorMargin);
}
if(false == m_oTblpX.IsInit() && false == m_oTblpXSpec.IsInit())
if(false == m_oTblpXSpec.IsInit())
{
m_oTblpXSpec.Init();
m_oTblpXSpec->SetValue(SimpleTypes::xalignLeft);
if(false == m_oTblpX.IsInit())
{
m_oTblpX.Init();
m_oTblpX->FromTwips(0);
}
//Several values of sprmTDxaAbs have special meanings as specified by
//[ECMA-376] Part 4, Section 2.18.114. These values are specified as
//follows.
switch(m_oTblpX->ToTwips())
{
case 0:
m_oTblpX.reset(NULL);
m_oTblpXSpec.Init();
m_oTblpXSpec->SetValue(SimpleTypes::xalignLeft);
break;
case -4:
m_oTblpX.reset(NULL);
m_oTblpXSpec.Init();
m_oTblpXSpec->SetValue(SimpleTypes::xalignCenter);
break;
case -8:
m_oTblpX.reset(NULL);
m_oTblpXSpec.Init();
m_oTblpXSpec->SetValue(SimpleTypes::xalignRight);
break;
case -12:
m_oTblpX.reset(NULL);
m_oTblpXSpec.Init();
m_oTblpXSpec->SetValue(SimpleTypes::xalignInside);
break;
case -16:
m_oTblpX.reset(NULL);
m_oTblpXSpec.Init();
m_oTblpXSpec->SetValue(SimpleTypes::xalignOutside);
break;
}
}
if(false == m_oTblpY.IsInit() && false == m_oTblpYSpec.IsInit())
if(false == m_oTblpYSpec.IsInit())
{
m_oTblpY.Init();
m_oTblpY->FromTwips(0);
if(false == m_oTblpY.IsInit())
{
m_oTblpY.Init();
m_oTblpY->FromTwips(0);
}
//The meanings that are provided correspond to
//values that are defined in [ECMA-376] Part 4, Section 2.18.115 ST_YAlign
//(Vertical Alignment Location).
switch(m_oTblpY->ToTwips())
{
case 0:
m_oVertAnchor.Init();
m_oVertAnchor->SetValue(SimpleTypes::vanchorText);
break;
case -4:
m_oTblpY.reset(NULL);
m_oTblpYSpec.Init();
m_oTblpYSpec->SetValue(SimpleTypes::yalignTop);
break;
case -8:
m_oTblpY.reset(NULL);
m_oTblpYSpec.Init();
m_oTblpYSpec->SetValue(SimpleTypes::yalignCenter);
break;
case -12:
m_oTblpY.reset(NULL);
m_oTblpYSpec.Init();
m_oTblpYSpec->SetValue(SimpleTypes::yalignBottom);
break;
case -16:
m_oTblpY.reset(NULL);
m_oTblpYSpec.Init();
m_oTblpYSpec->SetValue(SimpleTypes::yalignInside);
break;
case -20:
m_oTblpY.reset(NULL);
m_oTblpYSpec.Init();
m_oTblpYSpec->SetValue(SimpleTypes::yalignOutside);
break;
}
}
}
virtual void FromXML(XmlUtils::CXmlNode& oNode)

View File

@ -65,7 +65,7 @@ isEqual(QT_MAJOR_VERSION, 5) {
ios {
CONFIG += core_ios
DEFINES += _IOS IOS LINUX _LINUX _MAC _XCODE
DEFINES += _IOS IOS LINUX _LINUX MAC _MAC _XCODE
}
android {
CONFIG += core_android
@ -139,6 +139,22 @@ core_windows {
QMAKE_CXXFLAGS_RELEASE -= -Zc:strictStrings
QMAKE_CXXFLAGS -= -Zc:strictStrings
QMAKE_CXXFLAGS += /MP
equals(TEMPLATE, app) {
console {
core_win_64:QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:CONSOLE,5.02
core_win_32:QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:CONSOLE,5.01
} else {
core_win_64:QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:WINDOWS,5.02
core_win_32:QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:WINDOWS,5.01
}
}
}
core_linux {
equals(TEMPLATE, app) {
QMAKE_LFLAGS += -Wl,--rpath=./:./system
}
}
core_win_32 {
@ -205,10 +221,12 @@ core_ios {
#QMAKE_MAC_XCODE_SETTINGS += Q_ENABLE_BITCODE
#QMAKE_MAC_XCODE_SETTINGS += Q_BITCODE_GENERATION_MODE
# for libraries§
QMAKE_LFLAGS += -Xlinker -bitcode_verify
QMAKE_LFLAGS += -Xlinker -bitcode_hide_symbols
#QMAKE_LFLAGS += -Xlinker -bitcode_symbol_map -Xlinker $$CORE_BUILDS_LIBRARIES_PATH
# for libraries
!core_debug {
QMAKE_LFLAGS += -Xlinker -bitcode_verify
QMAKE_LFLAGS += -Xlinker -bitcode_hide_symbols
#QMAKE_LFLAGS += -Xlinker -bitcode_symbol_map -Xlinker $$CORE_BUILDS_LIBRARIES_PATH
}
}
}

View File

@ -1210,6 +1210,22 @@ std::wstring CorrectDir(const std::wstring& sDir)
return sDir.substr(pos1, pos2 - pos1);
}
std::wstring CorrectValue(const std::wstring& value)
{
if (value.empty())
return L"";
const wchar_t* data = value.c_str();
std::wstring::size_type pos1 = (data[0] == '\"') ? 1 : 0;
std::wstring::size_type pos2 = value.length();
if (data[pos2 - 1] == '\"')
--pos2;
return value.substr(pos1, pos2 - pos1);
}
#ifdef WIN32
int wmain(int argc, wchar_t** argv)
#else
@ -1252,6 +1268,7 @@ int main(int argc, char** argv)
if (sKey == L"--use-system")
{
sValue = CorrectValue(sValue);
if (sValue == L"1" || sValue == L"true")
bIsUseSystemFonts = true;
}
@ -1283,7 +1300,7 @@ int main(int argc, char** argv)
{
if (srcPrev != src)
{
arFontsDirs.push_back(std::wstring(srcPrev, src - srcPrev));
arFontsDirs.push_back(CorrectDir(std::wstring(srcPrev, src - srcPrev)));
}
src++;
srcPrev = src;
@ -1294,7 +1311,7 @@ int main(int argc, char** argv)
if (src > srcPrev)
{
arFontsDirs.push_back(std::wstring(srcPrev, src - srcPrev));
arFontsDirs.push_back(CorrectDir(std::wstring(srcPrev, src - srcPrev)));
}
}
else if (sKey == L"--output-web")

View File

@ -791,4 +791,42 @@
#define ASC_EVENT_TYPE_SPELLCHECK_MESSAGE 22004
#define ASC_EVENT_TYPE_SPELLCHECK_TURN_ON 22005
#define ASC_MENU_EVENT_TYPE_DO_NONPRINTING_DISPLAY 22006
// Comments
#define ASC_MENU_EVENT_TYPE_ADD_COMMENT 23001
#define ASC_MENU_EVENT_TYPE_ADD_COMMENTS 23002
#define ASC_MENU_EVENT_TYPE_REMOVE_COMMENT 23003
#define ASC_MENU_EVENT_TYPE_CHANGE_COMMENTS 23004
#define ASC_MENU_EVENT_TYPE_REMOVE_COMMENTS 23005
#define ASC_MENU_EVENT_TYPE_CHANGE_COMMENT_DATA 23006
#define ASC_MENU_EVENT_TYPE_LOCK_COMMENT 23007
#define ASC_MENU_EVENT_TYPE_UNLOCK_COMMENT 23008
#define ASC_MENU_EVENT_TYPE_SHOW_COMMENT 23009
#define ASC_MENU_EVENT_TYPE_HIDE_COMMENT 23010
#define ASC_MENU_EVENT_TYPE_UPDATE_COMMENT_POSITION 23011
#define ASC_MENU_EVENT_TYPE_DOCUMENT_PLACE_CHANGED 23012
#define ASC_MENU_EVENT_TYPE_DO_SELECT_COMMENT 23101
#define ASC_MENU_EVENT_TYPE_DO_SHOW_COMMENT 23102
#define ASC_MENU_EVENT_TYPE_DO_SELECT_COMMENTS 23103
#define ASC_MENU_EVENT_TYPE_DO_DESELECT_COMMENTS 23104
#define ASC_MENU_EVENT_TYPE_DO_ADD_COMMENT 23105
#define ASC_MENU_EVENT_TYPE_DO_REMOVE_COMMENT 23106
#define ASC_MENU_EVENT_TYPE_DO_REMOVE_ALL_COMMENTS 23107
#define ASC_MENU_EVENT_TYPE_DO_CHANGE_COMMENT 23108
// Track reviews
#define ASC_MENU_EVENT_TYPE_SHOW_REVISIONS_CHANGE 24001
#define ASC_MENU_EVENT_TYPE_DO_SET_TRACK_REVISIONS 24101
#define ASC_MENU_EVENT_TYPE_DO_BEGIN_VIEWMODE_IN_REVIEW 24102
#define ASC_MENU_EVENT_TYPE_DO_END_VIEWMODE_IN_REVIEW 24103
#define ASC_MENU_EVENT_TYPE_DO_ACCEPT_ALL_CHANGES 24104
#define ASC_MENU_EVENT_TYPE_DO_REJECT_ALL_CHANGES 24105
#define ASC_MENU_EVENT_TYPE_DO_GET_PREV_REVISIONS_CHANGE 24106
#define ASC_MENU_EVENT_TYPE_DO_GET_NEXT_REVISIONS_CHANGE 24107
#define ASC_MENU_EVENT_TYPE_DO_ACCEPT_CHANGES 24108
#define ASC_MENU_EVENT_TYPE_DO_REJECT_CHANGES 24109
#define ASC_MENU_EVENT_TYPE_DO_FOLLOW_REVISION_MOVE 24110
#endif //_BUILD_EDITOR_DEFINES_CROSSPLATFORM_H_

View File

@ -72,6 +72,21 @@ std::wstring CorrectDir(const std::wstring& sDir)
return sDir.substr(pos1, pos2 - pos1);
}
std::wstring CorrectValue(const std::wstring& value)
{
if (value.empty())
return L"";
const wchar_t* data = value.c_str();
std::wstring::size_type pos1 = (data[0] == '\"') ? 1 : 0;
std::wstring::size_type pos2 = value.length();
if (data[pos2 - 1] == '\"')
--pos2;
return value.substr(pos1, pos2 - pos1);
}
void string_replace(std::wstring& text, const std::wstring& replaceFrom, const std::wstring& replaceTo)
{
size_t posn = 0;
@ -308,6 +323,7 @@ int main(int argc, char** argv)
}
else if (sKey == L"--change-sdk")
{
sValue = CorrectValue(sValue);
if (L"1" == sValue || L"true" == sValue)
{
bIsNeedCorrectSdkAll = true;
@ -315,6 +331,7 @@ int main(int argc, char** argv)
}
else if (sKey == L"--allfonts")
{
sValue = CorrectValue(sValue);
sAllFonts = sValue;
}
else if (sKey == L"--params")

View File

@ -365,6 +365,118 @@ namespace NSDirectory
#endif
return false;
}
bool CopyDirectory(const std::wstring& strSrc, const std::wstring& strDst, bool bIsRecursion)
{
if (!NSDirectory::Exists(strDst))
NSDirectory::CreateDirectory(strDst);
#ifdef WIN32
WIN32_FIND_DATAW oFD;
std::wstring sSpec = strSrc + L"\\*.*";
HANDLE hRes = FindFirstFileW( sSpec.c_str(), &oFD );
if( INVALID_HANDLE_VALUE == hRes )
return false;
do
{
sSpec = oFD.cFileName;
if (sSpec != L"." && sSpec != L"..")
{
if( !( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
{
NSFile::CFileBinary::Copy(strSrc + L"/" + sSpec, strDst + L"/" + sSpec);
}
else if (bIsRecursion)
{
CopyDirectory(strSrc + L"/" + sSpec, strDst + L"/" + sSpec, bIsRecursion);
}
}
} while( FindNextFileW( hRes, &oFD ) );
FindClose( hRes );
return true;
#endif
#ifdef __linux__
BYTE* pUtf8 = NULL;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strSrc.c_str(), strSrc.length(), pUtf8, lLen, false);
DIR *dp;
struct dirent *dirp;
if((dp = opendir((char*)pUtf8)) != NULL)
{
while ((dirp = readdir(dp)) != NULL)
{
int nType = 0;
if(DT_REG == dirp->d_type)
nType = 2;
else if (DT_DIR == dirp->d_type)
nType = 1;
else if (DT_UNKNOWN == dirp->d_type)
{
// XFS problem
struct stat buff;
std::string sTmp = std::string((char*)pUtf8) + "/" + std::string(dirp->d_name);
stat(sTmp.c_str(), &buff);
if (S_ISREG(buff.st_mode))
nType = 2;
else if (S_ISDIR(buff.st_mode))
nType = 1;
}
if (2 == nType)
{
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
NSFile::CFileBinary::Copy(strSrc + L"/" + sName, strDst + L"/" + sName);
}
if (bIsRecursion && (1 == nType))
{
if(dirp->d_name[0] != '.')
{
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
CopyDirectory(strSrc + L"/" + sName, strDst + L"/" + sName, bIsRecursion);
}
}
}
closedir(dp);
}
delete [] pUtf8;
return true;
#endif
#if defined(MAC) || defined (_IOS)
BYTE* pUtf8 = NULL;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strSrc.c_str(), strSrc.length(), pUtf8, lLen, false);
DIR *dp;
struct dirent *dirp;
if((dp = opendir((char*)pUtf8)) != NULL)
{
while ((dirp = readdir(dp)) != NULL)
{
if(DT_REG == dirp->d_type)
{
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
NSFile::CFileBinary::Copy(strSrc + L"/" + sName, strDst + L"/" + sName);
}
if (bIsRecursion && DT_DIR == dirp->d_type)
{
if(dirp->d_name[0] != '.')
{
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
CopyDirectory(strSrc + L"/" + sName, strDst + L"/" + sName, bIsRecursion);
}
}
}
closedir(dp);
}
delete [] pUtf8;
return true;
#endif
return false;
}
void DeleteDirectory(const std::wstring& strDirectory, bool deleteRoot)
{
std::vector<std::wstring> aFiles = GetFiles(strDirectory);

View File

@ -33,6 +33,9 @@
#if defined(CreateDirectory)
#undef CreateDirectory
#endif
#if defined(CopyDirectory)
#undef CopyDirectory
#endif
#ifndef _BUILD_DIRECTORY_CROSSPLATFORM_H_
#define _BUILD_DIRECTORY_CROSSPLATFORM_H_
@ -67,6 +70,7 @@ namespace NSDirectory
KERNEL_DECL bool Exists(const std::wstring& strDirectory);
KERNEL_DECL bool CreateDirectory(const std::wstring& strDirectory);
KERNEL_DECL bool CreateDirectories(const std::wstring& strDirectory);
KERNEL_DECL bool CopyDirectory(const std::wstring& strSrc, const std::wstring& strDst, bool bIsRecursion = true);
KERNEL_DECL void DeleteDirectory(const std::wstring& strDirectory, bool deleteRoot = true);
KERNEL_DECL std::wstring GetFolderPath(const std::wstring& wsFolderPath);
KERNEL_DECL std::wstring CreateTempFileWithUniqueName (const std::wstring & strFolderPathRoot, std::wstring Prefix);

View File

@ -26,17 +26,6 @@ PWD_ROOT_DIR = $$PWD
include($$CORE_ROOT_DIR/Common/base.pri)
include($$CORE_ROOT_DIR/Common/3dParty/icu/icu.pri)
core_linux {
QMAKE_LFLAGS += -Wl,--rpath=./:./system
}
core_win_64 {
QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:CONSOLE,5.02
}
core_win_32 {
QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:CONSOLE,5.01
}
CUSTOM_VERSION_PATH = $$(DOCBUILDER_VERSION_PATH)
isEmpty(CUSTOM_VERSION_PATH){
CUSTOM_VERSION_PATH=.

View File

@ -145,6 +145,12 @@ void _SetFilePath(const v8::FunctionCallbackInfo<v8::Value>& args)
CNativeControl* pNative = unwrap_nativeobject(args.This());
pNative->SetFilePath(CV8Convert::ToString(args[0]));
}
void _GetImagesPath(const v8::FunctionCallbackInfo<v8::Value>& args)
{
CNativeControl* pNative = unwrap_nativeobject(args.This());
std::string sReturn = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(pNative->m_strImagesDirectory);
args.GetReturnValue().Set(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sReturn.c_str()));
}
void _GetFontsDirectory(const v8::FunctionCallbackInfo<v8::Value>& args)
{
@ -554,6 +560,7 @@ v8::Handle<v8::ObjectTemplate> CreateNativeControlTemplate(v8::Isolate* isolate)
result->Set(current, "ZipClose", v8::FunctionTemplate::New(current, _zipCloseFile));
result->Set(current, "getImageUrl", v8::FunctionTemplate::New(current, _GetImageUrl));
result->Set(current, "getImagesDirectory", v8::FunctionTemplate::New(current, _GetImagesPath));
// возвращаем временный хэндл хитрым образом, который переносит наш хэндл в предыдущий HandleScope и не дает ему
// уничтожиться при уничтожении "нашего" HandleScope - handle_scope
@ -604,6 +611,7 @@ v8::Handle<v8::ObjectTemplate> CreateNativeControlTemplateBuilder(v8::Isolate* i
result->Set(current, "ZipClose", v8::FunctionTemplate::New(current, _zipCloseFile));
result->Set(current, "getImageUrl", v8::FunctionTemplate::New(current, _GetImageUrl));
result->Set(current, "getImagesDirectory", v8::FunctionTemplate::New(current, _GetImagesPath));
// возвращаем временный хэндл хитрым образом, который переносит наш хэндл в предыдущий HandleScope и не дает ему
// уничтожиться при уничтожении "нашего" HandleScope - handle_scope

View File

@ -461,6 +461,7 @@ CNativeControl* unwrap_nativeobject(v8::Handle<v8::Object> obj);
void _GetFilePath(const v8::FunctionCallbackInfo<v8::Value>& args);
void _SetFilePath(const v8::FunctionCallbackInfo<v8::Value>& args);
void _GetImagesPath(const v8::FunctionCallbackInfo<v8::Value>& args);
void _GetFontsDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
void _GetEditorType(const v8::FunctionCallbackInfo<v8::Value>& args);

View File

@ -432,7 +432,7 @@ class X2t private constructor() {
if (File(mInputParams.to).exists()) {
if (mIsOverwrite) {
FileUtils.deletePath(result.root!!)
FileUtils.deletePath(result.to!!)
} else {
result.code = CONVERTER_CODE_EXIST
return@let
@ -555,6 +555,7 @@ class X2t private constructor() {
this.to = cache1.to
this.temp = cache1.temp
this.theme = inputParams.theme
this.password = inputParams.password
}
var code = first.invoke(inputTemp)
@ -565,6 +566,7 @@ class X2t private constructor() {
this.to = inputParams.to
this.temp = cache2.temp
this.theme = "${cache2.root}/theme"
this.password = inputParams.password
}
if (!FileUtils.createPath(inputResult.theme!!)) {

View File

@ -18,21 +18,10 @@ include(../../../Common/3dParty/icu/icu.pri)
core_windows {
QMAKE_LFLAGS += /INCREMENTAL:NO
contains(QMAKE_TARGET.arch, x86_64):{
QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:CONSOLE,5.02
} else {
QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:CONSOLE,5.01
}
} else {
QMAKE_CXXFLAGS += -Wall -Wno-ignored-qualifiers
}
core_linux {
QMAKE_LFLAGS += -Wl,--rpath=./:./system
}
DEFINES += UNICODE \
_UNICODE \
#DISABLE_FILE_DOWNLOADER \

View File

@ -1,478 +1,478 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "CSVReader.h"
#include <map>
#include <locale>
#include "../../DesktopEditor/common/File.h"
#include "../../Common/DocxFormat/Source/Base/unicode_util.h"
#include "../../Common/OfficeFileErrorDescription.h"
#include "../../UnicodeConverter/UnicodeConverter.h"
#include "../../UnicodeConverter/UnicodeConverter_Encodings.h"
#include "../../Common/DocxFormat/Source/XlsxFormat/Workbook/Workbook.h"
#include "../../Common/DocxFormat/Source/XlsxFormat/SharedStrings/SharedStrings.h"
#include "../../Common/DocxFormat/Source/XlsxFormat/Styles/Styles.h"
namespace CSVReader
{
const std::wstring ansi_2_unicode(const unsigned char* data, DWORD data_size)
{
std::wstring result;
std::locale loc("");
std::ctype<wchar_t> const &facet = std::use_facet<std::ctype<wchar_t> >(loc);
result.resize(data_size);
facet.widen((char*)data, (char*)data + data_size, &result[0]);
return result;
}
const std::wstring utf8_2_unicode(const unsigned char* data, DWORD data_size)
{
if (sizeof(wchar_t) == 2)//utf8 -> utf16
{
unsigned int nLength = data_size;
UTF16 *pStrUtf16 = new UTF16 [nLength + 1];
memset ((void *) pStrUtf16, 0, sizeof (UTF16) * (nLength + 1));
UTF8 *pStrUtf8 = (UTF8 *) data;
const UTF8 *pStrUtf8_Conv = pStrUtf8;
UTF16 *pStrUtf16_Conv = pStrUtf16;
ConversionResult eUnicodeConversionResult = ConvertUTF8toUTF16 (&pStrUtf8_Conv, &pStrUtf8[nLength]
, &pStrUtf16_Conv, &pStrUtf16 [nLength]
, strictConversion);
if (conversionOK != eUnicodeConversionResult)
{
delete [] pStrUtf16;
return std::wstring();
}
std::wstring utf16Str ((wchar_t *) pStrUtf16);
delete [] pStrUtf16;
return utf16Str;
}
else //utf8 -> utf32
{
unsigned int nLength = data_size;
UTF32 *pStrUtf32 = new UTF32 [nLength + 1];
memset ((void *) pStrUtf32, 0, sizeof (UTF32) * (nLength + 1));
UTF8 *pStrUtf8 = (UTF8 *) data;
const UTF8 *pStrUtf8_Conv = pStrUtf8;
UTF32 *pStrUtf32_Conv = pStrUtf32;
ConversionResult eUnicodeConversionResult = ConvertUTF8toUTF32 (&pStrUtf8_Conv, &pStrUtf8[nLength]
, &pStrUtf32_Conv, &pStrUtf32 [nLength]
, strictConversion);
if (conversionOK != eUnicodeConversionResult)
{
delete [] pStrUtf32;
return std::wstring();
}
std::wstring utf32Str ((wchar_t *) pStrUtf32);
delete [] pStrUtf32;
return utf32Str;
}
}
const std::wstring utf16_2_unicode(const unsigned char* data, DWORD data_size)
{
if (sizeof(wchar_t) == 2)//utf16 -> utf16
{
return std::wstring((wchar_t*)data, data_size / 2);
}
else //utf16 -> utf32
{
unsigned int nLength = data_size / 2;
UTF32 *pStrUtf32 = new UTF32 [nLength + 1];
memset ((void *) pStrUtf32, 0, sizeof (UTF32) * (nLength + 1));
UTF16 *pStrUtf16 = (UTF16 *) data;
const UTF16 *pStrUtf16_Conv = pStrUtf16;
UTF32 *pStrUtf32_Conv = pStrUtf32;
ConversionResult eUnicodeConversionResult = ConvertUTF16toUTF32 (&pStrUtf16_Conv, &pStrUtf16[nLength]
, &pStrUtf32_Conv, &pStrUtf32 [nLength]
, strictConversion);
if (conversionOK != eUnicodeConversionResult)
{
delete [] pStrUtf32;
return std::wstring();
}
std::wstring utf32Str ((wchar_t *) pStrUtf32);
delete [] pStrUtf32;
return utf32Str;
}
}
const std::wstring utf32_2_unicode(const unsigned char* data, DWORD data_size)
{
if (sizeof(wchar_t) == 4)//utf32 -> utf32
{
return std::wstring((wchar_t*)data, data_size / 4);
}
else //utf32 -> utf16
{
unsigned int nLength = data_size / 4;
UTF16 *pStrUtf16 = new UTF16 [nLength + 1];
memset ((void *) pStrUtf16, 0, sizeof (UTF16) * (nLength + 1));
UTF32 *pStrUtf32 = (UTF32 *) data;
const UTF32 *pStrUtf32_Conv = pStrUtf32;
UTF16 *pStrUtf16_Conv = pStrUtf16;
ConversionResult eUnicodeConversionResult = ConvertUTF32toUTF16 (&pStrUtf32_Conv, &pStrUtf32[nLength]
, &pStrUtf16_Conv, &pStrUtf16 [nLength]
, strictConversion);
if (conversionOK != eUnicodeConversionResult)
{
delete [] pStrUtf16;
return std::wstring();
}
std::wstring utf16Str ((wchar_t *) pStrUtf16);
delete [] pStrUtf16;
return utf16Str;
}
}
//-----------------------------------------------------------------------------------------------
void AddCell(std::wstring &sText, INT nStartCell, std::stack<INT> &oDeleteChars, OOX::Spreadsheet::CRow &oRow, INT nRow, INT nCol, bool bIsWrap)
{
while(!oDeleteChars.empty())
{
INT nIndex = oDeleteChars.top() - nStartCell;
sText.erase(nIndex, 1);
oDeleteChars.pop();
}
// Пустую не пишем
if (0 == sText.length())
return;
OOX::Spreadsheet::CCell *pCell = new OOX::Spreadsheet::CCell();
pCell->m_oType.Init();
WCHAR *pEndPtr;
double dValue = wcstod(sText.c_str(), &pEndPtr);
if (0 != *pEndPtr)
{
// Не число
pCell->m_oType->SetValue(SimpleTypes::Spreadsheet::celltypeInlineStr);
pCell->m_oRichText.Init();
OOX::Spreadsheet::CText *pText = new OOX::Spreadsheet::CText();
pText->m_sText = sText;
pCell->m_oRichText->m_arrItems.push_back(pText);
}
else
{
// Число
pCell->m_oValue.Init();
pCell->m_oValue->m_sText = sText;
}
if (bIsWrap)
{
// WrapStyle
pCell->m_oStyle.Init();
pCell->m_oStyle->SetValue(1);
}
pCell->setRowCol(nRow, nCol);
oRow.m_arrItems.push_back(pCell);
}
_UINT32 ReadFromCsvToXlsx(const std::wstring &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const std::wstring& sDelimiter)
{
NSFile::CFileBinary oFile;
if (false == oFile.OpenFile(sFileName)) return AVS_FILEUTILS_ERROR_CONVERT;
//-----------------------------------------------------------------------------------
// Создадим Workbook
oXlsx.CreateWorkbook();
// Создадим стили
oXlsx.CreateStyles();
// Добавим стили для wrap-а
oXlsx.m_pStyles->m_oCellXfs.Init();
oXlsx.m_pStyles->m_oCellXfs->m_oCount.Init();
oXlsx.m_pStyles->m_oCellXfs->m_oCount->SetValue(2);
// Normall default
OOX::Spreadsheet::CXfs* pXfs = NULL;
pXfs = new OOX::Spreadsheet::CXfs();
pXfs->m_oBorderId.Init();
pXfs->m_oBorderId->SetValue(0);
pXfs->m_oFillId.Init();
pXfs->m_oFillId->SetValue(0);
pXfs->m_oFontId.Init();
pXfs->m_oFontId->SetValue(0);
pXfs->m_oNumFmtId.Init();
pXfs->m_oNumFmtId->SetValue(0);
oXlsx.m_pStyles->m_oCellXfs->m_arrItems.push_back(pXfs);
// Wrap style
pXfs = new OOX::Spreadsheet::CXfs();
pXfs->m_oBorderId.Init();
pXfs->m_oBorderId->SetValue(0);
pXfs->m_oFillId.Init();
pXfs->m_oFillId->SetValue(0);
pXfs->m_oFontId.Init();
pXfs->m_oFontId->SetValue(0);
pXfs->m_oNumFmtId.Init();
pXfs->m_oNumFmtId->SetValue(0);
pXfs->m_oApplyAlignment.Init();
pXfs->m_oApplyAlignment->SetValue(SimpleTypes::onoffTrue);
pXfs->m_oAligment.Init();
pXfs->m_oAligment->m_oWrapText.Init();
pXfs->m_oAligment->m_oWrapText->SetValue(SimpleTypes::onoffTrue);
oXlsx.m_pStyles->m_oCellXfs->m_arrItems.push_back(pXfs);
std::wstring sSheetRId = L"rId1";
OOX::Spreadsheet::CWorksheet* pWorksheet = new OOX::Spreadsheet::CWorksheet(NULL);
pWorksheet->m_oSheetData.Init();
OOX::Spreadsheet::CSheet *pSheet = new OOX::Spreadsheet::CSheet();
pSheet->m_oName.Init();
pSheet->m_oName->append(L"Sheet1");
pSheet->m_oSheetId.Init();
pSheet->m_oSheetId->SetValue(1);
pSheet->m_oRid.Init();
pSheet->m_oRid->SetValue(sSheetRId);
oXlsx.m_pWorkbook->m_oSheets.Init();
oXlsx.m_pWorkbook->m_oSheets->m_arrItems.push_back(pSheet);
//-----------------------------------------------------------------------------------
DWORD nFileSize = 0;
BYTE* pFileData = new BYTE[oFile.GetFileSize()];
oFile.ReadFile(pFileData, oFile.GetFileSize(), nFileSize);
oFile.CloseFile();
//skip bom
DWORD nInputBufferSize = nFileSize;
BYTE* pInputBuffer = pFileData;
if (nInputBufferSize >= 3 && 0xef == pInputBuffer[0] && 0xbb == pInputBuffer[1] && 0xbf == pInputBuffer[2])
{
nInputBufferSize -= 3;
pInputBuffer += 3;
}
else if (nInputBufferSize >= 2 && ((0xfe == pInputBuffer[0] && 0xff == pInputBuffer[1]) || (0xff == pInputBuffer[0] && 0xfe == pInputBuffer[1])))
{
nInputBufferSize -= 2;
pInputBuffer += 2;
}
std::wstring sFileDataW;
if (nCodePage == 1000)
{
sFileDataW = ansi_2_unicode(pInputBuffer, nInputBufferSize);
}
else if (nCodePage == 46)//utf-8
{
sFileDataW = utf8_2_unicode(pInputBuffer, nInputBufferSize);
}
else if (nCodePage == 48)//utf-16
{
sFileDataW = utf16_2_unicode(pInputBuffer, nInputBufferSize);
}
else if (nCodePage == 50) // utf-32
{
sFileDataW = utf32_2_unicode(pInputBuffer, nInputBufferSize);
}
else
{
const NSUnicodeConverter::EncodindId& oEncodindId = NSUnicodeConverter::Encodings[nCodePage];
NSUnicodeConverter::CUnicodeConverter oUnicodeConverter;
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId.Name);
}
//------------------------------------------------------------------------------------------------------------------------------
size_t nSize = sFileDataW.length();
if (nSize < 1 && nInputBufferSize > 0)
{//для синхронности вывода превью и нормального результата
const NSUnicodeConverter::EncodindId& oEncodindId = NSUnicodeConverter::Encodings[nCodePage];
NSUnicodeConverter::CUnicodeConverter oUnicodeConverter;
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId.Name);
nSize = sFileDataW.length();
//return AVS_FILEUTILS_ERROR_CONVERT_ICU;
}
const WCHAR *pTemp = sFileDataW.c_str();
WCHAR wcDelimiterLeading = L'\0';
WCHAR wcDelimiterTrailing = L'\0';
int nDelimiterSize = 0;
if (sDelimiter.length() > 0)
{
wcDelimiterLeading = sDelimiter[0];
nDelimiterSize = 1;
if (2 == sizeof(wchar_t) && 0xD800 <= wcDelimiterLeading && wcDelimiterLeading <= 0xDBFF && sDelimiter.length() > 1)
{
wcDelimiterTrailing = sDelimiter[1];
nDelimiterSize = 2;
}
}
const WCHAR wcNewLineN = _T('\n');
const WCHAR wcNewLineR = _T('\r');
const WCHAR wcQuote = _T('"');
const WCHAR wcTab = _T('\t');
bool bIsWrap = false;
WCHAR wcCurrent;
INT nStartCell = 0;
std::stack<INT> oDeleteChars;
bool bInQuote = false;
INT nIndexRow = 0;
INT nIndexCol = 0;
OOX::Spreadsheet::CRow *pRow = new OOX::Spreadsheet::CRow();
pRow->m_oR.Init();
pRow->m_oR->SetValue(nIndexRow + 1);
for (size_t nIndex = 0; nIndex < nSize; ++nIndex)
{
wcCurrent = pTemp[nIndex];
if (wcDelimiterLeading == wcCurrent && (L'\0' == wcDelimiterTrailing || (nIndex + 1 < nSize && wcDelimiterTrailing == pTemp[nIndex + 1])))
{
if (bInQuote)
continue;
// New Cell
std::wstring sCellText(pTemp + nStartCell, nIndex - nStartCell);
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
bIsWrap = false;
nStartCell = nIndex + nDelimiterSize;
if (nStartCell == nSize)
{
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
pRow = NULL;
}
}
else if (wcNewLineN == wcCurrent || wcNewLineR == wcCurrent)
{
if (bInQuote)
{
// Добавим Wrap
bIsWrap = true;
continue;
}
// New line
if (nStartCell != nIndex)
{
std::wstring sCellText(pTemp + nStartCell, nIndex - nStartCell);
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
bIsWrap = false;
}
if (wcNewLineR == wcCurrent && nIndex + 1 != nSize && wcNewLineN == pTemp[nIndex + 1])
{
// На комбинацию \r\n должен быть только 1 перенос
++nIndex;
}
nStartCell = nIndex + 1;
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
pRow = new OOX::Spreadsheet::CRow();
pRow->m_oR.Init();
pRow->m_oR->SetValue(++nIndexRow + 1);
nIndexCol = 0;
}
else if (wcQuote == wcCurrent)
{
// Quote
if (false == bInQuote && nStartCell == nIndex && nIndex + 1 != nSize)
{
// Начало новой ячейки (только если мы сразу после разделителя и не в конце файла)
bInQuote = !bInQuote;
nStartCell = nIndex + 1;
}
else if ( bInQuote )
{
// Нужно удалить кавычку ограничитель
oDeleteChars.push(nIndex);
// Если следующий символ кавычка, то мы не закончили ограничитель строки (1997,Ford,E350,"Super, ""luxurious"" truck")
if (nIndex + 1 != nSize && wcQuote == pTemp[nIndex + 1])
++nIndex;
else
bInQuote = !bInQuote;
}
}
else if (wcTab == wcCurrent)
{
// delete tab if not delimiter
oDeleteChars.push(nIndex);
}
}
if (nStartCell != nSize)
{
// New line
std::wstring sCellText(pTemp + nStartCell, nSize - nStartCell);
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
}
else
{
RELEASEOBJECT(pRow);
}
oXlsx.m_arWorksheets.push_back(pWorksheet);
oXlsx.m_mapWorksheets.insert(std::make_pair(sSheetRId, pWorksheet));
return 0;
}
}
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "CSVReader.h"
#include <map>
#include <locale>
#include "../../DesktopEditor/common/File.h"
#include "../../Common/DocxFormat/Source/Base/unicode_util.h"
#include "../../Common/OfficeFileErrorDescription.h"
#include "../../UnicodeConverter/UnicodeConverter.h"
#include "../../UnicodeConverter/UnicodeConverter_Encodings.h"
#include "../../Common/DocxFormat/Source/XlsxFormat/Workbook/Workbook.h"
#include "../../Common/DocxFormat/Source/XlsxFormat/SharedStrings/SharedStrings.h"
#include "../../Common/DocxFormat/Source/XlsxFormat/Styles/Styles.h"
namespace CSVReader
{
const std::wstring ansi_2_unicode(const unsigned char* data, DWORD data_size)
{
std::wstring result;
std::locale loc("");
std::ctype<wchar_t> const &facet = std::use_facet<std::ctype<wchar_t> >(loc);
result.resize(data_size);
facet.widen((char*)data, (char*)data + data_size, &result[0]);
return result;
}
const std::wstring utf8_2_unicode(const unsigned char* data, DWORD data_size)
{
if (sizeof(wchar_t) == 2)//utf8 -> utf16
{
unsigned int nLength = data_size;
UTF16 *pStrUtf16 = new UTF16 [nLength + 1];
memset ((void *) pStrUtf16, 0, sizeof (UTF16) * (nLength + 1));
UTF8 *pStrUtf8 = (UTF8 *) data;
const UTF8 *pStrUtf8_Conv = pStrUtf8;
UTF16 *pStrUtf16_Conv = pStrUtf16;
ConversionResult eUnicodeConversionResult = ConvertUTF8toUTF16 (&pStrUtf8_Conv, &pStrUtf8[nLength]
, &pStrUtf16_Conv, &pStrUtf16 [nLength]
, strictConversion);
if (conversionOK != eUnicodeConversionResult)
{
delete [] pStrUtf16;
return std::wstring();
}
std::wstring utf16Str ((wchar_t *) pStrUtf16);
delete [] pStrUtf16;
return utf16Str;
}
else //utf8 -> utf32
{
unsigned int nLength = data_size;
UTF32 *pStrUtf32 = new UTF32 [nLength + 1];
memset ((void *) pStrUtf32, 0, sizeof (UTF32) * (nLength + 1));
UTF8 *pStrUtf8 = (UTF8 *) data;
const UTF8 *pStrUtf8_Conv = pStrUtf8;
UTF32 *pStrUtf32_Conv = pStrUtf32;
ConversionResult eUnicodeConversionResult = ConvertUTF8toUTF32 (&pStrUtf8_Conv, &pStrUtf8[nLength]
, &pStrUtf32_Conv, &pStrUtf32 [nLength]
, strictConversion);
if (conversionOK != eUnicodeConversionResult)
{
delete [] pStrUtf32;
return std::wstring();
}
std::wstring utf32Str ((wchar_t *) pStrUtf32);
delete [] pStrUtf32;
return utf32Str;
}
}
const std::wstring utf16_2_unicode(const unsigned char* data, DWORD data_size)
{
if (sizeof(wchar_t) == 2)//utf16 -> utf16
{
return std::wstring((wchar_t*)data, data_size / 2);
}
else //utf16 -> utf32
{
unsigned int nLength = data_size / 2;
UTF32 *pStrUtf32 = new UTF32 [nLength + 1];
memset ((void *) pStrUtf32, 0, sizeof (UTF32) * (nLength + 1));
UTF16 *pStrUtf16 = (UTF16 *) data;
const UTF16 *pStrUtf16_Conv = pStrUtf16;
UTF32 *pStrUtf32_Conv = pStrUtf32;
ConversionResult eUnicodeConversionResult = ConvertUTF16toUTF32 (&pStrUtf16_Conv, &pStrUtf16[nLength]
, &pStrUtf32_Conv, &pStrUtf32 [nLength]
, strictConversion);
if (conversionOK != eUnicodeConversionResult)
{
delete [] pStrUtf32;
return std::wstring();
}
std::wstring utf32Str ((wchar_t *) pStrUtf32);
delete [] pStrUtf32;
return utf32Str;
}
}
const std::wstring utf32_2_unicode(const unsigned char* data, DWORD data_size)
{
if (sizeof(wchar_t) == 4)//utf32 -> utf32
{
return std::wstring((wchar_t*)data, data_size / 4);
}
else //utf32 -> utf16
{
unsigned int nLength = data_size / 4;
UTF16 *pStrUtf16 = new UTF16 [nLength + 1];
memset ((void *) pStrUtf16, 0, sizeof (UTF16) * (nLength + 1));
UTF32 *pStrUtf32 = (UTF32 *) data;
const UTF32 *pStrUtf32_Conv = pStrUtf32;
UTF16 *pStrUtf16_Conv = pStrUtf16;
ConversionResult eUnicodeConversionResult = ConvertUTF32toUTF16 (&pStrUtf32_Conv, &pStrUtf32[nLength]
, &pStrUtf16_Conv, &pStrUtf16 [nLength]
, strictConversion);
if (conversionOK != eUnicodeConversionResult)
{
delete [] pStrUtf16;
return std::wstring();
}
std::wstring utf16Str ((wchar_t *) pStrUtf16);
delete [] pStrUtf16;
return utf16Str;
}
}
//-----------------------------------------------------------------------------------------------
void AddCell(std::wstring &sText, INT nStartCell, std::stack<INT> &oDeleteChars, OOX::Spreadsheet::CRow &oRow, INT nRow, INT nCol, bool bIsWrap)
{
while(!oDeleteChars.empty())
{
INT nIndex = oDeleteChars.top() - nStartCell;
sText.erase(nIndex, 1);
oDeleteChars.pop();
}
// Пустую не пишем
if (0 == sText.length())
return;
OOX::Spreadsheet::CCell *pCell = new OOX::Spreadsheet::CCell();
pCell->m_oType.Init();
WCHAR *pEndPtr;
double dValue = wcstod(sText.c_str(), &pEndPtr);
if (0 != *pEndPtr)
{
// Не число
pCell->m_oType->SetValue(SimpleTypes::Spreadsheet::celltypeInlineStr);
pCell->m_oRichText.Init();
OOX::Spreadsheet::CText *pText = new OOX::Spreadsheet::CText();
pText->m_sText = sText;
pCell->m_oRichText->m_arrItems.push_back(pText);
}
else
{
// Число
pCell->m_oValue.Init();
pCell->m_oValue->m_sText = sText;
}
if (bIsWrap)
{
// WrapStyle
pCell->m_oStyle.Init();
pCell->m_oStyle->SetValue(1);
}
pCell->setRowCol(nRow, nCol);
oRow.m_arrItems.push_back(pCell);
}
_UINT32 ReadFromCsvToXlsx(const std::wstring &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const std::wstring& sDelimiter)
{
NSFile::CFileBinary oFile;
if (false == oFile.OpenFile(sFileName)) return AVS_FILEUTILS_ERROR_CONVERT;
//-----------------------------------------------------------------------------------
// Создадим Workbook
oXlsx.CreateWorkbook();
// Создадим стили
oXlsx.CreateStyles();
// Добавим стили для wrap-а
oXlsx.m_pStyles->m_oCellXfs.Init();
oXlsx.m_pStyles->m_oCellXfs->m_oCount.Init();
oXlsx.m_pStyles->m_oCellXfs->m_oCount->SetValue(2);
// Normall default
OOX::Spreadsheet::CXfs* pXfs = NULL;
pXfs = new OOX::Spreadsheet::CXfs();
pXfs->m_oBorderId.Init();
pXfs->m_oBorderId->SetValue(0);
pXfs->m_oFillId.Init();
pXfs->m_oFillId->SetValue(0);
pXfs->m_oFontId.Init();
pXfs->m_oFontId->SetValue(0);
pXfs->m_oNumFmtId.Init();
pXfs->m_oNumFmtId->SetValue(0);
oXlsx.m_pStyles->m_oCellXfs->m_arrItems.push_back(pXfs);
// Wrap style
pXfs = new OOX::Spreadsheet::CXfs();
pXfs->m_oBorderId.Init();
pXfs->m_oBorderId->SetValue(0);
pXfs->m_oFillId.Init();
pXfs->m_oFillId->SetValue(0);
pXfs->m_oFontId.Init();
pXfs->m_oFontId->SetValue(0);
pXfs->m_oNumFmtId.Init();
pXfs->m_oNumFmtId->SetValue(0);
pXfs->m_oApplyAlignment.Init();
pXfs->m_oApplyAlignment->SetValue(SimpleTypes::onoffTrue);
pXfs->m_oAligment.Init();
pXfs->m_oAligment->m_oWrapText.Init();
pXfs->m_oAligment->m_oWrapText->SetValue(SimpleTypes::onoffTrue);
oXlsx.m_pStyles->m_oCellXfs->m_arrItems.push_back(pXfs);
std::wstring sSheetRId = L"rId1";
OOX::Spreadsheet::CWorksheet* pWorksheet = new OOX::Spreadsheet::CWorksheet(NULL);
pWorksheet->m_oSheetData.Init();
OOX::Spreadsheet::CSheet *pSheet = new OOX::Spreadsheet::CSheet();
pSheet->m_oName.Init();
pSheet->m_oName->append(L"Sheet1");
pSheet->m_oSheetId.Init();
pSheet->m_oSheetId->SetValue(1);
pSheet->m_oRid.Init();
pSheet->m_oRid->SetValue(sSheetRId);
oXlsx.m_pWorkbook->m_oSheets.Init();
oXlsx.m_pWorkbook->m_oSheets->m_arrItems.push_back(pSheet);
//-----------------------------------------------------------------------------------
DWORD nFileSize = 0;
BYTE* pFileData = new BYTE[oFile.GetFileSize()];
oFile.ReadFile(pFileData, oFile.GetFileSize(), nFileSize);
oFile.CloseFile();
//skip bom
DWORD nInputBufferSize = nFileSize;
BYTE* pInputBuffer = pFileData;
if (nInputBufferSize >= 3 && 0xef == pInputBuffer[0] && 0xbb == pInputBuffer[1] && 0xbf == pInputBuffer[2])
{
nInputBufferSize -= 3;
pInputBuffer += 3;
}
else if (nInputBufferSize >= 2 && ((0xfe == pInputBuffer[0] && 0xff == pInputBuffer[1]) || (0xff == pInputBuffer[0] && 0xfe == pInputBuffer[1])))
{
nInputBufferSize -= 2;
pInputBuffer += 2;
}
std::wstring sFileDataW;
if (nCodePage == 1000)
{
sFileDataW = ansi_2_unicode(pInputBuffer, nInputBufferSize);
}
else if (nCodePage == 46)//utf-8
{
sFileDataW = utf8_2_unicode(pInputBuffer, nInputBufferSize);
}
else if (nCodePage == 48)//utf-16
{
sFileDataW = utf16_2_unicode(pInputBuffer, nInputBufferSize);
}
else if (nCodePage == 50) // utf-32
{
sFileDataW = utf32_2_unicode(pInputBuffer, nInputBufferSize);
}
else
{
const auto oEncodindId = std::find_if (NSUnicodeConverter::Encodings, NSUnicodeConverter::Encodings + UNICODE_CONVERTER_ENCODINGS_COUNT - 1, [nCodePage] (const NSUnicodeConverter::EncodindId& ei) { return ei.WindowsCodePage == nCodePage; });
NSUnicodeConverter::CUnicodeConverter oUnicodeConverter;
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId->Name);
}
//------------------------------------------------------------------------------------------------------------------------------
size_t nSize = sFileDataW.length();
if (nSize < 1 && nInputBufferSize > 0)
{//для синхронности вывода превью и нормального результата
const auto oEncodindId = std::find_if (NSUnicodeConverter::Encodings, NSUnicodeConverter::Encodings + UNICODE_CONVERTER_ENCODINGS_COUNT - 1, [nCodePage] (const NSUnicodeConverter::EncodindId& ei) { return ei.WindowsCodePage == nCodePage; });
NSUnicodeConverter::CUnicodeConverter oUnicodeConverter;
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId->Name);
nSize = sFileDataW.length();
//return AVS_FILEUTILS_ERROR_CONVERT_ICU;
}
const WCHAR *pTemp = sFileDataW.c_str();
WCHAR wcDelimiterLeading = L'\0';
WCHAR wcDelimiterTrailing = L'\0';
int nDelimiterSize = 0;
if (sDelimiter.length() > 0)
{
wcDelimiterLeading = sDelimiter[0];
nDelimiterSize = 1;
if (2 == sizeof(wchar_t) && 0xD800 <= wcDelimiterLeading && wcDelimiterLeading <= 0xDBFF && sDelimiter.length() > 1)
{
wcDelimiterTrailing = sDelimiter[1];
nDelimiterSize = 2;
}
}
const WCHAR wcNewLineN = _T('\n');
const WCHAR wcNewLineR = _T('\r');
const WCHAR wcQuote = _T('"');
const WCHAR wcTab = _T('\t');
bool bIsWrap = false;
WCHAR wcCurrent;
INT nStartCell = 0;
std::stack<INT> oDeleteChars;
bool bInQuote = false;
INT nIndexRow = 0;
INT nIndexCol = 0;
OOX::Spreadsheet::CRow *pRow = new OOX::Spreadsheet::CRow();
pRow->m_oR.Init();
pRow->m_oR->SetValue(nIndexRow + 1);
for (size_t nIndex = 0; nIndex < nSize; ++nIndex)
{
wcCurrent = pTemp[nIndex];
if (wcDelimiterLeading == wcCurrent && (L'\0' == wcDelimiterTrailing || (nIndex + 1 < nSize && wcDelimiterTrailing == pTemp[nIndex + 1])))
{
if (bInQuote)
continue;
// New Cell
std::wstring sCellText(pTemp + nStartCell, nIndex - nStartCell);
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
bIsWrap = false;
nStartCell = nIndex + nDelimiterSize;
if (nStartCell == nSize)
{
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
pRow = NULL;
}
}
else if (wcNewLineN == wcCurrent || wcNewLineR == wcCurrent)
{
if (bInQuote)
{
// Добавим Wrap
bIsWrap = true;
continue;
}
// New line
if (nStartCell != nIndex)
{
std::wstring sCellText(pTemp + nStartCell, nIndex - nStartCell);
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
bIsWrap = false;
}
if (wcNewLineR == wcCurrent && nIndex + 1 != nSize && wcNewLineN == pTemp[nIndex + 1])
{
// На комбинацию \r\n должен быть только 1 перенос
++nIndex;
}
nStartCell = nIndex + 1;
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
pRow = new OOX::Spreadsheet::CRow();
pRow->m_oR.Init();
pRow->m_oR->SetValue(++nIndexRow + 1);
nIndexCol = 0;
}
else if (wcQuote == wcCurrent)
{
// Quote
if (false == bInQuote && nStartCell == nIndex && nIndex + 1 != nSize)
{
// Начало новой ячейки (только если мы сразу после разделителя и не в конце файла)
bInQuote = !bInQuote;
nStartCell = nIndex + 1;
}
else if ( bInQuote )
{
// Нужно удалить кавычку ограничитель
oDeleteChars.push(nIndex);
// Если следующий символ кавычка, то мы не закончили ограничитель строки (1997,Ford,E350,"Super, ""luxurious"" truck")
if (nIndex + 1 != nSize && wcQuote == pTemp[nIndex + 1])
++nIndex;
else
bInQuote = !bInQuote;
}
}
else if (wcTab == wcCurrent)
{
// delete tab if not delimiter
oDeleteChars.push(nIndex);
}
}
if (nStartCell != nSize)
{
// New line
std::wstring sCellText(pTemp + nStartCell, nSize - nStartCell);
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
pWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
}
else
{
RELEASEOBJECT(pRow);
}
oXlsx.m_arWorksheets.push_back(pWorksheet);
oXlsx.m_mapWorksheets.insert(std::make_pair(sSheetRId, pWorksheet));
return 0;
}
}