Styling.
Rafael Dominguez
venccsralph at gmail.com
Mon Jul 30 10:07:23 PDT 2012
Well for the thumbnail i use this code, it dosent open the whole
document, just extracts the embedded thumbnail picture.
BitmapEx TemplateAbstractView::scaleImg (const BitmapEx &rImg, long
width, long height)
{
BitmapEx aImg = rImg;
int sWidth = std::min(aImg.GetSizePixel().getWidth(),width);
int sHeight = std::min(aImg.GetSizePixel().getHeight(),height);
aImg.Scale(Size(sWidth,sHeight),BMP_SCALE_INTERPOLATE);
return aImg;
}
BitmapEx TemplateAbstractView::fetchThumbnail (const rtl::OUString
&msURL, long width, long height)
{
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
// Load the thumbnail from a template document.
uno::Reference<io::XInputStream> xIStream;
uno::Reference< lang::XMultiServiceFactory > xServiceManager
(comphelper::getProcessServiceFactory());
if (xServiceManager.is())
{
try
{
uno::Reference<lang::XSingleServiceFactory> xStorageFactory(
xServiceManager->createInstance(
"com.sun.star.embed.StorageFactory"),
uno::UNO_QUERY);
if (xStorageFactory.is())
{
uno::Sequence<uno::Any> aArgs (2);
aArgs[0] <<= msURL;
aArgs[1] <<= embed::ElementModes::READ;
uno::Reference<embed::XStorage> xDocStorage (
xStorageFactory->createInstanceWithArguments(aArgs),
uno::UNO_QUERY);
try
{
if (xDocStorage.is())
{
uno::Reference<embed::XStorage> xStorage (
xDocStorage->openStorageElement(
"Thumbnails",
embed::ElementModes::READ));
if (xStorage.is())
{
uno::Reference<io::XStream> xThumbnailCopy (
xStorage->cloneStreamElement("thumbnail.png"));
if (xThumbnailCopy.is())
xIStream = xThumbnailCopy->getInputStream();
}
}
}
catch (const uno::Exception& rException)
{
OSL_TRACE (
"caught exception while trying to access
Thumbnail/thumbnail.png of %s: %s",
::rtl::OUStringToOString(msURL,
RTL_TEXTENCODING_UTF8).getStr(),
::rtl::OUStringToOString(rException.Message,
RTL_TEXTENCODING_UTF8).getStr());
}
try
{
// An (older) implementation had a bug - The storage
// name was "Thumbnail" instead of "Thumbnails". The
// old name is still used as fallback but this code can
// be removed soon.
if ( ! xIStream.is())
{
uno::Reference<embed::XStorage> xStorage (
xDocStorage->openStorageElement( "Thumbnail",
embed::ElementModes::READ));
if (xStorage.is())
{
uno::Reference<io::XStream> xThumbnailCopy (
xStorage->cloneStreamElement("thumbnail.png"));
if (xThumbnailCopy.is())
xIStream = xThumbnailCopy->getInputStream();
}
}
}
catch (const uno::Exception& rException)
{
OSL_TRACE (
"caught exception while trying to access
Thumbnails/thumbnail.png of %s: %s",
::rtl::OUStringToOString(msURL,
RTL_TEXTENCODING_UTF8).getStr(),
::rtl::OUStringToOString(rException.Message,
RTL_TEXTENCODING_UTF8).getStr());
}
}
}
catch (const uno::Exception& rException)
{
OSL_TRACE (
"caught exception while trying to access tuhmbnail of %s: %s",
::rtl::OUStringToOString(msURL,
RTL_TEXTENCODING_UTF8).getStr(),
::rtl::OUStringToOString(rException.Message,
RTL_TEXTENCODING_UTF8).getStr());
}
}
// Extract the image from the stream.
BitmapEx aThumbnail;
if (xIStream.is())
{
::std::auto_ptr<SvStream> pStream (
::utl::UcbStreamHelper::CreateStream (xIStream));
::vcl::PNGReader aReader (*pStream);
aThumbnail = aReader.Read ();
}
return TemplateAbstractView::scaleImg(aThumbnail,width,height);
}
More information about the LibreOffice
mailing list