| OLD | NEW |
| 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/ge/cfx_folderfontinfo.h" | 7 #include "core/fxge/ge/cfx_folderfontinfo.h" |
| 8 | 8 |
| 9 #include "core/fxge/cfx_fontmapper.h" | 9 #include "core/fxge/cfx_fontmapper.h" |
| 10 #include "core/fxge/fx_font.h" | 10 #include "core/fxge/fx_font.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 return CHARSET_FLAG_SYMBOL; | 69 return CHARSET_FLAG_SYMBOL; |
| 70 case FXFONT_ANSI_CHARSET: | 70 case FXFONT_ANSI_CHARSET: |
| 71 return CHARSET_FLAG_ANSI; | 71 return CHARSET_FLAG_ANSI; |
| 72 default: | 72 default: |
| 73 break; | 73 break; |
| 74 } | 74 } |
| 75 return 0; | 75 return 0; |
| 76 } | 76 } |
| 77 | 77 |
| 78 int32_t GetSimilarValue(int weight, | 78 int32_t GetSimilarValue(int weight, |
| 79 FX_BOOL bItalic, | 79 bool bItalic, |
| 80 int pitch_family, | 80 int pitch_family, |
| 81 uint32_t style) { | 81 uint32_t style) { |
| 82 int32_t iSimilarValue = 0; | 82 int32_t iSimilarValue = 0; |
| 83 if (!!(style & FXFONT_BOLD) == (weight > 400)) | 83 if (!!(style & FXFONT_BOLD) == (weight > 400)) |
| 84 iSimilarValue += 16; | 84 iSimilarValue += 16; |
| 85 if (!!(style & FXFONT_ITALIC) == bItalic) | 85 if (!!(style & FXFONT_ITALIC) == bItalic) |
| 86 iSimilarValue += 16; | 86 iSimilarValue += 16; |
| 87 if (!!(style & FXFONT_SERIF) == !!(pitch_family & FXFONT_FF_ROMAN)) | 87 if (!!(style & FXFONT_SERIF) == !!(pitch_family & FXFONT_FF_ROMAN)) |
| 88 iSimilarValue += 16; | 88 iSimilarValue += 16; |
| 89 if (!!(style & FXFONT_SCRIPT) == !!(pitch_family & FXFONT_FF_SCRIPT)) | 89 if (!!(style & FXFONT_SCRIPT) == !!(pitch_family & FXFONT_FF_SCRIPT)) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 101 | 101 |
| 102 CFX_FolderFontInfo::~CFX_FolderFontInfo() { | 102 CFX_FolderFontInfo::~CFX_FolderFontInfo() { |
| 103 for (const auto& pair : m_FontList) | 103 for (const auto& pair : m_FontList) |
| 104 delete pair.second; | 104 delete pair.second; |
| 105 } | 105 } |
| 106 | 106 |
| 107 void CFX_FolderFontInfo::AddPath(const CFX_ByteStringC& path) { | 107 void CFX_FolderFontInfo::AddPath(const CFX_ByteStringC& path) { |
| 108 m_PathList.push_back(CFX_ByteString(path)); | 108 m_PathList.push_back(CFX_ByteString(path)); |
| 109 } | 109 } |
| 110 | 110 |
| 111 FX_BOOL CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper) { | 111 bool CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper) { |
| 112 m_pMapper = pMapper; | 112 m_pMapper = pMapper; |
| 113 for (const auto& path : m_PathList) | 113 for (const auto& path : m_PathList) |
| 114 ScanPath(path); | 114 ScanPath(path); |
| 115 return TRUE; | 115 return true; |
| 116 } | 116 } |
| 117 | 117 |
| 118 void CFX_FolderFontInfo::ScanPath(const CFX_ByteString& path) { | 118 void CFX_FolderFontInfo::ScanPath(const CFX_ByteString& path) { |
| 119 FX_FileHandle* handle = FX_OpenFolder(path.c_str()); | 119 FX_FileHandle* handle = FX_OpenFolder(path.c_str()); |
| 120 if (!handle) | 120 if (!handle) |
| 121 return; | 121 return; |
| 122 | 122 |
| 123 CFX_ByteString filename; | 123 CFX_ByteString filename; |
| 124 bool bFolder; | 124 bool bFolder; |
| 125 while (FX_GetNextFile(handle, &filename, &bFolder)) { | 125 while (FX_GetNextFile(handle, &filename, &bFolder)) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 void* CFX_FolderFontInfo::GetSubstFont(const CFX_ByteString& face) { | 263 void* CFX_FolderFontInfo::GetSubstFont(const CFX_ByteString& face) { |
| 264 for (size_t iBaseFont = 0; iBaseFont < FX_ArraySize(Base14Substs); | 264 for (size_t iBaseFont = 0; iBaseFont < FX_ArraySize(Base14Substs); |
| 265 iBaseFont++) { | 265 iBaseFont++) { |
| 266 if (face == Base14Substs[iBaseFont].m_pName) | 266 if (face == Base14Substs[iBaseFont].m_pName) |
| 267 return GetFont(Base14Substs[iBaseFont].m_pSubstName); | 267 return GetFont(Base14Substs[iBaseFont].m_pSubstName); |
| 268 } | 268 } |
| 269 return nullptr; | 269 return nullptr; |
| 270 } | 270 } |
| 271 | 271 |
| 272 void* CFX_FolderFontInfo::FindFont(int weight, | 272 void* CFX_FolderFontInfo::FindFont(int weight, |
| 273 FX_BOOL bItalic, | 273 bool bItalic, |
| 274 int charset, | 274 int charset, |
| 275 int pitch_family, | 275 int pitch_family, |
| 276 const FX_CHAR* family, | 276 const FX_CHAR* family, |
| 277 FX_BOOL bMatchName) { | 277 bool bMatchName) { |
| 278 CFX_FontFaceInfo* pFind = nullptr; | 278 CFX_FontFaceInfo* pFind = nullptr; |
| 279 if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH)) | 279 if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH)) |
| 280 return GetFont("Courier New"); | 280 return GetFont("Courier New"); |
| 281 uint32_t charset_flag = GetCharset(charset); | 281 uint32_t charset_flag = GetCharset(charset); |
| 282 int32_t iBestSimilar = 0; | 282 int32_t iBestSimilar = 0; |
| 283 for (const auto& it : m_FontList) { | 283 for (const auto& it : m_FontList) { |
| 284 const CFX_ByteString& bsName = it.first; | 284 const CFX_ByteString& bsName = it.first; |
| 285 CFX_FontFaceInfo* pFont = it.second; | 285 CFX_FontFaceInfo* pFont = it.second; |
| 286 if (!(pFont->m_Charsets & charset_flag) && | 286 if (!(pFont->m_Charsets & charset_flag) && |
| 287 charset != FXFONT_DEFAULT_CHARSET) { | 287 charset != FXFONT_DEFAULT_CHARSET) { |
| 288 continue; | 288 continue; |
| 289 } | 289 } |
| 290 int32_t index = bsName.Find(family); | 290 int32_t index = bsName.Find(family); |
| 291 if (bMatchName && index < 0) | 291 if (bMatchName && index < 0) |
| 292 continue; | 292 continue; |
| 293 int32_t iSimilarValue = | 293 int32_t iSimilarValue = |
| 294 GetSimilarValue(weight, bItalic, pitch_family, pFont->m_Styles); | 294 GetSimilarValue(weight, bItalic, pitch_family, pFont->m_Styles); |
| 295 if (iSimilarValue > iBestSimilar) { | 295 if (iSimilarValue > iBestSimilar) { |
| 296 iBestSimilar = iSimilarValue; | 296 iBestSimilar = iSimilarValue; |
| 297 pFind = pFont; | 297 pFind = pFont; |
| 298 } | 298 } |
| 299 } | 299 } |
| 300 return pFind; | 300 return pFind; |
| 301 } | 301 } |
| 302 | 302 |
| 303 void* CFX_FolderFontInfo::MapFont(int weight, | 303 void* CFX_FolderFontInfo::MapFont(int weight, |
| 304 FX_BOOL bItalic, | 304 bool bItalic, |
| 305 int charset, | 305 int charset, |
| 306 int pitch_family, | 306 int pitch_family, |
| 307 const FX_CHAR* family, | 307 const FX_CHAR* family, |
| 308 int& iExact) { | 308 int& iExact) { |
| 309 return nullptr; | 309 return nullptr; |
| 310 } | 310 } |
| 311 | 311 |
| 312 #ifdef PDF_ENABLE_XFA | 312 #ifdef PDF_ENABLE_XFA |
| 313 void* CFX_FolderFontInfo::MapFontByUnicode(uint32_t dwUnicode, | 313 void* CFX_FolderFontInfo::MapFontByUnicode(uint32_t dwUnicode, |
| 314 int weight, | 314 int weight, |
| 315 FX_BOOL bItalic, | 315 bool bItalic, |
| 316 int pitch_family) { | 316 int pitch_family) { |
| 317 return nullptr; | 317 return nullptr; |
| 318 } | 318 } |
| 319 #endif // PDF_ENABLE_XFA | 319 #endif // PDF_ENABLE_XFA |
| 320 | 320 |
| 321 void* CFX_FolderFontInfo::GetFont(const FX_CHAR* face) { | 321 void* CFX_FolderFontInfo::GetFont(const FX_CHAR* face) { |
| 322 auto it = m_FontList.find(face); | 322 auto it = m_FontList.find(face); |
| 323 return it != m_FontList.end() ? it->second : nullptr; | 323 return it != m_FontList.end() ? it->second : nullptr; |
| 324 } | 324 } |
| 325 | 325 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 357 |
| 358 if (FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET) < 0 || | 358 if (FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET) < 0 || |
| 359 FXSYS_fread(buffer, datasize, 1, pFile) != 1) { | 359 FXSYS_fread(buffer, datasize, 1, pFile) != 1) { |
| 360 datasize = 0; | 360 datasize = 0; |
| 361 } | 361 } |
| 362 FXSYS_fclose(pFile); | 362 FXSYS_fclose(pFile); |
| 363 return datasize; | 363 return datasize; |
| 364 } | 364 } |
| 365 | 365 |
| 366 void CFX_FolderFontInfo::DeleteFont(void* hFont) {} | 366 void CFX_FolderFontInfo::DeleteFont(void* hFont) {} |
| 367 FX_BOOL CFX_FolderFontInfo::GetFaceName(void* hFont, CFX_ByteString& name) { | 367 bool CFX_FolderFontInfo::GetFaceName(void* hFont, CFX_ByteString& name) { |
| 368 if (!hFont) | 368 if (!hFont) |
| 369 return FALSE; | 369 return false; |
| 370 CFX_FontFaceInfo* pFont = (CFX_FontFaceInfo*)hFont; | 370 CFX_FontFaceInfo* pFont = (CFX_FontFaceInfo*)hFont; |
| 371 name = pFont->m_FaceName; | 371 name = pFont->m_FaceName; |
| 372 return TRUE; | 372 return true; |
| 373 } | 373 } |
| 374 | 374 |
| 375 FX_BOOL CFX_FolderFontInfo::GetFontCharset(void* hFont, int& charset) { | 375 bool CFX_FolderFontInfo::GetFontCharset(void* hFont, int& charset) { |
| 376 return FALSE; | 376 return false; |
| 377 } | 377 } |
| OLD | NEW |