OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "printing/emf_win.h" | 5 #include "printing/emf_win.h" |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 DCHECK(hdc); | 536 DCHECK(hdc); |
537 skia::InitializeDC(hdc); | 537 skia::InitializeDC(hdc); |
538 | 538 |
539 // Params are ignored. | 539 // Params are ignored. |
540 result->StartPage(page_bounds.size(), page_bounds, 1); | 540 result->StartPage(page_bounds.size(), page_bounds, 1); |
541 | 541 |
542 ::ModifyWorldTransform(hdc, NULL, MWT_IDENTITY); | 542 ::ModifyWorldTransform(hdc, NULL, MWT_IDENTITY); |
543 XFORM xform = { | 543 XFORM xform = { |
544 float(page_bounds.width()) / bitmap_rect.width(), 0, | 544 float(page_bounds.width()) / bitmap_rect.width(), 0, |
545 0, float(page_bounds.height()) / bitmap_rect.height(), | 545 0, float(page_bounds.height()) / bitmap_rect.height(), |
546 page_bounds.x(), | 546 static_cast<float>(page_bounds.x()), |
547 page_bounds.y(), | 547 static_cast<float>(page_bounds.y()), |
548 }; | 548 }; |
549 ::SetWorldTransform(hdc, &xform); | 549 ::SetWorldTransform(hdc, &xform); |
550 ::BitBlt(hdc, 0, 0, bitmap_rect.width(), bitmap_rect.height(), | 550 ::BitBlt(hdc, 0, 0, bitmap_rect.width(), bitmap_rect.height(), |
551 bitmap.context(), bitmap_rect.x(), bitmap_rect.y(), SRCCOPY); | 551 bitmap.context(), bitmap_rect.x(), bitmap_rect.y(), SRCCOPY); |
552 | 552 |
553 result->FinishPage(); | 553 result->FinishPage(); |
554 result->FinishDocument(); | 554 result->FinishDocument(); |
555 | 555 |
556 return result.Pass(); | 556 return result.Pass(); |
557 } | 557 } |
558 | 558 |
559 scoped_ptr<Emf> Emf::RasterizeAlphaBlend() const { | 559 scoped_ptr<Emf> Emf::RasterizeAlphaBlend() const { |
560 gfx::Rect page_bounds = GetPageBounds(1); | 560 gfx::Rect page_bounds = GetPageBounds(1); |
561 if (page_bounds.size().GetArea() <= 0) { | 561 if (page_bounds.size().GetArea() <= 0) { |
562 NOTREACHED() << "Metafile is empty"; | 562 NOTREACHED() << "Metafile is empty"; |
563 page_bounds = gfx::Rect(1, 1); | 563 page_bounds = gfx::Rect(1, 1); |
564 } | 564 } |
565 | 565 |
566 RasterBitmap bitmap(page_bounds.size()); | 566 RasterBitmap bitmap(page_bounds.size()); |
567 | 567 |
568 // Map metafile page_bounds.x(), page_bounds.y() to bitmap 0, 0. | 568 // Map metafile page_bounds.x(), page_bounds.y() to bitmap 0, 0. |
569 XFORM xform = { 1, 0, 0, 1, -page_bounds.x(), -page_bounds.y()}; | 569 XFORM xform = {1, |
| 570 0, |
| 571 0, |
| 572 1, |
| 573 static_cast<float>(-page_bounds.x()), |
| 574 static_cast<float>(-page_bounds.y())}; |
570 ::SetWorldTransform(bitmap.context(), &xform); | 575 ::SetWorldTransform(bitmap.context(), &xform); |
571 | 576 |
572 scoped_ptr<Emf> result(new Emf); | 577 scoped_ptr<Emf> result(new Emf); |
573 result->Init(); | 578 result->Init(); |
574 HDC hdc = result->context(); | 579 HDC hdc = result->context(); |
575 DCHECK(hdc); | 580 DCHECK(hdc); |
576 skia::InitializeDC(hdc); | 581 skia::InitializeDC(hdc); |
577 | 582 |
578 HDC bitmap_dc = bitmap.context(); | 583 HDC bitmap_dc = bitmap.context(); |
579 RECT rect = page_bounds.ToRECT(); | 584 RECT rect = page_bounds.ToRECT(); |
580 ::EnumEnhMetaFile(hdc, emf(), &RasterizeAlphaBlendProc, &bitmap_dc, &rect); | 585 ::EnumEnhMetaFile(hdc, emf(), &RasterizeAlphaBlendProc, &bitmap_dc, &rect); |
581 | 586 |
582 result->FinishDocument(); | 587 result->FinishDocument(); |
583 | 588 |
584 return result.Pass(); | 589 return result.Pass(); |
585 } | 590 } |
586 | 591 |
587 | 592 |
588 } // namespace printing | 593 } // namespace printing |
OLD | NEW |