diff options
author | Mihai Varga <mihai.varga@collabora.com> | 2015-09-10 11:31:48 +0300 |
---|---|---|
committer | Mihai Varga <mihai.mv13@gmail.com> | 2015-09-10 11:34:32 +0300 |
commit | 1806882317af1162edce5c2389c9c5eeb18455ac (patch) | |
tree | 4711e91a2ea9ab67ace8c6af311cf207479ec328 /desktop/source | |
parent | 39975c477a38be613e9e162acb6de241999f0ae1 (diff) |
LOK: getFonts method
Returns a json mapping of the available fonts to their possible font
sizes
Change-Id: I80c0bdd79e3ef2d814f64b8d38143d6c2b9ca720
Diffstat (limited to 'desktop/source')
-rw-r--r-- | desktop/source/lib/init.cxx | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 7a020d142ddc..be1a01867cf5 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -45,10 +45,15 @@ #include <com/sun/star/ucb/XContentProvider.hpp> #include <com/sun/star/ucb/XUniversalContentBroker.hpp> +#include <editeng/fontitem.hxx> +#include <editeng/flstitem.hxx> +#include <sfx2/objsh.hxx> +#include <svx/svxids.hrc> #include <vcl/svapp.hxx> #include <vcl/svpforlokit.hxx> #include <tools/resmgr.hxx> #include <tools/fract.hxx> +#include <svtools/ctrltool.hxx> #include <vcl/graphicfilter.hxx> #include <vcl/sysdata.hxx> #include <vcl/virdev.hxx> @@ -864,6 +869,43 @@ static void doc_resetSelection(LibreOfficeKitDocument* pThis) pDoc->resetSelection(); } +static char* getFonts (const char* pCommand) +{ + SfxObjectShell* pDocSh = SfxObjectShell::Current(); + const SvxFontListItem* pFonts = static_cast<const SvxFontListItem*>( + pDocSh->GetItem(SID_ATTR_CHAR_FONTLIST)); + const FontList* pList = pFonts ? pFonts->GetFontList() : 0; + + boost::property_tree::ptree aTree; + aTree.put("commandName", pCommand); + boost::property_tree::ptree aValues; + if ( pList ) + { + sal_uInt16 nFontCount = pList->GetFontNameCount(); + for (sal_uInt16 i = 0; i < nFontCount; ++i) + { + boost::property_tree::ptree aChildren; + const vcl::FontInfo& rInfo = pList->GetFontName(i); + const sal_IntPtr* pAry = pList->GetSizeAry(rInfo); + sal_uInt16 nSizeCount = 0; + while (pAry[nSizeCount]) + { + boost::property_tree::ptree aChild; + aChild.put("", (float)pAry[nSizeCount] / 10); + aChildren.push_back(std::make_pair("", aChild)); + nSizeCount++; + } + aValues.add_child(rInfo.GetName().toUtf8().getStr(), aChildren); + } + } + aTree.add_child("commandValues", aValues); + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1)); + strcpy(pJson, aStream.str().c_str()); + pJson[aStream.str().size()] = '\0'; + return pJson; +} static char* getStyles(LibreOfficeKitDocument* pThis, const char* pCommand) { @@ -901,7 +943,11 @@ static char* getStyles(LibreOfficeKitDocument* pThis, const char* pCommand) static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand) { - if (!strcmp(pCommand, ".uno:StyleApply")) + if (!strcmp(pCommand, ".uno:CharFontName")) + { + return getFonts(pCommand); + } + else if (!strcmp(pCommand, ".uno:StyleApply")) { return getStyles(pThis, pCommand); } |