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 #include "core/fxcodec/include/fx_codec.h" | 9 #include "core/fxcodec/include/fx_codec.h" |
10 #include "core/fxge/ge/fx_text_int.h" | 10 #include "core/fxge/ge/fx_text_int.h" |
11 | 11 |
12 struct PSGlyph { | 12 struct PSGlyph { |
13 CFX_Font* m_pFont; | 13 CFX_Font* m_pFont; |
14 uint32_t m_GlyphIndex; | 14 uint32_t m_GlyphIndex; |
15 FX_BOOL m_bGlyphAdjust; | 15 FX_BOOL m_bGlyphAdjust; |
16 FX_FLOAT m_AdjustMatrix[4]; | 16 FX_FLOAT m_AdjustMatrix[4]; |
17 }; | 17 }; |
18 class CPSFont { | 18 class CPSFont { |
19 public: | 19 public: |
20 PSGlyph m_Glyphs[256]; | 20 PSGlyph m_Glyphs[256]; |
21 int m_nGlyphs; | 21 int m_nGlyphs; |
22 }; | 22 }; |
23 CFX_PSRenderer::CFX_PSRenderer() { | 23 CFX_PSRenderer::CFX_PSRenderer() { |
24 m_pOutput = NULL; | 24 m_pOutput = nullptr; |
25 m_bColorSet = m_bGraphStateSet = FALSE; | 25 m_bColorSet = m_bGraphStateSet = FALSE; |
26 m_bInited = FALSE; | 26 m_bInited = FALSE; |
27 } | 27 } |
28 CFX_PSRenderer::~CFX_PSRenderer() { | 28 CFX_PSRenderer::~CFX_PSRenderer() { |
29 for (int i = 0; i < (int)m_PSFontList.GetSize(); i++) { | 29 for (int i = 0; i < (int)m_PSFontList.GetSize(); i++) { |
30 CPSFont* pFont = m_PSFontList[i]; | 30 CPSFont* pFont = m_PSFontList[i]; |
31 delete pFont; | 31 delete pFont; |
32 } | 32 } |
33 } | 33 } |
34 #define OUTPUT_PS(str) m_pOutput->OutputPS(str, sizeof str - 1) | 34 #define OUTPUT_PS(str) m_pOutput->OutputPS(str, sizeof str - 1) |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 const CFX_GraphStateData* pGraphState) { | 163 const CFX_GraphStateData* pGraphState) { |
164 StartRendering(); | 164 StartRendering(); |
165 SetGraphState(pGraphState); | 165 SetGraphState(pGraphState); |
166 if (pObject2Device) { | 166 if (pObject2Device) { |
167 CFX_ByteTextBuf buf; | 167 CFX_ByteTextBuf buf; |
168 buf << "mx Cm [" << pObject2Device->a << " " << pObject2Device->b << " " | 168 buf << "mx Cm [" << pObject2Device->a << " " << pObject2Device->b << " " |
169 << pObject2Device->c << " " << pObject2Device->d << " " | 169 << pObject2Device->c << " " << pObject2Device->d << " " |
170 << pObject2Device->e << " " << pObject2Device->f << "]cm "; | 170 << pObject2Device->e << " " << pObject2Device->f << "]cm "; |
171 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); | 171 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); |
172 } | 172 } |
173 OutputPath(pPathData, NULL); | 173 OutputPath(pPathData, nullptr); |
174 CFX_FloatRect rect = pPathData->GetBoundingBox(pGraphState->m_LineWidth, | 174 CFX_FloatRect rect = pPathData->GetBoundingBox(pGraphState->m_LineWidth, |
175 pGraphState->m_MiterLimit); | 175 pGraphState->m_MiterLimit); |
176 rect.Transform(pObject2Device); | 176 rect.Transform(pObject2Device); |
177 m_ClipBox.Intersect(rect.GetOutterRect()); | 177 m_ClipBox.Intersect(rect.GetOutterRect()); |
178 if (pObject2Device) { | 178 if (pObject2Device) { |
179 OUTPUT_PS("strokepath W n sm\n"); | 179 OUTPUT_PS("strokepath W n sm\n"); |
180 } else { | 180 } else { |
181 OUTPUT_PS("strokepath W n\n"); | 181 OUTPUT_PS("strokepath W n\n"); |
182 } | 182 } |
183 } | 183 } |
(...skipping 24 matching lines...) Expand all Loading... |
208 if (stroke_alpha) { | 208 if (stroke_alpha) { |
209 SetGraphState(pGraphState); | 209 SetGraphState(pGraphState); |
210 if (pObject2Device) { | 210 if (pObject2Device) { |
211 CFX_ByteTextBuf buf; | 211 CFX_ByteTextBuf buf; |
212 buf << "mx Cm [" << pObject2Device->a << " " << pObject2Device->b << " " | 212 buf << "mx Cm [" << pObject2Device->a << " " << pObject2Device->b << " " |
213 << pObject2Device->c << " " << pObject2Device->d << " " | 213 << pObject2Device->c << " " << pObject2Device->d << " " |
214 << pObject2Device->e << " " << pObject2Device->f << "]cm "; | 214 << pObject2Device->e << " " << pObject2Device->f << "]cm "; |
215 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); | 215 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); |
216 } | 216 } |
217 } | 217 } |
218 OutputPath(pPathData, stroke_alpha ? NULL : pObject2Device); | 218 OutputPath(pPathData, stroke_alpha ? nullptr : pObject2Device); |
219 if (fill_mode && fill_alpha) { | 219 if (fill_mode && fill_alpha) { |
220 SetColor(fill_color, alpha_flag, pIccTransform); | 220 SetColor(fill_color, alpha_flag, pIccTransform); |
221 if ((fill_mode & 3) == FXFILL_WINDING) { | 221 if ((fill_mode & 3) == FXFILL_WINDING) { |
222 if (stroke_alpha) { | 222 if (stroke_alpha) { |
223 OUTPUT_PS("q f Q "); | 223 OUTPUT_PS("q f Q "); |
224 } else { | 224 } else { |
225 OUTPUT_PS("f"); | 225 OUTPUT_PS("f"); |
226 } | 226 } |
227 } else if ((fill_mode & 3) == FXFILL_ALTERNATE) { | 227 } else if ((fill_mode & 3) == FXFILL_ALTERNATE) { |
228 if (stroke_alpha) { | 228 if (stroke_alpha) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 uint8_t*& output_buf, | 298 uint8_t*& output_buf, |
299 uint32_t& output_size, | 299 uint32_t& output_size, |
300 const FX_CHAR*& filter) { | 300 const FX_CHAR*& filter) { |
301 output_buf = src_buf; | 301 output_buf = src_buf; |
302 output_size = src_size; | 302 output_size = src_size; |
303 filter = ""; | 303 filter = ""; |
304 if (src_size < 1024) { | 304 if (src_size < 1024) { |
305 return; | 305 return; |
306 } | 306 } |
307 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); | 307 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); |
308 uint8_t* dest_buf = NULL; | 308 uint8_t* dest_buf = nullptr; |
309 uint32_t dest_size = src_size; | 309 uint32_t dest_size = src_size; |
310 if (PSLevel >= 3) { | 310 if (PSLevel >= 3) { |
311 if (pEncoders && | 311 if (pEncoders && |
312 pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, | 312 pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, |
313 dest_size)) { | 313 dest_size)) { |
314 filter = "/FlateDecode filter "; | 314 filter = "/FlateDecode filter "; |
315 } | 315 } |
316 } else { | 316 } else { |
317 if (pEncoders && | 317 if (pEncoders && |
318 pEncoders->GetBasicModule()->RunLengthEncode(src_buf, src_size, | 318 pEncoders->GetBasicModule()->RunLengthEncode(src_buf, src_size, |
319 dest_buf, dest_size)) { | 319 dest_buf, dest_size)) { |
320 filter = "/RunLengthDecode filter "; | 320 filter = "/RunLengthDecode filter "; |
321 } | 321 } |
322 } | 322 } |
323 if (dest_size < src_size) { | 323 if (dest_size < src_size) { |
324 output_buf = dest_buf; | 324 output_buf = dest_buf; |
325 output_size = dest_size; | 325 output_size = dest_size; |
326 } else { | 326 } else { |
327 filter = NULL; | 327 filter = nullptr; |
328 FX_Free(dest_buf); | 328 FX_Free(dest_buf); |
329 } | 329 } |
330 } | 330 } |
331 FX_BOOL CFX_PSRenderer::SetDIBits(const CFX_DIBSource* pSource, | 331 FX_BOOL CFX_PSRenderer::SetDIBits(const CFX_DIBSource* pSource, |
332 uint32_t color, | 332 uint32_t color, |
333 int left, | 333 int left, |
334 int top, | 334 int top, |
335 int alpha_flag, | 335 int alpha_flag, |
336 void* pIccTransform) { | 336 void* pIccTransform) { |
337 StartRendering(); | 337 StartRendering(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 } else { | 409 } else { |
410 buf << "false 1 colorimage\n"; | 410 buf << "false 1 colorimage\n"; |
411 } | 411 } |
412 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); | 412 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); |
413 WritePSBinary(output_buf, output_size); | 413 WritePSBinary(output_buf, output_size); |
414 FX_Free(output_buf); | 414 FX_Free(output_buf); |
415 } else { | 415 } else { |
416 CFX_DIBSource* pConverted = (CFX_DIBSource*)pSource; | 416 CFX_DIBSource* pConverted = (CFX_DIBSource*)pSource; |
417 if (pIccTransform) { | 417 if (pIccTransform) { |
418 FXDIB_Format format = m_bCmykOutput ? FXDIB_Cmyk : FXDIB_Rgb; | 418 FXDIB_Format format = m_bCmykOutput ? FXDIB_Cmyk : FXDIB_Rgb; |
419 pConverted = pSource->CloneConvert(format, NULL, pIccTransform); | 419 pConverted = pSource->CloneConvert(format, nullptr, pIccTransform); |
420 } else { | 420 } else { |
421 switch (pSource->GetFormat()) { | 421 switch (pSource->GetFormat()) { |
422 case FXDIB_1bppRgb: | 422 case FXDIB_1bppRgb: |
423 case FXDIB_Rgb32: | 423 case FXDIB_Rgb32: |
424 pConverted = pSource->CloneConvert(FXDIB_Rgb); | 424 pConverted = pSource->CloneConvert(FXDIB_Rgb); |
425 break; | 425 break; |
426 case FXDIB_8bppRgb: | 426 case FXDIB_8bppRgb: |
427 if (pSource->GetPalette()) { | 427 if (pSource->GetPalette()) { |
428 pConverted = pSource->CloneConvert(FXDIB_Rgb); | 428 pConverted = pSource->CloneConvert(FXDIB_Rgb); |
429 } | 429 } |
430 break; | 430 break; |
431 case FXDIB_1bppCmyk: | 431 case FXDIB_1bppCmyk: |
432 pConverted = pSource->CloneConvert(FXDIB_Cmyk); | 432 pConverted = pSource->CloneConvert(FXDIB_Cmyk); |
433 break; | 433 break; |
434 case FXDIB_8bppCmyk: | 434 case FXDIB_8bppCmyk: |
435 if (pSource->GetPalette()) { | 435 if (pSource->GetPalette()) { |
436 pConverted = pSource->CloneConvert(FXDIB_Cmyk); | 436 pConverted = pSource->CloneConvert(FXDIB_Cmyk); |
437 } | 437 } |
438 break; | 438 break; |
439 default: | 439 default: |
440 break; | 440 break; |
441 } | 441 } |
442 } | 442 } |
443 if (!pConverted) { | 443 if (!pConverted) { |
444 OUTPUT_PS("\nQ\n"); | 444 OUTPUT_PS("\nQ\n"); |
445 return FALSE; | 445 return FALSE; |
446 } | 446 } |
447 int Bpp = pConverted->GetBPP() / 8; | 447 int Bpp = pConverted->GetBPP() / 8; |
448 uint8_t* output_buf = NULL; | 448 uint8_t* output_buf = nullptr; |
449 FX_STRSIZE output_size = 0; | 449 FX_STRSIZE output_size = 0; |
450 const FX_CHAR* filter = NULL; | 450 const FX_CHAR* filter = nullptr; |
451 if (flags & FXRENDER_IMAGE_LOSSY) { | 451 if (flags & FXRENDER_IMAGE_LOSSY) { |
452 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); | 452 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); |
453 if (pEncoders && | 453 if (pEncoders && |
454 pEncoders->GetJpegModule()->Encode(pConverted, output_buf, | 454 pEncoders->GetJpegModule()->Encode(pConverted, output_buf, |
455 output_size)) { | 455 output_size)) { |
456 filter = "/DCTDecode filter "; | 456 filter = "/DCTDecode filter "; |
457 } | 457 } |
458 } | 458 } |
459 if (!filter) { | 459 if (!filter) { |
460 int src_pitch = width * Bpp; | 460 int src_pitch = width * Bpp; |
(...skipping 18 matching lines...) Expand all Loading... |
479 PSCompressData(m_PSLevel, output_buf, output_size, compressed_buf, | 479 PSCompressData(m_PSLevel, output_buf, output_size, compressed_buf, |
480 compressed_size, filter); | 480 compressed_size, filter); |
481 if (output_buf != compressed_buf) { | 481 if (output_buf != compressed_buf) { |
482 FX_Free(output_buf); | 482 FX_Free(output_buf); |
483 } | 483 } |
484 output_buf = compressed_buf; | 484 output_buf = compressed_buf; |
485 output_size = compressed_size; | 485 output_size = compressed_size; |
486 } | 486 } |
487 if (pConverted != pSource) { | 487 if (pConverted != pSource) { |
488 delete pConverted; | 488 delete pConverted; |
489 pConverted = NULL; | 489 pConverted = nullptr; |
490 } | 490 } |
491 buf << " 8["; | 491 buf << " 8["; |
492 buf << width << " 0 0 -" << height << " 0 " << height << "]"; | 492 buf << width << " 0 0 -" << height << " 0 " << height << "]"; |
493 buf << "currentfile/ASCII85Decode filter "; | 493 buf << "currentfile/ASCII85Decode filter "; |
494 if (filter) { | 494 if (filter) { |
495 buf << filter; | 495 buf << filter; |
496 } | 496 } |
497 buf << "false " << Bpp; | 497 buf << "false " << Bpp; |
498 buf << " colorimage\n"; | 498 buf << " colorimage\n"; |
499 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); | 499 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); |
500 WritePSBinary(output_buf, output_size); | 500 WritePSBinary(output_buf, output_size); |
501 FX_Free(output_buf); | 501 FX_Free(output_buf); |
502 } | 502 } |
503 OUTPUT_PS("\nQ\n"); | 503 OUTPUT_PS("\nQ\n"); |
504 return TRUE; | 504 return TRUE; |
505 } | 505 } |
506 void CFX_PSRenderer::SetColor(uint32_t color, | 506 void CFX_PSRenderer::SetColor(uint32_t color, |
507 int alpha_flag, | 507 int alpha_flag, |
508 void* pIccTransform) { | 508 void* pIccTransform) { |
509 if (!CFX_GEModule::Get()->GetCodecModule() || | 509 if (!CFX_GEModule::Get()->GetCodecModule() || |
510 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { | 510 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { |
511 pIccTransform = NULL; | 511 pIccTransform = nullptr; |
512 } | 512 } |
513 FX_BOOL bCMYK = FALSE; | 513 FX_BOOL bCMYK = FALSE; |
514 if (pIccTransform) { | 514 if (pIccTransform) { |
515 CCodec_IccModule* pIccModule = | 515 CCodec_IccModule* pIccModule = |
516 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); | 516 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
517 color = FXGETFLAG_COLORTYPE(alpha_flag) ? FXCMYK_TODIB(color) | 517 color = FXGETFLAG_COLORTYPE(alpha_flag) ? FXCMYK_TODIB(color) |
518 : FXARGB_TODIB(color); | 518 : FXARGB_TODIB(color); |
519 uint8_t* pColor = (uint8_t*)&color; | 519 uint8_t* pColor = (uint8_t*)&color; |
520 pIccModule->TranslateScanline(pIccTransform, pColor, pColor, 1); | 520 pIccModule->TranslateScanline(pIccTransform, pColor, pColor, 1); |
521 color = m_bCmykOutput ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); | 521 color = m_bCmykOutput ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 uint32_t dest_size; | 697 uint32_t dest_size; |
698 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); | 698 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); |
699 if (pEncoders && | 699 if (pEncoders && |
700 pEncoders->GetBasicModule()->A85Encode(data, len, dest_buf, dest_size)) { | 700 pEncoders->GetBasicModule()->A85Encode(data, len, dest_buf, dest_size)) { |
701 m_pOutput->OutputPS((const FX_CHAR*)dest_buf, dest_size); | 701 m_pOutput->OutputPS((const FX_CHAR*)dest_buf, dest_size); |
702 FX_Free(dest_buf); | 702 FX_Free(dest_buf); |
703 } else { | 703 } else { |
704 m_pOutput->OutputPS((const FX_CHAR*)data, len); | 704 m_pOutput->OutputPS((const FX_CHAR*)data, len); |
705 } | 705 } |
706 } | 706 } |
OLD | NEW |