| 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/win32/cfx_psrenderer.h" | 7 #include "core/fxge/win32/cfx_psrenderer.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "core/fxcodec/fx_codec.h" | 11 #include "core/fxcodec/fx_codec.h" |
| 12 #include "core/fxcrt/cfx_maybe_owned.h" | 12 #include "core/fxcrt/cfx_maybe_owned.h" |
| 13 #include "core/fxge/cfx_facecache.h" | 13 #include "core/fxge/cfx_facecache.h" |
| 14 #include "core/fxge/cfx_fontcache.h" | 14 #include "core/fxge/cfx_fontcache.h" |
| 15 #include "core/fxge/cfx_pathdata.h" | 15 #include "core/fxge/cfx_pathdata.h" |
| 16 #include "core/fxge/cfx_renderdevice.h" | 16 #include "core/fxge/cfx_renderdevice.h" |
| 17 #include "core/fxge/ge/fx_text_int.h" | 17 #include "core/fxge/ge/fx_text_int.h" |
| 18 #include "core/fxge/win32/cpsoutput.h" | 18 #include "core/fxge/win32/cpsoutput.h" |
| 19 #include "third_party/base/ptr_util.h" |
| 19 | 20 |
| 20 struct PSGlyph { | 21 struct PSGlyph { |
| 21 CFX_Font* m_pFont; | 22 CFX_Font* m_pFont; |
| 22 uint32_t m_GlyphIndex; | 23 uint32_t m_GlyphIndex; |
| 23 bool m_bGlyphAdjust; | 24 bool m_bGlyphAdjust; |
| 24 FX_FLOAT m_AdjustMatrix[4]; | 25 FX_FLOAT m_AdjustMatrix[4]; |
| 25 }; | 26 }; |
| 26 | 27 |
| 27 class CPSFont { | 28 class CPSFont { |
| 28 public: | 29 public: |
| 29 PSGlyph m_Glyphs[256]; | 30 PSGlyph m_Glyphs[256]; |
| 30 int m_nGlyphs; | 31 int m_nGlyphs; |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 CFX_PSRenderer::CFX_PSRenderer() { | 34 CFX_PSRenderer::CFX_PSRenderer() { |
| 34 m_pOutput = nullptr; | 35 m_pOutput = nullptr; |
| 35 m_bColorSet = m_bGraphStateSet = false; | 36 m_bColorSet = m_bGraphStateSet = false; |
| 36 m_bInited = false; | 37 m_bInited = false; |
| 37 } | 38 } |
| 38 | 39 |
| 39 CFX_PSRenderer::~CFX_PSRenderer() { | 40 CFX_PSRenderer::~CFX_PSRenderer() {} |
| 40 for (int i = 0; i < static_cast<int>(m_PSFontList.GetSize()); i++) { | |
| 41 CPSFont* pFont = m_PSFontList[i]; | |
| 42 delete pFont; | |
| 43 } | |
| 44 } | |
| 45 | 41 |
| 46 #define OUTPUT_PS(str) m_pOutput->OutputPS(str, sizeof str - 1) | 42 #define OUTPUT_PS(str) m_pOutput->OutputPS(str, sizeof str - 1) |
| 47 | 43 |
| 48 void CFX_PSRenderer::Init(CPSOutput* pOutput, | 44 void CFX_PSRenderer::Init(CPSOutput* pOutput, |
| 49 int pslevel, | 45 int pslevel, |
| 50 int width, | 46 int width, |
| 51 int height, | 47 int height, |
| 52 bool bCmykOutput) { | 48 bool bCmykOutput) { |
| 53 m_PSLevel = pslevel; | 49 m_PSLevel = pslevel; |
| 54 m_pOutput = pOutput; | 50 m_pOutput = pOutput; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 77 "/cm/concat load def/Cm/currentmatrix load def/mx/matrix load " | 73 "/cm/concat load def/Cm/currentmatrix load def/mx/matrix load " |
| 78 "def/sm/setmatrix load def\n"; | 74 "def/sm/setmatrix load def\n"; |
| 79 OUTPUT_PS(init_str); | 75 OUTPUT_PS(init_str); |
| 80 m_bInited = true; | 76 m_bInited = true; |
| 81 return true; | 77 return true; |
| 82 } | 78 } |
| 83 | 79 |
| 84 void CFX_PSRenderer::EndRendering() { | 80 void CFX_PSRenderer::EndRendering() { |
| 85 if (m_bInited) { | 81 if (m_bInited) { |
| 86 OUTPUT_PS("\nrestore\n"); | 82 OUTPUT_PS("\nrestore\n"); |
| 83 m_bInited = false; |
| 87 } | 84 } |
| 88 m_bInited = false; | |
| 89 } | 85 } |
| 90 | 86 |
| 91 void CFX_PSRenderer::SaveState() { | 87 void CFX_PSRenderer::SaveState() { |
| 92 StartRendering(); | 88 StartRendering(); |
| 93 OUTPUT_PS("q\n"); | 89 OUTPUT_PS("q\n"); |
| 94 m_ClipBoxStack.Add(m_ClipBox); | 90 m_ClipBoxStack.push_back(m_ClipBox); |
| 95 } | 91 } |
| 96 | 92 |
| 97 void CFX_PSRenderer::RestoreState(bool bKeepSaved) { | 93 void CFX_PSRenderer::RestoreState(bool bKeepSaved) { |
| 98 StartRendering(); | 94 StartRendering(); |
| 99 if (bKeepSaved) { | 95 if (bKeepSaved) |
| 100 OUTPUT_PS("Q\nq\n"); | 96 OUTPUT_PS("Q\nq\n"); |
| 101 } else { | 97 else |
| 102 OUTPUT_PS("Q\n"); | 98 OUTPUT_PS("Q\n"); |
| 103 } | 99 |
| 104 m_bColorSet = false; | 100 m_bColorSet = false; |
| 105 m_bGraphStateSet = false; | 101 m_bGraphStateSet = false; |
| 106 int size = m_ClipBoxStack.GetSize(); | 102 if (m_ClipBoxStack.empty()) |
| 107 if (!size) | |
| 108 return; | 103 return; |
| 109 | 104 |
| 110 m_ClipBox = m_ClipBoxStack.GetAt(size - 1); | 105 m_ClipBox = m_ClipBoxStack.back(); |
| 111 if (!bKeepSaved) | 106 if (!bKeepSaved) |
| 112 m_ClipBoxStack.RemoveAt(size - 1); | 107 m_ClipBoxStack.pop_back(); |
| 113 } | 108 } |
| 114 | 109 |
| 115 void CFX_PSRenderer::OutputPath(const CFX_PathData* pPathData, | 110 void CFX_PSRenderer::OutputPath(const CFX_PathData* pPathData, |
| 116 const CFX_Matrix* pObject2Device) { | 111 const CFX_Matrix* pObject2Device) { |
| 117 int nPoints = pPathData->GetPointCount(); | 112 int nPoints = pPathData->GetPointCount(); |
| 118 CFX_ByteTextBuf buf; | 113 CFX_ByteTextBuf buf; |
| 119 buf.EstimateSize(nPoints * 10); | 114 buf.EstimateSize(nPoints * 10); |
| 120 for (int i = 0; i < nPoints; i++) { | 115 for (int i = 0; i < nPoints; i++) { |
| 121 uint8_t flag = pPathData->GetFlag(i); | 116 uint8_t flag = pPathData->GetFlag(i); |
| 122 FX_FLOAT x = pPathData->GetPointX(i); | 117 FX_FLOAT x = pPathData->GetPointX(i); |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 } | 525 } |
| 531 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); | 526 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); |
| 532 } | 527 } |
| 533 } | 528 } |
| 534 | 529 |
| 535 void CFX_PSRenderer::FindPSFontGlyph(CFX_FaceCache* pFaceCache, | 530 void CFX_PSRenderer::FindPSFontGlyph(CFX_FaceCache* pFaceCache, |
| 536 CFX_Font* pFont, | 531 CFX_Font* pFont, |
| 537 const FXTEXT_CHARPOS& charpos, | 532 const FXTEXT_CHARPOS& charpos, |
| 538 int* ps_fontnum, | 533 int* ps_fontnum, |
| 539 int* ps_glyphindex) { | 534 int* ps_glyphindex) { |
| 540 for (int i = 0; i < m_PSFontList.GetSize(); i++) { | 535 int i = 0; |
| 541 CPSFont* pPSFont = m_PSFontList[i]; | 536 for (const auto& pPSFont : m_PSFontList) { |
| 542 for (int j = 0; j < pPSFont->m_nGlyphs; j++) | 537 for (int j = 0; j < pPSFont->m_nGlyphs; j++) { |
| 543 if (pPSFont->m_Glyphs[j].m_pFont == pFont && | 538 if (pPSFont->m_Glyphs[j].m_pFont == pFont && |
| 544 pPSFont->m_Glyphs[j].m_GlyphIndex == charpos.m_GlyphIndex) { | 539 pPSFont->m_Glyphs[j].m_GlyphIndex == charpos.m_GlyphIndex && |
| 545 if ((!pPSFont->m_Glyphs[j].m_bGlyphAdjust && !charpos.m_bGlyphAdjust) || | 540 ((!pPSFont->m_Glyphs[j].m_bGlyphAdjust && !charpos.m_bGlyphAdjust) || |
| 546 (pPSFont->m_Glyphs[j].m_bGlyphAdjust && charpos.m_bGlyphAdjust && | 541 (pPSFont->m_Glyphs[j].m_bGlyphAdjust && charpos.m_bGlyphAdjust && |
| 547 (FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[0] - | 542 (FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[0] - |
| 548 charpos.m_AdjustMatrix[0]) < 0.01 && | 543 charpos.m_AdjustMatrix[0]) < 0.01 && |
| 549 FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[1] - | 544 FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[1] - |
| 550 charpos.m_AdjustMatrix[1]) < 0.01 && | 545 charpos.m_AdjustMatrix[1]) < 0.01 && |
| 551 FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[2] - | 546 FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[2] - |
| 552 charpos.m_AdjustMatrix[2]) < 0.01 && | 547 charpos.m_AdjustMatrix[2]) < 0.01 && |
| 553 FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[3] - | 548 FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[3] - |
| 554 charpos.m_AdjustMatrix[3]) < 0.01))) { | 549 charpos.m_AdjustMatrix[3]) < 0.01)))) { |
| 555 *ps_fontnum = i; | 550 *ps_fontnum = i; |
| 556 *ps_glyphindex = j; | 551 *ps_glyphindex = j; |
| 557 return; | 552 return; |
| 558 } | |
| 559 } | 553 } |
| 554 } |
| 555 ++i; |
| 560 } | 556 } |
| 561 if (m_PSFontList.GetSize() == 0 || | 557 if (m_PSFontList.empty() || m_PSFontList.back()->m_nGlyphs == 256) { |
| 562 m_PSFontList[m_PSFontList.GetSize() - 1]->m_nGlyphs == 256) { | 558 m_PSFontList.push_back(pdfium::MakeUnique<CPSFont>()); |
| 563 CPSFont* pPSFont = new CPSFont; | 559 m_PSFontList.back()->m_nGlyphs = 0; |
| 564 pPSFont->m_nGlyphs = 0; | |
| 565 m_PSFontList.Add(pPSFont); | |
| 566 CFX_ByteTextBuf buf; | 560 CFX_ByteTextBuf buf; |
| 567 buf << "8 dict begin/FontType 3 def/FontMatrix[1 0 0 1 0 0]def\n" | 561 buf << "8 dict begin/FontType 3 def/FontMatrix[1 0 0 1 0 0]def\n" |
| 568 "/FontBBox[0 0 0 0]def/Encoding 256 array def 0 1 255{Encoding " | 562 "/FontBBox[0 0 0 0]def/Encoding 256 array def 0 1 255{Encoding " |
| 569 "exch/.notdef put}for\n" | 563 "exch/.notdef put}for\n" |
| 570 "/CharProcs 1 dict def CharProcs begin/.notdef {} def end\n" | 564 "/CharProcs 1 dict def CharProcs begin/.notdef {} def end\n" |
| 571 "/BuildGlyph{1 0 -10 -10 10 10 setcachedevice exch/CharProcs get " | 565 "/BuildGlyph{1 0 -10 -10 10 10 setcachedevice exch/CharProcs get " |
| 572 "exch 2 copy known not{pop/.notdef}if get exec}bind def\n" | 566 "exch 2 copy known not{pop/.notdef}if get exec}bind def\n" |
| 573 "/BuildChar{1 index/Encoding get exch get 1 index/BuildGlyph get " | 567 "/BuildChar{1 index/Encoding get exch get 1 index/BuildGlyph get " |
| 574 "exec}bind def\n" | 568 "exec}bind def\n" |
| 575 "currentdict end\n"; | 569 "currentdict end\n"; |
| 576 buf << "/X" << m_PSFontList.GetSize() - 1 << " exch definefont pop\n"; | 570 buf << "/X" << static_cast<uint32_t>(m_PSFontList.size() - 1) |
| 571 << " exch definefont pop\n"; |
| 577 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); | 572 m_pOutput->OutputPS((const FX_CHAR*)buf.GetBuffer(), buf.GetSize()); |
| 578 buf.Clear(); | 573 buf.Clear(); |
| 579 } | 574 } |
| 580 *ps_fontnum = m_PSFontList.GetSize() - 1; | 575 *ps_fontnum = m_PSFontList.size() - 1; |
| 581 CPSFont* pPSFont = m_PSFontList[*ps_fontnum]; | 576 CPSFont* pPSFont = m_PSFontList[*ps_fontnum].get(); |
| 582 int glyphindex = pPSFont->m_nGlyphs; | 577 int glyphindex = pPSFont->m_nGlyphs; |
| 583 *ps_glyphindex = glyphindex; | 578 *ps_glyphindex = glyphindex; |
| 584 pPSFont->m_Glyphs[glyphindex].m_GlyphIndex = charpos.m_GlyphIndex; | 579 pPSFont->m_Glyphs[glyphindex].m_GlyphIndex = charpos.m_GlyphIndex; |
| 585 pPSFont->m_Glyphs[glyphindex].m_pFont = pFont; | 580 pPSFont->m_Glyphs[glyphindex].m_pFont = pFont; |
| 586 pPSFont->m_Glyphs[glyphindex].m_bGlyphAdjust = charpos.m_bGlyphAdjust; | 581 pPSFont->m_Glyphs[glyphindex].m_bGlyphAdjust = charpos.m_bGlyphAdjust; |
| 587 if (charpos.m_bGlyphAdjust) { | 582 if (charpos.m_bGlyphAdjust) { |
| 588 pPSFont->m_Glyphs[glyphindex].m_AdjustMatrix[0] = charpos.m_AdjustMatrix[0]; | 583 pPSFont->m_Glyphs[glyphindex].m_AdjustMatrix[0] = charpos.m_AdjustMatrix[0]; |
| 589 pPSFont->m_Glyphs[glyphindex].m_AdjustMatrix[1] = charpos.m_AdjustMatrix[1]; | 584 pPSFont->m_Glyphs[glyphindex].m_AdjustMatrix[1] = charpos.m_AdjustMatrix[1]; |
| 590 pPSFont->m_Glyphs[glyphindex].m_AdjustMatrix[2] = charpos.m_AdjustMatrix[2]; | 585 pPSFont->m_Glyphs[glyphindex].m_AdjustMatrix[2] = charpos.m_AdjustMatrix[2]; |
| 591 pPSFont->m_Glyphs[glyphindex].m_AdjustMatrix[3] = charpos.m_AdjustMatrix[3]; | 586 pPSFont->m_Glyphs[glyphindex].m_AdjustMatrix[3] = charpos.m_AdjustMatrix[3]; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); | 679 CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); |
| 685 if (pEncoders && | 680 if (pEncoders && |
| 686 pEncoders->GetBasicModule()->A85Encode(data, len, &dest_buf, | 681 pEncoders->GetBasicModule()->A85Encode(data, len, &dest_buf, |
| 687 &dest_size)) { | 682 &dest_size)) { |
| 688 m_pOutput->OutputPS((const FX_CHAR*)dest_buf, dest_size); | 683 m_pOutput->OutputPS((const FX_CHAR*)dest_buf, dest_size); |
| 689 FX_Free(dest_buf); | 684 FX_Free(dest_buf); |
| 690 } else { | 685 } else { |
| 691 m_pOutput->OutputPS((const FX_CHAR*)data, len); | 686 m_pOutput->OutputPS((const FX_CHAR*)data, len); |
| 692 } | 687 } |
| 693 } | 688 } |
| OLD | NEW |