From 7a337f7c0446f2d5075bbcd1943773e519b56768 Mon Sep 17 00:00:00 2001 From: Kulikova Svetlana Date: Wed, 28 Oct 2020 14:49:27 +0300 Subject: [PATCH] refactoring --- DesktopEditor/doctrenderer/docbuilder_p.h | 2 +- .../doctrenderer/embed/GraphicsEmbed.cpp | 16 +- DesktopEditor/doctrenderer/graphics.cpp | 182 ++++----- DesktopEditor/doctrenderer/graphics.h | 40 +- .../doctrenderer/js/NativeGraphics.js | 374 +++++++++++++++--- 5 files changed, 420 insertions(+), 194 deletions(-) diff --git a/DesktopEditor/doctrenderer/docbuilder_p.h b/DesktopEditor/doctrenderer/docbuilder_p.h index 1edf25f99c..245e9e93a0 100644 --- a/DesktopEditor/doctrenderer/docbuilder_p.h +++ b/DesktopEditor/doctrenderer/docbuilder_p.h @@ -318,7 +318,7 @@ namespace NSDoctRenderer oWorker.m_bIsUseSystemFonts = bIsCheckSystemFonts; oWorker.m_bIsNeedThumbnails = false; oWorker.m_sDirectory = sDirectory; - NSGraphics::CGraphics::m_sApplicvationFontsDirectory = sDirectory; + NSGraphics::CGraphics::m_sApplicationFontsDirectory = sDirectory; NSFonts::IApplicationFonts* pFonts = oWorker.Check(); if(pFonts) pFonts->Release(); diff --git a/DesktopEditor/doctrenderer/embed/GraphicsEmbed.cpp b/DesktopEditor/doctrenderer/embed/GraphicsEmbed.cpp index 522a6a85db..8079d1a64e 100644 --- a/DesktopEditor/doctrenderer/embed/GraphicsEmbed.cpp +++ b/DesktopEditor/doctrenderer/embed/GraphicsEmbed.cpp @@ -65,7 +65,7 @@ JSSmart CGraphicsEmbed::transform(JSSmart sx, JSSmart CGraphicsEmbed::CalculateFullTransform(JSSmart isInvertNeed) { - m_pInternal->CalculateFullTransform(isInvertNeed->toBool()); + m_pInternal->CalculateFullTransform(); return NULL; } JSSmart CGraphicsEmbed::_s() @@ -165,7 +165,7 @@ JSSmart CGraphicsEmbed::GetFont() } JSSmart CGraphicsEmbed::font(JSSmart font_id, JSSmart font_size) { - m_pInternal->font(font_id->toInt32(), font_size->toInt32()); + m_pInternal->font(); return NULL; } JSSmart CGraphicsEmbed::SetFont(JSSmart path, JSSmart face, JSSmart size, JSSmart style) @@ -200,7 +200,7 @@ JSSmart CGraphicsEmbed::t(JSSmart x, JSSmart y, JS } JSSmart CGraphicsEmbed::FillText2(JSSmart x, JSSmart y, JSSmart text, JSSmart cropX, JSSmart cropW) { - m_pInternal->FillText2(x->toDouble(), y->toDouble(), text->toInt32(), cropX->toDouble(), cropW->toDouble()); + m_pInternal->FillText(x->toDouble(), y->toDouble(), text->toInt32()); return NULL; } JSSmart CGraphicsEmbed::t2(JSSmart x, JSSmart y, JSSmart _arr, JSSmart cropX, JSSmart cropW) @@ -210,7 +210,7 @@ JSSmart CGraphicsEmbed::t2(JSSmart x, JSSmart y, J } JSSmart CGraphicsEmbed::FillTextCode(JSSmart x, JSSmart y, JSSmart lUnicode) { - m_pInternal->FillTextCode(x->toDouble(), y->toDouble(), lUnicode->toInt32()); + m_pInternal->FillText(x->toDouble(), y->toDouble(), lUnicode->toInt32()); return NULL; } JSSmart CGraphicsEmbed::tg(JSSmart text, JSSmart x, JSSmart y) @@ -260,22 +260,22 @@ JSSmart CGraphicsEmbed::DrawStringASCII2(JSSmart name, JSSma } JSSmart CGraphicsEmbed::DrawHeaderEdit(JSSmart yPos, JSSmart lock_type, JSSmart sectionNum, JSSmart bIsRepeat, JSSmart type) { - m_pInternal->DrawHeaderEdit(yPos->toDouble(), lock_type->toInt32()); + m_pInternal->DrawHeaderEdit(yPos->toDouble()); return NULL; } JSSmart CGraphicsEmbed::DrawFooterEdit(JSSmart yPos, JSSmart lock_type, JSSmart sectionNum, JSSmart bIsRepeat, JSSmart type) { - m_pInternal->DrawFooterEdit(yPos->toDouble(), lock_type->toInt32()); + m_pInternal->DrawFooterEdit(yPos->toDouble()); return NULL; } JSSmart CGraphicsEmbed::DrawLockParagraph (JSSmart lock_type, JSSmart x, JSSmart y1, JSSmart y2) { - m_pInternal->DrawLockParagraph(lock_type->toInt32(), x->toDouble(), y1->toDouble(), y2->toDouble()); + m_pInternal->DrawLockParagraph(); return NULL; } JSSmart CGraphicsEmbed::DrawLockObjectRect(JSSmart lock_type, JSSmart x, JSSmart y, JSSmart w, JSSmart h) { - m_pInternal->DrawLockObjectRect(lock_type->toInt32(), x->toDouble(), y->toDouble(), w->toDouble(), h->toDouble()); + m_pInternal->DrawLockObjectRect(); return NULL; } JSSmart CGraphicsEmbed::DrawEmptyTableLine(JSSmart x1, JSSmart y1, JSSmart x2, JSSmart y2) diff --git a/DesktopEditor/doctrenderer/graphics.cpp b/DesktopEditor/doctrenderer/graphics.cpp index 1d17cac38f..315b6d077a 100644 --- a/DesktopEditor/doctrenderer/graphics.cpp +++ b/DesktopEditor/doctrenderer/graphics.cpp @@ -3,14 +3,14 @@ #include #include -std::wstring NSGraphics::CGraphics::m_sApplicvationFontsDirectory; +std::wstring NSGraphics::CGraphics::m_sApplicationFontsDirectory; namespace NSGraphics { void CGraphics::init(double width_px, double height_px, double width_mm, double height_mm) { m_pApplicationFonts = NSFonts::NSApplication::Create(); - m_pApplicationFonts->InitializeFromFolder(m_sApplicvationFontsDirectory.empty() ? NSFile::GetProcessDirectory() : m_sApplicvationFontsDirectory); + m_pApplicationFonts->InitializeFromFolder(m_sApplicationFontsDirectory.empty() ? NSFile::GetProcessDirectory() : m_sApplicationFontsDirectory); NSFonts::IFontManager* pManager = m_pApplicationFonts->GenerateFontManager(); @@ -126,7 +126,7 @@ void CGraphics::_l(double x, double y) m_pRenderer->PathCommandLineTo((int)x + 0.5, (int)y + 0.5); } } -void CGraphics::_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) { m_pRenderer->PathCommandCurveTo(x1, y1, x2, y2, x3, y3); } @@ -142,76 +142,95 @@ void CGraphics::df() { m_pRenderer->Fill(); } - void CGraphics::restore() { m_pRenderer->BeginCommand(c_nResetClipType); - m_pRenderer->EndCommand(c_nResetClipType); + m_pRenderer->EndCommand (c_nResetClipType); } - void CGraphics::clip() { m_pRenderer->BeginCommand(c_nClipType); - m_pRenderer->EndCommand(c_nClipType); + m_pRenderer->EndCommand (c_nClipType); } - void CGraphics::reset() { m_pRenderer->ResetTransform(); } - void CGraphics::transform3(double sx, double shy, double shx, double sy, double tx, double ty) { m_pRenderer->SetTransform(sx, shy, shx, sy, tx, ty); } - void CGraphics::drawImage(const std::wstring& img, double x, double y, double w, double h, BYTE alpha) { std::wstring strImage = (0 == img.find(L"theme") ? m_sThemesDirectory : m_sImagesDirectory) + img; m_pRenderer->DrawImageFromFile(strImage, x, y, w, h, alpha); } - void CGraphics::SetFont(const std::wstring& path, int face, double size, int style) { m_pRenderer->put_FontPath((std::string::npos == path.find(L'/') ? m_sFontsDirectory : L"") + path); m_pRenderer->put_FontFaceIndex(face); - m_pRenderer->put_FontSize(size); - m_pRenderer->put_FontStyle(style); + m_pRenderer->put_FontSize (size); + m_pRenderer->put_FontStyle (style); } - void CGraphics::FillText(double x, double y, int text) { m_pRenderer->CommandDrawTextCHAR(text, x, y, 0, 0); } - -void CGraphics::FillText2(double x, double y, int text, double cropX, double cropW) -{ - m_pRenderer->CommandDrawTextCHAR(text, x, y, 0, 0); -} - -void CGraphics::FillTextCode(double x, double y, int lUnicode) -{ - m_pRenderer->CommandDrawTextCHAR(lUnicode, x, y, 0, 0); -} - void CGraphics::tg(int text, double x, double y) { m_pRenderer->put_FontStringGID(TRUE); m_pRenderer->CommandDrawTextCHAR(text, x, y, 0, 0); m_pRenderer->put_FontStringGID(FALSE); } - void CGraphics::SetIntegerGrid(bool param) { m_pRenderer->put_IntegerGrid(param); } - bool CGraphics::GetIntegerGrid() { return m_pRenderer->get_IntegerGrid(); } +void CGraphics::DrawHeaderEdit(double yPos) +{ + m_pRenderer->PathCommandEnd(); -void CGraphics::DrawHeaderEdit(double yPos, BYTE lock_type) + Aggplus::CMatrix* pFull = m_pRenderer->GetFullTransform(); + double dPenSize = 0; + m_pRenderer->get_PenSize(&dPenSize); + + double _width; + m_pRenderer->get_Width(&_width); + pFull->TransformPoint(_width, yPos); + + BYTE nPenDashStyle = 0; + m_pRenderer->get_PenDashStyle(&nPenDashStyle); + + bool bIsIntegerGrid = m_pRenderer->get_IntegerGrid(); + if (!bIsIntegerGrid) + m_pRenderer->put_IntegerGrid(true); + + m_pRenderer->put_PenSize(2); + m_pRenderer->PathCommandStart(); + + double dash[2] = { 6, 3 }; + m_pRenderer->put_PenDashStyle(Aggplus::DashStyleCustom); + m_pRenderer->PenDashPattern(dash, 2); + + m_pRenderer->put_PenColor(0xBBBEC2); + + m_pRenderer->PathCommandMoveTo(0, (int)(yPos)); + m_pRenderer->PathCommandLineTo(_width, (int)(yPos)); + + 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::DrawFooterEdit(double yPos) { m_pRenderer->PathCommandEnd(); @@ -251,48 +270,6 @@ void CGraphics::DrawHeaderEdit(double yPos, BYTE lock_type) m_pRenderer->put_PenSize(dPenSize); m_pRenderer->put_PenDashStyle(nPenDashStyle); } - -void CGraphics::DrawFooterEdit(double yPos, BYTE lock_type) -{ - m_pRenderer->PathCommandEnd(); - - Aggplus::CMatrix* pFull = m_pRenderer->GetFullTransform(); - double dPenSize = 0; - m_pRenderer->get_PenSize(&dPenSize); - - double _width; - m_pRenderer->get_Width(&_width); - pFull->TransformPoint(_width, yPos); - - BYTE nPenDashStyle = 0; - m_pRenderer->get_PenDashStyle(&nPenDashStyle); - - bool bIsIntegerGrid = m_pRenderer->get_IntegerGrid(); - if (!bIsIntegerGrid) - m_pRenderer->put_IntegerGrid(true); - - m_pRenderer->put_PenSize(2); - m_pRenderer->PathCommandStart(); - - double dash[2] = { 6, 3 }; - m_pRenderer->put_PenDashStyle(Aggplus::DashStyleCustom); - m_pRenderer->PenDashPattern(dash, 2); - - m_pRenderer->put_PenColor(0xBBBEC2); - - m_pRenderer->PathCommandMoveTo(0, (int)(yPos)); - m_pRenderer->PathCommandLineTo(_width, (int)(yPos)); - - 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(); @@ -375,8 +352,7 @@ void CGraphics::DrawEmptyTableLine(double x1, double y1, double x2, double y2) m_pRenderer->put_PenSize(dPenSize); m_pRenderer->put_PenDashStyle(nPenDashStyle); } - -void CGraphics::DrawSpellingLine(double y0, double x0, double x1, double w) +void CGraphics::DrawSpellingLine (double y0, double x0, double x1, double w) { Aggplus::CMatrix* pMatrix = m_pRenderer->GetTransformMatrix(); if (!m_pRenderer->get_IntegerGrid()) @@ -415,8 +391,7 @@ void CGraphics::DrawSpellingLine(double y0, double x0, double x1, double w) } } - -void CGraphics::drawHorLine(BYTE align, double y, double x, double r, double penW) +void CGraphics::drawHorLine (BYTE align, double y, double x, double r, double penW) { Aggplus::CMatrix* pMatrix = m_pRenderer->GetTransformMatrix(); if (!m_pRenderer->get_IntegerGrid()) @@ -455,8 +430,7 @@ void CGraphics::drawHorLine(BYTE align, double y, double x, double r, double pen } } - -void CGraphics::drawHorLine2(BYTE align, double y, double x, double r, double penW) +void CGraphics::drawHorLine2 (BYTE align, double y, double x, double r, double penW) { Aggplus::CMatrix* pMatrix = m_pRenderer->GetTransformMatrix(); if (!m_pRenderer->get_IntegerGrid()) @@ -510,8 +484,7 @@ void CGraphics::drawHorLine2(BYTE align, double y, double x, double r, double pe } } } - -void CGraphics::drawVerLine(BYTE align, double x, double y, double b, double penW) +void CGraphics::drawVerLine (BYTE align, double x, double y, double b, double penW) { if (!m_pRenderer->get_IntegerGrid()) { @@ -536,7 +509,6 @@ void CGraphics::drawVerLine(BYTE align, double x, double y, double b, double pen m_pRenderer->drawVerLine(align, x, y, b, penW); } } - void CGraphics::drawHorLineExt(BYTE align, double y, double x, double r, double penW, double leftMW, double rightMW) { if (!m_pRenderer->get_IntegerGrid()) @@ -562,8 +534,7 @@ void CGraphics::drawHorLineExt(BYTE align, double y, double x, double r, double m_pRenderer->drawHorLineExt(align, y, x, r, penW, leftMW, rightMW); } } - -void CGraphics::rect(double x, double y, double w, double h) +void CGraphics::rect (double x, double y, double w, double h) { m_pRenderer->PathCommandEnd(); if (m_pRenderer->get_IntegerGrid()) @@ -586,7 +557,6 @@ void CGraphics::rect(double x, double y, double w, double h) m_pRenderer->AddRect(x, y, w, h); } } - void CGraphics::TableRect(double x, double y, double w, double h) { m_pRenderer->PathCommandEnd(); @@ -626,7 +596,7 @@ void CGraphics::AddClipRect(double x, double y, double w, double h) _histClip->Rect.right = x + w; _histClip->Rect.bottom = y + h; - oGrState.Clips.push_back(_histClip); + m_oGrState.Clips.push_back(_histClip); StartClipPath(); @@ -668,19 +638,19 @@ void CGraphics::SavePen() { CGrStatePen* pState = new CGrStatePen(); m_pRenderer->SavePen(pState->m_oPen); - oGrState.States.push_back(pState); + m_oGrState.States.push_back(pState); } void CGraphics::RestorePen() { - if (oGrState.States.empty()) + if (m_oGrState.States.empty()) return; - IGrState* pState = oGrState.States.back(); + IGrState* pState = m_oGrState.States.back(); if (pState->m_eType == gstPen) { m_pRenderer->RestorePen(((CGrStatePen*)pState)->m_oPen); - oGrState.States.pop_back(); + m_oGrState.States.pop_back(); RELEASEOBJECT(pState); } } @@ -689,19 +659,19 @@ void CGraphics::SaveBrush() { CGrStateBrush* pState = new CGrStateBrush(); m_pRenderer->SaveBrush(pState->m_oBrush); - oGrState.States.push_back(pState); + m_oGrState.States.push_back(pState); } void CGraphics::RestoreBrush() { - if (oGrState.States.empty()) + if (m_oGrState.States.empty()) return; - IGrState* pState = oGrState.States.back(); + IGrState* pState = m_oGrState.States.back(); if (pState->m_eType == gstBrush) { m_pRenderer->RestoreBrush(((CGrStateBrush*)pState)->m_oBrush); - oGrState.States.pop_back(); + m_oGrState.States.pop_back(); RELEASEOBJECT(pState); } } @@ -711,20 +681,20 @@ void CGraphics::SavePenBrush() CGrStatePenBrush* pState = new CGrStatePenBrush(); m_pRenderer->SavePen(pState->m_oPen); m_pRenderer->SaveBrush(pState->m_oBrush); - oGrState.States.push_back(pState); + m_oGrState.States.push_back(pState); } void CGraphics::RestorePenBrush() { - if (oGrState.States.empty()) + if (m_oGrState.States.empty()) return; - IGrState* pState = oGrState.States.back(); + IGrState* pState = m_oGrState.States.back(); if (pState->m_eType == gstPenBrush) { m_pRenderer->RestorePen(((CGrStatePenBrush*)pState)->m_oPen); m_pRenderer->RestoreBrush(((CGrStatePenBrush*)pState)->m_oBrush); - oGrState.States.pop_back(); + m_oGrState.States.pop_back(); RELEASEOBJECT(pState); } } @@ -733,32 +703,32 @@ void CGraphics::SaveGrState() { CGrStateState* pState = new CGrStateState(); pState->IsIntegerGrid = m_pRenderer->get_IntegerGrid(); - pState->Clips = oGrState.Clips; + pState->Clips = m_oGrState.Clips; double sx, shy, shx, sy, tx, ty; m_pRenderer->GetTransform(&sx, ­, &shx, &sy, &tx, &ty); pState->Transform.SetElements(sx, shy, shx, sy, tx, ty); - oGrState.Clips.clear(); - oGrState.States.push_back(pState); + m_oGrState.Clips.clear(); + m_oGrState.States.push_back(pState); } void CGraphics::RestoreGrState() { - if (oGrState.States.empty()) + if (m_oGrState.States.empty()) return; - IGrState* pState = oGrState.States.back(); + IGrState* pState = m_oGrState.States.back(); if (pState->m_eType != gstState) return; CGrStateState* pGrState = (CGrStateState*)pState; - if (!oGrState.Clips.empty()) + if (!m_oGrState.Clips.empty()) { RemoveClip(); - for (IGrState* i : oGrState.States) + for (IGrState* i : m_oGrState.States) { if (i->m_eType == gstState) { @@ -790,13 +760,13 @@ void CGraphics::RestoreGrState() } } - for (CHist_Clip* pClip : oGrState.Clips) + for (CHist_Clip* pClip : m_oGrState.Clips) RELEASEOBJECT(pClip); - oGrState.Clips.clear(); + m_oGrState.Clips.clear(); - oGrState.Clips = pGrState->Clips; + m_oGrState.Clips = pGrState->Clips; pGrState->Clips.clear(); - oGrState.States.pop_back(); + m_oGrState.States.pop_back(); Aggplus::CMatrix& oMatrix = pGrState->Transform; transform3(oMatrix.sx(), oMatrix.shy(), oMatrix.shx(), oMatrix.sy(), oMatrix.tx(), oMatrix.ty()); diff --git a/DesktopEditor/doctrenderer/graphics.h b/DesktopEditor/doctrenderer/graphics.h index 8493d2349a..015325823c 100644 --- a/DesktopEditor/doctrenderer/graphics.h +++ b/DesktopEditor/doctrenderer/graphics.h @@ -2,7 +2,6 @@ #define CGRAPHICS_H #include -#include #include "../common/Types.h" #include "../common/File.h" @@ -96,25 +95,24 @@ namespace NSGraphics class CGraphics { public: - static std::wstring m_sApplicvationFontsDirectory; + static std::wstring m_sApplicationFontsDirectory; private: - NSFonts::IApplicationFonts* m_pApplicationFonts; + NSFonts ::IApplicationFonts* m_pApplicationFonts; NSGraphics::IGraphicsRenderer* m_pRenderer; CBgraFrame m_oFrame; - CGrState oGrState; + CGrState m_oGrState; std::wstring m_sFontsDirectory; std::wstring m_sImagesDirectory; std::wstring m_sThemesDirectory; public: - CGraphics() - { - } + CGraphics() {} ~CGraphics() { - RELEASEOBJECT(m_pRenderer); + RELEASEINTERFACE(m_pRenderer); + RELEASEINTERFACE(m_pApplicationFonts); } void init(double width_px, double height_px, double width_mm, double height_mm); @@ -130,7 +128,7 @@ namespace NSGraphics 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) {} + void CalculateFullTransform() {} // path commands void _s(); void _e(); @@ -153,15 +151,13 @@ namespace NSGraphics void drawImage(const std::wstring& img, double x, double y, double w, double h, BYTE alpha); // text void GetFont() {} - void font(int font_id, int font_size) {} + void font() {} void SetFont(const std::wstring& path, int face, double size, int style); void SetTextPr() {} void GetTextPr() {} void FillText(double x, double y, int text); void t() {} - void FillText2(double x, double y, int text, double cropX, double cropW); void t2() {} - void FillTextCode(double x, double y, int lUnicode); void tg(int text, double x, double y); void charspace() {} // private methods @@ -172,29 +168,29 @@ namespace NSGraphics bool GetIntegerGrid(); void DrawStringASCII() {} void DrawStringASCII2() {} - void DrawHeaderEdit(double yPos, BYTE lock_type); - void DrawFooterEdit(double yPos, BYTE lock_type); - void DrawLockParagraph (BYTE lock_type, double x, double y1, double y2) {} - void DrawLockObjectRect(BYTE lock_type, double x, double y, double w, double h) {} + void DrawHeaderEdit(double yPos); + void DrawFooterEdit(double yPos); + void DrawLockParagraph () {} + void DrawLockObjectRect() {} void DrawEmptyTableLine(double x1, double y1, double x2, double y2); - void DrawSpellingLine(double y0, double x0, double x1, double w); + void DrawSpellingLine (double y0, double x0, double x1, double w); // smart methods for horizontal / vertical lines void drawHorLine (BYTE align, double y, double x, double r, double penW); void drawHorLine2(BYTE align, double y, double x, double r, double penW); void drawVerLine (BYTE align, double x, double y, double b, double penW); // мега крутые функции для таблиц void drawHorLineExt(BYTE align, double y, double x, double r, double penW, double leftMW, double rightMW); - void rect(double x, double y, double w, double h); + 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(double x, double y, double w, double h) {} + void SetClip (double x, double y, double w, double h) {} void RemoveClip() {} void drawCollaborativeChanges(double x, double y, double w, double h, int r, int g, int b, int a); - 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 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(); diff --git a/DesktopEditor/doctrenderer/js/NativeGraphics.js b/DesktopEditor/doctrenderer/js/NativeGraphics.js index a4c859e5ba..6d376f72bf 100644 --- a/DesktopEditor/doctrenderer/js/NativeGraphics.js +++ b/DesktopEditor/doctrenderer/js/NativeGraphics.js @@ -331,13 +331,6 @@ CNativeGraphics.prototype = transform3 : function(m, isNeedInvert) { this.Native["transform3"](m.sx, m.shy, m.shx, m.sy, m.tx, m.ty, isNeedInvert); - /* - if (null != this.m_oFontManager && false !== isNeedInvert) - { - this.m_oFontManager.SetTextMatrix(this.m_oTransform.sx, this.m_oTransform.shy, this.m_oTransform.shx, - this.m_oTransform.sy, this.m_oTransform.tx, this.m_oTransform.ty); - } - */ }, FreeFont : function() { @@ -362,7 +355,7 @@ CNativeGraphics.prototype = // text GetFont : function() { - this.Native["GetFont"](); + // this.Native["GetFont"](); return this.m_oCurFont; }, font : function(font_id, font_size) @@ -374,31 +367,163 @@ CNativeGraphics.prototype = if (null == font) return; - this.m_oCurFont = - { - FontFamily : - { - Index : font.FontFamily.Index, - Name : font.FontFamily.Name - }, - FontSize : font.FontSize, - Bold : font.Bold, - Italic : font.Italic - }; + this.m_oCurFont.Name = font.FontFamily.Name; + this.m_oCurFont.FontSize = font.FontSize; + this.m_oCurFont.Bold = font.Bold; + this.m_oCurFont.Italic = font.Italic; var bItalic = true === font.Italic; var bBold = true === font.Bold; - var oFontStyle = FontStyle.FontStyleRegular; + var oFontStyle = AscFonts.FontStyle.FontStyleRegular; if ( !bItalic && bBold ) - oFontStyle = FontStyle.FontStyleBold; + oFontStyle = AscFonts.FontStyle.FontStyleBold; else if ( bItalic && !bBold ) - oFontStyle = FontStyle.FontStyleItalic; + oFontStyle = AscFonts.FontStyle.FontStyleItalic; else if ( bItalic && bBold ) - oFontStyle = FontStyle.FontStyleBoldItalic; + oFontStyle = AscFonts.FontStyle.FontStyleBoldItalic; var _fontinfo = AscFonts.g_fontApplication.GetFontInfo(font.FontFamily.Name, oFontStyle, this.LastFontOriginInfo); - var _info = GetLoadInfoForMeasurer(_fontinfo, oFontStyle); + + // подбираем шрифт по стилю + var bNeedBold = false; + var bNeedItalic = false; + var index = -1; + var faceIndex = 0; + var bSrcItalic = false; + var bSrcBold = false; + + switch (oFontStyle) + { + case AscFonts.FontStyle.FontStyleBoldItalic: + { + bSrcItalic = true; + bSrcBold = true; + + bNeedBold = true; + bNeedItalic = true; + if (-1 != _fontinfo.indexBI) + { + index = _fontinfo.indexBI; + faceIndex = _fontinfo.faceIndexBI; + bNeedBold = false; + bNeedItalic = false; + } + else if (-1 != _fontinfo.indexB) + { + index = _fontinfo.indexB; + faceIndex = _fontinfo.faceIndexB; + bNeedBold = false; + } + else if (-1 != _fontinfo.indexI) + { + index = _fontinfo.indexI; + faceIndex = _fontinfo.faceIndexI; + bNeedItalic = false; + } + else + { + index = _fontinfo.indexR; + faceIndex = _fontinfo.faceIndexR; + } + break; + } + case AscFonts.FontStyle.FontStyleBold: + { + bSrcBold = true; + + bNeedBold = true; + bNeedItalic = false; + if (-1 != _fontinfo.indexB) + { + index = _fontinfo.indexB; + faceIndex = _fontinfo.faceIndexB; + bNeedBold = false; + } + else if (-1 != _fontinfo.indexR) + { + index = _fontinfo.indexR; + faceIndex = _fontinfo.faceIndexR; + } + else if (-1 != _fontinfo.indexBI) + { + index = _fontinfo.indexBI; + faceIndex = _fontinfo.faceIndexBI; + bNeedBold = false; + } + else + { + index = _fontinfo.indexI; + faceIndex = _fontinfo.faceIndexI; + } + break; + } + case AscFonts.FontStyle.FontStyleItalic: + { + bSrcItalic = true; + + bNeedBold = false; + bNeedItalic = true; + if (-1 != _fontinfo.indexI) + { + index = _fontinfo.indexI; + faceIndex = _fontinfo.faceIndexI; + bNeedItalic = false; + } + else if (-1 != _fontinfo.indexR) + { + index = _fontinfo.indexR; + faceIndex = _fontinfo.faceIndexR; + } + else if (-1 != _fontinfo.indexBI) + { + index = _fontinfo.indexBI; + faceIndex = _fontinfo.faceIndexBI; + bNeedItalic = false; + } + else + { + index = _fontinfo.indexB; + faceIndex = _fontinfo.faceIndexB; + } + break; + } + case AscFonts.FontStyle.FontStyleRegular: + { + bNeedBold = false; + bNeedItalic = false; + if (-1 != _fontinfo.indexR) + { + index = _fontinfo.indexR; + faceIndex = _fontinfo.faceIndexR; + } + else if (-1 != _fontinfo.indexI) + { + index = _fontinfo.indexI; + faceIndex = _fontinfo.faceIndexI; + } + else if (-1 != _fontinfo.indexB) + { + index = _fontinfo.indexB; + faceIndex = _fontinfo.faceIndexB; + } + else + { + index = _fontinfo.indexBI; + faceIndex = _fontinfo.faceIndexBI; + } + } + } + + var _info = + { + Path : AscFonts.g_font_files[index].Id, + FaceIndex : faceIndex, + NeedBold : bNeedBold, + NeedItalic : bNeedItalic, + SrcBold : bSrcBold, + SrcItalic : bSrcItalic + }; var flag = 0; if (_info.NeedBold) flag |= 0x01; @@ -415,11 +540,11 @@ CNativeGraphics.prototype = this.m_oGrFonts.checkFromTheme(theme.themeElements.fontScheme, this.m_oTextPr.RFonts); else this.m_oGrFonts = this.m_oTextPr.RFonts; - this.Native["SetTextPr"](textPr, theme); + // this.Native["SetTextPr"](textPr, theme); }, SetFontSlot : function(slot, fontSizeKoef) { - var _rfonts = this.m_oGrFonts; + var _rfonts = this.m_oGrFonts; var _lastFont = this.IsUseFonts2 ? this.m_oLastFont2 : this.m_oLastFont; switch (slot) @@ -472,14 +597,155 @@ CNativeGraphics.prototype = if (_lastFont.Bold) _style += 1; - if (_lastFont.Name != _lastFont.SetUpName || _lastFont.Size != _lastFont.SetUpSize || _style != _lastFont.SetUpStyle) + var _font_manager = this.IsUseFonts2 ? this.m_oFontManager2 : this.m_oFontManager; + + if (_lastFont.Name != _lastFont.SetUpName || _lastFont.Size != _lastFont.SetUpSize || _style != _lastFont.SetUpStyle || !_font_manager.m_pFont) { _lastFont.SetUpName = _lastFont.Name; _lastFont.SetUpSize = _lastFont.Size; _lastFont.SetUpStyle = _style; var _fontinfo = AscFonts.g_fontApplication.GetFontInfo(_lastFont.SetUpName, _lastFont.SetUpStyle, this.LastFontOriginInfo); - var _info = GetLoadInfoForMeasurer(_fontinfo, _lastFont.SetUpStyle); + + // подбираем шрифт по стилю + var bNeedBold = false; + var bNeedItalic = false; + var index = -1; + var faceIndex = 0; + var bSrcItalic = false; + var bSrcBold = false; + + switch (_lastFont.SetUpStyle) + { + case AscFonts.FontStyle.FontStyleBoldItalic: + { + bSrcItalic = true; + bSrcBold = true; + + bNeedBold = true; + bNeedItalic = true; + if (-1 != _fontinfo.indexBI) + { + index = _fontinfo.indexBI; + faceIndex = _fontinfo.faceIndexBI; + bNeedBold = false; + bNeedItalic = false; + } + else if (-1 != _fontinfo.indexB) + { + index = _fontinfo.indexB; + faceIndex = _fontinfo.faceIndexB; + bNeedBold = false; + } + else if (-1 != _fontinfo.indexI) + { + index = _fontinfo.indexI; + faceIndex = _fontinfo.faceIndexI; + bNeedItalic = false; + } + else + { + index = _fontinfo.indexR; + faceIndex = _fontinfo.faceIndexR; + } + break; + } + case AscFonts.FontStyle.FontStyleBold: + { + bSrcBold = true; + + bNeedBold = true; + bNeedItalic = false; + if (-1 != _fontinfo.indexB) + { + index = _fontinfo.indexB; + faceIndex = _fontinfo.faceIndexB; + bNeedBold = false; + } + else if (-1 != _fontinfo.indexR) + { + index = _fontinfo.indexR; + faceIndex = _fontinfo.faceIndexR; + } + else if (-1 != _fontinfo.indexBI) + { + index = _fontinfo.indexBI; + faceIndex = _fontinfo.faceIndexBI; + bNeedBold = false; + } + else + { + index = _fontinfo.indexI; + faceIndex = _fontinfo.faceIndexI; + } + break; + } + case AscFonts.FontStyle.FontStyleItalic: + { + bSrcItalic = true; + + bNeedBold = false; + bNeedItalic = true; + if (-1 != _fontinfo.indexI) + { + index = _fontinfo.indexI; + faceIndex = _fontinfo.faceIndexI; + bNeedItalic = false; + } + else if (-1 != _fontinfo.indexR) + { + index = _fontinfo.indexR; + faceIndex = _fontinfo.faceIndexR; + } + else if (-1 != _fontinfo.indexBI) + { + index = _fontinfo.indexBI; + faceIndex = _fontinfo.faceIndexBI; + bNeedItalic = false; + } + else + { + index = _fontinfo.indexB; + faceIndex = _fontinfo.faceIndexB; + } + break; + } + case AscFonts.FontStyle.FontStyleRegular: + { + bNeedBold = false; + bNeedItalic = false; + if (-1 != _fontinfo.indexR) + { + index = _fontinfo.indexR; + faceIndex = _fontinfo.faceIndexR; + } + else if (-1 != _fontinfo.indexI) + { + index = _fontinfo.indexI; + faceIndex = _fontinfo.faceIndexI; + } + else if (-1 != _fontinfo.indexB) + { + index = _fontinfo.indexB; + faceIndex = _fontinfo.faceIndexB; + } + else + { + index = _fontinfo.indexBI; + faceIndex = _fontinfo.faceIndexBI; + } + } + } + + var _info = + { + Path : AscFonts.g_font_files[index].Id, + FaceIndex : faceIndex, + NeedBold : bNeedBold, + NeedItalic : bNeedItalic, + SrcBold : bSrcBold, + SrcItalic : bSrcItalic + }; var flag = 0; if (_info.NeedBold) flag |= 0x01; @@ -487,12 +753,12 @@ CNativeGraphics.prototype = if (_info.SrcBold) flag |= 0x04; if (_info.SrcItalic) flag |= 0x08; - this.Native["SetFontSlot"](_info.Path, _info.FaceIndex, _lastFont.SetUpSize, flag); + this.Native["SetFont"](_info.Path, _info.FaceIndex, _lastFont.SetUpSize, flag); } }, GetTextPr : function() { - this.Native["GetTextPr"](); + // this.Native["GetTextPr"](); return this.m_oTextPr; }, FillText : function(x, y, text) @@ -542,7 +808,7 @@ CNativeGraphics.prototype = }, charspace : function(space) { - this.Native["charspace"](space); + // this.Native["charspace"](space); }, // private methods private_FillGlyph : function(pGlyph, _bounds) @@ -559,7 +825,7 @@ CNativeGraphics.prototype = var nX = (_font_manager.m_oGlyphString.m_fX >> 0) + (pGlyph.fX + pGlyph.oBitmap.nX) >> 0; var nY = (_font_manager.m_oGlyphString.m_fY >> 0) + (pGlyph.fY - pGlyph.oBitmap.nY) >> 0; - pGlyph.oBitmap.oGlyphData.checkColor(this.m_oBrush.Color1.R,this.m_oBrush.Color1.G,this.m_oBrush.Color1.B,nW,nH); + pGlyph.oBitmap.oGlyphData.checkColor(this.m_oBrush.Color1.R, this.m_oBrush.Color1.G, this.m_oBrush.Color1.B, nW, nH); if (null == this.TextClipRect) pGlyph.oBitmap.draw(this.m_oContext, nX, nY, this.TextClipRect); @@ -603,7 +869,7 @@ CNativeGraphics.prototype = if (cW <= 0) cW = 1; - pGlyph.oBitmap.oGlyphData.checkColor(this.m_oBrush.Color1.R,this.m_oBrush.Color1.G,this.m_oBrush.Color1.B,nW,nH); + pGlyph.oBitmap.oGlyphData.checkColor(this.m_oBrush.Color1.R, this.m_oBrush.Color1.G, this.m_oBrush.Color1.B, nW, nH); pGlyph.oBitmap.drawCrop(this.m_oContext, nX, nY, cW, nH, cX); this.Native["private_FillGlyphC"](pGlyph, cropX, cropW); @@ -624,7 +890,7 @@ CNativeGraphics.prototype = var nX = (_font_manager.m_oGlyphString.m_fX + pGlyph.fX + pGlyph.oBitmap.nX) >> 0; var nY = (_font_manager.m_oGlyphString.m_fY + pGlyph.fY - pGlyph.oBitmap.nY) >> 0; - var imageData = this.m_oContext.getImageData(nX,nY,nW,nH); + var imageData = this.m_oContext.getImageData(nX, nY, nW, nH); var pPixels = imageData.data; var _r = this.m_oBrush.Color1.R; @@ -661,27 +927,27 @@ CNativeGraphics.prototype = indx += 4; } } - this.m_oContext.putImageData(imageData,nX,nY); + this.m_oContext.putImageData(imageData, nX, nY); this.Native["private_FillGlyph2"](pGlyph); }, SetIntegerGrid : function(param) { - this.m_bIntegerGrid = true; + this.m_bIntegerGrid = param; this.Native["SetIntegerGrid"](param); }, GetIntegerGrid : function() { - this.Native["GetIntegerGrid"](); + // this.Native["GetIntegerGrid"](); return this.m_bIntegerGrid; }, DrawStringASCII : function(name, size, bold, italic, text, x, y, bIsHeader) { var _textProp = { - RFonts : { Ascii : { Name : name, Index : -1 }}, + RFonts : { Ascii : { Name : name, Index : -1 } }, FontSize : (((size * 2 * 96 / this.m_dDpiY) + 0.5) >> 0) / 2, - Bold : false, - Italic : false + Bold : false, + Italic : false }; this.m_oTextPr = _textProp; @@ -698,11 +964,11 @@ CNativeGraphics.prototype = _ctx.fillStyle = "#E1E1E1"; _ctx.strokeStyle = GlobalSkin.RulerOutline; this.m_bBrushColorInit = false; - this.m_bPenColorInit = false; + this.m_bPenColorInit = false; var _xPxOffset = 10; var _yPxOffset = 5; - if (AscBrowser.isRetina) + if (AscCommon.AscBrowser.isRetina) { _xPxOffset = (_xPxOffset * AscCommon.AscBrowser.retinaPixelRatio) >> 0; _yPxOffset = (_yPxOffset * AscCommon.AscBrowser.retinaPixelRatio) >> 0; @@ -716,7 +982,7 @@ CNativeGraphics.prototype = if (!bIsHeader) __y -= __h; - if (!AscBrowser.isRetina) + if (!AscCommon.AscBrowser.isRetina) _ctx.rect(__x + 0.5, __y + 0.5, __w, __h); else _ctx.rect(__x, __y, __w, __h); @@ -729,20 +995,17 @@ CNativeGraphics.prototype = var _koef_px_to_mm = 25.4 / this.m_dDpiY; - if (bIsHeader) - this.t(text, x + _xPxOffset * _koef_px_to_mm, y + (__h - _yPxOffset) * _koef_px_to_mm); - else - this.t(text, x + _xPxOffset * _koef_px_to_mm, y - _yPxOffset * _koef_px_to_mm); + this.t(text, x + _xPxOffset * _koef_px_to_mm, y + ((bIsHeader ? __h : 0) - _yPxOffset) * _koef_px_to_mm); this.Native["DrawStringASCII"](name, size, bold, italic, text, x, y, bIsHeader); }, DrawStringASCII2 : function(name, size, bold, italic, text, x, y, bIsHeader) { var _textProp = { - RFonts : { Ascii : { Name : name, Index : -1 }}, + RFonts : { Ascii : { Name : name, Index : -1 } }, FontSize : (((size * 2 * 96 / this.m_dDpiY) + 0.5) >> 0) / 2, - Bold : false, - Italic : false + Bold : false, + Italic : false }; this.m_oTextPr = _textProp; @@ -759,11 +1022,11 @@ CNativeGraphics.prototype = _ctx.fillStyle = "#E1E1E1"; _ctx.strokeStyle = GlobalSkin.RulerOutline; this.m_bBrushColorInit = false; - this.m_bPenColorInit = false; + this.m_bPenColorInit = false; var _xPxOffset = 10; var _yPxOffset = 5; - if (AscBrowser.isRetina) + if (AscCommon.AscBrowser.isRetina) { _xPxOffset = (_xPxOffset * AscCommon.AscBrowser.retinaPixelRatio) >> 0; _yPxOffset = (_yPxOffset * AscCommon.AscBrowser.retinaPixelRatio) >> 0; @@ -778,7 +1041,7 @@ CNativeGraphics.prototype = if (!bIsHeader) __y -= __h; - if (!AscBrowser.isRetina) + if (!AscCommon.AscBrowser.isRetina) _ctx.rect(__x + 0.5, __y + 0.5, __w, __h); else _ctx.rect(__x, __y, __w, __h); @@ -793,10 +1056,7 @@ CNativeGraphics.prototype = var xPos = this.m_dWidthMM - x - (__w - _xPxOffset) * _koef_px_to_mm; - if (bIsHeader) - this.t(text, xPos, y + (__h - _yPxOffset) * _koef_px_to_mm); - else - this.t(text, xPos, y - _yPxOffset * _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); },