• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The PDFium Authors
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 <utility>
8 
9 #include "third_party/base/check.h"
10 #include "third_party/base/numerics/safe_conversions.h"
11 
12 // static
New(FT_Library library,RetainPtr<Retainable> pDesc,pdfium::span<const FT_Byte> data,FT_Long face_index)13 RetainPtr<CFX_Face> CFX_Face::New(FT_Library library,
14                                   RetainPtr<Retainable> pDesc,
15                                   pdfium::span<const FT_Byte> data,
16                                   FT_Long face_index) {
17   FXFT_FaceRec* pRec = nullptr;
18   if (FT_New_Memory_Face(library, data.data(),
19                          pdfium::base::checked_cast<FT_Long>(data.size()),
20                          face_index, &pRec) != 0) {
21     return nullptr;
22   }
23   // Private ctor.
24   return pdfium::WrapRetain(new CFX_Face(pRec, std::move(pDesc)));
25 }
26 
27 // static
Open(FT_Library library,const FT_Open_Args * args,FT_Long face_index)28 RetainPtr<CFX_Face> CFX_Face::Open(FT_Library library,
29                                    const FT_Open_Args* args,
30                                    FT_Long face_index) {
31   FXFT_FaceRec* pRec = nullptr;
32   if (FT_Open_Face(library, args, face_index, &pRec) != 0)
33     return nullptr;
34 
35   // Private ctor.
36   return pdfium::WrapRetain(new CFX_Face(pRec, nullptr));
37 }
38 
CFX_Face(FXFT_FaceRec * rec,RetainPtr<Retainable> pDesc)39 CFX_Face::CFX_Face(FXFT_FaceRec* rec, RetainPtr<Retainable> pDesc)
40     : m_pRec(rec), m_pDesc(std::move(pDesc)) {
41   DCHECK(m_pRec);
42 }
43 
44 CFX_Face::~CFX_Face() = default;
45