xref: /trunk/main/vcl/source/gdi/imagerepository.cxx (revision 7168672c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_vcl.hxx"
26 
27 #include <vcl/bitmapex.hxx>
28 #include <vcl/imagerepository.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/image.hxx>
31 #include <vcl/pngread.hxx>
32 #include <rtl/bootstrap.hxx>
33 #include <tools/stream.hxx>
34 #include <tools/urlobj.hxx>
35 
36 #include "impimagetree.hxx"
37 
38 namespace vcl
39 {
40     bool ImageRepository::loadImage( const ::rtl::OUString& _rName,
41                                      BitmapEx& _out_rImage,
42                                      bool _bSearchLanguageDependent )
43     {
44         ::rtl::OUString sCurrentSymbolsStyle =
45             Application::GetSettings().GetStyleSettings().GetCurrentSymbolsStyleName();
46 
47         ImplImageTreeSingletonRef aImplImageTree;
48 
49         return aImplImageTree->loadImage( _rName,
50                                           sCurrentSymbolsStyle,
51                                           _out_rImage,
52                                           _bSearchLanguageDependent );
53     }
54 
55 
56     static bool lcl_loadPNG( const rtl::OUString &rPath,
57                              const rtl::OUString &rImageFileName,
58                              Image &rImage )
59     {
60         INetURLObject aObj( rPath );
61         aObj.insertName( rImageFileName );
62         SvFileStream aStrm( aObj.PathToFileName(), STREAM_STD_READ );
63         if ( !aStrm.GetError() )
64         {
65             PNGReader aReader( aStrm );
66             BitmapEx aBmp = aReader.Read();
67             rImage = Image( aBmp );
68 
69             return true;
70         }
71 
72         return false;
73     }
74 
75     /* TODO support bSearchLanguageDependent */
76     bool ImageRepository::loadBrandingImage( const rtl::OUString &rName,
77                                              Image &rImage,
78                                              bool /* bSearchLanguageDependent */ )
79     {
80         rtl::OUString sImages;
81         rtl::OUStringBuffer aBuff( rName );
82         rtl::OUString aBasePath( RTL_CONSTASCII_USTRINGPARAM( "$BRAND_BASE_DIR/program" ) );
83         rtl::Bootstrap::expandMacros( aBasePath );
84 
85         bool bLoaded = false;
86         sal_Int32 nIndex = 0;
87 
88         if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
89         {
90             aBuff.appendAscii( RTL_CONSTASCII_STRINGPARAM( "_hc.png," ) );
91             aBuff.append( rName );
92         }
93 
94         aBuff.appendAscii( RTL_CONSTASCII_STRINGPARAM( ".png" ) );
95         sImages = aBuff.makeStringAndClear();
96 
97         do
98         {
99             bLoaded = lcl_loadPNG( aBasePath,
100                                    sImages.getToken( 0, ',', nIndex ),
101                                    rImage );
102         }
103         while ( !bLoaded && ( nIndex >= 0 ) );
104 
105         return bLoaded;
106     }
107 }
108