xref: /aoo41x/main/vcl/source/gdi/imagerepository.cxx (revision 910823ae)
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 {
loadImage(const::rtl::OUString & _rName,BitmapEx & _out_rImage,bool _bSearchLanguageDependent)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 
lcl_loadPNG(const rtl::OUString & rPath,const rtl::OUString & rImageFileName,Image & rImage)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             if (!aBmp.IsEmpty())
68             {
69                 rImage = Image( aBmp );
70                 return true;
71             }
72         }
73 
74         return false;
75     }
76 
77     /* TODO support bSearchLanguageDependent */
loadBrandingImage(const rtl::OUString & rName,Image & rImage,bool)78     bool ImageRepository::loadBrandingImage( const rtl::OUString &rName,
79                                              Image &rImage,
80                                              bool /* bSearchLanguageDependent */ )
81     {
82         rtl::OUString sImages;
83         rtl::OUStringBuffer aBuff( rName );
84         rtl::OUString aBasePath( RTL_CONSTASCII_USTRINGPARAM( "$OOO_BASE_DIR/program" ) );
85         rtl::Bootstrap::expandMacros( aBasePath );
86 
87         bool bLoaded = false;
88         sal_Int32 nIndex = 0;
89 
90         if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
91         {
92             aBuff.appendAscii( RTL_CONSTASCII_STRINGPARAM( "_hc.png," ) );
93             aBuff.append( rName );
94         }
95 
96         aBuff.appendAscii( RTL_CONSTASCII_STRINGPARAM( ".png" ) );
97         sImages = aBuff.makeStringAndClear();
98 
99         do
100         {
101             bLoaded = lcl_loadPNG( aBasePath,
102                                    sImages.getToken( 0, ',', nIndex ),
103                                    rImage );
104         }
105         while ( !bLoaded && ( nIndex >= 0 ) );
106 
107         return bLoaded;
108     }
109 }
110