Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1405)

Unified Diff: src/utils/mac/SkCreateCGImageRef.cpp

Issue 2343933002: Revert of SkFontData to use smart pointers. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/utils/SkWhitelistTypefaces.cpp ('k') | src/utils/mac/SkStream_mac.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/mac/SkCreateCGImageRef.cpp
diff --git a/src/utils/mac/SkCreateCGImageRef.cpp b/src/utils/mac/SkCreateCGImageRef.cpp
index d9cdb86e49f975193fd6cf0cda1ab86820ab9740..7f15ed7090b1a26cba83ab084926498a1193e83c 100644
--- a/src/utils/mac/SkCreateCGImageRef.cpp
+++ b/src/utils/mac/SkCreateCGImageRef.cpp
@@ -176,6 +176,71 @@
}
}
+///////////////////////////////////////////////////////////////////////////////
+
+#include "SkStream.h"
+
+class SkAutoPDFRelease {
+public:
+ SkAutoPDFRelease(CGPDFDocumentRef doc) : fDoc(doc) {}
+ ~SkAutoPDFRelease() {
+ if (fDoc) {
+ CGPDFDocumentRelease(fDoc);
+ }
+ }
+private:
+ CGPDFDocumentRef fDoc;
+};
+#define SkAutoPDFRelease(...) SK_REQUIRE_LOCAL_VAR(SkAutoPDFRelease)
+
+bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output) {
+ CGDataProviderRef data = SkCreateDataProviderFromStream(stream);
+ if (nullptr == data) {
+ return false;
+ }
+
+ CGPDFDocumentRef pdf = CGPDFDocumentCreateWithProvider(data);
+ CGDataProviderRelease(data);
+ if (nullptr == pdf) {
+ return false;
+ }
+ SkAutoPDFRelease releaseMe(pdf);
+
+ CGPDFPageRef page = CGPDFDocumentGetPage(pdf, 1);
+ if (nullptr == page) {
+ return false;
+ }
+
+ CGRect bounds = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
+
+ int w = (int)CGRectGetWidth(bounds);
+ int h = (int)CGRectGetHeight(bounds);
+
+ SkBitmap bitmap;
+ if (!bitmap.tryAllocN32Pixels(w, h)) {
+ return false;
+ }
+ bitmap.eraseColor(SK_ColorWHITE);
+
+ size_t bitsPerComponent;
+ CGBitmapInfo info;
+ getBitmapInfo(bitmap, &bitsPerComponent, &info, nullptr);
+
+ CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
+ CGContextRef ctx = CGBitmapContextCreate(bitmap.getPixels(), w, h,
+ bitsPerComponent, bitmap.rowBytes(),
+ cs, info);
+ CGColorSpaceRelease(cs);
+
+ if (ctx) {
+ CGContextDrawPDFPage(ctx, page);
+ CGContextRelease(ctx);
+ }
+
+ output->swap(bitmap);
+ return true;
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
SK_API bool SkCopyPixelsFromCGImage(const SkImageInfo& info, size_t rowBytes, void* pixels,
« no previous file with comments | « src/utils/SkWhitelistTypefaces.cpp ('k') | src/utils/mac/SkStream_mac.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698