LibreOffice Module vcl (master)  1
brand.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <config_folders.h>
21 
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>
28 #include <vcl/pngread.hxx>
29 #include <vcl/svapp.hxx>
30 
31 namespace {
32  bool loadPng( const OUString & rPath, BitmapEx &rBitmap)
33  {
34  INetURLObject aObj( rPath );
35  SvFileStream aStrm( aObj.PathToFileName(), StreamMode::STD_READ );
36  if ( !aStrm.GetError() ) {
37  vcl::PNGReader aReader( aStrm );
38  rBitmap = aReader.Read();
39  return !rBitmap.IsEmpty();
40  }
41  else
42  return false;
43  }
44  bool tryLoadPng( const OUString& rBaseDir, const OUString& rName, BitmapEx& rBitmap )
45  {
46  return loadPng( rBaseDir + "/" LIBO_ETC_FOLDER + rName, rBitmap);
47  }
48 }
49 
50 bool Application::LoadBrandBitmap (const char* pName, BitmapEx &rBitmap)
51 {
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" );
58 
59  rtl_Locale *pLoc = nullptr;
60  osl_getProcessLocale (&pLoc);
61  LanguageTag aLanguageTag( *pLoc);
62 
63  ::std::vector< OUString > aFallbacks( aLanguageTag.getFallbackStrings( true));
64  for (const OUString & aFallback : aFallbacks)
65  {
66  if (tryLoadPng( aBaseDir, aBaseName + "-" + aFallback + aPng, rBitmap))
67  return true;
68  }
69 
70  return tryLoadPng( aBaseDir, aBaseName + aPng, rBitmap);
71 }
72 
73 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsEmpty() const
Definition: bitmapex.cxx:203
sal_uInt16 sal_Char * pName
::std::vector< OUString > getFallbackStrings(bool bIncludeFullBcp47) const
static bool LoadBrandBitmap(const char *pName, BitmapEx &rBitmap)
Load a localized branding PNG file as a bitmap.
Definition: brand.cxx:50