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

Side by Side Diff: core/fpdfapi/fpdf_font/cpdf_font.cpp

Issue 2364643003: Make CPDF_Font::Create() return a std::unique_ptr. (Closed)
Patch Set: Stray file Created 4 years, 3 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 | « no previous file | core/fpdfapi/fpdf_font/font_int.h » ('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 2016 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/fpdf_font/include/cpdf_font.h" 7 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 uint32_t charcode = GetNextChar(pString, size, offset); 292 uint32_t charcode = GetNextChar(pString, size, offset);
293 width += GetCharWidthF(charcode); 293 width += GetCharWidthF(charcode);
294 } 294 }
295 return width; 295 return width;
296 } 296 }
297 297
298 CPDF_Font* CPDF_Font::GetStockFont(CPDF_Document* pDoc, 298 CPDF_Font* CPDF_Font::GetStockFont(CPDF_Document* pDoc,
299 const CFX_ByteStringC& name) { 299 const CFX_ByteStringC& name) {
300 CFX_ByteString fontname(name); 300 CFX_ByteString fontname(name);
301 int font_id = PDF_GetStandardFontName(&fontname); 301 int font_id = PDF_GetStandardFontName(&fontname);
302 if (font_id < 0) { 302 if (font_id < 0)
303 return nullptr; 303 return nullptr;
304 } 304
305 CPDF_FontGlobals* pFontGlobals = 305 CPDF_FontGlobals* pFontGlobals =
306 CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals(); 306 CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
307 CPDF_Font* pFont = pFontGlobals->Find(pDoc, font_id); 307 CPDF_Font* pFont = pFontGlobals->Find(pDoc, font_id);
308 if (pFont) { 308 if (pFont)
309 return pFont; 309 return pFont;
310 } 310
311 CPDF_Dictionary* pDict = new CPDF_Dictionary; 311 CPDF_Dictionary* pDict = new CPDF_Dictionary;
312 pDict->SetNameFor("Type", "Font"); 312 pDict->SetNameFor("Type", "Font");
313 pDict->SetNameFor("Subtype", "Type1"); 313 pDict->SetNameFor("Subtype", "Type1");
314 pDict->SetNameFor("BaseFont", fontname); 314 pDict->SetNameFor("BaseFont", fontname);
315 pDict->SetNameFor("Encoding", "WinAnsiEncoding"); 315 pDict->SetNameFor("Encoding", "WinAnsiEncoding");
316 pFont = CPDF_Font::CreateFontF(nullptr, pDict); 316 return pFontGlobals->Set(pDoc, font_id, CPDF_Font::Create(nullptr, pDict));
317 pFontGlobals->Set(pDoc, font_id, pFont);
318 return pFont;
319 } 317 }
320 318
321 CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc, 319 std::unique_ptr<CPDF_Font> CPDF_Font::Create(CPDF_Document* pDoc,
322 CPDF_Dictionary* pFontDict) { 320 CPDF_Dictionary* pFontDict) {
323 CFX_ByteString type = pFontDict->GetStringFor("Subtype"); 321 CFX_ByteString type = pFontDict->GetStringFor("Subtype");
324 std::unique_ptr<CPDF_Font> pFont; 322 std::unique_ptr<CPDF_Font> pFont;
325 if (type == "TrueType") { 323 if (type == "TrueType") {
326 CFX_ByteString tag = pFontDict->GetStringFor("BaseFont").Left(4); 324 CFX_ByteString tag = pFontDict->GetStringFor("BaseFont").Left(4);
327 for (size_t i = 0; i < FX_ArraySize(kChineseFontNames); ++i) { 325 for (size_t i = 0; i < FX_ArraySize(kChineseFontNames); ++i) {
328 if (tag == CFX_ByteString(kChineseFontNames[i], 4)) { 326 if (tag == CFX_ByteString(kChineseFontNames[i], 4)) {
329 CPDF_Dictionary* pFontDesc = pFontDict->GetDictFor("FontDescriptor"); 327 CPDF_Dictionary* pFontDesc = pFontDict->GetDictFor("FontDescriptor");
330 if (!pFontDesc || !pFontDesc->KeyExist("FontFile2")) 328 if (!pFontDesc || !pFontDesc->KeyExist("FontFile2"))
331 pFont.reset(new CPDF_CIDFont); 329 pFont.reset(new CPDF_CIDFont);
332 break; 330 break;
333 } 331 }
334 } 332 }
335 if (!pFont) 333 if (!pFont)
336 pFont.reset(new CPDF_TrueTypeFont); 334 pFont.reset(new CPDF_TrueTypeFont);
337 } else if (type == "Type3") { 335 } else if (type == "Type3") {
338 pFont.reset(new CPDF_Type3Font); 336 pFont.reset(new CPDF_Type3Font);
339 } else if (type == "Type0") { 337 } else if (type == "Type0") {
340 pFont.reset(new CPDF_CIDFont); 338 pFont.reset(new CPDF_CIDFont);
341 } else { 339 } else {
342 pFont.reset(new CPDF_Type1Font); 340 pFont.reset(new CPDF_Type1Font);
343 } 341 }
344 pFont->m_pFontDict = pFontDict; 342 pFont->m_pFontDict = pFontDict;
345 pFont->m_pDocument = pDoc; 343 pFont->m_pDocument = pDoc;
346 pFont->m_BaseFont = pFontDict->GetStringFor("BaseFont"); 344 pFont->m_BaseFont = pFontDict->GetStringFor("BaseFont");
347 return pFont->Load() ? pFont.release() : nullptr; 345 return pFont->Load() ? std::move(pFont) : std::unique_ptr<CPDF_Font>();
348 } 346 }
349 347
350 uint32_t CPDF_Font::GetNextChar(const FX_CHAR* pString, 348 uint32_t CPDF_Font::GetNextChar(const FX_CHAR* pString,
351 int nStrLen, 349 int nStrLen,
352 int& offset) const { 350 int& offset) const {
353 if (offset < 0 || nStrLen < 1) { 351 if (offset < 0 || nStrLen < 1) {
354 return 0; 352 return 0;
355 } 353 }
356 uint8_t ch = offset < nStrLen ? pString[offset++] : pString[nStrLen - 1]; 354 uint8_t ch = offset < nStrLen ? pString[offset++] : pString[nStrLen - 1];
357 return static_cast<uint32_t>(ch); 355 return static_cast<uint32_t>(ch);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 if (fallbackFont < 0 || 466 if (fallbackFont < 0 ||
469 fallbackFont >= pdfium::CollectionSize<int>(m_FontFallbacks)) { 467 fallbackFont >= pdfium::CollectionSize<int>(m_FontFallbacks)) {
470 return -1; 468 return -1;
471 } 469 }
472 int glyph = 470 int glyph =
473 FXFT_Get_Char_Index(m_FontFallbacks[fallbackFont]->GetFace(), charcode); 471 FXFT_Get_Char_Index(m_FontFallbacks[fallbackFont]->GetFace(), charcode);
474 if (glyph == 0 || glyph == 0xffff) 472 if (glyph == 0 || glyph == 0xffff)
475 return -1; 473 return -1;
476 return glyph; 474 return glyph;
477 } 475 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_font/font_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698