зеркало из https://github.com/electron/electron.git
mac: Don't rely on NSImage to read file
It doesn't work with asar.
This commit is contained in:
Родитель
903ff0b61a
Коммит
509ce0d5cb
|
@ -28,7 +28,6 @@ namespace api {
|
|||
|
||||
namespace {
|
||||
|
||||
#if !defined(OS_MACOSX)
|
||||
struct ScaleFactorPair {
|
||||
const char* name;
|
||||
float scale;
|
||||
|
@ -102,7 +101,13 @@ bool PopulateImageSkiaRepsFromPath(gfx::ImageSkia* image,
|
|||
pair.scale);
|
||||
return succeed;
|
||||
}
|
||||
#endif // !defined(OS_MACOSX)
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
bool IsTemplateImage(const base::FilePath& path) {
|
||||
return (MatchPattern(path.value(), "*Template.*") ||
|
||||
MatchPattern(path.value(), "*Template@*x.*"));
|
||||
}
|
||||
#endif
|
||||
|
||||
v8::Persistent<v8::ObjectTemplate> template_;
|
||||
|
||||
|
@ -175,15 +180,18 @@ mate::Handle<NativeImage> NativeImage::CreateFromJPEG(
|
|||
return Create(isolate, image);
|
||||
}
|
||||
|
||||
#if !defined(OS_MACOSX)
|
||||
// static
|
||||
mate::Handle<NativeImage> NativeImage::CreateFromPath(
|
||||
v8::Isolate* isolate, const base::FilePath& path) {
|
||||
gfx::ImageSkia image_skia;
|
||||
PopulateImageSkiaRepsFromPath(&image_skia, path);
|
||||
return Create(isolate, gfx::Image(image_skia));
|
||||
gfx::Image image(image_skia);
|
||||
#if defined(OS_MACOSX)
|
||||
if (IsTemplateImage(path))
|
||||
MakeTemplateImage(&image);
|
||||
#endif
|
||||
return Create(isolate, image);
|
||||
}
|
||||
#endif // !defined(OS_MACOSX)
|
||||
|
||||
} // namespace api
|
||||
|
||||
|
|
|
@ -46,6 +46,11 @@ class NativeImage : public mate::Wrappable {
|
|||
v8::Isolate* isolate) override;
|
||||
|
||||
private:
|
||||
#if defined(OS_MACOSX)
|
||||
// Mark the image as template image if possible.
|
||||
static void MakeTemplateImage(gfx::Image* image);
|
||||
#endif
|
||||
|
||||
v8::Handle<v8::Value> ToPNG(v8::Isolate* isolate);
|
||||
v8::Handle<v8::Value> ToJPEG(v8::Isolate* isolate, int quality);
|
||||
bool IsEmpty();
|
||||
|
|
|
@ -6,35 +6,13 @@
|
|||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/mac/foundation_util.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
#include "ui/gfx/image/image_skia.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
namespace {
|
||||
|
||||
bool IsTemplateImage(const base::FilePath& path) {
|
||||
return (MatchPattern(path.value(), "*Template.*") ||
|
||||
MatchPattern(path.value(), "*Template@*x.*"));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
mate::Handle<NativeImage> NativeImage::CreateFromPath(
|
||||
v8::Isolate* isolate, const base::FilePath& path) {
|
||||
base::scoped_nsobject<NSImage> image([[NSImage alloc]
|
||||
initByReferencingFile:base::mac::FilePathToNSString(path)]);
|
||||
if (IsTemplateImage(path))
|
||||
[image setTemplate:YES];
|
||||
return Create(isolate, gfx::Image(image.release()));
|
||||
void NativeImage::MakeTemplateImage(gfx::Image* image) {
|
||||
[image->AsNSImage() setTemplate:YES];
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
|
Загрузка…
Ссылка в новой задаче