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/fpdfapi/fpdf_page/include/cpdf_pageobject.h" | 7 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" |
8 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h" | 8 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h" |
9 #include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h" | 9 #include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h" |
10 #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" | 10 #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" |
11 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" | 11 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" |
12 #include "core/fpdfapi/fpdf_render/include/cpdf_textrenderer.h" | 12 #include "core/fpdfapi/fpdf_render/include/cpdf_textrenderer.h" |
13 #include "core/fpdfdoc/include/cpvt_word.h" | 13 #include "core/fpdfdoc/include/cpvt_word.h" |
14 #include "core/fpdfdoc/include/ipvt_fontmap.h" | 14 #include "core/fpdfdoc/include/ipvt_fontmap.h" |
15 #include "core/fxge/include/fx_ge.h" | 15 #include "core/fxge/include/fx_ge.h" |
16 #include "fpdfsdk/cfx_systemhandler.h" | 16 #include "fpdfsdk/cfx_systemhandler.h" |
17 #include "fpdfsdk/fxedit/include/fx_edit.h" | 17 #include "fpdfsdk/fxedit/include/fx_edit.h" |
18 #include "fpdfsdk/fxedit/include/fxet_edit.h" | 18 #include "fpdfsdk/fxedit/include/fxet_edit.h" |
19 | 19 |
20 namespace { | |
21 | |
20 CFX_FloatRect GetUnderLineRect(const CPVT_Word& word) { | 22 CFX_FloatRect GetUnderLineRect(const CPVT_Word& word) { |
21 return CFX_FloatRect(word.ptWord.x, word.ptWord.y + word.fDescent * 0.5f, | 23 return CFX_FloatRect(word.ptWord.x, word.ptWord.y + word.fDescent * 0.5f, |
22 word.ptWord.x + word.fWidth, | 24 word.ptWord.x + word.fWidth, |
23 word.ptWord.y + word.fDescent * 0.25f); | 25 word.ptWord.y + word.fDescent * 0.25f); |
24 } | 26 } |
25 | 27 |
26 CFX_FloatRect GetCrossoutRect(const CPVT_Word& word) { | 28 CFX_FloatRect GetCrossoutRect(const CPVT_Word& word) { |
27 return CFX_FloatRect(word.ptWord.x, | 29 return CFX_FloatRect(word.ptWord.x, |
28 word.ptWord.y + (word.fAscent + word.fDescent) * 0.5f + | 30 word.ptWord.y + (word.fAscent + word.fDescent) * 0.5f + |
29 word.fDescent * 0.25f, | 31 word.fDescent * 0.25f, |
30 word.ptWord.x + word.fWidth, | 32 word.ptWord.x + word.fWidth, |
31 word.ptWord.y + (word.fAscent + word.fDescent) * 0.5f); | 33 word.ptWord.y + (word.fAscent + word.fDescent) * 0.5f); |
32 } | 34 } |
33 | 35 |
34 static void DrawTextString(CFX_RenderDevice* pDevice, | 36 void DrawTextString(CFX_RenderDevice* pDevice, |
35 const CFX_FloatPoint& pt, | 37 const CFX_FloatPoint& pt, |
36 CPDF_Font* pFont, | 38 CPDF_Font* pFont, |
37 FX_FLOAT fFontSize, | 39 FX_FLOAT fFontSize, |
38 CFX_Matrix* pUser2Device, | 40 CFX_Matrix* pUser2Device, |
39 const CFX_ByteString& str, | 41 const CFX_ByteString& str, |
40 FX_ARGB crTextFill, | 42 FX_ARGB crTextFill, |
41 FX_ARGB crTextStroke, | 43 FX_ARGB crTextStroke, |
42 int32_t nHorzScale) { | 44 int32_t nHorzScale) { |
43 FX_FLOAT x = pt.x, y = pt.y; | 45 FX_FLOAT x = pt.x, y = pt.y; |
44 pUser2Device->Transform(x, y); | 46 pUser2Device->Transform(x, y); |
45 | 47 |
46 if (pFont) { | 48 if (pFont) { |
47 if (nHorzScale != 100) { | 49 if (nHorzScale != 100) { |
48 CFX_Matrix mt(nHorzScale / 100.0f, 0, 0, 1, 0, 0); | 50 CFX_Matrix mt(nHorzScale / 100.0f, 0, 0, 1, 0, 0); |
49 mt.Concat(*pUser2Device); | 51 mt.Concat(*pUser2Device); |
50 | 52 |
51 CPDF_RenderOptions ro; | 53 CPDF_RenderOptions ro; |
52 ro.m_Flags = RENDER_CLEARTYPE; | 54 ro.m_Flags = RENDER_CLEARTYPE; |
53 ro.m_ColorMode = RENDER_COLOR_NORMAL; | 55 ro.m_ColorMode = RENDER_COLOR_NORMAL; |
54 | 56 |
55 if (crTextStroke != 0) { | 57 if (crTextStroke != 0) { |
56 CFX_FloatPoint pt1(0, 0), pt2(1, 0); | 58 CFX_FloatPoint pt1(0, 0), pt2(1, 0); |
57 pUser2Device->Transform(pt1.x, pt1.y); | 59 pUser2Device->Transform(pt1.x, pt1.y); |
58 pUser2Device->Transform(pt2.x, pt2.y); | 60 pUser2Device->Transform(pt2.x, pt2.y); |
59 CFX_GraphStateData gsd; | 61 CFX_GraphStateData gsd; |
60 gsd.m_LineWidth = | 62 gsd.m_LineWidth = |
61 (FX_FLOAT)FXSYS_fabs((pt2.x + pt2.y) - (pt1.x + pt1.y)); | 63 (FX_FLOAT)FXSYS_fabs((pt2.x + pt2.y) - (pt1.x + pt1.y)); |
62 | 64 |
63 CPDF_TextRenderer::DrawTextString(pDevice, x, y, pFont, fFontSize, &mt, | 65 CPDF_TextRenderer::DrawTextString(pDevice, x, y, pFont, fFontSize, &mt, |
64 str, crTextFill, crTextStroke, &gsd, | 66 str, crTextFill, crTextStroke, &gsd, |
65 &ro); | 67 &ro); |
66 } else { | 68 } else { |
67 CPDF_TextRenderer::DrawTextString(pDevice, x, y, pFont, fFontSize, &mt, | 69 CPDF_TextRenderer::DrawTextString(pDevice, x, y, pFont, fFontSize, &mt, |
68 str, crTextFill, 0, NULL, &ro); | 70 str, crTextFill, 0, nullptr, &ro); |
69 } | 71 } |
70 } else { | 72 } else { |
71 CPDF_RenderOptions ro; | 73 CPDF_RenderOptions ro; |
72 ro.m_Flags = RENDER_CLEARTYPE; | 74 ro.m_Flags = RENDER_CLEARTYPE; |
73 ro.m_ColorMode = RENDER_COLOR_NORMAL; | 75 ro.m_ColorMode = RENDER_COLOR_NORMAL; |
74 | 76 |
75 if (crTextStroke != 0) { | 77 if (crTextStroke != 0) { |
76 CFX_FloatPoint pt1(0, 0), pt2(1, 0); | 78 CFX_FloatPoint pt1(0, 0), pt2(1, 0); |
77 pUser2Device->Transform(pt1.x, pt1.y); | 79 pUser2Device->Transform(pt1.x, pt1.y); |
78 pUser2Device->Transform(pt2.x, pt2.y); | 80 pUser2Device->Transform(pt2.x, pt2.y); |
79 CFX_GraphStateData gsd; | 81 CFX_GraphStateData gsd; |
80 gsd.m_LineWidth = | 82 gsd.m_LineWidth = |
81 (FX_FLOAT)FXSYS_fabs((pt2.x + pt2.y) - (pt1.x + pt1.y)); | 83 (FX_FLOAT)FXSYS_fabs((pt2.x + pt2.y) - (pt1.x + pt1.y)); |
82 | 84 |
83 CPDF_TextRenderer::DrawTextString(pDevice, x, y, pFont, fFontSize, | 85 CPDF_TextRenderer::DrawTextString(pDevice, x, y, pFont, fFontSize, |
84 pUser2Device, str, crTextFill, | 86 pUser2Device, str, crTextFill, |
85 crTextStroke, &gsd, &ro); | 87 crTextStroke, &gsd, &ro); |
86 } else { | 88 } else { |
87 CPDF_TextRenderer::DrawTextString(pDevice, x, y, pFont, fFontSize, | 89 CPDF_TextRenderer::DrawTextString(pDevice, x, y, pFont, fFontSize, |
88 pUser2Device, str, crTextFill, 0, | 90 pUser2Device, str, crTextFill, 0, |
89 NULL, &ro); | 91 nullptr, &ro); |
90 } | 92 } |
91 } | 93 } |
92 } | 94 } |
93 } | 95 } |
94 | 96 |
97 void AddRectToPageObjects(CPDF_PageObjectHolder* pObjectHolder, | |
Lei Zhang
2016/05/26 18:00:51
Just moved code over, no changes.
| |
98 FX_COLORREF crFill, | |
99 const CFX_FloatRect& rcFill) { | |
100 std::unique_ptr<CPDF_PathObject> pPathObj(new CPDF_PathObject); | |
101 CFX_PathData* pPathData = pPathObj->m_Path.GetModify(); | |
102 pPathData->AppendRect(rcFill.left, rcFill.bottom, rcFill.right, rcFill.top); | |
103 | |
104 FX_FLOAT rgb[3]; | |
105 rgb[0] = FXARGB_R(crFill) / 255.0f; | |
106 rgb[1] = FXARGB_G(crFill) / 255.0f; | |
107 rgb[2] = FXARGB_B(crFill) / 255.0f; | |
108 pPathObj->m_ColorState.SetFillColor( | |
109 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); | |
110 | |
111 pPathObj->m_FillType = FXFILL_ALTERNATE; | |
112 pPathObj->m_bStroke = FALSE; | |
113 pObjectHolder->GetPageObjectList()->push_back(std::move(pPathObj)); | |
114 } | |
115 | |
116 CPDF_TextObject* AddTextObjToPageObjects(CPDF_PageObjectHolder* pObjectHolder, | |
117 FX_COLORREF crText, | |
118 CPDF_Font* pFont, | |
119 FX_FLOAT fFontSize, | |
120 FX_FLOAT fCharSpace, | |
121 int32_t nHorzScale, | |
122 const CFX_FloatPoint& point, | |
123 const CFX_ByteString& text) { | |
124 std::unique_ptr<CPDF_TextObject> pTxtObj(new CPDF_TextObject); | |
125 CPDF_TextStateData* pTextStateData = pTxtObj->m_TextState.GetModify(); | |
126 pTextStateData->m_pFont = pFont; | |
127 pTextStateData->m_FontSize = fFontSize; | |
128 pTextStateData->m_CharSpace = fCharSpace; | |
129 pTextStateData->m_WordSpace = 0; | |
130 pTextStateData->m_TextMode = TextRenderingMode::MODE_FILL; | |
131 pTextStateData->m_Matrix[0] = nHorzScale / 100.0f; | |
132 pTextStateData->m_Matrix[1] = 0; | |
133 pTextStateData->m_Matrix[2] = 0; | |
134 pTextStateData->m_Matrix[3] = 1; | |
135 | |
136 FX_FLOAT rgb[3]; | |
137 rgb[0] = FXARGB_R(crText) / 255.0f; | |
138 rgb[1] = FXARGB_G(crText) / 255.0f; | |
139 rgb[2] = FXARGB_B(crText) / 255.0f; | |
140 pTxtObj->m_ColorState.SetFillColor( | |
141 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); | |
142 pTxtObj->m_ColorState.SetStrokeColor( | |
143 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); | |
144 | |
145 pTxtObj->SetPosition(point.x, point.y); | |
146 pTxtObj->SetText(text); | |
147 | |
148 CPDF_TextObject* pRet = pTxtObj.get(); | |
149 pObjectHolder->GetPageObjectList()->push_back(std::move(pTxtObj)); | |
150 return pRet; | |
151 } | |
152 | |
153 } // namespace | |
154 | |
95 void IFX_Edit::DrawUnderline(CFX_RenderDevice* pDevice, | 155 void IFX_Edit::DrawUnderline(CFX_RenderDevice* pDevice, |
96 CFX_Matrix* pUser2Device, | 156 CFX_Matrix* pUser2Device, |
97 IFX_Edit* pEdit, | 157 IFX_Edit* pEdit, |
98 FX_COLORREF color, | 158 FX_COLORREF color, |
99 const CFX_FloatRect& rcClip, | 159 const CFX_FloatRect& rcClip, |
100 const CFX_FloatPoint& ptOffset, | 160 const CFX_FloatPoint& ptOffset, |
101 const CPVT_WordRange* pRange) { | 161 const CPVT_WordRange* pRange) { |
102 pDevice->SaveState(); | 162 pDevice->SaveState(); |
103 | 163 |
104 if (!rcClip.IsEmpty()) { | 164 if (!rcClip.IsEmpty()) { |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 DrawTextString( | 441 DrawTextString( |
382 pDevice, CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), | 442 pDevice, CFX_FloatPoint(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
383 pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, pUser2Device, | 443 pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, pUser2Device, |
384 sTextBuf.MakeString(), crOld, 0, wp.nHorzScale); | 444 sTextBuf.MakeString(), crOld, 0, wp.nHorzScale); |
385 } | 445 } |
386 } | 446 } |
387 | 447 |
388 pDevice->RestoreState(false); | 448 pDevice->RestoreState(false); |
389 } | 449 } |
390 | 450 |
391 static void AddRectToPageObjects(CPDF_PageObjectHolder* pObjectHolder, | |
392 FX_COLORREF crFill, | |
393 const CFX_FloatRect& rcFill) { | |
394 std::unique_ptr<CPDF_PathObject> pPathObj(new CPDF_PathObject); | |
395 CFX_PathData* pPathData = pPathObj->m_Path.GetModify(); | |
396 pPathData->AppendRect(rcFill.left, rcFill.bottom, rcFill.right, rcFill.top); | |
397 | |
398 FX_FLOAT rgb[3]; | |
399 rgb[0] = FXARGB_R(crFill) / 255.0f; | |
400 rgb[1] = FXARGB_G(crFill) / 255.0f; | |
401 rgb[2] = FXARGB_B(crFill) / 255.0f; | |
402 pPathObj->m_ColorState.SetFillColor( | |
403 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); | |
404 | |
405 pPathObj->m_FillType = FXFILL_ALTERNATE; | |
406 pPathObj->m_bStroke = FALSE; | |
407 pObjectHolder->GetPageObjectList()->push_back(std::move(pPathObj)); | |
408 } | |
409 | |
410 static CPDF_TextObject* AddTextObjToPageObjects( | |
411 CPDF_PageObjectHolder* pObjectHolder, | |
412 FX_COLORREF crText, | |
413 CPDF_Font* pFont, | |
414 FX_FLOAT fFontSize, | |
415 FX_FLOAT fCharSpace, | |
416 int32_t nHorzScale, | |
417 const CFX_FloatPoint& point, | |
418 const CFX_ByteString& text) { | |
419 std::unique_ptr<CPDF_TextObject> pTxtObj(new CPDF_TextObject); | |
420 CPDF_TextStateData* pTextStateData = pTxtObj->m_TextState.GetModify(); | |
421 pTextStateData->m_pFont = pFont; | |
422 pTextStateData->m_FontSize = fFontSize; | |
423 pTextStateData->m_CharSpace = fCharSpace; | |
424 pTextStateData->m_WordSpace = 0; | |
425 pTextStateData->m_TextMode = TextRenderingMode::MODE_FILL; | |
426 pTextStateData->m_Matrix[0] = nHorzScale / 100.0f; | |
427 pTextStateData->m_Matrix[1] = 0; | |
428 pTextStateData->m_Matrix[2] = 0; | |
429 pTextStateData->m_Matrix[3] = 1; | |
430 | |
431 FX_FLOAT rgb[3]; | |
432 rgb[0] = FXARGB_R(crText) / 255.0f; | |
433 rgb[1] = FXARGB_G(crText) / 255.0f; | |
434 rgb[2] = FXARGB_B(crText) / 255.0f; | |
435 pTxtObj->m_ColorState.SetFillColor( | |
436 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); | |
437 pTxtObj->m_ColorState.SetStrokeColor( | |
438 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); | |
439 | |
440 pTxtObj->SetPosition(point.x, point.y); | |
441 pTxtObj->SetText(text); | |
442 | |
443 CPDF_TextObject* pRet = pTxtObj.get(); | |
444 pObjectHolder->GetPageObjectList()->push_back(std::move(pTxtObj)); | |
445 return pRet; | |
446 } | |
447 | |
448 void IFX_Edit::GeneratePageObjects( | 451 void IFX_Edit::GeneratePageObjects( |
449 CPDF_PageObjectHolder* pObjectHolder, | 452 CPDF_PageObjectHolder* pObjectHolder, |
450 IFX_Edit* pEdit, | 453 IFX_Edit* pEdit, |
451 const CFX_FloatPoint& ptOffset, | 454 const CFX_FloatPoint& ptOffset, |
452 const CPVT_WordRange* pRange, | 455 const CPVT_WordRange* pRange, |
453 FX_COLORREF crText, | 456 FX_COLORREF crText, |
454 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { | 457 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { |
455 FX_FLOAT fFontSize = pEdit->GetFontSize(); | 458 FX_FLOAT fFontSize = pEdit->GetFontSize(); |
456 | 459 |
457 int32_t nOldFontIndex = -1; | 460 int32_t nOldFontIndex = -1; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
623 CFX_FloatRect rcUnderline = GetUnderLineRect(word); | 626 CFX_FloatRect rcUnderline = GetUnderLineRect(word); |
624 rcUnderline.left += ptOffset.x; | 627 rcUnderline.left += ptOffset.x; |
625 rcUnderline.right += ptOffset.x; | 628 rcUnderline.right += ptOffset.x; |
626 rcUnderline.top += ptOffset.y; | 629 rcUnderline.top += ptOffset.y; |
627 rcUnderline.bottom += ptOffset.y; | 630 rcUnderline.bottom += ptOffset.y; |
628 AddRectToPageObjects(pObjectHolder, color, rcUnderline); | 631 AddRectToPageObjects(pObjectHolder, color, rcUnderline); |
629 } | 632 } |
630 } | 633 } |
631 } | 634 } |
632 } | 635 } |
OLD | NEW |