LCOV - code coverage report
Current view: top level - libreoffice/vcl/source/app - brand.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 43 0.0 %
Date: 2012-12-27 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <rtl/ustring.hxx>
      21             : #include <rtl/bootstrap.hxx>
      22             : #include <osl/process.h>
      23             : #include <tools/urlobj.hxx>
      24             : #include <tools/stream.hxx>
      25             : #include <vcl/pngread.hxx>
      26             : #include <vcl/svapp.hxx>
      27             : #include <vcl/svgdata.hxx>
      28             : 
      29             : namespace {
      30           0 :     static bool loadPng(const char *pPath, const rtl::OUString &rName, BitmapEx &rBitmap)
      31             :     {
      32           0 :         rtl::OUString uri = rtl::OUString::createFromAscii( pPath ) + rName;
      33           0 :         rtl::Bootstrap::expandMacros( uri );
      34           0 :         INetURLObject aObj( uri );
      35           0 :         SvFileStream aStrm( aObj.PathToFileName(), STREAM_STD_READ );
      36           0 :         if ( !aStrm.GetError() ) {
      37           0 :             vcl::PNGReader aReader( aStrm );
      38           0 :             rBitmap = aReader.Read();
      39           0 :             return !rBitmap.IsEmpty();
      40             :         }
      41             :         else
      42           0 :             return false;
      43             :     }
      44           0 :     static bool loadSvg(rtl::OUString aUri, BitmapEx &rBitmap)
      45             :     {
      46           0 :         rtl::Bootstrap::expandMacros( aUri );
      47           0 :         INetURLObject aObj( aUri );
      48           0 :         SvgData aSvgData(aObj.PathToFileName());
      49           0 :         rBitmap = aSvgData.getReplacement();
      50           0 :         return !rBitmap.IsEmpty();
      51             :     }
      52             : }
      53             : 
      54           0 : bool Application::LoadBrandBitmap (const char* pName, BitmapEx &rBitmap)
      55             : {
      56             :     // TODO - if we want more flexibility we could add a branding path
      57             :     // in an rc file perhaps fallback to "about.bmp"
      58             :     rtl::OUString aBaseName = ( rtl::OUString("/") +
      59           0 :                                 rtl::OUString::createFromAscii( pName ) );
      60           0 :     rtl::OUString aPng( ".png" );
      61             : 
      62           0 :     rtl_Locale *pLoc = NULL;
      63           0 :     osl_getProcessLocale (&pLoc);
      64           0 :     LanguageTag aLanguageTag( *pLoc);
      65             : 
      66           0 :     rtl::OUString aName = aBaseName + aPng;
      67           0 :     rtl::OUString aLocaleName = ( aBaseName + rtl::OUString("-") +
      68           0 :                                   aLanguageTag.getBcp47() +
      69           0 :                                   aPng );
      70             : 
      71           0 :     return ( loadPng ("$BRAND_BASE_DIR/program/edition", aLocaleName, rBitmap) ||
      72           0 :              loadPng ("$BRAND_BASE_DIR/program", aLocaleName, rBitmap) ||
      73           0 :              loadPng ("$BRAND_BASE_DIR/program/edition", aName, rBitmap) ||
      74           0 :              loadPng ("$BRAND_BASE_DIR/program", aName, rBitmap) );
      75             : }
      76             : 
      77           0 : bool Application::LoadBrandSVG (const char *pName, BitmapEx &rBitmap)
      78             : {
      79             :     rtl::OUString aBaseName = ( rtl::OUString("/") +
      80           0 :                                 rtl::OUString::createFromAscii( pName ) );
      81           0 :     rtl::OUString aSvg( ".svg" );
      82             : 
      83           0 :     rtl_Locale *pLoc = NULL;
      84           0 :     osl_getProcessLocale (&pLoc);
      85           0 :     LanguageTag aLanguageTag( *pLoc);
      86             : 
      87           0 :     rtl::OUString aName = aBaseName + aSvg;
      88           0 :     rtl::OUString aLocaleName = ( aBaseName + rtl::OUString("-") +
      89           0 :                                   aLanguageTag.getBcp47() +
      90           0 :                                   aSvg );
      91           0 :     rtl::OUString uriOpt = rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program/edition" ) + aLocaleName;
      92           0 :     rtl::OUString uri = rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program" ) + aBaseName+aSvg;
      93           0 :     return ( loadSvg( uriOpt, rBitmap ) || loadSvg( uri, rBitmap ) );
      94             : }
      95             : 
      96             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10