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/include/fxge/fx_ge.h" | 7 #include "core/include/fxge/fx_ge.h" |
8 | 8 |
9 #include "core/fxge/ge/fx_text_int.h" | 9 #include "core/fxge/ge/fx_text_int.h" |
10 #include "core/include/fxcodec/fx_codec.h" | 10 #include "core/include/fxcodec/fx_codec.h" |
11 | 11 |
12 struct PSGlyph { | 12 struct PSGlyph { |
13 CFX_Font* m_pFont; | 13 CFX_Font* m_pFont; |
14 FX_DWORD 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 = NULL; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 m_ClipBox.Intersect(rect.GetOutterRect()); | 171 m_ClipBox.Intersect(rect.GetOutterRect()); |
172 if (pObject2Device) { | 172 if (pObject2Device) { |
173 OUTPUT_PS("strokepath W n sm\n"); | 173 OUTPUT_PS("strokepath W n sm\n"); |
174 } else { | 174 } else { |
175 OUTPUT_PS("strokepath W n\n"); | 175 OUTPUT_PS("strokepath W n\n"); |
176 } | 176 } |
177 } | 177 } |
178 FX_BOOL CFX_PSRenderer::DrawPath(const CFX_PathData* pPathData, | 178 FX_BOOL CFX_PSRenderer::DrawPath(const CFX_PathData* pPathData, |
179 const CFX_Matrix* pObject2Device, | 179 const CFX_Matrix* pObject2Device, |
180 const CFX_GraphStateData* pGraphState, | 180 const CFX_GraphStateData* pGraphState, |
181 FX_DWORD fill_color, | 181 uint32_t fill_color, |
182 FX_DWORD stroke_color, | 182 uint32_t stroke_color, |
183 int fill_mode, | 183 int fill_mode, |
184 int alpha_flag, | 184 int alpha_flag, |
185 void* pIccTransform) { | 185 void* pIccTransform) { |
186 StartRendering(); | 186 StartRendering(); |
187 int fill_alpha = FXGETFLAG_COLORTYPE(alpha_flag) | 187 int fill_alpha = FXGETFLAG_COLORTYPE(alpha_flag) |
188 ? FXGETFLAG_ALPHA_FILL(alpha_flag) | 188 ? FXGETFLAG_ALPHA_FILL(alpha_flag) |
189 : FXARGB_A(fill_color); | 189 : FXARGB_A(fill_color); |
190 int stroke_alpha = FXGETFLAG_COLORTYPE(alpha_flag) | 190 int stroke_alpha = FXGETFLAG_COLORTYPE(alpha_flag) |
191 ? FXGETFLAG_ALPHA_STROKE(alpha_flag) | 191 ? FXGETFLAG_ALPHA_STROKE(alpha_flag) |
192 : FXARGB_A(stroke_color); | 192 : FXARGB_A(stroke_color); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 m_CurGraphState.Copy(*pGraphState); | 268 m_CurGraphState.Copy(*pGraphState); |
269 m_bGraphStateSet = TRUE; | 269 m_bGraphStateSet = TRUE; |
270 if (buf.GetSize()) { | 270 if (buf.GetSize()) { |
271 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); | 271 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); |
272 } | 272 } |
273 } | 273 } |
274 static void FaxCompressData(uint8_t* src_buf, | 274 static void FaxCompressData(uint8_t* src_buf, |
275 int width, | 275 int width, |
276 int height, | 276 int height, |
277 uint8_t*& dest_buf, | 277 uint8_t*& dest_buf, |
278 FX_DWORD& dest_size) { | 278 uint32_t& dest_size) { |
279 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); | 279 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); |
280 if (width * height > 128 && pEncoders && | 280 if (width * height > 128 && pEncoders && |
281 pEncoders->GetFaxModule()->Encode(src_buf, width, height, (width + 7) / 8, | 281 pEncoders->GetFaxModule()->Encode(src_buf, width, height, (width + 7) / 8, |
282 dest_buf, dest_size)) { | 282 dest_buf, dest_size)) { |
283 FX_Free(src_buf); | 283 FX_Free(src_buf); |
284 } else { | 284 } else { |
285 dest_buf = src_buf; | 285 dest_buf = src_buf; |
286 dest_size = (width + 7) / 8 * height; | 286 dest_size = (width + 7) / 8 * height; |
287 } | 287 } |
288 } | 288 } |
289 static void PSCompressData(int PSLevel, | 289 static void PSCompressData(int PSLevel, |
290 uint8_t* src_buf, | 290 uint8_t* src_buf, |
291 FX_DWORD src_size, | 291 uint32_t src_size, |
292 uint8_t*& output_buf, | 292 uint8_t*& output_buf, |
293 FX_DWORD& output_size, | 293 uint32_t& output_size, |
294 const FX_CHAR*& filter) { | 294 const FX_CHAR*& filter) { |
295 output_buf = src_buf; | 295 output_buf = src_buf; |
296 output_size = src_size; | 296 output_size = src_size; |
297 filter = ""; | 297 filter = ""; |
298 if (src_size < 1024) { | 298 if (src_size < 1024) { |
299 return; | 299 return; |
300 } | 300 } |
301 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); | 301 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); |
302 uint8_t* dest_buf = NULL; | 302 uint8_t* dest_buf = NULL; |
303 FX_DWORD dest_size = src_size; | 303 uint32_t dest_size = src_size; |
304 if (PSLevel >= 3) { | 304 if (PSLevel >= 3) { |
305 if (pEncoders && | 305 if (pEncoders && |
306 pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, | 306 pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, |
307 dest_size)) { | 307 dest_size)) { |
308 filter = "/FlateDecode filter "; | 308 filter = "/FlateDecode filter "; |
309 } | 309 } |
310 } else { | 310 } else { |
311 if (pEncoders && | 311 if (pEncoders && |
312 pEncoders->GetBasicModule()->RunLengthEncode(src_buf, src_size, | 312 pEncoders->GetBasicModule()->RunLengthEncode(src_buf, src_size, |
313 dest_buf, dest_size)) { | 313 dest_buf, dest_size)) { |
314 filter = "/RunLengthDecode filter "; | 314 filter = "/RunLengthDecode filter "; |
315 } | 315 } |
316 } | 316 } |
317 if (dest_size < src_size) { | 317 if (dest_size < src_size) { |
318 output_buf = dest_buf; | 318 output_buf = dest_buf; |
319 output_size = dest_size; | 319 output_size = dest_size; |
320 } else { | 320 } else { |
321 filter = NULL; | 321 filter = NULL; |
322 FX_Free(dest_buf); | 322 FX_Free(dest_buf); |
323 } | 323 } |
324 } | 324 } |
325 FX_BOOL CFX_PSRenderer::SetDIBits(const CFX_DIBSource* pSource, | 325 FX_BOOL CFX_PSRenderer::SetDIBits(const CFX_DIBSource* pSource, |
326 FX_DWORD color, | 326 uint32_t color, |
327 int left, | 327 int left, |
328 int top, | 328 int top, |
329 int alpha_flag, | 329 int alpha_flag, |
330 void* pIccTransform) { | 330 void* pIccTransform) { |
331 StartRendering(); | 331 StartRendering(); |
332 CFX_Matrix matrix((FX_FLOAT)(pSource->GetWidth()), 0.0f, 0.0f, | 332 CFX_Matrix matrix((FX_FLOAT)(pSource->GetWidth()), 0.0f, 0.0f, |
333 -(FX_FLOAT)(pSource->GetHeight()), (FX_FLOAT)(left), | 333 -(FX_FLOAT)(pSource->GetHeight()), (FX_FLOAT)(left), |
334 (FX_FLOAT)(top + pSource->GetHeight())); | 334 (FX_FLOAT)(top + pSource->GetHeight())); |
335 return DrawDIBits(pSource, color, &matrix, 0, alpha_flag, pIccTransform); | 335 return DrawDIBits(pSource, color, &matrix, 0, alpha_flag, pIccTransform); |
336 } | 336 } |
337 FX_BOOL CFX_PSRenderer::StretchDIBits(const CFX_DIBSource* pSource, | 337 FX_BOOL CFX_PSRenderer::StretchDIBits(const CFX_DIBSource* pSource, |
338 FX_DWORD color, | 338 uint32_t color, |
339 int dest_left, | 339 int dest_left, |
340 int dest_top, | 340 int dest_top, |
341 int dest_width, | 341 int dest_width, |
342 int dest_height, | 342 int dest_height, |
343 FX_DWORD flags, | 343 uint32_t flags, |
344 int alpha_flag, | 344 int alpha_flag, |
345 void* pIccTransform) { | 345 void* pIccTransform) { |
346 StartRendering(); | 346 StartRendering(); |
347 CFX_Matrix matrix((FX_FLOAT)(dest_width), 0.0f, 0.0f, | 347 CFX_Matrix matrix((FX_FLOAT)(dest_width), 0.0f, 0.0f, |
348 (FX_FLOAT)(-dest_height), (FX_FLOAT)(dest_left), | 348 (FX_FLOAT)(-dest_height), (FX_FLOAT)(dest_left), |
349 (FX_FLOAT)(dest_top + dest_height)); | 349 (FX_FLOAT)(dest_top + dest_height)); |
350 return DrawDIBits(pSource, color, &matrix, flags, alpha_flag, pIccTransform); | 350 return DrawDIBits(pSource, color, &matrix, flags, alpha_flag, pIccTransform); |
351 } | 351 } |
352 FX_BOOL CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource, | 352 FX_BOOL CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource, |
353 FX_DWORD color, | 353 uint32_t color, |
354 const CFX_Matrix* pMatrix, | 354 const CFX_Matrix* pMatrix, |
355 FX_DWORD flags, | 355 uint32_t flags, |
356 int alpha_flag, | 356 int alpha_flag, |
357 void* pIccTransform) { | 357 void* pIccTransform) { |
358 StartRendering(); | 358 StartRendering(); |
359 if ((pMatrix->a == 0 && pMatrix->b == 0) || | 359 if ((pMatrix->a == 0 && pMatrix->b == 0) || |
360 (pMatrix->c == 0 && pMatrix->d == 0)) { | 360 (pMatrix->c == 0 && pMatrix->d == 0)) { |
361 return TRUE; | 361 return TRUE; |
362 } | 362 } |
363 if (pSource->HasAlpha()) { | 363 if (pSource->HasAlpha()) { |
364 return FALSE; | 364 return FALSE; |
365 } | 365 } |
366 int alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_FILL(color) | 366 int alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_FILL(color) |
367 : FXARGB_A(color); | 367 : FXARGB_A(color); |
368 if (pSource->IsAlphaMask() && (alpha < 255 || pSource->GetBPP() != 1)) { | 368 if (pSource->IsAlphaMask() && (alpha < 255 || pSource->GetBPP() != 1)) { |
369 return FALSE; | 369 return FALSE; |
370 } | 370 } |
371 OUTPUT_PS("q\n"); | 371 OUTPUT_PS("q\n"); |
372 CFX_ByteTextBuf buf; | 372 CFX_ByteTextBuf buf; |
373 buf << "[" << pMatrix->a << " " << pMatrix->b << " " << pMatrix->c << " " | 373 buf << "[" << pMatrix->a << " " << pMatrix->b << " " << pMatrix->c << " " |
374 << pMatrix->d << " " << pMatrix->e << " " << pMatrix->f << "]cm "; | 374 << pMatrix->d << " " << pMatrix->e << " " << pMatrix->f << "]cm "; |
375 int width = pSource->GetWidth(); | 375 int width = pSource->GetWidth(); |
376 int height = pSource->GetHeight(); | 376 int height = pSource->GetHeight(); |
377 buf << width << " " << height; | 377 buf << width << " " << height; |
378 if (pSource->GetBPP() == 1 && !pSource->GetPalette()) { | 378 if (pSource->GetBPP() == 1 && !pSource->GetPalette()) { |
379 int pitch = (width + 7) / 8; | 379 int pitch = (width + 7) / 8; |
380 FX_DWORD src_size = height * pitch; | 380 uint32_t src_size = height * pitch; |
381 uint8_t* src_buf = FX_Alloc(uint8_t, src_size); | 381 uint8_t* src_buf = FX_Alloc(uint8_t, src_size); |
382 for (int row = 0; row < height; row++) { | 382 for (int row = 0; row < height; row++) { |
383 const uint8_t* src_scan = pSource->GetScanline(row); | 383 const uint8_t* src_scan = pSource->GetScanline(row); |
384 FXSYS_memcpy(src_buf + row * pitch, src_scan, pitch); | 384 FXSYS_memcpy(src_buf + row * pitch, src_scan, pitch); |
385 } | 385 } |
386 uint8_t* output_buf; | 386 uint8_t* output_buf; |
387 FX_DWORD output_size; | 387 uint32_t output_size; |
388 FaxCompressData(src_buf, width, height, output_buf, output_size); | 388 FaxCompressData(src_buf, width, height, output_buf, output_size); |
389 if (pSource->IsAlphaMask()) { | 389 if (pSource->IsAlphaMask()) { |
390 SetColor(color, alpha_flag, pIccTransform); | 390 SetColor(color, alpha_flag, pIccTransform); |
391 m_bColorSet = FALSE; | 391 m_bColorSet = FALSE; |
392 buf << " true["; | 392 buf << " true["; |
393 } else { | 393 } else { |
394 buf << " 1["; | 394 buf << " 1["; |
395 } | 395 } |
396 buf << width << " 0 0 -" << height << " 0 " << height | 396 buf << width << " 0 0 -" << height << " 0 " << height |
397 << "]currentfile/ASCII85Decode filter "; | 397 << "]currentfile/ASCII85Decode filter "; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 *dest_scan++ = src_scan[2]; | 462 *dest_scan++ = src_scan[2]; |
463 *dest_scan++ = src_scan[1]; | 463 *dest_scan++ = src_scan[1]; |
464 *dest_scan++ = *src_scan; | 464 *dest_scan++ = *src_scan; |
465 src_scan += 3; | 465 src_scan += 3; |
466 } | 466 } |
467 } else { | 467 } else { |
468 FXSYS_memcpy(dest_scan, src_scan, src_pitch); | 468 FXSYS_memcpy(dest_scan, src_scan, src_pitch); |
469 } | 469 } |
470 } | 470 } |
471 uint8_t* compressed_buf; | 471 uint8_t* compressed_buf; |
472 FX_DWORD compressed_size; | 472 uint32_t compressed_size; |
473 PSCompressData(m_PSLevel, output_buf, output_size, compressed_buf, | 473 PSCompressData(m_PSLevel, output_buf, output_size, compressed_buf, |
474 compressed_size, filter); | 474 compressed_size, filter); |
475 if (output_buf != compressed_buf) { | 475 if (output_buf != compressed_buf) { |
476 FX_Free(output_buf); | 476 FX_Free(output_buf); |
477 } | 477 } |
478 output_buf = compressed_buf; | 478 output_buf = compressed_buf; |
479 output_size = compressed_size; | 479 output_size = compressed_size; |
480 } | 480 } |
481 if (pConverted != pSource) { | 481 if (pConverted != pSource) { |
482 delete pConverted; | 482 delete pConverted; |
483 pConverted = NULL; | 483 pConverted = NULL; |
484 } | 484 } |
485 buf << " 8["; | 485 buf << " 8["; |
486 buf << width << " 0 0 -" << height << " 0 " << height << "]"; | 486 buf << width << " 0 0 -" << height << " 0 " << height << "]"; |
487 buf << "currentfile/ASCII85Decode filter "; | 487 buf << "currentfile/ASCII85Decode filter "; |
488 if (filter) { | 488 if (filter) { |
489 buf << filter; | 489 buf << filter; |
490 } | 490 } |
491 buf << "false " << Bpp; | 491 buf << "false " << Bpp; |
492 buf << " colorimage\n"; | 492 buf << " colorimage\n"; |
493 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); | 493 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); |
494 WritePSBinary(output_buf, output_size); | 494 WritePSBinary(output_buf, output_size); |
495 FX_Free(output_buf); | 495 FX_Free(output_buf); |
496 } | 496 } |
497 OUTPUT_PS("\nQ\n"); | 497 OUTPUT_PS("\nQ\n"); |
498 return TRUE; | 498 return TRUE; |
499 } | 499 } |
500 void CFX_PSRenderer::SetColor(FX_DWORD color, | 500 void CFX_PSRenderer::SetColor(uint32_t color, |
501 int alpha_flag, | 501 int alpha_flag, |
502 void* pIccTransform) { | 502 void* pIccTransform) { |
503 if (!CFX_GEModule::Get()->GetCodecModule() || | 503 if (!CFX_GEModule::Get()->GetCodecModule() || |
504 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { | 504 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { |
505 pIccTransform = NULL; | 505 pIccTransform = NULL; |
506 } | 506 } |
507 FX_BOOL bCMYK = FALSE; | 507 FX_BOOL bCMYK = FALSE; |
508 if (pIccTransform) { | 508 if (pIccTransform) { |
509 ICodec_IccModule* pIccModule = | 509 ICodec_IccModule* pIccModule = |
510 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); | 510 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 buf << "/X" << ps_fontnum << " Ff/Encoding get " << ps_glyphindex << "/" | 639 buf << "/X" << ps_fontnum << " Ff/Encoding get " << ps_glyphindex << "/" |
640 << ps_glyphindex << " put\n"; | 640 << ps_glyphindex << " put\n"; |
641 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); | 641 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); |
642 } | 642 } |
643 FX_BOOL CFX_PSRenderer::DrawText(int nChars, | 643 FX_BOOL CFX_PSRenderer::DrawText(int nChars, |
644 const FXTEXT_CHARPOS* pCharPos, | 644 const FXTEXT_CHARPOS* pCharPos, |
645 CFX_Font* pFont, | 645 CFX_Font* pFont, |
646 CFX_FontCache* pCache, | 646 CFX_FontCache* pCache, |
647 const CFX_Matrix* pObject2Device, | 647 const CFX_Matrix* pObject2Device, |
648 FX_FLOAT font_size, | 648 FX_FLOAT font_size, |
649 FX_DWORD color, | 649 uint32_t color, |
650 int alpha_flag, | 650 int alpha_flag, |
651 void* pIccTransform) { | 651 void* pIccTransform) { |
652 StartRendering(); | 652 StartRendering(); |
653 int alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_FILL(alpha_flag) | 653 int alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_FILL(alpha_flag) |
654 : FXARGB_A(color); | 654 : FXARGB_A(color); |
655 if (alpha < 255) { | 655 if (alpha < 255) { |
656 return FALSE; | 656 return FALSE; |
657 } | 657 } |
658 if ((pObject2Device->a == 0 && pObject2Device->b == 0) || | 658 if ((pObject2Device->a == 0 && pObject2Device->b == 0) || |
659 (pObject2Device->c == 0 && pObject2Device->d == 0)) { | 659 (pObject2Device->c == 0 && pObject2Device->d == 0)) { |
(...skipping 21 matching lines...) Expand all Loading... |
681 CFX_ByteString hex; | 681 CFX_ByteString hex; |
682 hex.Format("<%02X>", ps_glyphindex); | 682 hex.Format("<%02X>", ps_glyphindex); |
683 buf << hex << "Tj\n"; | 683 buf << hex << "Tj\n"; |
684 } | 684 } |
685 buf << "Q\n"; | 685 buf << "Q\n"; |
686 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); | 686 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); |
687 return TRUE; | 687 return TRUE; |
688 } | 688 } |
689 void CFX_PSRenderer::WritePSBinary(const uint8_t* data, int len) { | 689 void CFX_PSRenderer::WritePSBinary(const uint8_t* data, int len) { |
690 uint8_t* dest_buf; | 690 uint8_t* dest_buf; |
691 FX_DWORD dest_size; | 691 uint32_t dest_size; |
692 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); | 692 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); |
693 if (pEncoders && | 693 if (pEncoders && |
694 pEncoders->GetBasicModule()->A85Encode(data, len, dest_buf, dest_size)) { | 694 pEncoders->GetBasicModule()->A85Encode(data, len, dest_buf, dest_size)) { |
695 m_pOutput->OutputPS((const FX_CHAR*)dest_buf, dest_size); | 695 m_pOutput->OutputPS((const FX_CHAR*)dest_buf, dest_size); |
696 FX_Free(dest_buf); | 696 FX_Free(dest_buf); |
697 } else { | 697 } else { |
698 m_pOutput->OutputPS((const FX_CHAR*)data, len); | 698 m_pOutput->OutputPS((const FX_CHAR*)data, len); |
699 } | 699 } |
700 } | 700 } |
OLD | NEW |