From a70c3bf2b7c064d5f121a61c9a6ab3af075725f0 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Wed, 18 Nov 2020 17:24:33 +0300 Subject: [PATCH] DrawLockParagraph --- .../doctrenderer/embed/GraphicsEmbed.cpp | 8 +- .../doctrenderer/embed/GraphicsEmbed.h | 4 +- .../doctrenderer/embed/v8/v8_Graphics.cpp | 4 +- DesktopEditor/doctrenderer/graphics.cpp | 90 ++++++++++++++++++- DesktopEditor/doctrenderer/graphics.h | 4 +- .../doctrenderer/js/NativeGraphics.js | 62 +------------ DesktopEditor/doctrenderer/js/test.js | 1 + 7 files changed, 103 insertions(+), 70 deletions(-) diff --git a/DesktopEditor/doctrenderer/embed/GraphicsEmbed.cpp b/DesktopEditor/doctrenderer/embed/GraphicsEmbed.cpp index 16741fe66b..6d4d5d0798 100644 --- a/DesktopEditor/doctrenderer/embed/GraphicsEmbed.cpp +++ b/DesktopEditor/doctrenderer/embed/GraphicsEmbed.cpp @@ -251,9 +251,9 @@ JSSmart CGraphicsEmbed::DrawStringASCII (JSSmart text, JSSma m_pInternal->DrawStringASCII(text->toStringW(), x->toDouble(), y->toDouble()); return NULL; } -JSSmart CGraphicsEmbed::DrawStringASCII2(JSSmart name, JSSmart size, JSSmart bold, JSSmart italic, JSSmart text, JSSmart x, JSSmart y, JSSmart bIsHeader) +JSSmart CGraphicsEmbed::DrawStringASCII2(JSSmart text, JSSmart x, JSSmart y) { - m_pInternal->DrawStringASCII2(); + m_pInternal->DrawStringASCII2(text->toStringW(), x->toDouble(), y->toDouble()); return NULL; } JSSmart CGraphicsEmbed::DrawHeaderEdit(JSSmart yPos, JSSmart lock_type, JSSmart sectionNum, JSSmart bIsRepeat, JSSmart type) @@ -266,9 +266,9 @@ JSSmart CGraphicsEmbed::DrawFooterEdit(JSSmart yPos, JSSmart m_pInternal->DrawFooterEdit(yPos->toDouble()); return NULL; } -JSSmart CGraphicsEmbed::DrawLockParagraph (JSSmart lock_type, JSSmart x, JSSmart y1, JSSmart y2) +JSSmart CGraphicsEmbed::DrawLockParagraph (JSSmart x, JSSmart y1, JSSmart y2) { - m_pInternal->DrawLockParagraph(); + m_pInternal->DrawLockParagraph(x->toDouble(), y1->toDouble(), y2->toDouble()); return NULL; } JSSmart CGraphicsEmbed::DrawLockObjectRect(JSSmart lock_type, JSSmart x, JSSmart y, JSSmart w, JSSmart h) diff --git a/DesktopEditor/doctrenderer/embed/GraphicsEmbed.h b/DesktopEditor/doctrenderer/embed/GraphicsEmbed.h index b7c6369f35..ae22ab10e7 100644 --- a/DesktopEditor/doctrenderer/embed/GraphicsEmbed.h +++ b/DesktopEditor/doctrenderer/embed/GraphicsEmbed.h @@ -73,10 +73,10 @@ public: JSSmart SetIntegerGrid(JSSmart param); JSSmart GetIntegerGrid(); JSSmart DrawStringASCII (JSSmart text, JSSmart x, JSSmart y); - JSSmart DrawStringASCII2(JSSmart name, JSSmart size, JSSmart bold, JSSmart italic, JSSmart text, JSSmart x, JSSmart y, JSSmart bIsHeader); + JSSmart DrawStringASCII2(JSSmart text, JSSmart x, JSSmart y); 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 DrawLockParagraph (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); diff --git a/DesktopEditor/doctrenderer/embed/v8/v8_Graphics.cpp b/DesktopEditor/doctrenderer/embed/v8/v8_Graphics.cpp index 4dde783d4d..a88778e503 100644 --- a/DesktopEditor/doctrenderer/embed/v8/v8_Graphics.cpp +++ b/DesktopEditor/doctrenderer/embed/v8/v8_Graphics.cpp @@ -62,10 +62,10 @@ namespace NSGraphics FUNCTION_WRAPPER_V8_1(_SetIntegerGrid, SetIntegerGrid) FUNCTION_WRAPPER_V8 (_GetIntegerGrid, GetIntegerGrid) FUNCTION_WRAPPER_V8_3(_DrawStringASCII, DrawStringASCII) - FUNCTION_WRAPPER_V8_8(_DrawStringASCII2, DrawStringASCII2) + FUNCTION_WRAPPER_V8_3(_DrawStringASCII2, DrawStringASCII2) FUNCTION_WRAPPER_V8_5(_DrawHeaderEdit, DrawHeaderEdit) FUNCTION_WRAPPER_V8_5(_DrawFooterEdit, DrawFooterEdit) - FUNCTION_WRAPPER_V8_4(_DrawLockParagraph, DrawLockParagraph) + FUNCTION_WRAPPER_V8_3(_DrawLockParagraph, DrawLockParagraph) FUNCTION_WRAPPER_V8_5(_DrawLockObjectRect, DrawLockObjectRect) FUNCTION_WRAPPER_V8_4(_DrawEmptyTableLine, DrawEmptyTableLine) FUNCTION_WRAPPER_V8_4(_DrawSpellingLine, DrawSpellingLine) diff --git a/DesktopEditor/doctrenderer/graphics.cpp b/DesktopEditor/doctrenderer/graphics.cpp index d122b8306e..a79b98c811 100644 --- a/DesktopEditor/doctrenderer/graphics.cpp +++ b/DesktopEditor/doctrenderer/graphics.cpp @@ -237,7 +237,26 @@ void CGraphics::DrawStringASCII(const std::wstring& text, double x, double y) b_color1(225, 225, 225, 255); m_pRenderer->GetFontManager()->LoadString2(text, x, y); TBBox oBox = m_pRenderer->GetFontManager()->MeasureString2(); - rect(x, y, oBox.fMaxY - y, oBox.fMinX); + rect(x, y, oBox.fMinX, oBox.fMinY); + df(); + ds(); + + b_color1(68, 68, 68, 255); + t(x + 10.0 * 25.4 / DpiY, y - 5.0 * 25.4 / DpiY, text); + + RestorePenBrush(); +} +void CGraphics::DrawStringASCII2(const std::wstring& text, double x, double y) +{ + double DpiY; + m_pRenderer->get_DpiY(&DpiY); + + SavePenBrush(); + + b_color1(225, 225, 225, 255); + m_pRenderer->GetFontManager()->LoadString2(text, x, y); + TBBox oBox = m_pRenderer->GetFontManager()->MeasureString2(); + rect(x, y, oBox.fMinX, oBox.fMinY); df(); ds(); @@ -326,6 +345,75 @@ void CGraphics::DrawFooterEdit(double yPos) m_pRenderer->put_PenSize(dPenSize); m_pRenderer->put_PenDashStyle(nPenDashStyle); } +void CGraphics::DrawLockParagraph (double x, double y1, double y2) +{ + m_pRenderer->PathCommandEnd(); + + Aggplus::CMatrix* pFull = m_pRenderer->GetFullTransform(); + double dPenSize = 0.0; + m_pRenderer->get_PenSize(&dPenSize); + BYTE nPenDashStyle = 0; + m_pRenderer->get_PenDashStyle(&nPenDashStyle); + m_pRenderer->put_PenColor(0x009C16); + + double _x = x; + double _xT = x; + double _y1 = y1; + double _y2 = y2; + pFull->TransformPoint(_x, _y1); + pFull->TransformPoint(_xT, _y2); + + _x = ((int)_x); + _xT = ((int)_xT); + _y1 = ((int)_y1) + 0.5; + _y2 = ((int)_y2) - 1.5; + + m_pRenderer->put_PenSize(1); + m_pRenderer->PathCommandStart(); + + double dash[2] = { 2.0, 2.0 }; + m_pRenderer->put_PenDashStyle(Aggplus::DashStyleCustom); + m_pRenderer->PenDashPattern(dash, 2); + + if(fabs(_x - _xT) > 0.001) + { + m_pRenderer->PathCommandMoveTo(x, y1); + m_pRenderer->PathCommandLineTo(x, y2); + + m_pRenderer->PathCommandMoveTo(x, y1); + m_pRenderer->PathCommandLineTo(x + 3.0, y1); + + m_pRenderer->PathCommandMoveTo(x, y2); + m_pRenderer->PathCommandLineTo(x + 3.0, y2); + + m_pRenderer->Stroke(); + m_pRenderer->PathCommandEnd(); + } + else + { + bool bIsIntegerGrid = m_pRenderer->get_IntegerGrid(); + if (!bIsIntegerGrid) + m_pRenderer->put_IntegerGrid(true); + + m_pRenderer->PathCommandMoveTo(_x + 0.5, _y1 - 0.5); + m_pRenderer->PathCommandLineTo(_x + 0.5, _y2 - 2.0); + + m_pRenderer->PathCommandMoveTo(_x, _y1); + m_pRenderer->PathCommandLineTo(_x + 3.0, _y1); + + m_pRenderer->PathCommandMoveTo(_x, _y2); + m_pRenderer->PathCommandLineTo(_x + 3.0, _y2); + + m_pRenderer->Stroke(); + m_pRenderer->PathCommandEnd(); + + if (!bIsIntegerGrid) + m_pRenderer->put_IntegerGrid(false); + } + + m_pRenderer->put_PenSize(dPenSize); + m_pRenderer->put_PenDashStyle(nPenDashStyle); +} void CGraphics::DrawEmptyTableLine(double x1, double y1, double x2, double y2) { m_pRenderer->PathCommandEnd(); diff --git a/DesktopEditor/doctrenderer/graphics.h b/DesktopEditor/doctrenderer/graphics.h index 24e886df34..d6224e4d3b 100644 --- a/DesktopEditor/doctrenderer/graphics.h +++ b/DesktopEditor/doctrenderer/graphics.h @@ -165,10 +165,10 @@ namespace NSGraphics void SetIntegerGrid(bool param); bool GetIntegerGrid(); void DrawStringASCII(const std::wstring& text, double x, double y); - void DrawStringASCII2() {} + void DrawStringASCII2(const std::wstring& text, double x, double y); void DrawHeaderEdit(double yPos); void DrawFooterEdit(double yPos); - void DrawLockParagraph () {} + void DrawLockParagraph (double x, double y1, double y2); void DrawLockObjectRect() {} void DrawEmptyTableLine(double x1, double y1, double x2, double y2); void DrawSpellingLine (double y0, double x0, double x1, double w); diff --git a/DesktopEditor/doctrenderer/js/NativeGraphics.js b/DesktopEditor/doctrenderer/js/NativeGraphics.js index 16d6b0da17..019d122cc8 100644 --- a/DesktopEditor/doctrenderer/js/NativeGraphics.js +++ b/DesktopEditor/doctrenderer/js/NativeGraphics.js @@ -290,64 +290,8 @@ CNativeGraphics.prototype = }, DrawStringASCII2 : function(name, size, bold, italic, text, x, y, bIsHeader) { - var _textProp = { - RFonts : { Ascii : { Name : name, Index : -1 } }, - FontSize : (((size * 2 * 96 / this.m_dDpiY) + 0.5) >> 0) / 2, - Bold : false, - Italic : false - }; - - this.m_oTextPr = _textProp; - this.m_oGrFonts.Ascii.Name = this.m_oTextPr.RFonts.Ascii.Name; - this.m_oGrFonts.Ascii.Index = -1; - - this.SetFontSlot(fontslot_ASCII, 1); - - this.m_oFontManager.LoadString2(text, 0, 0); - var measure = this.m_oFontManager.MeasureString2(); - - var _ctx = this.m_oContext; - _ctx.beginPath(); - _ctx.fillStyle = "#E1E1E1"; - _ctx.strokeStyle = GlobalSkin.RulerOutline; - this.m_bBrushColorInit = false; - this.m_bPenColorInit = false; - - var _xPxOffset = 10; - var _yPxOffset = 5; - if (AscCommon.AscBrowser.isRetina) - { - _xPxOffset = (_xPxOffset * AscCommon.AscBrowser.retinaPixelRatio) >> 0; - _yPxOffset = (_yPxOffset * AscCommon.AscBrowser.retinaPixelRatio) >> 0; - } - - var __x = this.m_oFullTransform.TransformPointX(this.m_dWidthMM - x, y) >> 0; - var __y = this.m_oFullTransform.TransformPointY(this.m_dWidthMM - x, y) >> 0; - var __w = (measure.fWidth >> 0) + 2 * _xPxOffset; - var __h = (Math.abs(measure.fY) >> 0) + 2 * _yPxOffset; - __x -= __w; - - if (!bIsHeader) - __y -= __h; - - if (!AscCommon.AscBrowser.isRetina) - _ctx.rect(__x + 0.5, __y + 0.5, __w, __h); - else - _ctx.rect(__x, __y, __w, __h); - - _ctx.fill(); - _ctx.stroke(); - _ctx.beginPath(); - - this.b_color1(68, 68, 68, 255); - - var _koef_px_to_mm = 25.4 / this.m_dDpiY; - - var xPos = this.m_dWidthMM - x - (__w - _xPxOffset) * _koef_px_to_mm; - - this.t(text, xPos, y + ((bIsHeader ? __h : 0) - _yPxOffset) * _koef_px_to_mm); - - this.Native["DrawStringASCII2"](name, size, bold, italic, text, x, y, bIsHeader); + this.SetFont({FontFamily : {Name : name, Index : -1}, FontSize : size, Italic : italic, Bold : bold}); + this.Native["DrawStringASCII2"](text, x, y); }, DrawHeaderEdit : function(yPos, lock_type, sectionNum, bIsRepeat, type) { @@ -359,7 +303,7 @@ CNativeGraphics.prototype = }, DrawLockParagraph : function(lock_type, x, y1, y2) { - this.Native["DrawLockParagraph"](lock_type, x, y1, y2); + this.Native["DrawLockParagraph"](x, y1, y2); }, DrawLockObjectRect : function(lock_type, x, y, w, h) { diff --git a/DesktopEditor/doctrenderer/js/test.js b/DesktopEditor/doctrenderer/js/test.js index 371155267f..7fa5c26f7d 100644 --- a/DesktopEditor/doctrenderer/js/test.js +++ b/DesktopEditor/doctrenderer/js/test.js @@ -77,6 +77,7 @@ MyGraphics.reset(); MyGraphics.DrawStringASCII("Times New Roman", 16, false, false, "Test TEXT TEXT TEXT TEXT", 10, 210, false); MyGraphics.DrawEmptyTableLine(10, 110, 110, 210); MyGraphics.DrawSpellingLine(120, 10, 100, 5); +MyGraphics.DrawLockParagraph(null, 10, 110, 200); var imageBase64 = MyGraphics.toDataURL("png"); MyGraphics.save();