Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / source / app / brand.cxx
blob3304c86d268508755fe4fe06a30d2940b21e2999
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_folders.h>
22 #include <rtl/ustring.hxx>
23 #include <rtl/bootstrap.hxx>
24 #include <osl/process.h>
25 #include <tools/urlobj.hxx>
26 #include <tools/stream.hxx>
27 #include <vcl/pngread.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/svgdata.hxx>
31 namespace {
32 static bool loadPng( const OUString & rPath, BitmapEx &rBitmap)
34 INetURLObject aObj( rPath );
35 SvFileStream aStrm( aObj.PathToFileName(), STREAM_STD_READ );
36 if ( !aStrm.GetError() ) {
37 vcl::PNGReader aReader( aStrm );
38 rBitmap = aReader.Read();
39 return !rBitmap.IsEmpty();
41 else
42 return false;
44 static bool tryLoadPng( const OUString& rBaseDir, const OUString& rName, BitmapEx& rBitmap )
46 return loadPng( rBaseDir + "/" LIBO_ETC_FOLDER + rName, rBitmap);
50 bool Application::LoadBrandBitmap (const char* pName, BitmapEx &rBitmap)
52 // TODO - if we want more flexibility we could add a branding path
53 // in an rc file perhaps fallback to "about.bmp"
54 OUString aBaseDir( "$BRAND_BASE_DIR");
55 rtl::Bootstrap::expandMacros( aBaseDir );
56 OUString aBaseName( "/" + OUString::createFromAscii( pName ) );
57 OUString aPng( ".png" );
59 rtl_Locale *pLoc = NULL;
60 osl_getProcessLocale (&pLoc);
61 LanguageTag aLanguageTag( *pLoc);
63 ::std::vector< OUString > aFallbacks( aLanguageTag.getFallbackStrings( true));
64 for (size_t i=0; i < aFallbacks.size(); ++i)
66 if (tryLoadPng( aBaseDir, aBaseName + "-" + aFallbacks[i] + aPng, rBitmap))
67 return true;
70 if (tryLoadPng( aBaseDir, aBaseName + aPng, rBitmap))
71 return true;
73 return false;
76 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */