OLD | NEW |
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 "core/fxge/include/fx_ge.h" | 7 #include "core/fxge/include/fx_ge.h" |
8 | 8 |
9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_ | 9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_ |
10 | 10 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 SetClip_PathFill(&path, pMatrix, WINDING); | 269 SetClip_PathFill(&path, pMatrix, WINDING); |
270 FX_BOOL ret = | 270 FX_BOOL ret = |
271 StretchDIBits(pTransformed.get(), color, full_rect.left, full_rect.top, | 271 StretchDIBits(pTransformed.get(), color, full_rect.left, full_rect.top, |
272 full_rect.Width(), full_rect.Height(), nullptr, 0, | 272 full_rect.Width(), full_rect.Height(), nullptr, 0, |
273 alpha_flag, pIccTransform, blend_type); | 273 alpha_flag, pIccTransform, blend_type); |
274 RestoreState(false); | 274 RestoreState(false); |
275 handle = nullptr; | 275 handle = nullptr; |
276 return ret; | 276 return ret; |
277 } | 277 } |
278 | 278 |
279 CPSOutput::CPSOutput(HDC hDC) { | |
280 m_hDC = hDC; | |
281 m_pBuf = NULL; | |
282 } | |
283 CPSOutput::~CPSOutput() { | |
284 FX_Free(m_pBuf); | |
285 } | |
286 void CPSOutput::Init() { | |
287 m_pBuf = FX_Alloc(FX_CHAR, 1026); | |
288 } | |
289 void CPSOutput::OutputPS(const FX_CHAR* str, int len) { | |
290 if (len < 0) { | |
291 len = (int)FXSYS_strlen(str); | |
292 } | |
293 int sent_len = 0; | |
294 while (len > 0) { | |
295 int send_len = len > 1024 ? 1024 : len; | |
296 *(uint16_t*)m_pBuf = send_len; | |
297 FXSYS_memcpy(m_pBuf + 2, str + sent_len, send_len); | |
298 ExtEscape(m_hDC, PASSTHROUGH, send_len + 2, m_pBuf, 0, NULL); | |
299 sent_len += send_len; | |
300 len -= send_len; | |
301 } | |
302 } | |
303 CPSPrinterDriver::CPSPrinterDriver() { | |
304 m_pPSOutput = NULL; | |
305 m_bCmykOutput = FALSE; | |
306 } | |
307 CPSPrinterDriver::~CPSPrinterDriver() { | |
308 EndRendering(); | |
309 delete m_pPSOutput; | |
310 } | |
311 FX_BOOL CPSPrinterDriver::Init(HDC hDC, int pslevel, FX_BOOL bCmykOutput) { | |
312 m_hDC = hDC; | |
313 m_HorzSize = ::GetDeviceCaps(m_hDC, HORZSIZE); | |
314 m_VertSize = ::GetDeviceCaps(m_hDC, VERTSIZE); | |
315 m_Width = ::GetDeviceCaps(m_hDC, HORZRES); | |
316 m_Height = ::GetDeviceCaps(m_hDC, VERTRES); | |
317 m_nBitsPerPixel = ::GetDeviceCaps(m_hDC, BITSPIXEL); | |
318 m_pPSOutput = new CPSOutput(hDC); | |
319 ((CPSOutput*)m_pPSOutput)->Init(); | |
320 m_PSRenderer.Init(m_pPSOutput, pslevel, m_Width, m_Height, bCmykOutput); | |
321 m_bCmykOutput = bCmykOutput; | |
322 HRGN hRgn = ::CreateRectRgn(0, 0, 1, 1); | |
323 int ret = ::GetClipRgn(hDC, hRgn); | |
324 if (ret == 1) { | |
325 ret = ::GetRegionData(hRgn, 0, NULL); | |
326 if (ret) { | |
327 RGNDATA* pData = (RGNDATA*)FX_Alloc(uint8_t, ret); | |
328 ret = ::GetRegionData(hRgn, ret, pData); | |
329 if (ret) { | |
330 CFX_PathData path; | |
331 path.AllocPointCount(pData->rdh.nCount * 5); | |
332 for (uint32_t i = 0; i < pData->rdh.nCount; i++) { | |
333 RECT* pRect = (RECT*)(pData->Buffer + pData->rdh.nRgnSize * i); | |
334 path.AppendRect((FX_FLOAT)pRect->left, (FX_FLOAT)pRect->bottom, | |
335 (FX_FLOAT)pRect->right, (FX_FLOAT)pRect->top); | |
336 } | |
337 m_PSRenderer.SetClip_PathFill(&path, NULL, FXFILL_WINDING); | |
338 } | |
339 FX_Free(pData); | |
340 } | |
341 } | |
342 ::DeleteObject(hRgn); | |
343 return TRUE; | |
344 } | |
345 int CPSPrinterDriver::GetDeviceCaps(int caps_id) { | |
346 switch (caps_id) { | |
347 case FXDC_DEVICE_CLASS: | |
348 return FXDC_PRINTER; | |
349 case FXDC_PIXEL_WIDTH: | |
350 return m_Width; | |
351 case FXDC_PIXEL_HEIGHT: | |
352 return m_Height; | |
353 case FXDC_BITS_PIXEL: | |
354 return m_nBitsPerPixel; | |
355 case FXDC_RENDER_CAPS: | |
356 return m_bCmykOutput ? FXRC_BIT_MASK | FXRC_CMYK_OUTPUT : FXRC_BIT_MASK; | |
357 case FXDC_HORZ_SIZE: | |
358 return m_HorzSize; | |
359 case FXDC_VERT_SIZE: | |
360 return m_VertSize; | |
361 } | |
362 return 0; | |
363 } | |
364 FX_BOOL CPSPrinterDriver::StartRendering() { | |
365 return m_PSRenderer.StartRendering(); | |
366 } | |
367 void CPSPrinterDriver::EndRendering() { | |
368 m_PSRenderer.EndRendering(); | |
369 } | |
370 void CPSPrinterDriver::SaveState() { | |
371 m_PSRenderer.SaveState(); | |
372 } | |
373 | |
374 void CPSPrinterDriver::RestoreState(bool bKeepSaved) { | |
375 m_PSRenderer.RestoreState(bKeepSaved); | |
376 } | |
377 | |
378 FX_BOOL CPSPrinterDriver::SetClip_PathFill(const CFX_PathData* pPathData, | |
379 const CFX_Matrix* pObject2Device, | |
380 int fill_mode) { | |
381 m_PSRenderer.SetClip_PathFill(pPathData, pObject2Device, fill_mode); | |
382 return TRUE; | |
383 } | |
384 FX_BOOL CPSPrinterDriver::SetClip_PathStroke( | |
385 const CFX_PathData* pPathData, | |
386 const CFX_Matrix* pObject2Device, | |
387 const CFX_GraphStateData* pGraphState) { | |
388 m_PSRenderer.SetClip_PathStroke(pPathData, pObject2Device, pGraphState); | |
389 return TRUE; | |
390 } | |
391 FX_BOOL CPSPrinterDriver::DrawPath(const CFX_PathData* pPathData, | |
392 const CFX_Matrix* pObject2Device, | |
393 const CFX_GraphStateData* pGraphState, | |
394 FX_ARGB fill_color, | |
395 FX_ARGB stroke_color, | |
396 int fill_mode, | |
397 int alpha_flag, | |
398 void* pIccTransform, | |
399 int blend_type) { | |
400 if (blend_type != FXDIB_BLEND_NORMAL) { | |
401 return FALSE; | |
402 } | |
403 return m_PSRenderer.DrawPath(pPathData, pObject2Device, pGraphState, | |
404 fill_color, stroke_color, fill_mode & 3, | |
405 alpha_flag, pIccTransform); | |
406 } | |
407 FX_BOOL CPSPrinterDriver::GetClipBox(FX_RECT* pRect) { | |
408 *pRect = m_PSRenderer.GetClipBox(); | |
409 return TRUE; | |
410 } | |
411 FX_BOOL CPSPrinterDriver::SetDIBits(const CFX_DIBSource* pBitmap, | |
412 uint32_t color, | |
413 const FX_RECT* pSrcRect, | |
414 int left, | |
415 int top, | |
416 int blend_type, | |
417 int alpha_flag, | |
418 void* pIccTransform) { | |
419 if (blend_type != FXDIB_BLEND_NORMAL) { | |
420 return FALSE; | |
421 } | |
422 return m_PSRenderer.SetDIBits(pBitmap, color, left, top, alpha_flag, | |
423 pIccTransform); | |
424 } | |
425 FX_BOOL CPSPrinterDriver::StretchDIBits(const CFX_DIBSource* pBitmap, | |
426 uint32_t color, | |
427 int dest_left, | |
428 int dest_top, | |
429 int dest_width, | |
430 int dest_height, | |
431 const FX_RECT* pClipRect, | |
432 uint32_t flags, | |
433 int alpha_flag, | |
434 void* pIccTransform, | |
435 int blend_type) { | |
436 if (blend_type != FXDIB_BLEND_NORMAL) { | |
437 return FALSE; | |
438 } | |
439 return m_PSRenderer.StretchDIBits(pBitmap, color, dest_left, dest_top, | |
440 dest_width, dest_height, flags, alpha_flag, | |
441 pIccTransform); | |
442 } | |
443 FX_BOOL CPSPrinterDriver::StartDIBits(const CFX_DIBSource* pBitmap, | |
444 int bitmap_alpha, | |
445 uint32_t color, | |
446 const CFX_Matrix* pMatrix, | |
447 uint32_t render_flags, | |
448 void*& handle, | |
449 int alpha_flag, | |
450 void* pIccTransform, | |
451 int blend_type) { | |
452 if (blend_type != FXDIB_BLEND_NORMAL) { | |
453 return FALSE; | |
454 } | |
455 if (bitmap_alpha < 255) { | |
456 return FALSE; | |
457 } | |
458 handle = NULL; | |
459 return m_PSRenderer.DrawDIBits(pBitmap, color, pMatrix, render_flags, | |
460 alpha_flag, pIccTransform); | |
461 } | |
462 FX_BOOL CPSPrinterDriver::DrawDeviceText(int nChars, | |
463 const FXTEXT_CHARPOS* pCharPos, | |
464 CFX_Font* pFont, | |
465 CFX_FontCache* pCache, | |
466 const CFX_Matrix* pObject2Device, | |
467 FX_FLOAT font_size, | |
468 uint32_t color, | |
469 int alpha_flag, | |
470 void* pIccTransform) { | |
471 return m_PSRenderer.DrawText(nChars, pCharPos, pFont, pCache, pObject2Device, | |
472 font_size, color, alpha_flag, pIccTransform); | |
473 } | |
474 #endif | 279 #endif |
OLD | NEW |