Compare commits
369 Commits
feature/ex
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| 64c7b7a3fd | |||
| d286b8459b | |||
| ff93f1e8b3 | |||
| 4471940b92 | |||
| 6df0cf26f3 | |||
| 720d66ad74 | |||
| e6522c6ce4 | |||
| 9b3c2291d8 | |||
| e7cfb67962 | |||
| 8725be55f0 | |||
| 37ae77d0d2 | |||
| 4c6ded76a1 | |||
| 2d8701cd4f | |||
| d5c321d47d | |||
| 324f7b3933 | |||
| edef6a83c8 | |||
| e7c21fb2cd | |||
| be8ba62c3f | |||
| fda8c8e445 | |||
| d9ebae1724 | |||
| f4867bd9f9 | |||
| 9b9da90dcc | |||
| cba4bc8085 | |||
| 325c2d3000 | |||
| 3187913c8e | |||
| 8958d13b56 | |||
| 9d13526724 | |||
| 93f70176bc | |||
| e2ad965d7c | |||
| d535aa64ef | |||
| c155a4c53a | |||
| 97cbd8dcc7 | |||
| d38576085c | |||
| 46dd9efa2e | |||
| 6af52920a2 | |||
| f13baca136 | |||
| 28a91a1519 | |||
| 0e48e65ef1 | |||
| ad1709d4af | |||
| e2c6ecec9b | |||
| ef55594f90 | |||
| 223bbe3347 | |||
| eca0cdb318 | |||
| 4a52368c30 | |||
| 73f4e20c56 | |||
| d53768969b | |||
| 324d6ec0bd | |||
| 767b652ef2 | |||
| 68f2f0760d | |||
| 694282a013 | |||
| e64eeb26af | |||
| 873b2b9351 | |||
| d5ecb00472 | |||
| 2ac6801afa | |||
| 213c65fe54 | |||
| 8269c14207 | |||
| f438a17779 | |||
| 9c8b739d0e | |||
| 7f0720bb95 | |||
| 846b212882 | |||
| 344a096e24 | |||
| 15eb4793f5 | |||
| 3ce4b4bfe8 | |||
| b8fab6f4df | |||
| 7ebf12c1e4 | |||
| 1813e09e1f | |||
| d2a986c480 | |||
| 73880f6207 | |||
| 24ad4adf6f | |||
| e4ea19ed81 | |||
| 575e379c4b | |||
| 86d8c7bfa3 | |||
| a3e1efb75b | |||
| e1f7feb5c1 | |||
| 13008c60e5 | |||
| df69099689 | |||
| 4e6f6e44bd | |||
| 67b54dc371 | |||
| b0c3172ae5 | |||
| 91d21a80ac | |||
| e820a9c936 | |||
| b38b12dfaf | |||
| 39b9e89e77 | |||
| 0b6ea2a399 | |||
| eee3161833 | |||
| fc422bb2e7 | |||
| f359f180bb | |||
| b0338919fe | |||
| 41358e3308 | |||
| 1a29fb1389 | |||
| 2fa048303f | |||
| e837479426 | |||
| e8f68e3a40 | |||
| 702987e00c | |||
| 83745da5f3 | |||
| 6b73faac12 | |||
| cab91648ce | |||
| 57b51a8854 | |||
| 4a84b8887f | |||
| 23027e4c2c | |||
| 52c61219dc | |||
| 2c37dac18c | |||
| aa7f104e60 | |||
| 83ea144c16 | |||
| ea6fdc8872 | |||
| b64b31a972 | |||
| 59fb6e4838 | |||
| d38ce5b836 | |||
| bb4ceb14e5 | |||
| ef9f25aa4d | |||
| 0c2a5eac1b | |||
| 0f85422315 | |||
| 38fa7436c0 | |||
| e2ce58a055 | |||
| cadba798b0 | |||
| 3941d5ced2 | |||
| c529cc6d5c | |||
| 31f274fbc4 | |||
| 58fe8ae679 | |||
| e3f77e11e0 | |||
| 6e696daa15 | |||
| 21dd930d30 | |||
| c4708222c6 | |||
| 34aae89432 | |||
| 273454a391 | |||
| ae4edab75e | |||
| e61aa447f2 | |||
| 6609e84bd1 | |||
| 402fe2c796 | |||
| e2aab8a241 | |||
| 555a251211 | |||
| 4a605d2424 | |||
| e49c4bc7fe | |||
| f5a4e570bb | |||
| af5a87327b | |||
| 11c637deeb | |||
| b3a7e20b35 | |||
| 915576a819 | |||
| 38a07b3c4d | |||
| ead20d7bfe | |||
| 90dc792fae | |||
| 0561ed2182 | |||
| 116ec89cd2 | |||
| f44de11437 | |||
| f5395b8b5f | |||
| 614222ee44 | |||
| 1b5d71a14c | |||
| 2ff12c06a4 | |||
| a3b6295058 | |||
| efd9e3a29e | |||
| 0fa13f3659 | |||
| 8133e3f7b7 | |||
| 7eabfd0838 | |||
| 3081d02c9c | |||
| fd2710e46e | |||
| bc076fb5b6 | |||
| 33fa3fa38b | |||
| 9bc03ffdef | |||
| 91afd3d340 | |||
| 6018add7a5 | |||
| b616ce6fd7 | |||
| 570482b60d | |||
| 201cae0e6f | |||
| 1cca5e3c12 | |||
| 048eebc613 | |||
| 760b4f9079 | |||
| 578118380e | |||
| 59f376908c | |||
| 38ceb61e4a | |||
| b3a76d5678 | |||
| c2d1bf113b | |||
| bde1115962 | |||
| d8dc82ea35 | |||
| 0ef0518f1a | |||
| f2da15defa | |||
| e3272a5e91 | |||
| d29dae37cb | |||
| d82c96dc0f | |||
| 69948ba383 | |||
| d04f9cb8cf | |||
| 5d6caf8a93 | |||
| f6ede7a53f | |||
| 3839ab4c15 | |||
| 6283a68841 | |||
| 75477e8c03 | |||
| 527cc5f89f | |||
| f4cb421b49 | |||
| 83d8a073a7 | |||
| 55ba36f4d2 | |||
| f760d03281 | |||
| 50ae7db2f0 | |||
| 0e02919540 | |||
| 1237991ffb | |||
| 5e5293b77b | |||
| 8250b59558 | |||
| 646c29166e | |||
| a2fc927b39 | |||
| b6f024b73f | |||
| 3aca7bec15 | |||
| 078ec02efd | |||
| dd17cb7243 | |||
| deff23eaac | |||
| b3988b002f | |||
| db2a9e88a1 | |||
| a8fe05fb6a | |||
| bb3091b6f1 | |||
| d908cb668e | |||
| d595d3ea86 | |||
| 41d79b0df6 | |||
| 2330f1dae8 | |||
| 8f108582b9 | |||
| 6c6d575908 | |||
| 14dd41a2a2 | |||
| b000343b86 | |||
| c7e1250287 | |||
| dc6ca55b57 | |||
| 707aab41f3 | |||
| fba3767e36 | |||
| 7b8eae26c1 | |||
| c445c0444d | |||
| 94edfff846 | |||
| 482810712e | |||
| 43ba8fca21 | |||
| f38759d071 | |||
| 52e47745de | |||
| 554d3d0dfd | |||
| c9100737e0 | |||
| d21b44a0b8 | |||
| 0da5ad2f48 | |||
| 8611c5f781 | |||
| ea338db68a | |||
| 5089a76b43 | |||
| a8678c5d10 | |||
| ac5c7d6d76 | |||
| 080ae0d924 | |||
| 77c9bd8c6d | |||
| 8144f98bb8 | |||
| aec1220bff | |||
| 76f3afc6c0 | |||
| 3e78043cdd | |||
| 0319918827 | |||
| 80d8f4b12e | |||
| c52cfd0886 | |||
| 4c9a24bf71 | |||
| 9ece4889a1 | |||
| 00c24f9d68 | |||
| 0223b1beab | |||
| 5c15b76598 | |||
| 72315df901 | |||
| cb0e361490 | |||
| db279bd725 | |||
| 40c4c922c1 | |||
| 67f287f30f | |||
| 964a44ed93 | |||
| 57984ca8a2 | |||
| a30f7dfdf4 | |||
| b369c32e9e | |||
| 40a4fa1a92 | |||
| 3870d23511 | |||
| 9c12c0b30a | |||
| 2779542061 | |||
| e232fc779d | |||
| 3209c8e42e | |||
| 037057ea7a | |||
| d373a8cc4c | |||
| 13e2efe724 | |||
| b09d441987 | |||
| 9e835d5cc1 | |||
| f75df05824 | |||
| 0d6d273573 | |||
| d7a1642a62 | |||
| d74899a116 | |||
| 981df3fce7 | |||
| d0dfd6737c | |||
| 05d7d88481 | |||
| cec10b7058 | |||
| c3b3a1b5ef | |||
| 47258d9c30 | |||
| 10ab7009a1 | |||
| 3623b0970b | |||
| 7ecab52601 | |||
| 9fedabc0e2 | |||
| 85d98daedd | |||
| fa46455e74 | |||
| 0c87e66785 | |||
| 9dacd4a548 | |||
| e815f39905 | |||
| fb8a72cd6b | |||
| ad6113cf21 | |||
| 11914f8dc2 | |||
| 50b2656c44 | |||
| 39235f7fd6 | |||
| d2527e5707 | |||
| 3484834b9d | |||
| 81b4ba3493 | |||
| 44e217cf7c | |||
| 61311457be | |||
| e15391ea35 | |||
| fefeb483e5 | |||
| e31e02d993 | |||
| 5c7ef5a6eb | |||
| bcdcfa8bf7 | |||
| fc110a004d | |||
| 12d33fad53 | |||
| 2534d2b5c9 | |||
| 7019b192bd | |||
| ac97a5680b | |||
| bebb39a619 | |||
| 1ee8baa672 | |||
| d014383a6d | |||
| 6422ce7f78 | |||
| 31f7136f70 | |||
| f2023f626b | |||
| 6ea64599bd | |||
| 3730827cd8 | |||
| eab6d5530b | |||
| dd00be6dce | |||
| b8748e40d5 | |||
| fa532edad6 | |||
| df82306306 | |||
| b5f0b39258 | |||
| 3f6a800dd8 | |||
| 1c8ad7a5c4 | |||
| 8464d3aeb7 | |||
| ed939ebd1d | |||
| fe6c5614d4 | |||
| cd80bca553 | |||
| 6e49670513 | |||
| f0b266793f | |||
| 490281dda0 | |||
| b98b808cda | |||
| 6c77718f17 | |||
| 74a2b3b06f | |||
| 8f3e19a5db | |||
| 0019f589bc | |||
| 200c17ee40 | |||
| 4543bfa6cd | |||
| 16e78d87a4 | |||
| 051597a78a | |||
| 13e03328af | |||
| 04ccd4fe27 | |||
| 7048f132c6 | |||
| 71e96930c9 | |||
| e4c84e2972 | |||
| 6cf6ade6e3 | |||
| 2399ba41e4 | |||
| fe2fb0c08d | |||
| 250c85c077 | |||
| dbd92bfdfa | |||
| 4b335fc796 | |||
| 5e177412e2 | |||
| 1dd5eb3368 | |||
| 5a491aea3e | |||
| dec13334db | |||
| c8ebcfac87 | |||
| 2931c4b53e | |||
| deb90037d5 | |||
| 930165a993 | |||
| fe2b631c87 | |||
| cb68e4389e | |||
| 0f1cb37153 | |||
| 95bad7b071 | |||
| 05404c1bad | |||
| b0e810013d | |||
| 9b3b6caef9 | |||
| 2aeec01f1e | |||
| 70412f5f8e | |||
| b1885e5b91 | |||
| 8e2d1e2c16 |
@ -6,12 +6,13 @@ import os
|
||||
if not base.is_dir("glm"):
|
||||
base.cmd("git", ["clone", "https://github.com/g-truc/glm.git"])
|
||||
base.cmd_in_dir("glm", "git", ["checkout", "33b4a621a697a305bc3a7610d290677b96beb181", "--quiet"])
|
||||
base.replaceInFile("./glm/glm/detail/func_common.inl", "vec<L, T, Q> v;", "vec<L, T, Q> v{};")
|
||||
|
||||
if not base.is_dir("mdds"):
|
||||
base.cmd("git", ["clone", "https://github.com/kohei-us/mdds.git"])
|
||||
base.cmd_in_dir("mdds", "git", ["checkout", "0783158939c6ce4b0b1b89e345ab983ccb0f0ad0"], "--quiet")
|
||||
|
||||
fix_cpp_version = "#if __cplusplus < 201402L\n"
|
||||
fix_cpp_version = "#if __cplusplus < 201703L\n"
|
||||
fix_cpp_version += "#ifndef _MSC_VER\n"
|
||||
fix_cpp_version += "namespace std {\n"
|
||||
fix_cpp_version += " template<bool __v>\n"
|
||||
|
||||
@ -3,6 +3,8 @@ DEPENDPATH += $$PWD
|
||||
|
||||
CORE_ROOT_DIR = $$PWD/../../../..
|
||||
|
||||
include($$CORE_ROOT_DIR/Common/3dParty/boost/boost.pri)
|
||||
|
||||
css_calculator_without_xhtml {
|
||||
HEADERS += \
|
||||
$$PWD/src/CCssCalculator_Private.h \
|
||||
|
||||
@ -4,11 +4,14 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
#include "../../../../DesktopEditor/graphics/Matrix.h"
|
||||
#include "CUnitMeasureConverter.h"
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include "boost/blank.hpp"
|
||||
#include <boost/variant2/variant.hpp>
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
namespace NSProperties
|
||||
@ -16,33 +19,34 @@ namespace NSCSS
|
||||
#define NEXT_LEVEL UINT_MAX, true
|
||||
|
||||
template<typename T>
|
||||
class CValue
|
||||
class CValueBase
|
||||
{
|
||||
friend class CString;
|
||||
friend class CMatrix;
|
||||
friend class CDigit;
|
||||
friend class CColor;
|
||||
friend class CEnum;
|
||||
friend class CURL;
|
||||
protected:
|
||||
CValueBase()
|
||||
: m_unLevel(0), m_bImportant(false)
|
||||
{}
|
||||
CValueBase(const CValueBase& oValue)
|
||||
: m_oValue(oValue.m_oValue), m_unLevel(oValue.m_unLevel), m_bImportant(oValue.m_bImportant)
|
||||
{}
|
||||
|
||||
CValueBase(const T& oValue, unsigned int unLevel, bool bImportant)
|
||||
: m_oValue(oValue), m_unLevel(unLevel), m_bImportant(bImportant)
|
||||
{}
|
||||
|
||||
T m_oValue;
|
||||
unsigned int m_unLevel;
|
||||
bool m_bImportant;
|
||||
public:
|
||||
CValue(const T& oValue, unsigned int unLevel, bool bImportant) :
|
||||
m_oValue(oValue), m_unLevel(unLevel), m_bImportant(bImportant)
|
||||
{
|
||||
}
|
||||
virtual bool Empty() const = 0;
|
||||
virtual void Clear() = 0;
|
||||
|
||||
virtual bool SetValue(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode) = 0;
|
||||
|
||||
virtual bool Empty() const = 0;
|
||||
virtual void Clear() = 0;
|
||||
virtual int ToInt() const = 0;
|
||||
virtual double ToDouble() const = 0;
|
||||
virtual std::wstring ToWString() const = 0;
|
||||
|
||||
static void Equation(CValue &oFirstValue, CValue &oSecondValue)
|
||||
static void Equation(CValueBase &oFirstValue, CValueBase &oSecondValue)
|
||||
{
|
||||
if (oFirstValue.m_bImportant && !oSecondValue.m_bImportant && oFirstValue.Empty())
|
||||
oSecondValue.Clear();
|
||||
@ -57,18 +61,39 @@ namespace NSCSS
|
||||
}
|
||||
}
|
||||
|
||||
static bool LevelIsSame(const CValue& oFirstValue, const CValue& oSecondValue)
|
||||
static bool LevelIsSame(const CValueBase& oFirstValue, const CValueBase& oSecondValue)
|
||||
{
|
||||
return oFirstValue.m_unLevel == oSecondValue.m_unLevel;
|
||||
}
|
||||
|
||||
bool operator==(const T& oValue) const { return m_oValue == oValue; }
|
||||
bool operator>=(const T& oValue) const { return m_oValue >= oValue; }
|
||||
bool operator<=(const T& oValue) const { return m_oValue <= oValue; }
|
||||
bool operator> (const T& oValue) const { return m_oValue > oValue; }
|
||||
bool operator< (const T& oValue) const { return m_oValue < oValue; }
|
||||
friend bool operator==(const CValueBase& oLeftValue, const CValueBase& oRightValue)
|
||||
{
|
||||
if (oLeftValue.Empty() && oRightValue.Empty())
|
||||
return true;
|
||||
|
||||
virtual CValue& operator =(const CValue& oValue)
|
||||
if (( oLeftValue.Empty() && !oRightValue.Empty()) ||
|
||||
(!oLeftValue.Empty() && oRightValue.Empty()))
|
||||
return false;
|
||||
|
||||
return oLeftValue.m_oValue == oRightValue.m_oValue;
|
||||
}
|
||||
|
||||
friend bool operator!=(const CValueBase& oLeftValue, const CValueBase& oRightValue)
|
||||
{
|
||||
return !(oLeftValue == oRightValue);
|
||||
}
|
||||
|
||||
bool operator==(const T& oValue) const
|
||||
{
|
||||
return m_oValue == oValue;
|
||||
}
|
||||
|
||||
bool operator!=(const T& oValue) const
|
||||
{
|
||||
return m_oValue != oValue;
|
||||
}
|
||||
|
||||
virtual CValueBase& operator =(const CValueBase& oValue)
|
||||
{
|
||||
m_oValue = oValue.m_oValue;
|
||||
m_unLevel = oValue.m_unLevel;
|
||||
@ -77,70 +102,93 @@ namespace NSCSS
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual CValue& operator =(const T& oValue)
|
||||
virtual CValueBase& operator =(const T& oValue)
|
||||
{
|
||||
//m_oValue = oValue.m_oValue;
|
||||
m_oValue = oValue;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual CValue& operator+=(const CValue& oValue)
|
||||
virtual CValueBase& operator+=(const CValueBase& oValue)
|
||||
{
|
||||
if (m_unLevel > oValue.m_unLevel || (m_bImportant && !oValue.m_bImportant) || oValue.Empty())
|
||||
return *this;
|
||||
|
||||
m_oValue = oValue.m_oValue;
|
||||
m_unLevel = oValue.m_unLevel;
|
||||
m_bImportant = oValue.m_bImportant;
|
||||
*this = oValue;
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
virtual bool operator==(const CValue& oValue) const
|
||||
template<typename T>
|
||||
class CValueOptional : public CValueBase<boost::optional<T>>
|
||||
{
|
||||
protected:
|
||||
CValueOptional() = default;
|
||||
|
||||
CValueOptional(const T& oValue, unsigned int unLevel = 0, bool bImportant = false)
|
||||
: CValueBase<boost::optional<T>>(oValue, unLevel, bImportant)
|
||||
{}
|
||||
public:
|
||||
virtual bool Empty() const override
|
||||
{
|
||||
return m_oValue == oValue.m_oValue;
|
||||
return !this->m_oValue.has_value();
|
||||
}
|
||||
void Clear() override
|
||||
{
|
||||
this->m_oValue.reset();
|
||||
this->m_unLevel = 0;
|
||||
this->m_bImportant = false;
|
||||
}
|
||||
|
||||
virtual bool operator!=(const CValue& oValue) const
|
||||
bool operator==(const T& oValue) const
|
||||
{
|
||||
return m_oValue != oValue.m_oValue;
|
||||
if (!this->m_oValue.has_value())
|
||||
return false;
|
||||
|
||||
return this->m_oValue.value() == oValue;
|
||||
}
|
||||
|
||||
virtual CValueOptional& operator=(const T& oValue)
|
||||
{
|
||||
this->m_oValue = oValue;
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
class CString : public CValue<std::wstring>
|
||||
class CString : public CValueOptional<std::wstring>
|
||||
{
|
||||
public:
|
||||
CString();
|
||||
CString(const std::wstring& wsValue, unsigned int unLevel, bool bImportant = false);
|
||||
CString() = default;
|
||||
CString(const std::wstring& wsValue, unsigned int unLevel = 0, bool bImportant = false);
|
||||
|
||||
bool SetValue(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode) override;
|
||||
bool SetValue(const std::wstring& wsValue, const std::vector<std::wstring>& arValiableValues, unsigned int unLevel, bool bHardMode);
|
||||
bool SetValue(const std::wstring& wsValue, const std::map<std::wstring, std::wstring>& arValiableValues, unsigned int unLevel, bool bHardMode);
|
||||
|
||||
bool Empty() const override;
|
||||
void Clear() override;
|
||||
|
||||
int ToInt() const override;
|
||||
double ToDouble() const override;
|
||||
std::wstring ToWString() const override;
|
||||
|
||||
CString& operator+=(const CString& oString);
|
||||
bool operator==(const wchar_t* pValue) const;
|
||||
bool operator!=(const wchar_t* pValue) const;
|
||||
|
||||
using CValueOptional<std::wstring>::operator=;
|
||||
};
|
||||
|
||||
class CDigit : public CValue<double>
|
||||
class CDigit : public CValueOptional<double>
|
||||
{
|
||||
UnitMeasure m_enUnitMeasure;
|
||||
|
||||
double ConvertValue(double dPrevValue, UnitMeasure enUnitMeasure) const;
|
||||
public:
|
||||
CDigit();
|
||||
CDigit(double dValue);
|
||||
CDigit(double dValue, unsigned int unLevel, bool bImportant = false);
|
||||
CDigit(const double& dValue, unsigned int unLevel = 0, bool bImportant = false);
|
||||
|
||||
bool SetValue(const std::wstring& wsValue, unsigned int unLevel = 0, bool bHardMode = true) override;
|
||||
bool SetValue(const CDigit& oValue);
|
||||
bool SetValue(const double& dValue, UnitMeasure enUnitMeasure, unsigned int unLevel = 0, bool bHardMode = true);
|
||||
|
||||
bool Empty() const override;
|
||||
bool Zero() const;
|
||||
void Clear() override;
|
||||
|
||||
@ -156,7 +204,7 @@ namespace NSCSS
|
||||
|
||||
UnitMeasure GetUnitMeasure() const;
|
||||
|
||||
bool operator==(const double& oValue) const;
|
||||
bool operator==(const double& dValue) const;
|
||||
bool operator==(const CDigit& oDigit) const;
|
||||
|
||||
bool operator!=(const double& oValue) const;
|
||||
@ -171,11 +219,19 @@ namespace NSCSS
|
||||
|
||||
CDigit& operator+=(const CDigit& oDigit);
|
||||
CDigit& operator-=(const CDigit& oDigit);
|
||||
CDigit& operator+=(double dValue);
|
||||
CDigit& operator-=(double dValue);
|
||||
CDigit& operator*=(double dValue);
|
||||
CDigit& operator/=(double dValue);
|
||||
CDigit& operator =(double dValue);
|
||||
CDigit& operator+=(const double& dValue);
|
||||
CDigit& operator-=(const double& dValue);
|
||||
CDigit& operator*=(const double& dValue);
|
||||
CDigit& operator/=(const double& dValue);
|
||||
|
||||
using CValueOptional<double>::operator=;
|
||||
private:
|
||||
UnitMeasure m_enUnitMeasure;
|
||||
|
||||
double ConvertValue(double dPrevValue, UnitMeasure enUnitMeasure) const;
|
||||
|
||||
template <typename Operation>
|
||||
CDigit ApplyOperation(const CDigit& oDigit, Operation operation) const;
|
||||
};
|
||||
|
||||
struct TRGB
|
||||
@ -186,6 +242,8 @@ namespace NSCSS
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
int ToInt() const;
|
||||
|
||||
bool operator==(const TRGB& oRGB) const;
|
||||
bool operator!=(const TRGB& oRGB) const;
|
||||
};
|
||||
@ -211,31 +269,58 @@ namespace NSCSS
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ColorEmpty,
|
||||
ColorNone,
|
||||
ColorRGB,
|
||||
ColorHEX,
|
||||
ColorUrl,
|
||||
ColorContextStroke,
|
||||
ColorContextFill
|
||||
} ColorType;
|
||||
} EColorType;
|
||||
|
||||
class CColor : public CValue<void*>
|
||||
class CColorValue
|
||||
{
|
||||
using color_value = boost::variant2::variant<boost::blank, std::wstring, TRGB, CURL>;
|
||||
protected:
|
||||
EColorType m_eType;
|
||||
public:
|
||||
CColorValue();
|
||||
CColorValue(const CColorValue& oValue);
|
||||
CColorValue(const std::wstring& wsValue);
|
||||
CColorValue(const TRGB& oValue);
|
||||
CColorValue(const CURL& oValue);
|
||||
|
||||
EColorType GetType() const;
|
||||
|
||||
bool operator==(const CColorValue& oValue) const;
|
||||
|
||||
color_value m_oValue;
|
||||
};
|
||||
|
||||
class CColorValueContextStroke : public CColorValue
|
||||
{
|
||||
public:
|
||||
CColorValueContextStroke();
|
||||
};
|
||||
|
||||
class CColorValueContextFill : public CColorValue
|
||||
{
|
||||
public:
|
||||
CColorValueContextFill();
|
||||
};
|
||||
|
||||
class CColor : public CValueOptional<CColorValue>
|
||||
{
|
||||
public:
|
||||
CColor();
|
||||
CColor(const CColor& oColor);
|
||||
~CColor();
|
||||
|
||||
bool SetValue(const std::wstring& wsValue, unsigned int unLevel = 0, bool bHardMode = true) override;
|
||||
bool SetOpacity(const std::wstring& wsValue, unsigned int unLevel = 0, bool bHardMode = true);
|
||||
|
||||
bool Empty() const override;
|
||||
bool None() const;
|
||||
bool Url() const;
|
||||
void Clear() override;
|
||||
|
||||
ColorType GetType() const;
|
||||
EColorType GetType() const;
|
||||
|
||||
double GetOpacity() const;
|
||||
|
||||
@ -249,20 +334,15 @@ namespace NSCSS
|
||||
static TRGB ConvertHEXtoRGB(const std::wstring& wsValue);
|
||||
static std::wstring ConvertRGBtoHEX(const TRGB& oValue);
|
||||
|
||||
bool operator==(const CColor& oColor) const;
|
||||
bool operator!=(const CColor& oColor) const;
|
||||
|
||||
CColor& operator =(const CColor& oColor);
|
||||
CColor& operator+=(const CColor& oColor);
|
||||
using CValueOptional<CColorValue>::operator=;
|
||||
private:
|
||||
CDigit m_oOpacity;
|
||||
ColorType m_enType;
|
||||
CDigit m_oOpacity;
|
||||
|
||||
void SetEmpty(unsigned int unLevel = 0);
|
||||
void SetRGB(unsigned char uchR, unsigned char uchG, unsigned char uchB);
|
||||
void SetRGB(const TRGB& oRGB);
|
||||
void SetHEX(const std::wstring& wsValue);
|
||||
void SetUrl(const std::wstring& wsValue);
|
||||
bool SetUrl(const std::wstring& wsValue);
|
||||
void SetNone();
|
||||
};
|
||||
|
||||
@ -279,7 +359,7 @@ namespace NSCSS
|
||||
|
||||
typedef std::vector<std::pair<std::vector<double>, TransformType>> MatrixValues;
|
||||
|
||||
class CMatrix : public CValue<MatrixValues>
|
||||
class CMatrix : public CValueBase<MatrixValues>
|
||||
{
|
||||
std::vector<std::wstring> CutTransforms(const std::wstring& wsValue) const;
|
||||
public:
|
||||
@ -304,29 +384,27 @@ namespace NSCSS
|
||||
bool operator==(const CMatrix& oMatrix) const;
|
||||
CMatrix& operator+=(const CMatrix& oMatrix);
|
||||
CMatrix& operator-=(const CMatrix& oMatrix);
|
||||
|
||||
using CValueBase<MatrixValues>::operator=;
|
||||
};
|
||||
|
||||
class CEnum : public CValue<int>
|
||||
class CEnum : public CValueOptional<int>
|
||||
{
|
||||
std::map<std::wstring, int> m_mMap;
|
||||
public:
|
||||
CEnum();
|
||||
|
||||
bool SetValue(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode) override;
|
||||
void SetMapping(const std::map<std::wstring, int>& mMap, int nDefaulvalue = -1);
|
||||
|
||||
bool Empty() const override;
|
||||
void Clear() override;
|
||||
|
||||
CEnum &operator =(int nValue);
|
||||
|
||||
bool operator==(int nValue) const;
|
||||
bool operator!=(int nValue) const;
|
||||
|
||||
int ToInt() const override;
|
||||
|
||||
using CValueOptional<int>::operator=;
|
||||
private:
|
||||
double ToDouble() const override;
|
||||
std::wstring ToWString() const override;
|
||||
|
||||
int m_nDefaultValue;
|
||||
std::map<std::wstring, int> m_mMap;
|
||||
};
|
||||
|
||||
// PROPERTIES
|
||||
@ -619,6 +697,30 @@ namespace NSCSS
|
||||
bool operator==(const TTextDecoration& oTextDecoration) const;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
Baseline,
|
||||
Sub,
|
||||
Super,
|
||||
Percentage,
|
||||
Length
|
||||
} EBaselineShift;
|
||||
|
||||
class CBaselineShift
|
||||
{
|
||||
CEnum m_eType;
|
||||
CDigit m_oValue;
|
||||
public:
|
||||
CBaselineShift();
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
EBaselineShift GetType() const;
|
||||
double GetValue() const;
|
||||
|
||||
bool SetValue(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
};
|
||||
|
||||
class CText
|
||||
{
|
||||
public:
|
||||
@ -626,11 +728,12 @@ namespace NSCSS
|
||||
|
||||
static void Equation(CText &oFirstText, CText &oSecondText);
|
||||
|
||||
bool SetIndent (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetAlign (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetDecoration(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetColor (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetHighlight (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetIndent (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetAlign (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetDecoration (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetColor (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetHighlight (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetBaselineShift (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
const CDigit& GetIndent() const;
|
||||
const CString& GetAlign() const;
|
||||
@ -638,6 +741,9 @@ namespace NSCSS
|
||||
const CColor& GetColor() const;
|
||||
const CColor& GetHighlight() const;
|
||||
|
||||
EBaselineShift GetBaselineShiftType() const;
|
||||
double GetBaselineShiftValue() const;
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
bool Underline() const;
|
||||
@ -647,6 +753,7 @@ namespace NSCSS
|
||||
CText& operator+=(const CText& oText);
|
||||
bool operator==(const CText& oText) const;
|
||||
private:
|
||||
CBaselineShift m_oBaselineShift;
|
||||
TTextDecoration m_oDecoration;
|
||||
CDigit m_oIndent;
|
||||
CString m_oAlign;
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
namespace Md
|
||||
{
|
||||
#define MD_PARSER_FLAGS MD_DIALECT_GITHUB | MD_FLAG_NOINDENTEDCODEBLOCKS | MD_HTML_FLAG_SKIP_UTF8_BOM | MD_FLAG_HARD_SOFT_BREAKS | MD_HTML_FLAG_XHTML
|
||||
#define MD_PARSER_FLAGS MD_DIALECT_GITHUB | MD_FLAG_NOINDENTEDCODEBLOCKS | MD_HTML_FLAG_SKIP_UTF8_BOM | MD_FLAG_HARD_SOFT_BREAKS | MD_HTML_FLAG_XHTML | MD_FLAG_LATEXMATHSPANS
|
||||
#define MD_RENDERER_FLAGS MD_HTML_FLAG_XHTML
|
||||
|
||||
void ToHtml(const MD_CHAR* pValue, MD_SIZE uSize, void* pData)
|
||||
|
||||
@ -133,7 +133,7 @@ namespace NSOpenSSL
|
||||
}
|
||||
|
||||
// rsa
|
||||
bool RSA_GenerateKeys(unsigned char*& publicKey, unsigned char*& privateKey, const int keyLen)
|
||||
bool RSA_GenerateKeys(unsigned char*& publicKey, unsigned char*& privateKey)
|
||||
{
|
||||
publicKey = NULL;
|
||||
privateKey = NULL;
|
||||
@ -142,8 +142,7 @@ namespace NSOpenSSL
|
||||
BIGNUM *exponent = BN_new();
|
||||
|
||||
BN_set_word(exponent, RSA_F4);
|
||||
int primes = (keyLen < 4096) ? 2 : 4;
|
||||
int result = RSA_generate_multi_prime_key(rsa, keyLen, primes, exponent, NULL);
|
||||
int result = RSA_generate_multi_prime_key(rsa, 2048, 2, exponent, NULL);
|
||||
if (0 == result)
|
||||
return false;
|
||||
|
||||
@ -371,27 +370,6 @@ namespace NSOpenSSL
|
||||
// new algs
|
||||
bool GenerateKeysByAlgs(const std::string& alg, std::string& publicKey, std::string& privateKey)
|
||||
{
|
||||
int nRsaKeyLen = 0;
|
||||
if ("rsa2048" == alg)
|
||||
nRsaKeyLen = 2048;
|
||||
else if ("rsa4096" == alg)
|
||||
nRsaKeyLen = 4096;
|
||||
|
||||
if (nRsaKeyLen > 0)
|
||||
{
|
||||
unsigned char* publicKeyPtr = NULL;
|
||||
unsigned char* privateKeyPtr = NULL;
|
||||
if (!RSA_GenerateKeys(publicKeyPtr, privateKeyPtr))
|
||||
return false;
|
||||
|
||||
publicKey = std::string((char*)publicKeyPtr);
|
||||
privateKey = std::string((char*)privateKeyPtr);
|
||||
|
||||
openssl_free(publicKeyPtr);
|
||||
openssl_free(privateKeyPtr);
|
||||
return true;
|
||||
}
|
||||
|
||||
EVP_PKEY* pkey = NULL;
|
||||
EVP_PKEY_CTX* pctx = NULL;
|
||||
|
||||
@ -475,7 +453,7 @@ namespace NSOpenSSL
|
||||
return (1 == nResult) ? true : false;
|
||||
}
|
||||
|
||||
CMemoryData Encrypt(const unsigned char* data, const int& data_len, const std::string& publicKey, const bool& isLenToBuffer)
|
||||
CMemoryData Enrypt(const unsigned char* data, const int& data_len, const std::string& publicKey)
|
||||
{
|
||||
CMemoryData returnData;
|
||||
|
||||
@ -499,19 +477,8 @@ namespace NSOpenSSL
|
||||
|
||||
size_t ciphertextLen = 0;
|
||||
EVP_PKEY_encrypt(ctx, NULL, &ciphertextLen, data, (size_t)data_len);
|
||||
|
||||
if (isLenToBuffer)
|
||||
{
|
||||
returnData.Alloc(ciphertextLen + 4);
|
||||
EVP_PKEY_encrypt(ctx, returnData.Data + 4, &returnData.Size, data, (size_t)data_len);
|
||||
int nLen = (int)returnData.Size;
|
||||
memcpy(returnData.Data, &nLen, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
returnData.Alloc(ciphertextLen);
|
||||
EVP_PKEY_encrypt(ctx, returnData.Data, &returnData.Size, data, (size_t)data_len);
|
||||
}
|
||||
returnData.Alloc(ciphertextLen);
|
||||
EVP_PKEY_encrypt(ctx, returnData.Data, &returnData.Size, data, (size_t)data_len);
|
||||
|
||||
EVP_PKEY_free(pkey);
|
||||
EVP_PKEY_CTX_free(ctx);
|
||||
@ -519,7 +486,7 @@ namespace NSOpenSSL
|
||||
return returnData;
|
||||
}
|
||||
|
||||
CMemoryData Decrypt(const unsigned char* data, const int& data_len, const std::string& privateKey, const bool& isLenToBuffer)
|
||||
CMemoryData Decrypt(const unsigned char* data, const int& data_len, const std::string& privateKey)
|
||||
{
|
||||
CMemoryData returnData;
|
||||
|
||||
@ -543,19 +510,8 @@ namespace NSOpenSSL
|
||||
|
||||
size_t ciphertextLen = 0;
|
||||
EVP_PKEY_decrypt(ctx, NULL, &ciphertextLen, data, (size_t)data_len);
|
||||
|
||||
if (isLenToBuffer)
|
||||
{
|
||||
returnData.Alloc(ciphertextLen + 4);
|
||||
EVP_PKEY_decrypt(ctx, returnData.Data + 4, &returnData.Size, data, (size_t)data_len);
|
||||
int nLen = (int)returnData.Size;
|
||||
memcpy(returnData.Data, &nLen, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
returnData.Alloc(ciphertextLen);
|
||||
EVP_PKEY_decrypt(ctx, returnData.Data, &returnData.Size, data, (size_t)data_len);
|
||||
}
|
||||
returnData.Alloc(ciphertextLen);
|
||||
EVP_PKEY_decrypt(ctx, returnData.Data, &returnData.Size, data, (size_t)data_len);
|
||||
|
||||
EVP_PKEY_free(pkey);
|
||||
EVP_PKEY_CTX_free(ctx);
|
||||
|
||||
@ -75,7 +75,7 @@ namespace NSOpenSSL
|
||||
OPENSSL_DECL unsigned char* GetHash(const unsigned char* data, const unsigned int& size, const int& alg, unsigned int& len);
|
||||
|
||||
// rsa
|
||||
OPENSSL_DECL bool RSA_GenerateKeys(unsigned char*& publicKey, unsigned char*& privateKey, const int keyLen = 2048);
|
||||
OPENSSL_DECL bool RSA_GenerateKeys(unsigned char*& publicKey, unsigned char*& privateKey);
|
||||
OPENSSL_DECL bool RSA_EncryptPublic(const unsigned char* publicKey, const unsigned char* data, const unsigned int& size, unsigned char*& data_crypt, unsigned int& data_crypt_len);
|
||||
OPENSSL_DECL bool RSA_DecryptPrivate(const unsigned char* privateKey, const unsigned char* data, const unsigned int& size, unsigned char*& data_decrypt, unsigned int& data_decrypt_len);
|
||||
|
||||
@ -91,8 +91,8 @@ namespace NSOpenSSL
|
||||
OPENSSL_DECL CMemoryData Sign(const unsigned char* data, const int& len, const std::string& privateKey);
|
||||
OPENSSL_DECL bool Verify(const unsigned char* data, const int& data_len, const std::string& publicKey,
|
||||
const unsigned char* signature, const int& signature_len);
|
||||
OPENSSL_DECL CMemoryData Encrypt(const unsigned char* data, const int& data_len, const std::string& publicKey, const bool& isLenToBuffer = false);
|
||||
OPENSSL_DECL CMemoryData Decrypt(const unsigned char* data, const int& data_len, const std::string& privateKey, const bool& isLenToBuffer = false);
|
||||
OPENSSL_DECL CMemoryData Enrypt(const unsigned char* data, const int& data_len, const std::string& publicKey);
|
||||
OPENSSL_DECL CMemoryData Decrypt(const unsigned char* data, const int& data_len, const std::string& privateKey);
|
||||
|
||||
// aes
|
||||
OPENSSL_DECL int AES_GetKeySize(int type);
|
||||
|
||||
@ -90,7 +90,7 @@ static std::wstring convertUtf16ToWString(const UTF16 * Data, int nLength)
|
||||
return std::wstring();
|
||||
}
|
||||
|
||||
std::wstring wstr ((wchar_t *) pStrUtf32);
|
||||
std::wstring wstr ((wchar_t *) pStrUtf32, nLength);
|
||||
|
||||
delete [] pStrUtf32;
|
||||
return wstr;
|
||||
|
||||
4
Common/3dParty/v8_89/.gitignore
vendored
@ -1,6 +1,6 @@
|
||||
.cipd
|
||||
.gclient
|
||||
.gclient_entries
|
||||
.gclient*
|
||||
.gcs*
|
||||
v8
|
||||
depot_tools
|
||||
v8.data
|
||||
|
||||
@ -967,7 +967,12 @@ bool COfficeFileFormatChecker::isOfficeFile(const std::wstring &_fileName)
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_MHT;
|
||||
else if (0 == sExt.compare(L".md"))
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_MD;
|
||||
else if (0 == sExt.compare(L".csv") || 0 == sExt.compare(L".xls") || 0 == sExt.compare(L".xlsx") || 0 == sExt.compare(L".xlsb"))
|
||||
else if (0 == sExt.compare(L".tsv"))
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_TSV;
|
||||
else if (0 == sExt.compare(L".scsv"))
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_SCSV;
|
||||
else if (0 == sExt.compare(L".csv") || 0 == sExt.compare(L".tsv") || 0 == sExt.compare(L".dsv") || 0 == sExt.compare(L".cssv")
|
||||
|| 0 == sExt.compare(L".xls") || 0 == sExt.compare(L".xlsx") || 0 == sExt.compare(L".xlsb"))
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV;
|
||||
else if (0 == sExt.compare(L".html") || 0 == sExt.compare(L".htm"))
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML;
|
||||
@ -1799,6 +1804,10 @@ std::wstring COfficeFileFormatChecker::GetExtensionByType(int type)
|
||||
return L".ods";
|
||||
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV:
|
||||
return L".csv";
|
||||
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_TSV:
|
||||
return L".tsv";
|
||||
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_SCSV:
|
||||
return L".scsv";
|
||||
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_ODS_FLAT:
|
||||
return L".fods";
|
||||
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_OTS:
|
||||
@ -1988,7 +1997,11 @@ int COfficeFileFormatChecker::GetFormatByExtension(const std::wstring &sExt)
|
||||
return AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSB;
|
||||
if (L".xls" == ext)
|
||||
return AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLS;
|
||||
if (L".csv" == ext)
|
||||
if (L".tsv" == ext)
|
||||
return AVS_OFFICESTUDIO_FILE_SPREADSHEET_TSV;
|
||||
if (L".scsv" == ext)
|
||||
return AVS_OFFICESTUDIO_FILE_SPREADSHEET_SCSV;
|
||||
if (L".csv" == ext || L".dsv" == ext)
|
||||
return AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV;
|
||||
if (L".fods" == ext)
|
||||
return AVS_OFFICESTUDIO_FILE_SPREADSHEET_ODS_FLAT;
|
||||
|
||||
@ -87,13 +87,14 @@
|
||||
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0005
|
||||
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTX AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0006
|
||||
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTM AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0007
|
||||
|
||||
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSB AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0008
|
||||
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_ODS_FLAT AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0009
|
||||
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_OTS AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x000a
|
||||
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX_FLAT AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x000b
|
||||
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX_PACKAGE AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x000c
|
||||
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_NUMBERS AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x000d
|
||||
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_TSV AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0014
|
||||
#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_SCSV AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0024
|
||||
|
||||
#define AVS_OFFICESTUDIO_FILE_CROSSPLATFORM 0x0200
|
||||
#define AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF AVS_OFFICESTUDIO_FILE_CROSSPLATFORM + 0x0001
|
||||
|
||||
200
Common/base.pri
@ -118,13 +118,13 @@ win32:contains(QMAKE_TARGET.arch, arm64): {
|
||||
}
|
||||
|
||||
linux-clang-libc++ {
|
||||
CONFIG += core_linux
|
||||
CONFIG += core_linux
|
||||
CONFIG += core_linux_64
|
||||
CONFIG += core_linux_clang
|
||||
message("linux-64-clang-libc++")
|
||||
}
|
||||
linux-clang-libc++-32 {
|
||||
CONFIG += core_linux
|
||||
CONFIG += core_linux
|
||||
CONFIG += core_linux_32
|
||||
CONFIG += core_linux_clang
|
||||
message("linux-32-clang-libc++")
|
||||
@ -180,9 +180,9 @@ mac {
|
||||
!core_ios {
|
||||
CONFIG += core_mac
|
||||
CONFIG += core_mac_64
|
||||
|
||||
DEFINES += _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
|
||||
}
|
||||
|
||||
DEFINES += _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
|
||||
}
|
||||
|
||||
# DEFINES
|
||||
@ -199,32 +199,58 @@ core_win_64 {
|
||||
DEFINES += WIN64 _WIN64
|
||||
}
|
||||
|
||||
defineTest(startsWith) {
|
||||
tmp = $$2
|
||||
tmp ~= s,^$$re_escape($$1),,
|
||||
!equals(tmp, $$2): return(true)
|
||||
return(false)
|
||||
}
|
||||
|
||||
core_linux {
|
||||
DEFINES += LINUX _LINUX
|
||||
|
||||
QMAKE_CUSTOM_SYSROOT = $$(QMAKE_CUSTOM_SYSROOT)
|
||||
QMAKE_CUSTOM_SYSROOT_BIN = $$(QMAKE_CUSTOM_SYSROOT)/usr/bin/
|
||||
!isEmpty(QMAKE_CUSTOM_SYSROOT) {
|
||||
CONFIG += core_linix_use_sysroot
|
||||
message("using custom sysroot $$QMAKE_CUSTOM_SYSROOT")
|
||||
|
||||
core_linux_64 {
|
||||
!linux_arm64 { # x86_64
|
||||
QMAKE_CUSTOM_SYSROOT_LIB = $$(QMAKE_CUSTOM_SYSROOT)/usr/lib/x86_64-linux-gnu
|
||||
!isEmpty(QMAKE_CUSTOM_SYSROOT) {
|
||||
message("using custom sysroot $$QMAKE_CUSTOM_SYSROOT")
|
||||
QMAKE_CC = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "gcc")
|
||||
QMAKE_CXX = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "g++")
|
||||
QMAKE_LINK = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "g++")
|
||||
QMAKE_LINK_SHLIB = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "g++")
|
||||
|
||||
QMAKE_CFLAGS += --sysroot $$QMAKE_CUSTOM_SYSROOT
|
||||
QMAKE_CXXFLAGS += --sysroot $$QMAKE_CUSTOM_SYSROOT -std=gnu++1y
|
||||
QMAKE_LFLAGS += --sysroot $$QMAKE_CUSTOM_SYSROOT
|
||||
}
|
||||
QMAKE_CUSTOM_SYSROOT_BIN = $$(QMAKE_CUSTOM_SYSROOT_BIN)
|
||||
isEmpty(QMAKE_CUSTOM_SYSROOT_BIN) {
|
||||
QMAKE_CUSTOM_SYSROOT_BIN = $$QMAKE_CUSTOM_SYSROOT/usr/bin
|
||||
}
|
||||
QMAKE_CUSTOM_SYSROOT_BIN = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , /)
|
||||
|
||||
startsWith($$QMAKE_CUSTOM_SYSROOT, $$QMAKE_CUSTOM_SYSROOT_BIN) {
|
||||
message("Using compilers from same sysroot")
|
||||
QMAKE_CC = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "gcc")
|
||||
QMAKE_CXX = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "g++")
|
||||
QMAKE_LINK = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "g++")
|
||||
QMAKE_LINK_SHLIB = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "g++")
|
||||
QMAKE_AR = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "ar") cqs
|
||||
QMAKE_RANLIB = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "ranlib")
|
||||
QMAKE_STRIP = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "strip")
|
||||
} else {
|
||||
message("Using cross-compilers from host sysroot")
|
||||
QMAKE_CC = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "aarch64-linux-gnu-gcc")
|
||||
QMAKE_CXX = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "aarch64-linux-gnu-g++")
|
||||
QMAKE_LINK = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "aarch64-linux-gnu-g++")
|
||||
QMAKE_LINK_SHLIB = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "aarch64-linux-gnu-g++")
|
||||
QMAKE_AR = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "aarch64-linux-gnu-ar") cqs
|
||||
QMAKE_RANLIB = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "aarch64-linux-gnu-ranlib")
|
||||
QMAKE_STRIP = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "aarch64-linux-gnu-strip")
|
||||
QMAKE_OBJCOPY = $$join(QMAKE_CUSTOM_SYSROOT_BIN, , , "aarch64-linux-gnu-objcopy")
|
||||
}
|
||||
|
||||
QMAKE_CFLAGS += --sysroot=$$QMAKE_CUSTOM_SYSROOT
|
||||
QMAKE_CXXFLAGS += --sysroot=$$QMAKE_CUSTOM_SYSROOT -std=gnu++1y
|
||||
|
||||
QMAKE_LFLAGS += --sysroot=$$QMAKE_CUSTOM_SYSROOT
|
||||
QMAKE_INCDIR += $$QMAKE_CUSTOM_SYSROOT/usr/include
|
||||
}
|
||||
}
|
||||
|
||||
gcc {
|
||||
COMPILER_VERSION = $$system($$QMAKE_CXX " -dumpversion")
|
||||
COMPILER_VERSION = $$system($$QMAKE_CXX " -dumpversion")
|
||||
COMPILER_MAJOR_VERSION_ARRAY = $$split(COMPILER_VERSION, ".")
|
||||
COMPILER_MAJOR_VERSION = $$member(COMPILER_MAJOR_VERSION_ARRAY, 0)
|
||||
lessThan(COMPILER_MAJOR_VERSION, 5): CONFIG += build_gcc_less_5
|
||||
@ -254,6 +280,11 @@ core_mac {
|
||||
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.12
|
||||
!apple_silicon:QMAKE_APPLE_DEVICE_ARCHS = x86_64
|
||||
}
|
||||
|
||||
!core_debug {
|
||||
equals(TEMPLATE, app):QMAKE_POST_LINK += strip $(TARGET)
|
||||
# TODO: plugin!
|
||||
}
|
||||
}
|
||||
|
||||
core_linux_clang {
|
||||
@ -312,6 +343,10 @@ core_linux {
|
||||
core_linux {
|
||||
equals(TEMPLATE, app):CONFIG += core_static_link_libstd
|
||||
plugin:CONFIG += core_static_link_libstd
|
||||
|
||||
|
||||
equals(TEMPLATE, app):QMAKE_LFLAGS_RELEASE += -Wl,-s
|
||||
plugin:QMAKE_LFLAGS_RELEASE += -Wl,-s
|
||||
}
|
||||
|
||||
core_win_32 {
|
||||
@ -321,7 +356,7 @@ core_win_64 {
|
||||
CORE_BUILDS_PLATFORM_PREFIX = win_64
|
||||
}
|
||||
core_win_arm64 {
|
||||
CORE_BUILDS_PLATFORM_PREFIX = win_arm64
|
||||
CORE_BUILDS_PLATFORM_PREFIX = win_arm64
|
||||
}
|
||||
core_linux_32 {
|
||||
CORE_BUILDS_PLATFORM_PREFIX = linux_32
|
||||
@ -343,27 +378,6 @@ core_linux_arm {
|
||||
linux_arm64 {
|
||||
CORE_BUILDS_PLATFORM_PREFIX = linux_arm64
|
||||
DEFINES += _ARM_ALIGN_
|
||||
|
||||
ARM64_TOOLCHAIN_BIN = $$(ARM64_TOOLCHAIN_BIN)
|
||||
ARM64_TOOLCHAIN_BIN_PREFIX = $$(ARM64_TOOLCHAIN_BIN_PREFIX)
|
||||
|
||||
!isEmpty(ARM64_TOOLCHAIN_BIN){
|
||||
!isEmpty(ARM64_TOOLCHAIN_BIN_PREFIX){
|
||||
ARM64_TOOLCHAIN_BIN_FULL = $$ARM64_TOOLCHAIN_BIN/$$ARM64_TOOLCHAIN_BIN_PREFIX
|
||||
message("using arm64 toolchain $$ARM64_TOOLCHAIN_BIN")
|
||||
|
||||
QMAKE_CC = $$join(ARM64_TOOLCHAIN_BIN_FULL, , , "gcc")
|
||||
QMAKE_CXX = $$join(ARM64_TOOLCHAIN_BIN_FULL, , , "g++")
|
||||
QMAKE_LINK = $$join(ARM64_TOOLCHAIN_BIN_FULL, , , "g++")
|
||||
QMAKE_LINK_SHLIB = $$join(ARM64_TOOLCHAIN_BIN_FULL, , , "g++")
|
||||
|
||||
QMAKE_AR = $$join(ARM64_TOOLCHAIN_BIN_FULL, , , "ar cqs")
|
||||
QMAKE_OBJCOPY = $$join(ARM64_TOOLCHAIN_BIN_FULL, , , "objcopy")
|
||||
QMAKE_NM = $$join(ARM64_TOOLCHAIN_BIN_FULL, , , "nm -P")
|
||||
QMAKE_STRIP = $$join(ARM64_TOOLCHAIN_BIN_FULL, , , "strip")
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
core_ios {
|
||||
CORE_BUILDS_PLATFORM_PREFIX = ios
|
||||
@ -690,3 +704,105 @@ ADD_INC_PATH = $$(ADDITIONAL_INCLUDE_PATH)
|
||||
!disable_precompiled_header {
|
||||
CONFIG += precompile_header
|
||||
}
|
||||
|
||||
SWIFT_SOURCES=
|
||||
defineTest(UseSwift) {
|
||||
isEmpty(SWIFT_SOURCES): return(false)
|
||||
# work only on ios and mac
|
||||
!core_ios:!core_mac {
|
||||
return(false)
|
||||
}
|
||||
|
||||
# path to the bridging header that exposes Objective-C code to Swift
|
||||
BRIDGING_HEADER = $$1
|
||||
# sdk and toolchain (set from environment variables)
|
||||
SDK_PATH = $$(SDK_PATH)
|
||||
XCODE_TOOLCHAIN_PATH = $$(XCODE_TOOLCHAIN_PATH)
|
||||
|
||||
IOS_TARGET_PLATFORM = apple-ios11.0
|
||||
SWIFT_GEN_HEADERS_PATH = $$PWD_ROOT_DIR/core_build/$$CORE_BUILDS_PLATFORM_PREFIX/$$CORE_BUILDS_CONFIGURATION_PREFIX
|
||||
ARCHS = arm64
|
||||
# simulator
|
||||
xcframework_platform_ios_simulator {
|
||||
IOS_TARGET_PLATFORM = $${IOS_TARGET_PLATFORM}-simulator
|
||||
SWIFT_GEN_HEADERS_PATH = $$SWIFT_GEN_HEADERS_PATH/simulator
|
||||
ARCHS += x86_64
|
||||
}
|
||||
|
||||
# add swift compiler for each architecture
|
||||
SWIFT_COMPILERS_OUT =
|
||||
for(ARCH, ARCHS) {
|
||||
COMPILER_NAME = swift_compiler_$${ARCH}
|
||||
COMPILER_OUTPUT = $$SWIFT_GEN_HEADERS_PATH/swift_module_$${ARCH}.o
|
||||
SWIFT_COMPILERS_OUT += $$COMPILER_OUTPUT
|
||||
|
||||
$${COMPILER_NAME}.name = SwiftCompiler_$${ARCH}
|
||||
$${COMPILER_NAME}.input = SWIFT_SOURCES
|
||||
$${COMPILER_NAME}.output = $$COMPILER_OUTPUT
|
||||
SWIFT_CMD = swiftc -c $$SWIFT_SOURCES \
|
||||
-module-name SwiftModule \
|
||||
-whole-module-optimization \
|
||||
-emit-objc-header \
|
||||
-emit-objc-header-path $$SWIFT_GEN_HEADERS_PATH/SwiftModule-Swift.h \
|
||||
-emit-object \
|
||||
-sdk $$SDK_PATH \
|
||||
-target $${ARCH}-$${IOS_TARGET_PLATFORM} \
|
||||
-o $$COMPILER_OUTPUT \
|
||||
-framework UIKit
|
||||
|
||||
!isEmpty(BRIDGING_HEADER) {
|
||||
SWIFT_CMD += -import-objc-header $$BRIDGING_HEADER
|
||||
}
|
||||
|
||||
$${COMPILER_NAME}.commands = $$SWIFT_CMD
|
||||
$${COMPILER_NAME}.CONFIG = combine target_predeps no_link
|
||||
|
||||
export($${COMPILER_NAME}.name)
|
||||
export($${COMPILER_NAME}.input)
|
||||
export($${COMPILER_NAME}.output)
|
||||
export($${COMPILER_NAME}.commands)
|
||||
export($${COMPILER_NAME}.CONFIG)
|
||||
QMAKE_EXTRA_COMPILERS += $${COMPILER_NAME}
|
||||
}
|
||||
|
||||
# add lipo tool execution to form universal binary
|
||||
LIPO_OUT = $$SWIFT_GEN_HEADERS_PATH/swift_module.o
|
||||
lipo_tool.name = LipoTool
|
||||
# as input for lipo_tool we set SWIFT_SOURCES (not SWIFT_COMPILERS_OUT as it won't be executed otherwise!)
|
||||
lipo_tool.input = SWIFT_SOURCES
|
||||
# compiled swift sources go into depends
|
||||
lipo_tool.depends = $$SWIFT_COMPILERS_OUT
|
||||
lipo_tool.output = $$LIPO_OUT
|
||||
lipo_tool.commands = lipo -create $$SWIFT_COMPILERS_OUT -output $$LIPO_OUT
|
||||
lipo_tool.CONFIG = combine target_predeps no_link
|
||||
lipo_tool.variable_out = OBJECTS
|
||||
|
||||
export(lipo_tool.name)
|
||||
export(lipo_tool.input)
|
||||
export(lipo_tool.depends)
|
||||
export(lipo_tool.output)
|
||||
export(lipo_tool.commands)
|
||||
export(lipo_tool.CONFIG)
|
||||
export(lipo_tool.variable_out)
|
||||
QMAKE_EXTRA_COMPILERS += lipo_tool
|
||||
|
||||
export(QMAKE_EXTRA_COMPILERS)
|
||||
|
||||
INCLUDEPATH += $$SWIFT_GEN_HEADERS_PATH
|
||||
export(INCLUDEPATH)
|
||||
|
||||
# link with libs from toolchain
|
||||
SWIFT_LIB_PATH = $$XCODE_TOOLCHAIN_PATH/usr/lib/swift/iphoneos
|
||||
xcframework_platform_ios_simulator {
|
||||
SWIFT_LIB_PATH = $$XCODE_TOOLCHAIN_PATH/usr/lib/swift/iphonesimulator
|
||||
}
|
||||
LIBS += -L$$SWIFT_LIB_PATH
|
||||
LIBS += -lswiftCore -lswiftFoundation -lswiftObjectiveC
|
||||
|
||||
export(LIBS)
|
||||
|
||||
OTHER_FILES += $$SWIFT_SOURCES
|
||||
export(OTHER_FILES)
|
||||
return(true)
|
||||
}
|
||||
|
||||
|
||||
@ -10,8 +10,6 @@ import common
|
||||
|
||||
base.configure_common_apps()
|
||||
|
||||
python_binary = sys.executable
|
||||
|
||||
# fetch emsdk
|
||||
command_prefix = "" if ("windows" == base.host_platform()) else "./"
|
||||
if not base.is_dir("emsdk"):
|
||||
@ -143,9 +141,9 @@ for param in argv:
|
||||
if json_data["run_before"]:
|
||||
base.print_info("before")
|
||||
if base.is_file(work_dir + json_data["run_before"]):
|
||||
base.cmd_in_dir(work_dir, python_binary, [json_data["run_before"]])
|
||||
base.cmd_in_dir(work_dir, "python", [json_data["run_before"]])
|
||||
else:
|
||||
base.cmd_in_dir(work_dir, python_binary, ["-c", json_data["run_before"]])
|
||||
base.cmd_in_dir(work_dir, "python", ["-c", json_data["run_before"]])
|
||||
|
||||
# remove previous version
|
||||
common.clear_dir(work_dir + "/o")
|
||||
@ -171,6 +169,6 @@ for param in argv:
|
||||
if json_data["run_after"]:
|
||||
base.print_info("after")
|
||||
if base.is_file(work_dir + json_data["run_after"]):
|
||||
base.cmd_in_dir(work_dir, python_binary, [json_data["run_after"]])
|
||||
base.cmd_in_dir(work_dir, "python", [json_data["run_after"]])
|
||||
else:
|
||||
base.cmd_in_dir(work_dir, python_binary, ["-c", json_data["run_after"]])
|
||||
base.cmd_in_dir(work_dir, "python", ["-c", json_data["run_after"]])
|
||||
|
||||
@ -60,6 +60,7 @@ namespace NSSystemUtils
|
||||
static const wchar_t* gc_EnvModified = L"MODIFIED";
|
||||
static const wchar_t* gc_EnvMemoryLimit = L"X2T_MEMORY_LIMIT";
|
||||
static const wchar_t* gc_EnvMemoryLimitDefault = L"4GiB";
|
||||
static const wchar_t* gc_EnvSigningKeystorePassphrase = L"SIGNING_KEYSTORE_PASSPHRASE";
|
||||
|
||||
KERNEL_DECL std::string GetEnvVariableA(const std::wstring& strName);
|
||||
KERNEL_DECL std::wstring GetEnvVariable(const std::wstring& strName);
|
||||
|
||||
@ -26,7 +26,7 @@ def _loadLibrary(path):
|
||||
library_name = 'libdocbuilder.c.dylib'
|
||||
# if there is no dylib file, get library from framework
|
||||
if not os.path.exists(path + '/' + library_name):
|
||||
path = path + '/docbuilder.c.framework'
|
||||
path = path + '/docbuilder.c.framework/Versions/A'
|
||||
library_name = 'docbuilder.c'
|
||||
|
||||
_lib = ctypes.CDLL(path + '/' + library_name)
|
||||
|
||||
@ -120,7 +120,7 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
bool OpenFile(const std::wstring& sFile, const std::wstring& sPassword)
|
||||
bool OpenFile(const std::wstring& sFile, const wchar_t* sPassword)
|
||||
{
|
||||
CloseFile();
|
||||
|
||||
@ -171,7 +171,7 @@ public:
|
||||
|
||||
return m_pFile ? true : false;
|
||||
}
|
||||
bool OpenFile(BYTE* data, LONG size, const std::wstring& sPassword)
|
||||
bool OpenFile(BYTE* data, LONG size, const wchar_t* sPassword)
|
||||
{
|
||||
CloseFile();
|
||||
|
||||
@ -245,7 +245,7 @@ public:
|
||||
|
||||
return 0;
|
||||
}
|
||||
bool CheckOwnerPassword(const std::wstring& sPassword)
|
||||
bool CheckOwnerPassword(const wchar_t* sPassword)
|
||||
{
|
||||
if (m_nType == 0)
|
||||
return ((CPdfFile*)m_pFile)->CheckOwnerPassword(sPassword);
|
||||
@ -454,6 +454,20 @@ public:
|
||||
if (m_nType == 0)
|
||||
((CPdfFile*)m_pFile)->SetCMapMemory(data, size);
|
||||
}
|
||||
void SetScanPageFonts(int nPageIndex)
|
||||
{
|
||||
if (NULL == m_pImageStorage)
|
||||
m_pImageStorage = NSDocxRenderer::CreateWasmImageStorage();
|
||||
|
||||
CDocxRenderer oRenderer(m_pApplicationFonts);
|
||||
oRenderer.SetExternalImageStorage(m_pImageStorage);
|
||||
oRenderer.SetTextAssociationType(NSDocxRenderer::TextAssociationType::tatParagraphToShape);
|
||||
|
||||
oRenderer.ScanPageBin(m_pFile, nPageIndex);
|
||||
|
||||
if (m_nType == 0)
|
||||
((CPdfFile*)m_pFile)->SetPageFonts(nPageIndex);
|
||||
}
|
||||
BYTE* ScanPage(int nPageIndex, int mode)
|
||||
{
|
||||
if (NULL == m_pImageStorage)
|
||||
@ -490,6 +504,9 @@ public:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (m_nType == 0)
|
||||
((CPdfFile*)m_pFile)->SetPageFonts(nPageIndex);
|
||||
|
||||
BYTE* res = oRes.GetBuffer();
|
||||
oRes.ClearWithoutAttack();
|
||||
return res;
|
||||
@ -578,6 +595,13 @@ public:
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
BYTE* GetGIDByUnicode(const std::string& sPathA)
|
||||
{
|
||||
if (m_nType != 0)
|
||||
return NULL;
|
||||
std::wstring sFontName = UTF8_TO_U(sPathA);
|
||||
return ((CPdfFile*)m_pFile)->GetGIDByUnicode(sFontName);
|
||||
}
|
||||
|
||||
std::wstring GetFontBinaryNative(const std::wstring& sName)
|
||||
{
|
||||
|
||||
@ -26,7 +26,8 @@ CDrawingFileEmbed::~CDrawingFileEmbed()
|
||||
|
||||
JSSmart<CJSValue> CDrawingFileEmbed::OpenFile(JSSmart<CJSValue> sFile, JSSmart<CJSValue> sPassword)
|
||||
{
|
||||
bool bResult = m_pFile->OpenFile(sFile->toStringW(), sPassword->isString() ? sPassword->toStringW() : L"");
|
||||
std::wstring wsPassword = sPassword->isString() ? sPassword->toStringW() : L"";
|
||||
bool bResult = m_pFile->OpenFile(sFile->toStringW(), sPassword->isString() ? wsPassword.c_str() : NULL);
|
||||
return CJSContext::createBool(bResult);
|
||||
}
|
||||
JSSmart<CJSValue> CDrawingFileEmbed::CloseFile()
|
||||
|
||||
@ -461,6 +461,8 @@ namespace NSJSBase
|
||||
v8::SnapshotCreator snapshotCreator;
|
||||
v8::Isolate* isolate = snapshotCreator.GetIsolate();
|
||||
{
|
||||
CV8TryCatch try_catch(isolate);
|
||||
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
// Create a new context
|
||||
v8::Local<v8::Context> context = v8::Context::New(isolate);
|
||||
@ -472,11 +474,12 @@ namespace NSJSBase
|
||||
global->Set(context, v8::String::NewFromUtf8Literal(isolate, "self"), global).Check();
|
||||
global->Set(context, v8::String::NewFromUtf8Literal(isolate, "native"), v8::Undefined(isolate)).Check();
|
||||
|
||||
// Compile and run
|
||||
// Compile
|
||||
v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, script.c_str()).ToLocalChecked();
|
||||
v8::Local<v8::Script> script = v8::Script::Compile(context, source).ToLocalChecked();
|
||||
|
||||
// Run
|
||||
script->Run(context).IsEmpty();
|
||||
|
||||
snapshotCreator.SetDefaultContext(context);
|
||||
}
|
||||
v8::StartupData data = snapshotCreator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kKeep);
|
||||
|
||||
@ -62,7 +62,13 @@ v8::Local<v8::String> CreateV8String(v8::Isolate* i, const std::string& str);
|
||||
#include <android/log.h>
|
||||
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, "js", __VA_ARGS__)
|
||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, "js", __VA_ARGS__)
|
||||
#endif
|
||||
#ifdef _DEBUG
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "js", __VA_ARGS__)
|
||||
#else
|
||||
// should be disabled for release builds
|
||||
#define LOGD(...)
|
||||
#endif // _DEBUG
|
||||
#endif // ANDROID_LOGS
|
||||
|
||||
#endif
|
||||
|
||||
@ -799,6 +805,9 @@ namespace NSJSBase
|
||||
CV8TryCatch() : CJSTryCatch(), try_catch(V8IsolateOneArg)
|
||||
{
|
||||
}
|
||||
CV8TryCatch(v8::Isolate* isolate) : CJSTryCatch(), try_catch(isolate)
|
||||
{
|
||||
}
|
||||
virtual ~CV8TryCatch()
|
||||
{
|
||||
}
|
||||
|
||||
@ -731,10 +731,10 @@ void CFontFile::CheckHintsSupport()
|
||||
int CFontFile::SetCMapForCharCode(long lUnicode, int *pnCMapIndex)
|
||||
{
|
||||
*pnCMapIndex = -1;
|
||||
if (!m_pFace)
|
||||
if (!m_pFace || !m_pFace->num_charmaps)
|
||||
return 0;
|
||||
|
||||
if ( m_bStringGID || 0 == m_pFace->num_charmaps )
|
||||
if ( m_bStringGID )
|
||||
return lUnicode;
|
||||
|
||||
int nCharIndex = 0;
|
||||
|
||||
@ -117,7 +117,7 @@ WASM_EXPORT unsigned int ASC_FT_SetCMapForCharCode(FT_Face face, unsigned int un
|
||||
return 0;
|
||||
|
||||
if ( 0 == face->num_charmaps )
|
||||
return unicode;
|
||||
return 0;
|
||||
|
||||
unsigned int nCharIndex = 0;
|
||||
|
||||
|
||||
@ -265,15 +265,15 @@
|
||||
},
|
||||
{
|
||||
"folder": "../../",
|
||||
"files": ["graphics/Image.cpp", "raster/BgraFrame.cpp", "raster/ImageFileFormatChecker.cpp", "graphics/Matrix.cpp"]
|
||||
"files": ["graphics/Image.cpp", "raster/BgraFrame.cpp", "raster/ImageFileFormatChecker.cpp", "graphics/Matrix.cpp", "graphics/GraphicsPath.cpp"]
|
||||
},
|
||||
{
|
||||
"folder": "../../agg-2.4/src/",
|
||||
"files": ["agg_trans_affine.cpp"]
|
||||
"files": ["agg_trans_affine.cpp", "agg_bezier_arc.cpp"]
|
||||
},
|
||||
{
|
||||
"folder": "../../raster/",
|
||||
"files": ["PICT/PICFile.cpp", "PICT/pic.cpp"]
|
||||
"files": ["PICT/PICFile.cpp"]
|
||||
},
|
||||
{
|
||||
"folder": "../../graphics/pro/js/qt/raster",
|
||||
|
||||
@ -737,11 +737,13 @@ CBooleanOperations::CBooleanOperations(const CGraphicsPath& path1,
|
||||
const CGraphicsPath& path2,
|
||||
BooleanOpType op,
|
||||
long fillType,
|
||||
bool isLuminosity) :
|
||||
bool isLuminosity,
|
||||
bool isSelf) :
|
||||
Op(op),
|
||||
Close1(path1.Is_poly_closed()),
|
||||
Close2(path2.Is_poly_closed()),
|
||||
IsLuminosity(isLuminosity),
|
||||
IsSelf(isSelf),
|
||||
FillType(fillType),
|
||||
Path1(path1),
|
||||
Path2(path2)
|
||||
@ -784,10 +786,9 @@ bool CBooleanOperations::IsSelfInters(const CGraphicsPath& p)
|
||||
void CBooleanOperations::TraceBoolean()
|
||||
{
|
||||
bool reverse = false;
|
||||
bool self = Path1 == Path2;
|
||||
if (((Op == Subtraction || Op == Exclusion) ^
|
||||
Path1.IsClockwise() ^
|
||||
Path2.IsClockwise()) && !self)
|
||||
Path2.IsClockwise()) && !IsSelf)
|
||||
reverse = true;
|
||||
|
||||
PreparePath(Path1, 1, Segments1, Curves1);
|
||||
@ -798,7 +799,7 @@ void CBooleanOperations::TraceBoolean()
|
||||
|
||||
GetIntersection();
|
||||
|
||||
if (self)
|
||||
if (IsSelf)
|
||||
{
|
||||
if (Op == Subtraction)
|
||||
return;
|
||||
@ -823,6 +824,11 @@ void CBooleanOperations::TraceBoolean()
|
||||
CreateNewPath(adj_matr);
|
||||
return;
|
||||
}
|
||||
else if (Path1 == Path2)
|
||||
{
|
||||
Result = std::move(Path1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Locations.empty())
|
||||
{
|
||||
@ -2355,7 +2361,7 @@ CGraphicsPath CalcBooleanOperation(const CGraphicsPath& path1,
|
||||
CBooleanOperations o;
|
||||
if (i > skip_end2 && o.IsSelfInters(paths2[i]))
|
||||
{
|
||||
CBooleanOperations operation(paths2[i], paths2[i], Intersection, fillType, isLuminosity);
|
||||
CBooleanOperations operation(paths2[i], paths2[i], Intersection, fillType, isLuminosity, true);
|
||||
CGraphicsPath p = std::move(operation.GetResult());
|
||||
|
||||
std::vector<CGraphicsPath> tmp_paths = p.GetSubPaths();
|
||||
@ -2370,7 +2376,7 @@ CGraphicsPath CalcBooleanOperation(const CGraphicsPath& path1,
|
||||
CBooleanOperations o2;
|
||||
if (j > skip_end1 && o2.IsSelfInters(paths1[j]))
|
||||
{
|
||||
CBooleanOperations operation(paths1[j], paths1[j], Intersection, fillType, isLuminosity);
|
||||
CBooleanOperations operation(paths1[j], paths1[j], Intersection, fillType, isLuminosity, true);
|
||||
CGraphicsPath p = std::move(operation.GetResult());
|
||||
|
||||
std::vector<CGraphicsPath> tmp_paths = p.GetSubPaths();
|
||||
@ -2380,7 +2386,7 @@ CGraphicsPath CalcBooleanOperation(const CGraphicsPath& path1,
|
||||
paths1.insert(paths1.begin() + i + k, tmp_paths[k]);
|
||||
}
|
||||
|
||||
CBooleanOperations operation(paths1[j], paths2[i], op, fillType, isLuminosity);
|
||||
CBooleanOperations operation(paths1[j], paths2[i], op, fillType, isLuminosity, false);
|
||||
paths.push_back(operation.GetResult());
|
||||
}
|
||||
|
||||
|
||||
@ -108,7 +108,7 @@ namespace Aggplus
|
||||
{
|
||||
public:
|
||||
CBooleanOperations() {};
|
||||
CBooleanOperations(const CGraphicsPath& path1, const CGraphicsPath& path2, BooleanOpType op, long fillType, bool isLuminosity);
|
||||
CBooleanOperations(const CGraphicsPath& path1, const CGraphicsPath& path2, BooleanOpType op, long fillType, bool isLuminosity, bool isSelf);
|
||||
~CBooleanOperations();
|
||||
CGraphicsPath&& GetResult();
|
||||
bool IsSelfInters(const CGraphicsPath& p);
|
||||
@ -166,6 +166,7 @@ namespace Aggplus
|
||||
bool Close1 = true;
|
||||
bool Close2 = true;
|
||||
bool IsLuminosity = false;
|
||||
bool IsSelf = false;
|
||||
|
||||
// c_nStroke, c_nWindingFillMode, c_nEvenOddFillMode
|
||||
long FillType = c_nWindingFillMode;
|
||||
|
||||
@ -419,6 +419,7 @@ namespace Aggplus
|
||||
m_bReleaseImage = FALSE;
|
||||
Alpha = 255;
|
||||
m_bUseBounds = false;
|
||||
m_bIsScale = false;
|
||||
}
|
||||
|
||||
CBrushTexture::CBrushTexture(const std::wstring& strName, WrapMode wrapMode) : CBrush(BrushTypeTextureFill), m_wrapMode(wrapMode)
|
||||
@ -427,6 +428,7 @@ namespace Aggplus
|
||||
m_bReleaseImage = TRUE;
|
||||
Alpha = 255;
|
||||
m_bUseBounds = false;
|
||||
m_bIsScale = false;
|
||||
}
|
||||
|
||||
CBrushTexture::CBrushTexture(CImage *pImage, WrapMode wrapMode) : CBrush(BrushTypeTextureFill), m_wrapMode(wrapMode)
|
||||
@ -435,6 +437,7 @@ namespace Aggplus
|
||||
m_bReleaseImage = FALSE;
|
||||
Alpha = 255;
|
||||
m_bUseBounds = false;
|
||||
m_bIsScale = false;
|
||||
}
|
||||
|
||||
CBrushTexture::~CBrushTexture()
|
||||
|
||||
@ -205,6 +205,10 @@ public:
|
||||
bool m_bUseBounds;
|
||||
CDoubleRect m_oBounds;
|
||||
|
||||
bool m_bIsScale;
|
||||
double m_dScaleX;
|
||||
double m_dScaleY;
|
||||
|
||||
BYTE Alpha;
|
||||
};
|
||||
}
|
||||
|
||||
@ -847,6 +847,8 @@ namespace Aggplus
|
||||
double dScaleY = m_dDpiY / m_dDpiTile;
|
||||
|
||||
brushMatrix.Scale(dScaleX, dScaleY, Aggplus::MatrixOrderAppend);
|
||||
if (ptxBrush->m_bIsScale)
|
||||
brushMatrix.Scale(ptxBrush->m_dScaleX, ptxBrush->m_dScaleY, Aggplus::MatrixOrderAppend);
|
||||
}
|
||||
|
||||
brushMatrix.Translate(x, y, Aggplus::MatrixOrderAppend);
|
||||
@ -2142,7 +2144,12 @@ namespace Aggplus
|
||||
agg::trans_affine* full_trans = &m_oFullTransform.m_internal->m_agg_mtx;
|
||||
double dDet = full_trans->determinant();
|
||||
|
||||
if (fabs(dDet) < 0.0001)
|
||||
double sx = sqrt(full_trans->sx * full_trans->sx + full_trans->shx * full_trans->shx);
|
||||
double sy = sqrt(full_trans->shy * full_trans->shy + full_trans->sy * full_trans->sy);
|
||||
double scale = std::max(sx, sy);
|
||||
double adaptive_threshold = 1.0 / (scale * scale * 10000.0);
|
||||
|
||||
if (fabs(dDet) < std::max(0.0001, adaptive_threshold))
|
||||
{
|
||||
path_copy.transform_all_paths(m_oFullTransform.m_internal->m_agg_mtx);
|
||||
dWidth *= sqrt(fabs(dDet));
|
||||
@ -2240,6 +2247,8 @@ namespace Aggplus
|
||||
LONG lCount2 = lCount / 2;
|
||||
|
||||
double dKoef = 1.0;
|
||||
if (bIsUseIdentity)
|
||||
dKoef = sqrt(fabs(m_oFullTransform.m_internal->m_agg_mtx.determinant()));
|
||||
|
||||
for (LONG i = 0; i < lCount2; ++i)
|
||||
{
|
||||
|
||||
@ -886,12 +886,12 @@ namespace Aggplus
|
||||
if (isCurve)
|
||||
{
|
||||
std::vector<PointD> points = GetPoints(idx, 4);
|
||||
area = 3.0 * (points[3].Y - points[0].Y) * (points[1].X + points[2].X)
|
||||
area = 3.0 * ((points[3].Y - points[0].Y) * (points[1].X + points[2].X)
|
||||
- (points[3].X - points[0].X) * (points[1].Y + points[2].Y)
|
||||
+ points[1].Y * (points[0].X - points[2].X)
|
||||
- points[1].X * (points[0].Y - points[2].Y)
|
||||
+ points[3].Y * (points[2].X + points[0].X / 3.0)
|
||||
- points[3].X * (points[2].Y + points[0].Y / 3.0) / 20.0;
|
||||
- points[3].X * (points[2].Y + points[0].Y / 3.0)) / 20.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1007,16 +1007,18 @@ namespace Aggplus
|
||||
bool CGraphicsPath::operator==(const CGraphicsPath& other) noexcept
|
||||
{
|
||||
unsigned pointsCount = GetPointCount(),
|
||||
otherPointsCount = other.GetPointCount();
|
||||
otherPointsCount = other.GetPointCount();
|
||||
|
||||
if (pointsCount != otherPointsCount)
|
||||
return false;
|
||||
|
||||
std::vector<PointD> points = GetPoints(0, pointsCount),
|
||||
otherPoints = other.GetPoints(0, otherPointsCount);
|
||||
otherPoints = other.GetPoints(0, otherPointsCount);
|
||||
|
||||
bool reverse = IsClockwise() ^ other.IsClockwise();
|
||||
|
||||
for (unsigned i = 0; i < pointsCount; i++)
|
||||
if (!points[i].Equals(otherPoints[i]))
|
||||
if (!points[i].Equals(otherPoints[reverse ? pointsCount - i - 1 : i]))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@ -1549,3 +1551,31 @@ namespace Aggplus
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
HRESULT IRenderer::AddPath(const Aggplus::CGraphicsPath& path)
|
||||
{
|
||||
if (path.GetPointCount() == 0)
|
||||
return S_FALSE;
|
||||
|
||||
size_t length = path.GetPointCount() + path.GetCloseCount();
|
||||
std::vector<Aggplus::PointD> points = path.GetPoints(0, length);
|
||||
|
||||
for (size_t i = 0; i < length; i++)
|
||||
{
|
||||
if (path.IsCurvePoint(i))
|
||||
{
|
||||
PathCommandCurveTo(points[i].X, points[i].Y,
|
||||
points[i + 1].X, points[i + 1].Y,
|
||||
points[i + 2].X, points[i + 2].Y);
|
||||
i += 2;
|
||||
}
|
||||
else if (path.IsMovePoint(i))
|
||||
PathCommandMoveTo(points[i].X, points[i].Y);
|
||||
else if (path.IsLinePoint(i))
|
||||
PathCommandLineTo(points[i].X, points[i].Y);
|
||||
else
|
||||
PathCommandClose();
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@ -613,6 +613,32 @@ HRESULT CGraphicsRenderer::put_BrushTransform(const Aggplus::CMatrix& oMatrix)
|
||||
m_oBrush.Transform = oMatrix;
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CGraphicsRenderer::get_BrushOffset(double& offsetX, double& offsetY) const
|
||||
{
|
||||
offsetX = m_oBrush.OffsetX;
|
||||
offsetY = m_oBrush.OffsetY;
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CGraphicsRenderer::put_BrushOffset(const double& offsetX, const double& offsetY)
|
||||
{
|
||||
m_oBrush.OffsetX = offsetX;
|
||||
m_oBrush.OffsetY = offsetY;
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CGraphicsRenderer::get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const
|
||||
{
|
||||
isScale = m_oBrush.IsScale;
|
||||
scaleX = m_oBrush.ScaleX;
|
||||
scaleY = m_oBrush.ScaleY;
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CGraphicsRenderer::put_BrushScale(bool isScale, const double& scaleX, const double& scaleY)
|
||||
{
|
||||
m_oBrush.IsScale = isScale;
|
||||
m_oBrush.ScaleX = scaleX;
|
||||
m_oBrush.ScaleY = scaleY;
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CGraphicsRenderer::BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height)
|
||||
{
|
||||
m_oBrush.Rectable = val;
|
||||
@ -946,11 +972,18 @@ HRESULT CGraphicsRenderer::DrawPath(const LONG& nType)
|
||||
switch (m_oBrush.TextureMode)
|
||||
{
|
||||
case c_BrushTextureModeTile:
|
||||
oMode = Aggplus::WrapModeTile;
|
||||
break;
|
||||
case c_BrushTextureModeTileCenter:
|
||||
oMode = Aggplus::WrapModeTile;
|
||||
break;
|
||||
case c_BrushTextureModeTileFlipX:
|
||||
oMode = Aggplus::WrapModeTileFlipX;
|
||||
break;
|
||||
case c_BrushTextureModeTileFlipY:
|
||||
oMode = Aggplus::WrapModeTileFlipY;
|
||||
break;
|
||||
case c_BrushTextureModeTileFlipXY:
|
||||
oMode = Aggplus::WrapModeTileFlipXY;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1023,11 +1056,18 @@ HRESULT CGraphicsRenderer::DrawPath(const LONG& nType)
|
||||
if (m_oBrush.Rectable == 1)
|
||||
{
|
||||
pTextureBrush->m_bUseBounds = true;
|
||||
pTextureBrush->m_oBounds.left = m_oBrush.Rect.X;
|
||||
pTextureBrush->m_oBounds.top = m_oBrush.Rect.Y;
|
||||
pTextureBrush->m_oBounds.left = m_oBrush.Rect.X + m_oBrush.OffsetX;
|
||||
pTextureBrush->m_oBounds.top = m_oBrush.Rect.Y + m_oBrush.OffsetY;
|
||||
pTextureBrush->m_oBounds.right = pTextureBrush->m_oBounds.left + m_oBrush.Rect.Width;
|
||||
pTextureBrush->m_oBounds.bottom = pTextureBrush->m_oBounds.top + m_oBrush.Rect.Height;
|
||||
}
|
||||
|
||||
if (m_oBrush.IsScale == 1)
|
||||
{
|
||||
pTextureBrush->m_bIsScale = true;
|
||||
pTextureBrush->m_dScaleX = m_oBrush.ScaleX;
|
||||
pTextureBrush->m_dScaleY = m_oBrush.ScaleY;
|
||||
}
|
||||
}
|
||||
|
||||
pBrush = pTextureBrush;
|
||||
|
||||
@ -189,6 +189,10 @@ public:
|
||||
virtual HRESULT put_BrushLinearAngle(const double& dAngle);
|
||||
virtual HRESULT get_BrushTransform(Aggplus::CMatrix& oMatrix);
|
||||
virtual HRESULT put_BrushTransform(const Aggplus::CMatrix& oMatrix);
|
||||
virtual HRESULT get_BrushOffset(double& offsetX, double& offsetY) const;
|
||||
virtual HRESULT put_BrushOffset(const double& offsetX, const double& offsetY);
|
||||
virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const;
|
||||
virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY);
|
||||
virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height);
|
||||
virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height);
|
||||
virtual HRESULT put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount);
|
||||
|
||||
@ -117,6 +117,7 @@ const long c_nDarkMode = 0x0008;
|
||||
const long c_nUseDictionaryFonts = 0x0010;
|
||||
const long c_nPenWidth0As1px = 0x0020;
|
||||
const long c_nSupportPathTextAsText = 0x0040;
|
||||
const long c_nFontSubstitution = 0x0080;
|
||||
|
||||
// типы рендерера
|
||||
const long c_nUnknownRenderer = 0x0000;
|
||||
@ -168,7 +169,10 @@ public:
|
||||
AdvancedCommandType GetCommandType() { return m_nCommandType; }
|
||||
};
|
||||
|
||||
namespace Aggplus { class CImage; }
|
||||
namespace Aggplus {
|
||||
class CImage;
|
||||
class CGraphicsPath;
|
||||
}
|
||||
|
||||
// IRenderer
|
||||
class IRenderer : public IGrObject
|
||||
@ -240,6 +244,32 @@ public:
|
||||
virtual HRESULT put_BrushTransform(const Aggplus::CMatrix& oMatrix) = 0;
|
||||
virtual HRESULT get_BrushLinearAngle(double* dAngle) = 0;
|
||||
virtual HRESULT put_BrushLinearAngle(const double& dAngle) = 0;
|
||||
virtual HRESULT get_BrushOffset(double& offsetX, double& offsetY) const
|
||||
{
|
||||
UNUSED_VARIABLE(offsetX);
|
||||
UNUSED_VARIABLE(offsetY);
|
||||
return S_OK;
|
||||
}
|
||||
virtual HRESULT put_BrushOffset(const double& offsetX, const double& offsetY)
|
||||
{
|
||||
UNUSED_VARIABLE(offsetX);
|
||||
UNUSED_VARIABLE(offsetY);
|
||||
return S_OK;
|
||||
}
|
||||
virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const
|
||||
{
|
||||
UNUSED_VARIABLE(isScale);
|
||||
UNUSED_VARIABLE(scaleX);
|
||||
UNUSED_VARIABLE(scaleY);
|
||||
return S_OK;
|
||||
}
|
||||
virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY)
|
||||
{
|
||||
UNUSED_VARIABLE(isScale);
|
||||
UNUSED_VARIABLE(scaleX);
|
||||
UNUSED_VARIABLE(scaleY);
|
||||
return S_OK;
|
||||
}
|
||||
virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height) = 0;
|
||||
virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height) = 0;
|
||||
|
||||
@ -299,6 +329,8 @@ public:
|
||||
virtual HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual HRESULT PathCommandTextEx(const std::wstring& sText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
|
||||
HRESULT AddPath(const Aggplus::CGraphicsPath& path);
|
||||
|
||||
//-------- Функции для вывода изображений ---------------------------------------------------
|
||||
virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual HRESULT DrawImageFromFile(const std::wstring&, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255) = 0;
|
||||
|
||||
@ -36,6 +36,7 @@
|
||||
#include "../fontengine/FontManager.h"
|
||||
#include "../raster/BgraFrame.h"
|
||||
#include "../common/StringExt.h"
|
||||
#include "GraphicsPath.h"
|
||||
|
||||
// этот класс нужно переписать. должно работать как и в js
|
||||
// а не просто на каждом символе переключаться, если нужно
|
||||
@ -351,7 +352,13 @@ namespace NSOnlineOfficeBinToPdf
|
||||
bool bIsPathOpened = false;
|
||||
bool bIsEnableBrushRect = false;
|
||||
|
||||
double old_t1, old_t2, old_t3, old_t4, old_t5, old_t6;
|
||||
|
||||
CBufferReader oReader(pBuffer, lBufferLen);
|
||||
Aggplus::CGraphicsPath path;
|
||||
Aggplus::CMatrix transMatrRot;
|
||||
Aggplus::RectF_T<double> clipRect;
|
||||
bool isResetRot = false;
|
||||
while (oReader.Check())
|
||||
{
|
||||
eCommand = (CommandType)(oReader.ReadByte());
|
||||
@ -382,6 +389,8 @@ namespace NSOnlineOfficeBinToPdf
|
||||
if (bIsPathOpened)
|
||||
{
|
||||
pRenderer->PathCommandEnd();
|
||||
if (path.GetPointCount())
|
||||
path.Reset();
|
||||
pRenderer->EndCommand(c_nPathType);
|
||||
}
|
||||
bIsPathOpened = false;
|
||||
@ -471,6 +480,16 @@ namespace NSOnlineOfficeBinToPdf
|
||||
double m2 = oReader.ReadDouble();
|
||||
double m3 = oReader.ReadDouble();
|
||||
double m4 = oReader.ReadDouble();
|
||||
|
||||
long type;
|
||||
pRenderer->get_BrushTextureMode(&type);
|
||||
if (type != c_BrushTextureModeStretch)
|
||||
{
|
||||
m1 = 0.0;
|
||||
m2 = 0.0;
|
||||
}
|
||||
|
||||
clipRect = Aggplus::RectF_T<double>(m1, m2, m3, m4);
|
||||
pRenderer->BrushRect(bIsEnableBrushRect ? 1 : 0, m1, m2, m3, m4);
|
||||
break;
|
||||
}
|
||||
@ -590,6 +609,16 @@ namespace NSOnlineOfficeBinToPdf
|
||||
pRenderer->put_BrushTextureAlpha(lAlpha);
|
||||
break;
|
||||
}
|
||||
case ctBrushResetRotation:
|
||||
{
|
||||
pRenderer->GetTransform(&old_t1, &old_t2, &old_t3, &old_t4, &old_t5, &old_t6);
|
||||
|
||||
Aggplus::CMatrix mtr(old_t1, old_t2, old_t3, old_t4, old_t5, old_t6);
|
||||
double rot = mtr.rotation();
|
||||
transMatrRot.Rotate(agg::rad2deg(rot));
|
||||
isResetRot = true;
|
||||
break;
|
||||
}
|
||||
case ctSetTransform:
|
||||
{
|
||||
double m1 = oReader.ReadDouble();
|
||||
@ -606,11 +635,15 @@ namespace NSOnlineOfficeBinToPdf
|
||||
if (bIsPathOpened)
|
||||
{
|
||||
pRenderer->PathCommandEnd();
|
||||
if (path.GetPointCount())
|
||||
path.Reset();
|
||||
pRenderer->EndCommand(c_nPathType);
|
||||
}
|
||||
|
||||
pRenderer->BeginCommand(c_nPathType);
|
||||
pRenderer->PathCommandStart();
|
||||
path.Reset();
|
||||
path.StartFigure();
|
||||
|
||||
bIsPathOpened = true;
|
||||
break;
|
||||
@ -619,14 +652,14 @@ namespace NSOnlineOfficeBinToPdf
|
||||
{
|
||||
double m1 = oReader.ReadDouble();
|
||||
double m2 = oReader.ReadDouble();
|
||||
pRenderer->PathCommandMoveTo(m1, m2);
|
||||
path.MoveTo(m1, m2);
|
||||
break;
|
||||
}
|
||||
case ctPathCommandLineTo:
|
||||
{
|
||||
double m1 = oReader.ReadDouble();
|
||||
double m2 = oReader.ReadDouble();
|
||||
pRenderer->PathCommandLineTo(m1, m2);
|
||||
path.LineTo(m1, m2);
|
||||
break;
|
||||
}
|
||||
case ctPathCommandCurveTo:
|
||||
@ -637,12 +670,12 @@ namespace NSOnlineOfficeBinToPdf
|
||||
double m4 = oReader.ReadDouble();
|
||||
double m5 = oReader.ReadDouble();
|
||||
double m6 = oReader.ReadDouble();
|
||||
pRenderer->PathCommandCurveTo(m1, m2, m3, m4, m5, m6);
|
||||
path.CurveTo(m1, m2, m3, m4, m5, m6);
|
||||
break;
|
||||
}
|
||||
case ctPathCommandClose:
|
||||
{
|
||||
pRenderer->PathCommandClose();
|
||||
path.CloseFigure();
|
||||
break;
|
||||
}
|
||||
case ctPathCommandEnd:
|
||||
@ -650,14 +683,108 @@ namespace NSOnlineOfficeBinToPdf
|
||||
if (bIsPathOpened)
|
||||
{
|
||||
pRenderer->PathCommandEnd();
|
||||
if (path.GetPointCount())
|
||||
path.Reset();
|
||||
pRenderer->EndCommand(c_nPathType);
|
||||
bIsPathOpened = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ctPathCommandOffset:
|
||||
{
|
||||
double m1 = oReader.ReadDouble();
|
||||
double m2 = oReader.ReadDouble();
|
||||
|
||||
pRenderer->put_BrushOffset(m1, m2);
|
||||
break;
|
||||
}
|
||||
case ctPathCommandScale:
|
||||
{
|
||||
double m1 = oReader.ReadDouble();
|
||||
double m2 = oReader.ReadDouble();
|
||||
|
||||
pRenderer->put_BrushScale(true, m1, m2);
|
||||
break;
|
||||
}
|
||||
case ctDrawPath:
|
||||
{
|
||||
pRenderer->DrawPath(oReader.ReadInt());
|
||||
long fill = oReader.ReadInt();
|
||||
long type;
|
||||
pRenderer->get_BrushType(&type);
|
||||
|
||||
if (fill != c_nStroke && type == c_BrushTypeTexture)
|
||||
{
|
||||
Aggplus::CGraphicsPath clipPath;
|
||||
Aggplus::CGraphicsPath drawPath(path);
|
||||
|
||||
if (isResetRot)
|
||||
{
|
||||
pRenderer->get_BrushTextureMode(&type);
|
||||
bool isStretch = type == c_BrushTextureModeStretch;
|
||||
|
||||
double left, top, width, height;
|
||||
drawPath.GetBounds(left, top, width, height);
|
||||
|
||||
double rot = transMatrRot.rotation();
|
||||
double cX = left + width / 2.0;
|
||||
double cY = top + height / 2.0;
|
||||
|
||||
bool isZeroPt = clipRect.X < 0.1 && clipRect.X > -0.1 && clipRect.Y < 0.1 && clipRect.Y > -0.1;
|
||||
bool isZeroRot = rot < 1e-6 && rot > -1e-6;
|
||||
|
||||
transMatrRot.Reset();
|
||||
transMatrRot.RotateAt(agg::rad2deg(rot), cX, cY, Aggplus::MatrixOrderAppend);
|
||||
|
||||
double offX = old_t5 - transMatrRot.tx();
|
||||
double offY = old_t6 - transMatrRot.ty();
|
||||
|
||||
drawPath.Transform(&transMatrRot);
|
||||
pRenderer->SetTransform(1.0, 0.0, 0.0, 1.0, offX, offY);
|
||||
|
||||
if (isZeroPt && !isZeroRot && isStretch)
|
||||
drawPath.GetBounds(left, top, width, height);
|
||||
else
|
||||
{
|
||||
Aggplus::CGraphicsPath tmpPath;
|
||||
tmpPath.AddRectangle(left, top, width, height);
|
||||
tmpPath.Transform(&transMatrRot);
|
||||
tmpPath.GetBounds(left, top, width, height);
|
||||
}
|
||||
|
||||
if (isZeroPt || !isStretch)
|
||||
clipRect = Aggplus::RectF_T<double>(left, top, width, height);
|
||||
|
||||
if (isStretch)
|
||||
{
|
||||
if (!isZeroPt)
|
||||
clipRect.Offset(-offX, -offY);
|
||||
pRenderer->BrushRect(true, clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
double tileOffX, tileOffY;
|
||||
pRenderer->get_BrushOffset(tileOffX, tileOffY);
|
||||
pRenderer->put_BrushOffset(tileOffX - offX, tileOffY - offY);
|
||||
}
|
||||
}
|
||||
|
||||
clipPath.AddRectangle(clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height);
|
||||
path = Aggplus::CalcBooleanOperation(drawPath, clipPath, Aggplus::Intersection);
|
||||
clipRect = Aggplus::RectF_T<double>();
|
||||
}
|
||||
|
||||
pRenderer->AddPath(path);
|
||||
pRenderer->DrawPath(fill);
|
||||
|
||||
if (isResetRot)
|
||||
{
|
||||
pRenderer->SetTransform(old_t1, old_t2, old_t3, old_t4, old_t5, old_t6);
|
||||
transMatrRot.Reset();
|
||||
isResetRot = false;
|
||||
}
|
||||
|
||||
pRenderer->put_BrushScale(false, 1.0, 1.0);
|
||||
pRenderer->put_BrushOffset(0.0, 0.0);
|
||||
break;
|
||||
}
|
||||
case ctDrawImageFromFile:
|
||||
@ -734,6 +861,8 @@ namespace NSOnlineOfficeBinToPdf
|
||||
if (bIsPathOpened)
|
||||
{
|
||||
pRenderer->PathCommandEnd();
|
||||
if (path.GetPointCount())
|
||||
path.Reset();
|
||||
pRenderer->EndCommand(4);
|
||||
bIsPathOpened = false;
|
||||
}
|
||||
@ -747,8 +876,13 @@ namespace NSOnlineOfficeBinToPdf
|
||||
pRenderer->EndCommand(4);
|
||||
bIsPathOpened = false;
|
||||
}
|
||||
pRenderer->EndCommand((DWORD)(oReader.ReadInt()));
|
||||
int nCommand = oReader.ReadInt();
|
||||
if (path.GetPointCount() && nCommand == c_nClipType)
|
||||
pRenderer->AddPath(path);
|
||||
pRenderer->EndCommand((DWORD)nCommand);
|
||||
pRenderer->PathCommandEnd();
|
||||
if (path.GetPointCount())
|
||||
path.Reset();
|
||||
break;
|
||||
}
|
||||
case ctGradientFill:
|
||||
@ -1132,6 +1266,10 @@ namespace NSOnlineOfficeBinToPdf
|
||||
oReader.Skip(1);
|
||||
break;
|
||||
}
|
||||
case ctBrushResetRotation:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case ctSetTransform:
|
||||
{
|
||||
oReader.SkipInt(6);
|
||||
@ -1164,6 +1302,16 @@ namespace NSOnlineOfficeBinToPdf
|
||||
{
|
||||
break;
|
||||
}
|
||||
case ctPathCommandOffset:
|
||||
{
|
||||
oReader.SkipInt(2);
|
||||
break;
|
||||
}
|
||||
case ctPathCommandScale:
|
||||
{
|
||||
oReader.SkipInt(2);
|
||||
break;
|
||||
}
|
||||
case ctDrawPath:
|
||||
{
|
||||
oReader.SkipInt();
|
||||
|
||||
@ -108,6 +108,7 @@ namespace NSOnlineOfficeBinToPdf
|
||||
ctBrushRectableEnabled = 30,
|
||||
ctBrushGradient = 31,
|
||||
ctBrushTexturePath = 32,
|
||||
ctBrushResetRotation = 33,
|
||||
|
||||
// font
|
||||
ctFontXML = 40,
|
||||
@ -153,6 +154,8 @@ namespace NSOnlineOfficeBinToPdf
|
||||
ctPathCommandGetCurrentPoint = 101,
|
||||
ctPathCommandText = 102,
|
||||
ctPathCommandTextEx = 103,
|
||||
ctPathCommandOffset = 104,
|
||||
ctPathCommandScale = 105,
|
||||
|
||||
// image
|
||||
ctDrawImage = 110,
|
||||
|
||||
@ -214,6 +214,18 @@ public:
|
||||
|
||||
inline bool IsPositive() { return Width > 0 && Height > 0; }
|
||||
|
||||
RectF_T& operator=(const RectF_T& other)
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
X = other.X;
|
||||
Y = other.Y;
|
||||
Width = other.Width;
|
||||
Height = other.Height;
|
||||
|
||||
return *this;
|
||||
};
|
||||
public:
|
||||
T X, Y, Width, Height;
|
||||
};
|
||||
|
||||
@ -46,6 +46,92 @@
|
||||
// void Set(const std::wstring& ws) { m_ws = ws; }
|
||||
// const std::wstring& Get() { return m_ws; }
|
||||
|
||||
CAnnotFieldInfo::CActionFieldPr* ReadAction(NSOnlineOfficeBinToPdf::CBufferReader* pReader)
|
||||
{
|
||||
CAnnotFieldInfo::CActionFieldPr* pRes = new CAnnotFieldInfo::CActionFieldPr();
|
||||
|
||||
pRes->nActionType = pReader->ReadByte();
|
||||
switch (pRes->nActionType)
|
||||
{
|
||||
case 14: // JavaScript
|
||||
{
|
||||
pRes->wsStr1 = pReader->ReadString();
|
||||
break;
|
||||
}
|
||||
case 1: // GoTo
|
||||
{
|
||||
pRes->nInt1 = pReader->ReadInt();
|
||||
pRes->nKind = pReader->ReadByte();
|
||||
switch (pRes->nKind)
|
||||
{
|
||||
case 0:
|
||||
case 2:
|
||||
case 3:
|
||||
case 6:
|
||||
case 7:
|
||||
{
|
||||
pRes->nFlags = pReader->ReadByte();
|
||||
if (pRes->nFlags & (1 << 0))
|
||||
pRes->dD[0] = pReader->ReadDouble();
|
||||
if (pRes->nFlags & (1 << 1))
|
||||
pRes->dD[1] = pReader->ReadDouble();
|
||||
if (pRes->nFlags & (1 << 2))
|
||||
pRes->dD[2] = pReader->ReadDouble();
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
pRes->dD[0] = pReader->ReadDouble();
|
||||
pRes->dD[1] = pReader->ReadDouble();
|
||||
pRes->dD[2] = pReader->ReadDouble();
|
||||
pRes->dD[3] = pReader->ReadDouble();
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
case 5:
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 10: // Named
|
||||
{
|
||||
pRes->wsStr1 = pReader->ReadString();
|
||||
break;
|
||||
}
|
||||
case 6: // URI
|
||||
{
|
||||
pRes->wsStr1 = pReader->ReadString();
|
||||
break;
|
||||
}
|
||||
case 9: // Hide
|
||||
{
|
||||
pRes->nKind = pReader->ReadByte();
|
||||
int n = pReader->ReadInt();
|
||||
pRes->arrStr.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
pRes->arrStr.push_back(pReader->ReadString());
|
||||
break;
|
||||
}
|
||||
case 12: // ResetForm
|
||||
{
|
||||
pRes->nInt1 = pReader->ReadInt();
|
||||
int n = pReader->ReadInt();
|
||||
pRes->arrStr.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
pRes->arrStr.push_back(pReader->ReadString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pReader->ReadByte())
|
||||
pRes->pNext = ReadAction(pReader);
|
||||
|
||||
return pRes;
|
||||
}
|
||||
|
||||
CAnnotFieldInfo::CAnnotFieldInfo() : IAdvancedCommand(AdvancedCommandType::Annotaion)
|
||||
{
|
||||
m_nType = EAnnotType::Unknown;
|
||||
@ -77,6 +163,7 @@ CAnnotFieldInfo::CAnnotFieldInfo() : IAdvancedCommand(AdvancedCommandType::Annot
|
||||
m_pCaretPr = NULL;
|
||||
m_pStampPr = NULL;
|
||||
m_pRedactPr = NULL;
|
||||
m_pLinkPr = NULL;
|
||||
m_pWidgetPr = NULL;
|
||||
}
|
||||
CAnnotFieldInfo::~CAnnotFieldInfo()
|
||||
@ -93,6 +180,7 @@ CAnnotFieldInfo::~CAnnotFieldInfo()
|
||||
RELEASEOBJECT(m_pCaretPr);
|
||||
RELEASEOBJECT(m_pStampPr);
|
||||
RELEASEOBJECT(m_pRedactPr);
|
||||
RELEASEOBJECT(m_pLinkPr);
|
||||
RELEASEOBJECT(m_pWidgetPr);
|
||||
}
|
||||
|
||||
@ -113,6 +201,12 @@ void CAnnotFieldInfo::SetType(int nType)
|
||||
m_pTextPr = new CAnnotFieldInfo::CTextAnnotPr();
|
||||
break;
|
||||
}
|
||||
case EAnnotType::Link:
|
||||
{
|
||||
RELEASEOBJECT(m_pLinkPr);
|
||||
m_pLinkPr = new CAnnotFieldInfo::CLinkAnnotPr();
|
||||
break;
|
||||
}
|
||||
case EAnnotType::FreeText:
|
||||
{
|
||||
CreateMarkup();
|
||||
@ -305,6 +399,10 @@ bool CAnnotFieldInfo::IsRedact() const
|
||||
{
|
||||
return (m_nType == 25);
|
||||
}
|
||||
bool CAnnotFieldInfo::IsLink() const
|
||||
{
|
||||
return (m_nType == 1);
|
||||
}
|
||||
|
||||
CAnnotFieldInfo::CMarkupAnnotPr* CAnnotFieldInfo::GetMarkupAnnotPr() { return m_pMarkupPr; }
|
||||
CAnnotFieldInfo::CTextAnnotPr* CAnnotFieldInfo::GetTextAnnotPr() { return m_pTextPr; }
|
||||
@ -318,6 +416,7 @@ CAnnotFieldInfo::CFreeTextAnnotPr* CAnnotFieldInfo::GetFreeTextAnnotPr()
|
||||
CAnnotFieldInfo::CCaretAnnotPr* CAnnotFieldInfo::GetCaretAnnotPr() { return m_pCaretPr; }
|
||||
CAnnotFieldInfo::CStampAnnotPr* CAnnotFieldInfo::GetStampAnnotPr() { return m_pStampPr; }
|
||||
CAnnotFieldInfo::CRedactAnnotPr* CAnnotFieldInfo::GetRedactAnnotPr() { return m_pRedactPr; }
|
||||
CAnnotFieldInfo::CLinkAnnotPr* CAnnotFieldInfo::GetLinkAnnotPr() { return m_pLinkPr; }
|
||||
CAnnotFieldInfo::CWidgetAnnotPr* CAnnotFieldInfo::GetWidgetAnnotPr() { return m_pWidgetPr; }
|
||||
|
||||
bool CAnnotFieldInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafileToRenderter* pCorrector)
|
||||
@ -412,6 +511,8 @@ bool CAnnotFieldInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMeta
|
||||
m_pPopupPr->Read(pReader);
|
||||
else if (IsWidget())
|
||||
m_pWidgetPr->Read(pReader, nType);
|
||||
else if (IsLink())
|
||||
m_pLinkPr->Read(pReader);
|
||||
|
||||
return m_nType != -1;
|
||||
}
|
||||
@ -721,6 +822,45 @@ void CAnnotFieldInfo::CRedactAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader
|
||||
}
|
||||
}
|
||||
|
||||
CAnnotFieldInfo::CLinkAnnotPr::CLinkAnnotPr()
|
||||
{
|
||||
m_pAction = NULL;
|
||||
m_pPA = NULL;
|
||||
}
|
||||
CAnnotFieldInfo::CLinkAnnotPr::~CLinkAnnotPr()
|
||||
{
|
||||
RELEASEOBJECT(m_pAction);
|
||||
RELEASEOBJECT(m_pPA);
|
||||
}
|
||||
BYTE CAnnotFieldInfo::CLinkAnnotPr::GetH() const { return m_nH; }
|
||||
int CAnnotFieldInfo::CLinkAnnotPr::GetFlags() const { return m_nFlags; }
|
||||
const std::vector<double>& CAnnotFieldInfo::CLinkAnnotPr::GetQuadPoints() { return m_arrQuadPoints; }
|
||||
CAnnotFieldInfo::CActionFieldPr* CAnnotFieldInfo::CLinkAnnotPr::GetA() { return m_pAction; }
|
||||
CAnnotFieldInfo::CActionFieldPr* CAnnotFieldInfo::CLinkAnnotPr::GetPA() { return m_pPA; }
|
||||
void CAnnotFieldInfo::CLinkAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader)
|
||||
{
|
||||
m_nFlags = pReader->ReadInt();
|
||||
if (m_nFlags & (1 << 0))
|
||||
{
|
||||
pReader->ReadString();
|
||||
m_pAction = ReadAction(pReader);
|
||||
}
|
||||
if (m_nFlags & (1 << 1))
|
||||
{
|
||||
pReader->ReadString();
|
||||
m_pPA = ReadAction(pReader);
|
||||
}
|
||||
if (m_nFlags & (1 << 2))
|
||||
m_nH = pReader->ReadByte();
|
||||
if (m_nFlags & (1 << 3))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrQuadPoints.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrQuadPoints.push_back(pReader->ReadDouble());
|
||||
}
|
||||
}
|
||||
|
||||
bool CAnnotFieldInfo::CPopupAnnotPr::IsOpen() const { return m_bOpen; }
|
||||
int CAnnotFieldInfo::CPopupAnnotPr::GetFlag() const { return m_nFlag; }
|
||||
int CAnnotFieldInfo::CPopupAnnotPr::GetParentID() const { return m_nParentID; }
|
||||
@ -752,7 +892,7 @@ const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::GetFontKey() { return m_w
|
||||
const std::vector<double>& CAnnotFieldInfo::CWidgetAnnotPr::GetTC() { return m_arrTC; }
|
||||
const std::vector<double>& CAnnotFieldInfo::CWidgetAnnotPr::GetBC() { return m_arrBC; }
|
||||
const std::vector<double>& CAnnotFieldInfo::CWidgetAnnotPr::GetBG() { return m_arrBG; }
|
||||
const std::vector<CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget*>& CAnnotFieldInfo::CWidgetAnnotPr::GetActions() { return m_arrAction; }
|
||||
const std::vector<CAnnotFieldInfo::CActionFieldPr*>& CAnnotFieldInfo::CWidgetAnnotPr::GetActions() { return m_arrAction; }
|
||||
CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr* CAnnotFieldInfo::CWidgetAnnotPr::GetButtonWidgetPr() { return m_pButtonPr; }
|
||||
CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr* CAnnotFieldInfo::CWidgetAnnotPr::GetTextWidgetPr() { return m_pTextPr; }
|
||||
CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr* CAnnotFieldInfo::CWidgetAnnotPr::GetChoiceWidgetPr() { return m_pChoicePr; }
|
||||
@ -812,93 +952,8 @@ CAnnotFieldInfo::CWidgetAnnotPr::~CWidgetAnnotPr()
|
||||
RELEASEOBJECT(m_arrAction[i]);
|
||||
}
|
||||
|
||||
CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget::CActionWidget() : pNext(NULL) {}
|
||||
CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget::~CActionWidget() { RELEASEOBJECT(pNext); }
|
||||
CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* ReadAction(NSOnlineOfficeBinToPdf::CBufferReader* pReader)
|
||||
{
|
||||
CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* pRes = new CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget();
|
||||
|
||||
pRes->nActionType = pReader->ReadByte();
|
||||
switch (pRes->nActionType)
|
||||
{
|
||||
case 14: // JavaScript
|
||||
{
|
||||
pRes->wsStr1 = pReader->ReadString();
|
||||
break;
|
||||
}
|
||||
case 1: // GoTo
|
||||
{
|
||||
pRes->nInt1 = pReader->ReadInt();
|
||||
pRes->nKind = pReader->ReadByte();
|
||||
switch (pRes->nKind)
|
||||
{
|
||||
case 0:
|
||||
case 2:
|
||||
case 3:
|
||||
case 6:
|
||||
case 7:
|
||||
{
|
||||
pRes->nFlags = pReader->ReadByte();
|
||||
if (pRes->nFlags & (1 << 0))
|
||||
pRes->dD[0] = pReader->ReadDouble();
|
||||
if (pRes->nFlags & (1 << 1))
|
||||
pRes->dD[1] = pReader->ReadDouble();
|
||||
if (pRes->nFlags & (1 << 2))
|
||||
pRes->dD[2] = pReader->ReadDouble();
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
pRes->dD[0] = pReader->ReadDouble();
|
||||
pRes->dD[1] = pReader->ReadDouble();
|
||||
pRes->dD[2] = pReader->ReadDouble();
|
||||
pRes->dD[3] = pReader->ReadDouble();
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
case 5:
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 10: // Named
|
||||
{
|
||||
pRes->wsStr1 = pReader->ReadString();
|
||||
break;
|
||||
}
|
||||
case 6: // URI
|
||||
{
|
||||
pRes->wsStr1 = pReader->ReadString();
|
||||
break;
|
||||
}
|
||||
case 9: // Hide
|
||||
{
|
||||
pRes->nKind = pReader->ReadByte();
|
||||
int n = pReader->ReadInt();
|
||||
pRes->arrStr.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
pRes->arrStr.push_back(pReader->ReadString());
|
||||
break;
|
||||
}
|
||||
case 12: // ResetForm
|
||||
{
|
||||
pRes->nInt1 = pReader->ReadInt();
|
||||
int n = pReader->ReadInt();
|
||||
pRes->arrStr.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
pRes->arrStr.push_back(pReader->ReadString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pReader->ReadByte())
|
||||
pRes->pNext = ReadAction(pReader);
|
||||
|
||||
return pRes;
|
||||
}
|
||||
CAnnotFieldInfo::CActionFieldPr::CActionFieldPr() : pNext(NULL) {}
|
||||
CAnnotFieldInfo::CActionFieldPr::~CActionFieldPr() { RELEASEOBJECT(pNext); }
|
||||
void CAnnotFieldInfo::CWidgetAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, BYTE nType)
|
||||
{
|
||||
m_wsFN = pReader->ReadString();
|
||||
@ -957,7 +1012,7 @@ void CAnnotFieldInfo::CWidgetAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader
|
||||
for (int i = 0; i < nAction; ++i)
|
||||
{
|
||||
std::wstring wsType = pReader->ReadString();
|
||||
CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* pA = ReadAction(pReader);
|
||||
CAnnotFieldInfo::CActionFieldPr* pA = ReadAction(pReader);
|
||||
if (pA)
|
||||
{
|
||||
pA->wsType = wsType;
|
||||
@ -987,6 +1042,7 @@ const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr::GetCA() {
|
||||
const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr::GetRC() { return m_wsRC; }
|
||||
const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr::GetAC() { return m_wsAC; }
|
||||
const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr::GetAP_N_Yes() { return m_wsAP_N_Yes; }
|
||||
const std::vector< std::pair<std::wstring, std::wstring> >& CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr::GetOpt() { return m_arrOpt; }
|
||||
void CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, BYTE nType, int nFlags)
|
||||
{
|
||||
if (nType == 27)
|
||||
@ -1027,6 +1083,17 @@ void CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr::Read(NSOnlineOfficeBinToP
|
||||
if (nFlags & (1 << 9))
|
||||
m_wsV = pReader->ReadString();
|
||||
m_nStyle = pReader->ReadByte();
|
||||
if (nFlags & (1 << 10))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrOpt.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
std::wstring s1 = pReader->ReadString();
|
||||
std::wstring s2 = pReader->ReadString();
|
||||
m_arrOpt.push_back(std::make_pair(s1, s2));
|
||||
}
|
||||
}
|
||||
if (nFlags & (1 << 14))
|
||||
m_wsAP_N_Yes = pReader->ReadString();
|
||||
}
|
||||
@ -1192,7 +1259,7 @@ bool CWidgetsInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafil
|
||||
for (int i = 0; i < nAction; ++i)
|
||||
{
|
||||
std::wstring wsType = pReader->ReadString();
|
||||
CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* pA = ReadAction(pReader);
|
||||
CAnnotFieldInfo::CActionFieldPr* pA = ReadAction(pReader);
|
||||
if (pA)
|
||||
{
|
||||
pA->wsType = wsType;
|
||||
|
||||
@ -70,6 +70,23 @@ public:
|
||||
WidgetSignature = 33
|
||||
};
|
||||
|
||||
class GRAPHICS_DECL CActionFieldPr
|
||||
{
|
||||
public:
|
||||
CActionFieldPr();
|
||||
~CActionFieldPr();
|
||||
|
||||
BYTE nKind;
|
||||
BYTE nFlags;
|
||||
BYTE nActionType;
|
||||
int nInt1;
|
||||
double dD[4]{};
|
||||
std::wstring wsType;
|
||||
std::wstring wsStr1;
|
||||
std::vector<std::wstring> arrStr;
|
||||
CActionFieldPr* pNext;
|
||||
};
|
||||
|
||||
class GRAPHICS_DECL CWidgetAnnotPr
|
||||
{
|
||||
public:
|
||||
@ -90,6 +107,7 @@ public:
|
||||
const std::wstring& GetRC();
|
||||
const std::wstring& GetAC();
|
||||
const std::wstring& GetAP_N_Yes();
|
||||
const std::vector< std::pair<std::wstring, std::wstring> >& GetOpt();
|
||||
|
||||
void Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, BYTE nType, int nFlags);
|
||||
|
||||
@ -108,6 +126,7 @@ public:
|
||||
std::wstring m_wsRC;
|
||||
std::wstring m_wsAC;
|
||||
std::wstring m_wsAP_N_Yes;
|
||||
std::vector< std::pair<std::wstring, std::wstring> > m_arrOpt;
|
||||
};
|
||||
|
||||
class GRAPHICS_DECL CTextWidgetPr
|
||||
@ -159,23 +178,6 @@ public:
|
||||
|
||||
};
|
||||
|
||||
class GRAPHICS_DECL CActionWidget
|
||||
{
|
||||
public:
|
||||
CActionWidget();
|
||||
~CActionWidget();
|
||||
|
||||
BYTE nKind;
|
||||
BYTE nFlags;
|
||||
BYTE nActionType;
|
||||
int nInt1;
|
||||
double dD[4]{};
|
||||
std::wstring wsType;
|
||||
std::wstring wsStr1;
|
||||
std::vector<std::wstring> arrStr;
|
||||
CActionWidget* pNext;
|
||||
};
|
||||
|
||||
CWidgetAnnotPr(BYTE nType);
|
||||
~CWidgetAnnotPr();
|
||||
|
||||
@ -199,7 +201,7 @@ public:
|
||||
const std::vector<double>& GetTC();
|
||||
const std::vector<double>& GetBC();
|
||||
const std::vector<double>& GetBG();
|
||||
const std::vector<CActionWidget*>& GetActions();
|
||||
const std::vector<CActionFieldPr*>& GetActions();
|
||||
|
||||
CButtonWidgetPr* GetButtonWidgetPr();
|
||||
CTextWidgetPr* GetTextWidgetPr();
|
||||
@ -229,7 +231,7 @@ public:
|
||||
std::vector<double> m_arrTC;
|
||||
std::vector<double> m_arrBC;
|
||||
std::vector<double> m_arrBG;
|
||||
std::vector<CActionWidget*> m_arrAction;
|
||||
std::vector<CActionFieldPr*> m_arrAction;
|
||||
|
||||
CButtonWidgetPr* m_pButtonPr;
|
||||
CTextWidgetPr* m_pTextPr;
|
||||
@ -389,7 +391,7 @@ public:
|
||||
{
|
||||
public:
|
||||
bool IsOpen() const;
|
||||
int GetFlag() const;
|
||||
int GetFlag() const;
|
||||
int GetParentID() const;
|
||||
|
||||
void Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader);
|
||||
@ -478,6 +480,28 @@ public:
|
||||
std::vector<double> m_arrQuadPoints;
|
||||
};
|
||||
|
||||
class GRAPHICS_DECL CLinkAnnotPr
|
||||
{
|
||||
public:
|
||||
CLinkAnnotPr();
|
||||
~CLinkAnnotPr();
|
||||
|
||||
BYTE GetH() const;
|
||||
int GetFlags() const;
|
||||
const std::vector<double>& GetQuadPoints();
|
||||
CActionFieldPr* GetA();
|
||||
CActionFieldPr* GetPA();
|
||||
|
||||
void Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader);
|
||||
|
||||
private:
|
||||
BYTE m_nH;
|
||||
int m_nFlags;
|
||||
std::vector<double> m_arrQuadPoints;
|
||||
CActionFieldPr* m_pAction;
|
||||
CActionFieldPr* m_pPA;
|
||||
};
|
||||
|
||||
CAnnotFieldInfo();
|
||||
virtual ~CAnnotFieldInfo();
|
||||
|
||||
@ -518,6 +542,7 @@ public:
|
||||
bool IsCaret() const;
|
||||
bool IsStamp() const;
|
||||
bool IsRedact() const;
|
||||
bool IsLink() const;
|
||||
|
||||
CMarkupAnnotPr* GetMarkupAnnotPr();
|
||||
CTextAnnotPr* GetTextAnnotPr();
|
||||
@ -531,6 +556,7 @@ public:
|
||||
CCaretAnnotPr* GetCaretAnnotPr();
|
||||
CStampAnnotPr* GetStampAnnotPr();
|
||||
CRedactAnnotPr* GetRedactAnnotPr();
|
||||
CLinkAnnotPr* GetLinkAnnotPr();
|
||||
CWidgetAnnotPr* GetWidgetAnnotPr();
|
||||
|
||||
bool Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafileToRenderter* pCorrector);
|
||||
@ -576,6 +602,7 @@ private:
|
||||
CCaretAnnotPr* m_pCaretPr;
|
||||
CStampAnnotPr* m_pStampPr;
|
||||
CRedactAnnotPr* m_pRedactPr;
|
||||
CLinkAnnotPr* m_pLinkPr;
|
||||
CWidgetAnnotPr* m_pWidgetPr;
|
||||
};
|
||||
|
||||
@ -610,7 +637,7 @@ public:
|
||||
std::wstring sTU;
|
||||
std::vector<int> arrI;
|
||||
std::vector<std::wstring> arrV;
|
||||
std::vector<CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget*> arrAction;
|
||||
std::vector<CAnnotFieldInfo::CActionFieldPr*> arrAction;
|
||||
std::vector< std::pair<std::wstring, std::wstring> > arrOpt;
|
||||
};
|
||||
|
||||
|
||||
@ -46,10 +46,12 @@
|
||||
"_InitializeFontsRanges",
|
||||
"_SetFontBinary",
|
||||
"_GetFontBinary",
|
||||
"_GetGIDByUnicode",
|
||||
"_IsFontBinaryExist",
|
||||
"_DestroyTextInfo",
|
||||
"_IsNeedCMap",
|
||||
"_SetCMapData",
|
||||
"_SetScanPageFonts",
|
||||
"_ScanPage",
|
||||
"_SplitPages",
|
||||
"_MergePages",
|
||||
@ -195,7 +197,7 @@
|
||||
},
|
||||
{
|
||||
"folder": "../../../../PdfFile/SrcReader/",
|
||||
"files": ["Adaptors.cpp", "GfxClip.cpp", "RendererOutputDev.cpp", "JPXStream2.cpp", "PdfAnnot.cpp"]
|
||||
"files": ["Adaptors.cpp", "GfxClip.cpp", "RendererOutputDev.cpp", "JPXStream2.cpp", "PdfAnnot.cpp", "PdfFont.cpp"]
|
||||
},
|
||||
{
|
||||
"folder": "../../../../PdfFile/SrcWriter/",
|
||||
|
||||
@ -639,6 +639,7 @@ SOURCES += \
|
||||
$$PDF_ROOT_DIR/SrcReader/Adaptors.cpp \
|
||||
$$PDF_ROOT_DIR/SrcReader/GfxClip.cpp \
|
||||
$$PDF_ROOT_DIR/SrcReader/PdfAnnot.cpp \
|
||||
$$PDF_ROOT_DIR/SrcReader/PdfFont.cpp \
|
||||
$$PDF_ROOT_DIR/Resources/BaseFonts.cpp \
|
||||
$$PDF_ROOT_DIR/Resources/CMapMemory/cmap_memory.cpp
|
||||
|
||||
@ -664,6 +665,7 @@ HEADERS +=\
|
||||
$$PDF_ROOT_DIR/SrcReader/MemoryUtils.h \
|
||||
$$PDF_ROOT_DIR/SrcReader/GfxClip.h \
|
||||
$$PDF_ROOT_DIR/SrcReader/FontsWasm.h \
|
||||
$$PDF_ROOT_DIR/SrcReader/PdfFont.h \
|
||||
$$PDF_ROOT_DIR/SrcReader/PdfAnnot.h
|
||||
|
||||
DEFINES += CRYPTOPP_DISABLE_ASM
|
||||
|
||||
@ -362,6 +362,11 @@ CFile.prototype["getFontByID"] = function(ID)
|
||||
return this._getFontByID(ID);
|
||||
};
|
||||
|
||||
CFile.prototype["getGIDByUnicode"] = function(ID)
|
||||
{
|
||||
return this._getGIDByUnicode(ID);
|
||||
};
|
||||
|
||||
CFile.prototype["setCMap"] = function(memoryBuffer)
|
||||
{
|
||||
if (!this.nativeFile)
|
||||
@ -421,9 +426,9 @@ function readAction(reader, rec, readDoubleFunc, readStringFunc)
|
||||
case 4:
|
||||
{
|
||||
rec["left"] = readDoubleFunc.call(reader);
|
||||
rec["bottom"] = readDoubleFunc.call(reader);
|
||||
rec["top"] = readDoubleFunc.call(reader);
|
||||
rec["right"] = readDoubleFunc.call(reader);
|
||||
rec["top"] = readDoubleFunc.call(reader);
|
||||
rec["bottom"] = readDoubleFunc.call(reader);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
@ -1035,6 +1040,37 @@ function readAnnotType(reader, rec, readDoubleFunc, readDouble2Func, readStringF
|
||||
rec["font"]["style"] = reader.readInt();
|
||||
}
|
||||
}
|
||||
// Link
|
||||
else if (rec["type"] == 1)
|
||||
{
|
||||
flags = reader.readInt();
|
||||
if (flags & (1 << 0))
|
||||
{
|
||||
rec["A"] = {};
|
||||
if (isRead)
|
||||
readStringFunc.call(reader);
|
||||
readAction(reader, rec["A"], readDoubleFunc, readStringFunc);
|
||||
}
|
||||
if (flags & (1 << 1))
|
||||
{
|
||||
rec["PA"] = {};
|
||||
if (isRead)
|
||||
readStringFunc.call(reader);
|
||||
readAction(reader, rec["PA"], readDoubleFunc, readStringFunc);
|
||||
}
|
||||
// Selection mode - H
|
||||
// 0 - none, 1 - invert, 2 - push, 3 - outline
|
||||
if (flags & (1 << 2))
|
||||
rec["highlight"] = reader.readByte();
|
||||
// QuadPoints
|
||||
if (flags & (1 << 3))
|
||||
{
|
||||
let n = reader.readInt();
|
||||
rec["QuadPoints"] = [];
|
||||
for (let i = 0; i < n; ++i)
|
||||
rec["QuadPoints"].push(readDoubleFunc.call(reader));
|
||||
}
|
||||
}
|
||||
}
|
||||
function readWidgetType(reader, rec, readDoubleFunc, readDouble2Func, readStringFunc, isRead = false)
|
||||
{
|
||||
@ -1179,6 +1215,20 @@ function readWidgetType(reader, rec, readDoubleFunc, readDouble2Func, readString
|
||||
rec["value"] = readStringFunc.call(reader);
|
||||
// 0 - check, 1 - cross, 2 - diamond, 3 - circle, 4 - star, 5 - square
|
||||
rec["style"] = reader.readByte();
|
||||
if (flags & (1 << 10))
|
||||
{
|
||||
let n = reader.readInt();
|
||||
rec["opt"] = [];
|
||||
for (let i = 0; i < n; ++i)
|
||||
{
|
||||
let opt1 = readStringFunc.call(reader);
|
||||
let opt2 = readStringFunc.call(reader);
|
||||
if (opt1 == "")
|
||||
rec["opt"].push(opt2);
|
||||
else
|
||||
rec["opt"].push([opt2, opt1]);
|
||||
}
|
||||
}
|
||||
if (flags & (1 << 14))
|
||||
rec["ExportValue"] = readStringFunc.call(reader);
|
||||
// 12.7.4.2.1
|
||||
@ -1656,6 +1706,11 @@ CFile.prototype["readAnnotationsInfoFromBinary"] = function(AnnotInfo)
|
||||
};
|
||||
|
||||
// SCAN PAGES
|
||||
CFile.prototype["scanPageFonts"] = function(page)
|
||||
{
|
||||
this._setScanPageFonts(page);
|
||||
};
|
||||
|
||||
CFile.prototype["scanPage"] = function(page, mode)
|
||||
{
|
||||
let ptr = this._scanPage(page, mode);
|
||||
|
||||
@ -172,6 +172,12 @@ CFile.prototype._getFontByID = function(ID)
|
||||
return g_native_drawing_file["GetFontBinary"](ID);
|
||||
};
|
||||
|
||||
CFile.prototype._getGIDByUnicode = function(ID)
|
||||
{
|
||||
g_module_pointer.ptr = g_native_drawing_file["GetGIDByUnicode"](ID);
|
||||
return g_module_pointer;
|
||||
}
|
||||
|
||||
CFile.prototype._getInteractiveFormsFonts = function(type)
|
||||
{
|
||||
g_module_pointer.ptr = g_native_drawing_file["GetInteractiveFormsFonts"](type);
|
||||
@ -246,6 +252,11 @@ CFile.prototype._getInteractiveFormsAP = function(width, height, backgroundColor
|
||||
};
|
||||
|
||||
// SCAN PAGES
|
||||
CFile.prototype._setScanPageFonts = function(page)
|
||||
{
|
||||
g_native_drawing_file["SetScanPageFonts"](page);
|
||||
};
|
||||
|
||||
CFile.prototype._scanPage = function(page, mode)
|
||||
{
|
||||
g_module_pointer.ptr = g_native_drawing_file["ScanPage"](page, (mode === undefined) ? 0 : mode);
|
||||
|
||||
@ -106,7 +106,7 @@ CFile.prototype._openFile = function(buffer, password)
|
||||
}
|
||||
|
||||
let passwordPtr = 0;
|
||||
if (password)
|
||||
if (password !== undefined)
|
||||
{
|
||||
let passwordBuf = password.toUtf8();
|
||||
passwordPtr = Module["_malloc"](passwordBuf.length);
|
||||
@ -227,7 +227,7 @@ CFile.prototype._UndoRedact = function()
|
||||
CFile.prototype._CheckOwnerPassword = function(password)
|
||||
{
|
||||
let passwordPtr = 0;
|
||||
if (password)
|
||||
if (password !== undefined)
|
||||
{
|
||||
let passwordBuf = password.toUtf8();
|
||||
passwordPtr = Module["_malloc"](passwordBuf.length);
|
||||
@ -286,6 +286,34 @@ CFile.prototype._getFontByID = function(ID)
|
||||
return res;
|
||||
};
|
||||
|
||||
CFile.prototype._getGIDByUnicode = function(ID)
|
||||
{
|
||||
if (ID === undefined)
|
||||
return null;
|
||||
|
||||
let idBuffer = ID.toUtf8();
|
||||
let idPointer = Module["_malloc"](idBuffer.length);
|
||||
Module["HEAP8"].set(idBuffer, idPointer);
|
||||
g_module_pointer.ptr = Module["_GetGIDByUnicode"](this.nativeFile, idPointer);
|
||||
Module["_free"](idPointer);
|
||||
|
||||
let reader = g_module_pointer.getReader();
|
||||
if (!reader)
|
||||
return null;
|
||||
|
||||
let res = {};
|
||||
let nFontLength = reader.readInt();
|
||||
for (let i = 0; i < nFontLength; i++)
|
||||
{
|
||||
let np1 = reader.readInt();
|
||||
let np2 = reader.readInt();
|
||||
res[np2] = np1;
|
||||
}
|
||||
|
||||
g_module_pointer.free();
|
||||
return res;
|
||||
}
|
||||
|
||||
CFile.prototype._getInteractiveFormsFonts = function(type)
|
||||
{
|
||||
g_module_pointer.ptr = Module["_GetInteractiveFormsFonts"](this.nativeFile, type);
|
||||
@ -360,6 +388,11 @@ CFile.prototype._getInteractiveFormsAP = function(width, height, backgroundColor
|
||||
};
|
||||
|
||||
// SCAN PAGES
|
||||
CFile.prototype._setScanPageFonts = function(page)
|
||||
{
|
||||
Module["_SetScanPageFonts"](this.nativeFile, page);
|
||||
};
|
||||
|
||||
CFile.prototype._scanPage = function(page, mode)
|
||||
{
|
||||
g_module_pointer.ptr = Module["_ScanPage"](this.nativeFile, page, (mode === undefined) ? 0 : mode);
|
||||
|
||||
@ -80,7 +80,7 @@ WASM_EXPORT CDrawingFile* Open(BYTE* data, LONG size, const char* password)
|
||||
std::wstring sPassword = L"";
|
||||
if (NULL != password)
|
||||
sPassword = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)password, strlen(password));
|
||||
pFile->OpenFile(data, size, sPassword);
|
||||
pFile->OpenFile(data, size, password ? sPassword.c_str() : NULL);
|
||||
return pFile;
|
||||
}
|
||||
WASM_EXPORT int GetType(CDrawingFile* pFile)
|
||||
@ -150,6 +150,10 @@ WASM_EXPORT BYTE* GetFontBinary(CDrawingFile* pFile, char* path)
|
||||
{
|
||||
return pFile->GetFontBinary(std::string(path));
|
||||
}
|
||||
WASM_EXPORT BYTE* GetGIDByUnicode(CDrawingFile* pFile, char* path)
|
||||
{
|
||||
return pFile->GetGIDByUnicode(std::string(path));
|
||||
}
|
||||
WASM_EXPORT void DestroyTextInfo(CDrawingFile* pFile)
|
||||
{
|
||||
return pFile->DestroyTextInfo();
|
||||
@ -162,6 +166,10 @@ WASM_EXPORT void SetCMapData(CDrawingFile* pFile, BYTE* data, int size)
|
||||
{
|
||||
pFile->SetCMapData(data, size);
|
||||
}
|
||||
WASM_EXPORT void SetScanPageFonts(CDrawingFile* pFile, int nPageIndex)
|
||||
{
|
||||
return pFile->SetScanPageFonts(nPageIndex);
|
||||
}
|
||||
WASM_EXPORT BYTE* ScanPage(CDrawingFile* pFile, int nPageIndex, int mode)
|
||||
{
|
||||
return pFile->ScanPage(nPageIndex, mode);
|
||||
@ -196,7 +204,7 @@ WASM_EXPORT int CheckOwnerPassword(CDrawingFile* pFile, const char* password)
|
||||
std::wstring sPassword = L"";
|
||||
if (NULL != password)
|
||||
sPassword = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)password, strlen(password));
|
||||
return pFile->CheckOwnerPassword(sPassword) ? 1 : 0;
|
||||
return pFile->CheckOwnerPassword(password ? sPassword.c_str() : NULL) ? 1 : 0;
|
||||
}
|
||||
WASM_EXPORT int CheckPerm(CDrawingFile* pFile, int nPermFlag)
|
||||
{
|
||||
|
||||
@ -704,6 +704,23 @@ void ReadInteractiveForms(BYTE* pWidgets, int& i)
|
||||
i += 1;
|
||||
std::cout << "Style " << arrStyle[nPathLength] << ", ";
|
||||
|
||||
if (nFlags & (1 << 10))
|
||||
{
|
||||
int nOptLength = READ_INT(pWidgets + i);
|
||||
i += 4;
|
||||
for (int j = 0; j < nOptLength; ++j)
|
||||
{
|
||||
nPathLength = READ_INT(pWidgets + i);
|
||||
i += 4;
|
||||
std::cout << std::to_string(j) << " Opt1 " << std::string((char*)(pWidgets + i), nPathLength) << ", ";
|
||||
i += nPathLength;
|
||||
|
||||
nPathLength = READ_INT(pWidgets + i);
|
||||
i += 4;
|
||||
std::cout << std::to_string(j) << " Opt2 " << std::string((char*)(pWidgets + i), nPathLength) << ", ";
|
||||
i += nPathLength;
|
||||
}
|
||||
}
|
||||
if (nFlags & (1 << 14))
|
||||
{
|
||||
nPathLength = READ_INT(pWidgets + i);
|
||||
@ -938,6 +955,36 @@ void ReadInteractiveFormsFonts(CDrawingFile* pGrFile, int nType)
|
||||
std::cout << "font" << j << ".txt";
|
||||
}
|
||||
|
||||
if (pFont)
|
||||
free(pFont);
|
||||
|
||||
if (false)
|
||||
continue;
|
||||
|
||||
pFont = GetGIDByUnicode(pGrFile, (char*)sFontName.c_str());
|
||||
nLength2 = READ_INT(pFont);
|
||||
i2 = 4;
|
||||
nLength2 -= 4;
|
||||
|
||||
while (i2 < nLength2)
|
||||
{
|
||||
int nFontLength = READ_INT(pFont + i2);
|
||||
i2 += 4;
|
||||
|
||||
std::cout << std::endl << "GIDtoUnicode" << std::endl;
|
||||
|
||||
for (int j = 0; j < nFontLength; ++j)
|
||||
{
|
||||
unsigned int code = READ_INT(pFont + i2);
|
||||
i2 += 4;
|
||||
unsigned int unicode = READ_INT(pFont + i2);
|
||||
i2 += 4;
|
||||
std::cout << "gid\t" << code << "\tunicode\t" << unicode << std::endl;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
if (pFont)
|
||||
free(pFont);
|
||||
}
|
||||
@ -1025,7 +1072,7 @@ int main(int argc, char* argv[])
|
||||
if (!NSFile::CFileBinary::ReadAllBytes(sFilePath, &pFileData, nFileDataLen))
|
||||
return 1;
|
||||
|
||||
CDrawingFile* pGrFile = Open(pFileData, (LONG)nFileDataLen, "");
|
||||
CDrawingFile* pGrFile = Open(pFileData, (LONG)nFileDataLen, NULL);
|
||||
int nError = GetErrorCode(pGrFile);
|
||||
|
||||
if (nError != 0)
|
||||
@ -1033,7 +1080,7 @@ int main(int argc, char* argv[])
|
||||
Close(pGrFile);
|
||||
if (nError == 4)
|
||||
{
|
||||
std::string sPassword = "123456";
|
||||
std::string sPassword = "";
|
||||
pGrFile = Open(pFileData, nFileDataLen, sPassword.c_str());
|
||||
}
|
||||
else
|
||||
@ -1053,7 +1100,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
if (true && GetFromBase64(NSFile::GetProcessDirectory() + L"/split.txt", &pBuffer, &nBufferLen))
|
||||
{
|
||||
std::vector<int> arrPages = { 2 };
|
||||
std::vector<int> arrPages = { 0 };
|
||||
BYTE* pSplitPages = SplitPages(pGrFile, arrPages.data(), arrPages.size(), pBuffer, nBufferLen);
|
||||
int nLength = READ_INT(pSplitPages);
|
||||
|
||||
@ -1128,7 +1175,7 @@ int main(int argc, char* argv[])
|
||||
// OWNER PASSWORD
|
||||
if (false)
|
||||
{
|
||||
std::string sPassword = "gfhjkmgfhjkm";
|
||||
std::string sPassword = "";
|
||||
std::cout << "CheckPerm 4 Edit " << CheckPerm(pGrFile, 4) << std::endl;
|
||||
std::cout << "CheckPerm 4 Print " << CheckPerm(pGrFile, 3) << std::endl;
|
||||
|
||||
@ -1137,26 +1184,26 @@ int main(int argc, char* argv[])
|
||||
std::cout << "CheckPerm 4 Print " << CheckPerm(pGrFile, 3) << std::endl;
|
||||
}
|
||||
|
||||
BYTE* pColor = new BYTE[12] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
// REDACT
|
||||
if (false)
|
||||
{
|
||||
BYTE* pColor = new BYTE[12] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
int pRect[8] = { 307499, 217499, 307499, 1124999, 1799999, 1124999, 1799999, 217499 };
|
||||
if (!RedactPage(pGrFile, nTestPage, pRect, 1, pColor, 12))
|
||||
std::cout << "Redact false" << std::endl;
|
||||
}
|
||||
|
||||
int i = nTestPage;
|
||||
//for (int i = 0; i < nPagesCount; ++i)
|
||||
// RASTER
|
||||
if (false)
|
||||
{
|
||||
// RASTER
|
||||
if (true)
|
||||
int i = nTestPage;
|
||||
//for (int i = 0; i < nPagesCount; ++i)
|
||||
{
|
||||
nWidth = READ_INT(pInfo + i * 16 + 12);
|
||||
nHeight = READ_INT(pInfo + i * 16 + 16);
|
||||
|
||||
//nWidth *= 3;
|
||||
//nHeight *= 3;
|
||||
//nWidth *= 2;
|
||||
//nHeight *= 2;
|
||||
|
||||
BYTE* res = NULL;
|
||||
res = GetPixmap(pGrFile, i, nWidth, nHeight, 0xFFFFFF);
|
||||
@ -1317,7 +1364,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
// INTERACTIVE FORMS
|
||||
if (true)
|
||||
if (false)
|
||||
{
|
||||
ReadInteractiveFormsFonts(pGrFile, 1);
|
||||
ReadInteractiveFormsFonts(pGrFile, 2);
|
||||
@ -1436,7 +1483,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
// ANNOTS
|
||||
if (true)
|
||||
if (false)
|
||||
{
|
||||
BYTE* pAnnots = GetAnnotationsInfo(pGrFile, -1);
|
||||
nLength = READ_INT(pAnnots);
|
||||
@ -2144,6 +2191,44 @@ int main(int argc, char* argv[])
|
||||
std::cout << nPathLength << ", ";
|
||||
}
|
||||
}
|
||||
else if (sType == "Link")
|
||||
{
|
||||
nFlags = READ_INT(pAnnots + i);
|
||||
i += 4;
|
||||
if (nFlags & (1 << 0))
|
||||
{
|
||||
std::cout << std::endl << "A ";
|
||||
ReadAction(pAnnots, i);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
if (nFlags & (1 << 1))
|
||||
{
|
||||
std::cout << std::endl << "PA ";
|
||||
ReadAction(pAnnots, i);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
if (nFlags & (1 << 2))
|
||||
{
|
||||
std::string arrHighlighting[] = {"none", "invert", "push", "outline"};
|
||||
nPathLength = READ_BYTE(pAnnots + i);
|
||||
i += 1;
|
||||
std::cout << "Highlight " << arrHighlighting[nPathLength] << ", ";
|
||||
}
|
||||
if (nFlags & (1 << 3))
|
||||
{
|
||||
std::cout << "QuadPoints";
|
||||
int nQuadPointsLength = READ_INT(pAnnots + i);
|
||||
i += 4;
|
||||
|
||||
for (int j = 0; j < nQuadPointsLength; ++j)
|
||||
{
|
||||
nPathLength = READ_INT(pAnnots + i);
|
||||
i += 4;
|
||||
std::cout << " " << (double)nPathLength / 100.0;
|
||||
}
|
||||
std::cout << ", ";
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << std::endl << "]" << std::endl;
|
||||
}
|
||||
@ -2166,12 +2251,13 @@ int main(int argc, char* argv[])
|
||||
free(pAnnotAP);
|
||||
}
|
||||
|
||||
// SCAN PAGE
|
||||
if (false)
|
||||
// SCAN PAGE Fonts
|
||||
if (true)
|
||||
{
|
||||
BYTE* pScan = ScanPage(pGrFile, nTestPage, 1);
|
||||
if (pScan)
|
||||
free(pScan);
|
||||
SetScanPageFonts(pGrFile, nTestPage);
|
||||
|
||||
ReadInteractiveFormsFonts(pGrFile, 1);
|
||||
ReadInteractiveFormsFonts(pGrFile, 2);
|
||||
}
|
||||
|
||||
Close(pGrFile);
|
||||
|
||||
@ -63,9 +63,9 @@ public:
|
||||
|
||||
// Open
|
||||
virtual bool LoadFromFile(const std::wstring& file, const std::wstring& options = L"",
|
||||
const std::wstring& owner_password = L"", const std::wstring& user_password = L"") = 0;
|
||||
const wchar_t* owner_password = NULL, const wchar_t* user_password = NULL) = 0;
|
||||
virtual bool LoadFromMemory(unsigned char* data, unsigned long length, const std::wstring& options = L"",
|
||||
const std::wstring& owner_password = L"", const std::wstring& user_password = L"") = 0;
|
||||
const wchar_t* owner_password = NULL, const wchar_t* user_password = NULL) = 0;
|
||||
|
||||
// Close
|
||||
virtual void Close() = 0;
|
||||
|
||||
@ -113,7 +113,10 @@ const long c_BrushTypeTensorCurveGradient = 6007;
|
||||
|
||||
const long c_BrushTextureModeStretch = 0;
|
||||
const long c_BrushTextureModeTile = 1;
|
||||
const long c_BrushTextureModeTileCenter = 2;
|
||||
const long c_BrushTextureModeTileFlipX = 2;
|
||||
const long c_BrushTextureModeTileFlipY = 3;
|
||||
const long c_BrushTextureModeTileFlipXY = 4;
|
||||
const long c_BrushTextureModeTileCenter = 5;
|
||||
// --------------------------------------------------------------
|
||||
|
||||
namespace Aggplus { class CImage; }
|
||||
@ -284,6 +287,13 @@ namespace NSStructures
|
||||
Aggplus::RectF Rect;
|
||||
Aggplus::CDoubleRect Bounds;
|
||||
|
||||
int IsScale;
|
||||
double ScaleX;
|
||||
double ScaleY;
|
||||
|
||||
double OffsetX;
|
||||
double OffsetY;
|
||||
|
||||
double LinearAngle;
|
||||
std::vector<TSubColor> m_arrSubColors;
|
||||
NSStructures::GradientInfo m_oGradientInfo;
|
||||
@ -415,6 +425,13 @@ namespace NSStructures
|
||||
Rect.Width = 0.0F;
|
||||
Rect.Height = 0.0F;
|
||||
|
||||
IsScale = FALSE;
|
||||
ScaleX = 1.0;
|
||||
ScaleY = 1.0;
|
||||
|
||||
OffsetX = 0.0;
|
||||
OffsetY = 0.0;
|
||||
|
||||
Bounds.left = 0;
|
||||
Bounds.top = 0;
|
||||
Bounds.right = 0;
|
||||
@ -454,6 +471,10 @@ namespace NSStructures
|
||||
Rect = other.Rect;
|
||||
Bounds = other.Bounds;
|
||||
|
||||
IsScale = other.IsScale;
|
||||
ScaleX = other.ScaleX;
|
||||
ScaleY = other.ScaleY;
|
||||
|
||||
LinearAngle = other.LinearAngle;
|
||||
m_arrSubColors = other.m_arrSubColors;
|
||||
m_oGradientInfo = other.m_oGradientInfo;
|
||||
|
||||
@ -8,8 +8,8 @@ namespace SVG
|
||||
: CObject(oReader), m_enUnits{EMarkerUnits::StrokeWidth}, m_enOrient{EMarkerOrient::Angle},
|
||||
m_dAngle(0.), m_oBounds{0., 0., 0., 0.}
|
||||
{
|
||||
m_oWindow.m_oWidth.SetValue(3);
|
||||
m_oWindow.m_oHeight.SetValue(3);
|
||||
m_oWindow.m_oWidth.SetValue(3, NSCSS::Pixel);
|
||||
m_oWindow.m_oHeight.SetValue(3, NSCSS::Pixel);
|
||||
}
|
||||
|
||||
ObjectType CMarker::GetType() const
|
||||
|
||||
@ -153,7 +153,7 @@ namespace SVG
|
||||
|
||||
bool CObject::ApplyClip(IRenderer *pRenderer, const TClip *pClip, const CSvgFile *pFile, const TBounds &oBounds) const
|
||||
{
|
||||
if (NULL == pRenderer || NULL == pClip || NULL == pFile || pClip->m_oHref.Empty() || NSCSS::NSProperties::ColorType::ColorUrl != pClip->m_oHref.GetType())
|
||||
if (NULL == pRenderer || NULL == pClip || NULL == pFile || pClip->m_oHref.Empty() || NSCSS::NSProperties::EColorType::ColorUrl != pClip->m_oHref.GetType())
|
||||
return false;
|
||||
|
||||
if (pClip->m_oRule == L"evenodd")
|
||||
@ -169,7 +169,7 @@ namespace SVG
|
||||
|
||||
bool CObject::ApplyMask(IRenderer *pRenderer, const NSCSS::NSProperties::CColor *pMask, const CSvgFile *pFile, const TBounds &oBounds) const
|
||||
{
|
||||
if (NULL == pRenderer || NULL == pMask || NULL == pFile || NSCSS::NSProperties::ColorType::ColorUrl != pMask->GetType())
|
||||
if (NULL == pRenderer || NULL == pMask || NULL == pFile || NSCSS::NSProperties::EColorType::ColorUrl != pMask->GetType())
|
||||
return false;
|
||||
|
||||
return ApplyDef(pRenderer, pFile, pMask->ToWString(), oBounds);
|
||||
@ -358,7 +358,7 @@ namespace SVG
|
||||
|
||||
bool CRenderedObject::ApplyStroke(IRenderer *pRenderer, const TStroke *pStroke, bool bUseDefault, const CRenderedObject* pContextObject) const
|
||||
{
|
||||
if (NULL == pRenderer || NULL == pStroke || NSCSS::NSProperties::ColorType::ColorNone == pStroke->m_oColor.GetType() || (!bUseDefault && ((pStroke->m_oWidth.Empty() || pStroke->m_oWidth.Zero()) && pStroke->m_oColor.Empty())))
|
||||
if (NULL == pRenderer || NULL == pStroke || pStroke->m_oColor.None() || (!bUseDefault && ((pStroke->m_oWidth.Empty() || pStroke->m_oWidth.Zero()) && pStroke->m_oColor.Empty())))
|
||||
{
|
||||
pRenderer->put_PenSize(0);
|
||||
return false;
|
||||
@ -369,12 +369,12 @@ namespace SVG
|
||||
if (Equals(0., dStrokeWidth))
|
||||
dStrokeWidth = 1.;
|
||||
|
||||
if (NSCSS::NSProperties::ColorType::ColorContextFill == pStroke->m_oColor.GetType() && NULL != pContextObject)
|
||||
if (NSCSS::NSProperties::EColorType::ColorContextFill == pStroke->m_oColor.GetType() && NULL != pContextObject)
|
||||
pRenderer->put_PenColor(pContextObject->m_oStyles.m_oFill.ToInt());
|
||||
else if (NSCSS::NSProperties::ColorType::ColorContextStroke == pStroke->m_oColor.GetType() && NULL != pContextObject)
|
||||
else if (NSCSS::NSProperties::EColorType::ColorContextStroke == pStroke->m_oColor.GetType() && NULL != pContextObject)
|
||||
pRenderer->put_PenColor(pContextObject->m_oStyles.m_oStroke.m_oColor.ToInt());
|
||||
else
|
||||
pRenderer->put_PenColor((pStroke->m_oColor.Empty() || NSCSS::NSProperties::ColorType::ColorNone == pStroke->m_oColor.GetType()) ? 0 : pStroke->m_oColor.ToInt());
|
||||
pRenderer->put_PenColor((pStroke->m_oColor.Empty() || NSCSS::NSProperties::EColorType::ColorNone == pStroke->m_oColor.GetType()) ? 0 : pStroke->m_oColor.ToInt());
|
||||
|
||||
pRenderer->put_PenSize(dStrokeWidth);
|
||||
pRenderer->put_PenAlpha(255. * pStroke->m_oColor.GetOpacity());
|
||||
@ -401,18 +401,18 @@ namespace SVG
|
||||
|
||||
bool CRenderedObject::ApplyFill(IRenderer *pRenderer, const NSCSS::NSProperties::CColor *pFill, const CSvgFile *pFile, bool bUseDefault, const CRenderedObject* pContextObject) const
|
||||
{
|
||||
if (NULL == pRenderer || NULL == pFill || NSCSS::NSProperties::ColorType::ColorNone == pFill->GetType() || (!bUseDefault && pFill->Empty()))
|
||||
if (NULL == pRenderer || NULL == pFill || pFill->None() || (!bUseDefault && pFill->Empty()))
|
||||
{
|
||||
pRenderer->put_BrushType(c_BrushTypeNoFill);
|
||||
return false;
|
||||
}
|
||||
else if (NSCSS::NSProperties::ColorType::ColorHEX == pFill->GetType() ||
|
||||
NSCSS::NSProperties::ColorType::ColorRGB == pFill->GetType())
|
||||
else if (NSCSS::NSProperties::EColorType::ColorHEX == pFill->GetType() ||
|
||||
NSCSS::NSProperties::EColorType::ColorRGB == pFill->GetType())
|
||||
{
|
||||
pRenderer->put_BrushColor1((pFill->Empty() && bUseDefault) ? 0 : pFill->ToInt());
|
||||
pRenderer->put_BrushType(c_BrushTypeSolid);
|
||||
}
|
||||
else if (NSCSS::NSProperties::ColorType::ColorUrl == pFill->GetType())
|
||||
else if (NSCSS::NSProperties::EColorType::ColorUrl == pFill->GetType())
|
||||
{
|
||||
if (!ApplyDef(pRenderer, pFile, pFill->ToWString(), GetBounds()))
|
||||
{
|
||||
@ -425,10 +425,16 @@ namespace SVG
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (NSCSS::NSProperties::ColorType::ColorContextFill == pFill->GetType() && NULL != pContextObject)
|
||||
pRenderer->put_BrushColor1(pContextObject->m_oStyles.m_oFill.ToInt());
|
||||
else if (NSCSS::NSProperties::ColorType::ColorContextStroke == pFill->GetType() && NULL != pContextObject)
|
||||
pRenderer->put_BrushColor1(pContextObject->m_oStyles.m_oStroke.m_oColor.ToInt());
|
||||
else if (NSCSS::NSProperties::EColorType::ColorContextFill == pFill->GetType() && NULL != pContextObject)
|
||||
{
|
||||
if (!ApplyFill(pRenderer, &pContextObject->m_oStyles.m_oFill, pFile, bUseDefault, pContextObject))
|
||||
return false;
|
||||
}
|
||||
else if (NSCSS::NSProperties::EColorType::ColorContextStroke == pFill->GetType() && NULL != pContextObject)
|
||||
{
|
||||
if (!ApplyFill(pRenderer, &pContextObject->m_oStyles.m_oStroke.m_oColor, pFile, bUseDefault, pContextObject))
|
||||
return false;
|
||||
}
|
||||
else if (bUseDefault)
|
||||
{
|
||||
pRenderer->put_BrushColor1(0);
|
||||
|
||||
@ -566,7 +566,7 @@ namespace SVG
|
||||
|
||||
#define CALCULATE_ANGLE(firstPoint, secondPoint) std::atan2(secondPoint.dY - firstPoint.dY, secondPoint.dX - firstPoint.dX) * 180. / M_PI
|
||||
|
||||
if (!m_oMarkers.m_oStart.Empty() && NSCSS::NSProperties::ColorType::ColorUrl == m_oMarkers.m_oStart.GetType())
|
||||
if (!m_oMarkers.m_oStart.Empty() && NSCSS::NSProperties::EColorType::ColorUrl == m_oMarkers.m_oStart.GetType())
|
||||
{
|
||||
CMarker *pStartMarker = dynamic_cast<CMarker*>(pFile->GetMarkedObject(m_oMarkers.m_oStart.ToWString()));
|
||||
|
||||
@ -610,7 +610,7 @@ namespace SVG
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_oMarkers.m_oMid.Empty() && NSCSS::NSProperties::ColorType::ColorUrl == m_oMarkers.m_oMid.GetType())
|
||||
if (!m_oMarkers.m_oMid.Empty() && NSCSS::NSProperties::EColorType::ColorUrl == m_oMarkers.m_oMid.GetType())
|
||||
{
|
||||
CMarker *pMidMarker = dynamic_cast<CMarker*>(pFile->GetMarkedObject(m_oMarkers.m_oMid.ToWString()));
|
||||
|
||||
@ -638,7 +638,7 @@ namespace SVG
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_oMarkers.m_oEnd.Empty() && NSCSS::NSProperties::ColorType::ColorUrl == m_oMarkers.m_oEnd.GetType())
|
||||
if (!m_oMarkers.m_oEnd.Empty() && NSCSS::NSProperties::EColorType::ColorUrl == m_oMarkers.m_oEnd.GetType())
|
||||
{
|
||||
CMarker *pEndMarker = dynamic_cast<CMarker*>(pFile->GetMarkedObject(m_oMarkers.m_oEnd.ToWString()));
|
||||
|
||||
|
||||
@ -110,6 +110,9 @@ namespace SVG
|
||||
if (mAttributes.end() != mAttributes.find(L"text-decoration"))
|
||||
m_oText.SetDecoration(mAttributes.at(L"text-decoration"), ushLevel, bHardMode);
|
||||
|
||||
if (mAttributes.end() != mAttributes.find(L"baseline-shift"))
|
||||
m_oText.SetBaselineShift(mAttributes.at(L"baseline-shift"), ushLevel, bHardMode);
|
||||
|
||||
//POSITION
|
||||
if (mAttributes.end() != mAttributes.find(L"rotate"))
|
||||
{
|
||||
@ -241,7 +244,27 @@ namespace SVG
|
||||
std::wstring wsFontFamily = DefaultFontFamily;
|
||||
double dFontSize = ((!m_oFont.GetSize().Empty()) ? m_oFont.GetSize().ToDouble(NSCSS::Pixel) : DEFAULT_FONT_SIZE) * 72. / 25.4;
|
||||
|
||||
Normalize(pRenderer, dX, dY, dFontSize, oOldMatrix);
|
||||
double dScaleX = 1., dScaleY = 1.;
|
||||
|
||||
NormalizeFontSize(dFontSize, dScaleX, dScaleY);
|
||||
|
||||
if (!Equals(1., dScaleX) || !Equals(1., dScaleY))
|
||||
{
|
||||
dX /= dScaleX;
|
||||
dY /= dScaleY;
|
||||
|
||||
double dM11, dM12, dM21, dM22, dDx, dDy;
|
||||
|
||||
pRenderer->GetTransform(&dM11, &dM12, &dM21, &dM22, &dDx, &dDy);
|
||||
|
||||
oOldMatrix.SetElements(dM11, dM12, dM21, dM22, dDx, dDy);
|
||||
|
||||
Aggplus::CMatrix oMatrix(dM11, dM12, dM21, dM22, dDx, dDy);
|
||||
|
||||
oMatrix.Scale(dScaleX, dScaleY);
|
||||
|
||||
pRenderer->SetTransform(oMatrix.sx(), oMatrix.shy(), oMatrix.shx(), oMatrix.sy(), oMatrix.tx(), oMatrix.ty());
|
||||
}
|
||||
|
||||
if (!m_oFont.GetFamily().Empty())
|
||||
{
|
||||
@ -271,12 +294,12 @@ namespace SVG
|
||||
m_pFontManager->LoadFontByName(wsFontFamily, dFontSize, nStyle, 72., 72.);
|
||||
m_pFontManager->SetCharSpacing(0);
|
||||
|
||||
double dKoef = 25.4 / 72.;
|
||||
const double dKoef = 25.4 / 72.;
|
||||
|
||||
NSFonts::IFontFile* pFontFile = m_pFontManager->GetFile();
|
||||
|
||||
if (pFontFile)
|
||||
dFHeight *= pFontFile->GetHeight() / pFontFile->Units_Per_Em() * dKoef;
|
||||
dFHeight *= pFontFile->GetHeight() / pFontFile->Units_Per_Em() * dKoef;
|
||||
|
||||
m_pFontManager->LoadString1(m_wsText, 0, 0);
|
||||
TBBox oBox = m_pFontManager->MeasureString2();
|
||||
@ -299,6 +322,45 @@ namespace SVG
|
||||
else if (L"center" == m_oText.GetAlign().ToWString())
|
||||
dX += -fW / 2;
|
||||
|
||||
if (NSCSS::NSProperties::EBaselineShift::Baseline != m_oText.GetBaselineShiftType())
|
||||
{
|
||||
switch(m_oText.GetBaselineShiftType())
|
||||
{
|
||||
case NSCSS::NSProperties::Sub:
|
||||
{
|
||||
dY += dFHeight / 2.;
|
||||
break;
|
||||
}
|
||||
case NSCSS::NSProperties::Super:
|
||||
{
|
||||
double dParentHeight{dFHeight};
|
||||
|
||||
if (nullptr != m_pParent)
|
||||
dParentHeight = ((CTSpan*)m_pParent)->GetFontHeight() / dScaleY;
|
||||
|
||||
dY -= dParentHeight - dFHeight / 2.;
|
||||
break;
|
||||
}
|
||||
case NSCSS::NSProperties::Percentage:
|
||||
{
|
||||
double dParentHeight{dFHeight};
|
||||
|
||||
if (nullptr != m_pParent)
|
||||
dParentHeight = ((CTSpan*)m_pParent)->GetFontHeight() / dScaleY;
|
||||
|
||||
dY -= dParentHeight * (m_oText.GetBaselineShiftValue() / 100.);
|
||||
break;
|
||||
}
|
||||
case NSCSS::NSProperties::Length:
|
||||
{
|
||||
dY -= m_oText.GetBaselineShiftValue() / dScaleY;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_oText.Underline() || m_oText.LineThrough() || m_oText.Overline())
|
||||
{
|
||||
pRenderer->put_PenSize((double)fUndSize);
|
||||
@ -389,7 +451,7 @@ namespace SVG
|
||||
oBounds.m_dRight = oBounds.m_dLeft + GetWidth();
|
||||
|
||||
oBounds.m_dBottom = m_oY.ToDouble(NSCSS::Pixel);
|
||||
oBounds.m_dTop = oBounds.m_dBottom + ((!m_oFont.GetSize().Empty()) ? m_oFont.GetSize().ToDouble(NSCSS::Pixel) : DEFAULT_FONT_SIZE);
|
||||
oBounds.m_dTop = oBounds.m_dBottom - ((!m_oFont.GetSize().Empty()) ? m_oFont.GetSize().ToDouble(NSCSS::Pixel) : DEFAULT_FONT_SIZE);
|
||||
|
||||
if (nullptr != pTransform)
|
||||
{
|
||||
@ -484,56 +546,33 @@ namespace SVG
|
||||
dY = m_oY.ToDouble(NSCSS::Pixel, oBounds.m_dBottom - oBounds.m_dTop);
|
||||
}
|
||||
|
||||
void CTSpan::Normalize(IRenderer *pRenderer, double &dX, double &dY, double &dFontHeight, Aggplus::CMatrix& oOldMatrix) const
|
||||
void CTSpan::NormalizeFontSize(double& dFontHeight, double& dScaleX, double& dScaleY) const
|
||||
{
|
||||
if (NULL == pRenderer)
|
||||
return;
|
||||
|
||||
Aggplus::CMatrix oCurrentMatrix(m_oTransformation.m_oTransform.GetMatrix().GetFinalValue());
|
||||
|
||||
double dXScale = 1., dYScale = 1.;
|
||||
|
||||
const double dModuleM11 = std::abs(oCurrentMatrix.sx());
|
||||
const double dModuleM22 = std::abs(oCurrentMatrix.sy());
|
||||
|
||||
if (!ISZERO(dModuleM11) && (dModuleM11 < MIN_SCALE || dModuleM11 > MAX_SCALE))
|
||||
dXScale /= dModuleM11;
|
||||
dScaleX /= dModuleM11;
|
||||
|
||||
if (!ISZERO(dModuleM22) && (dModuleM22 < MIN_SCALE || dModuleM22 > MAX_SCALE))
|
||||
dYScale /= dModuleM22;
|
||||
dScaleY /= dModuleM22;
|
||||
|
||||
dFontHeight *= dYScale;
|
||||
dFontHeight *= dScaleY;
|
||||
|
||||
if (!Equals(0., dFontHeight) && dFontHeight < MIN_FONT_SIZE)
|
||||
{
|
||||
dXScale *= MIN_FONT_SIZE / dFontHeight;
|
||||
dYScale *= MIN_FONT_SIZE / dFontHeight;
|
||||
dScaleX *= MIN_FONT_SIZE / dFontHeight;
|
||||
dScaleY *= MIN_FONT_SIZE / dFontHeight;
|
||||
dFontHeight = MIN_FONT_SIZE;
|
||||
}
|
||||
else if (!Equals(0., dFontHeight) && dFontHeight > MAX_FONT_SIZE)
|
||||
{
|
||||
dXScale *= dFontHeight / MAX_FONT_SIZE;
|
||||
dYScale *= dFontHeight / MAX_FONT_SIZE;
|
||||
dScaleX *= dFontHeight / MAX_FONT_SIZE;
|
||||
dScaleY *= dFontHeight / MAX_FONT_SIZE;
|
||||
dFontHeight = MAX_FONT_SIZE;
|
||||
}
|
||||
|
||||
if (Equals(1., dXScale) && Equals(1., dYScale))
|
||||
return;
|
||||
|
||||
dX /= dXScale;
|
||||
dY /= dYScale;
|
||||
|
||||
double dM11, dM12, dM21, dM22, dDx, dDy;
|
||||
|
||||
pRenderer->GetTransform(&dM11, &dM12, &dM21, &dM22, &dDx, &dDy);
|
||||
|
||||
oOldMatrix.SetElements(dM11, dM12, dM21, dM22, dDx, dDy);
|
||||
|
||||
Aggplus::CMatrix oMatrix(dM11, dM12, dM21, dM22, dDx, dDy);
|
||||
|
||||
oMatrix.Scale(dXScale, dYScale);
|
||||
|
||||
pRenderer->SetTransform(oMatrix.sx(), oMatrix.shy(), oMatrix.shx(), oMatrix.sy(), oMatrix.tx(), oMatrix.ty());
|
||||
}
|
||||
|
||||
void CTSpan::SetPosition(const Point &oPosition)
|
||||
@ -569,6 +608,40 @@ namespace SVG
|
||||
|
||||
}
|
||||
|
||||
double CTSpan::GetFontHeight() const
|
||||
{
|
||||
|
||||
if (NULL == m_pFontManager)
|
||||
return ((!m_oFont.GetSize().Empty()) ? m_oFont.GetSize().ToDouble(NSCSS::Pixel) : DEFAULT_FONT_SIZE) * 72. / 25.4;
|
||||
|
||||
std::wstring wsFontFamily = DefaultFontFamily;
|
||||
double dFontSize = ((!m_oFont.GetSize().Empty()) ? m_oFont.GetSize().ToDouble(NSCSS::Pixel) : DEFAULT_FONT_SIZE) * 72. / 25.4;
|
||||
|
||||
if (!m_oFont.GetFamily().Empty())
|
||||
{
|
||||
wsFontFamily = m_oFont.GetFamily().ToWString();
|
||||
CorrectFontFamily(wsFontFamily);
|
||||
}
|
||||
|
||||
int nStyle = 0;
|
||||
|
||||
if (m_oFont.GetWeight().ToWString() == L"bold")
|
||||
nStyle |= 0x01;
|
||||
if (m_oFont.GetStyle() .ToWString() == L"italic")
|
||||
nStyle |= 0x02;
|
||||
if (m_oText.Underline())
|
||||
nStyle |= (1 << 2);
|
||||
|
||||
// Вычиления размеров текста
|
||||
m_pFontManager->LoadFontByName(wsFontFamily, dFontSize, nStyle, 72., 72.);
|
||||
m_pFontManager->SetCharSpacing(0);
|
||||
|
||||
m_pFontManager->LoadString1(m_wsText, 0, 0);
|
||||
TBBox oBox = m_pFontManager->MeasureString2();
|
||||
|
||||
return (double)(25.4f / 72.f * (oBox.fMaxY - oBox.fMinY));
|
||||
}
|
||||
|
||||
std::vector<CTSpan> CTSpan::Split() const
|
||||
{
|
||||
std::vector<CTSpan> arGlyphs;
|
||||
|
||||
@ -44,11 +44,13 @@ namespace SVG
|
||||
|
||||
void CalculatePosition(double& dX, double& dY) const;
|
||||
|
||||
void Normalize(IRenderer* pRenderer, double& dX, double& dY, double& dFontHeight, Aggplus::CMatrix& oOldMatrix) const;
|
||||
void NormalizeFontSize(double& dFontHeight, double& dScaleX, double& dScaleY) const;
|
||||
void SetPosition(const Point& oPosition);
|
||||
|
||||
void SetPositionFromParent(CRenderedObject* pParent);
|
||||
|
||||
double GetFontHeight() const;
|
||||
|
||||
std::vector<CTSpan> Split() const;
|
||||
|
||||
NSFonts::IFontManager* m_pFontManager;
|
||||
|
||||
@ -72,11 +72,6 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
bool Sign(unsigned char* pData, unsigned int nSize, unsigned char*& pDataDst, unsigned int& nSizeDst)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string Sign(unsigned char* pData, unsigned int nSize)
|
||||
{
|
||||
NSOpenSSL::CMemoryData data = NSOpenSSL::Sign(pData, (int)nSize, m_pem_key);
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
#include <openssl/engine.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
@ -604,6 +605,12 @@ public:
|
||||
evp = EVP_sha512();
|
||||
else if (m_alg == OOXML_HASH_ALG_ECDSA_384)
|
||||
evp = EVP_sha384();
|
||||
else if (m_alg == OOXML_HASH_ALG_SHA256)
|
||||
evp = EVP_sha256();
|
||||
else if (m_alg == OOXML_HASH_ALG_SHA384)
|
||||
evp = EVP_sha384();
|
||||
else if (m_alg == OOXML_HASH_ALG_SHA512)
|
||||
evp = EVP_sha512();
|
||||
|
||||
if (!PKCS7_sign_add_signer(pkcs7, m_cert, m_key, evp, 0))
|
||||
{
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
import sys;
|
||||
sys.path.append("../../../../../../build_tools/scripts");
|
||||
import base;
|
||||
|
||||
base.replaceInFile("./deploy/engine.js", "__ATPOSTRUN__=[];", "__ATPOSTRUN__=[function(){window.cryptoJS.onLoad();}];");
|
||||
base.replaceInFile("./deploy/engine.js", "__ATPOSTRUN__ = [];", "__ATPOSTRUN__=[function(){window.cryptoJS.onLoad();}];");
|
||||
base.replaceInFile("./deploy/engine.js", "function getBinaryPromise()", "function getBinaryPromise2()");
|
||||
|
||||
base.replaceInFile("./deploy/engine_ie.js", "__ATPOSTRUN__=[];", "__ATPOSTRUN__=[function(){window.cryptoJS.onLoad();}];");
|
||||
base.replaceInFile("./deploy/engine_ie.js", "__ATPOSTRUN__ = [];", "__ATPOSTRUN__=[function(){window.cryptoJS.onLoad();}];");
|
||||
base.replaceInFile("./deploy/engine_ie.js", "function getBinaryPromise()", "function getBinaryPromise2()");
|
||||
|
||||
base.delete_file("./engine.wasm.js")
|
||||
@ -1,7 +0,0 @@
|
||||
import sys
|
||||
sys.path.append("../../../../../../build_tools/scripts")
|
||||
import base
|
||||
|
||||
base.cmd_in_dir("./../3rdParty", sys.executable, ["openssl.py"])
|
||||
|
||||
base.copy_file("./extension/engine.wasm.js", "./engine.wasm.js")
|
||||
@ -1,56 +0,0 @@
|
||||
{
|
||||
"name": "engine",
|
||||
"res_folder": "./deploy",
|
||||
"wasm": true,
|
||||
"asm": true,
|
||||
"embed_mem_file": true,
|
||||
"run_before": "before.py",
|
||||
"run_after": "after.py",
|
||||
"base_js_content": "./engine.wasm.js",
|
||||
|
||||
"compiler_flags": [
|
||||
"-O3",
|
||||
"-Wno-unused-command-line-argument",
|
||||
"-s ALLOW_MEMORY_GROWTH=1",
|
||||
"-s FILESYSTEM=0",
|
||||
"-s ENVIRONMENT='web'",
|
||||
"-s ASSERTIONS",
|
||||
"-s LLD_REPORT_UNDEFINED",
|
||||
"-s TOTAL_MEMORY=4MB"
|
||||
],
|
||||
"exported_functions": [
|
||||
"_malloc",
|
||||
"_free",
|
||||
"_Crypto_Malloc",
|
||||
"_Crypto_Free",
|
||||
"_Crypto_CreateKeys",
|
||||
"_Crypto_Sign",
|
||||
"_Crypto_ChangePassword",
|
||||
"_Crypto_Decrypt",
|
||||
"_Crypto_Encrypt"
|
||||
],
|
||||
"include_path": [
|
||||
"./../3rdParty/openssl/include", "./../3rdParty/openssl"
|
||||
],
|
||||
"define": [
|
||||
"__linux__", "_LINUX"
|
||||
],
|
||||
"compile_files_array": [
|
||||
{
|
||||
"name": "a",
|
||||
"folder": "../../../../common/",
|
||||
"files": ["Base64.cpp", "File.cpp"]
|
||||
},
|
||||
{
|
||||
"name": "b",
|
||||
"folder": "../../../../../Common/3dParty/openssl/common/",
|
||||
"files": ["common_openssl.cpp"]
|
||||
},
|
||||
{
|
||||
"name": "c",
|
||||
"folder": "./",
|
||||
"files": ["main.cpp"]
|
||||
}
|
||||
],
|
||||
"sources": ["./../3rdParty/openssl/libcrypto.a"]
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
QT -= core gui
|
||||
|
||||
TARGET = wasm
|
||||
TEMPLATE = app
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
DEFINES += TEST_AS_EXECUTABLE
|
||||
|
||||
CORE_ROOT_DIR = $$PWD/../../../../..
|
||||
PWD_ROOT_DIR = $$PWD
|
||||
include($$CORE_ROOT_DIR/Common/base.pri)
|
||||
|
||||
DEFINES += KERNEL_NO_USE_DYNAMIC_LIBRARY
|
||||
DEFINES += COMMON_OPENSSL_BUILDING_INTERNAL
|
||||
|
||||
SOURCES += \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/common/File.cpp \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/common/Base64.cpp
|
||||
|
||||
HEADERS += \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/include/Certificate.h \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/include/CertificateCommon.h
|
||||
|
||||
SOURCES += \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/src/CertificateCommon.cpp
|
||||
|
||||
DEFINES += SUPPORT_OFORM
|
||||
HEADERS += $$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/src/Certificate_oform.h
|
||||
|
||||
# OPENSSL
|
||||
CONFIG += open_ssl_common
|
||||
include($$CORE_ROOT_DIR/Common/3dParty/openssl/openssl.pri)
|
||||
|
||||
core_windows {
|
||||
LIBS += -lcrypt32
|
||||
LIBS += -lcryptui
|
||||
LIBS += -lAdvapi32
|
||||
LIBS += -lws2_32
|
||||
LIBS += -lUser32
|
||||
}
|
||||
|
||||
core_linux {
|
||||
LIBS += -ldl
|
||||
}
|
||||
|
||||
# WASM EXPORT
|
||||
SOURCES += main.cpp
|
||||
@ -1,24 +0,0 @@
|
||||
function KeyStorage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
console.log("reseived in background:", message);
|
||||
|
||||
// Отображение всплывающего окна
|
||||
chrome.action.openPopup();
|
||||
|
||||
// Посылаем событие обратно на страницу
|
||||
if (sender.tab) {
|
||||
chrome.scripting.executeScript({
|
||||
target: { tabId: sender.tab.id },
|
||||
func: (msg) => {
|
||||
document.dispatchEvent(new CustomEvent("customEventFromExtension", { detail: msg }));
|
||||
},
|
||||
args: [message]
|
||||
});
|
||||
}
|
||||
|
||||
sendResponse({ status: "received" });
|
||||
});
|
||||
@ -1,37 +0,0 @@
|
||||
function sendEventToPage(id, data) {
|
||||
document.dispatchEvent(new CustomEvent("olala", { detail: data }));
|
||||
}
|
||||
|
||||
var ENGINE_VERSION = 1;
|
||||
var ENGINE_MESSAGE_CHECK = "onlyoffice-engine-check";
|
||||
var ENGINE_MESSAGE_DATA = "onlyoffice-engine-data";
|
||||
|
||||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
if (message.action === "popupMessage") {
|
||||
console.log("Сообщение из popup:", message.text);
|
||||
|
||||
if (window.pluginEngine && window.pluginEngine.onMessageFromPlugin)
|
||||
window.pluginEngine.onMessageFromPlugin(message);
|
||||
|
||||
sendResponse({ status: "Сообщение получено!" });
|
||||
|
||||
sendEventToPage({ message: "Привет от content.js" });
|
||||
}
|
||||
});
|
||||
|
||||
// event from page with info about engine (is exist, version...)
|
||||
document.addEventListener(ENGINE_MESSAGE_CHECK + "-page", (event) => {
|
||||
document.dispatchEvent(new CustomEvent(ENGINE_MESSAGE_CHECK + "-content", { detail: { version : ENGINE_VERSION } }));
|
||||
});
|
||||
|
||||
// event from page with action (proxy to background)
|
||||
document.addEventListener(ENGINE_MESSAGE_DATA + "-page", (event) => {
|
||||
chrome.runtime.sendMessage({
|
||||
id : ENGINE_MESSAGE_DATA + "-engine",
|
||||
data : event.detail
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener(ENGINE_MESSAGE_DATA + "-engine", (event) => {
|
||||
document.dispatchEvent(new CustomEvent(ENGINE_MESSAGE_DATA + "-content", event.detail));
|
||||
});
|
||||
@ -1,31 +0,0 @@
|
||||
(function(window, undefined){
|
||||
|
||||
function Engine()
|
||||
{
|
||||
}
|
||||
|
||||
Engine.prototype.generateKeys = async function(alg, password, salt)
|
||||
{
|
||||
};
|
||||
|
||||
Engine.prototype.changePassword = async function(privateKey, passwordOld, passwordNew, salt)
|
||||
{
|
||||
};
|
||||
|
||||
Engine.prototype.sign = async function(privateKey, password, salt, xml)
|
||||
{
|
||||
};
|
||||
|
||||
// ENCRYPT
|
||||
Engine.prototype.decrypt = async function(privateKeyEnc, password, salt, data)
|
||||
{
|
||||
};
|
||||
|
||||
Engine.prototype.encrypt = async function(publicKey, data)
|
||||
{
|
||||
};
|
||||
|
||||
window.cryptoJS = new Engine();
|
||||
|
||||
})(window, undefined);
|
||||
|
||||
@ -1,223 +0,0 @@
|
||||
(function(window, undefined){
|
||||
WebAssembly.instantiateStreaming = undefined;
|
||||
|
||||
function MemoryData(ptr) {
|
||||
this.ptr = ptr;
|
||||
}
|
||||
MemoryData.prototype.isValid = function() {
|
||||
return (this.ptr === 0) ? false : true;
|
||||
};
|
||||
MemoryData.prototype.free = function() {
|
||||
if (0 != this.ptr)
|
||||
Module["_Crypto_Free"](this.ptr);
|
||||
};
|
||||
MemoryData.prototype.getData = function() {
|
||||
let lenArray = new Int32Array(Module["HEAP8"].buffer, this.ptr, 4);
|
||||
let len = lenArray[0];
|
||||
return new Uint8Array(Module["HEAP8"].buffer, this.ptr + 4, len);
|
||||
};
|
||||
|
||||
function StringPointer(pointer, len) {
|
||||
this.ptr = pointer;
|
||||
this.length = len;
|
||||
}
|
||||
StringPointer.prototype.free = function() {
|
||||
if (0 !== this.ptr)
|
||||
Module["_free"](this.ptr);
|
||||
};
|
||||
|
||||
String.prototype.toUtf8Pointer = function(isNoEndNull) {
|
||||
var tmp = this.toUtf8(isNoEndNull, true);
|
||||
var pointer = Module["_malloc"](tmp.length);
|
||||
if (0 == pointer)
|
||||
return null;
|
||||
|
||||
Module["HEAP8"].set(tmp, pointer);
|
||||
return new StringPointer(pointer,tmp.length);
|
||||
};
|
||||
|
||||
function typedArrayToMemory(data)
|
||||
{
|
||||
var pointer = Module["_malloc"](data.length);
|
||||
Module["HEAP8"].set(data, langBuffer);
|
||||
return pointer;
|
||||
}
|
||||
|
||||
function Engine()
|
||||
{
|
||||
this.isInit = false;
|
||||
this.waitResolvers = [];
|
||||
}
|
||||
|
||||
Engine.prototype.onLoad = function()
|
||||
{
|
||||
this.isInit = true;
|
||||
|
||||
for (let i = 0, len = this.waitResolvers.length; i < len; i++)
|
||||
this.waitResolvers[i]();
|
||||
|
||||
this.waitResolvers = [];
|
||||
};
|
||||
|
||||
Engine.prototype.init = async function()
|
||||
{
|
||||
if (this.isInit)
|
||||
return;
|
||||
|
||||
return new Promise(resolve => (function(){
|
||||
window.CryptoJS.waitResolvers.push(resolve);
|
||||
})());
|
||||
};
|
||||
|
||||
// SIGN
|
||||
Engine.prototype.generateKeys = async function(alg, password, salt)
|
||||
{
|
||||
await this.init();
|
||||
|
||||
if (!salt)
|
||||
salt = window.UtilsJS.toBase64(window.UtilsJS.random(32));
|
||||
|
||||
let algPtr = "ed25519".toUtf8Pointer();
|
||||
let passwordPtr = password.toUtf8Pointer();
|
||||
let saltPtr = salt.toUtf8Pointer();
|
||||
|
||||
let keys = Module["_Crypto_CreateKeys"](algPtr.ptr, passwordPtr.ptr, saltPtr.ptr);
|
||||
|
||||
algPtr.free();
|
||||
passwordPtr.free();
|
||||
saltPtr.free();
|
||||
|
||||
if (keys === 0)
|
||||
return null;
|
||||
|
||||
let heap = Module["HEAP8"];
|
||||
|
||||
let currentStart = keys;
|
||||
let currentEnd = currentStart;
|
||||
while (heap[currentEnd] != 0)
|
||||
currentEnd++;
|
||||
let publicKey = "".fromUtf8(heap, currentStart, currentEnd - currentStart);
|
||||
|
||||
currentStart = currentEnd + 1;
|
||||
currentEnd = currentStart;
|
||||
while (heap[currentEnd] != 0)
|
||||
currentEnd++;
|
||||
let privateKey = "".fromUtf8(heap, currentStart, currentEnd - currentStart);
|
||||
|
||||
Module["_Crypto_Free"](keys);
|
||||
|
||||
return {
|
||||
"salt": salt,
|
||||
"privateKey": privateKey,
|
||||
"publicKey": publicKey
|
||||
};
|
||||
};
|
||||
|
||||
Engine.prototype.changePassword = async function(privateKey, passwordOld, passwordNew, salt)
|
||||
{
|
||||
await this.init();
|
||||
|
||||
let privateKeyPtr = privateKey.toUtf8Pointer();
|
||||
let passwordOldPtr = passwordOld.toUtf8Pointer();
|
||||
let passwordNewPtr = passwordNew.toUtf8Pointer();
|
||||
let saltPtr = salt.toUtf8Pointer();
|
||||
|
||||
let privateKeyEnc = Module["_Crypto_ChangePassword"](privateKeyPtr.ptr, passwordOldPtr.ptr, passwordNewPtr.ptr, saltPtr.ptr);
|
||||
|
||||
privateKeyPtr.free();
|
||||
passwordOldPtr.free();
|
||||
passwordNewPtr.free();
|
||||
saltPtr.free();
|
||||
|
||||
if (privateKeyEnc === 0)
|
||||
return null;
|
||||
|
||||
let heap = Module["HEAP8"];
|
||||
|
||||
let currentStart = privateKeyEnc;
|
||||
let currentEnd = currentStart;
|
||||
while (heap[currentEnd] != 0)
|
||||
currentEnd++;
|
||||
|
||||
let privateKeyString = "".fromUtf8(heap, currentStart, currentEnd - currentStart);
|
||||
|
||||
Module["_Crypto_Free"](privateKeyEnc);
|
||||
return privateKeyString;
|
||||
};
|
||||
|
||||
Engine.prototype.sign = async function(privateKey, password, salt, xml)
|
||||
{
|
||||
await this.init();
|
||||
|
||||
let privateKeyPtr = privateKey.toUtf8Pointer();
|
||||
let passwordPtr = password.toUtf8Pointer();
|
||||
let saltPtr = salt.toUtf8Pointer();
|
||||
let xmlPtr = xml.toUtf8Pointer();
|
||||
|
||||
let signData = Module["_Crypto_Sign"](privateKeyPtr.ptr, passwordPtr.ptr, saltPtr.ptr, xmlPtr.ptr, xmlPtr.length);
|
||||
|
||||
privateKeyPtr.free();
|
||||
passwordPtr.free();
|
||||
saltPtr.free();
|
||||
xmlPtr.free();
|
||||
|
||||
if (signData === 0)
|
||||
return null;
|
||||
|
||||
let heap = Module["HEAP8"];
|
||||
|
||||
let currentStart = signData;
|
||||
let currentEnd = currentStart;
|
||||
while (heap[currentEnd] != 0)
|
||||
currentEnd++;
|
||||
|
||||
let signString = "".fromUtf8(heap, currentStart, currentEnd - currentStart);
|
||||
|
||||
Module["_Crypto_Free"](signData);
|
||||
return signString;
|
||||
};
|
||||
|
||||
// ENCRYPT
|
||||
Engine.prototype.decrypt = async function(privateKeyEnc, password, salt, data)
|
||||
{
|
||||
await this.init();
|
||||
|
||||
let privateKeyEncPtr = privateKeyEnc.toUtf8Pointer();
|
||||
let passwordPtr = password.toUtf8Pointer();
|
||||
let saltPtr = salt.toUtf8Pointer();
|
||||
|
||||
let dataPtr = typedArrayToMemory(data);
|
||||
|
||||
let decryptData = Module["_Crypto_Decrypt"](privateKeyEncPtr, passwordPtr, saltPtr.ptr, dataPtr, data.length);
|
||||
let memoryData = new CMemoryData(decryptData);
|
||||
|
||||
privateKeyEncPtr.free();
|
||||
passwordPtr.free();
|
||||
saltPtr.free();
|
||||
|
||||
Module["_free"](dataPtr);
|
||||
|
||||
return memoryData;
|
||||
};
|
||||
|
||||
Engine.prototype.encrypt = async function(publicKey, data)
|
||||
{
|
||||
await this.init();
|
||||
|
||||
let publicKeyEncPtr = publicKey.toUtf8Pointer();
|
||||
let dataPtr = typedArrayToMemory(data);
|
||||
|
||||
let encryptData = Module["_Crypto_Encrypt"](publicKeyEncPtr, dataPtr, data.length);
|
||||
let memoryData = new CMemoryData(decryptData);
|
||||
|
||||
publicKeyEncPtr.free();
|
||||
Module["_free"](dataPtr);
|
||||
|
||||
return memoryData;
|
||||
};
|
||||
|
||||
window.cryptoJS = new Engine();
|
||||
|
||||
//module
|
||||
|
||||
});
|
||||
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 999 B |
|
Before Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 8.4 KiB |
@ -1,43 +0,0 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "ONLYOFFICE Keychain",
|
||||
"version": "1.0",
|
||||
"permissions": ["tabs", "scripting"],
|
||||
"icons": {
|
||||
"16": "icons/icon16.png",
|
||||
"32": "icons/icon32.png",
|
||||
"48": "icons/icon48.png",
|
||||
"64": "icons/icon64.png",
|
||||
"128": "icons/icon128.png"
|
||||
},
|
||||
"background": {
|
||||
"service_worker": "background.js"
|
||||
},
|
||||
"host_permissions": ["<all_urls>"],
|
||||
"action": {
|
||||
"default_icon": {
|
||||
"16": "icons/icon16.png",
|
||||
"32": "icons/icon32.png",
|
||||
"48": "icons/icon48.png",
|
||||
"64": "icons/icon64.png",
|
||||
"128": "icons/icon128.png"
|
||||
},
|
||||
"default_popup": "popup.html"
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["<all_urls>"],
|
||||
"js": ["content.js"]
|
||||
}
|
||||
],
|
||||
"web_accessible_resources": [
|
||||
{
|
||||
"resources": ["engine.wasm"],
|
||||
"matches": ["<all_urls>"]
|
||||
}
|
||||
],
|
||||
"content_security_policy": {
|
||||
"extension_pages" : "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Popup</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Сообщение получено!</h2>
|
||||
<div id="message"></div>
|
||||
<button id="testButton">buttton</button>
|
||||
<script src="popup.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,17 +0,0 @@
|
||||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
document.getElementById("message").innerText = JSON.stringify(message);
|
||||
});
|
||||
|
||||
document.addEventListener("DOMContentLoaded", (event) => {
|
||||
|
||||
document.getElementById("testButton").onclick = function(e) {
|
||||
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
||||
if (tabs.length === 0) return;
|
||||
|
||||
chrome.tabs.sendMessage(tabs[0].id, { action: "popupMessage", text: "Привет от Popup!" }, (response) => {
|
||||
console.log("Ответ от контентного скрипта:", response);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
@ -1,22 +0,0 @@
|
||||
import sys
|
||||
sys.path.append("../../../../../../../build_tools/scripts")
|
||||
import base
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description='Generate background script for debug')
|
||||
|
||||
parser.add_argument("--wasm", action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
content = base.readFile("./utils.js") + "\n\n"
|
||||
|
||||
if args.wasm:
|
||||
content = content + "\n\n" + base.readFile("./../deploy/engine.js")
|
||||
base.copy_file("./../deploy/engine.wasm", "./engine.wasm")
|
||||
else:
|
||||
content = content + "\n\n" + base.readFile("./engine.js")
|
||||
|
||||
content = content + "\n\n" + base.readFile("./background_base.js")
|
||||
|
||||
base.delete_file("./background.js")
|
||||
base.writeFile("./background.js", content)
|
||||
@ -1,334 +0,0 @@
|
||||
(function(window, undefined) {
|
||||
if (undefined !== String.prototype.fromUtf8 && undefined !== String.prototype.toUtf8)
|
||||
return;
|
||||
|
||||
var STRING_UTF8_BUFFER_LENGTH = 1024;
|
||||
var STRING_UTF8_BUFFER = new ArrayBuffer(STRING_UTF8_BUFFER_LENGTH);
|
||||
|
||||
/**
|
||||
* Read string from utf8
|
||||
* @param {Uint8Array} buffer
|
||||
* @param {number} [start=0]
|
||||
* @param {number} [len]
|
||||
* @returns {string}
|
||||
*/
|
||||
String.prototype.fromUtf8 = function(buffer, start, len) {
|
||||
if (undefined === start)
|
||||
start = 0;
|
||||
if (undefined === len)
|
||||
len = buffer.length - start;
|
||||
|
||||
var result = "";
|
||||
var index = start;
|
||||
var end = start + len;
|
||||
while (index < end) {
|
||||
var u0 = buffer[index++];
|
||||
if (!(u0 & 128)) {
|
||||
result += String.fromCharCode(u0);
|
||||
continue;
|
||||
}
|
||||
var u1 = buffer[index++] & 63;
|
||||
if ((u0 & 224) == 192) {
|
||||
result += String.fromCharCode((u0 & 31) << 6 | u1);
|
||||
continue;
|
||||
}
|
||||
var u2 = buffer[index++] & 63;
|
||||
if ((u0 & 240) == 224)
|
||||
u0 = (u0 & 15) << 12 | u1 << 6 | u2;
|
||||
else
|
||||
u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | buffer[index++] & 63;
|
||||
if (u0 < 65536)
|
||||
result += String.fromCharCode(u0);
|
||||
else {
|
||||
var ch = u0 - 65536;
|
||||
result += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert string to utf8 array
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
String.prototype.toUtf8 = function(isNoEndNull, isUseBuffer) {
|
||||
var inputLen = this.length;
|
||||
var testLen = 6 * inputLen + 1;
|
||||
var tmpStrings = (isUseBuffer && testLen < STRING_UTF8_BUFFER_LENGTH) ? STRING_UTF8_BUFFER : new ArrayBuffer(testLen);
|
||||
|
||||
var code = 0;
|
||||
var index = 0;
|
||||
|
||||
var outputIndex = 0;
|
||||
var outputDataTmp = new Uint8Array(tmpStrings);
|
||||
var outputData = outputDataTmp;
|
||||
|
||||
while (index < inputLen) {
|
||||
code = this.charCodeAt(index++);
|
||||
if (code >= 0xD800 && code <= 0xDFFF && index < inputLen)
|
||||
code = 0x10000 + (((code & 0x3FF) << 10) | (0x03FF & this.charCodeAt(index++)));
|
||||
|
||||
if (code < 0x80)
|
||||
outputData[outputIndex++] = code;
|
||||
else if (code < 0x0800) {
|
||||
outputData[outputIndex++] = 0xC0 | (code >> 6);
|
||||
outputData[outputIndex++] = 0x80 | (code & 0x3F);
|
||||
} else if (code < 0x10000) {
|
||||
outputData[outputIndex++] = 0xE0 | (code >> 12);
|
||||
outputData[outputIndex++] = 0x80 | ((code >> 6) & 0x3F);
|
||||
outputData[outputIndex++] = 0x80 | (code & 0x3F);
|
||||
} else if (code < 0x1FFFFF) {
|
||||
outputData[outputIndex++] = 0xF0 | (code >> 18);
|
||||
outputData[outputIndex++] = 0x80 | ((code >> 12) & 0x3F);
|
||||
outputData[outputIndex++] = 0x80 | ((code >> 6) & 0x3F);
|
||||
outputData[outputIndex++] = 0x80 | (code & 0x3F);
|
||||
} else if (code < 0x3FFFFFF) {
|
||||
outputData[outputIndex++] = 0xF8 | (code >> 24);
|
||||
outputData[outputIndex++] = 0x80 | ((code >> 18) & 0x3F);
|
||||
outputData[outputIndex++] = 0x80 | ((code >> 12) & 0x3F);
|
||||
outputData[outputIndex++] = 0x80 | ((code >> 6) & 0x3F);
|
||||
outputData[outputIndex++] = 0x80 | (code & 0x3F);
|
||||
} else if (code < 0x7FFFFFFF) {
|
||||
outputData[outputIndex++] = 0xFC | (code >> 30);
|
||||
outputData[outputIndex++] = 0x80 | ((code >> 24) & 0x3F);
|
||||
outputData[outputIndex++] = 0x80 | ((code >> 18) & 0x3F);
|
||||
outputData[outputIndex++] = 0x80 | ((code >> 12) & 0x3F);
|
||||
outputData[outputIndex++] = 0x80 | ((code >> 6) & 0x3F);
|
||||
outputData[outputIndex++] = 0x80 | (code & 0x3F);
|
||||
}
|
||||
}
|
||||
|
||||
if (isNoEndNull !== true)
|
||||
outputData[outputIndex++] = 0;
|
||||
|
||||
return new Uint8Array(tmpStrings,0,outputIndex);
|
||||
};
|
||||
|
||||
window.UtilsJS = {};
|
||||
|
||||
var charA = "A".charCodeAt(0);
|
||||
var charZ = "Z".charCodeAt(0);
|
||||
var chara = "a".charCodeAt(0);
|
||||
var charz = "z".charCodeAt(0);
|
||||
var char0 = "0".charCodeAt(0);
|
||||
var char9 = "9".charCodeAt(0);
|
||||
var charp = "+".charCodeAt(0);
|
||||
var chars = "/".charCodeAt(0);
|
||||
var char_break = ";".charCodeAt(0);
|
||||
|
||||
function decodeBase64Char(ch)
|
||||
{
|
||||
if (ch >= charA && ch <= charZ)
|
||||
return ch - charA + 0;
|
||||
if (ch >= chara && ch <= charz)
|
||||
return ch - chara + 26;
|
||||
if (ch >= char0 && ch <= char9)
|
||||
return ch - char0 + 52;
|
||||
if (ch == charp)
|
||||
return 62;
|
||||
if (ch == chars)
|
||||
return 63;
|
||||
return -1;
|
||||
}
|
||||
|
||||
var stringBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
var arrayBase64 = [];
|
||||
for (var index64 = 0; index64 < stringBase64.length; index64++)
|
||||
{
|
||||
arrayBase64.push(stringBase64.charAt(index64));
|
||||
}
|
||||
|
||||
window.UtilsJS.Base64 = {};
|
||||
|
||||
window.UtilsJS.Base64.decodeData = function(input, input_offset, input_len, output, output_offset)
|
||||
{
|
||||
var isBase64 = typeof input === "string";
|
||||
if (undefined === input_len) input_len = input.length;
|
||||
var writeIndex = (undefined === output_offset) ? 0 : output_offset;
|
||||
var index = (undefined === input_offset) ? 0 : input_offset;
|
||||
|
||||
while (index < input_len)
|
||||
{
|
||||
var dwCurr = 0;
|
||||
var i;
|
||||
var nBits = 0;
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
if (index >= input_len)
|
||||
break;
|
||||
var nCh = decodeBase64Char(isBase64 ? input.charCodeAt(index) : input[index]);
|
||||
index++;
|
||||
if (nCh == -1)
|
||||
{
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
dwCurr <<= 6;
|
||||
dwCurr |= nCh;
|
||||
nBits += 6;
|
||||
}
|
||||
|
||||
dwCurr <<= 24-nBits;
|
||||
for (i=0; i<(nBits>>3); i++)
|
||||
{
|
||||
output[writeIndex++] = ((dwCurr & 0x00ff0000) >>> 16);
|
||||
dwCurr <<= 8;
|
||||
}
|
||||
}
|
||||
return writeIndex;
|
||||
};
|
||||
|
||||
window.UtilsJS.Base64.decode = function(input, isUsePrefix, dstlen, offset)
|
||||
{
|
||||
var srcLen = input.length;
|
||||
var index = (undefined === offset) ? 0 : offset;
|
||||
var dstLen = (undefined === dstlen) ? srcLen : dstlen;
|
||||
|
||||
var isBase64 = typeof input === "string";
|
||||
|
||||
if (isUsePrefix && isBase64)
|
||||
{
|
||||
dstLen = 0;
|
||||
var maxLen = Math.max(11, srcLen); // > 4 Gb
|
||||
while (index < maxLen)
|
||||
{
|
||||
var c = input.charCodeAt(index++);
|
||||
if (c == char_break)
|
||||
break;
|
||||
|
||||
dstLen *= 10;
|
||||
dstLen += (c - char0);
|
||||
}
|
||||
|
||||
if (index == maxLen)
|
||||
{
|
||||
index = 0;
|
||||
dstLen = srcLen;
|
||||
}
|
||||
}
|
||||
|
||||
var dst = new Uint8Array(dstLen);
|
||||
var writeIndex = window.AscCommon.Base64.decodeData(input, index, srcLen, dst, 0);
|
||||
|
||||
if (writeIndex == dstLen)
|
||||
return dst;
|
||||
|
||||
return new Uint8Array(dst.buffer, 0, writeIndex);
|
||||
};
|
||||
|
||||
window.UtilsJS.Base64.encode = function(input, offset, length, isUsePrefix)
|
||||
{
|
||||
var srcLen = (undefined === length) ? input.length : length;
|
||||
var index = (undefined === offset) ? 0 : offset;
|
||||
|
||||
var len1 = (((srcLen / 3) >> 0) * 4);
|
||||
var len2 = (len1 / 76) >> 0;
|
||||
var len3 = 19;
|
||||
var dstArray = [];
|
||||
|
||||
var sTemp = "";
|
||||
var dwCurr = 0;
|
||||
for (var i = 0; i <= len2; i++)
|
||||
{
|
||||
if (i == len2)
|
||||
len3 = ((len1 % 76) / 4) >> 0;
|
||||
|
||||
for (var j = 0; j < len3; j++)
|
||||
{
|
||||
dwCurr = 0;
|
||||
for (var n = 0; n < 3; n++)
|
||||
{
|
||||
dwCurr |= input[index++];
|
||||
dwCurr <<= 8;
|
||||
}
|
||||
|
||||
sTemp = "";
|
||||
for (var k = 0; k < 4; k++)
|
||||
{
|
||||
var b = (dwCurr >>> 26) & 0xFF;
|
||||
sTemp += arrayBase64[b];
|
||||
dwCurr <<= 6;
|
||||
dwCurr &= 0xFFFFFFFF;
|
||||
}
|
||||
dstArray.push(sTemp);
|
||||
}
|
||||
}
|
||||
len2 = (srcLen % 3 != 0) ? (srcLen % 3 + 1) : 0;
|
||||
if (len2)
|
||||
{
|
||||
dwCurr = 0;
|
||||
for (var n = 0; n < 3; n++)
|
||||
{
|
||||
if (n < (srcLen % 3))
|
||||
dwCurr |= input[index++];
|
||||
dwCurr <<= 8;
|
||||
}
|
||||
|
||||
sTemp = "";
|
||||
for (var k = 0; k < len2; k++)
|
||||
{
|
||||
var b = (dwCurr >>> 26) & 0xFF;
|
||||
sTemp += arrayBase64[b];
|
||||
dwCurr <<= 6;
|
||||
}
|
||||
|
||||
len3 = (len2 != 0) ? 4 - len2 : 0;
|
||||
for (var j = 0; j < len3; j++)
|
||||
{
|
||||
sTemp += '=';
|
||||
}
|
||||
dstArray.push(sTemp);
|
||||
}
|
||||
|
||||
return isUsePrefix ? (("" + srcLen + ";") + dstArray.join("")) : dstArray.join("");
|
||||
};
|
||||
|
||||
window.UtilsJS.Hex = {};
|
||||
|
||||
window.UtilsJS.Hex.decode = function(input)
|
||||
{
|
||||
var hexToByte = function(c) {
|
||||
if (c >= 48 && c <= 57) return c - 48; // 0..9
|
||||
if (c >= 97 && c <= 102) return c - 87;
|
||||
if (c >= 65 && c <= 70) return c - 55;
|
||||
return 0;
|
||||
};
|
||||
|
||||
var len = input.length;
|
||||
if (len & 0x01) len -= 1;
|
||||
var result = new Uint8Array(len >> 1);
|
||||
var resIndex = 0;
|
||||
for (var i = 0; i < len; i += 2)
|
||||
{
|
||||
result[resIndex++] = hexToByte(input.charCodeAt(i)) << 4 | hexToByte(input.charCodeAt(i + 1));
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
window.UtilsJS.Hex.encode = function(input, isUpperCase)
|
||||
{
|
||||
var byteToHex = new Array(256);
|
||||
for (var i = 0; i < 16; i++)
|
||||
byteToHex[i] = "0" + (isUpperCase ? i.toString(16).toUpperCase() : i.toString(16));
|
||||
for (var i = 16; i < 256; i++)
|
||||
byteToHex[i] = isUpperCase ? i.toString(16).toUpperCase() : i.toString(16);
|
||||
|
||||
var result = "";
|
||||
for (var i = 0, len = input.length; i < len; i++)
|
||||
result += byteToHex[input[i]];
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
window.UtilsJS.random = function(length) {
|
||||
let byteArray = new Uint8Array(length);
|
||||
let engine = window.crypto || window.msCrypto;
|
||||
if (engine)
|
||||
engine.getRandomValues(byteArray);
|
||||
else {
|
||||
for (let i = 0; i < length; i++)
|
||||
byteArray[i] = (Math.random() * 256) >> 0;
|
||||
}
|
||||
return byteArray;
|
||||
};
|
||||
})(self);
|
||||
@ -1,24 +0,0 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
@ -1,6 +0,0 @@
|
||||
# Onlyoffice keychain extension
|
||||
|
||||
To run the dev build:
|
||||
1. Go to the extension2 folder
|
||||
2. Run ```npm run dev```
|
||||
3. Upload the dist folder as an unpacked extension to the browser
|
||||
@ -1,26 +0,0 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import { globalIgnores } from 'eslint/config'
|
||||
|
||||
export default tseslint.config([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
tseslint.configs.recommended,
|
||||
reactHooks.configs['recommended-latest'],
|
||||
reactRefresh.configs.vite,
|
||||
],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
rules: {
|
||||
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
||||
}
|
||||
},
|
||||
])
|
||||
@ -1,34 +0,0 @@
|
||||
import { defineManifest } from '@crxjs/vite-plugin';
|
||||
import pkg from "./package.json";
|
||||
|
||||
export default defineManifest({
|
||||
manifest_version: 3,
|
||||
name: pkg.name,
|
||||
version: pkg.version,
|
||||
icons: {
|
||||
16: "public/icons/icon16.png",
|
||||
32: "public/icons/icon32.png",
|
||||
48: "public/icons/icon48.png",
|
||||
64: "public/icons/icon64.png",
|
||||
128: "public/icons/icon128.png",
|
||||
},
|
||||
action: {
|
||||
default_icon: {
|
||||
16: "public/icons/icon16.png",
|
||||
32: "public/icons/icon32.png",
|
||||
48: "public/icons/icon48.png",
|
||||
64: "public/icons/icon64.png",
|
||||
128: "public/icons/icon128.png",
|
||||
},
|
||||
default_popup: 'src/popup/index.html',
|
||||
},
|
||||
content_scripts: [{
|
||||
js: ['src/content/content.ts'],
|
||||
matches: ['<all_urls>'],
|
||||
run_at: "document_end"
|
||||
}],
|
||||
background: {
|
||||
service_worker: "src/background/background.ts"
|
||||
},
|
||||
permissions: ["storage"],
|
||||
});
|
||||
@ -1,33 +0,0 @@
|
||||
{
|
||||
"name": "ONLYOFFICE Keychain",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^19.1.1",
|
||||
"react-dom": "^19.1.1",
|
||||
"webextension-polyfill": "^0.12.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@crxjs/vite-plugin": "^2.2.0",
|
||||
"@eslint/js": "^9.33.0",
|
||||
"@types/react": "^19.1.10",
|
||||
"@types/react-dom": "^19.1.7",
|
||||
"@types/webextension-polyfill": "^0.12.3",
|
||||
"@vitejs/plugin-react": "^5.0.0",
|
||||
"chrome-types": "^0.1.375",
|
||||
"eslint": "^9.33.0",
|
||||
"eslint-plugin-react-hooks": "^5.2.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.20",
|
||||
"globals": "^16.3.0",
|
||||
"typescript": "~5.8.3",
|
||||
"typescript-eslint": "^8.39.1",
|
||||
"vite": "^7.1.5"
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 999 B |
|
Before Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 8.4 KiB |
@ -1,5 +0,0 @@
|
||||
import {initCheckOpenedPopup} from "./utils.ts";
|
||||
import initTaskManager from "./task-manager/task-manager.ts";
|
||||
|
||||
initTaskManager();
|
||||
initCheckOpenedPopup();
|
||||
@ -1,31 +0,0 @@
|
||||
import browser from "webextension-polyfill";
|
||||
import {messageTypes} from "../../common/message-const.ts";
|
||||
import {generatePopupKeys, selectSignKeys, signData, verifyData} from "./tasks.ts";
|
||||
import {isBackgroundMessageType} from "../../common/message-types.ts";
|
||||
|
||||
const initTaskManager = () => {
|
||||
browser.runtime.onMessage.addListener((message: unknown) => {
|
||||
if (!isBackgroundMessageType(message)) {
|
||||
return false;
|
||||
}
|
||||
const data = message.data;
|
||||
switch (data.type) {
|
||||
case messageTypes.GENERATE_KEYS: {
|
||||
return generatePopupKeys();
|
||||
}
|
||||
case messageTypes.SELECT_SIGN_KEYS: {
|
||||
return selectSignKeys();
|
||||
}
|
||||
case messageTypes.SIGN_DATA: {
|
||||
return signData(data.base64Data, data.guid);
|
||||
}
|
||||
case messageTypes.VERIFY_DATA: {
|
||||
return verifyData(data.base64Data, data.base64Signature, data.guid);
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export default initTaskManager;
|
||||
@ -1,43 +0,0 @@
|
||||
import {openPopup} from "../utils.ts";
|
||||
import {messageTypes} from "../../common/message-const.ts";
|
||||
import {sendToPopup} from "../../content/messenger.ts";
|
||||
// @ts-ignore
|
||||
import {StorageManager} from "../../common/storage.ts";
|
||||
import {ab2base64, base642ui} from "../../common/utils.ts";
|
||||
import getCrypto from "../../common/crypto.ts";
|
||||
|
||||
export const generatePopupKeys = async () => {
|
||||
await openPopup();
|
||||
await sendToPopup({type: messageTypes.WAIT_ENTER_PASSWORD});
|
||||
return true;
|
||||
}
|
||||
|
||||
export const selectSignKeys = async () => {
|
||||
await openPopup();
|
||||
await sendToPopup({type: messageTypes.WAIT_ENTER_PASSWORD});
|
||||
return await sendToPopup({type: messageTypes.SELECT_SIGN_KEYS});
|
||||
};
|
||||
|
||||
export const signData = async (base64Data: string , guid: string) => {
|
||||
const keyStorage = new StorageManager();
|
||||
await keyStorage.loadKeysFromStorage();
|
||||
const keyPair = keyStorage.getKeyByGuid(guid);
|
||||
if (!keyPair) {
|
||||
throw new Error("Key pair is not found");
|
||||
}
|
||||
const data = base642ui(base64Data);
|
||||
const signData = await keyPair.sign(data);
|
||||
return ab2base64(signData);
|
||||
}
|
||||
|
||||
export const verifyData = async (base64Data: string, base64Signature: string, guid: string) => {
|
||||
const keyStorage = new StorageManager();
|
||||
await keyStorage.loadKeysFromStorage();
|
||||
const keyPair = keyStorage.getKeyByGuid(guid);
|
||||
if (!keyPair) {
|
||||
throw new Error("Key pair is not found");
|
||||
}
|
||||
const data = base642ui(base64Data);
|
||||
const signature = base642ui(base64Signature);
|
||||
return await keyPair.verify(signature, data);
|
||||
}
|
||||
@ -1,52 +0,0 @@
|
||||
import browser from "webextension-polyfill";
|
||||
import getCrypto from "../common/crypto.ts";
|
||||
|
||||
export const initCheckOpenedPopup = () => {
|
||||
browser.runtime.onConnect.addListener((port) => {
|
||||
if (port.name === "popup") {
|
||||
browser.storage.session.set({isOpenPopup: true});
|
||||
|
||||
port.onDisconnect.addListener(() => {
|
||||
browser.storage.session.set({isOpenPopup: false});
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const isOpenedPopup = async () => {
|
||||
const isOpenPopupItem = await browser.storage.session.get("isOpenPopup");
|
||||
return !!(isOpenPopupItem && isOpenPopupItem.isOpenPopup);
|
||||
};
|
||||
|
||||
const waitClosingPopup = async () => {
|
||||
const isOpenPopup = await isOpenedPopup();
|
||||
if (!isOpenPopup) {
|
||||
return true;
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
browser.storage.session.onChanged.addListener(function handler(change) {
|
||||
if (change.isOpenPopup && !change.isOpenPopup.newValue) {
|
||||
browser.storage.session.onChanged.removeListener(handler);
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const openPopup = async () => {
|
||||
await waitClosingPopup();
|
||||
await browser.action.openPopup();
|
||||
return new Promise(resolve => {
|
||||
browser.storage.session.onChanged.addListener(function handler(change) {
|
||||
if (change.isOpenPopup && change.isOpenPopup.newValue) {
|
||||
browser.storage.session.onChanged.removeListener(handler);
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
type TGuid = `{${string}-${string}-${string}-${string}-${string}}`
|
||||
export const getGUID = (): TGuid => {
|
||||
const crypto = getCrypto();
|
||||
return `{${crypto.randomUUID()}}`;
|
||||
}
|
||||
@ -1,138 +0,0 @@
|
||||
import {Key, KeyPair, KeyUsages, PrivateKey, PublicKey, SymmetricKey} from "./keys/keys.ts";
|
||||
import {
|
||||
type DigestType,
|
||||
digestTypes,
|
||||
type ExportKeyFormat,
|
||||
exportKeyFormats,
|
||||
type KeyGenParams,
|
||||
type KeyParams
|
||||
} from "./keys/key-types.ts";
|
||||
import {AesGcmGenParams, type AesGcmParams} from "./keys/params.ts";
|
||||
|
||||
const pbkdf2Parameters = {
|
||||
iterations: 150000,
|
||||
hash: digestTypes.SHA256,
|
||||
saltLength: 16
|
||||
};
|
||||
// type DecryptKey = PrivateKey | SymmetricKey;
|
||||
// type EncryptKey = PublicKey | SymmetricKey;
|
||||
abstract class CCryptoBase {
|
||||
abstract sign(key: PrivateKey, data: ArrayBuffer): Promise<ArrayBuffer>;
|
||||
abstract digest(algorithm: DigestType, data: ArrayBuffer): Promise<ArrayBuffer>;
|
||||
abstract verify(key: PublicKey, signature: ArrayBuffer, data: ArrayBuffer): Promise<boolean>;
|
||||
// abstract decrypt(key: DecryptKey, data: ArrayBuffer): Promise<ArrayBuffer>;
|
||||
// abstract encrypt(key: EncryptKey, data: ArrayBuffer): Promise<ArrayBuffer>;
|
||||
abstract generateKey(params: KeyGenParams, keyUsage: KeyUsages): Promise<SymmetricKey | KeyPair>;
|
||||
abstract wrapKey(format: ExportKeyFormat, key: Key, masterPassword: ArrayBuffer, salt: ArrayBuffer, aesParams: AesGcmParams, keyUsage: KeyUsages): Promise<ArrayBuffer>
|
||||
abstract unwrapKey(format: ExportKeyFormat, key: ArrayBuffer, masterPassword: ArrayBuffer, salt: ArrayBuffer, aesParams: AesGcmParams, keyParams: KeyParams, keyUsage: KeyUsages): Promise<ArrayBuffer>
|
||||
abstract getRandomValues(length: number): ArrayBuffer;
|
||||
abstract randomUUID(): string;
|
||||
}
|
||||
class CWebCrypto extends CCryptoBase {
|
||||
crypto = globalThis.crypto;
|
||||
subtle = this.crypto.subtle;
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
getRandomValues(length: number) {
|
||||
const ui = new Uint8Array(length);
|
||||
return this.crypto.getRandomValues(ui);
|
||||
}
|
||||
async getAesCryptoKey(masterPassword: ArrayBuffer, salt: ArrayBuffer) {
|
||||
const pwKey = await this.subtle.importKey(
|
||||
'raw',
|
||||
masterPassword,
|
||||
{ name: 'PBKDF2' },
|
||||
false,
|
||||
['deriveKey']
|
||||
);
|
||||
return this.subtle.deriveKey(
|
||||
{
|
||||
name: 'PBKDF2',
|
||||
salt: salt,
|
||||
iterations: pbkdf2Parameters.iterations,
|
||||
hash: pbkdf2Parameters.hash
|
||||
},
|
||||
pwKey,
|
||||
new AesGcmGenParams(),
|
||||
false,
|
||||
['wrapKey', 'unwrapKey']
|
||||
);
|
||||
};
|
||||
async wrapKey(format: ExportKeyFormat, key: Key, masterPassword: ArrayBuffer, salt: ArrayBuffer, aesParams: AesGcmParams, keyUsage: KeyUsages) {
|
||||
const cryptoAesKey = await this.getAesCryptoKey(masterPassword, salt);
|
||||
const importKey = await this.getCryptoKeyFromWrapper(key, keyUsage);
|
||||
return this.subtle.wrapKey(format, importKey, cryptoAesKey, aesParams);
|
||||
}
|
||||
async unwrapKey(format: ExportKeyFormat, key: ArrayBuffer, masterPassword: ArrayBuffer, salt: ArrayBuffer, aesParams: AesGcmParams, keyParams: KeyParams, keyUsages: KeyUsages) {
|
||||
const cryptoAesKey = await this.getAesCryptoKey(masterPassword, salt);
|
||||
const cryptoKey = await this.subtle.unwrapKey(format, key, cryptoAesKey, aesParams, keyParams, true, /*this.getKeyUsages(keyUsages)*/["sign"]);
|
||||
return this.subtle.exportKey(format, cryptoKey);
|
||||
}
|
||||
async getCryptoKeyFromWrapper(key: Key, keyUsage: KeyUsages) {
|
||||
return this.subtle.importKey(key.exportFormat, key.key, key.params, true, this.getKeyUsages(keyUsage, key));
|
||||
}
|
||||
getKeyUsages({isEncrypt, isSign}: KeyUsages, key?: Key) {
|
||||
const keyUsages: KeyUsage[] = [];
|
||||
if (isEncrypt) {
|
||||
if (key instanceof PrivateKey) {
|
||||
keyUsages.push("decrypt");
|
||||
} else if (key instanceof PublicKey) {
|
||||
keyUsages.push("encrypt");
|
||||
} else {
|
||||
keyUsages.push("encrypt", "decrypt");
|
||||
}
|
||||
}
|
||||
if (isSign) {
|
||||
if (key instanceof PrivateKey) {
|
||||
keyUsages.push("sign");
|
||||
} else if (key instanceof PublicKey) {
|
||||
keyUsages.push("verify");
|
||||
} else {
|
||||
keyUsages.push("sign", "verify");
|
||||
}
|
||||
}
|
||||
return keyUsages;
|
||||
}
|
||||
async sign(key: PrivateKey, data: ArrayBuffer): Promise<ArrayBuffer> {
|
||||
const cryptoKey = await this.getCryptoKeyFromWrapper(key, new KeyUsages(false, true));
|
||||
return this.subtle.sign(key.params, cryptoKey, data);
|
||||
}
|
||||
async digest(algorithm: DigestType, data: ArrayBuffer): Promise<ArrayBuffer> {
|
||||
return this.subtle.digest(algorithm, data);
|
||||
}
|
||||
async verify(key: PublicKey, signature: ArrayBuffer, data: ArrayBuffer): Promise<boolean> {
|
||||
const cryptoKey = await this.getCryptoKeyFromWrapper(key, new KeyUsages(false, true));
|
||||
return this.subtle.verify(key.params, cryptoKey, signature, data);
|
||||
}
|
||||
// async decrypt(key: DecryptKey, data: ArrayBuffer): Promise<ArrayBuffer> {
|
||||
// const cryptoKey = await this.getCryptoKeyFromWrapper(key);
|
||||
// return this.subtle.decrypt(cryptoKey);
|
||||
// }
|
||||
// async encrypt(key: EncryptKey, data: ArrayBuffer): Promise<ArrayBuffer> {
|
||||
// throw new Error("Method not implemented.");
|
||||
// }
|
||||
async generateKey(params: KeyGenParams, keyUsage: KeyUsages) {
|
||||
const cryptoKey = await this.subtle.generateKey(params, true, this.getKeyUsages(keyUsage));
|
||||
const importParams = params.getImportParams();
|
||||
if (("privateKey" in cryptoKey) && ("publicKey" in cryptoKey)) {
|
||||
const publicKeyBuffer = await this.subtle.exportKey(exportKeyFormats.spki, cryptoKey.publicKey);
|
||||
const publicKey = new PublicKey(publicKeyBuffer, importParams);
|
||||
const privateKeyBuffer = await this.subtle.exportKey(exportKeyFormats.pkcs8, cryptoKey.privateKey);
|
||||
const privateKey = new PrivateKey(privateKeyBuffer, importParams, this.getRandomValues(pbkdf2Parameters.saltLength));
|
||||
return new KeyPair(publicKey, privateKey, keyUsage);
|
||||
}
|
||||
const keyBuffer = await this.subtle.exportKey(exportKeyFormats.raw, cryptoKey);
|
||||
return new SymmetricKey(keyBuffer, importParams, keyUsage);
|
||||
};
|
||||
|
||||
randomUUID() {
|
||||
return this.crypto.randomUUID();
|
||||
}
|
||||
}
|
||||
|
||||
const getCrypto = () => {
|
||||
return new CWebCrypto();
|
||||
}
|
||||
|
||||
export default getCrypto;
|
||||
@ -1,73 +0,0 @@
|
||||
import {KeyStorage} from "key-storage";
|
||||
import {downloadBinary, selectBinary} from "./utils.ts";
|
||||
|
||||
export function StorageManager() {
|
||||
this.keyStorage = new KeyStorage();
|
||||
}
|
||||
StorageManager.prototype.getBinaryKeys = function () {
|
||||
return Promise.resolve(null);
|
||||
};
|
||||
StorageManager.prototype.loadKeysFromStorage = function() {
|
||||
const oThis = this;
|
||||
return Promise.all([this.getMasterPassword(), this.getBinaryKeys()]).then(function ([masterPassword, binaryData]) {
|
||||
return oThis.keyStorage.import(binaryData, masterPassword);
|
||||
});
|
||||
}
|
||||
StorageManager.prototype.changeMasterPassword = function(newMasterPassword) {
|
||||
const oThis = this;
|
||||
return this.getMasterPassword().then(function (oldMasterPassword) {
|
||||
return oThis.keyStorage.changeMasterPassword(oldMasterPassword, newMasterPassword);
|
||||
});
|
||||
};
|
||||
StorageManager.prototype.getMasterPassword = function() {
|
||||
return Promise.resolve(null);
|
||||
};
|
||||
StorageManager.prototype.writeKeys = function() {
|
||||
const oThis = this;
|
||||
return this.keyStorage.export().then(function (exportedKeys) {
|
||||
return oThis.setStorageKeys(exportedKeys);
|
||||
});
|
||||
}
|
||||
StorageManager.prototype.setStorageKeys = function (exportedKeys) {
|
||||
return Promise.resolve();
|
||||
};
|
||||
StorageManager.prototype.addNewKeys = function (keys) {
|
||||
this.keyStorage.addKeys(keys);
|
||||
return this.writeKeys();
|
||||
};
|
||||
StorageManager.prototype.deprecateKey = function (key) {
|
||||
key.setIsValid(false);
|
||||
return this.writeKeys();
|
||||
};
|
||||
|
||||
StorageManager.prototype.exportKeys = function () {
|
||||
return this.keyStorage.export().then(downloadBinary);
|
||||
};
|
||||
|
||||
StorageManager.prototype.importKeys = function (callback) {
|
||||
const oThis = this;
|
||||
return this.getMasterPassword().then(function (masterPassword) {
|
||||
selectBinary(function (file) {
|
||||
try {
|
||||
file.arrayBuffer().then(function (binaryData) {
|
||||
return oThis.keyStorage.import(binaryData, masterPassword);
|
||||
}).then(function (keyObjects) {
|
||||
return oThis.addNewKeys(keyObjects);
|
||||
}).then(function () {
|
||||
callback();
|
||||
});
|
||||
} catch (e) {
|
||||
}
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
StorageManager.prototype.generateKeys = function (params) {
|
||||
return this.keyStorage.generateKey(params);
|
||||
};
|
||||
StorageManager.prototype.getValidKeys = function () {
|
||||
return this.keyStorage.getValidKeys();
|
||||
};
|
||||
StorageManager.prototype.getKeyByGuid = function (guid) {
|
||||
return this.keyStorage.getKeyByGuid(guid);
|
||||
};
|
||||
@ -1,108 +0,0 @@
|
||||
import {
|
||||
AesGcmParams,
|
||||
AesImportParams,
|
||||
AesKeyGenParams, Ed25519ImportParams,
|
||||
Ed25519KeyGenParams,
|
||||
type RsaImportParams,
|
||||
RSAKeyGenParams
|
||||
} from "./params.ts";
|
||||
import {Key, KeyPair, PrivateKey, PublicKey} from "./keys.ts";
|
||||
export const exportKeyFormats = {
|
||||
pkcs8: "pkcs8",
|
||||
spki: "spki",
|
||||
raw: "raw"
|
||||
} as const;
|
||||
|
||||
export const algorithmTypes = {
|
||||
AES_GCM: "AES-GCM",
|
||||
AES_CTR: "AES-CTR",
|
||||
AES_CBC: "AES-CBC",
|
||||
AES_KW: "AES-KW",
|
||||
ED25519: "Ed25519",
|
||||
RSASSA_PKCS1_v1_5: "RSASSA-PKCS1-v1_5",
|
||||
RSA_PSS: "RSA-PSS",
|
||||
RSA_OAEP: "RSA-OAEP"
|
||||
} as const;
|
||||
|
||||
export const rsaTypes = {
|
||||
RSASSA_PKCS1_v1_5: algorithmTypes.RSASSA_PKCS1_v1_5,
|
||||
RSA_PSS: algorithmTypes.RSA_PSS,
|
||||
RSA_OAEP: algorithmTypes.RSA_OAEP,
|
||||
} as const;
|
||||
|
||||
export const aesTypes = {
|
||||
AES_GCM: algorithmTypes.AES_GCM,
|
||||
AES_CTR: algorithmTypes.AES_CTR,
|
||||
AES_CBC: algorithmTypes.AES_CBC,
|
||||
AES_KW: algorithmTypes.AES_KW,
|
||||
} as const;
|
||||
|
||||
export const digestTypes = {
|
||||
SHA1: "SHA-1",
|
||||
SHA256: "SHA-256",
|
||||
SHA384: "SHA-384",
|
||||
SHA512: "SHA-512",
|
||||
} as const;
|
||||
|
||||
export const keyTypes = {
|
||||
symmetric: "symmetric",
|
||||
pair: "pair"
|
||||
} as const;
|
||||
|
||||
export const pairKeyTypes = {
|
||||
private: "private",
|
||||
public: "public",
|
||||
} as const;
|
||||
|
||||
export const signAlgorithms = {
|
||||
ED25519: algorithmTypes.ED25519
|
||||
}
|
||||
|
||||
export const cryptAlgorithms = {
|
||||
...aesTypes,
|
||||
RSA_OAEP: algorithmTypes.RSA_OAEP
|
||||
}
|
||||
|
||||
export const isRSAJson = (obj: JSONKeyParams): obj is RsaJSONType => {
|
||||
const name = obj.name;
|
||||
return Object.values(rsaTypes).includes(name as RsaType);
|
||||
}
|
||||
export const isEd25519Json = (obj: JSONKeyParams): obj is Ed25519JSONParams => {
|
||||
const name = obj.name;
|
||||
return name === algorithmTypes.ED25519;
|
||||
};
|
||||
export const isAesJson = (obj: JSONKeyParams): obj is AesJSONType => {
|
||||
const name = obj.name;
|
||||
return Object.values(aesTypes).includes(name as AesType);
|
||||
}
|
||||
|
||||
export type RsaJSONType = ReturnType<RsaImportParams["toJSON"]>;
|
||||
export type AesJSONType = ReturnType<AesImportParams["toJSON"]>;
|
||||
export type Ed25519JSONParams = ReturnType<Ed25519ImportParams["toJSON"]>;
|
||||
export type JSONAesGcmParams = ReturnType<AesGcmParams["toJSON"]>;
|
||||
export type AesKeyGenLength = 128 | 192 | 256;
|
||||
export type KeyParams = RsaImportParams | AesImportParams | Ed25519ImportParams;
|
||||
export type JSONKeyParams = RsaJSONType | AesJSONType | Ed25519JSONParams;
|
||||
export type KeyGenParams = RSAKeyGenParams | Ed25519KeyGenParams | AesKeyGenParams;
|
||||
export type DigestType = typeof digestTypes[keyof typeof digestTypes];
|
||||
export type AesType = typeof aesTypes[keyof typeof aesTypes];
|
||||
export type RsaType = typeof rsaTypes[keyof typeof rsaTypes];
|
||||
export type AlgorithmType = typeof algorithmTypes[keyof typeof algorithmTypes];
|
||||
export type ExportKeyFormat = typeof exportKeyFormats[keyof typeof exportKeyFormats];
|
||||
export type SignAlgorithm = typeof signAlgorithms[keyof typeof signAlgorithms];
|
||||
export type CryptAlgorithm = typeof cryptAlgorithms[keyof typeof cryptAlgorithms];
|
||||
export type JSONKey = Awaited<ReturnType<Key["toJSON"]>>;
|
||||
export type JSONPublicKey = Awaited<ReturnType<PublicKey["toJSON"]>>;
|
||||
export type JSONPrivateKey = Awaited<ReturnType<PrivateKey["toJSON"]>>;
|
||||
export type JSONKeyPair = Awaited<ReturnType<KeyPair["toJSON"]>>;
|
||||
export type PairKey = PrivateKey | PublicKey;
|
||||
type JSONEncryptExportKeyFormat = {
|
||||
encrypt: true;
|
||||
salt: string;
|
||||
data: string;
|
||||
};
|
||||
type JSONDecryptExportKeyFormat = {
|
||||
encrypt: false;
|
||||
data: JSONKeyPair[];
|
||||
};
|
||||
export type JSONExportKeyFormat = JSONEncryptExportKeyFormat | JSONDecryptExportKeyFormat;
|
||||
@ -1,156 +0,0 @@
|
||||
import {getGUID} from "../../background/utils.ts";
|
||||
import {ab2base64, base642ui, str2ui} from "../utils.ts";
|
||||
import {
|
||||
type ExportKeyFormat,
|
||||
exportKeyFormats, type JSONKey, type JSONKeyPair, type JSONPrivateKey, type JSONPublicKey,
|
||||
type KeyParams,
|
||||
keyTypes,
|
||||
pairKeyTypes
|
||||
} from "./key-types.ts";
|
||||
import getCrypto from "../crypto.ts";
|
||||
import {AesGcmParams, getKeyParamsFromJson} from "./params.ts";
|
||||
|
||||
export class Key {
|
||||
params: KeyParams;
|
||||
key;
|
||||
exportFormat;
|
||||
constructor(key: ArrayBuffer, params: KeyParams, exportFormat: ExportKeyFormat) {
|
||||
this.key = key;
|
||||
this.params = params;
|
||||
this.exportFormat = exportFormat;
|
||||
}
|
||||
static async fromJSON(json: JSONKey, _masterPassword?: string, _keyUsage?: KeyUsages) {
|
||||
const params = getKeyParamsFromJson(json.params);
|
||||
const key = base642ui(json.key);
|
||||
return new this(key, params, exportKeyFormats.raw);
|
||||
}
|
||||
async toJSON(_masterPassword?: string, _keyUsage?: KeyUsages) {
|
||||
const key = ab2base64(this.key);
|
||||
return {
|
||||
params: this.params.toJSON(),
|
||||
key: key
|
||||
};
|
||||
}
|
||||
}
|
||||
export class SymmetricKey extends Key {
|
||||
type = keyTypes.symmetric;
|
||||
keyUsages;
|
||||
constructor(key: ArrayBuffer, params: KeyParams, keyUsage = new KeyUsages(true)) {
|
||||
super(key, params, exportKeyFormats.raw);
|
||||
this.keyUsages = keyUsage;
|
||||
}
|
||||
}
|
||||
export class PublicKey extends Key {
|
||||
type = pairKeyTypes.public;
|
||||
constructor(key: ArrayBuffer, params: KeyParams) {
|
||||
super(key, params, exportKeyFormats.spki);
|
||||
}
|
||||
static override async fromJSON(json: JSONPublicKey) {
|
||||
const params = getKeyParamsFromJson(json.params);
|
||||
const key = base642ui(json.key);
|
||||
return new PublicKey(key, params);
|
||||
}
|
||||
override async toJSON() {
|
||||
const params = this.params.toJSON();
|
||||
const base64Key = ab2base64(this.key);
|
||||
return {
|
||||
format: exportKeyFormats.spki,
|
||||
key: base64Key,
|
||||
params
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class PrivateKey extends Key {
|
||||
type = pairKeyTypes.private;
|
||||
salt;
|
||||
constructor(key: ArrayBuffer, params: KeyParams, salt: ArrayBuffer) {
|
||||
super(key, params, exportKeyFormats.pkcs8);
|
||||
this.salt = salt;
|
||||
}
|
||||
static override async fromJSON(json: JSONPrivateKey, masterPassword: string, keyUsage: KeyUsages) {
|
||||
const salt = base642ui(json.salt);
|
||||
const params = getKeyParamsFromJson(json.params);
|
||||
const crypto = getCrypto();
|
||||
const strWrapKey = json.key;
|
||||
const wrapKey = base642ui(strWrapKey);
|
||||
const wrapParams = new AesGcmParams();
|
||||
wrapParams.fromJSON(json.wrapParams);
|
||||
const key = await crypto.unwrapKey(exportKeyFormats.pkcs8, wrapKey, str2ui(masterPassword), salt, wrapParams, params, keyUsage);
|
||||
|
||||
return new PrivateKey(key, params, salt);
|
||||
}
|
||||
override async toJSON(masterPassword: string, keyUsage: KeyUsages) {
|
||||
const crypto = getCrypto();
|
||||
const iv = crypto.getRandomValues(12);
|
||||
const aesParams = new AesGcmParams(iv);
|
||||
const wrapKey = await crypto.wrapKey(this.exportFormat, this, str2ui(masterPassword), this.salt, aesParams, keyUsage);
|
||||
const base64WrapKey = ab2base64(wrapKey);
|
||||
const params = this.params.toJSON();
|
||||
const wrapParams = aesParams.toJSON();
|
||||
return {
|
||||
format: this.exportFormat,
|
||||
key: base64WrapKey,
|
||||
salt: ab2base64(this.salt),
|
||||
params,
|
||||
wrapParams
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class KeyPair {
|
||||
privateKey;
|
||||
publicKey;
|
||||
date;
|
||||
type = keyTypes.pair;
|
||||
keyUsage;
|
||||
guid;
|
||||
isValid;
|
||||
static async fromJSON(json: JSONKeyPair, masterPassword: string) {
|
||||
const keyUsage = KeyUsages.fromJSON(json.keyUsage);
|
||||
const publicKey = await PublicKey.fromJSON(json.publicKey);
|
||||
const privateKey = await PrivateKey.fromJSON(json.privateKey, masterPassword, keyUsage);
|
||||
const date = new Date(json.date);
|
||||
const guid = json.guid;
|
||||
const isValid = json.isValid;
|
||||
return new KeyPair(publicKey, privateKey, keyUsage, date, guid, isValid);
|
||||
}
|
||||
constructor(publicKey: PublicKey, privateKey: PrivateKey, keyUsage = new KeyUsages(true), date = new Date(), guid: string = getGUID(), isValid: boolean = true) {
|
||||
this.privateKey = privateKey;
|
||||
this.publicKey = publicKey;
|
||||
this.date = date;
|
||||
this.keyUsage = keyUsage;
|
||||
this.guid = guid;
|
||||
this.isValid = isValid;
|
||||
}
|
||||
async toJSON(masterPassword: string) {
|
||||
return {
|
||||
publicKey: await this.publicKey.toJSON(),
|
||||
privateKey: await this.privateKey.toJSON(masterPassword, this.keyUsage),
|
||||
date: this.date.toISOString(),
|
||||
keyUsage: this.keyUsage.toJSON(),
|
||||
guid: this.guid,
|
||||
isValid: this.isValid
|
||||
}
|
||||
}
|
||||
setIsValid(isValid: boolean) {
|
||||
this.isValid = isValid;
|
||||
};
|
||||
}
|
||||
export class KeyUsages {
|
||||
isEncrypt;
|
||||
isSign;
|
||||
constructor(isEncrypt?: boolean, isSign?: boolean) {
|
||||
this.isEncrypt = !!isEncrypt;
|
||||
this.isSign = !!isSign;
|
||||
}
|
||||
static fromJSON(json: ReturnType<KeyUsages["toJSON"]>) {
|
||||
return new KeyUsages(json.isEncrypt, json.isSign);
|
||||
}
|
||||
toJSON() {
|
||||
return {
|
||||
isEncrypt: this.isEncrypt,
|
||||
isSign: this.isSign
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,128 +0,0 @@
|
||||
import {
|
||||
type AesKeyGenLength,
|
||||
type AesType,
|
||||
aesTypes,
|
||||
type AlgorithmType,
|
||||
algorithmTypes,
|
||||
type DigestType,
|
||||
digestTypes, isAesJson, isEd25519Json,
|
||||
isRSAJson,
|
||||
type JSONAesGcmParams,
|
||||
type JSONKeyParams,
|
||||
type RsaJSONType,
|
||||
type RsaType
|
||||
} from "./key-types.ts";
|
||||
import {ab2base64, base642ui} from "../utils.ts";
|
||||
|
||||
export const getKeyParamsFromJson = (keyParamsJson: JSONKeyParams) => {
|
||||
if (isRSAJson(keyParamsJson)) {
|
||||
return new RsaImportParams(keyParamsJson.name, keyParamsJson.hash);
|
||||
}
|
||||
if (isEd25519Json(keyParamsJson)) {
|
||||
return new Ed25519ImportParams();
|
||||
}
|
||||
if (isAesJson(keyParamsJson)) {
|
||||
return new AesImportParams(keyParamsJson.name);
|
||||
}
|
||||
throw new Error("Unknown param type");
|
||||
};
|
||||
|
||||
|
||||
export class AlgorithmParams<TName extends AlgorithmType = AlgorithmType> {
|
||||
name: TName;
|
||||
constructor(name: TName) {
|
||||
this.name = name;
|
||||
}
|
||||
toJSON() {
|
||||
return {
|
||||
name: this.name
|
||||
};
|
||||
};
|
||||
fromJSON(json: {name: TName}) {
|
||||
this.name = json.name;
|
||||
}
|
||||
getImportParams() {
|
||||
return new AlgorithmParams(this.name);
|
||||
}
|
||||
}
|
||||
|
||||
export class RsaImportParams extends AlgorithmParams<RsaType> {
|
||||
hash;
|
||||
constructor(name: RsaType, hash: DigestType = digestTypes.SHA256) {
|
||||
super(name);
|
||||
this.hash = hash;
|
||||
}
|
||||
override toJSON() {
|
||||
return {
|
||||
name: this.name,
|
||||
hash: this.hash,
|
||||
}
|
||||
}
|
||||
override fromJSON(json: RsaJSONType) {
|
||||
this.name = json.name;
|
||||
this.hash = json.hash;
|
||||
}
|
||||
}
|
||||
|
||||
export class RSAKeyGenParams extends RsaImportParams {
|
||||
modulusLength;
|
||||
publicExponent;
|
||||
constructor(name: RsaType, hash: DigestType = digestTypes.SHA256, modulusLength = 2048, publicExponent = new Uint8Array([0x01, 0x00, 0x01])) {
|
||||
super(name, hash);
|
||||
this.modulusLength = modulusLength;
|
||||
this.publicExponent = publicExponent;
|
||||
}
|
||||
override getImportParams() {
|
||||
return new RsaImportParams(this.name, this.hash);
|
||||
}
|
||||
}
|
||||
export class Ed25519ImportParams extends AlgorithmParams<typeof algorithmTypes.ED25519> {
|
||||
constructor() {
|
||||
super(algorithmTypes.ED25519);
|
||||
}
|
||||
}
|
||||
|
||||
export class AesImportParams extends AlgorithmParams<AesType> {
|
||||
constructor(name: AesType) {
|
||||
super(name);
|
||||
}
|
||||
}
|
||||
|
||||
export class AesGcmParams {
|
||||
name = algorithmTypes.AES_GCM;
|
||||
iv: ArrayBuffer;
|
||||
constructor(iv: ArrayBuffer = new Uint8Array(12)) {
|
||||
this.iv = iv;
|
||||
}
|
||||
toJSON() {
|
||||
return {
|
||||
name: this.name,
|
||||
iv: ab2base64(this.iv)
|
||||
}
|
||||
};
|
||||
fromJSON(json: JSONAesGcmParams) {
|
||||
this.iv = base642ui(json.iv);
|
||||
};
|
||||
}
|
||||
|
||||
export class AesKeyGenParams extends AesImportParams {
|
||||
length: AesKeyGenLength;
|
||||
constructor(name: AesType, length: AesKeyGenLength) {
|
||||
super(name);
|
||||
this.length = length;
|
||||
}
|
||||
override getImportParams() {
|
||||
return new AesImportParams(this.name);
|
||||
}
|
||||
}
|
||||
export class AesGcmGenParams extends AesKeyGenParams {
|
||||
constructor() {
|
||||
super(aesTypes.AES_GCM, 256);
|
||||
}
|
||||
}
|
||||
export class Ed25519KeyGenParams extends Ed25519ImportParams {
|
||||
override getImportParams() {
|
||||
return new Ed25519ImportParams();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
export const messageTypes = {
|
||||
GENERATE_KEYS: "GENERATE_KEYS",
|
||||
POPUP_IS_OPENED: "POPUP_IS_OPENED",
|
||||
WAIT_ENTER_PASSWORD: "WAIT_ENTER_PASSWORD",
|
||||
SELECT_SIGN_KEYS: "SELECT_SIGN_KEYS",
|
||||
SIGN_DATA: "SIGN_DATA",
|
||||
VERIFY_DATA: "VERIFY_DATA",
|
||||
ENCRYPT: "ENCRYPT",
|
||||
ENGINE_IS_EXIST: "ENGINE_IS_EXIST"
|
||||
} as const;
|
||||
|
||||
export const messageListeners = {
|
||||
background: "background",
|
||||
popup: "popup",
|
||||
} as const;
|
||||
|
||||
export const onlyofficeChannels = {
|
||||
onlyofficeExtensionChannel: "onlyoffice-sign-extension-channel",
|
||||
onlyofficeClientChannel: "onlyoffice-sign-client-channel",
|
||||
} as const;
|
||||
@ -1,35 +0,0 @@
|
||||
import {messageListeners, messageTypes} from "./message-const.ts";
|
||||
|
||||
|
||||
export type MessagesType = {type: typeof messageTypes[keyof typeof messageTypes]};
|
||||
|
||||
export const isMessages = (arg: unknown): arg is MessagesType => {
|
||||
return !!(arg && typeof arg === "object" && "type" in arg && typeof arg.type === "string" && arg.type in messageTypes);
|
||||
};
|
||||
|
||||
export type DispatchEventMessageType = {
|
||||
id?: number;
|
||||
data: MessagesType;
|
||||
}
|
||||
export type AnswerMainPageEventType = {
|
||||
id?: number;
|
||||
data: unknown;
|
||||
};
|
||||
type Listeners = typeof messageListeners[keyof typeof messageListeners];
|
||||
type ExtensionMessage<T extends Listeners = Listeners> = {
|
||||
data: MessagesType;
|
||||
listener: T;
|
||||
};
|
||||
export type BackgroundMessage = ExtensionMessage<typeof messageListeners.background>;
|
||||
export type PopupMessage = ExtensionMessage<typeof messageListeners.popup>;
|
||||
|
||||
const isExtensionMessageType = (arg: unknown): arg is ExtensionMessage => {
|
||||
return !!(arg && typeof arg === "object" && "data" in arg && isMessages(arg.data) && "listener" in arg && typeof arg.listener === "string");
|
||||
};
|
||||
export const isBackgroundMessageType = (arg: unknown): arg is BackgroundMessage => {
|
||||
return isExtensionMessageType(arg) && arg.listener === messageListeners.background;
|
||||
};
|
||||
|
||||
export const isPopupMessageType = (arg: unknown): arg is PopupMessage => {
|
||||
return isExtensionMessageType(arg) && arg.listener === messageListeners.popup;
|
||||
};
|
||||
@ -1,29 +0,0 @@
|
||||
// @ts-ignore
|
||||
import {StorageManager} from "../../../key-storage/key-storage.js";
|
||||
import browser from "webextension-polyfill";
|
||||
import type {JSONKeyPair} from "./keys/key-types.ts";
|
||||
|
||||
function ExtensionStorageManager() {
|
||||
StorageManager.call(this);
|
||||
}
|
||||
ExtensionStorageManager.prototype = Object.create(StorageManager);
|
||||
ExtensionStorageManager.prototype.constructor = ExtensionStorageManager;
|
||||
ExtensionStorageManager.prototype.getStorageKeys = function() {
|
||||
return browser.storage.local.get("keys").then(function(item) {
|
||||
if (item && Array.isArray(item.keys)) {
|
||||
return item.keys;
|
||||
}
|
||||
return [];
|
||||
});
|
||||
};
|
||||
ExtensionStorageManager.prototype.getMasterPassword = function() {
|
||||
return browser.storage.local.get("masterPassword").then(function(item) {
|
||||
return item.masterPassword ? item.masterPassword : null;
|
||||
});
|
||||
};
|
||||
ExtensionStorageManager.prototype.setStorageKeys = function(exportedKeys: JSONKeyPair[]) {
|
||||
return browser.storage.local.set({keys: exportedKeys});
|
||||
}
|
||||
ExtensionStorageManager.prototype.setMasterPasswordWithKeys = function(exportedKeys: JSONKeyPair[]) {
|
||||
return browser.storage.local.set({keys: exportedKeys});
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
export function ab2str(buf: ArrayBuffer) {
|
||||
return String.fromCharCode.apply(null, buf);
|
||||
}
|
||||
export function ab2base64(buf: ArrayBuffer) {
|
||||
const str = ab2str(buf);
|
||||
return btoa(str);
|
||||
}
|
||||
export function base642ui(base64: string) {
|
||||
const str = atob(base64);
|
||||
return str2ui(str);
|
||||
}
|
||||
export function str2ui(str: string) {
|
||||
const ui = new Uint8Array(str.length);
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
ui[i] = str.charCodeAt(i);
|
||||
}
|
||||
return ui;
|
||||
}
|
||||
|
||||
export const selectBinary = (callback: (file: File) => void) => {
|
||||
const input = document.createElement("input");
|
||||
input.type = "file";
|
||||
input.accept = "application/octet-stream";
|
||||
input.addEventListener("change", (e) => {
|
||||
const target = e.target as HTMLInputElement;
|
||||
const file = target.files?.[0];
|
||||
if (file) {
|
||||
callback(file);
|
||||
}
|
||||
});
|
||||
input.click();
|
||||
};
|
||||
|
||||
export const downloadBinary = (data: Uint8Array) => {
|
||||
const blob = new Blob([data], {type: "application/octet-stream"});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = `onlyoffice_keychain_${(new Date()).toISOString()}.bin`;
|
||||
link.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
import {sendToBackground, sendToPage} from "./messenger.ts";
|
||||
import {messageTypes, onlyofficeChannels} from "../common/message-const.ts";
|
||||
import {
|
||||
type DispatchEventMessageType,
|
||||
} from "../common/message-types.ts";
|
||||
|
||||
window.addEventListener(onlyofficeChannels.onlyofficeExtensionChannel, (event: CustomEvent<DispatchEventMessageType>) => {
|
||||
sendToBackground(event.detail.data).then((response: unknown) => {
|
||||
sendToPage({id: event.detail.id, data: response});
|
||||
});
|
||||
});
|
||||
window.dispatchEvent(new CustomEvent<DispatchEventMessageType>(onlyofficeChannels.onlyofficeClientChannel, {detail: {data: {type: messageTypes.ENGINE_IS_EXIST}}}));
|
||||