Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License. You may obtain a copy of the License at
8 : : * http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * The Initial Developer of the Original Code is
16 : : * Novell, Inc.
17 : : * Portions created by the Initial Developer are Copyright (C) 2010 the
18 : : * Initial Developer. All Rights Reserved.
19 : : *
20 : : * Contributor(s): Michael Meeks <michael.meeks@novell.com>
21 : : *
22 : : * Alternatively, the contents of this file may be used under the terms of
23 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : : * instead of those above.
27 : : */
28 : :
29 : : #include <rtl/ustring.hxx>
30 : : #include <rtl/bootstrap.hxx>
31 : : #include <rtl/locale.hxx>
32 : : #include <osl/process.h>
33 : : #include <tools/urlobj.hxx>
34 : : #include <tools/stream.hxx>
35 : : #include <vcl/pngread.hxx>
36 : : #include <vcl/svgread.hxx>
37 : : #include <vcl/svapp.hxx>
38 : : #include <vcl/rendergraphicrasterizer.hxx>
39 : :
40 : : namespace {
41 : 24 : static bool loadPng(const char *pPath, const rtl::OUString &rName, BitmapEx &rBitmap)
42 : : {
43 : 24 : rtl::OUString uri = rtl::OUString::createFromAscii( pPath ) + rName;
44 : 24 : rtl::Bootstrap::expandMacros( uri );
45 [ + - ]: 24 : INetURLObject aObj( uri );
46 [ + - ][ + - ]: 24 : SvFileStream aStrm( aObj.PathToFileName(), STREAM_STD_READ );
[ + - ][ + - ]
47 [ + + ]: 24 : if ( !aStrm.GetError() ) {
48 [ + - ]: 6 : vcl::PNGReader aReader( aStrm );
49 [ + - ][ + - ]: 6 : rBitmap = aReader.Read();
[ + - ]
50 [ + - ][ + - ]: 6 : return !rBitmap.IsEmpty();
51 : : }
52 : : else
53 [ + - ][ + - ]: 24 : return false;
54 : : }
55 : :
56 : 0 : static vcl::RenderGraphicRasterizer loadSvg(const char *pPath, const rtl::OUString &rName)
57 : : {
58 : 0 : rtl::OUString uri = rtl::OUString::createFromAscii( pPath ) + rName;
59 : 0 : rtl::Bootstrap::expandMacros( uri );
60 [ # # ]: 0 : INetURLObject aObj( uri );
61 [ # # ][ # # ]: 0 : SvFileStream aStrm( aObj.PathToFileName(), STREAM_STD_READ );
[ # # ][ # # ]
62 : :
63 [ # # ]: 0 : vcl::RenderGraphic aRenderGraphic;
64 [ # # ]: 0 : vcl::RenderGraphic aRasterizer ( aRenderGraphic );
65 : :
66 [ # # ]: 0 : if ( !aStrm.GetError() ) {
67 [ # # ]: 0 : vcl::SVGReader aSVGReader( aStrm );
68 [ # # ][ # # ]: 0 : aRenderGraphic = aSVGReader.GetRenderGraphic();
[ # # ]
69 [ # # ]: 0 : vcl::RenderGraphic aNewRasterizer ( aRenderGraphic );
70 [ # # ][ # # ]: 0 : aRasterizer = aNewRasterizer;
[ # # ]
71 : : }
72 [ # # ][ # # ]: 0 : return aRasterizer;
[ # # ][ # # ]
[ # # ]
73 : : }
74 : : }
75 : :
76 : 6 : bool Application::LoadBrandBitmap (const char* pName, BitmapEx &rBitmap)
77 : : {
78 : : // TODO - if we want more flexibility we could add a branding path
79 : : // in an rc file perhaps fallback to "about.bmp"
80 : : rtl::OUString aBaseName = ( rtl::OUString("/") +
81 : 6 : rtl::OUString::createFromAscii( pName ) );
82 : 6 : rtl::OUString aPng( ".png" );
83 : :
84 : 6 : rtl_Locale *pLoc = NULL;
85 [ + - ]: 6 : osl_getProcessLocale (&pLoc);
86 : 6 : rtl::OLocale aLoc( pLoc );
87 : :
88 : 6 : rtl::OUString aName = aBaseName + aPng;
89 : : rtl::OUString aLocaleName = ( aBaseName + rtl::OUString("-") +
90 : : aLoc.getLanguage() +
91 : : rtl::OUString("_") +
92 : 6 : aLoc.getCountry() + aPng );
93 : :
94 [ + - ]: 6 : return ( loadPng ("$BRAND_BASE_DIR/program/edition", aLocaleName, rBitmap) ||
95 [ + - ]: 6 : loadPng ("$BRAND_BASE_DIR/program", aLocaleName, rBitmap) ||
96 [ + - ]: 6 : loadPng ("$BRAND_BASE_DIR/program/edition", aName, rBitmap) ||
97 [ + - ][ + - ]: 18 : loadPng ("$BRAND_BASE_DIR/program", aName, rBitmap) );
[ + - ][ + - ]
[ + - ]
98 : : }
99 : :
100 : 0 : vcl::RenderGraphicRasterizer Application::LoadBrandSVG (const char* pName)
101 : : {
102 : : rtl::OUString aBaseName = ( rtl::OUString("/") +
103 : 0 : rtl::OUString::createFromAscii( pName ) );
104 : 0 : rtl::OUString aSvg( ".svg" );
105 : :
106 : 0 : rtl_Locale *pLoc = NULL;
107 [ # # ]: 0 : osl_getProcessLocale (&pLoc);
108 : 0 : rtl::OLocale aLoc( pLoc );
109 : :
110 : 0 : rtl::OUString aName = aBaseName + aSvg;
111 : : rtl::OUString aLocaleName = ( aBaseName + rtl::OUString("-") +
112 : : aLoc.getLanguage() +
113 : : rtl::OUString("_") +
114 : 0 : aLoc.getCountry() + aSvg );
115 : :
116 [ # # ]: 0 : vcl::RenderGraphicRasterizer aRasterizer = loadSvg ("$BRAND_BASE_DIR/program/edition", aLocaleName);
117 [ # # ][ # # ]: 0 : if (!aRasterizer.GetRenderGraphic().IsEmpty())
118 : : return aRasterizer;
119 [ # # ][ # # ]: 0 : aRasterizer = loadSvg ("$BRAND_BASE_DIR/program", aLocaleName);
[ # # ]
120 [ # # ][ # # ]: 0 : if (!aRasterizer.GetRenderGraphic().IsEmpty())
121 : : return aRasterizer;
122 [ # # ][ # # ]: 0 : aRasterizer = loadSvg ("$BRAND_BASE_DIR/program/edition", aName);
[ # # ]
123 [ # # ][ # # ]: 0 : if (!aRasterizer.GetRenderGraphic().IsEmpty())
124 : : return aRasterizer;
125 : :
126 [ # # ][ # # ]: 0 : aRasterizer = loadSvg ("$BRAND_BASE_DIR/program", aName);
[ # # ]
127 : 0 : return aRasterizer;
128 : : }
129 : :
130 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|