• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "core/fxge/cttfontdesc.h"
8 
9 #include "core/fxge/fx_freetype.h"
10 #include "third_party/base/stl_util.h"
11 
CTTFontDesc(uint8_t * pData,FXFT_Face face)12 CTTFontDesc::CTTFontDesc(uint8_t* pData, FXFT_Face face)
13     : m_bIsTTC(false), m_SingleFace(face), m_pFontData(pData) {}
14 
CTTFontDesc(uint8_t * pData,size_t index,FXFT_Face face)15 CTTFontDesc::CTTFontDesc(uint8_t* pData, size_t index, FXFT_Face face)
16     : m_bIsTTC(true), m_pFontData(pData) {
17   for (size_t i = 0; i < FX_ArraySize(m_TTCFaces); i++)
18     m_TTCFaces[i] = nullptr;
19   SetTTCFace(index, face);
20 }
21 
~CTTFontDesc()22 CTTFontDesc::~CTTFontDesc() {
23   ASSERT(m_RefCount == 0);
24   if (m_bIsTTC) {
25     for (size_t i = 0; i < FX_ArraySize(m_TTCFaces); i++) {
26       if (m_TTCFaces[i])
27         FXFT_Done_Face(m_TTCFaces[i]);
28     }
29   } else {
30     if (m_SingleFace)
31       FXFT_Done_Face(m_SingleFace);
32   }
33   FX_Free(m_pFontData);
34 }
35 
SetTTCFace(size_t index,FXFT_Face face)36 void CTTFontDesc::SetTTCFace(size_t index, FXFT_Face face) {
37   ASSERT(m_bIsTTC);
38   ASSERT(index < FX_ArraySize(m_TTCFaces));
39   m_TTCFaces[index] = face;
40 }
41 
AddRef()42 void CTTFontDesc::AddRef() {
43   ASSERT(m_RefCount > 0);
44   ++m_RefCount;
45 }
46 
ReleaseFace(FXFT_Face face)47 CTTFontDesc::ReleaseStatus CTTFontDesc::ReleaseFace(FXFT_Face face) {
48   if (m_bIsTTC) {
49     if (!pdfium::ContainsValue(m_TTCFaces, face))
50       return kNotAppropriate;
51   } else {
52     if (m_SingleFace != face)
53       return kNotAppropriate;
54   }
55   ASSERT(m_RefCount > 0);
56   return --m_RefCount == 0 ? kReleased : kNotReleased;
57 }
58 
SingleFace() const59 FXFT_Face CTTFontDesc::SingleFace() const {
60   ASSERT(!m_bIsTTC);
61   return m_SingleFace;
62 }
63 
TTCFace(size_t index) const64 FXFT_Face CTTFontDesc::TTCFace(size_t index) const {
65   ASSERT(m_bIsTTC);
66   ASSERT(index < FX_ArraySize(m_TTCFaces));
67   return m_TTCFaces[index];
68 }
69