diff --git a/DesktopEditor/doctrenderer/doctrenderer.pro b/DesktopEditor/doctrenderer/doctrenderer.pro index 45d91d2f49..8c10f5984e 100644 --- a/DesktopEditor/doctrenderer/doctrenderer.pro +++ b/DesktopEditor/doctrenderer/doctrenderer.pro @@ -48,7 +48,8 @@ SOURCES += \ doctrenderer.cpp \ docbuilder.cpp \ docbuilder_p.cpp \ - nativebuilder.cpp + nativebuilder.cpp \ + graphics.cpp SOURCES += \ ../../Common/OfficeFileFormatChecker2.cpp \ @@ -60,7 +61,18 @@ HEADERS += \ docbuilder_p.h \ memorystream.h \ nativecontrol.h \ - nativebuilder.h + nativebuilder.h \ + graphics.h + +HEADERS += \ + js_internal/embed/GraphicsEmbed.h \ + js_internal/js_base.h \ + js_internal/v8/v8_base.h + +SOURCES += \ + js_internal/embed/GraphicsEmbed.cpp \ + js_internal/embed/v8/v8_Graphics.cpp \ + js_internal/v8/v8_base.cpp } # downloader diff --git a/DesktopEditor/doctrenderer/jsgraphics/graphics.cpp b/DesktopEditor/doctrenderer/graphics.cpp similarity index 89% rename from DesktopEditor/doctrenderer/jsgraphics/graphics.cpp rename to DesktopEditor/doctrenderer/graphics.cpp index 95e242cead..549722faa2 100644 --- a/DesktopEditor/doctrenderer/jsgraphics/graphics.cpp +++ b/DesktopEditor/doctrenderer/graphics.cpp @@ -3,90 +3,10 @@ #include #include -CJSGraphics::CJSGraphics() +namespace NSGraphics { - m_oContext = nullptr; - m_dWidthMM = 0.0; - m_dHeightMM = 0.0; - m_lWidthPix = 0.0; - m_lHeightPix = 0.0; - m_dDpiX = 96.0; - m_dDpiY = 96.0; - m_bIsBreak = false; - m_oPen = nullptr; // new AscCommon.CPen(); - m_bPenColorInit = false; - m_oBrush = nullptr; // new AscCommon.CBrush(); - m_bBrushColorInit = false; - - m_oFontManager = nullptr; - - m_oCoordTransform = nullptr; // new CMatrixL(); - m_oBaseTransform = nullptr; // new CMatrixL(); - m_oTransform = nullptr; // new CMatrixL(); - m_oFullTransform = nullptr; // new CMatrixL(); - m_oInvertFullTransform = nullptr; // new CMatrixL(); - - ArrayPoints = nullptr; - - m_oTextPr = nullptr; - m_oGrFonts = nullptr; // new AscCommon.CGrRFonts(); - m_oLastFont = nullptr; // new AscCommon.CFontSetup(); - - m_bIntegerGrid = true; - - ClipManager = nullptr; // new AscCommon.CClipManager(); - // ClipManager.BaseObject = this; - - TextureFillTransformScaleX = 1; - TextureFillTransformScaleY = 1; - IsThumbnail = false; - - IsDemonstrationMode = false; - - GrState = nullptr; // new AscCommon.CGrState(); - // GrState.Parent = this; - - globalAlpha = 1; - - TextClipRect = nullptr; - IsClipContext = false; - - IsUseFonts2 = false; - m_oFontManager2 = nullptr; - m_oLastFont2 = nullptr; - - ClearMode = false; - IsRetina = false; - - dash_no_smart = nullptr; -} - -CJSGraphics::~CJSGraphics() -{ - if(m_oContext) delete m_oContext; - if(m_oPen) delete m_oPen; - if(m_oBrush) delete m_oBrush; - if(m_oFontManager) delete m_oFontManager; - if(m_oCoordTransform) delete m_oCoordTransform; - if(m_oBaseTransform) delete m_oBaseTransform; - if(m_oTransform) delete m_oTransform; - if(m_oFullTransform) delete m_oFullTransform; - if(m_oInvertFullTransform) delete m_oInvertFullTransform; - if(ArrayPoints) delete ArrayPoints; - if(m_oTextPr) delete m_oTextPr; - if(m_oGrFonts) delete m_oGrFonts; - if(m_oLastFont) delete m_oLastFont; - if(LastFontOriginInfo.Replace) delete LastFontOriginInfo.Replace; - if(ClipManager) delete ClipManager; - if(GrState) delete GrState; - if(TextClipRect) delete TextClipRect; - if(m_oFontManager2) delete m_oFontManager2; - if(m_oLastFont2) delete m_oLastFont2; - if(dash_no_smart) delete dash_no_smart; -} - -void CJSGraphics::init(v8::Local* context, double width_px, double height_px, double width_mm, double height_mm) +void CGraphics::init(v8::Local* context, double width_px, double height_px, double width_mm, double height_mm) { m_oContext = context; m_lHeightPix = height_px; // height_px >> 0; @@ -111,7 +31,7 @@ void CJSGraphics::init(v8::Local* context, double width_px, double he m_bBrushColorInit = false; } -void CJSGraphics::put_GlobalAlpha(bool enable, int alpha) +void CGraphics::put_GlobalAlpha(bool enable, int alpha) { if(!enable) { @@ -125,7 +45,7 @@ void CJSGraphics::put_GlobalAlpha(bool enable, int alpha) } } -void CJSGraphics::End_GlobalAlpha() +void CGraphics::End_GlobalAlpha() { if (!m_bIntegerGrid) { @@ -147,7 +67,7 @@ void CJSGraphics::End_GlobalAlpha() } } -void CJSGraphics::p_color(int r, int g, int b, int a) +void CGraphics::p_color(int r, int g, int b, int a) { /* var _c = m_oPen.Color; @@ -165,7 +85,7 @@ void CJSGraphics::p_color(int r, int g, int b, int a) */ } -void CJSGraphics::p_width(int w) +void CGraphics::p_width(int w) { // m_oPen.LineWidth = static_cast(static_cast(w) / 1000.0); @@ -208,7 +128,7 @@ void CJSGraphics::p_width(int w) } } -void CJSGraphics::p_dash(const v8::Local& params) +void CGraphics::p_dash(const v8::Local& params) { /* if (!m_oContext.setLineDash) @@ -219,7 +139,7 @@ void CJSGraphics::p_dash(const v8::Local& params) */ } -void CJSGraphics::b_color1(int r, int g, int b, int a) +void CGraphics::b_color1(int r, int g, int b, int a) { /* var _c = m_oBrush.Color1; @@ -238,7 +158,7 @@ void CJSGraphics::b_color1(int r, int g, int b, int a) */ } -void CJSGraphics::b_color2(int r, int g, int b, int a) +void CGraphics::b_color2(int r, int g, int b, int a) { /* var _c = m_oBrush.Color2; @@ -249,7 +169,7 @@ void CJSGraphics::b_color2(int r, int g, int b, int a) */ } -void CJSGraphics::transform(double sx, double shy, double shx, double sy, double tx, double ty) +void CGraphics::transform(double sx, double shy, double shx, double sy, double tx, double ty) { /* v8::Local _t = m_oTransform; @@ -272,7 +192,7 @@ void CJSGraphics::transform(double sx, double shy, double shx, double sy, double */ } -void CJSGraphics::CalculateFullTransform(bool isInvertNeed) +void CGraphics::CalculateFullTransform(bool isInvertNeed) { /* v8::Local _ft = m_oFullTransform; @@ -300,22 +220,22 @@ void CJSGraphics::CalculateFullTransform(bool isInvertNeed) */ } -void CJSGraphics::_s() +void CGraphics::_s() { // m_oContext.beginPath(); } -void CJSGraphics::_e() +void CGraphics::_e() { // m_oContext.beginPath(); } -void CJSGraphics::_z() +void CGraphics::_z() { // m_oContext.closePath(); } -void CJSGraphics::_m(double x, double y) +void CGraphics::_m(double x, double y) { /* if (!m_bIntegerGrid) @@ -334,7 +254,7 @@ void CJSGraphics::_m(double x, double y) */ } -void CJSGraphics::_l(double x, double y) +void CGraphics::_l(double x, double y) { /* if (!m_bIntegerGrid) @@ -353,7 +273,7 @@ void CJSGraphics::_l(double x, double y) */ } -void CJSGraphics::_c(double x1, double y1, double x2, double y2, double x3, double y3) +void CGraphics::_c(double x1, double y1, double x2, double y2, double x3, double y3) { /* if (!m_bIntegerGrid) @@ -382,7 +302,7 @@ void CJSGraphics::_c(double x1, double y1, double x2, double y2, double x3, doub */ } -void CJSGraphics::_c2(double x1, double y1, double x2, double y2) +void CGraphics::_c2(double x1, double y1, double x2, double y2) { /* if (!m_bIntegerGrid) @@ -408,22 +328,22 @@ void CJSGraphics::_c2(double x1, double y1, double x2, double y2) */ } -void CJSGraphics::ds() +void CGraphics::ds() { // m_oContext.stroke(); } -void CJSGraphics::df() +void CGraphics::df() { // m_oContext.fill(); } -void CJSGraphics::save() +void CGraphics::save() { // m_oContext.save(); } -void CJSGraphics::restore() +void CGraphics::restore() { // m_oContext.restore(); @@ -431,12 +351,12 @@ void CJSGraphics::restore() m_bBrushColorInit = false; } -void CJSGraphics::clip() +void CGraphics::clip() { // m_oContext.clip(); } -void CJSGraphics::reset() +void CGraphics::reset() { // m_oTransform.Reset(); CalculateFullTransform(false); @@ -447,7 +367,7 @@ void CJSGraphics::reset() */ } -void CJSGraphics::transform3(const v8::Local& m, bool isNeedInvert) +void CGraphics::transform3(const v8::Local& m, bool isNeedInvert) { /* v8::Local _t = m_oTransform; @@ -469,12 +389,12 @@ void CJSGraphics::transform3(const v8::Local& m, bool isNeedInvert) */ } -void CJSGraphics::FreeFont() +void CGraphics::FreeFont() { // m_oFontManager.m_pFont = null; } -void CJSGraphics::ClearLastFont() +void CGraphics::ClearLastFont() { /* m_oLastFont = new AscCommon.CFontSetup(); @@ -482,7 +402,7 @@ void CJSGraphics::ClearLastFont() */ } -void CJSGraphics::drawImage2(const v8::Local& img, double x, double y, double w, double h, int alpha, const v8::Local& srcRect) +void CGraphics::drawImage2(const v8::Local& img, double x, double y, double w, double h, int alpha, const v8::Local& srcRect) { /* if (srcRect) @@ -698,7 +618,7 @@ void CJSGraphics::drawImage2(const v8::Local& img, double x, double y */ } -void CJSGraphics::drawImage(const v8::Local& img, double x, double y, double w, double h, int alpha, const v8::Local& srcRect, const v8::Local& nativeImage) +void CGraphics::drawImage(const v8::Local& img, double x, double y, double w, double h, int alpha, const v8::Local& srcRect, const v8::Local& nativeImage) { /* if (nativeImage) @@ -787,12 +707,12 @@ void CJSGraphics::drawImage(const v8::Local& img, double x, double y, */ } -CFont CJSGraphics::GetFont() +CFont CGraphics::GetFont() { return m_oCurFont; } -void CJSGraphics::font(unsigned int font_id, int font_size) +void CGraphics::font(unsigned int font_id, int font_size) { /* AscFonts.g_font_infos[AscFonts.g_map_font_index[font_id]].LoadFont(editor.FontLoader, this.IsUseFonts2 ? this.m_oFontManager2 : this.m_oFontManager, @@ -800,7 +720,7 @@ void CJSGraphics::font(unsigned int font_id, int font_size) */ } -void CJSGraphics::SetFont(const v8::Local& font) +void CGraphics::SetFont(const v8::Local& font) { /* if (null == font) @@ -843,7 +763,7 @@ void CJSGraphics::SetFont(const v8::Local& font) */ } -void CJSGraphics::SetTextPr(const v8::Local& textPr, const v8::Local& theme) +void CGraphics::SetTextPr(const v8::Local& textPr, const v8::Local& theme) { /* m_oTextPr = textPr; @@ -854,7 +774,7 @@ void CJSGraphics::SetTextPr(const v8::Local& textPr, const v8::Local< */ } -void CJSGraphics::SetFontSlot(const v8::Local& slot, double fontSizeKoef) +void CGraphics::SetFontSlot(const v8::Local& slot, double fontSizeKoef) { /* var _rfonts = this.m_oGrFonts; @@ -949,12 +869,12 @@ void CJSGraphics::SetFontSlot(const v8::Local& slot, double fontSizeK */ } -v8::Local CJSGraphics::GetTextPr() +v8::Local CGraphics::GetTextPr() { return *m_oTextPr; } -void CJSGraphics::FillText(double x, double y, const v8::Local& text) +void CGraphics::FillText(double x, double y, const v8::Local& text) { /* if (this.m_bIsBreak) @@ -998,7 +918,7 @@ void CJSGraphics::FillText(double x, double y, const v8::Local& text) */ } -void CJSGraphics::t(const v8::Local& text, double x, double y, bool isBounds) +void CGraphics::t(const v8::Local& text, double x, double y, bool isBounds) { /* if (this.m_bIsBreak) @@ -1040,7 +960,7 @@ void CJSGraphics::t(const v8::Local& text, double x, double y, bool i */ } -void CJSGraphics::FillText2(double x, double y, const v8::Local& text, double cropX, double cropW) +void CGraphics::FillText2(double x, double y, const v8::Local& text, double cropX, double cropW) { /* if (this.m_bIsBreak) @@ -1081,7 +1001,7 @@ void CJSGraphics::FillText2(double x, double y, const v8::Local& text */ } -void CJSGraphics::t2(const v8::Local& text, double x, double y, double cropX, double cropW) +void CGraphics::t2(const v8::Local& text, double x, double y, double cropX, double cropW) { /* if (this.m_bIsBreak) @@ -1121,7 +1041,7 @@ void CJSGraphics::t2(const v8::Local& text, double x, double y, doubl */ } -void CJSGraphics::FillTextCode(double x, double y, const v8::Local& lUnicode) +void CGraphics::FillTextCode(double x, double y, const v8::Local& lUnicode) { /* if (this.m_bIsBreak) @@ -1163,7 +1083,7 @@ void CJSGraphics::FillTextCode(double x, double y, const v8::Local& l */ } -void CJSGraphics::tg(const v8::Local& text, double x, double y) +void CGraphics::tg(const v8::Local& text, double x, double y) { /* if (this.m_bIsBreak) @@ -1208,7 +1128,7 @@ void CJSGraphics::tg(const v8::Local& text, double x, double y) */ } -void CJSGraphics::private_FillGlyph(const v8::Local& pGlyph, const v8::Local& _bounds) +void CGraphics::private_FillGlyph(const v8::Local& pGlyph, const v8::Local& _bounds) { /* var nW = pGlyph.oBitmap.nWidth; @@ -1245,7 +1165,7 @@ void CJSGraphics::private_FillGlyph(const v8::Local& pGlyph, const v8 */ } -void CJSGraphics::private_FillGlyphC(const v8::Local& pGlyph, double cropX, double cropW) +void CGraphics::private_FillGlyphC(const v8::Local& pGlyph, double cropX, double cropW) { /* var nW = pGlyph.oBitmap.nWidth; @@ -1271,7 +1191,7 @@ void CJSGraphics::private_FillGlyphC(const v8::Local& pGlyph, double */ } -void CJSGraphics::private_FillGlyph2(const v8::Local& pGlyph) +void CGraphics::private_FillGlyph2(const v8::Local& pGlyph) { /* var i = 0; @@ -1329,7 +1249,7 @@ void CJSGraphics::private_FillGlyph2(const v8::Local& pGlyph) */ } -void CJSGraphics::SetIntegerGrid(bool param) +void CGraphics::SetIntegerGrid(bool param) { /* if (true == param) @@ -1346,12 +1266,12 @@ void CJSGraphics::SetIntegerGrid(bool param) */ } -bool CJSGraphics::GetIntegerGrid() +bool CGraphics::GetIntegerGrid() { return m_bIntegerGrid; } -void CJSGraphics::DrawStringASCII(const std::string& name, int size, bool bold, bool italic, const v8::Local& text, double x, double y, bool bIsHeader) +void CGraphics::DrawStringASCII(const std::string& name, int size, bool bold, bool italic, const v8::Local& text, double x, double y, bool bIsHeader) { /* var _textProp = { @@ -1413,7 +1333,7 @@ void CJSGraphics::DrawStringASCII(const std::string& name, int size, bool bold, */ } -void CJSGraphics::DrawStringASCII2(const std::string& name, int size, bool bold, bool italic, const v8::Local& text, double x, double y, bool bIsHeader) +void CGraphics::DrawStringASCII2(const std::string& name, int size, bool bold, bool italic, const v8::Local& text, double x, double y, bool bIsHeader) { /* var _textProp = { @@ -1478,7 +1398,7 @@ void CJSGraphics::DrawStringASCII2(const std::string& name, int size, bool bold, */ } -void CJSGraphics::DrawHeaderEdit(double yPos, const v8::Local& lock_type, int sectionNum, bool bIsRepeat, const v8::Local& type) +void CGraphics::DrawHeaderEdit(double yPos, const v8::Local& lock_type, int sectionNum, bool bIsRepeat, const v8::Local& type) { /* var _y = this.m_oFullTransform.TransformPointY(0,yPos); @@ -1584,7 +1504,7 @@ void CJSGraphics::DrawHeaderEdit(double yPos, const v8::Local& lock_t */ } -void CJSGraphics::DrawFooterEdit(double yPos, const v8::Local& lock_type, int sectionNum, bool bIsRepeat, const v8::Local& type) +void CGraphics::DrawFooterEdit(double yPos, const v8::Local& lock_type, int sectionNum, bool bIsRepeat, const v8::Local& type) { /* var _y = this.m_oFullTransform.TransformPointY(0,yPos); @@ -1689,7 +1609,7 @@ void CJSGraphics::DrawFooterEdit(double yPos, const v8::Local& lock_t */ } -void CJSGraphics::DrawLockParagraph(const v8::Local& lock_type, double x, double y1, double y2) +void CGraphics::DrawLockParagraph(const v8::Local& lock_type, double x, double y1, double y2) { /* if (lock_type == locktype_None || editor.WordControl.m_oDrawingDocument.IsLockObjectsEnable === false || editor.isViewMode || (lock_type === locktype_Mine && true === AscCommon.CollaborativeEditing.Is_Fast())) @@ -1783,7 +1703,7 @@ void CJSGraphics::DrawLockParagraph(const v8::Local& lock_type, doubl */ } -void CJSGraphics::DrawLockObjectRect(const v8::Local& lock_type, double x, double y, double w, double h) +void CGraphics::DrawLockObjectRect(const v8::Local& lock_type, double x, double y, double w, double h) { /* if (editor.isViewMode || this.IsThumbnail || lock_type == locktype_None || this.IsDemonstrationMode || (lock_type === locktype_Mine && true === AscCommon.CollaborativeEditing.Is_Fast())) @@ -1893,7 +1813,7 @@ void CJSGraphics::DrawLockObjectRect(const v8::Local& lock_type, doub */ } -void CJSGraphics::DrawEmptyTableLine(double x1, double y1, double x2, double y2) +void CGraphics::DrawEmptyTableLine(double x1, double y1, double x2, double y2) { /* if ((!editor.isShowTableEmptyLine || editor.isViewMode) && (editor.isShowTableEmptyLineAttack === false)) @@ -1992,7 +1912,7 @@ void CJSGraphics::DrawEmptyTableLine(double x1, double y1, double x2, double y2) */ } -void CJSGraphics::DrawSpellingLine(double y0, double x0, double x1, double w) +void CGraphics::DrawSpellingLine(double y0, double x0, double x1, double w) { /* if (!editor.isViewMode) @@ -2000,7 +1920,7 @@ void CJSGraphics::DrawSpellingLine(double y0, double x0, double x1, double w) */ } -void CJSGraphics::drawHorLine(int align, double y, double x, double r, int penW) +void CGraphics::drawHorLine(int align, double y, double x, double r, int penW) { /* var _check_transform = global_MatrixTransformer.IsIdentity2(this.m_oTransform); @@ -2085,7 +2005,7 @@ void CJSGraphics::drawHorLine(int align, double y, double x, double r, int penW) */ } -void CJSGraphics::drawHorLine2(int align, double y, double x, double r, int penW) +void CGraphics::drawHorLine2(int align, double y, double x, double r, int penW) { /* var _check_transform = global_MatrixTransformer.IsIdentity2(this.m_oTransform); @@ -2165,7 +2085,7 @@ void CJSGraphics::drawHorLine2(int align, double y, double x, double r, int penW */ } -void CJSGraphics::drawVerLine(int align, double x, double y, double b, int penW) +void CGraphics::drawVerLine(int align, double x, double y, double b, int penW) { /* var _check_transform = global_MatrixTransformer.IsIdentity2(this.m_oTransform); @@ -2247,7 +2167,7 @@ void CJSGraphics::drawVerLine(int align, double x, double y, double b, int penW) */ } -void CJSGraphics::drawHorLineExt(int align, double y, double x, double r, int penW, double leftMW, double rightMW) +void CGraphics::drawHorLineExt(int align, double y, double x, double r, int penW, double leftMW, double rightMW) { /* var _check_transform = global_MatrixTransformer.IsIdentity2(this.m_oTransform); @@ -2385,7 +2305,7 @@ void CJSGraphics::drawHorLineExt(int align, double y, double x, double r, int pe */ } -void CJSGraphics::rect(double x, double y, double w, double h) +void CGraphics::rect(double x, double y, double w, double h) { /* var ctx = this.m_oContext; @@ -2427,7 +2347,7 @@ void CJSGraphics::rect(double x, double y, double w, double h) */ } -void CJSGraphics::TableRect(double x, double y, double w, double h) +void CGraphics::TableRect(double x, double y, double w, double h) { /* var ctx = this.m_oContext; @@ -2448,7 +2368,7 @@ void CJSGraphics::TableRect(double x, double y, double w, double h) */ } -void CJSGraphics::AddClipRect(double x, double y, double w, double h) +void CGraphics::AddClipRect(double x, double y, double w, double h) { /* var __rect = new AscCommon._rect(); @@ -2460,7 +2380,7 @@ void CJSGraphics::AddClipRect(double x, double y, double w, double h) */ } -void CJSGraphics::SetClip(const v8::Local& r) +void CGraphics::SetClip(const v8::Local& r) { /* var ctx = this.m_oContext; @@ -2486,7 +2406,7 @@ void CJSGraphics::SetClip(const v8::Local& r) */ } -void CJSGraphics::RemoveClip() +void CGraphics::RemoveClip() { /* this.m_oContext.restore(); @@ -2500,7 +2420,7 @@ void CJSGraphics::RemoveClip() */ } -void CJSGraphics::drawCollaborativeChanges(double x, double y, double w, double h, const v8::Local& Color) +void CGraphics::drawCollaborativeChanges(double x, double y, double w, double h, const v8::Local& Color) { /* this.b_color1( Color.r, Color.g, Color.b, 255 ); @@ -2509,7 +2429,7 @@ void CJSGraphics::drawCollaborativeChanges(double x, double y, double w, double */ } -void CJSGraphics::drawMailMergeField(double x, double y, double w, double h) +void CGraphics::drawMailMergeField(double x, double y, double w, double h) { /* this.b_color1(206, 212, 223, 204); @@ -2519,7 +2439,7 @@ void CJSGraphics::drawMailMergeField(double x, double y, double w, double h) */ } -void CJSGraphics::drawSearchResult(double x, double y, double w, double h) +void CGraphics::drawSearchResult(double x, double y, double w, double h) { /* this.b_color1( 255, 238, 128, 255 ); @@ -2528,7 +2448,7 @@ void CJSGraphics::drawSearchResult(double x, double y, double w, double h) */ } -void CJSGraphics::drawFlowAnchor(double x, double y) +void CGraphics::drawFlowAnchor(double x, double y) { /* if (!AscCommon.g_flow_anchor || !AscCommon.g_flow_anchor.asc_complete || (!editor || !editor.ShowParaMarks)) @@ -2552,52 +2472,52 @@ void CJSGraphics::drawFlowAnchor(double x, double y) */ } -void CJSGraphics::SavePen() +void CGraphics::SavePen() { // this.GrState.SavePen(); } -void CJSGraphics::RestorePen() +void CGraphics::RestorePen() { // this.GrState.RestorePen(); } -void CJSGraphics::SaveBrush() +void CGraphics::SaveBrush() { // this.GrState.SaveBrush(); } -void CJSGraphics::RestoreBrush() +void CGraphics::RestoreBrush() { // this.GrState.RestoreBrush(); } -void CJSGraphics::SavePenBrush() +void CGraphics::SavePenBrush() { // this.GrState.SavePenBrush(); } -void CJSGraphics::RestorePenBrush() +void CGraphics::RestorePenBrush() { // this.GrState.RestorePenBrush(); } -void CJSGraphics::SaveGrState() +void CGraphics::SaveGrState() { // this.GrState.SaveGrState(); } -void CJSGraphics::RestoreGrState() +void CGraphics::RestoreGrState() { // this.GrState.RestoreGrState(); } -void CJSGraphics::EndClipPath() +void CGraphics::EndClipPath() { // this.m_oContext.clip(); } -void CJSGraphics::StartCheckTableDraw() +void CGraphics::StartCheckTableDraw() { /* if (!this.m_bIntegerGrid && global_MatrixTransformer.IsIdentity2(this.m_oTransform)) @@ -2610,13 +2530,13 @@ void CJSGraphics::StartCheckTableDraw() */ } -void CJSGraphics::EndCheckTableDraw(bool bIsRestore) +void CGraphics::EndCheckTableDraw(bool bIsRestore) { if (bIsRestore) RestoreGrState(); } -void CJSGraphics::SetTextClipRect(double _l, double _t, double _r, double _b) +void CGraphics::SetTextClipRect(double _l, double _t, double _r, double _b) { /* this.TextClipRect = { @@ -2628,7 +2548,7 @@ void CJSGraphics::SetTextClipRect(double _l, double _t, double _r, double _b) */ } -void CJSGraphics::AddSmartRect(double x, double y, double w, double h, int pen_w) +void CGraphics::AddSmartRect(double x, double y, double w, double h, int pen_w) { /* if (!global_MatrixTransformer.IsIdentity2(this.m_oTransform)) @@ -2782,7 +2702,7 @@ void CJSGraphics::AddSmartRect(double x, double y, double w, double h, int pen_w */ } -void CJSGraphics::CheckUseFonts2(const v8::Local& _transform) +void CGraphics::CheckUseFonts2(const v8::Local& _transform) { /* if (!global_MatrixTransformer.IsIdentity2(_transform)) @@ -2803,12 +2723,12 @@ void CJSGraphics::CheckUseFonts2(const v8::Local& _transform) */ } -void CJSGraphics::UncheckUseFonts2() +void CGraphics::UncheckUseFonts2() { // IsUseFonts2 = false; } -void CJSGraphics::DrawPresentationComment(const v8::Local& type, double x, double y, double w, double h) +void CGraphics::DrawPresentationComment(const v8::Local& type, double x, double y, double w, double h) { /* if (this.IsThumbnail || this.IsDemonstrationMode) @@ -2843,7 +2763,7 @@ void CJSGraphics::DrawPresentationComment(const v8::Local& type, doub */ } -void CJSGraphics::DrawPolygon(const v8::Local& oPath, int lineWidth, double shift) +void CGraphics::DrawPolygon(const v8::Local& oPath, int lineWidth, double shift) { /* this.m_oContext.lineWidth = lineWidth; @@ -2903,7 +2823,7 @@ void CJSGraphics::DrawPolygon(const v8::Local& oPath, int lineWidth, */ } -void CJSGraphics::DrawFootnoteRect(double x, double y, double w, double h) +void CGraphics::DrawFootnoteRect(double x, double y, double w, double h) { /* var _old = this.m_bIntegerGrid; @@ -2933,3 +2853,4 @@ void CJSGraphics::DrawFootnoteRect(double x, double y, double w, double h) this.SetIntegerGrid(false); */ } +} diff --git a/DesktopEditor/doctrenderer/graphics.h b/DesktopEditor/doctrenderer/graphics.h new file mode 100644 index 0000000000..91e166aea8 --- /dev/null +++ b/DesktopEditor/doctrenderer/graphics.h @@ -0,0 +1,359 @@ +#ifndef CGRAPHICS_H +#define CGRAPHICS_H + +#include + +#include "../common/Types.h" +#include "v8.h" +#include "libplatform/libplatform.h" + +struct CFont +{ + std::string Name; + int FontSize; + bool Bold; + bool Italic; + + CFont() : Name(""), FontSize(10), Bold(false), Italic(false) {} +}; + +struct CLastFontOriginInfo +{ + std::string Name; + v8::Local* Replace; + + CLastFontOriginInfo() : Name(""), Replace(nullptr) {} +}; + +namespace NSGraphics +{ + class CGraphics + { + private: + v8::Local* m_oContext; + double m_dWidthMM; + double m_dHeightMM; + double m_lWidthPix; + double m_lHeightPix; + double m_dDpiX; + double m_dDpiY; + bool m_bIsBreak; + + v8::Local* m_oPen; + bool m_bPenColorInit; + v8::Local* m_oBrush; + bool m_bBrushColorInit; + + v8::Local* m_oFontManager; + + v8::Local* m_oCoordTransform; + v8::Local* m_oBaseTransform; + v8::Local* m_oTransform; + v8::Local* m_oFullTransform; + v8::Local* m_oInvertFullTransform; + + v8::Local* ArrayPoints; + + CFont m_oCurFont; + + v8::Local* m_oTextPr; + v8::Local* m_oGrFonts; + v8::Local* m_oLastFont; + + CLastFontOriginInfo LastFontOriginInfo; + + bool m_bIntegerGrid; + + v8::Local* ClipManager; + + int TextureFillTransformScaleX; + int TextureFillTransformScaleY; + bool IsThumbnail; + + bool IsDemonstrationMode; + + v8::Local* GrState; + + int globalAlpha; + + v8::Local* TextClipRect; + bool IsClipContext; + + bool IsUseFonts2; + v8::Local* m_oFontManager2; + v8::Local* m_oLastFont2; + + bool ClearMode; + bool IsRetina; + + v8::Local* dash_no_smart; + public: + CGraphics() + { + m_oContext = nullptr; + m_dWidthMM = 0.0; + m_dHeightMM = 0.0; + m_lWidthPix = 0.0; + m_lHeightPix = 0.0; + m_dDpiX = 96.0; + m_dDpiY = 96.0; + m_bIsBreak = false; + + m_oPen = nullptr; // new AscCommon.CPen(); + m_bPenColorInit = false; + m_oBrush = nullptr; // new AscCommon.CBrush(); + m_bBrushColorInit = false; + + m_oFontManager = nullptr; + + m_oCoordTransform = nullptr; // new CMatrixL(); + m_oBaseTransform = nullptr; // new CMatrixL(); + m_oTransform = nullptr; // new CMatrixL(); + m_oFullTransform = nullptr; // new CMatrixL(); + m_oInvertFullTransform = nullptr; // new CMatrixL(); + + ArrayPoints = nullptr; + + m_oTextPr = nullptr; + m_oGrFonts = nullptr; // new AscCommon.CGrRFonts(); + m_oLastFont = nullptr; // new AscCommon.CFontSetup(); + + m_bIntegerGrid = true; + + ClipManager = nullptr; // new AscCommon.CClipManager(); + // ClipManager.BaseObject = this; + + TextureFillTransformScaleX = 1; + TextureFillTransformScaleY = 1; + IsThumbnail = false; + + IsDemonstrationMode = false; + + GrState = nullptr; // new AscCommon.CGrState(); + // GrState.Parent = this; + + globalAlpha = 1; + + TextClipRect = nullptr; + IsClipContext = false; + + IsUseFonts2 = false; + m_oFontManager2 = nullptr; + m_oLastFont2 = nullptr; + + ClearMode = false; + IsRetina = false; + + dash_no_smart = nullptr; + } + ~CGraphics() + { + if(m_oContext) delete m_oContext; + if(m_oPen) delete m_oPen; + if(m_oBrush) delete m_oBrush; + if(m_oFontManager) delete m_oFontManager; + if(m_oCoordTransform) delete m_oCoordTransform; + if(m_oBaseTransform) delete m_oBaseTransform; + if(m_oTransform) delete m_oTransform; + if(m_oFullTransform) delete m_oFullTransform; + if(m_oInvertFullTransform) delete m_oInvertFullTransform; + if(ArrayPoints) delete ArrayPoints; + if(m_oTextPr) delete m_oTextPr; + if(m_oGrFonts) delete m_oGrFonts; + if(m_oLastFont) delete m_oLastFont; + if(LastFontOriginInfo.Replace) delete LastFontOriginInfo.Replace; + if(ClipManager) delete ClipManager; + if(GrState) delete GrState; + if(TextClipRect) delete TextClipRect; + if(m_oFontManager2) delete m_oFontManager2; + if(m_oLastFont2) delete m_oLastFont2; + if(dash_no_smart) delete dash_no_smart; + } + + void init(v8::Local* context, double width_px, double height_px, double width_mm, double height_mm); + void EndDraw() {} + void put_GlobalAlpha(bool enable, int globalAlpha); + void Start_GlobalAlpha() {} + void End_GlobalAlpha(); + // pen methods + void p_color(int r, int g, int b, int a); + void p_width(int w); + void p_dash(const v8::Local& params); + // brush methods + void b_color1(int r, int g, int b, int a); + void b_color2(int r, int g, int b, int a); + void transform(double sx, double shy, double shx, double sy, double tx, double ty); + void CalculateFullTransform(bool isInvertNeed); + // path commands + void _s(); + void _e(); + void _z(); + void _m(double x, double y); + void _l(double x, double y); + void _c(double x1, double y1, double x2, double y2, double x3, double y3); + void _c2(double x1, double y1, double x2, double y2); + void ds(); + void df(); + // canvas state + void save(); + void restore(); + void clip(); + void reset(); + void transform3(const v8::Local& m, bool isNeedInvert); + void FreeFont(); + void ClearLastFont(); + // images + void drawImage2(const v8::Local& img, double x, double y, double w, double h, int alpha, const v8::Local& srcRect); + void drawImage(const v8::Local& img, double x, double y, double w, double h, int alpha, const v8::Local& srcRect, const v8::Local& nativeImage); + // text + CFont GetFont(); + void font(unsigned int font_id, int font_size); + void SetFont(const v8::Local& font); + void SetTextPr(const v8::Local& textPr, const v8::Local& theme); + void SetFontSlot(const v8::Local& slot, double fontSizeKoef); + v8::Local GetTextPr(); + void FillText(double x, double y, const v8::Local& text); + void t(const v8::Local& text, double x, double y, bool isBounds); + void FillText2(double x, double y, const v8::Local& text, double cropX, double cropW); + void t2(const v8::Local& text, double x, double y, double cropX, double cropW); + void FillTextCode(double x, double y, const v8::Local& lUnicode); + void tg(const v8::Local& text, double x, double y); + void charspace(const v8::Local& space) {} + // private methods + void private_FillGlyph(const v8::Local& pGlyph, const v8::Local& _bounds); + void private_FillGlyphC(const v8::Local& pGlyph, double cropX, double cropW); + void private_FillGlyph2(const v8::Local& pGlyph); + void SetIntegerGrid(bool param); + bool GetIntegerGrid(); + void DrawStringASCII(const std::string& name, int size, bool bold, bool italic, const v8::Local& text, double x, double y, bool bIsHeader); + void DrawStringASCII2(const std::string& name, int size, bool bold, bool italic, const v8::Local& text, double x, double y, bool bIsHeader); + void DrawHeaderEdit(double yPos, const v8::Local& lock_type, int sectionNum, bool bIsRepeat, const v8::Local& type); + void DrawFooterEdit(double yPos, const v8::Local& lock_type, int sectionNum, bool bIsRepeat, const v8::Local& type); + void DrawLockParagraph(const v8::Local& lock_type, double x, double y1, double y2); + void DrawLockObjectRect(const v8::Local& lock_type, double x, double y, double w, double h); + void DrawEmptyTableLine(double x1, double y1, double x2, double y2); + void DrawSpellingLine(double y0, double x0, double x1, double w); + // smart methods for horizontal / vertical lines + void drawHorLine(int align, double y, double x, double r, int penW); + void drawHorLine2(int align, double y, double x, double r, int penW); + void drawVerLine(int align, double x, double y, double b, int penW); + // мега крутые функции для таблиц + void drawHorLineExt(int align, double y, double x, double r, int penW, double leftMW, double rightMW); + void rect(double x, double y, double w, double h); + void TableRect(double x, double y, double w, double h); + // функции клиппирования + void AddClipRect(double x, double y, double w, double h); + void RemoveClipRect() {} + void SetClip(const v8::Local& r); + void RemoveClip(); + void drawCollaborativeChanges(double x, double y, double w, double h, const v8::Local& Color); + void drawMailMergeField(double x, double y, double w, double h); + void drawSearchResult(double x, double y, double w, double h); + void drawFlowAnchor(double x, double y); + void SavePen(); + void RestorePen(); + void SaveBrush(); + void RestoreBrush(); + void SavePenBrush(); + void RestorePenBrush(); + void SaveGrState(); + void RestoreGrState(); + void StartClipPath() {} + void EndClipPath(); + void StartCheckTableDraw(); + void EndCheckTableDraw(bool bIsRestore); + void SetTextClipRect(double _l, double _t, double _r, double _b); + void AddSmartRect(double x, double y, double w, double h, int pen_w); + void CheckUseFonts2(const v8::Local& _transform); + void UncheckUseFonts2(); + void Drawing_StartCheckBounds(double x, double y, double w, double h) {} + void Drawing_EndCheckBounds() {} + void DrawPresentationComment(const v8::Local& type, double x, double y, double w, double h); + void DrawPolygon(const v8::Local& oPath, int lineWidth, double shift); + void DrawFootnoteRect(double x, double y, double w, double h); + + v8::Local* g_m_oContext() { return m_oContext; } + v8::Local* g_m_oPen() { return m_oPen; } + v8::Local* g_m_oBrush() { return m_oBrush; } + v8::Local* g_m_oFontManager() { return m_oFontManager; } + v8::Local* g_m_oCoordTransform() { return m_oCoordTransform; } + v8::Local* g_m_oBaseTransform() { return m_oBaseTransform; } + v8::Local* g_m_oTransform() { return m_oTransform; } + v8::Local* g_m_oFullTransform() { return m_oFullTransform; } + v8::Local* g_m_oInvertFullTransform() { return m_oInvertFullTransform; } + v8::Local* g_ArrayPoints() { return ArrayPoints; } + v8::Local* g_m_oTextPr() { return m_oTextPr; } + v8::Local* g_m_oGrFonts() { return m_oGrFonts; } + v8::Local* g_m_oLastFont() { return m_oLastFont; } + v8::Local* g_ClipManager() { return ClipManager; } + v8::Local* g_GrState() { return GrState; } + v8::Local* g_TextClipRect() { return TextClipRect; } + v8::Local* g_m_oFontManager2() { return m_oFontManager2; } + v8::Local* g_m_oLastFont2() { return m_oLastFont2; } + v8::Local* g_dash_no_smart() { return dash_no_smart; } + double g_m_dWidthMM() { return m_dWidthMM; } + double g_m_dHeightMM() { return m_dHeightMM; } + double g_m_lWidthPix() { return m_lWidthPix; } + double g_m_lHeightPix() { return m_lHeightPix; } + double g_m_dDpiX() { return m_dDpiX; } + double g_m_dDpiY() { return m_dDpiY; } + bool g_m_bIsBreak() { return m_bIsBreak; } + bool g_m_bPenColorInit() { return m_bPenColorInit; } + bool g_m_bBrushColorInit() { return m_bBrushColorInit; } + bool g_m_bIntegerGrid() { return m_bIntegerGrid; } + bool g_IsThumbnail() { return IsThumbnail; } + bool g_IsDemonstrationMode() { return IsDemonstrationMode; } + bool g_IsClipContext() { return IsClipContext; } + bool g_IsUseFonts2() { return IsUseFonts2; } + bool g_ClearMode() { return ClearMode; } + bool g_IsRetina() { return IsRetina; } + CFont g_m_oCurFont() { return m_oCurFont; } + CLastFontOriginInfo g_LastFontOriginInfo() { return LastFontOriginInfo; } + int g_TextureFillTransformScaleX() { return TextureFillTransformScaleX; } + int g_TextureFillTransformScaleY() { return TextureFillTransformScaleY; } + int g_globalAlpha() { return globalAlpha; } + + void s_m_oContext (v8::Local* a) { m_oContext = a; } + void s_m_oPen (v8::Local* a) { m_oPen = a; } + void s_m_oBrush (v8::Local* a) { m_oBrush = a; } + void s_m_oFontManager (v8::Local* a) { m_oFontManager = a; } + void s_m_oCoordTransform (v8::Local* a) { m_oCoordTransform = a; } + void s_m_oBaseTransform (v8::Local* a) { m_oBaseTransform = a; } + void s_m_oTransform (v8::Local* a) { m_oTransform = a; } + void s_m_oFullTransform (v8::Local* a) { m_oFullTransform = a; } + void s_m_oInvertFullTransform(v8::Local* a) { m_oInvertFullTransform = a; } + void s_ArrayPoints (v8::Local* a) { ArrayPoints = a; } + void s_m_oTextPr (v8::Local* a) { m_oTextPr = a; } + void s_m_oGrFonts (v8::Local* a) { m_oGrFonts = a; } + void s_m_oLastFont (v8::Local* a) { m_oLastFont = a; } + void s_ClipManager (v8::Local* a) { ClipManager = a; } + void s_GrState (v8::Local* a) { GrState = a; } + void s_TextClipRect (v8::Local* a) { TextClipRect = a; } + void s_m_oFontManager2 (v8::Local* a) { m_oFontManager2 = a; } + void s_m_oLastFont2 (v8::Local* a) { m_oLastFont2 = a; } + void s_dash_no_smart (v8::Local* a) { dash_no_smart = a; } + void s_m_dWidthMM (double a) { m_dWidthMM = a; } + void s_m_dHeightMM (double a) { m_dHeightMM = a; } + void s_m_lWidthPix (double a) { m_lWidthPix = a; } + void s_m_lHeightPix (double a) { m_lHeightPix = a; } + void s_m_dDpiX (double a) { m_dDpiX = a; } + void s_m_dDpiY (double a) { m_dDpiY = a; } + void s_m_bIsBreak (bool a) { m_bIsBreak = a; } + void s_m_bPenColorInit (bool a) { m_bPenColorInit = a; } + void s_m_bBrushColorInit (bool a) { m_bBrushColorInit = a; } + void s_m_bIntegerGrid (bool a) { m_bIntegerGrid = a; } + void s_IsThumbnail (bool a) { IsThumbnail = a; } + void s_IsDemonstrationMode(bool a) { IsDemonstrationMode = a; } + void s_IsClipContext (bool a) { IsClipContext = a; } + void s_IsUseFonts2 (bool a) { IsUseFonts2 = a; } + void s_ClearMode (bool a) { ClearMode = a; } + void s_IsRetina (bool a) { IsRetina = a; } + void s_m_oCurFont (CFont a) { m_oCurFont = a; } + void s_LastFontOriginInfo(CLastFontOriginInfo a) { LastFontOriginInfo = a; } + void s_TextureFillTransformScaleX(int a) { TextureFillTransformScaleX = a; } + void s_TextureFillTransformScaleY(int a) { TextureFillTransformScaleY = a; } + void s_globalAlpha (int a) { globalAlpha = a; } + }; +} + +#endif // CGRAPHICS_H diff --git a/DesktopEditor/doctrenderer/js_internal/embed/GraphicsEmbed.cpp b/DesktopEditor/doctrenderer/js_internal/embed/GraphicsEmbed.cpp new file mode 100644 index 0000000000..a2f2219629 --- /dev/null +++ b/DesktopEditor/doctrenderer/js_internal/embed/GraphicsEmbed.cpp @@ -0,0 +1,97 @@ +#include "./GraphicsEmbed.h" + +JSSmart CGraphicsEmbed::init(JSSmart context, JSSmart width_px, JSSmart height_px, JSSmart width_mm, JSSmart height_mm) +{ + m_pInternal->init(context->toObject(), width_px->toDouble(), height_px->toDouble(), width_mm->toDouble(), height_mm->toDouble()); + return NULL; +} +JSSmart CGraphicsEmbed::EndDraw() {} +JSSmart CGraphicsEmbed::put_GlobalAlpha(JSSmart enable, JSSmart globalAlpha); +JSSmart CGraphicsEmbed::Start_GlobalAlpha() {} +JSSmart CGraphicsEmbed::End_GlobalAlpha(); +JSSmart CGraphicsEmbed::p_color(JSSmart r, JSSmart g, JSSmart b, JSSmart a); +JSSmart CGraphicsEmbed::p_width(JSSmart w); +JSSmart CGraphicsEmbed::p_dash(JSSmart params); +JSSmart CGraphicsEmbed::b_color1(JSSmart r, JSSmart g, JSSmart b, JSSmart a); +JSSmart CGraphicsEmbed::b_color2(JSSmart r, JSSmart g, JSSmart b, JSSmart a); +JSSmart CGraphicsEmbed::transform(JSSmart sx, JSSmart shy, JSSmart shx, JSSmart sy, JSSmart tx, JSSmart ty); +JSSmart CGraphicsEmbed::CalculateFullTransform(JSSmart isInvertNeed); +JSSmart CGraphicsEmbed::_s(); +JSSmart CGraphicsEmbed::_e(); +JSSmart CGraphicsEmbed::_z(); +JSSmart CGraphicsEmbed::_m (JSSmart x, JSSmart y); +JSSmart CGraphicsEmbed::_l (JSSmart x, JSSmart y); +JSSmart CGraphicsEmbed::_c (JSSmart x1, JSSmart y1, JSSmart x2, JSSmart y2, JSSmart x3, JSSmart y3); +JSSmart CGraphicsEmbed::_c2(JSSmart x1, JSSmart y1, JSSmart x2, JSSmart y2); +JSSmart CGraphicsEmbed::ds(); +JSSmart CGraphicsEmbed::df(); +JSSmart CGraphicsEmbed::save(); +JSSmart CGraphicsEmbed::restore(); +JSSmart CGraphicsEmbed::clip(); +JSSmart CGraphicsEmbed::reset(); +JSSmart CGraphicsEmbed::transform3(JSSmart m, JSSmart isNeedInvert); +JSSmart CGraphicsEmbed::FreeFont(); +JSSmart CGraphicsEmbed::ClearLastFont(); +JSSmart CGraphicsEmbed::drawImage2(JSSmart img, JSSmart x, JSSmart y, JSSmart w, JSSmart h, JSSmart alpha, JSSmart srcRect); +JSSmart CGraphicsEmbed::drawImage (JSSmart img, JSSmart x, JSSmart y, JSSmart w, JSSmart h, JSSmart alpha, JSSmart srcRect, JSSmart nativeImage); +JSSmart CGraphicsEmbed::GetFont(); +JSSmart CGraphicsEmbed::font(JSSmart font_id, JSSmart font_size); +JSSmart CGraphicsEmbed::SetFont(JSSmart font); +JSSmart CGraphicsEmbed::SetTextPr(JSSmart textPr, JSSmart theme); +JSSmart CGraphicsEmbed::SetFontSlot(JSSmart slot, JSSmart fontSizeKoef); +JSSmart CGraphicsEmbed::GetTextPr(); +JSSmart CGraphicsEmbed::FillText(JSSmart x, JSSmart y, JSSmart text); +JSSmart CGraphicsEmbed::t(JSSmart text, JSSmart x, JSSmart y, JSSmart isBounds); +JSSmart CGraphicsEmbed::FillText2(JSSmart x, JSSmart y, JSSmart text, JSSmart cropX, JSSmart cropW); +JSSmart CGraphicsEmbed::t2(JSSmart text, JSSmart x, JSSmart y, JSSmart cropX, JSSmart cropW); +JSSmart CGraphicsEmbed::FillTextCode(JSSmart x, JSSmart y, JSSmart lUnicode); +JSSmart CGraphicsEmbed::tg(JSSmart text, JSSmart x, JSSmart y); +JSSmart CGraphicsEmbed::charspace(JSSmart space) {} +JSSmart CGraphicsEmbed::private_FillGlyph (JSSmart pGlyph, JSSmart _bounds); +JSSmart CGraphicsEmbed::private_FillGlyphC(JSSmart pGlyph, JSSmart cropX, JSSmart cropW); +JSSmart CGraphicsEmbed::private_FillGlyph2(JSSmart pGlyph); +JSSmart CGraphicsEmbed::SetIntegerGrid(JSSmart param); +JSSmart CGraphicsEmbed::GetIntegerGrid(); +JSSmart CGraphicsEmbed::DrawStringASCII (JSSmart name, JSSmart size, JSSmart bold, JSSmart italic, JSSmart text, JSSmart x, JSSmart y, JSSmart bIsHeader); +JSSmart CGraphicsEmbed::DrawStringASCII2(JSSmart name, JSSmart size, JSSmart bold, JSSmart italic, JSSmart text, JSSmart x, JSSmart y, JSSmart bIsHeader); +JSSmart CGraphicsEmbed::DrawHeaderEdit(JSSmart yPos, JSSmart lock_type, JSSmart sectionNum, JSSmart bIsRepeat, JSSmart type); +JSSmart CGraphicsEmbed::DrawFooterEdit(JSSmart yPos, JSSmart lock_type, JSSmart sectionNum, JSSmart bIsRepeat, JSSmart type); +JSSmart CGraphicsEmbed::DrawLockParagraph (JSSmart lock_type, JSSmart x, JSSmart y1, JSSmart y2); +JSSmart CGraphicsEmbed::DrawLockObjectRect(JSSmart lock_type, JSSmart x, JSSmart y, JSSmart w, JSSmart h); +JSSmart CGraphicsEmbed::DrawEmptyTableLine(JSSmart x1, JSSmart y1, JSSmart x2, JSSmart y2); +JSSmart CGraphicsEmbed::DrawSpellingLine (JSSmart y0, JSSmart x0, JSSmart x1, JSSmart w); +JSSmart CGraphicsEmbed::drawHorLine (JSSmart align, JSSmart y, JSSmart x, JSSmart r, JSSmart penW); +JSSmart CGraphicsEmbed::drawHorLine2(JSSmart align, JSSmart y, JSSmart x, JSSmart r, JSSmart penW); +JSSmart CGraphicsEmbed::drawVerLine (JSSmart align, JSSmart x, JSSmart y, JSSmart b, JSSmart penW); +JSSmart CGraphicsEmbed::drawHorLineExt(JSSmart align, JSSmart y, JSSmart x, JSSmart r, JSSmart penW, JSSmart leftMW, JSSmart rightMW); +JSSmart CGraphicsEmbed::rect (JSSmart x, JSSmart y, JSSmart w, JSSmart h); +JSSmart CGraphicsEmbed::TableRect(JSSmart x, JSSmart y, JSSmart w, JSSmart h); +JSSmart CGraphicsEmbed::AddClipRect(JSSmart x, JSSmart y, JSSmart w, JSSmart h); +JSSmart CGraphicsEmbed::RemoveClipRect() {} +JSSmart CGraphicsEmbed::SetClip(JSSmart r); +JSSmart CGraphicsEmbed::RemoveClip(); +JSSmart CGraphicsEmbed::drawCollaborativeChanges(JSSmart x, JSSmart y, JSSmart w, JSSmart h, JSSmart Color); +JSSmart CGraphicsEmbed::drawMailMergeField(JSSmart x, JSSmart y, JSSmart w, JSSmart h); +JSSmart CGraphicsEmbed::drawSearchResult (JSSmart x, JSSmart y, JSSmart w, JSSmart h); +JSSmart CGraphicsEmbed::drawFlowAnchor (JSSmart x, JSSmart y); +JSSmart CGraphicsEmbed::SavePen(); +JSSmart CGraphicsEmbed::RestorePen(); +JSSmart CGraphicsEmbed::SaveBrush(); +JSSmart CGraphicsEmbed::RestoreBrush(); +JSSmart CGraphicsEmbed::SavePenBrush(); +JSSmart CGraphicsEmbed::RestorePenBrush(); +JSSmart CGraphicsEmbed::SaveGrState(); +JSSmart CGraphicsEmbed::RestoreGrState(); +JSSmart CGraphicsEmbed::StartClipPath() {} +JSSmart CGraphicsEmbed::EndClipPath(); +JSSmart CGraphicsEmbed::StartCheckTableDraw(); +JSSmart CGraphicsEmbed::EndCheckTableDraw(JSSmart bIsRestore); +JSSmart CGraphicsEmbed::SetTextClipRect(JSSmart _l, JSSmart _t, JSSmart _r, JSSmart _b); +JSSmart CGraphicsEmbed::AddSmartRect (JSSmart x, JSSmart y, JSSmart w, JSSmart h, JSSmart pen_w); +JSSmart CGraphicsEmbed::CheckUseFonts2 (JSSmart _transform); +JSSmart CGraphicsEmbed::UncheckUseFonts2(); +JSSmart CGraphicsEmbed::Drawing_StartCheckBounds(JSSmart x, JSSmart y, JSSmart w, JSSmart h) {} +JSSmart CGraphicsEmbed::Drawing_EndCheckBounds() {} +JSSmart CGraphicsEmbed::DrawPresentationComment(JSSmart type, JSSmart x, JSSmart y, JSSmart w, JSSmart h); +JSSmart CGraphicsEmbed::DrawPolygon(JSSmart oPath, JSSmart lineWidth, JSSmart shift); +JSSmart CGraphicsEmbed::DrawFootnoteRect(JSSmart x, JSSmart y, JSSmart w, JSSmart h); diff --git a/DesktopEditor/doctrenderer/js_internal/embed/GraphicsEmbed.h b/DesktopEditor/doctrenderer/js_internal/embed/GraphicsEmbed.h new file mode 100644 index 0000000000..8ef385cb3e --- /dev/null +++ b/DesktopEditor/doctrenderer/js_internal/embed/GraphicsEmbed.h @@ -0,0 +1,125 @@ +#ifndef _BUILD_NATIVE_GRAPHICS_EMBED_H_ +#define _BUILD_NATIVE_GRAPHICS_EMBED_H_ + +#include "../../graphics.h" +#include "../js_base.h" + +using namespace NSJSBase; +class CGraphicsEmbed : public CJSEmbedObject +{ +public: + NSGraphics::CGraphics* m_pInternal; + +public: + CGraphicsEmbed() : m_pInternal(new NSGraphics::CGraphics()) {} + ~CGraphicsEmbed() { RELEASEOBJECT(m_pInternal); } + + virtual void* getObject() { return (void*)m_pInternal; } + +public: + JSSmart init(JSSmart context, JSSmart width_px, JSSmart height_px, JSSmart width_mm, JSSmart height_mm); + JSSmart EndDraw() {} + JSSmart put_GlobalAlpha(JSSmart enable, JSSmart globalAlpha); + JSSmart Start_GlobalAlpha() {} + JSSmart End_GlobalAlpha(); + // pen methods + JSSmart p_color(JSSmart r, JSSmart g, JSSmart b, JSSmart a); + JSSmart p_width(JSSmart w); + JSSmart p_dash(JSSmart params); + // brush methods + JSSmart b_color1(JSSmart r, JSSmart g, JSSmart b, JSSmart a); + JSSmart b_color2(JSSmart r, JSSmart g, JSSmart b, JSSmart a); + JSSmart transform(JSSmart sx, JSSmart shy, JSSmart shx, JSSmart sy, JSSmart tx, JSSmart ty); + JSSmart CalculateFullTransform(JSSmart isInvertNeed); + // path commands + JSSmart _s(); + JSSmart _e(); + JSSmart _z(); + JSSmart _m (JSSmart x, JSSmart y); + JSSmart _l (JSSmart x, JSSmart y); + JSSmart _c (JSSmart x1, JSSmart y1, JSSmart x2, JSSmart y2, JSSmart x3, JSSmart y3); + JSSmart _c2(JSSmart x1, JSSmart y1, JSSmart x2, JSSmart y2); + JSSmart ds(); + JSSmart df(); + // canvas state + JSSmart save(); + JSSmart restore(); + JSSmart clip(); + JSSmart reset(); + JSSmart transform3(JSSmart m, JSSmart isNeedInvert); + JSSmart FreeFont(); + JSSmart ClearLastFont(); + // images + JSSmart drawImage2(JSSmart img, JSSmart x, JSSmart y, JSSmart w, JSSmart h, JSSmart alpha, JSSmart srcRect); + JSSmart drawImage (JSSmart img, JSSmart x, JSSmart y, JSSmart w, JSSmart h, JSSmart alpha, JSSmart srcRect, JSSmart nativeImage); + // text + JSSmart GetFont(); + JSSmart font(JSSmart font_id, JSSmart font_size); + JSSmart SetFont(JSSmart font); + JSSmart SetTextPr(JSSmart textPr, JSSmart theme); + JSSmart SetFontSlot(JSSmart slot, JSSmart fontSizeKoef); + JSSmart GetTextPr(); + JSSmart FillText(JSSmart x, JSSmart y, JSSmart text); + JSSmart t(JSSmart text, JSSmart x, JSSmart y, JSSmart isBounds); + JSSmart FillText2(JSSmart x, JSSmart y, JSSmart text, JSSmart cropX, JSSmart cropW); + JSSmart t2(JSSmart text, JSSmart x, JSSmart y, JSSmart cropX, JSSmart cropW); + JSSmart FillTextCode(JSSmart x, JSSmart y, JSSmart lUnicode); + JSSmart tg(JSSmart text, JSSmart x, JSSmart y); + JSSmart charspace(JSSmart space) {} + // private methods + JSSmart private_FillGlyph (JSSmart pGlyph, JSSmart _bounds); + JSSmart private_FillGlyphC(JSSmart pGlyph, JSSmart cropX, JSSmart cropW); + JSSmart private_FillGlyph2(JSSmart pGlyph); + JSSmart SetIntegerGrid(JSSmart param); + JSSmart GetIntegerGrid(); + JSSmart DrawStringASCII (JSSmart name, JSSmart size, JSSmart bold, JSSmart italic, JSSmart text, JSSmart x, JSSmart y, JSSmart bIsHeader); + JSSmart DrawStringASCII2(JSSmart name, JSSmart size, JSSmart bold, JSSmart italic, JSSmart text, JSSmart x, JSSmart y, JSSmart bIsHeader); + JSSmart DrawHeaderEdit(JSSmart yPos, JSSmart lock_type, JSSmart sectionNum, JSSmart bIsRepeat, JSSmart type); + JSSmart DrawFooterEdit(JSSmart yPos, JSSmart lock_type, JSSmart sectionNum, JSSmart bIsRepeat, JSSmart type); + JSSmart DrawLockParagraph (JSSmart lock_type, JSSmart x, JSSmart y1, JSSmart y2); + JSSmart DrawLockObjectRect(JSSmart lock_type, JSSmart x, JSSmart y, JSSmart w, JSSmart h); + JSSmart DrawEmptyTableLine(JSSmart x1, JSSmart y1, JSSmart x2, JSSmart y2); + JSSmart DrawSpellingLine (JSSmart y0, JSSmart x0, JSSmart x1, JSSmart w); + // smart methods for horizontal / vertical lines + JSSmart drawHorLine (JSSmart align, JSSmart y, JSSmart x, JSSmart r, JSSmart penW); + JSSmart drawHorLine2(JSSmart align, JSSmart y, JSSmart x, JSSmart r, JSSmart penW); + JSSmart drawVerLine (JSSmart align, JSSmart x, JSSmart y, JSSmart b, JSSmart penW); + // мега крутые функции для таблиц + JSSmart drawHorLineExt(JSSmart align, JSSmart y, JSSmart x, JSSmart r, JSSmart penW, JSSmart leftMW, JSSmart rightMW); + JSSmart rect (JSSmart x, JSSmart y, JSSmart w, JSSmart h); + JSSmart TableRect(JSSmart x, JSSmart y, JSSmart w, JSSmart h); + // функции клиппирования + JSSmart AddClipRect(JSSmart x, JSSmart y, JSSmart w, JSSmart h); + JSSmart RemoveClipRect() {} + JSSmart SetClip(JSSmart r); + JSSmart RemoveClip(); + JSSmart drawCollaborativeChanges(JSSmart x, JSSmart y, JSSmart w, JSSmart h, JSSmart Color); + JSSmart drawMailMergeField(JSSmart x, JSSmart y, JSSmart w, JSSmart h); + JSSmart drawSearchResult (JSSmart x, JSSmart y, JSSmart w, JSSmart h); + JSSmart drawFlowAnchor (JSSmart x, JSSmart y); + JSSmart SavePen(); + JSSmart RestorePen(); + JSSmart SaveBrush(); + JSSmart RestoreBrush(); + JSSmart SavePenBrush(); + JSSmart RestorePenBrush(); + JSSmart SaveGrState(); + JSSmart RestoreGrState(); + JSSmart StartClipPath() {} + JSSmart EndClipPath(); + JSSmart StartCheckTableDraw(); + JSSmart EndCheckTableDraw(JSSmart bIsRestore); + JSSmart SetTextClipRect(JSSmart _l, JSSmart _t, JSSmart _r, JSSmart _b); + JSSmart AddSmartRect (JSSmart x, JSSmart y, JSSmart w, JSSmart h, JSSmart pen_w); + JSSmart CheckUseFonts2 (JSSmart _transform); + JSSmart UncheckUseFonts2(); + JSSmart Drawing_StartCheckBounds(JSSmart x, JSSmart y, JSSmart w, JSSmart h) {} + JSSmart Drawing_EndCheckBounds() {} + JSSmart DrawPresentationComment(JSSmart type, JSSmart x, JSSmart y, JSSmart w, JSSmart h); + JSSmart DrawPolygon(JSSmart oPath, JSSmart lineWidth, JSSmart shift); + JSSmart DrawFootnoteRect(JSSmart x, JSSmart y, JSSmart w, JSSmart h); + + static void CreateObjectInContext(const std::string& name, JSSmart context); +}; + +#endif // _BUILD_NATIVE_GRAPHICS_EMBED_H_ diff --git a/DesktopEditor/doctrenderer/jsgraphics/graphics_wrapper.cpp b/DesktopEditor/doctrenderer/js_internal/embed/v8/v8_Graphics.cpp similarity index 74% rename from DesktopEditor/doctrenderer/jsgraphics/graphics_wrapper.cpp rename to DesktopEditor/doctrenderer/js_internal/embed/v8/v8_Graphics.cpp index 072756b5af..7a79b0759c 100644 --- a/DesktopEditor/doctrenderer/jsgraphics/graphics_wrapper.cpp +++ b/DesktopEditor/doctrenderer/js_internal/embed/v8/v8_Graphics.cpp @@ -1,47 +1,344 @@ -#include "graphics_wrapper.h" +#include "../GraphicsEmbed.h" +#include "../../v8/v8_base.h" -#include +#define PROPERTY_GET(NAME, NAME_EMBED, TYPE) \ + void NAME(v8::Local _name, const v8::PropertyCallbackInfo& info) \ + { \ + CURRENTWRAPPER* _this = (CURRENTWRAPPER*)unwrap_native(info.Holder()); \ + info.GetReturnValue().Set(TYPE::New(v8::Isolate::GetCurrent(), _this->->m_pInternal->NAME_EMBED())) \ + } -static double to_double(const v8::Local& v) +#define PROPERTY_GET_OBJECT(NAME, NAME_EMBED) \ + void NAME(v8::Local _name, const v8::PropertyCallbackInfo& info) \ + { \ + CURRENTWRAPPER* _this = (CURRENTWRAPPER*)unwrap_native(info.Holder()); \ + v8::Local* v = _this->m_pInternal->NAME_EMBED(); \ + if(v) info.GetReturnValue().Set(*v); \ + else info.GetReturnValue().Set(v8::Undefined(v8::Isolate::GetCurrent())); \ + } + +namespace NSGraphics { - return v->ToNumber(v8::Isolate::GetCurrent()->GetCurrentContext()).FromMaybe(v8::Local())->Value(); -} -static bool to_bool (const v8::Local& v) -{ - return v->ToBoolean(v8::Isolate::GetCurrent()->GetCurrentContext()).FromMaybe(v8::Local())->Value(); -} -static int to_int (const v8::Local& v) -{ - return v->ToInt32(v8::Isolate::GetCurrent()->GetCurrentContext()).FromMaybe(v8::Local())->Value(); -} -static unsigned int to_uint (const v8::Local& v) -{ - return v->ToUint32(v8::Isolate::GetCurrent()->GetCurrentContext()).FromMaybe(v8::Local())->Value(); -} -static std::string to_string(const v8::Local& v) -{ - v8::String::Utf8Value data(v); - const char* p = *data; - if (p == NULL) return std::string(); - return std::string(p); + #define CURRENTWRAPPER CGraphicsEmbed + + // FUNCTION + FUNCTION_WRAPPER_V8_5(_init, init) + FUNCTION_WRAPPER_V8 (_EndDraw, EndDraw) + FUNCTION_WRAPPER_V8_2(_put_GlobalAlpha, put_GlobalAlpha) + FUNCTION_WRAPPER_V8 (_Start_GlobalAlpha, Start_GlobalAlpha) + FUNCTION_WRAPPER_V8 (_End_GlobalAlpha, End_GlobalAlpha) + // pen methods + FUNCTION_WRAPPER_V8_4(_p_color, p_color) + FUNCTION_WRAPPER_V8_1(_p_width, p_width) + FUNCTION_WRAPPER_V8_1(_p_dash, p_dash) + // brush methods + FUNCTION_WRAPPER_V8_4(_b_color1, b_color1) + FUNCTION_WRAPPER_V8_4(_b_color2, b_color2) + FUNCTION_WRAPPER_V8_6(_transform, transform) + FUNCTION_WRAPPER_V8_1(_CalculateFullTransform, CalculateFullTransform) + // path commands + FUNCTION_WRAPPER_V8 (__s, _s) + FUNCTION_WRAPPER_V8 (__e, _e) + FUNCTION_WRAPPER_V8 (__z, _z) + FUNCTION_WRAPPER_V8_2(__m, _m) + FUNCTION_WRAPPER_V8_2(__l, _l) + FUNCTION_WRAPPER_V8_6(__c, _c) + FUNCTION_WRAPPER_V8_4(__c2, _c2) + FUNCTION_WRAPPER_V8 (_ds, ds) + FUNCTION_WRAPPER_V8 (_df, df) + // canvas state + FUNCTION_WRAPPER_V8 (_save, save) + FUNCTION_WRAPPER_V8 (_restore, restore) + FUNCTION_WRAPPER_V8 (_clip, clip) + FUNCTION_WRAPPER_V8 (_reset, reset) + FUNCTION_WRAPPER_V8_2(_transform3, transform3) + FUNCTION_WRAPPER_V8 (_FreeFont, FreeFont) + FUNCTION_WRAPPER_V8 (_ClearLastFont, ClearLastFont) + // images + FUNCTION_WRAPPER_V8_7(_drawImage2, drawImage2) + FUNCTION_WRAPPER_V8_8(_drawImage, drawImage) + // text + FUNCTION_WRAPPER_V8 (_GetFont, GetFont) + FUNCTION_WRAPPER_V8_2(_font, font) + FUNCTION_WRAPPER_V8_1(_SetFont, SetFont) + FUNCTION_WRAPPER_V8_2(_SetTextPr, SetTextPr) + FUNCTION_WRAPPER_V8_2(_SetFontSlot, SetFontSlot) + FUNCTION_WRAPPER_V8 (_GetTextPr, GetTextPr) + FUNCTION_WRAPPER_V8_3(_FillText, FillText) + FUNCTION_WRAPPER_V8_4(_t, t) + FUNCTION_WRAPPER_V8_5(_FillText2, FillText2) + FUNCTION_WRAPPER_V8_5(_t2, t2) + FUNCTION_WRAPPER_V8_3(_FillTextCode, FillTextCode) + FUNCTION_WRAPPER_V8_3(_tg, tg) + FUNCTION_WRAPPER_V8_1(_charspace, charspace) + // private methods + FUNCTION_WRAPPER_V8_2(_private_FillGlyph, private_FillGlyph) + FUNCTION_WRAPPER_V8_3(_private_FillGlyphC, private_FillGlyphC) + FUNCTION_WRAPPER_V8_1(_private_FillGlyph2, private_FillGlyph2) + FUNCTION_WRAPPER_V8_1(_SetIntegerGrid, SetIntegerGrid) + FUNCTION_WRAPPER_V8 (_GetIntegerGrid, GetIntegerGrid) + FUNCTION_WRAPPER_V8_8(_DrawStringASCII, DrawStringASCII) + FUNCTION_WRAPPER_V8_8(_DrawStringASCII2, DrawStringASCII2) + FUNCTION_WRAPPER_V8_5(_DrawHeaderEdit, DrawHeaderEdit) + FUNCTION_WRAPPER_V8_5(_DrawFooterEdit, DrawFooterEdit) + FUNCTION_WRAPPER_V8_4(_DrawLockParagraph, DrawLockParagraph) + FUNCTION_WRAPPER_V8_5(_DrawLockObjectRect, DrawLockObjectRect) + FUNCTION_WRAPPER_V8_4(_DrawEmptyTableLine, DrawEmptyTableLine) + FUNCTION_WRAPPER_V8_4(_DrawSpellingLine, DrawSpellingLine) + // smart methods for horizontal / vertical lines + FUNCTION_WRAPPER_V8_5(_drawHorLine, drawHorLine) + FUNCTION_WRAPPER_V8_5(_drawHorLine2, drawHorLine2) + FUNCTION_WRAPPER_V8_5(_drawVerLine, drawVerLine) + // мега крутые функции для таблиц + FUNCTION_WRAPPER_V8_7(_drawHorLineExt, drawHorLineExt) + FUNCTION_WRAPPER_V8_4(_rect, rect) + FUNCTION_WRAPPER_V8_4(_TableRect, TableRect) + // функции клиппирования + FUNCTION_WRAPPER_V8_4(_AddClipRect, AddClipRect) + FUNCTION_WRAPPER_V8 (_RemoveClipRect, RemoveClipRect) + FUNCTION_WRAPPER_V8_1(_SetClip, SetClip) + FUNCTION_WRAPPER_V8 (_RemoveClip, RemoveClip) + FUNCTION_WRAPPER_V8_5(_drawCollaborativeChanges, drawCollaborativeChanges) + FUNCTION_WRAPPER_V8_4(_drawMailMergeField, drawMailMergeField) + FUNCTION_WRAPPER_V8_4(_drawSearchResult, drawSearchResult) + FUNCTION_WRAPPER_V8_2(_drawFlowAnchor, drawFlowAnchor) + FUNCTION_WRAPPER_V8 (_SavePen, SavePen) + FUNCTION_WRAPPER_V8 (_RestorePen, RestorePen) + FUNCTION_WRAPPER_V8 (_SaveBrush, SaveBrush) + FUNCTION_WRAPPER_V8 (_RestoreBrush, RestoreBrush) + FUNCTION_WRAPPER_V8 (_SavePenBrush, SavePenBrush) + FUNCTION_WRAPPER_V8 (_RestorePenBrush, RestorePenBrush) + FUNCTION_WRAPPER_V8 (_SaveGrState, SaveGrState) + FUNCTION_WRAPPER_V8 (_RestoreGrState, RestoreGrState) + FUNCTION_WRAPPER_V8 (_StartClipPath, StartClipPath) + FUNCTION_WRAPPER_V8 (_EndClipPath, EndClipPath) + FUNCTION_WRAPPER_V8 (_StartCheckTableDraw, StartCheckTableDraw) + FUNCTION_WRAPPER_V8_1(_EndCheckTableDraw, EndCheckTableDraw) + FUNCTION_WRAPPER_V8_4(_SetTextClipRect, SetTextClipRect) + FUNCTION_WRAPPER_V8_5(_AddSmartRect, AddSmartRect) + FUNCTION_WRAPPER_V8_1(_CheckUseFonts2, CheckUseFonts2) + FUNCTION_WRAPPER_V8 (_UncheckUseFonts2, UncheckUseFonts2) + FUNCTION_WRAPPER_V8_4(_Drawing_StartCheckBounds, Drawing_StartCheckBounds) + FUNCTION_WRAPPER_V8 (_Drawing_EndCheckBounds, Drawing_EndCheckBounds) + FUNCTION_WRAPPER_V8_5(_DrawPresentationComment, DrawPresentationComment) + FUNCTION_WRAPPER_V8_3(_DrawPolygon, DrawPolygon) + FUNCTION_WRAPPER_V8_4(_DrawFootnoteRect, DrawFootnoteRect) + + // PROPERTY GET + PROPERTY_GET_OBJECT(_g_m_oContext, g_m_oContext) + PROPERTY_GET_OBJECT(_g_m_oPen, g_m_oPen) + PROPERTY_GET_OBJECT(_g_m_oBrush, g_m_oBrush) + PROPERTY_GET_OBJECT(_g_m_oFontManager, g_m_oFontManager) + PROPERTY_GET_OBJECT(_g_m_oCoordTransform, g_m_oCoordTransform) + PROPERTY_GET_OBJECT(_g_m_oBaseTransform, g_m_oBaseTransform) + PROPERTY_GET_OBJECT(_g_m_oTransform, g_m_oTransform) + PROPERTY_GET_OBJECT(_g_m_oFullTransform, g_m_oFullTransform) + PROPERTY_GET_OBJECT(_g_m_oInvertFullTransform, g_m_oInvertFullTransform) + PROPERTY_GET_OBJECT(_g_ArrayPoints, g_ArrayPoints) + PROPERTY_GET_OBJECT(_g_m_oTextPr, g_m_oTextPr) + PROPERTY_GET_OBJECT(_g_m_oGrFonts, g_m_oGrFonts) + PROPERTY_GET_OBJECT(_g_m_oLastFont, g_m_oLastFont) + PROPERTY_GET_OBJECT(_g_ClipManager, g_ClipManager) + PROPERTY_GET_OBJECT(_g_GrState, g_GrState) + PROPERTY_GET_OBJECT(_g_TextClipRect, g_TextClipRect) + PROPERTY_GET_OBJECT(_g_m_oFontManager2, g_m_oFontManager2) + PROPERTY_GET_OBJECT(_g_m_oLastFont2, g_m_oLastFont2) + PROPERTY_GET_OBJECT(_g_dash_no_smart, g_dash_no_smart) + /* + double m_dWidthMM_get() { return m_dWidthMM; } + double m_dHeightMM_get() { return m_dHeightMM; } + double m_lWidthPix_get() { return m_lWidthPix; } + double m_lHeightPix_get() { return m_lHeightPix; } + double m_dDpiX_get() { return m_dDpiX; } + double m_dDpiY_get() { return m_dDpiY; } + bool m_bIsBreak_get() { return m_bIsBreak; } + bool m_bPenColorInit_get() { return m_bPenColorInit; } + bool m_bBrushColorInit_get() { return m_bBrushColorInit; } + bool m_bIntegerGrid_get() { return m_bIntegerGrid; } + bool IsThumbnail_get() { return IsThumbnail; } + bool IsDemonstrationMode_get() { return IsDemonstrationMode; } + bool IsClipContext_get() { return IsClipContext; } + bool IsUseFonts2_get() { return IsUseFonts2; } + bool ClearMode_get() { return ClearMode; } + bool IsRetina_get() { return IsRetina; } + CFont m_oCurFont_get() { return m_oCurFont; } + CLastFontOriginInfo LastFontOriginInfo_get() { return LastFontOriginInfo; } + int TextureFillTransformScaleX_get() { return TextureFillTransformScaleX; } + int TextureFillTransformScaleY_get() { return TextureFillTransformScaleY; } + int globalAlpha_get() { return globalAlpha; } + */ + + v8::Handle CreateGraphicsTemplate(v8::Isolate* isolate) + { + v8::EscapableHandleScope handle_scope(isolate); + + v8::Local result = v8::ObjectTemplate::New(); + result->SetInternalFieldCount(1); + + v8::Isolate* current = v8::Isolate::GetCurrent(); + + // свойства + /* + result->SetAccessor(v8::String::NewFromUtf8(current, "m_oContext"), m_oContext_get_w, m_oContext_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_dWidthMM"), m_dWidthMM_get_w, m_dWidthMM_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_dHeightMM"), m_dHeightMM_get_w, m_dHeightMM_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_lWidthPix"), m_lWidthPix_get_w, m_lWidthPix_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_lHeightPix"), m_lHeightPix_get_w, m_lHeightPix_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_dDpiX"), m_dDpiX_get_w, m_dDpiX_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_dDpiY"), m_dDpiY_get_w, m_dDpiY_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_bIsBreak"), m_bIsBreak_get_w, m_bIsBreak_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_oPen"), m_oPen_get_w, m_oPen_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_bPenColorInit"), m_bPenColorInit_get_w, m_bPenColorInit_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_oBrush"), m_oBrush_get_w, m_oBrush_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_bBrushColorInit"), m_bBrushColorInit_get_w, m_bBrushColorInit_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_oFontManager"), m_oFontManager_get_w, m_oFontManager_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_oCoordTransform"), m_oCoordTransform_get_w, m_oCoordTransform_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_oBaseTransform"), m_oBaseTransform_get_w, m_oBaseTransform_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_oFullTransform"), m_oFullTransform_get_w, m_oFullTransform_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_oInvertFullTransform"), m_oInvertFullTransform_get_w, m_oInvertFullTransform_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "ArrayPoints"), ArrayPoints_get_w, ArrayPoints_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_oCurFont"), m_oCurFont_get_w, m_oCurFont_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_oTextPr"), m_oTextPr_get_w, m_oTextPr_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_oGrFonts"), m_oGrFonts_get_w, m_oGrFonts_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_oLastFont"), m_oLastFont_get_w, m_oLastFont_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "LastFontOriginInfo"), LastFontOriginInfo_get_w, LastFontOriginInfo_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_bIntegerGrid"), m_bIntegerGrid_get_w, m_bIntegerGrid_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "ClipManager"), ClipManager_get_w, ClipManager_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "TextureFillTransformScaleX"), TextureFillTransformScaleX_get_w, TextureFillTransformScaleX_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "TextureFillTransformScaleY"), TextureFillTransformScaleY_get_w, TextureFillTransformScaleY_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "IsThumbnail"), IsThumbnail_get_w, IsThumbnail_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "IsDemonstrationMode"), IsDemonstrationMode_get_w, IsDemonstrationMode_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "IsDemonstrationMode"), IsDemonstrationMode_get_w, IsDemonstrationMode_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "GrState"), GrState_get_w, GrState_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "globalAlpha"), globalAlpha_get_w, globalAlpha_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "TextClipRect"), TextClipRect_get_w, TextClipRect_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "IsClipContext"), IsClipContext_get_w, IsClipContext_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "IsUseFonts2"), IsUseFonts2_get_w, IsUseFonts2_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_oFontManager2"), m_oFontManager2_get_w, m_oFontManager2_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "m_oLastFont2"), m_oLastFont2_get_w, m_oLastFont2_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "ClearMode"), ClearMode_get_w, ClearMode_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "IsRetina"), IsRetina_get_w, IsRetina_set_w); + result->SetAccessor(v8::String::NewFromUtf8(current, "dash_no_smart"), dash_no_smart_get_w, dash_no_smart_set_w); + */ + + // методы + NSV8Objects::Template_Set(result, "init", _init); + NSV8Objects::Template_Set(result, "EndDraw", _EndDraw); + NSV8Objects::Template_Set(result, "put_GlobalAlpha", _put_GlobalAlpha); + NSV8Objects::Template_Set(result, "Start_GlobalAlpha", _Start_GlobalAlpha); + NSV8Objects::Template_Set(result, "End_GlobalAlpha", _End_GlobalAlpha); + NSV8Objects::Template_Set(result, "p_color", _p_color); + NSV8Objects::Template_Set(result, "p_width", _p_width); + NSV8Objects::Template_Set(result, "p_dash", _p_dash); + NSV8Objects::Template_Set(result, "b_color1", _b_color1); + NSV8Objects::Template_Set(result, "b_color2", _b_color2); + NSV8Objects::Template_Set(result, "transform", _transform); + NSV8Objects::Template_Set(result, "CalculateFullTransform", _CalculateFullTransform); + NSV8Objects::Template_Set(result, "_s", __s); + NSV8Objects::Template_Set(result, "_e", __e); + NSV8Objects::Template_Set(result, "_z", __z); + NSV8Objects::Template_Set(result, "_m", __m); + NSV8Objects::Template_Set(result, "_l", __l); + NSV8Objects::Template_Set(result, "_c", __c); + NSV8Objects::Template_Set(result, "_c2", __c2); + NSV8Objects::Template_Set(result, "ds", _ds); + NSV8Objects::Template_Set(result, "df", _df); + NSV8Objects::Template_Set(result, "save", _save); + NSV8Objects::Template_Set(result, "restore", _restore); + NSV8Objects::Template_Set(result, "clip", _clip); + NSV8Objects::Template_Set(result, "reset", _reset); + NSV8Objects::Template_Set(result, "transform3", _transform3); + NSV8Objects::Template_Set(result, "FreeFont", _FreeFont); + NSV8Objects::Template_Set(result, "ClearLastFont", _ClearLastFont); + NSV8Objects::Template_Set(result, "drawImage2", _drawImage2); + NSV8Objects::Template_Set(result, "drawImage", _drawImage); + NSV8Objects::Template_Set(result, "GetFont", _GetFont); + NSV8Objects::Template_Set(result, "font", _font); + NSV8Objects::Template_Set(result, "SetFont", _SetFont); + NSV8Objects::Template_Set(result, "SetTextPr", _SetTextPr); + NSV8Objects::Template_Set(result, "SetFontSlot", _SetFontSlot); + NSV8Objects::Template_Set(result, "GetTextPr", _GetTextPr); + NSV8Objects::Template_Set(result, "FillText", _FillText); + NSV8Objects::Template_Set(result, "t", _t); + NSV8Objects::Template_Set(result, "FillText2", _FillText2); + NSV8Objects::Template_Set(result, "t2", _t2); + NSV8Objects::Template_Set(result, "FillTextCode", _FillTextCode); + NSV8Objects::Template_Set(result, "tg", _tg); + NSV8Objects::Template_Set(result, "charspace", _charspace); + NSV8Objects::Template_Set(result, "private_FillGlyph", _private_FillGlyph); + NSV8Objects::Template_Set(result, "private_FillGlyphC", _private_FillGlyphC); + NSV8Objects::Template_Set(result, "private_FillGlyph2", _private_FillGlyph2); + NSV8Objects::Template_Set(result, "SetIntegerGrid", _SetIntegerGrid); + NSV8Objects::Template_Set(result, "GetIntegerGrid", _GetIntegerGrid); + NSV8Objects::Template_Set(result, "DrawStringASCII", _DrawStringASCII); + NSV8Objects::Template_Set(result, "DrawStringASCII2", _DrawStringASCII2); + NSV8Objects::Template_Set(result, "DrawHeaderEdit", _DrawHeaderEdit); + NSV8Objects::Template_Set(result, "DrawFooterEdit", _DrawFooterEdit); + NSV8Objects::Template_Set(result, "DrawLockParagraph", _DrawLockParagraph); + NSV8Objects::Template_Set(result, "DrawLockObjectRect", _DrawLockObjectRect); + NSV8Objects::Template_Set(result, "DrawEmptyTableLine", _DrawEmptyTableLine); + NSV8Objects::Template_Set(result, "DrawSpellingLine", _DrawSpellingLine); + NSV8Objects::Template_Set(result, "drawHorLine", _drawHorLine); + NSV8Objects::Template_Set(result, "drawHorLine2", _drawHorLine2); + NSV8Objects::Template_Set(result, "drawVerLine", _drawVerLine); + NSV8Objects::Template_Set(result, "drawHorLineExt", _drawHorLineExt); + NSV8Objects::Template_Set(result, "rect", _rect); + NSV8Objects::Template_Set(result, "TableRect", _TableRect); + NSV8Objects::Template_Set(result, "AddClipRect", _AddClipRect); + NSV8Objects::Template_Set(result, "RemoveClipRect", _RemoveClipRect); + NSV8Objects::Template_Set(result, "SetClip", _SetClip); + NSV8Objects::Template_Set(result, "RemoveClip", _RemoveClip); + NSV8Objects::Template_Set(result, "drawCollaborativeChanges", _drawCollaborativeChanges); + NSV8Objects::Template_Set(result, "drawMailMergeField", _drawMailMergeField); + NSV8Objects::Template_Set(result, "drawSearchResult", _drawSearchResult); + NSV8Objects::Template_Set(result, "drawFlowAnchor", _drawFlowAnchor); + NSV8Objects::Template_Set(result, "SavePen", _SavePen); + NSV8Objects::Template_Set(result, "RestorePen", _RestorePen); + NSV8Objects::Template_Set(result, "SaveBrush", _SaveBrush); + NSV8Objects::Template_Set(result, "RestoreBrush", _RestoreBrush); + NSV8Objects::Template_Set(result, "SavePenBrush", _SavePenBrush); + NSV8Objects::Template_Set(result, "RestorePenBrush", _RestorePenBrush); + NSV8Objects::Template_Set(result, "SaveGrState", _SaveGrState); + NSV8Objects::Template_Set(result, "RestoreGrState", _RestoreGrState); + NSV8Objects::Template_Set(result, "StartClipPath", _StartClipPath); + NSV8Objects::Template_Set(result, "EndClipPath", _EndClipPath); + NSV8Objects::Template_Set(result, "StartCheckTableDraw", _StartCheckTableDraw); + NSV8Objects::Template_Set(result, "EndCheckTableDraw", _EndCheckTableDraw); + NSV8Objects::Template_Set(result, "SetTextClipRect", _SetTextClipRect); + NSV8Objects::Template_Set(result, "AddSmartRect", _AddSmartRect); + NSV8Objects::Template_Set(result, "CheckUseFonts2", _CheckUseFonts2); + NSV8Objects::Template_Set(result, "UncheckUseFonts2", _UncheckUseFonts2); + NSV8Objects::Template_Set(result, "Drawing_StartCheckBounds", _Drawing_StartCheckBounds); + NSV8Objects::Template_Set(result, "Drawing_EndCheckBounds", _Drawing_EndCheckBounds); + NSV8Objects::Template_Set(result, "DrawPresentationComment", _DrawPresentationComment); + NSV8Objects::Template_Set(result, "DrawPolygon", _DrawPolygon); + NSV8Objects::Template_Set(result, "DrawFootnoteRect", _DrawFootnoteRect); + + return handle_scope.Escape(result); + } + + void CreateNativeGraphics(const v8::FunctionCallbackInfo& args) + { + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope scope(isolate); + + v8::Handle GraphicsTemplate = NSGraphics::CreateGraphicsTemplate(isolate); + CGraphicsEmbed* pGraphics = new CGraphicsEmbed(); + + v8::Local obj = GraphicsTemplate->NewInstance(isolate->GetCurrentContext()).ToLocalChecked(); + obj->SetInternalField(0, v8::External::New(CV8Worker::GetCurrent(), pGraphics)); + + args.GetReturnValue().Set(obj); + } } -CJSGraphics* unwrap_Graphics (v8::Handle obj) +void CGraphicsEmbed::CreateObjectInContext(const std::string& name, JSSmart context) { - v8::Handle field = v8::Handle::Cast(obj->GetInternalField(0)); - return static_cast(field->Value()); -} -CFont* unwrap_Font (v8::Handle obj) -{ - v8::Handle field = v8::Handle::Cast(obj->GetInternalField(0)); - return static_cast(field->Value()); -} -CLastFontOriginInfo* unwrap_LastFontOriginInfo(v8::Handle obj) -{ - v8::Handle field = v8::Handle::Cast(obj->GetInternalField(0)); - return static_cast(field->Value()); + v8::Isolate* current = CV8Worker::GetCurrent(); + context->m_internal->m_global->Set(current, name.c_str(), v8::FunctionTemplate::New(current, NSGraphics::CreateNativeGraphics)); } +/* void init_w (const v8::FunctionCallbackInfo& args) { args.GetReturnValue().Set(v8::Undefined(v8::Isolate::GetCurrent())); @@ -707,7 +1004,8 @@ void DrawFootnoteRect_w (const v8::FunctionCallbackInfo& args) CJSGraphics* pGraphics = unwrap_Graphics(args.This()); pGraphics->DrawFootnoteRect(to_double(args[0]), to_double(args[1]), to_double(args[2]), to_double(args[3])); } - +*/ +/* void m_oContext_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info) { CJSGraphics* pGraphics = unwrap_Graphics(info.Holder()); @@ -1346,3 +1644,4 @@ void CreateGraphics(const v8::FunctionCallbackInfo& args) args.GetReturnValue().Set(obj); } +*/ diff --git a/DesktopEditor/doctrenderer/js_internal/js_base.h b/DesktopEditor/doctrenderer/js_internal/js_base.h new file mode 100644 index 0000000000..18e0c5abfc --- /dev/null +++ b/DesktopEditor/doctrenderer/js_internal/js_base.h @@ -0,0 +1,212 @@ +#ifndef _CORE_EXT_JS_BASE_H_ +#define _CORE_EXT_JS_BASE_H_ + +#include "../../common/File.h" +#include "../../common/Array.h" +#include "../../../Common/DocxFormat/Source/Base/SmartPtr.h" + +#define JS_VALUE_EXIST(value) (value.is_init() && !value->isNull() && !value->isUndefined()) +#define JS_IS_VALUE_ARRAY(value) (value.is_init() && !value->isNull() && !value->isUndefined() && value->isArray()) + +template +using JSSmart = NSCommon::smart_ptr; + +namespace NSJSBase +{ + class CJSObject; + class CJSArray; + class CJSTypedArray; + class CJSFunction; + + class CJSValue + { + public: + CJSValue() {} + virtual ~CJSValue() {} + + virtual bool isUndefined() = 0; + virtual bool isNull() = 0; + virtual bool isBool() = 0; + virtual bool isNumber() = 0; + virtual bool isString() = 0; + virtual bool isArray() = 0; + virtual bool isTypedArray() = 0; + virtual bool isObject() = 0; + virtual bool isFunction() = 0; + + virtual void doUndefined() = 0; + virtual void doNull() = 0; + + virtual bool toBool() = 0; + virtual int toInt32() = 0; + virtual double toDouble() = 0; + virtual std::string toStringA() = 0; + virtual std::wstring toStringW() = 0; + + virtual CJSObject* toObject() = 0; + virtual CJSArray* toArray() = 0; + virtual CJSTypedArray* toTypedArray() = 0; + virtual CJSFunction* toFunction() = 0; + }; + + class CJSEmbedObject + { + public: + CJSEmbedObject() {} + virtual ~CJSEmbedObject() {} + + public: + virtual void* getObject() { return NULL; } + }; + + class CJSObject : public CJSValue + { + public: + CJSObject() {} + virtual ~CJSObject() {} + + virtual CJSValue* get(const char* name) = 0; + virtual void set(const char* name, CJSValue* value) = 0; + + virtual void set(const char* name, const int& value) = 0; + virtual void set(const char* name, const double& value) = 0; + + virtual CJSEmbedObject* getNative() = 0; + + virtual JSSmart call_func(const char* name, const int argc = 0, JSSmart argv[] = NULL) = 0; + virtual JSSmart toValue() = 0; + }; + + class CJSArray : public CJSValue + { + public: + CJSArray() {} + virtual ~CJSArray() {} + + virtual int getCount() = 0; + virtual JSSmart get(const int& index) = 0; + virtual void set(const int& index, CJSValue* value) = 0; + virtual void set(const int& index, const bool& value) = 0; + virtual void set(const int& index, const int& value) = 0; + virtual void set(const int& index, const double& value) = 0; + + virtual void add(CJSValue* value) = 0; + virtual void add_null() = 0; + virtual void add_undefined() = 0; + virtual void add_bool(const bool& value) = 0; + virtual void add_byte(const BYTE& value) = 0; + virtual void add_int(const int& value) = 0; + virtual void add_double(const double& value) = 0; + virtual void add_stringa(const std::string& value) = 0; + virtual void add_string(const std::wstring& value) = 0; + virtual JSSmart toValue() = 0; + }; + + class CJSTypedArray : public CJSValue + { + public: + CJSTypedArray(BYTE* data = NULL, int count = 0) {} + virtual ~CJSTypedArray() {} + + virtual int getCount() = 0; + virtual const BYTE* getData() = 0; + }; + + class CJSFunction : public CJSValue + { + public: + CJSFunction() {} + virtual ~CJSFunction() {} + + virtual CJSValue* Call(CJSValue* recv, int argc, JSSmart argv[]) = 0; + }; + + class CJSTryCatch + { + public: + CJSTryCatch() {} + virtual ~CJSTryCatch() {} + virtual bool Check() = 0; + }; + + + class CJSIsolateScope + { + public: + CJSIsolateScope() + { + } + virtual ~CJSIsolateScope() + { + } + }; + + class CJSContextScope + { + public: + CJSContextScope() + { + } + virtual ~CJSContextScope() + { + } + }; + + class CJSLocalScope + { + public: + CJSLocalScope() + { + } + virtual ~CJSLocalScope() + { + } + }; + + class CJSContextPrivate; + class CJSContext + { + public: + CJSContextPrivate* m_internal; + + public: + CJSContext(); + ~CJSContext(); + + void Initialize(); + void Dispose(); + + CJSTryCatch* GetExceptions(); + + void CreateContext(); + void CreateGlobalForContext(); + CJSObject* GetGlobal(); + + CJSIsolateScope* CreateIsolateScope(); + CJSContextScope* CreateContextScope(); + CJSLocalScope* CreateLocalScope(); + + JSSmart runScript(const std::string& script, JSSmart exception = NULL, const std::wstring& scriptPath = std::wstring(L"")); + + public: + static CJSValue* createUndefined(); + static CJSValue* createNull(); + static CJSValue* createBool(const bool& value); + static CJSValue* createInt(const int& value); + static CJSValue* createDouble(const double& value); + static CJSValue* createString(const char* value, const int& length = -1); + static CJSValue* createString(const std::string& value); + static CJSValue* createString(const std::wstring& value); + + static CJSObject* createObject(); + + static CJSArray* createArray(const int& count); + + static CJSTypedArray* createUint8Array(BYTE* data = NULL, int count = 0); + + public: + static CJSContext* GetCurrent(); + }; +} + +#endif // _CORE_EXT_JS_BASE_H_ diff --git a/DesktopEditor/doctrenderer/js_internal/jsc/jsc_base.h b/DesktopEditor/doctrenderer/js_internal/jsc/jsc_base.h new file mode 100644 index 0000000000..fb35dbd812 --- /dev/null +++ b/DesktopEditor/doctrenderer/js_internal/jsc/jsc_base.h @@ -0,0 +1,517 @@ +#ifndef _BUILD_NATIVE_CONTROL_JSC_BASE_H_ +#define _BUILD_NATIVE_CONTROL_JSC_BASE_H_ + +#include "../js_base.h" + +#import +#import +#include +#include + +#import "../../../../core/DesktopEditor/common/Mac/NSString+StringUtils.h" + +@protocol JSEmbedObjectProtocol +- (void*) getNative; +@end + +namespace NSJSBase +{ + class CJSContextPrivate + { + public: + JSContext* context; + + static JSContext* g_lockedContext; + + public: + CJSContextPrivate() + { + context = nil; + } + ~CJSContextPrivate() + { + context = nil; + } + }; +} + +static JSContext* _getCurrentContext() +{ + return NSJSBase::CJSContextPrivate::g_lockedContext; +} + +namespace NSJSBase +{ + template + class CJSValueJSCTemplate : public T + { + public: + JSValue* value; + JSContext* context; + + CJSValueJSCTemplate() + { + value = nil; + context = nil; + } + CJSValueJSCTemplate(JSValue* _value) + { + value = _value; + context = _getCurrentContext(); + + if (context == nil) { + context = _value.context; + } + } + + public: + + virtual ~CJSValueJSCTemplate() + { + value = nil; + context = nil; + } + + virtual bool isUndefined(); + virtual bool isNull(); + virtual bool isBool(); + virtual bool isNumber(); + virtual bool isString(); + virtual bool isArray(); + virtual bool isTypedArray(); + virtual bool isObject(); + virtual bool isFunction(); + + virtual void doUndefined(); + virtual void doNull(); + virtual bool toBool(); + virtual int toInt32(); + virtual double toDouble(); + virtual std::string toStringA(); + virtual std::wstring toStringW(); + + virtual CJSObject* toObject(); + virtual CJSArray* toArray(); + virtual CJSTypedArray* toTypedArray(); + virtual CJSFunction* toFunction(); + }; + + typedef CJSValueJSCTemplate CJSValueJSC; + + class CJSObjectJSC : public CJSValueJSCTemplate + { + public: + CJSObjectJSC() + { + } + CJSObjectJSC(JSValue* _value) : CJSValueJSCTemplate(_value) + { + } + + virtual ~CJSObjectJSC() + { + value = nil; + context = nil; + } + + virtual CJSValue* get(const char* name) + { + CJSValueJSC* _value = new CJSValueJSC(); + _value->value = [value valueForProperty:[[NSString alloc] initWithUTF8String:name]]; + _value->context = context; + return _value; + } + + virtual void set(const char* name, CJSValue* value_param) + { + CJSValueJSC* _value = static_cast(value_param); + [value setValue:_value->value forProperty:[[NSString alloc] initWithUTF8String:name]]; + } + + virtual void set(const char* name, const int& _value) + { + [value setValue:[JSValue valueWithInt32:_value inContext: context] forProperty:[[NSString alloc] initWithUTF8String:name]]; + } + + virtual void set(const char* name, const double& _value) + { + [value setValue:[JSValue valueWithDouble:_value inContext: context] forProperty:[[NSString alloc] initWithUTF8String:name]]; + } + + virtual CJSEmbedObject* getNative() + { + id _wrapper = [value toObject]; + if ([_wrapper conformsToProtocol:@protocol(JSEmbedObjectProtocol)]) + { + return (CJSEmbedObject*)([_wrapper getNative]); + } + return NULL; + } + + virtual JSSmart call_func(const char* name, const int argc = 0, JSSmart argv[] = NULL) + { + NSMutableArray* arr = nil; + + if (argc > 0) + { + arr = [[NSMutableArray alloc] init]; + for (int i = 0; i < argc; ++i) + { + CJSValueJSC* _val = (CJSValueJSC*)argv[i].operator ->(); + [arr addObject:_val->value]; + } + } + + CJSValueJSC* _return = new CJSValueJSC(); + _return->context = context; + _return->value = [value invokeMethod: [[NSString alloc] initWithUTF8String:name] + withArguments: arr]; + + return _return; + } + + virtual JSSmart toValue() + { + CJSValueJSC* _value = new CJSValueJSC(); + _value->value = value; + //_value->value = [JSValue valueWithJSValueRef:[value JSValueRef] inContext:context]; + _value->context = context; + return _value; + } + }; + + class CJSArrayJSC : public CJSValueJSCTemplate + { + public: + int m_count; + public: + CJSArrayJSC() + { + m_count = 0; + } + virtual ~CJSArrayJSC() + { + value = nil; + context = nil; + } + + virtual int getCount() + { + JSValue* _ret = [value valueForProperty:@"length"]; + if (nil != _ret && NO == [_ret isUndefined]) + return [_ret toInt32]; + return 0; + } + + virtual JSSmart get(const int& index) + { + CJSValueJSC* _value = new CJSValueJSC(); + _value->value = [value valueAtIndex:(NSUInteger)index]; + _value->context = context; + return _value; + } + + virtual void set(const int& index, CJSValue* value_param) + { + CJSValueJSC* _value = static_cast(value_param); + [value setValue:_value->value atIndex:index]; + } + + virtual void add(CJSValue* value_param) + { + set(getCount(), value_param); + } + + virtual void set(const int& index, const bool& _value) + { + [value setValue:[JSValue valueWithBool:_value inContext : context] atIndex:index]; + } + + virtual void set(const int& index, const int& _value) + { + [value setValue:[JSValue valueWithInt32:_value inContext : context] atIndex:index]; + } + + virtual void set(const int& index, const double& _value) + { + [value setValue:[JSValue valueWithDouble:_value inContext : context] atIndex:index]; + } + + virtual void add_null() + { + [value setValue:[JSValue valueWithNullInContext:context] atIndex:m_count++]; + } + + virtual void add_undefined() + { + [value setValue:nil atIndex:m_count++]; + } + + virtual void add_bool(const bool& _value) + { + [value setValue:[JSValue valueWithBool:_value inContext : context] atIndex:m_count++]; + } + + virtual void add_byte(const BYTE& _value) + { + [value setValue:[JSValue valueWithInt32:(int)_value inContext : context] atIndex:m_count++]; + } + + virtual void add_int(const int& _value) + { + [value setValue:[JSValue valueWithInt32:_value inContext : context] atIndex:m_count++]; + } + + virtual void add_double(const double& _value) + { + [value setValue:[JSValue valueWithDouble:_value inContext : context] atIndex:m_count++]; + } + + virtual void add_stringa(const std::string& _value) + { + [value setValue:[NSString stringWithAString:_value] atIndex:m_count++]; + } + + virtual void add_string(const std::wstring& _value) + { + [value setValue:[NSString stringWithWString:_value] atIndex:m_count++]; + } + + virtual JSSmart toValue() + { + CJSValueJSC* _value = new CJSValueJSC(); + _value->value = value; + _value->context = context; + return _value; + } + }; + + class CJSTypedArrayJSC : public CJSValueJSCTemplate + { + public: + CJSTypedArrayJSC(JSContext* _context, BYTE* data = NULL, int count = 0) + { + context = _context; + if (0 < count) + { + JSObjectRef object = JSObjectMakeTypedArrayWithBytesNoCopy(context.JSGlobalContextRef, + kJSTypedArrayTypeUint8Array, + (void*)data, (size_t)count, + data_destroy, nullptr, nullptr); + if (object) + { + value = [JSValue valueWithJSValueRef:object inContext:context]; + } + } + } + virtual ~CJSTypedArrayJSC() + { + value = nil; + context = nil; + } + + static void data_destroy(void* bytes, void* deallocatorContext) + { + free(bytes); + } + + virtual int getCount() + { + JSObjectRef obj = JSValueToObject(context.JSGlobalContextRef, value.JSValueRef, NULL); + return (int)JSObjectGetTypedArrayByteLength(context.JSGlobalContextRef, obj, NULL); + } + + virtual const BYTE* getData() + { + JSObjectRef obj = JSValueToObject(context.JSGlobalContextRef, value.JSValueRef, NULL); + return (BYTE*)JSObjectGetTypedArrayBytesPtr(context.JSGlobalContextRef, obj, NULL); + } + }; + + class CJSFunctionJSC : public CJSValueJSCTemplate + { + public: + CJSFunctionJSC() + { + } + virtual ~CJSFunctionJSC() + { + value = nil; + context = nil; + } + + virtual CJSValue* Call(CJSValue* recv, int argc, JSSmart argv[]) + { + NSMutableArray* arr = [[NSMutableArray alloc] init]; + for (int i = 0; i < argc; ++i) + { + CJSValueJSC* _val = (CJSValueJSC*)argv[i].operator ->(); + [arr addObject:_val->value]; + } + + CJSValueJSC* _return = new CJSValueJSC(); + _return->context = context; + _return->value = [value callWithArguments:arr]; + + return _return; + } + }; + + template + CJSObject* CJSValueJSCTemplate::toObject() + { + CJSObjectJSC* _value = new CJSObjectJSC(); + _value->value = value; + _value->context = context; + return _value; + } + + template + CJSArray* CJSValueJSCTemplate::toArray() + { + CJSArrayJSC* _value = new CJSArrayJSC(); + _value->value = value; + _value->context = context; + return _value; + } + + template + CJSTypedArray* CJSValueJSCTemplate::toTypedArray() + { + CJSTypedArrayJSC* _value = new CJSTypedArrayJSC(context); + _value->value = value; + _value->context = context; + return _value; + } + + template + CJSFunction* CJSValueJSCTemplate::toFunction() + { + CJSFunctionJSC* _value = new CJSFunctionJSC(); + _value->value = value; + _value->context = context; + return _value; + } +} + +namespace NSJSBase +{ + // TRY - CATCH + class CJSCTryCatch : public CJSTryCatch + { + public: + JSContext* context; + JSSmart smartContext; + + public: + CJSCTryCatch() : CJSTryCatch() + { + smartContext = CJSContext::GetCurrent(); + context = smartContext->m_internal->context; + } + virtual ~CJSCTryCatch() + { + context = nil; + } + + public: + virtual bool Check(); + }; +} + +inline JSSmart js_value(JSValue* _value) +{ + return new NSJSBase::CJSValueJSC(_value); +} +inline JSSmart js_object(JSValue* _value) +{ + return new NSJSBase::CJSObjectJSC(_value); +} +inline JSValue* js_return(JSSmart _value) +{ + if (!_value.is_init()) + return nil; + NSJSBase::CJSValueJSC* _tmp = (NSJSBase::CJSValueJSC*)(_value.operator ->()); + return _tmp->value; +} + +#define FUNCTION_WRAPPER_JS(NAME, NAME_EMBED) \ + -(JSValue*) NAME \ + { \ + return js_return(m_internal->NAME_EMBED()); \ + } + +#define FUNCTION_WRAPPER_JS_1(NAME, NAME_EMBED) \ + -(JSValue*) NAME:(JSValue*)p1 \ + { \ + return js_return(m_internal->NAME_EMBED(js_value(p1))); \ + } +#define FUNCTION_WRAPPER_JS_2(NAME, NAME_EMBED) \ + -(JSValue*) NAME:(JSValue*)p1 : (JSValue*)p2 \ + { \ + return js_return(m_internal->NAME_EMBED(js_value(p1), js_value(p2))); \ + } +#define FUNCTION_WRAPPER_JS_3(NAME, NAME_EMBED) \ + -(JSValue*) NAME:(JSValue*)p1 : (JSValue*)p2 : (JSValue*)p3 \ + { \ + return js_return(m_internal->NAME_EMBED(js_value(p1), js_value(p2), js_value(p3))); \ + } +#define FUNCTION_WRAPPER_JS_4(NAME, NAME_EMBED) \ + -(JSValue*) NAME:(JSValue*)p1 : (JSValue*)p2 : (JSValue*)p3 : (JSValue*)p4 \ + { \ + return js_return(m_internal->NAME_EMBED(js_value(p1), js_value(p2), js_value(p3), js_value(p4))); \ + } +#define FUNCTION_WRAPPER_JS_5(NAME, NAME_EMBED) \ + -(JSValue*) NAME:(JSValue*)p1 : (JSValue*)p2 : (JSValue*)p3 : (JSValue*)p4 : (JSValue*)p5 \ + { \ + return js_return(m_internal->NAME_EMBED(js_value(p1), js_value(p2), js_value(p3), js_value(p4), js_value(p5))); \ + } +#define FUNCTION_WRAPPER_JS_6(NAME, NAME_EMBED) \ + -(JSValue*) NAME:(JSValue*)p1 : (JSValue*)p2 : (JSValue*)p3 : (JSValue*)p4 : (JSValue*)p5 : (JSValue*)p6 \ + { \ + return js_return(m_internal->NAME_EMBED(js_value(p1), js_value(p2), js_value(p3), js_value(p4), js_value(p5), js_value(p6))); \ + } +#define FUNCTION_WRAPPER_JS_7(NAME, NAME_EMBED) \ + -(JSValue*) NAME:(JSValue*)p1 : (JSValue*)p2 : (JSValue*)p3 : (JSValue*)p4 : (JSValue*)p5 : (JSValue*)p6 : (JSValue*)p7 \ + { \ + return js_return(m_internal->NAME_EMBED(js_value(p1), js_value(p2), js_value(p3), js_value(p4), js_value(p5), js_value(p6), js_value(p7))); \ + } + +#if __has_feature(objc_arc) +#define EMBED_OBJECT_WRAPPER_METHODS(CLASS) \ +-(id) init \ +{ \ + self = [super init]; \ + if (self) \ + m_internal = new CLASS(); \ + return self; \ +} \ +-(void) dealloc \ +{ \ + RELEASEOBJECT(m_internal); \ +} \ +- (void*) getNative \ +{ \ + return m_internal; \ +} +#else +#define EMBED_OBJECT_WRAPPER_METHODS(CLASS) \ +-(id) init \ +{ \ + self = [super init]; \ + if (self) \ + m_internal = new CLASS(); \ + return self; \ +} \ +-(void) dealloc \ +{ \ + RELEASEOBJECT(m_internal); \ + [super dealloc]; \ +} \ +- (void*) getNative \ +{ \ + return m_internal; \ +} +#endif + +#endif // _BUILD_NATIVE_CONTROL_JSC_BASE_H_ diff --git a/DesktopEditor/doctrenderer/js_internal/jsc/jsc_base.mm b/DesktopEditor/doctrenderer/js_internal/jsc/jsc_base.mm new file mode 100644 index 0000000000..67dd046f6a --- /dev/null +++ b/DesktopEditor/doctrenderer/js_internal/jsc/jsc_base.mm @@ -0,0 +1,275 @@ +#import "jsc_base.h" + +using namespace NSJSBase; + +JSContext* NSJSBase::CJSContextPrivate::g_lockedContext = nil; + +template +bool CJSValueJSCTemplate::isUndefined() +{ + return (value == nil) ? true : ([value isUndefined] == YES); +} +template +bool CJSValueJSCTemplate::isNull() +{ + return (value == nil) ? false : ([value isNull] == YES); +} +template +bool CJSValueJSCTemplate::isBool() +{ + return (value == nil) ? false : ([value isBoolean] == YES); +} +template +bool CJSValueJSCTemplate::isNumber() +{ + return (value == nil) ? false : ([value isNumber] == YES); +} +template +bool CJSValueJSCTemplate::isString() +{ + return (value == nil) ? false : ([value isString] == YES); +} +template +bool CJSValueJSCTemplate::isArray() +{ + return (value == nil) ? false : JSValueIsArray(context.JSGlobalContextRef, value.JSValueRef); +} +template +bool CJSValueJSCTemplate::isTypedArray() +{ + return (value == nil) ? false : (kJSTypedArrayTypeNone == JSValueGetTypedArrayType(context.JSGlobalContextRef, value.JSValueRef, NULL)); +} +template +bool CJSValueJSCTemplate::isObject() +{ + return (value == nil) ? false : ([value isObject] == YES); +} +template +bool CJSValueJSCTemplate::isFunction() +{ + return true; // TODO!!! +} +template +void CJSValueJSCTemplate::doUndefined() +{ + value = [JSValue valueWithUndefinedInContext:context]; +} +template +void CJSValueJSCTemplate::doNull() +{ + value = [JSValue valueWithNullInContext:context]; +} +template +bool CJSValueJSCTemplate::toBool() +{ + return ([value toBool] == YES) ? true : false; +} +template +int CJSValueJSCTemplate::toInt32() +{ + return [value toInt32]; +} +template +double CJSValueJSCTemplate::toDouble() +{ + return [value toDouble]; +} +template +std::string CJSValueJSCTemplate::toStringA() +{ + return [[value toString] stdstring]; +} +template +std::wstring CJSValueJSCTemplate::toStringW() +{ + return [[value toString] stdwstring]; +} + +namespace NSJSBase +{ + CJSContext::CJSContext() + { + m_internal = new CJSContextPrivate(); + } + CJSContext::~CJSContext() + { + m_internal->context = nil; + RELEASEOBJECT(m_internal); + } + + CJSTryCatch* CJSContext::GetExceptions() + { + return new CJSCTryCatch(); + } + + void CJSContext::Initialize() + { + m_internal->context = [[JSContext alloc] init]; + } + void CJSContext::Dispose() + { + m_internal->context = nil; + m_internal->g_lockedContext = nil; + NSJSBase::CJSContextPrivate::g_lockedContext = nil; + } + + void CJSContext::CreateContext() + { + // NONE + } + + void CJSContext::CreateGlobalForContext() + { + // NONE + } + + CJSObject* CJSContext::GetGlobal() + { + CJSObjectJSC* ret = new CJSObjectJSC(); + ret->context = m_internal->context; + ret->value = [m_internal->context globalObject]; + return ret; + } + + CJSIsolateScope* CJSContext::CreateIsolateScope() + { +#if 0 + // FOR DEBUG + [m_internal->context setExceptionHandler:^(JSContext *context, JSValue *value) { + NSLog(@"%@", value); + }]; +#endif + + m_internal->g_lockedContext = m_internal->context; + return new CJSIsolateScope(); + } + + CJSContextScope* CJSContext::CreateContextScope() + { + return new CJSContextScope(); + } + + CJSLocalScope* CJSContext::CreateLocalScope() + { + return new CJSLocalScope(); + } + + CJSValue* CJSContext::createUndefined() + { + CJSValueJSC* _value = new CJSValueJSC(); + _value->context = _getCurrentContext(); + _value->doUndefined(); + return _value; + } + + CJSValue* CJSContext::createNull() + { + CJSValueJSC* _value = new CJSValueJSC(); + _value->context = _getCurrentContext(); + _value->doNull(); + return _value; + } + + CJSValue* CJSContext::createBool(const bool& value) + { + CJSValueJSC* _value = new CJSValueJSC(); + _value->context = _getCurrentContext(); + _value->value = [JSValue valueWithBool:(value ? YES : NO) inContext:_value->context]; + return _value; + } + + CJSValue* CJSContext::createInt(const int& value) + { + CJSValueJSC* _value = new CJSValueJSC(); + _value->context = _getCurrentContext(); + _value->value = [JSValue valueWithInt32:((int32_t) value) inContext:_value->context]; + return _value; + } + + CJSValue* CJSContext::createDouble(const double& value) + { + CJSValueJSC* _value = new CJSValueJSC(); + _value->context = _getCurrentContext(); + _value->value = [JSValue valueWithDouble:value inContext:_value->context]; + return _value; + } + + CJSValue* CJSContext::createString(const char* value, const int& len) + { + CJSValueJSC* _value = new CJSValueJSC(); + _value->context = _getCurrentContext(); + _value->value = [NSString stringWithUtf8Buffer:value + length:(size_t)len]; + return _value; + } + + CJSValue* CJSContext::createString(const std::string& value) + { + CJSValueJSC* _value = new CJSValueJSC(); + _value->context = _getCurrentContext(); + _value->value = [NSString stringWithAString:value]; + return _value; + } + + CJSValue* CJSContext::createString(const std::wstring& value) + { + CJSValueJSC* _value = new CJSValueJSC(); + _value->context = _getCurrentContext(); + _value->value = [NSString stringWithWString:value]; + return _value; + } + + CJSObject* CJSContext::createObject() + { + CJSObjectJSC* _value = new CJSObjectJSC(); + _value->context = _getCurrentContext(); + _value->value = [JSValue valueWithNewObjectInContext:_value->context]; + return _value; + } + + CJSArray* CJSContext::createArray(const int& count) + { + CJSArrayJSC* _value = new CJSArrayJSC(); + _value->context = _getCurrentContext(); + _value->value = [JSValue valueWithNewArrayInContext:_value->context]; + return _value; + } + + CJSTypedArray* CJSContext::createUint8Array(BYTE* data, int count) + { + JSContext* _current = _getCurrentContext(); + CJSTypedArrayJSC* _value = new CJSTypedArrayJSC(_current, data, count); + return _value; + } + + JSSmart CJSContext::runScript(const std::string& script, JSSmart exception, const std::wstring& scriptPath) + { + CJSValueJSC* _value = new CJSValueJSC(); + _value->value = [m_internal->context evaluateScript:[NSString stringWithAString:script]]; + _value->context = m_internal->context; + return _value; + } + + CJSContext* CJSContext::GetCurrent() + { + CJSContext* ret = new CJSContext(); + ret->m_internal->context = _getCurrentContext(); + return ret; + } +} + +namespace NSJSBase +{ + bool CJSCTryCatch::Check() + { + JSValue* exc = [context exception]; + if (exc == nil || [exc isNull] || [exc isUndefined]) + return false; + + NSString* pExсeption = [[context exception] toString]; +#if 1 + NSLog(@"%@", pExсeption); +#endif + return true; + } +} diff --git a/DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp b/DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp new file mode 100644 index 0000000000..545dd803c9 --- /dev/null +++ b/DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp @@ -0,0 +1,303 @@ +#include "v8_base.h" + +CV8Initializer* CV8Worker::m_pInitializer = NULL; + +namespace NSJSBase +{ + + class CCacheDataScript + { + private: + BYTE* Data; + int Length; + + v8::ScriptCompiler::Source* Source; + v8::ScriptCompiler::CachedData* CachedData; + + std::wstring Path; + + public: + CCacheDataScript(const std::wstring& sPath) + { + Data = NULL; + Length = 0; + + if (!sPath.empty()) + { + BYTE* _data = NULL; + DWORD _data_length = 0; + if (NSFile::CFileBinary::ReadAllBytes(sPath, &_data, _data_length)) + { + Data = _data; + Length = (int)_data_length; + } + } + + Source = NULL; + CachedData = NULL; + Path = sPath; + } + ~CCacheDataScript() + { + //RELEASEOBJECT(Source); + //RELEASEOBJECT(CachedData); + RELEASEARRAYOBJECTS(Data); + } + + v8::Local Compile(const v8::Local& _context, const v8::Local& source) + { + v8::Local script; + if (NULL == Data) + { + Source = new v8::ScriptCompiler::Source(source); + script = v8::ScriptCompiler::Compile(_context, Source, v8::ScriptCompiler::kProduceCodeCache).ToLocalChecked(); + + const v8::ScriptCompiler::CachedData* _cachedData = Source->GetCachedData(); + NSFile::CFileBinary oFileTest; + if (oFileTest.CreateFileW(Path)) + { + oFileTest.WriteFile(_cachedData->data, (DWORD)_cachedData->length); + oFileTest.CloseFile(); + } + } + else + { + CachedData = new v8::ScriptCompiler::CachedData(Data, Length); + Source = new v8::ScriptCompiler::Source(source, CachedData); + script = v8::ScriptCompiler::Compile(_context, Source, v8::ScriptCompiler::kConsumeCodeCache).ToLocalChecked(); + } + return script; + } + + bool IsInit() + { + return Data != NULL && Length > 0; + } + }; + + class CJSIsolateScopeV8 : public CJSIsolateScope + { + public: + v8::Isolate::Scope isolate_scope; + v8::Locker isolate_locker; + + public: + CJSIsolateScopeV8(v8::Isolate* isolate) : CJSIsolateScope(), + isolate_scope(isolate), + isolate_locker(isolate) + { + } + virtual ~CJSIsolateScopeV8() + { + } + }; + + class CJSContextScopeV8 : public CJSContextScope + { + public: + v8::Context::Scope m_scope; + + public: + CJSContextScopeV8(v8::Local context) : m_scope(context) + { + } + virtual ~CJSContextScopeV8() + { + } + }; + + class CJSLocalScopeV8 : public CJSLocalScope + { + public: + v8::HandleScope m_scope; + + public: + CJSLocalScopeV8() : m_scope(CV8Worker::GetCurrent()) + { + } + virtual ~CJSLocalScopeV8() + { + } + }; + + + CJSContext::CJSContext() + { + m_internal = new CJSContextPrivate(); + } + CJSContext::~CJSContext() + { + RELEASEOBJECT(m_internal); + } + + CJSTryCatch* CJSContext::GetExceptions() + { + return new CV8TryCatch(); + } + + void CJSContext::Initialize() + { + CV8Worker::Initialize(); + m_internal->m_isolate = CV8Worker::getInitializer()->CreateNew(); + } + void CJSContext::Dispose() + { + m_internal->m_isolate->Dispose(); + CV8Worker::Dispose(); + } + + void CJSContext::CreateContext() + { + m_internal->m_context = v8::Context::New(CV8Worker::GetCurrent(), NULL, m_internal->m_global); + } + + void CJSContext::CreateGlobalForContext() + { + m_internal->m_global = v8::ObjectTemplate::New(CV8Worker::GetCurrent()); + } + + CJSObject* CJSContext::GetGlobal() + { + CJSObjectV8* ret = new CJSObjectV8(); + ret->value = m_internal->m_context->Global(); + return ret; + } + + CJSIsolateScope* CJSContext::CreateIsolateScope() + { + return new CJSIsolateScopeV8(m_internal->m_isolate); + } + + CJSContextScope* CJSContext::CreateContextScope() + { + return new CJSContextScopeV8(m_internal->m_context); + } + + CJSLocalScope* CJSContext::CreateLocalScope() + { + return new CJSLocalScopeV8(); + } + + CJSValue* CJSContext::createUndefined() + { + CJSValueV8* _value = new CJSValueV8(); + _value->doUndefined(); + return _value; + } + + CJSValue* CJSContext::createNull() + { + CJSValueV8* _value = new CJSValueV8(); + _value->doNull(); + return _value; + } + + CJSValue* CJSContext::createBool(const bool& value) + { + CJSValueV8* _value = new CJSValueV8(); + _value->value = v8::Boolean::New(CV8Worker::GetCurrent(), value); + return _value; + } + + CJSValue* CJSContext::createInt(const int& value) + { + CJSValueV8* _value = new CJSValueV8(); + _value->value = v8::Integer::New(CV8Worker::GetCurrent(), value); + return _value; + } + + CJSValue* CJSContext::createDouble(const double& value) + { + CJSValueV8* _value = new CJSValueV8(); + _value->value = v8::Number::New(CV8Worker::GetCurrent(), value); + return _value; + } + + CJSValue* CJSContext::createString(const char* value, const int& length) + { + CJSValueV8* _value = new CJSValueV8(); + _value->value = v8::String::NewFromUtf8(CV8Worker::GetCurrent(), value, v8::String::kNormalString, length); + return _value; + } + + CJSValue* CJSContext::createString(const std::string& value) + { + CJSValueV8* _value = new CJSValueV8(); + _value->value = v8::String::NewFromUtf8(CV8Worker::GetCurrent(), value.c_str(), v8::String::kNormalString, (int)value.length()); + return _value; + } + + CJSValue* CJSContext::createString(const std::wstring& value) + { + std::string sReturn = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(value); + return createString(sReturn); + } + + CJSObject* CJSContext::createObject() + { + CJSObjectV8* _value = new CJSObjectV8(); + _value->value = v8::Object::New(CV8Worker::GetCurrent()); + return _value; + } + + CJSArray* CJSContext::createArray(const int& count) + { + CJSArrayV8* _value = new CJSArrayV8(); + _value->value = v8::Array::New(CV8Worker::GetCurrent(), count); + _value->m_count = count; + return _value; + } + + CJSTypedArray* CJSContext::createUint8Array(BYTE* data, int count) + { + CJSTypedArrayV8* _value = new CJSTypedArrayV8(data, count); + return _value; + } + + JSSmart CJSContext::runScript(const std::string& script, JSSmart exception, const std::wstring& scriptPath) + { + v8::Local _source = v8::String::NewFromUtf8(CV8Worker::GetCurrent(), script.c_str()); + + v8::Local _script; + if(scriptPath.length() > 0) + { + std::wstring sCachePath = scriptPath.substr(0, scriptPath.find(L".")) + L".cache"; + CCacheDataScript oCachedScript(sCachePath); + // if (!oCachedScript.IsInit()) + // { + // _script = v8::Script::Compile(_source); + // } + // else + // { + _script = oCachedScript.Compile(m_internal->m_context, _source); + // } + } + else + { + _script = v8::Script::Compile(_source); + } + + CJSValueV8* _return = new CJSValueV8(); + + if (exception.is_init()) + { + if (!exception->Check()) + _return->value = _script->Run(); + } + else + { + _return->value = _script->Run(); + } + + return _return; + } + + CJSContext* CJSContext::GetCurrent() + { + CJSContext* ret = new CJSContext(); + ret->m_internal->m_isolate = CV8Worker::GetCurrent(); + ret->m_internal->m_context = ret->m_internal->m_isolate->GetCurrentContext(); + // global??? + return ret; + } +} diff --git a/DesktopEditor/doctrenderer/js_internal/v8/v8_base.h b/DesktopEditor/doctrenderer/js_internal/v8/v8_base.h new file mode 100644 index 0000000000..e278aee39d --- /dev/null +++ b/DesktopEditor/doctrenderer/js_internal/v8/v8_base.h @@ -0,0 +1,760 @@ +#ifndef _BUILD_NATIVE_CONTROL_V8_BASE_H_ +#define _BUILD_NATIVE_CONTROL_V8_BASE_H_ + +#include "../js_base.h" + +#include "v8.h" +#include "libplatform/libplatform.h" + +#ifdef __ANDROID__ + #include +#endif + +class MallocArrayBufferAllocator : public v8::ArrayBuffer::Allocator +{ +public: + virtual void* Allocate(size_t length) + { + void* ret = malloc(length); + memset(ret, 0, length); + return ret; + } + virtual void* AllocateUninitialized(size_t length) + { + return malloc(length); + } + virtual void Free(void* data, size_t length) + { + free(data); + } +}; + +class CV8Initializer +{ +private: + v8::Platform* m_platform; + v8::ArrayBuffer::Allocator* m_pAllocator; + +public: + CV8Initializer() + { + std::wstring sPrW = NSFile::GetProcessPath(); + std::string sPrA = U_TO_UTF8(sPrW); + + m_pAllocator = NULL; + + v8::V8::InitializeICUDefaultLocation(sPrA.c_str()); + v8::V8::InitializeExternalStartupData(sPrA.c_str()); + m_platform = v8::platform::CreateDefaultPlatform(); + v8::V8::InitializePlatform(m_platform); + v8::V8::Initialize(); + } + ~CV8Initializer() + { + v8::V8::Dispose(); + v8::V8::ShutdownPlatform(); + delete m_platform; + if (m_pAllocator) + delete m_pAllocator; + } + + v8::ArrayBuffer::Allocator* getAllocator() + { + return m_pAllocator; + } + + v8::Isolate* CreateNew() + { + v8::Isolate::CreateParams create_params; + m_pAllocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator(); + create_params.array_buffer_allocator = m_pAllocator; + return v8::Isolate::New(create_params); + } +}; + +class CV8Worker +{ +private: + static CV8Initializer* m_pInitializer; + +public: + CV8Worker() {} + ~CV8Worker() {} + + static void Initialize() + { + if (NULL == m_pInitializer) + m_pInitializer = new CV8Initializer(); + } + + static void Dispose() + { + if (NULL != m_pInitializer) + delete m_pInitializer; + m_pInitializer = NULL; + } + + static CV8Initializer* getInitializer() + { + if (NULL == m_pInitializer) + { + m_pInitializer = new CV8Initializer(); + } + + return CV8Worker::m_pInitializer; + } + + static v8::Isolate* GetCurrent() + { + return v8::Isolate::GetCurrent(); + } +}; + +namespace NSJSBase +{ + + template + class CJSValueV8Template : public B + { + public: + v8::Local value; + + CJSValueV8Template() + { + } + + CJSValueV8Template(const v8::Local& _value) + { + value = _value; + } + + public: + + virtual ~CJSValueV8Template() + { + value.Clear(); + } + + virtual bool isUndefined() + { + return value.IsEmpty() ? false : value->IsUndefined(); + } + virtual bool isNull() + { + return value.IsEmpty() ? false : value->IsNull(); + } + virtual bool isBool() + { + return value.IsEmpty() ? false : value->IsBoolean(); + } + virtual bool isNumber() + { + return value.IsEmpty() ? false : value->IsNumber(); + } + virtual bool isString() + { + return value.IsEmpty() ? false : value->IsString(); + } + virtual bool isArray() + { + return value.IsEmpty() ? false : value->IsArray(); + } + virtual bool isTypedArray() + { + return value.IsEmpty() ? false : value->IsTypedArray(); + } + virtual bool isObject() + { + return value.IsEmpty() ? false : value->IsObject(); + } + virtual bool isFunction() + { + return value.IsEmpty() ? false : value->IsFunction(); + } + + virtual void doUndefined() + { + } + + virtual void doNull() + { + } + + virtual bool toBool() + { + return false; + } + + virtual int toInt32() + { + return 0; + } + + virtual double toDouble() + { + return 0; + } + + virtual std::string toStringA() + { + return ""; + } + + virtual std::wstring toStringW() + { + return L""; + } + + virtual CJSObject* toObject(); + virtual CJSArray* toArray(); + virtual CJSTypedArray* toTypedArray(); + virtual CJSFunction* toFunction(); + }; + + class CJSValueV8TemplatePrimitive : public CJSValueV8Template + { + public: + CJSValueV8TemplatePrimitive() + { + } + CJSValueV8TemplatePrimitive(const v8::Local& _value) : CJSValueV8Template(_value) + { + } + + virtual ~CJSValueV8TemplatePrimitive() + { + value.Clear(); + } + + virtual void doUndefined() + { + value = v8::Undefined(CV8Worker::GetCurrent()); + } + + virtual void doNull() + { + value = v8::Null(CV8Worker::GetCurrent()); + } + + virtual bool toBool() + { + return value.IsEmpty() ? false : value->BooleanValue(); + } + + virtual int toInt32() + { + return value.IsEmpty() ? 0 : value->Int32Value(); + } + + virtual double toDouble() + { + return value.IsEmpty() ? 0 : value->NumberValue(); + } + + virtual std::string toStringA() + { + if (value.IsEmpty()) + return ""; + + v8::String::Utf8Value data(value); + if (NULL == *data) + return ""; + + return std::string((char*)(*data), data.length()); + } + + virtual std::wstring toStringW() + { + if (value.IsEmpty()) + return L""; + + v8::String::Utf8Value data(value); + if (NULL == *data) + return L""; + + return NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)(*data), data.length()); + } + }; + + typedef CJSValueV8TemplatePrimitive CJSValueV8; + + class CJSObjectV8 : public CJSValueV8Template + { + public: + CJSObjectV8() + { + } + + virtual ~CJSObjectV8() + { + value.Clear(); + } + + virtual CJSValue* get(const char* name) + { + CJSValueV8* _value = new CJSValueV8(); + v8::Local _name = v8::String::NewFromUtf8(CV8Worker::GetCurrent(), name, v8::String::kNormalString, -1); + _value->value = value->Get(_name); + return _value; + } + + virtual void set(const char* name, CJSValue* value_param) + { + CJSValueV8* _value = static_cast(value_param); + v8::Local _name = v8::String::NewFromUtf8(CV8Worker::GetCurrent(), name, v8::String::kNormalString, -1); + value->Set(_name, _value->value); + } + + virtual void set(const char* name, const int& _value) + { + v8::Isolate* isolate = CV8Worker::GetCurrent(); + v8::Local _name = v8::String::NewFromUtf8(isolate, name, v8::String::kNormalString, -1); + value->Set(_name, v8::Integer::New(isolate, _value)); + } + + virtual void set(const char* name, const double& _value) + { + v8::Isolate* isolate = CV8Worker::GetCurrent(); + v8::Local _name = v8::String::NewFromUtf8(isolate, name, v8::String::kNormalString, -1); + value->Set(_name, v8::Number::New(isolate, _value)); + } + + virtual CJSEmbedObject* getNative() + { + v8::Handle field = v8::Handle::Cast(value->GetInternalField(0)); + return (CJSEmbedObject*)field->Value(); + } + + virtual JSSmart call_func(const char* name, const int argc = 0, JSSmart argv[] = NULL) + { + v8::Local _name = v8::String::NewFromUtf8(CV8Worker::GetCurrent(), name, v8::String::kNormalString, -1); + v8::Handle _func = value->Get(_name); + + CJSValueV8* _return = new CJSValueV8(); + if (_func->IsFunction()) + { + v8::Handle _funcN = v8::Handle::Cast(_func); + + if (0 == argc) + { + _return->value = _funcN->Call(value, 0, NULL); + } + else + { + v8::Local* args = new v8::Local[argc]; + for (int i = 0; i < argc; ++i) + { + CJSValueV8* _value_arg = static_cast(argv[i].operator ->()); + args[i] = _value_arg->value; + } + _return->value = _funcN->Call(value, argc, args); + RELEASEARRAYOBJECTS(args); + } + } + + JSSmart _ret = _return; + return _ret; + } + + virtual JSSmart toValue() + { + CJSValueV8* _value = new CJSValueV8(); + _value->value = value; + return _value; + } + }; + + class CJSArrayV8 : public CJSValueV8Template + { + public: + int m_count; + public: + CJSArrayV8() + { + m_count = 0; + } + virtual ~CJSArrayV8() + { + value.Clear(); + } + + virtual int getCount() + { + return value->Length(); + } + + virtual JSSmart get(const int& index) + { + CJSValueV8* _value = new CJSValueV8(); + _value->value = value->Get(index); + return _value; + } + + virtual void set(const int& index, CJSValue* value_param) + { + CJSValueV8* _value = static_cast(value_param); + value->Set(index, _value->value); + } + + virtual void add(CJSValue* value_param) + { + CJSValueV8* _value = static_cast(value_param); + value->Set(getCount(), _value->value); + } + + virtual void set(const int& index, const bool& _value) + { + value->Set(index, v8::Boolean::New(CV8Worker::GetCurrent(), _value)); + } + + virtual void set(const int& index, const int& _value) + { + value->Set(index, v8::Integer::New(CV8Worker::GetCurrent(), _value)); + } + + virtual void set(const int& index, const double& _value) + { + value->Set(index, v8::Number::New(CV8Worker::GetCurrent(), _value)); + } + + virtual void add_null() + { + value->Set(m_count++, v8::Null(CV8Worker::GetCurrent())); + } + + virtual void add_undefined() + { + value->Set(m_count++, v8::Undefined(CV8Worker::GetCurrent())); + } + + virtual void add_bool(const bool& _value) + { + value->Set(m_count++, v8::Boolean::New(CV8Worker::GetCurrent(), _value)); + } + + virtual void add_byte(const BYTE& _value) + { + value->Set(m_count++, v8::Integer::New(CV8Worker::GetCurrent(), (int)_value)); + } + + virtual void add_int(const int& _value) + { + value->Set(m_count++, v8::Integer::New(CV8Worker::GetCurrent(), _value)); + } + + virtual void add_double(const double& _value) + { + value->Set(m_count++, v8::Number::New(CV8Worker::GetCurrent(), _value)); + } + + virtual void add_stringa(const std::string& _value) + { + value->Set(m_count++, v8::String::NewFromUtf8(CV8Worker::GetCurrent(), _value.c_str(), v8::String::kNormalString, (int)_value.length())); + } + + virtual void add_string(const std::wstring& _value) + { + std::string sReturn = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(_value); + add_stringa(sReturn); + } + + virtual JSSmart toValue() + { + CJSValueV8* _value = new CJSValueV8(); + _value->value = value; + return _value; + } + }; + + class CJSTypedArrayV8 : public CJSValueV8Template + { + public: + CJSTypedArrayV8(BYTE* data = NULL, int count = 0) + { + if (0 < count) + { + v8::Local _buffer = v8::ArrayBuffer::New(CV8Worker::GetCurrent(), (void*)data, (size_t)count); + value = v8::Uint8Array::New(_buffer, 0, (size_t)count); + } + } + virtual ~CJSTypedArrayV8() + { + value.Clear(); + } + + virtual int getCount() + { + return (int)value->ByteLength(); + } + + virtual const BYTE* getData() + { + return (BYTE*)value->Buffer()->Externalize().Data(); + } + }; + + class CJSFunctionV8 : public CJSValueV8Template + { + public: + CJSFunctionV8() + { + } + virtual ~CJSFunctionV8() + { + value.Clear(); + } + + virtual CJSValue* Call(CJSValue* recv, int argc, JSSmart argv[]) + { + CJSValueV8* _value = static_cast(recv); + CJSValueV8* _return = new CJSValueV8(); + if (0 == argc) + { + _return->value = value->Call(_value->value, 0, NULL); + } + else + { + v8::Local* args = new v8::Local[argc]; + for (int i = 0; i < argc; ++i) + { + CJSValueV8* _value_arg = static_cast(argv[i].operator ->()); + args[i] = _value_arg->value; + } + _return->value = value->Call(_value->value, argc, args); + RELEASEARRAYOBJECTS(args); + } + return _return; + } + }; + + template + CJSObject* CJSValueV8Template::toObject() + { + CJSObjectV8* _value = new CJSObjectV8(); + _value->value = value->ToObject(); + return _value; + } + + template + CJSArray* CJSValueV8Template::toArray() + { + CJSArrayV8* _value = new CJSArrayV8(); + _value->value = v8::Local::Cast(value); + return _value; + } + + template + CJSTypedArray* CJSValueV8Template::toTypedArray() + { + CJSTypedArrayV8* _value = new CJSTypedArrayV8(); + _value->value = v8::Local::Cast(value); + return _value; + } + + template + CJSFunction* CJSValueV8Template::toFunction() + { + CJSFunctionV8* _value = new CJSFunctionV8(); + _value->value = v8::Local::Cast(value); + return _value; + } +} + +namespace NSJSBase +{ + // TRY - CATCH + class CV8TryCatch : public CJSTryCatch + { + private: + v8::TryCatch try_catch; + + public: + CV8TryCatch() : CJSTryCatch(), try_catch() + { + } + virtual ~CV8TryCatch() + { + } + + public: + virtual bool Check() + { + if (try_catch.HasCaught()) + { + int nLineNumber = try_catch.Message()->GetLineNumber(); + + JSSmart _line = new CJSValueV8(); + _line->value = try_catch.Message()->GetSourceLine(); + + JSSmart _exception = new CJSValueV8(); + _exception->value = try_catch.Message()->Get(); + + std::string strCode = _line->toStringA(); + std::string strException = _exception->toStringA(); + +#if 0 && !defined(__ANDROID__) + FILE* f = fopen("D:\\errors.txt", "a+"); + fprintf(f, "error: "); + fprintf(f, strCode.c_str()); + fprintf(f, "\n"); + fprintf(f, strException.c_str()); + fprintf(f, "\n"); + fclose(f); +#endif + +#ifdef __ANDROID__ + LOGE("NSJSBase::CV8TryCatch::Check() - error:"); + LOGE(std::to_string(nLineNumber).c_str()); + LOGE(strCode.c_str()); + LOGE(strException.c_str()); +#endif + return true; + } + return false; + } + }; +} + +namespace NSJSBase +{ + class CJSContextPrivate + { + public: + CV8Worker m_oWorker; + v8::Isolate* m_isolate; + + v8::Local m_global; + v8::Local m_context; + + public: + CJSContextPrivate() : m_oWorker(), m_isolate(NULL) + { + } + }; +} + +namespace NSV8Objects +{ + static void Template_Set(v8::Local& obj, const char* name, v8::FunctionCallback callback) + { + v8::Isolate* current = CV8Worker::GetCurrent(); + obj->Set(v8::String::NewFromUtf8(current, name), v8::FunctionTemplate::New(current, callback)); + } +} + +inline NSJSBase::CJSEmbedObject* unwrap_native(const v8::Local& value) +{ + v8::Handle field = v8::Handle::Cast(value->GetInternalField(0)); + return (NSJSBase::CJSEmbedObject*)field->Value(); +} +inline NSJSBase::CJSEmbedObject* unwrap_native2(const v8::Local& value) +{ + v8::Local _obj = value->ToObject(); + v8::Handle field = v8::Handle::Cast(_obj->GetInternalField(0)); + return (NSJSBase::CJSEmbedObject*)field->Value(); +} + +inline JSSmart js_value(const v8::Local& value) +{ + return new NSJSBase::CJSValueV8(value); +} +inline JSSmart js_object(const v8::Local& value) +{ + NSJSBase::CJSObjectV8* _ret = new NSJSBase::CJSObjectV8(); + _ret->value = value; + return _ret; +} +inline void js_return(const v8::FunctionCallbackInfo& args, JSSmart& value) +{ + if (value.is_init()) + { + NSJSBase::CJSValueV8* _value = (NSJSBase::CJSValueV8*)(value.operator ->()); + args.GetReturnValue().Set(_value->value); + } +} + +#define FUNCTION_WRAPPER_V8(NAME, NAME_EMBED) \ + void NAME(const v8::FunctionCallbackInfo& args) \ + { \ + CURRENTWRAPPER* _this = (CURRENTWRAPPER*)unwrap_native(args.This()); \ + JSSmart ret = _this->NAME_EMBED(); \ + js_return(args, ret); \ + } + +#define FUNCTION_WRAPPER_V8_1(NAME, NAME_EMBED) \ + void NAME(const v8::FunctionCallbackInfo& args) \ + { \ + CURRENTWRAPPER* _this = (CURRENTWRAPPER*)unwrap_native(args.This()); \ + JSSmart ret = _this->NAME_EMBED(js_value(args[0])); \ + js_return(args, ret); \ + } +#define FUNCTION_WRAPPER_V8_2(NAME, NAME_EMBED) \ + void NAME(const v8::FunctionCallbackInfo& args) \ + { \ + CURRENTWRAPPER* _this = (CURRENTWRAPPER*)unwrap_native(args.This()); \ + JSSmart ret = _this->NAME_EMBED(js_value(args[0]), js_value(args[1])); \ + js_return(args, ret); \ + } +#define FUNCTION_WRAPPER_V8_3(NAME, NAME_EMBED) \ + void NAME(const v8::FunctionCallbackInfo& args) \ + { \ + CURRENTWRAPPER* _this = (CURRENTWRAPPER*)unwrap_native(args.This()); \ + JSSmart ret = _this->NAME_EMBED(js_value(args[0]), js_value(args[1]), js_value(args[2])); \ + js_return(args, ret); \ + } +#define FUNCTION_WRAPPER_V8_4(NAME, NAME_EMBED) \ + void NAME(const v8::FunctionCallbackInfo& args) \ + { \ + CURRENTWRAPPER* _this = (CURRENTWRAPPER*)unwrap_native(args.This()); \ + JSSmart ret = _this->NAME_EMBED(js_value(args[0]), js_value(args[1]), js_value(args[2]), js_value(args[3])); \ + js_return(args, ret); \ + } +#define FUNCTION_WRAPPER_V8_5(NAME, NAME_EMBED) \ + void NAME(const v8::FunctionCallbackInfo& args) \ + { \ + CURRENTWRAPPER* _this = (CURRENTWRAPPER*)unwrap_native(args.This()); \ + JSSmart ret = _this->NAME_EMBED(js_value(args[0]), js_value(args[1]), js_value(args[2]), js_value(args[3]), js_value(args[4])); \ + js_return(args, ret); \ + } +#define FUNCTION_WRAPPER_V8_6(NAME, NAME_EMBED) \ + void NAME(const v8::FunctionCallbackInfo& args) \ + { \ + CURRENTWRAPPER* _this = (CURRENTWRAPPER*)unwrap_native(args.This()); \ + JSSmart ret = _this->NAME_EMBED(js_value(args[0]), js_value(args[1]), js_value(args[2]), js_value(args[3]), js_value(args[4]), js_value(args[5])); \ + js_return(args, ret); \ + } +#define FUNCTION_WRAPPER_V8_7(NAME, NAME_EMBED) \ +void NAME(const v8::FunctionCallbackInfo& args) \ + { \ + CURRENTWRAPPER* _this = (CURRENTWRAPPER*)unwrap_native(args.This()); \ + JSSmart ret = _this->NAME_EMBED(js_value(args[0]), js_value(args[1]), js_value(args[2]), js_value(args[3]), js_value(args[4]), \ + js_value(args[5]), js_value(args[6])); \ + js_return(args, ret); \ + } +#define FUNCTION_WRAPPER_V8_8(NAME, NAME_EMBED) \ +void NAME(const v8::FunctionCallbackInfo& args) \ + { \ + CURRENTWRAPPER* _this = (CURRENTWRAPPER*)unwrap_native(args.This()); \ + JSSmart ret = _this->NAME_EMBED(js_value(args[0]), js_value(args[1]), js_value(args[2]), js_value(args[3]), js_value(args[4]), \ + js_value(args[5]), js_value(args[6]), js_value(args[7])); \ + js_return(args, ret); \ + } +#define FUNCTION_WRAPPER_V8_10(NAME, NAME_EMBED) \ + void NAME(const v8::FunctionCallbackInfo& args) \ + { \ + CURRENTWRAPPER* _this = (CURRENTWRAPPER*)unwrap_native(args.This()); \ + JSSmart ret = _this->NAME_EMBED(js_value(args[0]), js_value(args[1]), js_value(args[2]), js_value(args[3]), js_value(args[4]), js_value(args[5]), \ + js_value(args[6]), js_value(args[7]), js_value(args[8]), js_value(args[9])); \ + js_return(args, ret); \ + } +#define FUNCTION_WRAPPER_V8_13(NAME, NAME_EMBED) \ + void NAME(const v8::FunctionCallbackInfo& args) \ + { \ + CURRENTWRAPPER* _this = (CURRENTWRAPPER*)unwrap_native(args.This()); \ + JSSmart ret = _this->NAME_EMBED(js_value(args[0]), js_value(args[1]), js_value(args[2]), js_value(args[3]), js_value(args[4]), js_value(args[5]), \ + js_value(args[6]), js_value(args[7]), js_value(args[8]), js_value(args[9]), js_value(args[10]), js_value(args[11]), \ + js_value(args[12])); \ + js_return(args, ret); \ + } + +#endif // _BUILD_NATIVE_CONTROL_V8_BASE_H_ diff --git a/DesktopEditor/doctrenderer/jsgraphics/graphics.h b/DesktopEditor/doctrenderer/jsgraphics/graphics.h deleted file mode 100644 index 6759385cea..0000000000 --- a/DesktopEditor/doctrenderer/jsgraphics/graphics.h +++ /dev/null @@ -1,277 +0,0 @@ -#ifndef CJSGRAPHICS_H -#define CJSGRAPHICS_H - -#include - -#include "../../common/Types.h" -#include "../../../Common/3dParty/v8/v8/include/v8.h" -#include "../../../Common/3dParty/v8/v8/include/libplatform/libplatform.h" - -struct CFont -{ - std::string Name; - int FontSize; - bool Bold; - bool Italic; - - CFont() : Name(""), FontSize(10), Bold(false), Italic(false) {} -}; - -struct CLastFontOriginInfo -{ - std::string Name; - v8::Local* Replace; - - CLastFontOriginInfo() : Name(""), Replace(nullptr) {} -}; - -class CJSGraphics -{ -private: - v8::Local* m_oContext; - double m_dWidthMM; - double m_dHeightMM; - double m_lWidthPix; - double m_lHeightPix; - double m_dDpiX; - double m_dDpiY; - bool m_bIsBreak; - - v8::Local* m_oPen; - bool m_bPenColorInit; - v8::Local* m_oBrush; - bool m_bBrushColorInit; - - v8::Local* m_oFontManager; - - v8::Local* m_oCoordTransform; - v8::Local* m_oBaseTransform; - v8::Local* m_oTransform; - v8::Local* m_oFullTransform; - v8::Local* m_oInvertFullTransform; - - v8::Local* ArrayPoints; - - CFont m_oCurFont; - - v8::Local* m_oTextPr; - v8::Local* m_oGrFonts; - v8::Local* m_oLastFont; - - CLastFontOriginInfo LastFontOriginInfo; - - bool m_bIntegerGrid; - - v8::Local* ClipManager; - - int TextureFillTransformScaleX; - int TextureFillTransformScaleY; - bool IsThumbnail; - - bool IsDemonstrationMode; - - v8::Local* GrState; - - int globalAlpha; - - v8::Local* TextClipRect; - bool IsClipContext; - - bool IsUseFonts2; - v8::Local* m_oFontManager2; - v8::Local* m_oLastFont2; - - bool ClearMode; - bool IsRetina; - - v8::Local* dash_no_smart; -public: - CJSGraphics(); - ~CJSGraphics(); - - void init(v8::Local* context, double width_px, double height_px, double width_mm, double height_mm); - void EndDraw() {} - void put_GlobalAlpha(bool enable, int globalAlpha); - void Start_GlobalAlpha() {} - void End_GlobalAlpha(); - // pen methods - void p_color(int r, int g, int b, int a); - void p_width(int w); - void p_dash(const v8::Local& params); - // brush methods - void b_color1(int r, int g, int b, int a); - void b_color2(int r, int g, int b, int a); - void transform(double sx, double shy, double shx, double sy, double tx, double ty); - void CalculateFullTransform(bool isInvertNeed); - // path commands - void _s(); - void _e(); - void _z(); - void _m(double x, double y); - void _l(double x, double y); - void _c(double x1, double y1, double x2, double y2, double x3, double y3); - void _c2(double x1, double y1, double x2, double y2); - void ds(); - void df(); - // canvas state - void save(); - void restore(); - void clip(); - void reset(); - void transform3(const v8::Local& m, bool isNeedInvert); - void FreeFont(); - void ClearLastFont(); - // images - void drawImage2(const v8::Local& img, double x, double y, double w, double h, int alpha, const v8::Local& srcRect); - void drawImage(const v8::Local& img, double x, double y, double w, double h, int alpha, const v8::Local& srcRect, const v8::Local& nativeImage); - // text - CFont GetFont(); - void font(unsigned int font_id, int font_size); - void SetFont(const v8::Local& font); - void SetTextPr(const v8::Local& textPr, const v8::Local& theme); - void SetFontSlot(const v8::Local& slot, double fontSizeKoef); - v8::Local GetTextPr(); - void FillText(double x, double y, const v8::Local& text); - void t(const v8::Local& text, double x, double y, bool isBounds); - void FillText2(double x, double y, const v8::Local& text, double cropX, double cropW); - void t2(const v8::Local& text, double x, double y, double cropX, double cropW); - void FillTextCode(double x, double y, const v8::Local& lUnicode); - void tg(const v8::Local& text, double x, double y); - void charspace(const v8::Local& space) {} - // private methods - void private_FillGlyph(const v8::Local& pGlyph, const v8::Local& _bounds); - void private_FillGlyphC(const v8::Local& pGlyph, double cropX, double cropW); - void private_FillGlyph2(const v8::Local& pGlyph); - void SetIntegerGrid(bool param); - bool GetIntegerGrid(); - void DrawStringASCII(const std::string& name, int size, bool bold, bool italic, const v8::Local& text, double x, double y, bool bIsHeader); - void DrawStringASCII2(const std::string& name, int size, bool bold, bool italic, const v8::Local& text, double x, double y, bool bIsHeader); - void DrawHeaderEdit(double yPos, const v8::Local& lock_type, int sectionNum, bool bIsRepeat, const v8::Local& type); - void DrawFooterEdit(double yPos, const v8::Local& lock_type, int sectionNum, bool bIsRepeat, const v8::Local& type); - void DrawLockParagraph(const v8::Local& lock_type, double x, double y1, double y2); - void DrawLockObjectRect(const v8::Local& lock_type, double x, double y, double w, double h); - void DrawEmptyTableLine(double x1, double y1, double x2, double y2); - void DrawSpellingLine(double y0, double x0, double x1, double w); - // smart methods for horizontal / vertical lines - void drawHorLine(int align, double y, double x, double r, int penW); - void drawHorLine2(int align, double y, double x, double r, int penW); - void drawVerLine(int align, double x, double y, double b, int penW); - // мега крутые функции для таблиц - void drawHorLineExt(int align, double y, double x, double r, int penW, double leftMW, double rightMW); - void rect(double x, double y, double w, double h); - void TableRect(double x, double y, double w, double h); - // функции клиппирования - void AddClipRect(double x, double y, double w, double h); - void RemoveClipRect() {} - void SetClip(const v8::Local& r); - void RemoveClip(); - void drawCollaborativeChanges(double x, double y, double w, double h, const v8::Local& Color); - void drawMailMergeField(double x, double y, double w, double h); - void drawSearchResult(double x, double y, double w, double h); - void drawFlowAnchor(double x, double y); - void SavePen(); - void RestorePen(); - void SaveBrush(); - void RestoreBrush(); - void SavePenBrush(); - void RestorePenBrush(); - void SaveGrState(); - void RestoreGrState(); - void StartClipPath() {} - void EndClipPath(); - void StartCheckTableDraw(); - void EndCheckTableDraw(bool bIsRestore); - void SetTextClipRect(double _l, double _t, double _r, double _b); - void AddSmartRect(double x, double y, double w, double h, int pen_w); - void CheckUseFonts2(const v8::Local& _transform); - void UncheckUseFonts2(); - void Drawing_StartCheckBounds(double x, double y, double w, double h) {} - void Drawing_EndCheckBounds() {} - void DrawPresentationComment(const v8::Local& type, double x, double y, double w, double h); - void DrawPolygon(const v8::Local& oPath, int lineWidth, double shift); - void DrawFootnoteRect(double x, double y, double w, double h); - - v8::Local* m_oContext_get() { return m_oContext; } - v8::Local* m_oPen_get() { return m_oPen; } - v8::Local* m_oBrush_get() { return m_oBrush; } - v8::Local* m_oFontManager_get() { return m_oFontManager; } - v8::Local* m_oCoordTransform_get() { return m_oCoordTransform; } - v8::Local* m_oBaseTransform_get() { return m_oBaseTransform; } - v8::Local* m_oTransform_get() { return m_oTransform; } - v8::Local* m_oFullTransform_get() { return m_oFullTransform; } - v8::Local* m_oInvertFullTransform_get() { return m_oInvertFullTransform; } - v8::Local* ArrayPoints_get() { return ArrayPoints; } - v8::Local* m_oTextPr_get() { return m_oTextPr; } - v8::Local* m_oGrFonts_get() { return m_oGrFonts; } - v8::Local* m_oLastFont_get() { return m_oLastFont; } - v8::Local* ClipManager_get() { return ClipManager; } - v8::Local* GrState_get() { return GrState; } - v8::Local* TextClipRect_get() { return TextClipRect; } - v8::Local* m_oFontManager2_get() { return m_oFontManager2; } - v8::Local* m_oLastFont2_get() { return m_oLastFont2; } - v8::Local* dash_no_smart_get() { return dash_no_smart; } - double m_dWidthMM_get() { return m_dWidthMM; } - double m_dHeightMM_get() { return m_dHeightMM; } - double m_lWidthPix_get() { return m_lWidthPix; } - double m_lHeightPix_get() { return m_lHeightPix; } - double m_dDpiX_get() { return m_dDpiX; } - double m_dDpiY_get() { return m_dDpiY; } - bool m_bIsBreak_get() { return m_bIsBreak; } - bool m_bPenColorInit_get() { return m_bPenColorInit; } - bool m_bBrushColorInit_get() { return m_bBrushColorInit; } - bool m_bIntegerGrid_get() { return m_bIntegerGrid; } - bool IsThumbnail_get() { return IsThumbnail; } - bool IsDemonstrationMode_get() { return IsDemonstrationMode; } - bool IsClipContext_get() { return IsClipContext; } - bool IsUseFonts2_get() { return IsUseFonts2; } - bool ClearMode_get() { return ClearMode; } - bool IsRetina_get() { return IsRetina; } - CFont m_oCurFont_get() { return m_oCurFont; } - CLastFontOriginInfo LastFontOriginInfo_get() { return LastFontOriginInfo; } - int TextureFillTransformScaleX_get() { return TextureFillTransformScaleX; } - int TextureFillTransformScaleY_get() { return TextureFillTransformScaleY; } - int globalAlpha_get() { return globalAlpha; } - - void m_oContext_set (v8::Local* a) { m_oContext = a; } - void m_oPen_set (v8::Local* a) { m_oPen = a; } - void m_oBrush_set (v8::Local* a) { m_oBrush = a; } - void m_oFontManager_set (v8::Local* a) { m_oFontManager = a; } - void m_oCoordTransform_set (v8::Local* a) { m_oCoordTransform = a; } - void m_oBaseTransform_set (v8::Local* a) { m_oBaseTransform = a; } - void m_oTransform_set (v8::Local* a) { m_oTransform = a; } - void m_oFullTransform_set (v8::Local* a) { m_oFullTransform = a; } - void m_oInvertFullTransform_set(v8::Local* a) { m_oInvertFullTransform = a; } - void ArrayPoints_set (v8::Local* a) { ArrayPoints = a; } - void m_oTextPr_set (v8::Local* a) { m_oTextPr = a; } - void m_oGrFonts_set (v8::Local* a) { m_oGrFonts = a; } - void m_oLastFont_set (v8::Local* a) { m_oLastFont = a; } - void ClipManager_set (v8::Local* a) { ClipManager = a; } - void GrState_set (v8::Local* a) { GrState = a; } - void TextClipRect_set (v8::Local* a) { TextClipRect = a; } - void m_oFontManager2_set (v8::Local* a) { m_oFontManager2 = a; } - void m_oLastFont2_set (v8::Local* a) { m_oLastFont2 = a; } - void dash_no_smart_set (v8::Local* a) { dash_no_smart = a; } - void m_dWidthMM_set (double a) { m_dWidthMM = a; } - void m_dHeightMM_set (double a) { m_dHeightMM = a; } - void m_lWidthPix_set (double a) { m_lWidthPix = a; } - void m_lHeightPix_set (double a) { m_lHeightPix = a; } - void m_dDpiX_set (double a) { m_dDpiX = a; } - void m_dDpiY_set (double a) { m_dDpiY = a; } - void m_bIsBreak_set (bool a) { m_bIsBreak = a; } - void m_bPenColorInit_set (bool a) { m_bPenColorInit = a; } - void m_bBrushColorInit_set (bool a) { m_bBrushColorInit = a; } - void m_bIntegerGrid_set (bool a) { m_bIntegerGrid = a; } - void IsThumbnail_set (bool a) { IsThumbnail = a; } - void IsDemonstrationMode_set(bool a) { IsDemonstrationMode = a; } - void IsClipContext_set (bool a) { IsClipContext = a; } - void IsUseFonts2_set (bool a) { IsUseFonts2 = a; } - void ClearMode_set (bool a) { ClearMode = a; } - void IsRetina_set (bool a) { IsRetina = a; } - void m_oCurFont_set (CFont a) { m_oCurFont = a; } - void LastFontOriginInfo_set(CLastFontOriginInfo a) { LastFontOriginInfo = a; } - void TextureFillTransformScaleX_set(int a) { TextureFillTransformScaleX = a; } - void TextureFillTransformScaleY_set(int a) { TextureFillTransformScaleY = a; } - void globalAlpha_set (int a) { globalAlpha = a; } -}; - -#endif // CJSGRAPHICS_H diff --git a/DesktopEditor/doctrenderer/jsgraphics/graphics_wrapper.h b/DesktopEditor/doctrenderer/jsgraphics/graphics_wrapper.h deleted file mode 100644 index 7cfdbf2ab3..0000000000 --- a/DesktopEditor/doctrenderer/jsgraphics/graphics_wrapper.h +++ /dev/null @@ -1,190 +0,0 @@ -#include "graphics.h" - -#include - -double to_double(const v8::Local& v); -bool to_bool (const v8::Local& v); -int to_int (const v8::Local& v); -unsigned int to_uint (const v8::Local& v); -std::string to_string(const v8::Local& v); - -CJSGraphics* unwrap_Graphics (v8::Handle obj); -CFont* unwrap_Font (v8::Handle obj); -CLastFontOriginInfo* unwrap_LastFontOriginInfo(v8::Handle obj); - -void init_w (const v8::FunctionCallbackInfo& args); -void EndDraw_w (const v8::FunctionCallbackInfo& args); -void put_GlobalAlpha_w (const v8::FunctionCallbackInfo& args); -void Start_GlobalAlpha_w (const v8::FunctionCallbackInfo& args); -void End_GlobalAlpha_w (const v8::FunctionCallbackInfo& args); -void p_color_w (const v8::FunctionCallbackInfo& args); -void p_width_w (const v8::FunctionCallbackInfo& args); -void p_dash_w (const v8::FunctionCallbackInfo& args); -void b_color1_w (const v8::FunctionCallbackInfo& args); -void b_color2_w (const v8::FunctionCallbackInfo& args); -void transform_w (const v8::FunctionCallbackInfo& args); -void CalculateFullTransform_w (const v8::FunctionCallbackInfo& args); -void _s_w (const v8::FunctionCallbackInfo& args); -void _e_w (const v8::FunctionCallbackInfo& args); -void _z_w (const v8::FunctionCallbackInfo& args); -void _m_w (const v8::FunctionCallbackInfo& args); -void _l_w (const v8::FunctionCallbackInfo& args); -void _c_w (const v8::FunctionCallbackInfo& args); -void _c2_w (const v8::FunctionCallbackInfo& args); -void ds_w (const v8::FunctionCallbackInfo& args); -void df_w (const v8::FunctionCallbackInfo& args); -void save_w (const v8::FunctionCallbackInfo& args); -void restore_w (const v8::FunctionCallbackInfo& args); -void clip_w (const v8::FunctionCallbackInfo& args); -void reset_w (const v8::FunctionCallbackInfo& args); -void transform3_w (const v8::FunctionCallbackInfo& args); -void FreeFont_w (const v8::FunctionCallbackInfo& args); -void ClearLastFont_w (const v8::FunctionCallbackInfo& args); -void drawImage2_w (const v8::FunctionCallbackInfo& args); -void drawImage_w (const v8::FunctionCallbackInfo& args); -void GetFont_w (const v8::FunctionCallbackInfo& args); -void font_w (const v8::FunctionCallbackInfo& args); -void SetFont_w (const v8::FunctionCallbackInfo& args); -void SetTextPr_w (const v8::FunctionCallbackInfo& args); -void SetFontSlot_w (const v8::FunctionCallbackInfo& args); -void GetTextPr_w (const v8::FunctionCallbackInfo& args); -void FillText_w (const v8::FunctionCallbackInfo& args); -void t_w (const v8::FunctionCallbackInfo& args); -void FillText2_w (const v8::FunctionCallbackInfo& args); -void t2_w (const v8::FunctionCallbackInfo& args); -void FillTextCode_w (const v8::FunctionCallbackInfo& args); -void tg_w (const v8::FunctionCallbackInfo& args); -void charspace_w (const v8::FunctionCallbackInfo& args); -void private_FillGlyph_w (const v8::FunctionCallbackInfo& args); -void private_FillGlyphC_w (const v8::FunctionCallbackInfo& args); -void private_FillGlyph2_w (const v8::FunctionCallbackInfo& args); -void SetIntegerGrid_w (const v8::FunctionCallbackInfo& args); -void GetIntegerGrid_w (const v8::FunctionCallbackInfo& args); -void DrawStringASCII_w (const v8::FunctionCallbackInfo& args); -void DrawStringASCII2_w (const v8::FunctionCallbackInfo& args); -void DrawHeaderEdit_w (const v8::FunctionCallbackInfo& args); -void DrawFooterEdit_w (const v8::FunctionCallbackInfo& args); -void DrawLockParagraph_w (const v8::FunctionCallbackInfo& args); -void DrawLockObjectRect_w (const v8::FunctionCallbackInfo& args); -void DrawEmptyTableLine_w (const v8::FunctionCallbackInfo& args); -void DrawSpellingLine_w (const v8::FunctionCallbackInfo& args); -void drawHorLine_w (const v8::FunctionCallbackInfo& args); -void drawHorLine2_w (const v8::FunctionCallbackInfo& args); -void drawVerLine_w (const v8::FunctionCallbackInfo& args); -void drawHorLineExt_w (const v8::FunctionCallbackInfo& args); -void rect_w (const v8::FunctionCallbackInfo& args); -void TableRect_w (const v8::FunctionCallbackInfo& args); -void AddClipRect_w (const v8::FunctionCallbackInfo& args); -void RemoveClipRect_w (const v8::FunctionCallbackInfo& args); -void SetClip_w (const v8::FunctionCallbackInfo& args); -void RemoveClip_w (const v8::FunctionCallbackInfo& args); -void drawCollaborativeChanges_w(const v8::FunctionCallbackInfo& args); -void drawMailMergeField_w (const v8::FunctionCallbackInfo& args); -void drawSearchResult_w (const v8::FunctionCallbackInfo& args); -void drawFlowAnchor_w (const v8::FunctionCallbackInfo& args); -void SavePen_w (const v8::FunctionCallbackInfo& args); -void RestorePen_w (const v8::FunctionCallbackInfo& args); -void SaveBrush_w (const v8::FunctionCallbackInfo& args); -void RestoreBrush_w (const v8::FunctionCallbackInfo& args); -void SavePenBrush_w (const v8::FunctionCallbackInfo& args); -void RestorePenBrush_w (const v8::FunctionCallbackInfo& args); -void SaveGrState_w (const v8::FunctionCallbackInfo& args); -void RestoreGrState_w (const v8::FunctionCallbackInfo& args); -void StartClipPath_w (const v8::FunctionCallbackInfo& args); -void EndClipPath_w (const v8::FunctionCallbackInfo& args); -void StartCheckTableDraw_w (const v8::FunctionCallbackInfo& args); -void EndCheckTableDraw_w (const v8::FunctionCallbackInfo& args); -void SetTextClipRect_w (const v8::FunctionCallbackInfo& args); -void AddSmartRect_w (const v8::FunctionCallbackInfo& args); -void CheckUseFonts2_w (const v8::FunctionCallbackInfo& args); -void UncheckUseFonts2_w (const v8::FunctionCallbackInfo& args); -void Drawing_StartCheckBounds_w(const v8::FunctionCallbackInfo& args); -void Drawing_EndCheckBounds_w (const v8::FunctionCallbackInfo& args); -void DrawPresentationComment_w (const v8::FunctionCallbackInfo& args); -void DrawPolygon_w (const v8::FunctionCallbackInfo& args); -void DrawFootnoteRect_w (const v8::FunctionCallbackInfo& args); - -void m_oContext_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_dWidthMM_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_dHeightMM_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_lWidthPix_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_lHeightPix_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_dDpiX_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_dDpiY_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_bIsBreak_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_oPen_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_bPenColorInit_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_oBrush_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_bBrushColorInit_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_oFontManager_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_oCoordTransform_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_oBaseTransform_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_oTransform_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_oFullTransform_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_oInvertFullTransform_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void ArrayPoints_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_oCurFont_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_oTextPr_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_oGrFonts_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_oLastFont_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void LastFontOriginInfo_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_bIntegerGrid_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void ClipManager_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void TextureFillTransformScaleX_get_w(v8::Local _name, const v8::PropertyCallbackInfo& info); -void TextureFillTransformScaleY_get_w(v8::Local _name, const v8::PropertyCallbackInfo& info); -void IsThumbnail_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void IsDemonstrationMode_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void GrState_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void globalAlpha_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void TextClipRect_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void IsClipContext_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void IsUseFonts2_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_oFontManager2_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void m_oLastFont2_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void ClearMode_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void IsRetina_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); -void dash_no_smart_get_w (v8::Local _name, const v8::PropertyCallbackInfo& info); - -void m_oContext_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_dWidthMM_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_dHeightMM_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_lWidthPix_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_lHeightPix_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_dDpiX_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_dDpiY_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_bIsBreak_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_oPen_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_bPenColorInit_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_oBrush_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_bBrushColorInit_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_oFontManager_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_oCoordTransform_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_oBaseTransform_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_oTransform_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_oFullTransform_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_oInvertFullTransform_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void ArrayPoints_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_oCurFont_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_oTextPr_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_oGrFonts_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_oLastFont_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void LastFontOriginInfo_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_bIntegerGrid_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void ClipManager_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void TextureFillTransformScaleX_set_w(v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void TextureFillTransformScaleY_set_w(v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void IsThumbnail_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void IsDemonstrationMode_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void GrState_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void globalAlpha_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void TextClipRect_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void IsClipContext_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void IsUseFonts2_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_oFontManager2_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void m_oLastFont2_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void ClearMode_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void IsRetina_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); -void dash_no_smart_set_w (v8::Local _name, v8::Local value, const v8::PropertyCallbackInfo& info); - -v8::Handle CreateGraphicsTemplate(v8::Isolate* isolate); -void CreateGraphics(const v8::FunctionCallbackInfo& args);