diff options
author | Khaled Hosny <khaled@libreoffice.org> | 2023-09-28 10:15:03 +0300 |
---|---|---|
committer | خالد حسني <khaled@libreoffice.org> | 2023-09-28 14:34:22 +0200 |
commit | c7f20a1dad66a7d3241c103546cd268152bc778f (patch) | |
tree | 220a0703ecc5d7622294b9d0fe8b2f3accfb139a /starmath | |
parent | d68cb3beddcf26e0b19101f18bd77a56c53d2009 (diff) |
tdf#142095: Render symbols in Math Symbols Catalogue using document settings
Use the document format to resolve the font and style of the symbol.
This makes the symbols use the current document font, as well as apply
settings like GreekCharStyle.
Change-Id: I668e582704b7e011e032f8b9e1dfb509e0d00d3e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157348
Tested-by: Jenkins
Reviewed-by: خالد حسني <khaled@libreoffice.org>
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/inc/dialog.hxx | 6 | ||||
-rw-r--r-- | starmath/source/dialog.cxx | 33 |
2 files changed, 31 insertions, 8 deletions
diff --git a/starmath/inc/dialog.hxx b/starmath/inc/dialog.hxx index bed55f9ddabf..66db01d295f4 100644 --- a/starmath/inc/dialog.hxx +++ b/starmath/inc/dialog.hxx @@ -247,6 +247,7 @@ public: class SmShowSymbolSet final : public weld::CustomWidgetController { + SmViewShell &m_rViewShell; Size m_aOldSize; SymbolPtrVec_t aSymbolSet; Link<SmShowSymbolSet&,void> aSelectHdlLink; @@ -268,7 +269,7 @@ class SmShowSymbolSet final : public weld::CustomWidgetController DECL_LINK(ScrollHdl, weld::ScrolledWindow&, void); public: - SmShowSymbolSet(std::unique_ptr<weld::ScrolledWindow> pScrolledWindow); + SmShowSymbolSet(std::unique_ptr<weld::ScrolledWindow> pScrolledWindow, SmViewShell &rViewShell); virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override { @@ -291,6 +292,7 @@ public: class SmShowSymbol final : public weld::CustomWidgetController { private: + SmViewShell &m_rViewShell; vcl::Font m_aFont; OUString m_aText; @@ -302,7 +304,7 @@ private: void setFontSize(vcl::Font &rFont) const; public: - SmShowSymbol(); + SmShowSymbol(SmViewShell &rViewShell); virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override { diff --git a/starmath/source/dialog.cxx b/starmath/source/dialog.cxx index c87b987660e4..585f5a0df475 100644 --- a/starmath/source/dialog.cxx +++ b/starmath/source/dialog.cxx @@ -85,6 +85,24 @@ public: const OUString& GetStyleName(sal_uInt16 nIdx) const; }; +vcl::Font lclGetSymbolFont(const SmViewShell& rViewShell, const SmSym &rSymbol) +{ + const SmDocShell* pDoc = rViewShell.GetDoc(); + if (pDoc) + { + // If we have a document, we want to render the symbol useing the font and style used in + // the documnet, so we do that by creating a node and preparing it, then get the resolved + // font and style from it. + SmToken token(TSPECIAL, '\0', "%" + rSymbol.GetUiName()); + SmSpecialNode aNode(token); + aNode.Prepare(pDoc->GetFormat(), *pDoc, 1); + aNode.PrepareAttributes(); + return aNode.GetFont(); + } + + return rSymbol.GetFace(); +} + } // end anonymous namespace SmFontStyles::SmFontStyles() @@ -985,8 +1003,9 @@ void SmAlignDialog::WriteTo(SmFormat &rFormat) const rFormat.RequestApplyChanges(); } -SmShowSymbolSet::SmShowSymbolSet(std::unique_ptr<weld::ScrolledWindow> pScrolledWindow) - : nLen(0) +SmShowSymbolSet::SmShowSymbolSet(std::unique_ptr<weld::ScrolledWindow> pScrolledWindow, SmViewShell &rViewShell) + : m_rViewShell(rViewShell) + , nLen(0) , nRows(0) , nColumns(0) , nXOffset(0) @@ -1034,7 +1053,7 @@ void SmShowSymbolSet::Paint(vcl::RenderContext& rRenderContext, const tools::Rec for (size_t i = v; i < nSymbols ; i++) { SmSym aSymbol(*aSymbolSet[i]); - vcl::Font aFont(aSymbol.GetFace()); + vcl::Font aFont(lclGetSymbolFont(m_rViewShell, aSymbol)); aFont.SetAlignment(ALIGN_TOP); // taking a FontSize which is a bit smaller (compared to nLen) in order to have a buffer @@ -1198,7 +1217,8 @@ IMPL_LINK_NOARG(SmShowSymbolSet, ScrollHdl, weld::ScrolledWindow&, void) Invalidate(); } -SmShowSymbol::SmShowSymbol() +SmShowSymbol::SmShowSymbol(SmViewShell& rViewShell) + : m_rViewShell(rViewShell) { } @@ -1239,7 +1259,7 @@ void SmShowSymbol::SetSymbol(const SmSym *pSymbol) { if (pSymbol) { - vcl::Font aFont(pSymbol->GetFace()); + vcl::Font aFont(lclGetSymbolFont(m_rViewShell, *pSymbol)); aFont.SetAlignment(ALIGN_BASELINE); SetFont(aFont); @@ -1348,8 +1368,9 @@ SmSymbolDialog::SmSymbolDialog(weld::Window *pParent, OutputDevice *pFntListDevi , rViewSh(rViewShell) , rSymbolMgr(rMgr) , pFontListDev(pFntListDevice) + , m_aSymbolDisplay(rViewShell) , m_xSymbolSets(m_xBuilder->weld_combo_box("symbolset")) - , m_xSymbolSetDisplay(new SmShowSymbolSet(m_xBuilder->weld_scrolled_window("scrolledwindow", true))) + , m_xSymbolSetDisplay(new SmShowSymbolSet(m_xBuilder->weld_scrolled_window("scrolledwindow", true), rViewShell)) , m_xSymbolSetDisplayArea(new weld::CustomWeld(*m_xBuilder, "symbolsetdisplay", *m_xSymbolSetDisplay)) , m_xSymbolName(m_xBuilder->weld_label("symbolname")) , m_xSymbolDisplay(new weld::CustomWeld(*m_xBuilder, "preview", m_aSymbolDisplay)) |