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

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

Issue 2276653002: Add fallback fonts in pdfium (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Address comments Created 4 years, 4 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
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>
11 11
12 #include "core/fpdfapi/fpdf_font/cpdf_truetypefont.h" 12 #include "core/fpdfapi/fpdf_font/cpdf_truetypefont.h"
13 #include "core/fpdfapi/fpdf_font/cpdf_type1font.h" 13 #include "core/fpdfapi/fpdf_font/cpdf_type1font.h"
14 #include "core/fpdfapi/fpdf_font/cpdf_type3font.h" 14 #include "core/fpdfapi/fpdf_font/cpdf_type3font.h"
15 #include "core/fpdfapi/fpdf_font/font_int.h" 15 #include "core/fpdfapi/fpdf_font/font_int.h"
16 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" 16 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h"
17 #include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h" 17 #include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h"
18 #include "core/fpdfapi/fpdf_page/pageint.h" 18 #include "core/fpdfapi/fpdf_page/pageint.h"
19 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 19 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
20 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 20 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
21 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 21 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
22 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" 22 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h"
23 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" 23 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h"
24 #include "core/fpdfapi/include/cpdf_modulemgr.h" 24 #include "core/fpdfapi/include/cpdf_modulemgr.h"
25 #include "core/fxcrt/include/fx_memory.h"
25 #include "core/fxge/include/fx_freetype.h" 26 #include "core/fxge/include/fx_freetype.h"
26 27
27 namespace { 28 namespace {
28 29
29 const uint8_t kChineseFontNames[][5] = {{0xCB, 0xCE, 0xCC, 0xE5, 0x00}, 30 const uint8_t kChineseFontNames[][5] = {{0xCB, 0xCE, 0xCC, 0xE5, 0x00},
30 {0xBF, 0xAC, 0xCC, 0xE5, 0x00}, 31 {0xBF, 0xAC, 0xCC, 0xE5, 0x00},
31 {0xBA, 0xDA, 0xCC, 0xE5, 0x00}, 32 {0xBA, 0xDA, 0xCC, 0xE5, 0x00},
32 {0xB7, 0xC2, 0xCB, 0xCE, 0x00}, 33 {0xB7, 0xC2, 0xCB, 0xCE, 0x00},
33 {0xD0, 0xC2, 0xCB, 0xCE, 0x00}}; 34 {0xD0, 0xC2, 0xCB, 0xCE, 0x00}};
34 35
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 } 445 }
445 446
446 if (!charnames.empty() && !charnames[charcode].IsEmpty()) 447 if (!charnames.empty() && !charnames[charcode].IsEmpty())
447 return charnames[charcode].c_str(); 448 return charnames[charcode].c_str();
448 449
449 const FX_CHAR* name = nullptr; 450 const FX_CHAR* name = nullptr;
450 if (iBaseEncoding) 451 if (iBaseEncoding)
451 name = PDF_CharNameFromPredefinedCharSet(iBaseEncoding, charcode); 452 name = PDF_CharNameFromPredefinedCharSet(iBaseEncoding, charcode);
452 return name && name[0] ? name : nullptr; 453 return name && name[0] ? name : nullptr;
453 } 454 }
455
456 uint32_t CPDF_Font::FallbackFontFromCharcode(uint32_t charcode,
457 bool* pVertGlyph) {
458 if (m_FontFallbacks.empty()) {
459 m_FontFallbacks.push_back(WrapUnique(new CFX_Font()));
460 m_FontFallbacks[0]->LoadSubst("Arial", IsTrueTypeFont(), m_Flags,
461 m_StemV * 5, m_ItalicAngle, 0,
462 IsVertWriting());
463 }
464 return 0;
465 }
466
467 int CPDF_Font::FallbackGlyphFromCharcode(int fallbackFont,
468 uint32_t charcode,
469 bool* pVertGlyph) {
470 if (fallbackFont < 0 ||
471 fallbackFont >= static_cast<int>(m_FontFallbacks.size())) {
Tom Sepez 2016/08/24 16:23:49 nit: pdfium::CollectionSize<int>(m_FontFallbacks)
npm 2016/08/24 17:47:15 Done.
472 return -1;
473 }
474 int glyph =
475 FXFT_Get_Char_Index(m_FontFallbacks[fallbackFont]->GetFace(), charcode);
476 if (glyph == 0 || glyph == 0xffff)
477 return -1;
478 return glyph;
479 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_font/include/cpdf_font.h » ('j') | core/fpdfapi/fpdf_render/fpdf_render_text.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698