Hi, I have submitted a patch for review:
https://gerrit.libreoffice.org/3953 To pull it, you can do: git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/53/3953/1 Allow 'textual links' on icon theme packages This would allow use of better icon names ( fdo#30425 ) and minimizes space size needed by reuses of same icons bitmaps with different filenames. Icon packages shoud have a file named "links.txt" on root folder in order to achieve that. It binds a name of a 'virtual' file to an existing one, to avoid duplicates. This file should contain one or more lines like this: path/for/fakefile_that_reuse_a_bitmap.png path/for/existing_one.png Implemented as discussed in: http://lists.freedesktop.org/archives/libreoffice/2013-April/049650.html Change-Id: Ia65a1ba18f93297fae47fa520104821f6f336694 Signed-off-by: Rodolfo Ribeiro Gomes <rodolf...@gmail.com> --- M vcl/inc/impimagetree.hxx M vcl/source/gdi/impimagetree.cxx 2 files changed, 92 insertions(+), 3 deletions(-) diff --git a/vcl/inc/impimagetree.hxx b/vcl/inc/impimagetree.hxx index d22e770..11c003e 100644 --- a/vcl/inc/impimagetree.hxx +++ b/vcl/inc/impimagetree.hxx @@ -72,12 +72,15 @@ OUString, bool, OUStringHash > CheckStyleCache; typedef boost::unordered_map< OUString, std::pair< bool, BitmapEx >, OUStringHash > IconCache; + typedef boost::unordered_map< + OUString, OUString, OUStringHash > IconLinkCache; OUString m_style; Path m_path; CheckStyleCache m_checkStyleCache; IconCache m_iconCache; bool m_cacheIcons; + IconLinkCache m_iconLinkCache; void setStyle(OUString const & style ); @@ -87,6 +90,10 @@ bool iconCacheLookup( OUString const & name, bool localized, BitmapEx & bitmap ); bool find(std::vector< OUString > const & paths, BitmapEx & bitmap ); + + void loadImageLinks(); + void parseLinkFile(boost::shared_ptr< SvStream > stream); + OUString const & getRealImageName(OUString const & name); }; typedef salhelper::SingletonRef< ImplImageTree > ImplImageTreeSingletonRef; diff --git a/vcl/source/gdi/impimagetree.cxx b/vcl/source/gdi/impimagetree.cxx index fe252fa..b8426e7 100644 --- a/vcl/source/gdi/impimagetree.cxx +++ b/vcl/source/gdi/impimagetree.cxx @@ -193,7 +193,7 @@ bitmap.SetEmpty(); } std::vector< OUString > paths; - paths.push_back(name); + paths.push_back(getRealImageName(name)); if (localized) { sal_Int32 pos = name.lastIndexOf('/'); if (pos != -1) { @@ -202,7 +202,7 @@ for (std::vector< OUString >::const_reverse_iterator it( aFallbacks.rbegin()); it != aFallbacks.rend(); ++it) { - paths.push_back(createPath(name, pos, *it)); + paths.push_back( getRealImageName( createPath(name, pos, *it) ) ); } } } @@ -225,6 +225,7 @@ // for safety; empty m_style means "not initialized" m_iconCache.clear(); m_checkStyleCache.clear(); + m_iconLinkCache.clear(); } void ImplImageTree::setStyle(OUString const & style) { @@ -233,6 +234,8 @@ m_style = style; resetPaths(); m_iconCache.clear(); + m_iconLinkCache.clear(); + loadImageLinks(); } } @@ -281,7 +284,8 @@ std::vector< OUString > const & paths, BitmapEx & bitmap) { if (!m_cacheIcons) { - for (std::vector< OUString >::const_reverse_iterator j(paths.rbegin()); + for (std::vector< OUString >::const_reverse_iterator j( + paths.rbegin()); j != paths.rend(); ++j) { osl::File file(m_path.first + "/" + *j); @@ -324,4 +328,82 @@ return false; } +void ImplImageTree::loadImageLinks() +{ + const OUString aLinkFilename("links.txt"); + + if (!m_cacheIcons) + { + osl::File file(m_path.first + "/" + aLinkFilename); + if (file.open(osl_File_OpenFlag_Read) == ::osl::FileBase::E_None) + { + parseLinkFile( wrapFile(file) ); + file.close(); + return; + } + } + + if ( !m_path.second.is() ) + { + css::uno::Sequence< css::uno::Any > args(1); + args[0] <<= m_path.first + ".zip"; + try + { + m_path.second.set( + comphelper::getProcessServiceFactory()->createInstanceWithArguments( + OUString( "com.sun.star.packages.zip.ZipFileAccess"), + args), + css::uno::UNO_QUERY_THROW); + } + catch (css::uno::RuntimeException &) + { + throw; + } + catch (const css::uno::Exception & e) + { + SAL_INFO("vcl", "ImplImageTree::find exception " + << e.Message << " for " << m_path.first); + return; + } + } + if ( m_path.second->hasByName(aLinkFilename) ) + { + css::uno::Reference< css::io::XInputStream > s; + bool ok = m_path.second->getByName(aLinkFilename) >>= s; + OSL_ASSERT(ok); (void) ok; + + parseLinkFile( wrapStream(s) ); + return; + } +} + +void ImplImageTree::parseLinkFile(boost::shared_ptr< SvStream > pStream) +{ + OString aLine; + OUString aLink, aOriginal; + while ( pStream->ReadLine( aLine ) ) + { + sal_Int32 nIndex = 0; + if ( aLine.isEmpty() ) + continue; + aLink = OStringToOUString( aLine.getToken(0, ' ', nIndex), RTL_TEXTENCODING_UTF8 ); + aOriginal = OStringToOUString( aLine.getToken(0, ' ', nIndex), RTL_TEXTENCODING_UTF8 ); + if ( aLink.isEmpty() || aOriginal.isEmpty() ) + { + SAL_INFO("vcl", "ImplImageTree::parseLinkFile: icon links.txt parse error. " + "Link is incomplete." ); + continue; + } + m_iconLinkCache[aLink] = aOriginal; + } +} + +OUString const & ImplImageTree::getRealImageName(OUString const & name) +{ + IconLinkCache::iterator it(m_iconLinkCache.find(name)); + if (it == m_iconLinkCache.end()) + return name; + return it->second; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- To view, visit https://gerrit.libreoffice.org/3953 To unsubscribe, visit https://gerrit.libreoffice.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia65a1ba18f93297fae47fa520104821f6f336694 Gerrit-PatchSet: 1 Gerrit-Project: core Gerrit-Branch: master Gerrit-Owner: Rodolfo Ribeiro Gomes <l...@rodolfo.eng.br> _______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice