From 3e1393496709c3a9922f7fe3a644f3e8d359da35 Mon Sep 17 00:00:00 2001 From: Kulikova Svetlana Date: Mon, 2 Nov 2020 13:07:38 +0300 Subject: [PATCH] test text function --- DesktopEditor/doctrenderer/graphics.cpp | 9 +- DesktopEditor/doctrenderer/graphics.h | 2 +- .../doctrenderer/js/NativeGraphics.js | 168 +----------------- DesktopEditor/doctrenderer/js/test.js | 7 + 4 files changed, 20 insertions(+), 166 deletions(-) diff --git a/DesktopEditor/doctrenderer/graphics.cpp b/DesktopEditor/doctrenderer/graphics.cpp index 4fc776ce9e..96f24d40ba 100644 --- a/DesktopEditor/doctrenderer/graphics.cpp +++ b/DesktopEditor/doctrenderer/graphics.cpp @@ -1,6 +1,7 @@ #include "graphics.h" #include +#include #include "../common/Base64.h" @@ -186,9 +187,13 @@ 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); } -void CGraphics::SetFont(const std::wstring& path, int face, double size, int style) +void CGraphics::SetFont(const std::wstring& name, int face, double size, int style) { - m_pRenderer->put_FontPath((std::string::npos == path.find(L'/') ? m_sApplicationFontsDirectory : L"") + path); + double DpiX, DpiY; + m_pRenderer->get_DpiX(&DpiX); + m_pRenderer->get_DpiY(&DpiY); + m_pRenderer->GetFontManager()->LoadFontByName(name, size, style, DpiX, DpiY); + m_pRenderer->put_FontFaceIndex(face); m_pRenderer->put_FontSize (size); m_pRenderer->put_FontStyle (style); diff --git a/DesktopEditor/doctrenderer/graphics.h b/DesktopEditor/doctrenderer/graphics.h index 90abf363c7..a9feb24460 100644 --- a/DesktopEditor/doctrenderer/graphics.h +++ b/DesktopEditor/doctrenderer/graphics.h @@ -150,7 +150,7 @@ namespace NSGraphics // text void GetFont() {} void font() {} - void SetFont(const std::wstring& path, int face, double size, int style); + void SetFont(const std::wstring& name, int face, double size, int style); void SetTextPr() {} void GetTextPr() {} void FillText(double x, double y, int text); diff --git a/DesktopEditor/doctrenderer/js/NativeGraphics.js b/DesktopEditor/doctrenderer/js/NativeGraphics.js index 61f569f310..639bd36e18 100644 --- a/DesktopEditor/doctrenderer/js/NativeGraphics.js +++ b/DesktopEditor/doctrenderer/js/NativeGraphics.js @@ -210,171 +210,13 @@ CNativeGraphics.prototype = if (null == font) return; - 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 = AscFonts.FontStyle.FontStyleRegular; - if ( !bItalic && bBold ) - oFontStyle = AscFonts.FontStyle.FontStyleBold; - else if ( bItalic && !bBold ) - oFontStyle = AscFonts.FontStyle.FontStyleItalic; - else if ( bItalic && bBold ) - oFontStyle = AscFonts.FontStyle.FontStyleBoldItalic; - - var _fontinfo = AscFonts.g_fontApplication.GetFontInfo(font.FontFamily.Name, oFontStyle, this.LastFontOriginInfo); - - // подбираем шрифт по стилю - 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; - if (_info.NeedItalic) flag |= 0x02; - if (_info.SrcBold) flag |= 0x04; - if (_info.SrcItalic) flag |= 0x08; + if (font.Bold) flag |= 0x01; + if (font.Italic) flag |= 0x02; + if (font.Bold) flag |= 0x04; + if (font.Italic) flag |= 0x08; - this.Native["SetFont"](_info.Path, _info.FaceIndex, font.FontSize, flag); + this.Native["SetFont"](font.FontFamily.Name, font.FontFamily.Index, font.FontSize, flag); }, SetTextPr : function(textPr, theme) { diff --git a/DesktopEditor/doctrenderer/js/test.js b/DesktopEditor/doctrenderer/js/test.js index af67f261af..6318f12d94 100644 --- a/DesktopEditor/doctrenderer/js/test.js +++ b/DesktopEditor/doctrenderer/js/test.js @@ -3,6 +3,10 @@ var MyGraphics = new CNativeGraphics(); // Задаём размеры холста и всё будет полупрозрачное MyGraphics.init(null, 1000, 1000, 1000 * 25.4 / 96, 1000 * 25.4 / 96); + +MyGraphics.DrawHeaderEdit(10); +MyGraphics.DrawFooterEdit(250); + MyGraphics.put_GlobalAlpha(true, 0.5); // Рисуем желтый квадрат с красной пунктирной обводкой и толщиной 2 @@ -35,6 +39,9 @@ MyGraphics.ds(); MyGraphics.reset(); MyGraphics.put_GlobalAlpha(true, 1); +MyGraphics.SetFont({FontFamily : {Name : "Arial", Index : -1}, FontSize : 12, Italic : false, Bold : false}); +MyGraphics.FillText(10, 110, "A"); + // Рисуем кривую с одной контрольной точкой MyGraphics.b_color1(66, 255, 158, 255); MyGraphics._s();