• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "core/fxge/cfx_face.h"
6 
7 #include "third_party/base/ptr_util.h"
8 
9 // static
New(FT_Library library,const RetainPtr<Retainable> & pDesc,pdfium::span<const FT_Byte> data,FT_Long face_index)10 RetainPtr<CFX_Face> CFX_Face::New(FT_Library library,
11                                   const RetainPtr<Retainable>& pDesc,
12                                   pdfium::span<const FT_Byte> data,
13                                   FT_Long face_index) {
14   FXFT_FaceRec* pRec = nullptr;
15   if (FT_New_Memory_Face(library, data.data(), data.size(), face_index,
16                          &pRec) != 0) {
17     return nullptr;
18   }
19   return pdfium::WrapRetain(new CFX_Face(pRec, pDesc));
20 }
21 
22 // static
Open(FT_Library library,const FT_Open_Args * args,FT_Long face_index)23 RetainPtr<CFX_Face> CFX_Face::Open(FT_Library library,
24                                    const FT_Open_Args* args,
25                                    FT_Long face_index) {
26   FXFT_FaceRec* pRec = nullptr;
27   if (FT_Open_Face(library, args, face_index, &pRec) != 0)
28     return nullptr;
29 
30   return pdfium::WrapRetain(new CFX_Face(pRec, nullptr));
31 }
32 
CFX_Face(FXFT_FaceRec * rec,const RetainPtr<Retainable> & pDesc)33 CFX_Face::CFX_Face(FXFT_FaceRec* rec, const RetainPtr<Retainable>& pDesc)
34     : m_pRec(rec), m_pDesc(pDesc) {
35   ASSERT(m_pRec);
36 }
37 
38 CFX_Face::~CFX_Face() = default;
39