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

Unified Diff: chrome/renderer/print_web_view_helper_win.cc

Issue 10830364: Extracted FlattenTransparency method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/print_web_view_helper_win.cc
diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc
index 7b1916b44463d5cccd51d062f2fe2436f40b149a..7d4506d8a45f199b550529a09dc0170394c6031a 100644
--- a/chrome/renderer/print_web_view_helper_win.cc
+++ b/chrome/renderer/print_web_view_helper_win.cc
@@ -93,6 +93,54 @@ int CALLBACK EnhMetaFileProc(HDC dc,
return 1; // Continue enumeration
}
+Metafile* FlattenTransparency(Metafile* metafile, gfx::Size page_size) {
Lei Zhang 2012/08/17 02:30:00 gfx::Size -> const gfx::Size& ?
Vitaly Buka (NO REVIEWS) 2012/08/17 02:40:32 Done. But it's just 64bit. It's below my threshold
+ // Currently, we handle alpha blend transparency for a single page.
+ // Therefore, expecting a metafile with page count 1.
+ DCHECK_EQ(1U, metafile->GetPageCount());
+
+ // Close the device context to retrieve the compiled metafile.
+ if (!metafile->FinishDocument())
+ NOTREACHED();
+
+ // Page used alpha blend, but printer doesn't support it. Rewrite the
+ // metafile and flatten out the transparency.
+ base::win::ScopedGetDC screen_dc(NULL);
+ base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(screen_dc));
+ if (!bitmap_dc)
+ NOTREACHED() << "Bitmap DC creation failed";
+ SetGraphicsMode(bitmap_dc, GM_ADVANCED);
+ void* bits = NULL;
+ BITMAPINFO hdr;
+ gfx::CreateBitmapHeader(page_size.width(), page_size.height(),
+ &hdr.bmiHeader);
+ base::win::ScopedBitmap hbitmap(CreateDIBSection(
+ bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0));
+ if (!hbitmap)
+ NOTREACHED() << "Raster bitmap creation for printing failed";
+
+ base::win::ScopedSelectObject selectBitmap(bitmap_dc, hbitmap);
+ RECT rect = { 0, 0, page_size.width(), page_size.height() };
+ HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
+ FillRect(bitmap_dc, &rect, whiteBrush);
+
+ Metafile* metafile2(new printing::NativeMetafile);
+ metafile2->Init();
+ HDC hdc = metafile2->context();
+ DCHECK(hdc);
+ skia::InitializeDC(hdc);
+
+ RECT metafile_bounds = metafile->GetPageBounds(1).ToRECT();
+ // Process the old metafile, placing all non-AlphaBlend calls into the
+ // new metafile, and copying the results of all the AlphaBlend calls
+ // from the bitmap DC.
+ EnumEnhMetaFile(hdc,
+ metafile->emf(),
+ EnhMetaFileProc,
+ &bitmap_dc,
+ &metafile_bounds);
+ return metafile2;
+}
+
} // namespace
void PrintWebViewHelper::PrintPageInternal(
@@ -278,51 +326,7 @@ Metafile* PrintWebViewHelper::RenderPage(
DCHECK(!is_preview);
skia::PlatformDevice* platform_device = skia::GetPlatformDevice(device);
if (platform_device && platform_device->AlphaBlendUsed()) {
- // Currently, we handle alpha blend transparency for a single page.
- // Therefore, expecting a metafile with page count 1.
- DCHECK_EQ(1U, metafile->GetPageCount());
-
- // Close the device context to retrieve the compiled metafile.
- if (!metafile->FinishDocument())
- NOTREACHED();
-
- // Page used alpha blend, but printer doesn't support it. Rewrite the
- // metafile and flatten out the transparency.
- base::win::ScopedGetDC screen_dc(NULL);
- base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(screen_dc));
- if (!bitmap_dc)
- NOTREACHED() << "Bitmap DC creation failed";
- SetGraphicsMode(bitmap_dc, GM_ADVANCED);
- void* bits = NULL;
- BITMAPINFO hdr;
- gfx::CreateBitmapHeader(page_size.width(), page_size.height(),
- &hdr.bmiHeader);
- base::win::ScopedBitmap hbitmap(CreateDIBSection(
- bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0));
- if (!hbitmap)
- NOTREACHED() << "Raster bitmap creation for printing failed";
-
- base::win::ScopedSelectObject selectBitmap(bitmap_dc, hbitmap);
- RECT rect = { 0, 0, page_size.width(), page_size.height() };
- HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
- FillRect(bitmap_dc, &rect, whiteBrush);
-
- Metafile* metafile2(new printing::NativeMetafile);
- metafile2->Init();
- HDC hdc = metafile2->context();
- DCHECK(hdc);
- skia::InitializeDC(hdc);
-
- RECT metafile_bounds = metafile->GetPageBounds(1).ToRECT();
- // Process the old metafile, placing all non-AlphaBlend calls into the
- // new metafile, and copying the results of all the AlphaBlend calls
- // from the bitmap DC.
- EnumEnhMetaFile(hdc,
- metafile->emf(),
- EnhMetaFileProc,
- &bitmap_dc,
- &metafile_bounds);
- return metafile2;
+ return FlattenTransparency(metafile, page_size);
}
}
return metafile;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698