OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/render/render_int.h" | 7 #include "core/fpdfapi/render/cpdf_textrenderer.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "core/fpdfapi/font/cpdf_cidfont.h" | |
12 #include "core/fpdfapi/font/cpdf_font.h" | 11 #include "core/fpdfapi/font/cpdf_font.h" |
13 #include "core/fpdfapi/font/cpdf_type3char.h" | |
14 #include "core/fpdfapi/font/cpdf_type3font.h" | |
15 #include "core/fpdfapi/page/cpdf_docpagedata.h" | |
16 #include "core/fpdfapi/page/cpdf_form.h" | |
17 #include "core/fpdfapi/page/cpdf_imageobject.h" | |
18 #include "core/fpdfapi/page/cpdf_pageobject.h" | |
19 #include "core/fpdfapi/page/cpdf_pathobject.h" | |
20 #include "core/fpdfapi/page/cpdf_textobject.h" | |
21 #include "core/fpdfapi/parser/cpdf_dictionary.h" | |
22 #include "core/fpdfapi/parser/cpdf_document.h" | |
23 #include "core/fpdfapi/render/cpdf_charposlist.h" | 12 #include "core/fpdfapi/render/cpdf_charposlist.h" |
24 #include "core/fpdfapi/render/cpdf_docrenderdata.h" | |
25 #include "core/fpdfapi/render/cpdf_renderoptions.h" | 13 #include "core/fpdfapi/render/cpdf_renderoptions.h" |
26 #include "core/fpdfapi/render/cpdf_renderstatus.h" | |
27 #include "core/fpdfapi/render/cpdf_textrenderer.h" | |
28 #include "core/fpdfapi/render/cpdf_type3cache.h" | |
29 #include "core/fxge/cfx_facecache.h" | |
30 #include "core/fxge/cfx_fxgedevice.h" | |
31 #include "core/fxge/cfx_gemodule.h" | |
32 #include "core/fxge/cfx_graphstatedata.h" | 14 #include "core/fxge/cfx_graphstatedata.h" |
33 #include "core/fxge/cfx_pathdata.h" | 15 #include "core/fxge/cfx_pathdata.h" |
34 #include "core/fxge/cfx_renderdevice.h" | 16 #include "core/fxge/cfx_renderdevice.h" |
35 #include "third_party/base/numerics/safe_math.h" | |
36 | 17 |
37 // static | 18 // static |
38 bool CPDF_TextRenderer::DrawTextPath(CFX_RenderDevice* pDevice, | 19 bool CPDF_TextRenderer::DrawTextPath(CFX_RenderDevice* pDevice, |
39 int nChars, | 20 int nChars, |
40 uint32_t* pCharCodes, | 21 uint32_t* pCharCodes, |
41 FX_FLOAT* pCharPos, | 22 FX_FLOAT* pCharPos, |
42 CPDF_Font* pFont, | 23 CPDF_Font* pFont, |
43 FX_FLOAT font_size, | 24 FX_FLOAT font_size, |
44 const CFX_Matrix* pText2User, | 25 const CFX_Matrix* pText2User, |
45 const CFX_Matrix* pUser2Device, | 26 const CFX_Matrix* pUser2Device, |
46 const CFX_GraphStateData* pGraphState, | 27 const CFX_GraphStateData* pGraphState, |
47 FX_ARGB fill_argb, | 28 FX_ARGB fill_argb, |
48 FX_ARGB stroke_argb, | 29 FX_ARGB stroke_argb, |
49 CFX_PathData* pClippingPath, | 30 CFX_PathData* pClippingPath, |
50 int nFlag) { | 31 int nFlag) { |
51 CPDF_CharPosList CharPosList; | 32 CPDF_CharPosList CharPosList; |
52 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); | 33 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); |
53 if (CharPosList.m_nChars == 0) | 34 if (CharPosList.m_nChars == 0) |
54 return true; | 35 return true; |
| 36 |
55 bool bDraw = true; | 37 bool bDraw = true; |
56 int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; | 38 int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; |
57 uint32_t startIndex = 0; | 39 uint32_t startIndex = 0; |
58 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { | 40 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { |
59 int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition; | 41 int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition; |
60 if (fontPosition == curFontPosition) | 42 if (fontPosition == curFontPosition) |
61 continue; | 43 continue; |
62 auto* font = fontPosition == -1 | 44 auto* font = fontPosition == -1 |
63 ? &pFont->m_Font | 45 ? &pFont->m_Font |
64 : pFont->m_FontFallbacks[fontPosition].get(); | 46 : pFont->m_FontFallbacks[fontPosition].get(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 const CPDF_RenderOptions* pOptions) { | 134 const CPDF_RenderOptions* pOptions) { |
153 CPDF_CharPosList CharPosList; | 135 CPDF_CharPosList CharPosList; |
154 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); | 136 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); |
155 if (CharPosList.m_nChars == 0) | 137 if (CharPosList.m_nChars == 0) |
156 return true; | 138 return true; |
157 int FXGE_flags = 0; | 139 int FXGE_flags = 0; |
158 if (pOptions) { | 140 if (pOptions) { |
159 uint32_t dwFlags = pOptions->m_Flags; | 141 uint32_t dwFlags = pOptions->m_Flags; |
160 if (dwFlags & RENDER_CLEARTYPE) { | 142 if (dwFlags & RENDER_CLEARTYPE) { |
161 FXGE_flags |= FXTEXT_CLEARTYPE; | 143 FXGE_flags |= FXTEXT_CLEARTYPE; |
162 if (dwFlags & RENDER_BGR_STRIPE) { | 144 if (dwFlags & RENDER_BGR_STRIPE) |
163 FXGE_flags |= FXTEXT_BGR_STRIPE; | 145 FXGE_flags |= FXTEXT_BGR_STRIPE; |
164 } | |
165 } | 146 } |
166 if (dwFlags & RENDER_NOTEXTSMOOTH) { | 147 if (dwFlags & RENDER_NOTEXTSMOOTH) |
167 FXGE_flags |= FXTEXT_NOSMOOTH; | 148 FXGE_flags |= FXTEXT_NOSMOOTH; |
168 } | 149 if (dwFlags & RENDER_PRINTGRAPHICTEXT) |
169 if (dwFlags & RENDER_PRINTGRAPHICTEXT) { | |
170 FXGE_flags |= FXTEXT_PRINTGRAPHICTEXT; | 150 FXGE_flags |= FXTEXT_PRINTGRAPHICTEXT; |
171 } | 151 if (dwFlags & RENDER_NO_NATIVETEXT) |
172 if (dwFlags & RENDER_NO_NATIVETEXT) { | |
173 FXGE_flags |= FXTEXT_NO_NATIVETEXT; | 152 FXGE_flags |= FXTEXT_NO_NATIVETEXT; |
174 } | 153 if (dwFlags & RENDER_PRINTIMAGETEXT) |
175 if (dwFlags & RENDER_PRINTIMAGETEXT) { | |
176 FXGE_flags |= FXTEXT_PRINTIMAGETEXT; | 154 FXGE_flags |= FXTEXT_PRINTIMAGETEXT; |
177 } | |
178 } else { | 155 } else { |
179 FXGE_flags = FXTEXT_CLEARTYPE; | 156 FXGE_flags = FXTEXT_CLEARTYPE; |
180 } | 157 } |
181 if (pFont->IsCIDFont()) { | 158 if (pFont->IsCIDFont()) |
182 FXGE_flags |= FXFONT_CIDFONT; | 159 FXGE_flags |= FXFONT_CIDFONT; |
183 } | |
184 bool bDraw = true; | 160 bool bDraw = true; |
185 int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; | 161 int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; |
186 uint32_t startIndex = 0; | 162 uint32_t startIndex = 0; |
187 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { | 163 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { |
188 int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition; | 164 int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition; |
189 if (fontPosition == curFontPosition) | 165 if (fontPosition == curFontPosition) |
190 continue; | 166 continue; |
191 auto* font = fontPosition == -1 | 167 auto* font = fontPosition == -1 |
192 ? &pFont->m_Font | 168 ? &pFont->m_Font |
193 : pFont->m_FontFallbacks[fontPosition].get(); | 169 : pFont->m_FontFallbacks[fontPosition].get(); |
194 if (!pDevice->DrawNormalText( | 170 if (!pDevice->DrawNormalText( |
195 i - startIndex, CharPosList.m_pCharPos + startIndex, font, | 171 i - startIndex, CharPosList.m_pCharPos + startIndex, font, |
196 font_size, pText2Device, fill_argb, FXGE_flags)) { | 172 font_size, pText2Device, fill_argb, FXGE_flags)) { |
197 bDraw = false; | 173 bDraw = false; |
198 } | 174 } |
199 fontPosition = curFontPosition; | 175 fontPosition = curFontPosition; |
200 startIndex = i; | 176 startIndex = i; |
201 } | 177 } |
202 auto* font = fontPosition == -1 ? &pFont->m_Font | 178 auto* font = fontPosition == -1 ? &pFont->m_Font |
203 : pFont->m_FontFallbacks[fontPosition].get(); | 179 : pFont->m_FontFallbacks[fontPosition].get(); |
204 if (!pDevice->DrawNormalText(CharPosList.m_nChars - startIndex, | 180 if (!pDevice->DrawNormalText(CharPosList.m_nChars - startIndex, |
205 CharPosList.m_pCharPos + startIndex, font, | 181 CharPosList.m_pCharPos + startIndex, font, |
206 font_size, pText2Device, fill_argb, | 182 font_size, pText2Device, fill_argb, |
207 FXGE_flags)) { | 183 FXGE_flags)) { |
208 bDraw = false; | 184 bDraw = false; |
209 } | 185 } |
210 return bDraw; | 186 return bDraw; |
211 } | 187 } |
OLD | NEW |