desktop/source/lib/init.cxx | 55 ++++++++++++++++++++++++++++++ include/LibreOfficeKit/LibreOfficeKit.h | 6 +++ include/LibreOfficeKit/LibreOfficeKit.hxx | 12 ++++++ 3 files changed, 73 insertions(+)
New commits: commit e47cf7f2795045c70fdc38e6063d7662b8f0e575 Author: Caolán McNamara <[email protected]> Date: Mon Dec 7 13:45:26 2015 +0000 last arg of SetOutputSizePixelScaleOffsetAndBuffer no longer used Change-Id: I65e7e82e46c5751617b00a39df47d864b29b6ce1 Reviewed-on: https://gerrit.libreoffice.org/20441 Tested-by: Jenkins <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Caolán McNamara <[email protected]> (cherry picked from commit 2191a11022f657eae5fb21f87dd443ea9228920b) diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 9d49c3b..2a079dd 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1659,7 +1659,7 @@ unsigned char* doc_renderFont(LibreOfficeKitDocument* /*pThis*/, aDevice->SetBackground(Wallpaper(COL_TRANSPARENT)); aDevice->SetOutputSizePixelScaleOffsetAndBuffer( Size(nFontWidth, nFontHeight), Fraction(1.0), Point(), - aBuffer, nullptr); + aBuffer); aDevice->DrawText(Point(0,0), aFontName); return pBuffer; commit e10e613f2caa9802148ded6178c7e9093e3c7c41 Author: Stephan Bergmann <[email protected]> Date: Mon Nov 30 20:16:53 2015 +0100 loplugin:vclwidgets Change-Id: I520e27de82f11cc3c44c0e059ad60f3edaa4c370 (cherry picked from commit cd8a295444690b9c0dfb43ee4de01bf6ffeb1aa1) diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 4385cca..9d49c3b 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1639,12 +1639,14 @@ unsigned char* doc_renderFont(LibreOfficeKitDocument* /*pThis*/, if (!aSearchedFontName.equals(aFontName.toUtf8().getStr())) continue; - VirtualDevice aDevice(nullptr, Size(1, 1), DeviceFormat::DEFAULT); + auto aDevice( + VclPtr<VirtualDevice>::Create( + nullptr, Size(1, 1), DeviceFormat::DEFAULT)); ::Rectangle aRect; vcl::Font aFont(rInfo); aFont.SetSize(Size(0, 25)); - aDevice.SetFont(aFont); - aDevice.GetTextBoundRect(aRect, aFontName); + aDevice->SetFont(aFont); + aDevice->GetTextBoundRect(aRect, aFontName); int nFontWidth = aRect.BottomRight().X() + 1; *pFontWidth = nFontWidth; int nFontHeight = aRect.BottomRight().Y() + 1; @@ -1654,11 +1656,11 @@ unsigned char* doc_renderFont(LibreOfficeKitDocument* /*pThis*/, memset(pBuffer, 0, nFontWidth * nFontHeight * 4); boost::shared_array<sal_uInt8> aBuffer(pBuffer, NoDelete< sal_uInt8 >()); - aDevice.SetBackground(Wallpaper(COL_TRANSPARENT)); - aDevice.SetOutputSizePixelScaleOffsetAndBuffer( + aDevice->SetBackground(Wallpaper(COL_TRANSPARENT)); + aDevice->SetOutputSizePixelScaleOffsetAndBuffer( Size(nFontWidth, nFontHeight), Fraction(1.0), Point(), aBuffer, nullptr); - aDevice.DrawText(Point(0,0), aFontName); + aDevice->DrawText(Point(0,0), aFontName); return pBuffer; } commit 9eb0737da9900115c3026f332b63f5ba9042938b Author: Mihai Varga <[email protected]> Date: Fri Nov 27 16:19:09 2015 +0200 LOK: renderFont method Renders the given font in a virtual output device. For now it iterates over a list of fonts until it finds the one that matches the requested font. Change-Id: Ie4ecc3a1441519840d8f4f4a890e92670759b4fc (cherry picked from commit 24d981998b5859c7601d5c804e0ee70c5fec280f) diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 2148d33..4385cca 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -376,6 +376,10 @@ static void doc_destroyView(LibreOfficeKitDocument* pThis, int nId); static void doc_setView(LibreOfficeKitDocument* pThis, int nId); static int doc_getView(LibreOfficeKitDocument* pThis); static int doc_getViews(LibreOfficeKitDocument* pThis); +static unsigned char* doc_renderFont(LibreOfficeKitDocument* pThis, + const char *pFontName, + int* pFontWidth, + int* pFontHeight); LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) : mxComponent(xComponent) @@ -397,6 +401,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone m_pDocumentClass->setPart = doc_setPart; m_pDocumentClass->getPartName = doc_getPartName; m_pDocumentClass->setPartMode = doc_setPartMode; + m_pDocumentClass->renderFont = doc_renderFont; m_pDocumentClass->paintTile = doc_paintTile; m_pDocumentClass->getTileMode = doc_getTileMode; m_pDocumentClass->getDocumentSize = doc_getDocumentSize; @@ -1613,6 +1618,54 @@ static int doc_getViews(LibreOfficeKitDocument* /*pThis*/) return SfxLokHelper::getViews(); } +unsigned char* doc_renderFont(LibreOfficeKitDocument* /*pThis*/, + const char* pFontName, + int* pFontWidth, + int* pFontHeight) +{ + OString aSearchedFontName(pFontName); + SfxObjectShell* pDocSh = SfxObjectShell::Current(); + const SvxFontListItem* pFonts = static_cast<const SvxFontListItem*>( + pDocSh->GetItem(SID_ATTR_CHAR_FONTLIST)); + const FontList* pList = pFonts ? pFonts->GetFontList() : nullptr; + + if ( pList ) + { + sal_uInt16 nFontCount = pList->GetFontNameCount(); + for (sal_uInt16 i = 0; i < nFontCount; ++i) + { + const vcl::FontInfo& rInfo = pList->GetFontName(i); + OUString aFontName = rInfo.GetName(); + if (!aSearchedFontName.equals(aFontName.toUtf8().getStr())) + continue; + + VirtualDevice aDevice(nullptr, Size(1, 1), DeviceFormat::DEFAULT); + ::Rectangle aRect; + vcl::Font aFont(rInfo); + aFont.SetSize(Size(0, 25)); + aDevice.SetFont(aFont); + aDevice.GetTextBoundRect(aRect, aFontName); + int nFontWidth = aRect.BottomRight().X() + 1; + *pFontWidth = nFontWidth; + int nFontHeight = aRect.BottomRight().Y() + 1; + *pFontHeight = nFontHeight; + + unsigned char* pBuffer = static_cast<unsigned char*>(malloc(4 * nFontWidth * nFontHeight)); + memset(pBuffer, 0, nFontWidth * nFontHeight * 4); + boost::shared_array<sal_uInt8> aBuffer(pBuffer, NoDelete< sal_uInt8 >()); + + aDevice.SetBackground(Wallpaper(COL_TRANSPARENT)); + aDevice.SetOutputSizePixelScaleOffsetAndBuffer( + Size(nFontWidth, nFontHeight), Fraction(1.0), Point(), + aBuffer, nullptr); + aDevice.DrawText(Point(0,0), aFontName); + + return pBuffer; + } + } + return nullptr; +} + static char* lo_getError (LibreOfficeKit *pThis) { LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis); diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index 0ad5dc6..4feaaf7 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -216,6 +216,12 @@ struct _LibreOfficeKitDocumentClass int (*getView) (LibreOfficeKitDocument* pThis); /// @see lok::Document::getViews(). int (*getViews) (LibreOfficeKitDocument* pThis); + + /// @see lok::Document::renderFont(). + unsigned char* (*renderFont) (LibreOfficeKitDocument* pThis, + const char* pFontName, + int* pFontWidth, + int* pFontHeight); #endif // LOK_USE_UNSTABLE_API }; diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index 5331cd9..8128090 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -396,6 +396,18 @@ public: { return mpDoc->pClass->getViews(mpDoc); } + + /** + * Paints a font name to be displayed in the font list + * @param pFontName the font to be painted + */ + inline unsigned char* renderFont(const char *pFontName, + int *pFontWidth, + int *pFontHeight) + { + return mpDoc->pClass->renderFont(mpDoc, pFontName, pFontWidth, pFontHeight); + } + #endif // LOK_USE_UNSTABLE_API };
_______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
