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

Side by Side Diff: core/fxge/ge/cfx_fontmapper.cpp

Issue 2477443002: Remove FX_BOOL from core (Closed)
Patch Set: Created 4 years, 1 month 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/fxge/ge/cfx_font.cpp ('k') | core/fxge/ge/cfx_fontmgr.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 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/fxge/cfx_fontmapper.h" 7 #include "core/fxge/cfx_fontmapper.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 if (bsStyle.Right(pStyle->len).Compare(pStyle->style) == 0) 251 if (bsStyle.Right(pStyle->len).Compare(pStyle->style) == 0)
252 return i; 252 return i;
253 } else { 253 } else {
254 if (bsStyle.Left(pStyle->len).Compare(pStyle->style) == 0) 254 if (bsStyle.Left(pStyle->len).Compare(pStyle->style) == 0)
255 return i; 255 return i;
256 } 256 }
257 } 257 }
258 return -1; 258 return -1;
259 } 259 }
260 260
261 FX_BOOL CheckSupportThirdPartFont(CFX_ByteString name, int& PitchFamily) { 261 bool CheckSupportThirdPartFont(CFX_ByteString name, int& PitchFamily) {
262 if (name == "MyriadPro") { 262 if (name == "MyriadPro") {
263 PitchFamily &= ~FXFONT_FF_ROMAN; 263 PitchFamily &= ~FXFONT_FF_ROMAN;
264 return TRUE; 264 return true;
265 } 265 }
266 return FALSE; 266 return false;
267 } 267 }
268 268
269 void UpdatePitchFamily(uint32_t flags, int& PitchFamily) { 269 void UpdatePitchFamily(uint32_t flags, int& PitchFamily) {
270 if (flags & FXFONT_SERIF) 270 if (flags & FXFONT_SERIF)
271 PitchFamily |= FXFONT_FF_ROMAN; 271 PitchFamily |= FXFONT_FF_ROMAN;
272 if (flags & FXFONT_SCRIPT) 272 if (flags & FXFONT_SCRIPT)
273 PitchFamily |= FXFONT_FF_SCRIPT; 273 PitchFamily |= FXFONT_FF_SCRIPT;
274 if (flags & FXFONT_FIXED_PITCH) 274 if (flags & FXFONT_FIXED_PITCH)
275 PitchFamily |= FXFONT_FF_FIXEDPITCH; 275 PitchFamily |= FXFONT_FF_FIXEDPITCH;
276 } 276 }
277 277
278 } // namespace 278 } // namespace
279 279
280 CFX_FontMapper::CFX_FontMapper(CFX_FontMgr* mgr) 280 CFX_FontMapper::CFX_FontMapper(CFX_FontMgr* mgr)
281 : m_bListLoaded(FALSE), m_pFontMgr(mgr) { 281 : m_bListLoaded(false), m_pFontMgr(mgr) {
282 m_MMFaces[0] = nullptr; 282 m_MMFaces[0] = nullptr;
283 m_MMFaces[1] = nullptr; 283 m_MMFaces[1] = nullptr;
284 FXSYS_memset(m_FoxitFaces, 0, sizeof(m_FoxitFaces)); 284 FXSYS_memset(m_FoxitFaces, 0, sizeof(m_FoxitFaces));
285 } 285 }
286 286
287 CFX_FontMapper::~CFX_FontMapper() { 287 CFX_FontMapper::~CFX_FontMapper() {
288 for (size_t i = 0; i < FX_ArraySize(m_FoxitFaces); ++i) { 288 for (size_t i = 0; i < FX_ArraySize(m_FoxitFaces); ++i) {
289 if (m_FoxitFaces[i]) 289 if (m_FoxitFaces[i])
290 FXFT_Done_Face(m_FoxitFaces[i]); 290 FXFT_Done_Face(m_FoxitFaces[i]);
291 } 291 }
(...skipping 29 matching lines...) Expand all
321 321
322 void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) { 322 void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) {
323 if (!m_pFontInfo) 323 if (!m_pFontInfo)
324 return; 324 return;
325 325
326 m_FaceArray.push_back({name, static_cast<uint32_t>(charset)}); 326 m_FaceArray.push_back({name, static_cast<uint32_t>(charset)});
327 if (name == m_LastFamily) 327 if (name == m_LastFamily)
328 return; 328 return;
329 329
330 const uint8_t* ptr = name.raw_str(); 330 const uint8_t* ptr = name.raw_str();
331 FX_BOOL bLocalized = FALSE; 331 bool bLocalized = false;
332 for (int i = 0; i < name.GetLength(); i++) { 332 for (int i = 0; i < name.GetLength(); i++) {
333 if (ptr[i] > 0x80) { 333 if (ptr[i] > 0x80) {
334 bLocalized = TRUE; 334 bLocalized = true;
335 break; 335 break;
336 } 336 }
337 } 337 }
338 338
339 if (bLocalized) { 339 if (bLocalized) {
340 void* hFont = m_pFontInfo->GetFont(name.c_str()); 340 void* hFont = m_pFontInfo->GetFont(name.c_str());
341 if (!hFont) { 341 if (!hFont) {
342 int iExact; 342 int iExact;
343 hFont = m_pFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0, 343 hFont = m_pFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0,
344 name.c_str(), iExact); 344 name.c_str(), iExact);
345 if (!hFont) 345 if (!hFont)
346 return; 346 return;
347 } 347 }
348 348
349 CFX_ByteString new_name = GetPSNameFromTT(hFont); 349 CFX_ByteString new_name = GetPSNameFromTT(hFont);
350 if (!new_name.IsEmpty()) 350 if (!new_name.IsEmpty())
351 m_LocalizedTTFonts.push_back(std::make_pair(new_name, name)); 351 m_LocalizedTTFonts.push_back(std::make_pair(new_name, name));
352 m_pFontInfo->DeleteFont(hFont); 352 m_pFontInfo->DeleteFont(hFont);
353 } 353 }
354 m_InstalledTTFonts.push_back(name); 354 m_InstalledTTFonts.push_back(name);
355 m_LastFamily = name; 355 m_LastFamily = name;
356 } 356 }
357 357
358 void CFX_FontMapper::LoadInstalledFonts() { 358 void CFX_FontMapper::LoadInstalledFonts() {
359 if (!m_pFontInfo || m_bListLoaded) 359 if (!m_pFontInfo || m_bListLoaded)
360 return; 360 return;
361 361
362 m_pFontInfo->EnumFontList(this); 362 m_pFontInfo->EnumFontList(this);
363 m_bListLoaded = TRUE; 363 m_bListLoaded = true;
364 } 364 }
365 365
366 CFX_ByteString CFX_FontMapper::MatchInstalledFonts( 366 CFX_ByteString CFX_FontMapper::MatchInstalledFonts(
367 const CFX_ByteString& norm_name) { 367 const CFX_ByteString& norm_name) {
368 LoadInstalledFonts(); 368 LoadInstalledFonts();
369 int i; 369 int i;
370 for (i = pdfium::CollectionSize<int>(m_InstalledTTFonts) - 1; i >= 0; i--) { 370 for (i = pdfium::CollectionSize<int>(m_InstalledTTFonts) - 1; i >= 0; i--) {
371 CFX_ByteString norm1 = TT_NormalizeName(m_InstalledTTFonts[i].c_str()); 371 CFX_ByteString norm1 = TT_NormalizeName(m_InstalledTTFonts[i].c_str());
372 if (norm1 == norm_name) 372 if (norm1 == norm_name)
373 return m_InstalledTTFonts[i]; 373 return m_InstalledTTFonts[i];
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 if (m_MMFaces[0]) 415 if (m_MMFaces[0])
416 return m_MMFaces[0]; 416 return m_MMFaces[0];
417 const uint8_t* pFontData = nullptr; 417 const uint8_t* pFontData = nullptr;
418 uint32_t size = 0; 418 uint32_t size = 0;
419 m_pFontMgr->GetBuiltinFont(15, &pFontData, &size); 419 m_pFontMgr->GetBuiltinFont(15, &pFontData, &size);
420 m_MMFaces[0] = m_pFontMgr->GetFixedFace(pFontData, size, 0); 420 m_MMFaces[0] = m_pFontMgr->GetFixedFace(pFontData, size, 0);
421 return m_MMFaces[0]; 421 return m_MMFaces[0];
422 } 422 }
423 423
424 FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name, 424 FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
425 FX_BOOL bTrueType, 425 bool bTrueType,
426 uint32_t flags, 426 uint32_t flags,
427 int weight, 427 int weight,
428 int italic_angle, 428 int italic_angle,
429 int WindowCP, 429 int WindowCP,
430 CFX_SubstFont* pSubstFont) { 430 CFX_SubstFont* pSubstFont) {
431 if (!(flags & FXFONT_USEEXTERNATTR)) { 431 if (!(flags & FXFONT_USEEXTERNATTR)) {
432 weight = FXFONT_FW_NORMAL; 432 weight = FXFONT_FW_NORMAL;
433 italic_angle = 0; 433 italic_angle = 0;
434 } 434 }
435 CFX_ByteString SubstName = name; 435 CFX_ByteString SubstName = name;
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 } 707 }
708 708
709 #ifdef PDF_ENABLE_XFA 709 #ifdef PDF_ENABLE_XFA
710 FXFT_Face CFX_FontMapper::FindSubstFontByUnicode(uint32_t dwUnicode, 710 FXFT_Face CFX_FontMapper::FindSubstFontByUnicode(uint32_t dwUnicode,
711 uint32_t flags, 711 uint32_t flags,
712 int weight, 712 int weight,
713 int italic_angle) { 713 int italic_angle) {
714 if (!m_pFontInfo) 714 if (!m_pFontInfo)
715 return nullptr; 715 return nullptr;
716 716
717 FX_BOOL bItalic = (flags & FXFONT_ITALIC) != 0; 717 bool bItalic = (flags & FXFONT_ITALIC) != 0;
718 int PitchFamily = 0; 718 int PitchFamily = 0;
719 UpdatePitchFamily(flags, PitchFamily); 719 UpdatePitchFamily(flags, PitchFamily);
720 void* hFont = 720 void* hFont =
721 m_pFontInfo->MapFontByUnicode(dwUnicode, weight, bItalic, PitchFamily); 721 m_pFontInfo->MapFontByUnicode(dwUnicode, weight, bItalic, PitchFamily);
722 if (!hFont) 722 if (!hFont)
723 return nullptr; 723 return nullptr;
724 724
725 uint32_t ttc_size = m_pFontInfo->GetFontData(hFont, 0x74746366, nullptr, 0); 725 uint32_t ttc_size = m_pFontInfo->GetFontData(hFont, 0x74746366, nullptr, 0);
726 uint32_t font_size = m_pFontInfo->GetFontData(hFont, 0, nullptr, 0); 726 uint32_t font_size = m_pFontInfo->GetFontData(hFont, 0, nullptr, 0);
727 if (font_size == 0 && ttc_size == 0) { 727 if (font_size == 0 && ttc_size == 0) {
(...skipping 10 matching lines...) Expand all
738 } 738 }
739 m_pFontInfo->DeleteFont(hFont); 739 m_pFontInfo->DeleteFont(hFont);
740 return face; 740 return face;
741 } 741 }
742 #endif // PDF_ENABLE_XFA 742 #endif // PDF_ENABLE_XFA
743 743
744 int CFX_FontMapper::GetFaceSize() const { 744 int CFX_FontMapper::GetFaceSize() const {
745 return pdfium::CollectionSize<int>(m_FaceArray); 745 return pdfium::CollectionSize<int>(m_FaceArray);
746 } 746 }
747 747
748 FX_BOOL CFX_FontMapper::IsBuiltinFace(const FXFT_Face face) const { 748 bool CFX_FontMapper::IsBuiltinFace(const FXFT_Face face) const {
749 for (size_t i = 0; i < MM_FACE_COUNT; ++i) { 749 for (size_t i = 0; i < MM_FACE_COUNT; ++i) {
750 if (m_MMFaces[i] == face) 750 if (m_MMFaces[i] == face)
751 return TRUE; 751 return true;
752 } 752 }
753 for (size_t i = 0; i < FOXIT_FACE_COUNT; ++i) { 753 for (size_t i = 0; i < FOXIT_FACE_COUNT; ++i) {
754 if (m_FoxitFaces[i] == face) 754 if (m_FoxitFaces[i] == face)
755 return TRUE; 755 return true;
756 } 756 }
757 return FALSE; 757 return false;
758 } 758 }
759 759
760 FXFT_Face CFX_FontMapper::GetCachedTTCFace(void* hFont, 760 FXFT_Face CFX_FontMapper::GetCachedTTCFace(void* hFont,
761 const uint32_t tableTTCF, 761 const uint32_t tableTTCF,
762 uint32_t ttc_size, 762 uint32_t ttc_size,
763 uint32_t font_size) { 763 uint32_t font_size) {
764 FXFT_Face face; 764 FXFT_Face face;
765 uint8_t buffer[1024]; 765 uint8_t buffer[1024];
766 m_pFontInfo->GetFontData(hFont, tableTTCF, buffer, FX_ArraySize(buffer)); 766 m_pFontInfo->GetFontData(hFont, tableTTCF, buffer, FX_ArraySize(buffer));
767 uint32_t* pBuffer = reinterpret_cast<uint32_t*>(buffer); 767 uint32_t* pBuffer = reinterpret_cast<uint32_t*>(buffer);
768 uint32_t checksum = 0; 768 uint32_t checksum = 0;
769 for (int i = 0; i < 256; i++) 769 for (int i = 0; i < 256; i++)
770 checksum += pBuffer[i]; 770 checksum += pBuffer[i];
771 uint8_t* pFontData; 771 uint8_t* pFontData;
772 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, ttc_size - font_size, 772 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, ttc_size - font_size,
773 pFontData); 773 pFontData);
774 if (!face) { 774 if (!face) {
775 pFontData = FX_Alloc(uint8_t, ttc_size); 775 pFontData = FX_Alloc(uint8_t, ttc_size);
776 m_pFontInfo->GetFontData(hFont, tableTTCF, pFontData, ttc_size); 776 m_pFontInfo->GetFontData(hFont, tableTTCF, pFontData, ttc_size);
777 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, ttc_size, 777 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, ttc_size,
778 ttc_size - font_size); 778 ttc_size - font_size);
779 } 779 }
780 return face; 780 return face;
781 } 781 }
782 782
783 FXFT_Face CFX_FontMapper::GetCachedFace(void* hFont, 783 FXFT_Face CFX_FontMapper::GetCachedFace(void* hFont,
784 CFX_ByteString SubstName, 784 CFX_ByteString SubstName,
785 int weight, 785 int weight,
786 FX_BOOL bItalic, 786 bool bItalic,
787 uint32_t font_size) { 787 uint32_t font_size) {
788 FXFT_Face face; 788 FXFT_Face face;
789 uint8_t* pFontData; 789 uint8_t* pFontData;
790 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData); 790 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData);
791 if (!face) { 791 if (!face) {
792 pFontData = FX_Alloc(uint8_t, font_size); 792 pFontData = FX_Alloc(uint8_t, font_size);
793 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size); 793 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size);
794 face = 794 face =
795 m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontData, 795 m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontData,
796 font_size, m_pFontInfo->GetFaceIndex(hFont)); 796 font_size, m_pFontInfo->GetFaceIndex(hFont));
797 } 797 }
798 return face; 798 return face;
799 } 799 }
800 800
801 int PDF_GetStandardFontName(CFX_ByteString* name) { 801 int PDF_GetStandardFontName(CFX_ByteString* name) {
802 AltFontName* found = static_cast<AltFontName*>( 802 AltFontName* found = static_cast<AltFontName*>(
803 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), 803 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames),
804 sizeof(AltFontName), CompareString)); 804 sizeof(AltFontName), CompareString));
805 if (!found) 805 if (!found)
806 return -1; 806 return -1;
807 807
808 *name = g_Base14FontNames[found->m_Index]; 808 *name = g_Base14FontNames[found->m_Index];
809 return found->m_Index; 809 return found->m_Index;
810 } 810 }
OLDNEW
« no previous file with comments | « core/fxge/ge/cfx_font.cpp ('k') | core/fxge/ge/cfx_fontmgr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698