Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef CORE_FXGE_INCLUDE_FX_FONT_H_ | 7 #ifndef CORE_FXGE_INCLUDE_FX_FONT_H_ |
| 8 #define CORE_FXGE_INCLUDE_FX_FONT_H_ | 8 #define CORE_FXGE_INCLUDE_FX_FONT_H_ |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "core/fxcrt/include/fx_system.h" | 14 #include "core/fxcrt/include/fx_system.h" |
| 15 #include "core/fxge/include/fx_dib.h" | 15 #include "core/fxge/include/fx_dib.h" |
| 16 #include "core/fxge/include/fx_freetype.h" | 16 #include "core/fxge/include/fx_freetype.h" |
| 17 | 17 |
| 18 typedef struct FT_FaceRec_* FXFT_Face; | 18 typedef struct FT_FaceRec_* FXFT_Face; |
| 19 typedef void* FXFT_Library; | 19 typedef void* FXFT_Library; |
| 20 | 20 |
| 21 class CFX_FaceCache; | 21 class CFX_FaceCache; |
| 22 class CFX_FontMapper; | |
| 23 class CFX_PathData; | 22 class CFX_PathData; |
| 24 class CFX_SizeGlyphCache; | 23 class CFX_SizeGlyphCache; |
| 25 class CFX_SubstFont; | 24 class CFX_SubstFont; |
| 26 class CTTFontDesc; | 25 class CTTFontDesc; |
| 27 class IFX_SystemFontInfo; | |
| 28 | 26 |
| 29 #ifdef _SKIA_SUPPORT_ | 27 #ifdef _SKIA_SUPPORT_ |
| 30 class SkTypeface; | 28 class SkTypeface; |
| 31 | 29 |
| 32 using CFX_TypeFace = SkTypeface; | 30 using CFX_TypeFace = SkTypeface; |
| 33 #endif | 31 #endif |
| 34 | 32 |
| 35 #define FXFONT_FIXED_PITCH 0x01 | 33 #define FXFONT_FIXED_PITCH 0x01 |
| 36 #define FXFONT_SERIF 0x02 | 34 #define FXFONT_SERIF 0x02 |
| 37 #define FXFONT_SYMBOLIC 0x04 | 35 #define FXFONT_SYMBOLIC 0x04 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 64 #define FXFONT_FW_NORMAL 400 | 62 #define FXFONT_FW_NORMAL 400 |
| 65 #define FXFONT_FW_BOLD 700 | 63 #define FXFONT_FW_BOLD 700 |
| 66 | 64 |
| 67 #define CHARSET_FLAG_ANSI 1 | 65 #define CHARSET_FLAG_ANSI 1 |
| 68 #define CHARSET_FLAG_SYMBOL 2 | 66 #define CHARSET_FLAG_SYMBOL 2 |
| 69 #define CHARSET_FLAG_SHIFTJIS 4 | 67 #define CHARSET_FLAG_SHIFTJIS 4 |
| 70 #define CHARSET_FLAG_BIG5 8 | 68 #define CHARSET_FLAG_BIG5 8 |
| 71 #define CHARSET_FLAG_GB 16 | 69 #define CHARSET_FLAG_GB 16 |
| 72 #define CHARSET_FLAG_KOREAN 32 | 70 #define CHARSET_FLAG_KOREAN 32 |
| 73 | 71 |
| 72 #define GET_TT_SHORT(w) (uint16_t)(((w)[0] << 8) | (w)[1]) | |
|
dsinclair
2016/07/27 17:36:01
Do these need to be in the header or can they move
npm
2016/07/27 18:51:58
Used in a couple of .cpp files
| |
| 73 #define GET_TT_LONG(w) \ | |
| 74 (uint32_t)(((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3]) | |
| 75 | |
| 74 class CFX_Font { | 76 class CFX_Font { |
| 75 public: | 77 public: |
| 76 CFX_Font(); | 78 CFX_Font(); |
| 77 ~CFX_Font(); | 79 ~CFX_Font(); |
| 78 | 80 |
| 79 void LoadSubst(const CFX_ByteString& face_name, | 81 void LoadSubst(const CFX_ByteString& face_name, |
| 80 FX_BOOL bTrueType, | 82 FX_BOOL bTrueType, |
| 81 uint32_t flags, | 83 uint32_t flags, |
| 82 int weight, | 84 int weight, |
| 83 int italic_angle, | 85 int italic_angle, |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 }; | 233 }; |
| 232 | 234 |
| 233 #define FX_FONT_FLAG_SERIF 0x01 | 235 #define FX_FONT_FLAG_SERIF 0x01 |
| 234 #define FX_FONT_FLAG_FIXEDPITCH 0x02 | 236 #define FX_FONT_FLAG_FIXEDPITCH 0x02 |
| 235 #define FX_FONT_FLAG_ITALIC 0x04 | 237 #define FX_FONT_FLAG_ITALIC 0x04 |
| 236 #define FX_FONT_FLAG_BOLD 0x08 | 238 #define FX_FONT_FLAG_BOLD 0x08 |
| 237 #define FX_FONT_FLAG_SYMBOLIC_SYMBOL 0x10 | 239 #define FX_FONT_FLAG_SYMBOLIC_SYMBOL 0x10 |
| 238 #define FX_FONT_FLAG_SYMBOLIC_DINGBATS 0x20 | 240 #define FX_FONT_FLAG_SYMBOLIC_DINGBATS 0x20 |
| 239 #define FX_FONT_FLAG_MULTIPLEMASTER 0x40 | 241 #define FX_FONT_FLAG_MULTIPLEMASTER 0x40 |
| 240 | 242 |
| 241 class CFX_FontMgr { | |
| 242 public: | |
| 243 CFX_FontMgr(); | |
| 244 ~CFX_FontMgr(); | |
| 245 | |
| 246 void InitFTLibrary(); | |
| 247 | |
| 248 FXFT_Face GetCachedFace(const CFX_ByteString& face_name, | |
| 249 int weight, | |
| 250 FX_BOOL bItalic, | |
| 251 uint8_t*& pFontData); | |
| 252 FXFT_Face AddCachedFace(const CFX_ByteString& face_name, | |
| 253 int weight, | |
| 254 FX_BOOL bItalic, | |
| 255 uint8_t* pData, | |
| 256 uint32_t size, | |
| 257 int face_index); | |
| 258 FXFT_Face GetCachedTTCFace(int ttc_size, | |
| 259 uint32_t checksum, | |
| 260 int font_offset, | |
| 261 uint8_t*& pFontData); | |
| 262 FXFT_Face AddCachedTTCFace(int ttc_size, | |
| 263 uint32_t checksum, | |
| 264 uint8_t* pData, | |
| 265 uint32_t size, | |
| 266 int font_offset); | |
| 267 FXFT_Face GetFileFace(const FX_CHAR* filename, int face_index); | |
| 268 FXFT_Face GetFixedFace(const uint8_t* pData, uint32_t size, int face_index); | |
| 269 void ReleaseFace(FXFT_Face face); | |
| 270 void SetSystemFontInfo(std::unique_ptr<IFX_SystemFontInfo> pFontInfo); | |
| 271 FXFT_Face FindSubstFont(const CFX_ByteString& face_name, | |
| 272 FX_BOOL bTrueType, | |
| 273 uint32_t flags, | |
| 274 int weight, | |
| 275 int italic_angle, | |
| 276 int CharsetCP, | |
| 277 CFX_SubstFont* pSubstFont); | |
| 278 bool GetBuiltinFont(size_t index, const uint8_t** pFontData, uint32_t* size); | |
| 279 CFX_FontMapper* GetBuiltinMapper() const { return m_pBuiltinMapper.get(); } | |
| 280 FXFT_Library GetFTLibrary() const { return m_FTLibrary; } | |
| 281 bool FTLibrarySupportsHinting() const { return m_FTLibrarySupportsHinting; } | |
| 282 | |
| 283 private: | |
| 284 std::unique_ptr<CFX_FontMapper> m_pBuiltinMapper; | |
| 285 std::map<CFX_ByteString, CTTFontDesc*> m_FaceMap; | |
| 286 FXFT_Library m_FTLibrary; | |
| 287 bool m_FTLibrarySupportsHinting; | |
| 288 }; | |
| 289 | |
| 290 class CFX_FontMapper { | |
| 291 public: | |
| 292 explicit CFX_FontMapper(CFX_FontMgr* mgr); | |
| 293 ~CFX_FontMapper(); | |
| 294 | |
| 295 void SetSystemFontInfo(std::unique_ptr<IFX_SystemFontInfo> pFontInfo); | |
| 296 IFX_SystemFontInfo* GetSystemFontInfo() { return m_pFontInfo.get(); } | |
| 297 void AddInstalledFont(const CFX_ByteString& name, int charset); | |
| 298 void LoadInstalledFonts(); | |
| 299 | |
| 300 FXFT_Face FindSubstFont(const CFX_ByteString& face_name, | |
| 301 FX_BOOL bTrueType, | |
| 302 uint32_t flags, | |
| 303 int weight, | |
| 304 int italic_angle, | |
| 305 int CharsetCP, | |
| 306 CFX_SubstFont* pSubstFont); | |
| 307 #ifdef PDF_ENABLE_XFA | |
| 308 FXFT_Face FindSubstFontByUnicode(uint32_t dwUnicode, | |
| 309 uint32_t flags, | |
| 310 int weight, | |
| 311 int italic_angle); | |
| 312 #endif // PDF_ENABLE_XFA | |
| 313 FX_BOOL IsBuiltinFace(const FXFT_Face face) const; | |
| 314 int GetFaceSize() const; | |
| 315 CFX_ByteString GetFaceName(int index) const { | |
| 316 return m_FaceArray[index].name; | |
| 317 } | |
| 318 | |
| 319 std::vector<CFX_ByteString> m_InstalledTTFonts; | |
| 320 | |
| 321 private: | |
| 322 static const size_t MM_FACE_COUNT = 2; | |
| 323 static const size_t FOXIT_FACE_COUNT = 14; | |
| 324 | |
| 325 CFX_ByteString GetPSNameFromTT(void* hFont); | |
| 326 CFX_ByteString MatchInstalledFonts(const CFX_ByteString& norm_name); | |
| 327 FXFT_Face UseInternalSubst(CFX_SubstFont* pSubstFont, | |
| 328 int iBaseFont, | |
| 329 int italic_angle, | |
| 330 int weight, | |
| 331 int picthfamily); | |
| 332 | |
| 333 struct FaceData { | |
| 334 CFX_ByteString name; | |
| 335 uint32_t charset; | |
| 336 }; | |
| 337 | |
| 338 FX_BOOL m_bListLoaded; | |
| 339 FXFT_Face m_MMFaces[MM_FACE_COUNT]; | |
| 340 CFX_ByteString m_LastFamily; | |
| 341 std::vector<FaceData> m_FaceArray; | |
| 342 std::unique_ptr<IFX_SystemFontInfo> m_pFontInfo; | |
| 343 FXFT_Face m_FoxitFaces[FOXIT_FACE_COUNT]; | |
| 344 CFX_FontMgr* const m_pFontMgr; | |
| 345 }; | |
| 346 | |
| 347 class IFX_SystemFontInfo { | |
| 348 public: | |
| 349 static std::unique_ptr<IFX_SystemFontInfo> CreateDefault( | |
| 350 const char** pUserPaths); | |
| 351 | |
| 352 virtual ~IFX_SystemFontInfo() {} | |
| 353 | |
| 354 virtual FX_BOOL EnumFontList(CFX_FontMapper* pMapper) = 0; | |
| 355 virtual void* MapFont(int weight, | |
| 356 FX_BOOL bItalic, | |
| 357 int charset, | |
| 358 int pitch_family, | |
| 359 const FX_CHAR* face, | |
| 360 int& iExact) = 0; | |
| 361 | |
| 362 #ifdef PDF_ENABLE_XFA | |
| 363 virtual void* MapFontByUnicode(uint32_t dwUnicode, | |
| 364 int weight, | |
| 365 FX_BOOL bItalic, | |
| 366 int pitch_family); | |
| 367 #endif // PDF_ENABLE_XFA | |
| 368 | |
| 369 virtual void* GetFont(const FX_CHAR* face) = 0; | |
| 370 virtual uint32_t GetFontData(void* hFont, | |
| 371 uint32_t table, | |
| 372 uint8_t* buffer, | |
| 373 uint32_t size) = 0; | |
| 374 virtual FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) = 0; | |
| 375 virtual FX_BOOL GetFontCharset(void* hFont, int& charset) = 0; | |
| 376 virtual int GetFaceIndex(void* hFont); | |
| 377 virtual void DeleteFont(void* hFont) = 0; | |
| 378 virtual void* RetainFont(void* hFont); | |
| 379 }; | |
| 380 | |
| 381 class CTTFontDesc { | 243 class CTTFontDesc { |
| 382 public: | 244 public: |
| 383 CTTFontDesc() { | 245 CTTFontDesc() { |
| 384 m_Type = 0; | 246 m_Type = 0; |
| 385 m_pFontData = nullptr; | 247 m_pFontData = nullptr; |
| 386 m_RefCount = 0; | 248 m_RefCount = 0; |
| 387 } | 249 } |
| 388 ~CTTFontDesc(); | 250 ~CTTFontDesc(); |
| 389 // ret < 0, releaseface not appropriate for this object. | 251 // ret < 0, releaseface not appropriate for this object. |
| 390 // ret == 0, object released | 252 // ret == 0, object released |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 415 | 277 |
| 416 const CFX_ByteString m_FilePath; | 278 const CFX_ByteString m_FilePath; |
| 417 const CFX_ByteString m_FaceName; | 279 const CFX_ByteString m_FaceName; |
| 418 const CFX_ByteString m_FontTables; | 280 const CFX_ByteString m_FontTables; |
| 419 const uint32_t m_FontOffset; | 281 const uint32_t m_FontOffset; |
| 420 const uint32_t m_FileSize; | 282 const uint32_t m_FileSize; |
| 421 uint32_t m_Styles; | 283 uint32_t m_Styles; |
| 422 uint32_t m_Charsets; | 284 uint32_t m_Charsets; |
| 423 }; | 285 }; |
| 424 | 286 |
| 425 class CFX_FolderFontInfo : public IFX_SystemFontInfo { | |
| 426 public: | |
| 427 CFX_FolderFontInfo(); | |
| 428 ~CFX_FolderFontInfo() override; | |
| 429 | |
| 430 void AddPath(const CFX_ByteStringC& path); | |
| 431 | |
| 432 // IFX_SytemFontInfo: | |
| 433 FX_BOOL EnumFontList(CFX_FontMapper* pMapper) override; | |
| 434 void* MapFont(int weight, | |
| 435 FX_BOOL bItalic, | |
| 436 int charset, | |
| 437 int pitch_family, | |
| 438 const FX_CHAR* face, | |
| 439 int& bExact) override; | |
| 440 #ifdef PDF_ENABLE_XFA | |
| 441 void* MapFontByUnicode(uint32_t dwUnicode, | |
| 442 int weight, | |
| 443 FX_BOOL bItalic, | |
| 444 int pitch_family) override; | |
| 445 #endif // PDF_ENABLE_XFA | |
| 446 void* GetFont(const FX_CHAR* face) override; | |
| 447 uint32_t GetFontData(void* hFont, | |
| 448 uint32_t table, | |
| 449 uint8_t* buffer, | |
| 450 uint32_t size) override; | |
| 451 void DeleteFont(void* hFont) override; | |
| 452 FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) override; | |
| 453 FX_BOOL GetFontCharset(void* hFont, int& charset) override; | |
| 454 | |
| 455 protected: | |
| 456 void ScanPath(const CFX_ByteString& path); | |
| 457 void ScanFile(const CFX_ByteString& path); | |
| 458 void ReportFace(const CFX_ByteString& path, | |
| 459 FXSYS_FILE* pFile, | |
| 460 uint32_t filesize, | |
| 461 uint32_t offset); | |
| 462 void* GetSubstFont(const CFX_ByteString& face); | |
| 463 void* FindFont(int weight, | |
| 464 FX_BOOL bItalic, | |
| 465 int charset, | |
| 466 int pitch_family, | |
| 467 const FX_CHAR* family, | |
| 468 FX_BOOL bMatchName); | |
| 469 | |
| 470 std::map<CFX_ByteString, CFX_FontFaceInfo*> m_FontList; | |
| 471 std::vector<CFX_ByteString> m_PathList; | |
| 472 CFX_FontMapper* m_pMapper; | |
| 473 }; | |
| 474 | |
| 475 class CFX_CountedFaceCache { | 287 class CFX_CountedFaceCache { |
| 476 public: | 288 public: |
| 477 CFX_FaceCache* m_Obj; | 289 CFX_FaceCache* m_Obj; |
| 478 uint32_t m_nCount; | 290 uint32_t m_nCount; |
| 479 }; | 291 }; |
| 480 | 292 |
| 481 class CFX_FontCache { | 293 class CFX_FontCache { |
| 482 public: | 294 public: |
| 483 CFX_FontCache(); | 295 CFX_FontCache(); |
| 484 ~CFX_FontCache(); | 296 ~CFX_FontCache(); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 FX_FLOAT retinaScaleX = 1.0f, | 386 FX_FLOAT retinaScaleX = 1.0f, |
| 575 FX_FLOAT retinaScaleY = 1.0f); | 387 FX_FLOAT retinaScaleY = 1.0f); |
| 576 | 388 |
| 577 CFX_ByteString GetNameFromTT(const uint8_t* name_table, | 389 CFX_ByteString GetNameFromTT(const uint8_t* name_table, |
| 578 uint32_t name_table_size, | 390 uint32_t name_table_size, |
| 579 uint32_t name); | 391 uint32_t name); |
| 580 | 392 |
| 581 int PDF_GetStandardFontName(CFX_ByteString* name); | 393 int PDF_GetStandardFontName(CFX_ByteString* name); |
| 582 | 394 |
| 583 #endif // CORE_FXGE_INCLUDE_FX_FONT_H_ | 395 #endif // CORE_FXGE_INCLUDE_FX_FONT_H_ |
| OLD | NEW |