]> khamidou — GitHub mirrors - electron.git/commitdiff
Recognize the "@2x" suffix of icon's filename.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 23 Jun 2014 05:09:06 +0000 (13:09 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 23 Jun 2014 05:09:06 +0000 (13:09 +0800)
atom/common/native_mate_converters/image_converter.cc

index 5564f1e5dfc049b9c08ab127b5820752062faf8c..ca676c8d0091bdeb4580a65db7ebfe0a8b4d72ab 100644 (file)
@@ -8,12 +8,25 @@
 
 #include "atom/common/native_mate_converters/file_path_converter.h"
 #include "base/file_util.h"
+#include "base/strings/string_util.h"
 #include "ui/gfx/codec/jpeg_codec.h"
 #include "ui/gfx/codec/png_codec.h"
 #include "ui/gfx/image/image_skia.h"
 
 namespace mate {
 
+namespace {
+
+ui::ScaleFactor GetScaleFactorFromFileName(const base::FilePath& path) {
+  std::string filename(path.BaseName().RemoveExtension().AsUTF8Unsafe());
+  if (EndsWith(filename, "@2x", true))
+    return ui::SCALE_FACTOR_200P;
+  else
+    return ui::SCALE_FACTOR_100P;
+}
+
+}  // namespace
+
 bool Converter<gfx::ImageSkia>::FromV8(v8::Isolate* isolate,
                                        v8::Handle<v8::Value> val,
                                        gfx::ImageSkia* out) {
@@ -34,7 +47,8 @@ bool Converter<gfx::ImageSkia>::FromV8(v8::Isolate* isolate,
       decoded.reset(gfx::JPEGCodec::Decode(data, size));
 
     if (decoded) {
-      *out = gfx::ImageSkia::CreateFrom1xBitmap(*decoded.release());
+      *out = gfx::ImageSkia(gfx::ImageSkiaRep(*decoded.release(),
+                            GetScaleFactorFromFileName(path)));
       return true;
     }
   }