summaryrefslogtreecommitdiff
path: root/core/fxge/cttfontdesc.cpp
blob: 3d0b27b15904279d72947766ee46b80e8463fbc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#include "core/fxge/cttfontdesc.h"

#include <utility>

#include "core/fxge/fx_freetype.h"
#include "third_party/base/stl_util.h"

CTTFontDesc::CTTFontDesc(std::unique_ptr<uint8_t, FxFreeDeleter> pData)
    : m_pFontData(std::move(pData)) {
  for (size_t i = 0; i < FX_ArraySize(m_TTCFaces); i++)
    m_TTCFaces[i] = nullptr;
}

CTTFontDesc::~CTTFontDesc() {
  ASSERT(m_RefCount == 0);
  for (size_t i = 0; i < FX_ArraySize(m_TTCFaces); i++) {
    if (m_TTCFaces[i])
      FXFT_Done_Face(m_TTCFaces[i]);
  }
}

void CTTFontDesc::SetFace(size_t index, FXFT_Face face) {
  ASSERT(index < FX_ArraySize(m_TTCFaces));
  m_TTCFaces[index] = face;
}

void CTTFontDesc::AddRef() {
  ASSERT(m_RefCount > 0);
  ++m_RefCount;
}

CTTFontDesc::ReleaseStatus CTTFontDesc::ReleaseFace(FXFT_Face face) {
  if (!pdfium::ContainsValue(m_TTCFaces, face))
    return kNotAppropriate;

  ASSERT(m_RefCount > 0);
  return --m_RefCount == 0 ? kReleased : kNotReleased;
}

FXFT_Face CTTFontDesc::GetFace(size_t index) const {
  ASSERT(index < FX_ArraySize(m_TTCFaces));
  return m_TTCFaces[index];
}