Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp ('k') | core/src/fpdfdoc/doc_action.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 top = top_line; 156 top = top_line;
157 if (image_matrix.a < 0) { 157 if (image_matrix.a < 0) {
158 image_matrix.Scale(retinaScaleX, retinaScaleY); 158 image_matrix.Scale(retinaScaleX, retinaScaleY);
159 left = FXSYS_round(image_matrix.e + image_matrix.a); 159 left = FXSYS_round(image_matrix.e + image_matrix.a);
160 } else { 160 } else {
161 left = FXSYS_round(image_matrix.e); 161 left = FXSYS_round(image_matrix.e);
162 } 162 }
163 } else { 163 } else {
164 } 164 }
165 } 165 }
166 if (pResBitmap == NULL) { 166 if (!pResBitmap) {
167 image_matrix.Scale(retinaScaleX, retinaScaleY); 167 image_matrix.Scale(retinaScaleX, retinaScaleY);
168 pResBitmap = pBitmap->TransformTo(&image_matrix, left, top); 168 pResBitmap = pBitmap->TransformTo(&image_matrix, left, top);
169 } 169 }
170 if (pResBitmap == NULL) { 170 if (!pResBitmap) {
171 return NULL; 171 return NULL;
172 } 172 }
173 CFX_GlyphBitmap* pGlyph = new CFX_GlyphBitmap; 173 CFX_GlyphBitmap* pGlyph = new CFX_GlyphBitmap;
174 pGlyph->m_Left = left; 174 pGlyph->m_Left = left;
175 pGlyph->m_Top = -top; 175 pGlyph->m_Top = -top;
176 pGlyph->m_Bitmap.TakeOver(pResBitmap); 176 pGlyph->m_Bitmap.TakeOver(pResBitmap);
177 delete pResBitmap; 177 delete pResBitmap;
178 return pGlyph; 178 return pGlyph;
179 } 179 }
180 void _CPDF_UniqueKeyGen::Generate(int count, ...) { 180 void _CPDF_UniqueKeyGen::Generate(int count, ...) {
(...skipping 24 matching lines...) Expand all
205 if (pClippingPath) { 205 if (pClippingPath) {
206 bClip = TRUE; 206 bClip = TRUE;
207 } else { 207 } else {
208 switch (text_render_mode) { 208 switch (text_render_mode) {
209 case 0: 209 case 0:
210 case 4: 210 case 4:
211 bFill = TRUE; 211 bFill = TRUE;
212 break; 212 break;
213 case 1: 213 case 1:
214 case 5: 214 case 5:
215 if (pFont->GetFace() == NULL && 215 if (!pFont->GetFace() &&
216 !(pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) { 216 !(pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) {
217 bFill = TRUE; 217 bFill = TRUE;
218 } else { 218 } else {
219 bStroke = TRUE; 219 bStroke = TRUE;
220 } 220 }
221 break; 221 break;
222 case 2: 222 case 2:
223 case 6: 223 case 6:
224 if (pFont->GetFace() == NULL && 224 if (!pFont->GetFace() &&
225 !(pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) { 225 !(pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) {
226 bFill = TRUE; 226 bFill = TRUE;
227 } else { 227 } else {
228 bFill = bStroke = TRUE; 228 bFill = bStroke = TRUE;
229 } 229 }
230 break; 230 break;
231 case 3: 231 case 3:
232 case 7: 232 case 7:
233 return TRUE; 233 return TRUE;
234 default: 234 default:
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 m_pDevice, textobj->m_nChars, textobj->m_pCharCodes, 292 m_pDevice, textobj->m_nChars, textobj->m_pCharCodes,
293 textobj->m_pCharPos, pFont, font_size, &text_matrix, pDeviceMatrix, 293 textobj->m_pCharPos, pFont, font_size, &text_matrix, pDeviceMatrix,
294 textobj->m_GraphState, fill_argb, stroke_argb, pClippingPath, flag); 294 textobj->m_GraphState, fill_argb, stroke_argb, pClippingPath, flag);
295 } 295 }
296 text_matrix.Concat(*pObj2Device); 296 text_matrix.Concat(*pObj2Device);
297 return CPDF_TextRenderer::DrawNormalText( 297 return CPDF_TextRenderer::DrawNormalText(
298 m_pDevice, textobj->m_nChars, textobj->m_pCharCodes, textobj->m_pCharPos, 298 m_pDevice, textobj->m_nChars, textobj->m_pCharCodes, textobj->m_pCharPos,
299 pFont, font_size, &text_matrix, fill_argb, &m_Options); 299 pFont, font_size, &text_matrix, fill_argb, &m_Options);
300 } 300 }
301 CPDF_Type3Cache* CPDF_RenderStatus::GetCachedType3(CPDF_Type3Font* pFont) { 301 CPDF_Type3Cache* CPDF_RenderStatus::GetCachedType3(CPDF_Type3Font* pFont) {
302 if (pFont->m_pDocument == NULL) { 302 if (!pFont->m_pDocument) {
303 return NULL; 303 return NULL;
304 } 304 }
305 pFont->m_pDocument->GetPageData()->GetFont(pFont->GetFontDict(), FALSE); 305 pFont->m_pDocument->GetPageData()->GetFont(pFont->GetFontDict(), FALSE);
306 return pFont->m_pDocument->GetRenderData()->GetCachedType3(pFont); 306 return pFont->m_pDocument->GetRenderData()->GetCachedType3(pFont);
307 } 307 }
308 static void ReleaseCachedType3(CPDF_Type3Font* pFont) { 308 static void ReleaseCachedType3(CPDF_Type3Font* pFont) {
309 if (pFont->m_pDocument == NULL) { 309 if (!pFont->m_pDocument) {
310 return; 310 return;
311 } 311 }
312 pFont->m_pDocument->GetRenderData()->ReleaseCachedType3(pFont); 312 pFont->m_pDocument->GetRenderData()->ReleaseCachedType3(pFont);
313 pFont->m_pDocument->GetPageData()->ReleaseFont(pFont->GetFontDict()); 313 pFont->m_pDocument->GetPageData()->ReleaseFont(pFont->GetFontDict());
314 } 314 }
315 FX_BOOL CPDF_Type3Char::LoadBitmap(CPDF_RenderContext* pContext) { 315 FX_BOOL CPDF_Type3Char::LoadBitmap(CPDF_RenderContext* pContext) {
316 if (m_pBitmap || m_pForm == NULL) { 316 if (m_pBitmap || !m_pForm) {
317 return TRUE; 317 return TRUE;
318 } 318 }
319 if (m_pForm->CountObjects() == 1 && !m_bColored) { 319 if (m_pForm->CountObjects() == 1 && !m_bColored) {
320 CPDF_PageObject* pPageObj = 320 CPDF_PageObject* pPageObj =
321 m_pForm->GetObjectAt(m_pForm->GetFirstObjectPosition()); 321 m_pForm->GetObjectAt(m_pForm->GetFirstObjectPosition());
322 if (pPageObj->m_Type == PDFPAGE_IMAGE) { 322 if (pPageObj->m_Type == PDFPAGE_IMAGE) {
323 CPDF_ImageObject* pImage = (CPDF_ImageObject*)pPageObj; 323 CPDF_ImageObject* pImage = (CPDF_ImageObject*)pPageObj;
324 m_ImageMatrix = pImage->m_Matrix; 324 m_ImageMatrix = pImage->m_Matrix;
325 const CFX_DIBSource* pSource = pImage->m_pImage->LoadDIBSource(); 325 const CFX_DIBSource* pSource = pImage->m_pImage->LoadDIBSource();
326 if (pSource) { 326 if (pSource) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 FX_DWORD* pChars = textobj->m_pCharCodes; 376 FX_DWORD* pChars = textobj->m_pCharCodes;
377 if (textobj->m_nChars == 1) { 377 if (textobj->m_nChars == 1) {
378 pChars = (FX_DWORD*)(&textobj->m_pCharCodes); 378 pChars = (FX_DWORD*)(&textobj->m_pCharCodes);
379 } 379 }
380 for (int iChar = 0; iChar < textobj->m_nChars; iChar++) { 380 for (int iChar = 0; iChar < textobj->m_nChars; iChar++) {
381 FX_DWORD charcode = pChars[iChar]; 381 FX_DWORD charcode = pChars[iChar];
382 if (charcode == (FX_DWORD)-1) { 382 if (charcode == (FX_DWORD)-1) {
383 continue; 383 continue;
384 } 384 }
385 CPDF_Type3Char* pType3Char = pType3Font->LoadChar(charcode); 385 CPDF_Type3Char* pType3Char = pType3Font->LoadChar(charcode);
386 if (pType3Char == NULL) { 386 if (!pType3Char) {
387 continue; 387 continue;
388 } 388 }
389 CFX_Matrix matrix = char_matrix; 389 CFX_Matrix matrix = char_matrix;
390 matrix.e += iChar ? textobj->m_pCharPos[iChar - 1] : 0; 390 matrix.e += iChar ? textobj->m_pCharPos[iChar - 1] : 0;
391 matrix.Concat(text_matrix); 391 matrix.Concat(text_matrix);
392 matrix.Concat(*pObj2Device); 392 matrix.Concat(*pObj2Device);
393 if (!pType3Char->LoadBitmap(m_pContext)) { 393 if (!pType3Char->LoadBitmap(m_pContext)) {
394 if (pGlyphAndPos) { 394 if (pGlyphAndPos) {
395 for (int i = 0; i < iChar; i++) { 395 for (int i = 0; i < iChar; i++) {
396 FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[i]; 396 FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[i];
397 if (glyph.m_pGlyph == NULL) { 397 if (!glyph.m_pGlyph) {
398 continue; 398 continue;
399 } 399 }
400 m_pDevice->SetBitMask(&glyph.m_pGlyph->m_Bitmap, 400 m_pDevice->SetBitMask(&glyph.m_pGlyph->m_Bitmap,
401 glyph.m_OriginX + glyph.m_pGlyph->m_Left, 401 glyph.m_OriginX + glyph.m_pGlyph->m_Left,
402 glyph.m_OriginY - glyph.m_pGlyph->m_Top, 402 glyph.m_OriginY - glyph.m_pGlyph->m_Top,
403 fill_argb); 403 fill_argb);
404 } 404 }
405 FX_Free(pGlyphAndPos); 405 FX_Free(pGlyphAndPos);
406 pGlyphAndPos = NULL; 406 pGlyphAndPos = NULL;
407 } 407 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 matrix.Scale(sa, sd); 445 matrix.Scale(sa, sd);
446 status.RenderObjectList(pType3Char->m_pForm, &matrix); 446 status.RenderObjectList(pType3Char->m_pForm, &matrix);
447 m_pDevice->SetDIBits(bitmap_device.GetBitmap(), rect.left, rect.top); 447 m_pDevice->SetDIBits(bitmap_device.GetBitmap(), rect.left, rect.top);
448 } 448 }
449 delete pStates; 449 delete pStates;
450 } else if (pType3Char->m_pBitmap) { 450 } else if (pType3Char->m_pBitmap) {
451 if (device_class == FXDC_DISPLAY) { 451 if (device_class == FXDC_DISPLAY) {
452 CPDF_Type3Cache* pCache = GetCachedType3(pType3Font); 452 CPDF_Type3Cache* pCache = GetCachedType3(pType3Font);
453 refTypeCache.m_dwCount++; 453 refTypeCache.m_dwCount++;
454 CFX_GlyphBitmap* pBitmap = pCache->LoadGlyph(charcode, &matrix, sa, sd); 454 CFX_GlyphBitmap* pBitmap = pCache->LoadGlyph(charcode, &matrix, sa, sd);
455 if (pBitmap == NULL) { 455 if (!pBitmap) {
456 continue; 456 continue;
457 } 457 }
458 int origin_x = FXSYS_round(matrix.e); 458 int origin_x = FXSYS_round(matrix.e);
459 int origin_y = FXSYS_round(matrix.f); 459 int origin_y = FXSYS_round(matrix.f);
460 if (pGlyphAndPos) { 460 if (pGlyphAndPos) {
461 pGlyphAndPos[iChar].m_pGlyph = pBitmap; 461 pGlyphAndPos[iChar].m_pGlyph = pBitmap;
462 pGlyphAndPos[iChar].m_OriginX = origin_x; 462 pGlyphAndPos[iChar].m_OriginX = origin_x;
463 pGlyphAndPos[iChar].m_OriginY = origin_y; 463 pGlyphAndPos[iChar].m_OriginY = origin_y;
464 } else { 464 } else {
465 m_pDevice->SetBitMask(&pBitmap->m_Bitmap, origin_x + pBitmap->m_Left, 465 m_pDevice->SetBitMask(&pBitmap->m_Bitmap, origin_x + pBitmap->m_Left,
(...skipping 18 matching lines...) Expand all
484 FXGE_GetGlyphsBBox(pGlyphAndPos, textobj->m_nChars, 0, sa, sd); 484 FXGE_GetGlyphsBBox(pGlyphAndPos, textobj->m_nChars, 0, sa, sd);
485 CFX_DIBitmap bitmap; 485 CFX_DIBitmap bitmap;
486 if (!bitmap.Create((int)(rect.Width() * sa), (int)(rect.Height() * sd), 486 if (!bitmap.Create((int)(rect.Width() * sa), (int)(rect.Height() * sd),
487 FXDIB_8bppMask)) { 487 FXDIB_8bppMask)) {
488 FX_Free(pGlyphAndPos); 488 FX_Free(pGlyphAndPos);
489 return TRUE; 489 return TRUE;
490 } 490 }
491 bitmap.Clear(0); 491 bitmap.Clear(0);
492 for (int iChar = 0; iChar < textobj->m_nChars; iChar++) { 492 for (int iChar = 0; iChar < textobj->m_nChars; iChar++) {
493 FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar]; 493 FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar];
494 if (glyph.m_pGlyph == NULL) { 494 if (!glyph.m_pGlyph) {
495 continue; 495 continue;
496 } 496 }
497 bitmap.TransferBitmap( 497 bitmap.TransferBitmap(
498 (int)((glyph.m_OriginX + glyph.m_pGlyph->m_Left - rect.left) * sa), 498 (int)((glyph.m_OriginX + glyph.m_pGlyph->m_Left - rect.left) * sa),
499 (int)((glyph.m_OriginY - glyph.m_pGlyph->m_Top - rect.top) * sd), 499 (int)((glyph.m_OriginY - glyph.m_pGlyph->m_Top - rect.top) * sd),
500 glyph.m_pGlyph->m_Bitmap.GetWidth(), 500 glyph.m_pGlyph->m_Bitmap.GetWidth(),
501 glyph.m_pGlyph->m_Bitmap.GetHeight(), &glyph.m_pGlyph->m_Bitmap, 0, 501 glyph.m_pGlyph->m_Bitmap.GetHeight(), &glyph.m_pGlyph->m_Bitmap, 0,
502 0); 502 0);
503 } 503 }
504 m_pDevice->SetBitMask(&bitmap, rect.left, rect.top, fill_argb); 504 m_pDevice->SetBitMask(&bitmap, rect.left, rect.top, fill_argb);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 charpos.m_ExtGID = pFont->GlyphFromCharCodeExt(CharCode); 550 charpos.m_ExtGID = pFont->GlyphFromCharCodeExt(CharCode);
551 #endif 551 #endif
552 if (!pFont->IsEmbedded() && pFont->GetFontType() != PDFFONT_CIDFONT) { 552 if (!pFont->IsEmbedded() && pFont->GetFontType() != PDFFONT_CIDFONT) {
553 charpos.m_FontCharWidth = pFont->GetCharWidthF(CharCode); 553 charpos.m_FontCharWidth = pFont->GetCharWidthF(CharCode);
554 } else { 554 } else {
555 charpos.m_FontCharWidth = 0; 555 charpos.m_FontCharWidth = 0;
556 } 556 }
557 charpos.m_OriginX = iChar ? pCharPos[iChar - 1] : 0; 557 charpos.m_OriginX = iChar ? pCharPos[iChar - 1] : 0;
558 charpos.m_OriginY = 0; 558 charpos.m_OriginY = 0;
559 charpos.m_bGlyphAdjust = FALSE; 559 charpos.m_bGlyphAdjust = FALSE;
560 if (pCIDFont == NULL) { 560 if (!pCIDFont) {
561 continue; 561 continue;
562 } 562 }
563 FX_WORD CID = pCIDFont->CIDFromCharCode(CharCode); 563 FX_WORD CID = pCIDFont->CIDFromCharCode(CharCode);
564 if (bVertWriting) { 564 if (bVertWriting) {
565 charpos.m_OriginY = charpos.m_OriginX; 565 charpos.m_OriginY = charpos.m_OriginX;
566 charpos.m_OriginX = 0; 566 charpos.m_OriginX = 0;
567 short vx, vy; 567 short vx, vy;
568 pCIDFont->GetVertOrigin(CID, vx, vy); 568 pCIDFont->GetVertOrigin(CID, vx, vy);
569 charpos.m_OriginX -= FontSize * vx / 1000; 569 charpos.m_OriginX -= FontSize * vx / 1000;
570 charpos.m_OriginY -= FontSize * vy / 1000; 570 charpos.m_OriginY -= FontSize * vy / 1000;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 } 755 }
756 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(&pFont->m_Font); 756 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(&pFont->m_Font);
757 FX_FONTCACHE_DEFINE(pCache, &pFont->m_Font); 757 FX_FONTCACHE_DEFINE(pCache, &pFont->m_Font);
758 CPDF_CharPosList CharPosList; 758 CPDF_CharPosList CharPosList;
759 CharPosList.Load(textobj->m_nChars, textobj->m_pCharCodes, 759 CharPosList.Load(textobj->m_nChars, textobj->m_pCharCodes,
760 textobj->m_pCharPos, pFont, font_size); 760 textobj->m_pCharPos, pFont, font_size);
761 for (FX_DWORD i = 0; i < CharPosList.m_nChars; i++) { 761 for (FX_DWORD i = 0; i < CharPosList.m_nChars; i++) {
762 FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i]; 762 FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i];
763 const CFX_PathData* pPath = pFaceCache->LoadGlyphPath( 763 const CFX_PathData* pPath = pFaceCache->LoadGlyphPath(
764 &pFont->m_Font, charpos.m_GlyphIndex, charpos.m_FontCharWidth); 764 &pFont->m_Font, charpos.m_GlyphIndex, charpos.m_FontCharWidth);
765 if (pPath == NULL) { 765 if (!pPath) {
766 continue; 766 continue;
767 } 767 }
768 CPDF_PathObject path; 768 CPDF_PathObject path;
769 path.m_GraphState = textobj->m_GraphState; 769 path.m_GraphState = textobj->m_GraphState;
770 path.m_ColorState = textobj->m_ColorState; 770 path.m_ColorState = textobj->m_ColorState;
771 CFX_Matrix matrix; 771 CFX_Matrix matrix;
772 if (charpos.m_bGlyphAdjust) 772 if (charpos.m_bGlyphAdjust)
773 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], 773 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1],
774 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); 774 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0);
775 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, 775 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX,
776 charpos.m_OriginY); 776 charpos.m_OriginY);
777 path.m_Path.New()->Append(pPath, &matrix); 777 path.m_Path.New()->Append(pPath, &matrix);
778 path.m_Matrix = *pTextMatrix; 778 path.m_Matrix = *pTextMatrix;
779 path.m_bStroke = bStroke; 779 path.m_bStroke = bStroke;
780 path.m_FillType = bFill ? FXFILL_WINDING : 0; 780 path.m_FillType = bFill ? FXFILL_WINDING : 0;
781 path.CalcBoundingBox(); 781 path.CalcBoundingBox();
782 ProcessPath(&path, pObj2Device); 782 ProcessPath(&path, pObj2Device);
783 } 783 }
784 } 784 }
785 785
786 CFX_PathData* CPDF_Font::LoadGlyphPath(FX_DWORD charcode, int dest_width) { 786 CFX_PathData* CPDF_Font::LoadGlyphPath(FX_DWORD charcode, int dest_width) {
787 int glyph_index = GlyphFromCharCode(charcode); 787 int glyph_index = GlyphFromCharCode(charcode);
788 if (!m_Font.GetFace()) 788 if (!m_Font.GetFace())
789 return nullptr; 789 return nullptr;
790 return m_Font.LoadGlyphPath(glyph_index, dest_width); 790 return m_Font.LoadGlyphPath(glyph_index, dest_width);
791 } 791 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp ('k') | core/src/fpdfdoc/doc_action.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698