From 173fef2766de70aaea3408e7dc23883acb1db209 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Fri, 13 Nov 2020 17:17:42 +0300 Subject: [PATCH] test functions text --- DesktopEditor/doctrenderer/doctrenderer.cpp | 5 ----- DesktopEditor/doctrenderer/embed/GraphicsEmbed.cpp | 5 ++--- DesktopEditor/doctrenderer/graphics.cpp | 14 +++++++++++++- DesktopEditor/doctrenderer/graphics.h | 6 +++--- DesktopEditor/doctrenderer/js/NativeGraphics.js | 14 +++++--------- DesktopEditor/doctrenderer/js/test.js | 7 +++++-- 6 files changed, 28 insertions(+), 23 deletions(-) diff --git a/DesktopEditor/doctrenderer/doctrenderer.cpp b/DesktopEditor/doctrenderer/doctrenderer.cpp index 8fdb695494..d1d4903cf4 100644 --- a/DesktopEditor/doctrenderer/doctrenderer.cpp +++ b/DesktopEditor/doctrenderer/doctrenderer.cpp @@ -642,11 +642,6 @@ namespace NSDoctRenderer bIsBreak = true; } -#ifdef _DEBUG - std::string sRes = res->toStringA(); - std::cout << sRes << std::endl; -#endif - LOGGER_SPEED_LAP("run") //--------------------------------------------------------------- diff --git a/DesktopEditor/doctrenderer/embed/GraphicsEmbed.cpp b/DesktopEditor/doctrenderer/embed/GraphicsEmbed.cpp index f8109e8036..ac21349c9a 100644 --- a/DesktopEditor/doctrenderer/embed/GraphicsEmbed.cpp +++ b/DesktopEditor/doctrenderer/embed/GraphicsEmbed.cpp @@ -160,8 +160,7 @@ JSSmart CGraphicsEmbed::drawImage (JSSmart img, JSSmart CGraphicsEmbed::GetFont() { - m_pInternal->GetFont(); - return NULL; + return CJSContext::createString(m_pInternal->GetFont()); } JSSmart CGraphicsEmbed::font(JSSmart font_id, JSSmart font_size) { @@ -195,7 +194,7 @@ JSSmart CGraphicsEmbed::FillText(JSSmart x, JSSmart CGraphicsEmbed::t(JSSmart x, JSSmart y, JSSmart _arr) { - m_pInternal->t(); + m_pInternal->t(x->toDouble(), y->toDouble(), _arr->toStringW()); return NULL; } JSSmart CGraphicsEmbed::FillText2(JSSmart x, JSSmart y, JSSmart text, JSSmart cropX, JSSmart cropW) diff --git a/DesktopEditor/doctrenderer/graphics.cpp b/DesktopEditor/doctrenderer/graphics.cpp index 96f24d40ba..008ab15738 100644 --- a/DesktopEditor/doctrenderer/graphics.cpp +++ b/DesktopEditor/doctrenderer/graphics.cpp @@ -15,7 +15,6 @@ void CGraphics::init(double width_px, double height_px, double width_mm, double { m_pApplicationFonts = NSFonts::NSApplication::Create(); m_pApplicationFonts->InitializeFromFolder(m_sApplicationFontsDirectory.empty() ? NSFile::GetProcessDirectory() : m_sApplicationFontsDirectory); - NSFonts::IFontManager* pManager = m_pApplicationFonts->GenerateFontManager(); m_pRenderer = NSGraphics::Create(); @@ -164,6 +163,10 @@ void CGraphics::df() { m_pRenderer->Fill(); } +void CGraphics::save() +{ + m_oFrame.SaveFile(m_sApplicationImagesDirectory + L"/img.png", _CXIMAGE_FORMAT_PNG); +} void CGraphics::restore() { m_pRenderer->BeginCommand(c_nResetClipType); @@ -187,6 +190,10 @@ void CGraphics::drawImage(const std::wstring& img, double x, double y, double w, std::wstring strImage = (0 == img.find(L"theme") ? m_sApplicationThemesDirectory : m_sApplicationImagesDirectory) + L'/' + img; m_pRenderer->DrawImageFromFile(strImage, x, y, w, h, alpha); } +std::wstring CGraphics::GetFont() +{ + return m_pRenderer->GetFontManager()->GetName(); +} void CGraphics::SetFont(const std::wstring& name, int face, double size, int style) { double DpiX, DpiY; @@ -202,6 +209,10 @@ void CGraphics::FillText(double x, double y, int text) { m_pRenderer->CommandDrawTextCHAR(text, x, y, 0, 0); } +void CGraphics::t(double x, double y, const std::wstring& text) +{ + m_pRenderer->CommandDrawText(text, x, y, 0, 0); +} void CGraphics::tg(int text, double x, double y) { m_pRenderer->put_FontStringGID(TRUE); @@ -827,6 +838,7 @@ std::string CGraphics::toDataURL(std::wstring type) DWORD dwReaded; oReader.ReadFile(pFileContent, dwFileSize, dwReaded); oReader.CloseFile(); + NSFile::CFileBinary::Remove(m_sApplicationImagesDirectory + L"/img." + type); int nEncodeLen = NSBase64::Base64EncodeGetRequiredLength(dwFileSize); BYTE* pImageData = new BYTE[nEncodeLen]; diff --git a/DesktopEditor/doctrenderer/graphics.h b/DesktopEditor/doctrenderer/graphics.h index a9feb24460..e6414055e3 100644 --- a/DesktopEditor/doctrenderer/graphics.h +++ b/DesktopEditor/doctrenderer/graphics.h @@ -138,7 +138,7 @@ namespace NSGraphics void ds(); void df(); // canvas state - void save() {} + void save(); void restore(); void clip(); void reset(); @@ -148,13 +148,13 @@ namespace NSGraphics // images void drawImage(const std::wstring& img, double x, double y, double w, double h, BYTE alpha); // text - void GetFont() {} + std::wstring GetFont(); void font() {} void SetFont(const std::wstring& name, int face, double size, int style); void SetTextPr() {} void GetTextPr() {} void FillText(double x, double y, int text); - void t() {} + void t(double x, double y, const std::wstring& text); void t2() {} void tg(int text, double x, double y); void charspace() {} diff --git a/DesktopEditor/doctrenderer/js/NativeGraphics.js b/DesktopEditor/doctrenderer/js/NativeGraphics.js index 639bd36e18..913d9fa652 100644 --- a/DesktopEditor/doctrenderer/js/NativeGraphics.js +++ b/DesktopEditor/doctrenderer/js/NativeGraphics.js @@ -181,11 +181,11 @@ CNativeGraphics.prototype = }, FreeFont : function() { - this.Native["FreeFont"](); + // this.Native["FreeFont"](); }, ClearLastFont : function() { - this.Native["ClearLastFont"](); + // this.Native["ClearLastFont"](); }, // images drawImage2 : function(img, x, y, w, h, alpha, srcRect) @@ -453,12 +453,7 @@ CNativeGraphics.prototype = }, t : function(text, x, y, isBounds) { - var _arr = []; - var _len = text.length; - for (var i = 0; i < _len; i++) - _arr.push(text.charCodeAt(i)); - - this.Native["t"](x, y, _arr); + this.Native["t"](x, y, text); }, FillText2 : function(x, y, text, cropX, cropW) { @@ -486,7 +481,8 @@ CNativeGraphics.prototype = }, tg : function(text, x, y) { - this.Native["tg"](text, x, y); + var _code = text.charCodeAt(0); + this.Native["tg"](_code, x, y); }, charspace : function(space) { diff --git a/DesktopEditor/doctrenderer/js/test.js b/DesktopEditor/doctrenderer/js/test.js index 6318f12d94..528a940f48 100644 --- a/DesktopEditor/doctrenderer/js/test.js +++ b/DesktopEditor/doctrenderer/js/test.js @@ -39,8 +39,10 @@ MyGraphics.ds(); MyGraphics.reset(); MyGraphics.put_GlobalAlpha(true, 1); -MyGraphics.SetFont({FontFamily : {Name : "Arial", Index : -1}, FontSize : 12, Italic : false, Bold : false}); +MyGraphics.SetFont({FontFamily : {Name : "Arial", Index : -1}, FontSize : 16, Italic : true, Bold : true}); MyGraphics.FillText(10, 110, "A"); +MyGraphics.tg("A", 10, 130); +MyGraphics.t("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 10, 230, false); // Рисуем кривую с одной контрольной точкой MyGraphics.b_color1(66, 255, 158, 255); @@ -72,4 +74,5 @@ MyGraphics.transform3({ sx : 1, shy : 0.5, shx : 0.1, sy : 1, tx : 0, ty : 0 }, MyGraphics.drawImage2("image1.png", 95, 76, 60, 48, 0, null); var imageBase64 = MyGraphics.toDataURL("png"); -imageBase64; +MyGraphics.save(); +MyGraphics.GetFont();