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 <sal/config.h>
21
22#include <string_view>
23
24#include <config_folders.h>
25
26#include <rtl/ustring.hxx>
27#include <rtl/bootstrap.hxx>
28#include <osl/process.h>
29#include <tools/urlobj.hxx>
30#include <tools/stream.hxx>
33#include <vcl/bitmapex.hxx>
34#include <vcl/svapp.hxx>
35
36namespace {
37 bool loadPng( std::u16string_view rPath, BitmapEx &rBitmap)
38 {
39 INetURLObject aObj( rPath );
40 SvFileStream aStrm( aObj.PathToFileName(), StreamMode::STD_READ );
41 if ( !aStrm.GetError() ) {
42 vcl::PngImageReader aReader( aStrm );
43 rBitmap = aReader.read();
44 return !rBitmap.IsEmpty();
45 }
46 else
47 return false;
48 }
49 bool tryLoadPng( std::u16string_view rBaseDir, std::u16string_view rName, BitmapEx& rBitmap )
50 {
51 return loadPng( rtl::Concat2View(OUString::Concat(rBaseDir) + "/" LIBO_ETC_FOLDER + rName), rBitmap);
52 }
53}
54
55bool Application::LoadBrandBitmap (std::u16string_view pName, BitmapEx &rBitmap)
56{
57 // TODO - if we want more flexibility we could add a branding path
58 // in an rc file perhaps fallback to "about.bmp"
59 OUString aBaseDir( "$BRAND_BASE_DIR");
60 rtl::Bootstrap::expandMacros( aBaseDir );
61 OUString aBaseName(OUStringChar('/') + pName);
62 OUString aPng( ".png" );
63
64 rtl_Locale *pLoc = nullptr;
65 osl_getProcessLocale (&pLoc);
66 LanguageTag aLanguageTag( *pLoc);
67
68 ::std::vector< OUString > aFallbacks( aLanguageTag.getFallbackStrings( true));
69 for (const OUString & aFallback : aFallbacks)
70 {
71 if (tryLoadPng( aBaseDir, Concat2View(aBaseName + "-" + aFallback + aPng), rBitmap))
72 return true;
73 }
74
75 return tryLoadPng( aBaseDir, Concat2View(aBaseName + aPng), rBitmap);
76}
77
78/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char * pName
static bool LoadBrandBitmap(std::u16string_view pName, BitmapEx &rBitmap)
Load a localized branding PNG file as a bitmap.
Definition: brand.cxx:55
bool IsEmpty() const
Definition: BitmapEx.cxx:186
::std::vector< OUString > getFallbackStrings(bool bIncludeFullBcp47) const