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

Side by Side Diff: core/fxge/win32/fx_win32_print.cpp

Issue 2615703002: Revert postscript code removal. (Closed)
Patch Set: Move files, remove extra class, remove non const refs Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « core/fxge/win32/cpsoutput.cpp ('k') | core/fxge/win32/win32_int.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #include "core/fxcrt/fx_system.h" 13 #include "core/fxcrt/fx_system.h"
14 #include "core/fxge/cfx_renderdevice.h" 14 #include "core/fxge/cfx_renderdevice.h"
15 #include "core/fxge/cfx_windowsdevice.h" 15 #include "core/fxge/cfx_windowsdevice.h"
16 #include "core/fxge/dib/dib_int.h" 16 #include "core/fxge/dib/dib_int.h"
17 #include "core/fxge/fx_freetype.h" 17 #include "core/fxge/fx_freetype.h"
18 #include "core/fxge/ge/fx_text_int.h" 18 #include "core/fxge/ge/fx_text_int.h"
19 #include "core/fxge/win32/win32_int.h" 19 #include "core/fxge/win32/win32_int.h"
20 #include "third_party/base/ptr_util.h"
20 21
21 #if defined(PDFIUM_PRINT_TEXT_WITH_GDI) 22 #if defined(PDFIUM_PRINT_TEXT_WITH_GDI)
22 namespace { 23 namespace {
23 24
24 class ScopedState { 25 class ScopedState {
25 public: 26 public:
26 ScopedState(HDC hDC, HFONT hFont) : m_hDC(hDC) { 27 ScopedState(HDC hDC, HFONT hFont) : m_hDC(hDC) {
27 m_iState = SaveDC(m_hDC); 28 m_iState = SaveDC(m_hDC);
28 m_hFont = SelectObject(m_hDC, hFont); 29 m_hFont = SelectObject(m_hDC, hFont);
29 } 30 }
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 return false; 320 return false;
320 321
321 // Try to get the font and draw again. 322 // Try to get the font and draw again.
322 g_pdfium_typeface_accessible_func(&lf, wsText.c_str(), nChars); 323 g_pdfium_typeface_accessible_func(&lf, wsText.c_str(), nChars);
323 return !!ExtTextOutW(m_hDC, 0, 0, ETO_GLYPH_INDEX, nullptr, wsText.c_str(), 324 return !!ExtTextOutW(m_hDC, 0, 0, ETO_GLYPH_INDEX, nullptr, wsText.c_str(),
324 nChars, nChars > 1 ? &spacing[1] : nullptr); 325 nChars, nChars > 1 ? &spacing[1] : nullptr);
325 #else 326 #else
326 return false; 327 return false;
327 #endif 328 #endif
328 } 329 }
330
331 CPSPrinterDriver::CPSPrinterDriver(HDC hDC, int pslevel, bool bCmykOutput) {
332 m_hDC = hDC;
333 m_HorzSize = ::GetDeviceCaps(m_hDC, HORZSIZE);
334 m_VertSize = ::GetDeviceCaps(m_hDC, VERTSIZE);
335 m_Width = ::GetDeviceCaps(m_hDC, HORZRES);
336 m_Height = ::GetDeviceCaps(m_hDC, VERTRES);
337 m_nBitsPerPixel = ::GetDeviceCaps(m_hDC, BITSPIXEL);
338 m_pPSOutput = pdfium::MakeUnique<CPSOutput>(m_hDC);
339 m_PSRenderer.Init(m_pPSOutput.get(), pslevel, m_Width, m_Height, bCmykOutput);
340 m_bCmykOutput = bCmykOutput;
341 HRGN hRgn = ::CreateRectRgn(0, 0, 1, 1);
342 int ret = ::GetClipRgn(hDC, hRgn);
343 if (ret == 1) {
344 ret = ::GetRegionData(hRgn, 0, NULL);
345 if (ret) {
346 RGNDATA* pData = reinterpret_cast<RGNDATA*>(FX_Alloc(uint8_t, ret));
347 ret = ::GetRegionData(hRgn, ret, pData);
348 if (ret) {
349 CFX_PathData path;
350 path.AllocPointCount(pData->rdh.nCount * 5);
351 for (uint32_t i = 0; i < pData->rdh.nCount; i++) {
352 RECT* pRect =
353 reinterpret_cast<RECT*>(pData->Buffer + pData->rdh.nRgnSize * i);
354 path.AppendRect((FX_FLOAT)pRect->left, (FX_FLOAT)pRect->bottom,
355 (FX_FLOAT)pRect->right, (FX_FLOAT)pRect->top);
356 }
357 m_PSRenderer.SetClip_PathFill(&path, NULL, FXFILL_WINDING);
358 }
359 FX_Free(pData);
360 }
361 }
362 ::DeleteObject(hRgn);
363 }
364
365 CPSPrinterDriver::~CPSPrinterDriver() {
366 EndRendering();
367 }
368
369 int CPSPrinterDriver::GetDeviceCaps(int caps_id) const {
370 switch (caps_id) {
371 case FXDC_DEVICE_CLASS:
372 return FXDC_PRINTER;
373 case FXDC_PIXEL_WIDTH:
374 return m_Width;
375 case FXDC_PIXEL_HEIGHT:
376 return m_Height;
377 case FXDC_BITS_PIXEL:
378 return m_nBitsPerPixel;
379 case FXDC_RENDER_CAPS:
380 return m_bCmykOutput ? FXRC_BIT_MASK | FXRC_CMYK_OUTPUT : FXRC_BIT_MASK;
381 case FXDC_HORZ_SIZE:
382 return m_HorzSize;
383 case FXDC_VERT_SIZE:
384 return m_VertSize;
385 }
386 return 0;
387 }
388
389 bool CPSPrinterDriver::StartRendering() {
390 return m_PSRenderer.StartRendering();
391 }
392
393 void CPSPrinterDriver::EndRendering() {
394 m_PSRenderer.EndRendering();
395 }
396
397 void CPSPrinterDriver::SaveState() {
398 m_PSRenderer.SaveState();
399 }
400
401 void CPSPrinterDriver::RestoreState(bool bKeepSaved) {
402 m_PSRenderer.RestoreState(bKeepSaved);
403 }
404
405 bool CPSPrinterDriver::SetClip_PathFill(const CFX_PathData* pPathData,
406 const CFX_Matrix* pObject2Device,
407 int fill_mode) {
408 m_PSRenderer.SetClip_PathFill(pPathData, pObject2Device, fill_mode);
409 return true;
410 }
411
412 bool CPSPrinterDriver::SetClip_PathStroke(
413 const CFX_PathData* pPathData,
414 const CFX_Matrix* pObject2Device,
415 const CFX_GraphStateData* pGraphState) {
416 m_PSRenderer.SetClip_PathStroke(pPathData, pObject2Device, pGraphState);
417 return true;
418 }
419
420 bool CPSPrinterDriver::DrawPath(const CFX_PathData* pPathData,
421 const CFX_Matrix* pObject2Device,
422 const CFX_GraphStateData* pGraphState,
423 FX_ARGB fill_color,
424 FX_ARGB stroke_color,
425 int fill_mode,
426 int blend_type) {
427 if (blend_type != FXDIB_BLEND_NORMAL) {
428 return false;
429 }
430 return m_PSRenderer.DrawPath(pPathData, pObject2Device, pGraphState,
431 fill_color, stroke_color, fill_mode & 3);
432 }
433
434 bool CPSPrinterDriver::GetClipBox(FX_RECT* pRect) {
435 *pRect = m_PSRenderer.GetClipBox();
436 return true;
437 }
438
439 bool CPSPrinterDriver::SetDIBits(const CFX_DIBSource* pBitmap,
440 uint32_t color,
441 const FX_RECT* pSrcRect,
442 int left,
443 int top,
444 int blend_type) {
445 if (blend_type != FXDIB_BLEND_NORMAL)
446 return false;
447 return m_PSRenderer.SetDIBits(pBitmap, color, left, top);
448 }
449
450 bool CPSPrinterDriver::StretchDIBits(const CFX_DIBSource* pBitmap,
451 uint32_t color,
452 int dest_left,
453 int dest_top,
454 int dest_width,
455 int dest_height,
456 const FX_RECT* pClipRect,
457 uint32_t flags,
458 int blend_type) {
459 if (blend_type != FXDIB_BLEND_NORMAL)
460 return false;
461 return m_PSRenderer.StretchDIBits(pBitmap, color, dest_left, dest_top,
462 dest_width, dest_height, flags);
463 }
464
465 bool CPSPrinterDriver::StartDIBits(const CFX_DIBSource* pBitmap,
466 int bitmap_alpha,
467 uint32_t color,
468 const CFX_Matrix* pMatrix,
469 uint32_t render_flags,
470 void*& handle,
471 int blend_type) {
472 if (blend_type != FXDIB_BLEND_NORMAL)
473 return false;
474
475 if (bitmap_alpha < 255)
476 return false;
477
478 handle = nullptr;
479 return m_PSRenderer.DrawDIBits(pBitmap, color, pMatrix, render_flags);
480 }
481
482 bool CPSPrinterDriver::DrawDeviceText(int nChars,
483 const FXTEXT_CHARPOS* pCharPos,
484 CFX_Font* pFont,
485 const CFX_Matrix* pObject2Device,
486 FX_FLOAT font_size,
487 uint32_t color) {
488 return m_PSRenderer.DrawText(nChars, pCharPos, pFont, pObject2Device,
489 font_size, color);
490 }
491
492 void* CPSPrinterDriver::GetPlatformSurface() const {
493 return m_hDC;
494 }
OLDNEW
« no previous file with comments | « core/fxge/win32/cpsoutput.cpp ('k') | core/fxge/win32/win32_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698