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 "render_int.h" | 7 #include "render_int.h" |
8 | 8 |
9 #include "core/include/fpdfapi/fpdf_pageobj.h" | 9 #include "core/include/fpdfapi/fpdf_pageobj.h" |
10 #include "core/include/fpdfapi/fpdf_render.h" | 10 #include "core/include/fpdfapi/fpdf_render.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 top = top_line; | 162 top = top_line; |
163 if (image_matrix.a < 0) { | 163 if (image_matrix.a < 0) { |
164 image_matrix.Scale(retinaScaleX, retinaScaleY); | 164 image_matrix.Scale(retinaScaleX, retinaScaleY); |
165 left = FXSYS_round(image_matrix.e + image_matrix.a); | 165 left = FXSYS_round(image_matrix.e + image_matrix.a); |
166 } else { | 166 } else { |
167 left = FXSYS_round(image_matrix.e); | 167 left = FXSYS_round(image_matrix.e); |
168 } | 168 } |
169 } else { | 169 } else { |
170 } | 170 } |
171 } | 171 } |
172 if (pResBitmap == NULL) { | 172 if (!pResBitmap) { |
173 image_matrix.Scale(retinaScaleX, retinaScaleY); | 173 image_matrix.Scale(retinaScaleX, retinaScaleY); |
174 pResBitmap = pBitmap->TransformTo(&image_matrix, left, top); | 174 pResBitmap = pBitmap->TransformTo(&image_matrix, left, top); |
175 } | 175 } |
176 if (pResBitmap == NULL) { | 176 if (!pResBitmap) { |
177 return NULL; | 177 return NULL; |
178 } | 178 } |
179 CFX_GlyphBitmap* pGlyph = new CFX_GlyphBitmap; | 179 CFX_GlyphBitmap* pGlyph = new CFX_GlyphBitmap; |
180 pGlyph->m_Left = left; | 180 pGlyph->m_Left = left; |
181 pGlyph->m_Top = -top; | 181 pGlyph->m_Top = -top; |
182 pGlyph->m_Bitmap.TakeOver(pResBitmap); | 182 pGlyph->m_Bitmap.TakeOver(pResBitmap); |
183 delete pResBitmap; | 183 delete pResBitmap; |
184 return pGlyph; | 184 return pGlyph; |
185 } | 185 } |
186 void _CPDF_UniqueKeyGen::Generate(int count, ...) { | 186 void _CPDF_UniqueKeyGen::Generate(int count, ...) { |
(...skipping 24 matching lines...) Expand all Loading... |
211 if (pClippingPath) { | 211 if (pClippingPath) { |
212 bClip = TRUE; | 212 bClip = TRUE; |
213 } else { | 213 } else { |
214 switch (text_render_mode) { | 214 switch (text_render_mode) { |
215 case 0: | 215 case 0: |
216 case 4: | 216 case 4: |
217 bFill = TRUE; | 217 bFill = TRUE; |
218 break; | 218 break; |
219 case 1: | 219 case 1: |
220 case 5: | 220 case 5: |
221 if (pFont->GetFace() == NULL && | 221 if (!pFont->GetFace() && |
222 !(pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) { | 222 !(pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) { |
223 bFill = TRUE; | 223 bFill = TRUE; |
224 } else { | 224 } else { |
225 bStroke = TRUE; | 225 bStroke = TRUE; |
226 } | 226 } |
227 break; | 227 break; |
228 case 2: | 228 case 2: |
229 case 6: | 229 case 6: |
230 if (pFont->GetFace() == NULL && | 230 if (!pFont->GetFace() && |
231 !(pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) { | 231 !(pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) { |
232 bFill = TRUE; | 232 bFill = TRUE; |
233 } else { | 233 } else { |
234 bFill = bStroke = TRUE; | 234 bFill = bStroke = TRUE; |
235 } | 235 } |
236 break; | 236 break; |
237 case 3: | 237 case 3: |
238 case 7: | 238 case 7: |
239 return TRUE; | 239 return TRUE; |
240 default: | 240 default: |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 m_pDevice, textobj->m_nChars, textobj->m_pCharCodes, | 298 m_pDevice, textobj->m_nChars, textobj->m_pCharCodes, |
299 textobj->m_pCharPos, pFont, font_size, &text_matrix, pDeviceMatrix, | 299 textobj->m_pCharPos, pFont, font_size, &text_matrix, pDeviceMatrix, |
300 textobj->m_GraphState, fill_argb, stroke_argb, pClippingPath, flag); | 300 textobj->m_GraphState, fill_argb, stroke_argb, pClippingPath, flag); |
301 } | 301 } |
302 text_matrix.Concat(*pObj2Device); | 302 text_matrix.Concat(*pObj2Device); |
303 return CPDF_TextRenderer::DrawNormalText( | 303 return CPDF_TextRenderer::DrawNormalText( |
304 m_pDevice, textobj->m_nChars, textobj->m_pCharCodes, textobj->m_pCharPos, | 304 m_pDevice, textobj->m_nChars, textobj->m_pCharCodes, textobj->m_pCharPos, |
305 pFont, font_size, &text_matrix, fill_argb, &m_Options); | 305 pFont, font_size, &text_matrix, fill_argb, &m_Options); |
306 } | 306 } |
307 CPDF_Type3Cache* CPDF_RenderStatus::GetCachedType3(CPDF_Type3Font* pFont) { | 307 CPDF_Type3Cache* CPDF_RenderStatus::GetCachedType3(CPDF_Type3Font* pFont) { |
308 if (pFont->m_pDocument == NULL) { | 308 if (!pFont->m_pDocument) { |
309 return NULL; | 309 return NULL; |
310 } | 310 } |
311 pFont->m_pDocument->GetPageData()->GetFont(pFont->GetFontDict(), FALSE); | 311 pFont->m_pDocument->GetPageData()->GetFont(pFont->GetFontDict(), FALSE); |
312 return pFont->m_pDocument->GetRenderData()->GetCachedType3(pFont); | 312 return pFont->m_pDocument->GetRenderData()->GetCachedType3(pFont); |
313 } | 313 } |
314 static void ReleaseCachedType3(CPDF_Type3Font* pFont) { | 314 static void ReleaseCachedType3(CPDF_Type3Font* pFont) { |
315 if (pFont->m_pDocument == NULL) { | 315 if (!pFont->m_pDocument) { |
316 return; | 316 return; |
317 } | 317 } |
318 pFont->m_pDocument->GetRenderData()->ReleaseCachedType3(pFont); | 318 pFont->m_pDocument->GetRenderData()->ReleaseCachedType3(pFont); |
319 pFont->m_pDocument->GetPageData()->ReleaseFont(pFont->GetFontDict()); | 319 pFont->m_pDocument->GetPageData()->ReleaseFont(pFont->GetFontDict()); |
320 } | 320 } |
321 FX_BOOL CPDF_Type3Char::LoadBitmap(CPDF_RenderContext* pContext) { | 321 FX_BOOL CPDF_Type3Char::LoadBitmap(CPDF_RenderContext* pContext) { |
322 if (m_pBitmap || m_pForm == NULL) { | 322 if (m_pBitmap || !m_pForm) { |
323 return TRUE; | 323 return TRUE; |
324 } | 324 } |
325 if (m_pForm->CountObjects() == 1 && !m_bColored) { | 325 if (m_pForm->CountObjects() == 1 && !m_bColored) { |
326 CPDF_PageObject* pPageObj = | 326 CPDF_PageObject* pPageObj = |
327 m_pForm->GetObjectAt(m_pForm->GetFirstObjectPosition()); | 327 m_pForm->GetObjectAt(m_pForm->GetFirstObjectPosition()); |
328 if (pPageObj->m_Type == PDFPAGE_IMAGE) { | 328 if (pPageObj->m_Type == PDFPAGE_IMAGE) { |
329 CPDF_ImageObject* pImage = (CPDF_ImageObject*)pPageObj; | 329 CPDF_ImageObject* pImage = (CPDF_ImageObject*)pPageObj; |
330 m_ImageMatrix = pImage->m_Matrix; | 330 m_ImageMatrix = pImage->m_Matrix; |
331 const CFX_DIBSource* pSource = pImage->m_pImage->LoadDIBSource(); | 331 const CFX_DIBSource* pSource = pImage->m_pImage->LoadDIBSource(); |
332 if (pSource) { | 332 if (pSource) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 FX_DWORD* pChars = textobj->m_pCharCodes; | 383 FX_DWORD* pChars = textobj->m_pCharCodes; |
384 if (textobj->m_nChars == 1) { | 384 if (textobj->m_nChars == 1) { |
385 pChars = (FX_DWORD*)(&textobj->m_pCharCodes); | 385 pChars = (FX_DWORD*)(&textobj->m_pCharCodes); |
386 } | 386 } |
387 for (int iChar = 0; iChar < textobj->m_nChars; iChar++) { | 387 for (int iChar = 0; iChar < textobj->m_nChars; iChar++) { |
388 FX_DWORD charcode = pChars[iChar]; | 388 FX_DWORD charcode = pChars[iChar]; |
389 if (charcode == (FX_DWORD)-1) { | 389 if (charcode == (FX_DWORD)-1) { |
390 continue; | 390 continue; |
391 } | 391 } |
392 CPDF_Type3Char* pType3Char = pType3Font->LoadChar(charcode); | 392 CPDF_Type3Char* pType3Char = pType3Font->LoadChar(charcode); |
393 if (pType3Char == NULL) { | 393 if (!pType3Char) { |
394 continue; | 394 continue; |
395 } | 395 } |
396 CFX_AffineMatrix matrix = char_matrix; | 396 CFX_AffineMatrix matrix = char_matrix; |
397 matrix.e += iChar ? textobj->m_pCharPos[iChar - 1] : 0; | 397 matrix.e += iChar ? textobj->m_pCharPos[iChar - 1] : 0; |
398 matrix.Concat(text_matrix); | 398 matrix.Concat(text_matrix); |
399 matrix.Concat(*pObj2Device); | 399 matrix.Concat(*pObj2Device); |
400 if (!pType3Char->LoadBitmap(m_pContext)) { | 400 if (!pType3Char->LoadBitmap(m_pContext)) { |
401 if (pGlyphAndPos) { | 401 if (pGlyphAndPos) { |
402 for (int i = 0; i < iChar; i++) { | 402 for (int i = 0; i < iChar; i++) { |
403 FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[i]; | 403 FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[i]; |
404 if (glyph.m_pGlyph == NULL) { | 404 if (!glyph.m_pGlyph) { |
405 continue; | 405 continue; |
406 } | 406 } |
407 m_pDevice->SetBitMask(&glyph.m_pGlyph->m_Bitmap, | 407 m_pDevice->SetBitMask(&glyph.m_pGlyph->m_Bitmap, |
408 glyph.m_OriginX + glyph.m_pGlyph->m_Left, | 408 glyph.m_OriginX + glyph.m_pGlyph->m_Left, |
409 glyph.m_OriginY - glyph.m_pGlyph->m_Top, | 409 glyph.m_OriginY - glyph.m_pGlyph->m_Top, |
410 fill_argb); | 410 fill_argb); |
411 } | 411 } |
412 FX_Free(pGlyphAndPos); | 412 FX_Free(pGlyphAndPos); |
413 pGlyphAndPos = NULL; | 413 pGlyphAndPos = NULL; |
414 } | 414 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 matrix.Scale(sa, sd); | 452 matrix.Scale(sa, sd); |
453 status.RenderObjectList(pType3Char->m_pForm, &matrix); | 453 status.RenderObjectList(pType3Char->m_pForm, &matrix); |
454 m_pDevice->SetDIBits(bitmap_device.GetBitmap(), rect.left, rect.top); | 454 m_pDevice->SetDIBits(bitmap_device.GetBitmap(), rect.left, rect.top); |
455 } | 455 } |
456 delete pStates; | 456 delete pStates; |
457 } else if (pType3Char->m_pBitmap) { | 457 } else if (pType3Char->m_pBitmap) { |
458 if (device_class == FXDC_DISPLAY) { | 458 if (device_class == FXDC_DISPLAY) { |
459 CPDF_Type3Cache* pCache = GetCachedType3(pType3Font); | 459 CPDF_Type3Cache* pCache = GetCachedType3(pType3Font); |
460 refTypeCache.m_dwCount++; | 460 refTypeCache.m_dwCount++; |
461 CFX_GlyphBitmap* pBitmap = pCache->LoadGlyph(charcode, &matrix, sa, sd); | 461 CFX_GlyphBitmap* pBitmap = pCache->LoadGlyph(charcode, &matrix, sa, sd); |
462 if (pBitmap == NULL) { | 462 if (!pBitmap) { |
463 continue; | 463 continue; |
464 } | 464 } |
465 int origin_x = FXSYS_round(matrix.e); | 465 int origin_x = FXSYS_round(matrix.e); |
466 int origin_y = FXSYS_round(matrix.f); | 466 int origin_y = FXSYS_round(matrix.f); |
467 if (pGlyphAndPos) { | 467 if (pGlyphAndPos) { |
468 pGlyphAndPos[iChar].m_pGlyph = pBitmap; | 468 pGlyphAndPos[iChar].m_pGlyph = pBitmap; |
469 pGlyphAndPos[iChar].m_OriginX = origin_x; | 469 pGlyphAndPos[iChar].m_OriginX = origin_x; |
470 pGlyphAndPos[iChar].m_OriginY = origin_y; | 470 pGlyphAndPos[iChar].m_OriginY = origin_y; |
471 } else { | 471 } else { |
472 m_pDevice->SetBitMask(&pBitmap->m_Bitmap, origin_x + pBitmap->m_Left, | 472 m_pDevice->SetBitMask(&pBitmap->m_Bitmap, origin_x + pBitmap->m_Left, |
(...skipping 18 matching lines...) Expand all Loading... |
491 FXGE_GetGlyphsBBox(pGlyphAndPos, textobj->m_nChars, 0, sa, sd); | 491 FXGE_GetGlyphsBBox(pGlyphAndPos, textobj->m_nChars, 0, sa, sd); |
492 CFX_DIBitmap bitmap; | 492 CFX_DIBitmap bitmap; |
493 if (!bitmap.Create((int)(rect.Width() * sa), (int)(rect.Height() * sd), | 493 if (!bitmap.Create((int)(rect.Width() * sa), (int)(rect.Height() * sd), |
494 FXDIB_8bppMask)) { | 494 FXDIB_8bppMask)) { |
495 FX_Free(pGlyphAndPos); | 495 FX_Free(pGlyphAndPos); |
496 return TRUE; | 496 return TRUE; |
497 } | 497 } |
498 bitmap.Clear(0); | 498 bitmap.Clear(0); |
499 for (int iChar = 0; iChar < textobj->m_nChars; iChar++) { | 499 for (int iChar = 0; iChar < textobj->m_nChars; iChar++) { |
500 FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar]; | 500 FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar]; |
501 if (glyph.m_pGlyph == NULL) { | 501 if (!glyph.m_pGlyph) { |
502 continue; | 502 continue; |
503 } | 503 } |
504 bitmap.TransferBitmap( | 504 bitmap.TransferBitmap( |
505 (int)((glyph.m_OriginX + glyph.m_pGlyph->m_Left - rect.left) * sa), | 505 (int)((glyph.m_OriginX + glyph.m_pGlyph->m_Left - rect.left) * sa), |
506 (int)((glyph.m_OriginY - glyph.m_pGlyph->m_Top - rect.top) * sd), | 506 (int)((glyph.m_OriginY - glyph.m_pGlyph->m_Top - rect.top) * sd), |
507 glyph.m_pGlyph->m_Bitmap.GetWidth(), | 507 glyph.m_pGlyph->m_Bitmap.GetWidth(), |
508 glyph.m_pGlyph->m_Bitmap.GetHeight(), &glyph.m_pGlyph->m_Bitmap, 0, | 508 glyph.m_pGlyph->m_Bitmap.GetHeight(), &glyph.m_pGlyph->m_Bitmap, 0, |
509 0); | 509 0); |
510 } | 510 } |
511 m_pDevice->SetBitMask(&bitmap, rect.left, rect.top, fill_argb); | 511 m_pDevice->SetBitMask(&bitmap, rect.left, rect.top, fill_argb); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 charpos.m_ExtGID = pFont->GlyphFromCharCodeExt(CharCode); | 557 charpos.m_ExtGID = pFont->GlyphFromCharCodeExt(CharCode); |
558 #endif | 558 #endif |
559 if (!pFont->IsEmbedded() && pFont->GetFontType() != PDFFONT_CIDFONT) { | 559 if (!pFont->IsEmbedded() && pFont->GetFontType() != PDFFONT_CIDFONT) { |
560 charpos.m_FontCharWidth = pFont->GetCharWidthF(CharCode); | 560 charpos.m_FontCharWidth = pFont->GetCharWidthF(CharCode); |
561 } else { | 561 } else { |
562 charpos.m_FontCharWidth = 0; | 562 charpos.m_FontCharWidth = 0; |
563 } | 563 } |
564 charpos.m_OriginX = iChar ? pCharPos[iChar - 1] : 0; | 564 charpos.m_OriginX = iChar ? pCharPos[iChar - 1] : 0; |
565 charpos.m_OriginY = 0; | 565 charpos.m_OriginY = 0; |
566 charpos.m_bGlyphAdjust = FALSE; | 566 charpos.m_bGlyphAdjust = FALSE; |
567 if (pCIDFont == NULL) { | 567 if (!pCIDFont) { |
568 continue; | 568 continue; |
569 } | 569 } |
570 FX_WORD CID = pCIDFont->CIDFromCharCode(CharCode); | 570 FX_WORD CID = pCIDFont->CIDFromCharCode(CharCode); |
571 if (bVertWriting) { | 571 if (bVertWriting) { |
572 charpos.m_OriginY = charpos.m_OriginX; | 572 charpos.m_OriginY = charpos.m_OriginX; |
573 charpos.m_OriginX = 0; | 573 charpos.m_OriginX = 0; |
574 short vx, vy; | 574 short vx, vy; |
575 pCIDFont->GetVertOrigin(CID, vx, vy); | 575 pCIDFont->GetVertOrigin(CID, vx, vy); |
576 charpos.m_OriginX -= FontSize * vx / 1000; | 576 charpos.m_OriginX -= FontSize * vx / 1000; |
577 charpos.m_OriginY -= FontSize * vy / 1000; | 577 charpos.m_OriginY -= FontSize * vy / 1000; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 } | 763 } |
764 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(&pFont->m_Font); | 764 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(&pFont->m_Font); |
765 FX_FONTCACHE_DEFINE(pCache, &pFont->m_Font); | 765 FX_FONTCACHE_DEFINE(pCache, &pFont->m_Font); |
766 CPDF_CharPosList CharPosList; | 766 CPDF_CharPosList CharPosList; |
767 CharPosList.Load(textobj->m_nChars, textobj->m_pCharCodes, | 767 CharPosList.Load(textobj->m_nChars, textobj->m_pCharCodes, |
768 textobj->m_pCharPos, pFont, font_size); | 768 textobj->m_pCharPos, pFont, font_size); |
769 for (FX_DWORD i = 0; i < CharPosList.m_nChars; i++) { | 769 for (FX_DWORD i = 0; i < CharPosList.m_nChars; i++) { |
770 FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i]; | 770 FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i]; |
771 const CFX_PathData* pPath = pFaceCache->LoadGlyphPath( | 771 const CFX_PathData* pPath = pFaceCache->LoadGlyphPath( |
772 &pFont->m_Font, charpos.m_GlyphIndex, charpos.m_FontCharWidth); | 772 &pFont->m_Font, charpos.m_GlyphIndex, charpos.m_FontCharWidth); |
773 if (pPath == NULL) { | 773 if (!pPath) { |
774 continue; | 774 continue; |
775 } | 775 } |
776 CPDF_PathObject path; | 776 CPDF_PathObject path; |
777 path.m_GraphState = textobj->m_GraphState; | 777 path.m_GraphState = textobj->m_GraphState; |
778 path.m_ColorState = textobj->m_ColorState; | 778 path.m_ColorState = textobj->m_ColorState; |
779 CFX_AffineMatrix matrix; | 779 CFX_AffineMatrix matrix; |
780 if (charpos.m_bGlyphAdjust) | 780 if (charpos.m_bGlyphAdjust) |
781 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], | 781 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], |
782 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); | 782 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); |
783 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, | 783 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, |
784 charpos.m_OriginY); | 784 charpos.m_OriginY); |
785 path.m_Path.New()->Append(pPath, &matrix); | 785 path.m_Path.New()->Append(pPath, &matrix); |
786 path.m_Matrix = *pTextMatrix; | 786 path.m_Matrix = *pTextMatrix; |
787 path.m_bStroke = bStroke; | 787 path.m_bStroke = bStroke; |
788 path.m_FillType = bFill ? FXFILL_WINDING : 0; | 788 path.m_FillType = bFill ? FXFILL_WINDING : 0; |
789 path.CalcBoundingBox(); | 789 path.CalcBoundingBox(); |
790 ProcessPath(&path, pObj2Device); | 790 ProcessPath(&path, pObj2Device); |
791 } | 791 } |
792 } | 792 } |
793 | 793 |
794 CFX_PathData* CPDF_Font::LoadGlyphPath(FX_DWORD charcode, int dest_width) { | 794 CFX_PathData* CPDF_Font::LoadGlyphPath(FX_DWORD charcode, int dest_width) { |
795 int glyph_index = GlyphFromCharCode(charcode); | 795 int glyph_index = GlyphFromCharCode(charcode); |
796 if (!m_Font.GetFace()) | 796 if (!m_Font.GetFace()) |
797 return nullptr; | 797 return nullptr; |
798 return m_Font.LoadGlyphPath(glyph_index, dest_width); | 798 return m_Font.LoadGlyphPath(glyph_index, dest_width); |
799 } | 799 } |
OLD | NEW |