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

Side by Side Diff: core/src/fxge/ge/fx_ge_fontmap.cpp

Issue 1145843005: Revert "Remove FX_Alloc() null checks now that it can't return NULL." (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 7 months 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/fxge/ge/fx_ge_font.cpp ('k') | core/src/fxge/ge/fx_ge_path.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 "../../../include/fxge/fx_ge.h" 7 #include "../../../include/fxge/fx_ge.h"
8 #include "../../../include/fxge/fx_freetype.h" 8 #include "../../../include/fxge/fx_freetype.h"
9 #include "text_int.h" 9 #include "text_int.h"
10 #define GET_TT_SHORT(w) (FX_WORD)(((w)[0] << 8) | (w)[1]) 10 #define GET_TT_SHORT(w) (FX_WORD)(((w)[0] << 8) | (w)[1])
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 } 557 }
558 CFX_ByteString CFX_FontMapper::GetPSNameFromTT(void* hFont) 558 CFX_ByteString CFX_FontMapper::GetPSNameFromTT(void* hFont)
559 { 559 {
560 if (m_pFontInfo == NULL) { 560 if (m_pFontInfo == NULL) {
561 CFX_ByteString(); 561 CFX_ByteString();
562 } 562 }
563 CFX_ByteString result; 563 CFX_ByteString result;
564 FX_DWORD size = m_pFontInfo->GetFontData(hFont, 0x6e616d65, NULL, 0); 564 FX_DWORD size = m_pFontInfo->GetFontData(hFont, 0x6e616d65, NULL, 0);
565 if (size) { 565 if (size) {
566 FX_LPBYTE buffer = FX_Alloc(FX_BYTE, size); 566 FX_LPBYTE buffer = FX_Alloc(FX_BYTE, size);
567 if (!buffer) {
568 return result;
569 }
567 m_pFontInfo->GetFontData(hFont, 0x6e616d65, buffer, size); 570 m_pFontInfo->GetFontData(hFont, 0x6e616d65, buffer, size);
568 result = _FPDF_GetNameFromTT(buffer, 6); 571 result = _FPDF_GetNameFromTT(buffer, 6);
569 FX_Free(buffer); 572 FX_Free(buffer);
570 } 573 }
571 return result; 574 return result;
572 } 575 }
573 void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) 576 void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset)
574 { 577 {
575 if (m_pFontInfo == NULL) { 578 if (m_pFontInfo == NULL) {
576 return; 579 return;
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 FX_BYTE temp[1024]; 1202 FX_BYTE temp[1024];
1200 m_pFontInfo->GetFontData(hFont, 0x74746366, temp, 1024); 1203 m_pFontInfo->GetFontData(hFont, 0x74746366, temp, 1024);
1201 FX_DWORD checksum = 0; 1204 FX_DWORD checksum = 0;
1202 for (int i = 0; i < 256; i ++) { 1205 for (int i = 0; i < 256; i ++) {
1203 checksum += ((FX_DWORD*)temp)[i]; 1206 checksum += ((FX_DWORD*)temp)[i];
1204 } 1207 }
1205 FX_LPBYTE pFontData; 1208 FX_LPBYTE pFontData;
1206 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, ttc_size - font_ size, pFontData); 1209 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, ttc_size - font_ size, pFontData);
1207 if (face == NULL) { 1210 if (face == NULL) {
1208 pFontData = FX_Alloc(FX_BYTE, ttc_size); 1211 pFontData = FX_Alloc(FX_BYTE, ttc_size);
1209 m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size); 1212 if (pFontData) {
1210 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, t tc_size, 1213 m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size) ;
1211 ttc_size - font_size); 1214 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontDat a, ttc_size,
1215 ttc_size - font_size);
1216 }
1212 } 1217 }
1213 } else { 1218 } else {
1214 FX_LPBYTE pFontData; 1219 FX_LPBYTE pFontData;
1215 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData); 1220 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData);
1216 if (face == NULL) { 1221 if (face == NULL) {
1217 pFontData = FX_Alloc(FX_BYTE, font_size); 1222 pFontData = FX_Alloc(FX_BYTE, font_size);
1223 if (!pFontData) {
1224 m_pFontInfo->DeleteFont(hFont);
1225 return NULL;
1226 }
1218 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size); 1227 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size);
1219 face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontDa ta, font_size, m_pFontInfo->GetFaceIndex(hFont)); 1228 face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontDa ta, font_size, m_pFontInfo->GetFaceIndex(hFont));
1220 } 1229 }
1221 } 1230 }
1222 if (face == NULL) { 1231 if (face == NULL) {
1223 m_pFontInfo->DeleteFont(hFont); 1232 m_pFontInfo->DeleteFont(hFont);
1224 return NULL; 1233 return NULL;
1225 } 1234 }
1226 pSubstFont->m_Family = SubstName; 1235 pSubstFont->m_Family = SubstName;
1227 pSubstFont->m_Charset = Charset; 1236 pSubstFont->m_Charset = Charset;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 } 1373 }
1365 1374
1366 if (GET_TT_LONG(buffer) == 0x74746366) { 1375 if (GET_TT_LONG(buffer) == 0x74746366) {
1367 FX_DWORD nFaces = GET_TT_LONG(buffer + 8); 1376 FX_DWORD nFaces = GET_TT_LONG(buffer + 8);
1368 if (nFaces > FX_DWORD_MAX / 4) { 1377 if (nFaces > FX_DWORD_MAX / 4) {
1369 FXSYS_fclose(pFile); 1378 FXSYS_fclose(pFile);
1370 return; 1379 return;
1371 } 1380 }
1372 FX_DWORD face_bytes = nFaces * 4; 1381 FX_DWORD face_bytes = nFaces * 4;
1373 FX_LPBYTE offsets = FX_Alloc(FX_BYTE, face_bytes); 1382 FX_LPBYTE offsets = FX_Alloc(FX_BYTE, face_bytes);
1383 if (!offsets) {
1384 FXSYS_fclose(pFile);
1385 return;
1386 }
1374 readCnt = FXSYS_fread(offsets, face_bytes, 1, pFile); 1387 readCnt = FXSYS_fread(offsets, face_bytes, 1, pFile);
1375 if (readCnt != face_bytes) { 1388 if (readCnt != face_bytes) {
1376 FX_Free(offsets); 1389 FX_Free(offsets);
1377 FXSYS_fclose(pFile); 1390 FXSYS_fclose(pFile);
1378 return; 1391 return;
1379 } 1392 }
1380 for (FX_DWORD i = 0; i < nFaces; i ++) { 1393 for (FX_DWORD i = 0; i < nFaces; i ++) {
1381 FX_LPBYTE p = offsets + i * 4; 1394 FX_LPBYTE p = offsets + i * 4;
1382 ReportFace(path, pFile, filesize, GET_TT_LONG(p)); 1395 ReportFace(path, pFile, filesize, GET_TT_LONG(p));
1383 } 1396 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 return FALSE; 1529 return FALSE;
1517 } 1530 }
1518 CFontFaceInfo* pFont = (CFontFaceInfo*)hFont; 1531 CFontFaceInfo* pFont = (CFontFaceInfo*)hFont;
1519 name = pFont->m_FaceName; 1532 name = pFont->m_FaceName;
1520 return TRUE; 1533 return TRUE;
1521 } 1534 }
1522 FX_BOOL CFX_FolderFontInfo::GetFontCharset(void* hFont, int& charset) 1535 FX_BOOL CFX_FolderFontInfo::GetFontCharset(void* hFont, int& charset)
1523 { 1536 {
1524 return FALSE; 1537 return FALSE;
1525 } 1538 }
OLDNEW
« no previous file with comments | « core/src/fxge/ge/fx_ge_font.cpp ('k') | core/src/fxge/ge/fx_ge_path.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698