Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "NativeFontResourceFontconfig.h"
8 : #include "ScaledFontFontconfig.h"
9 : #include "UnscaledFontFreeType.h"
10 : #include "Logging.h"
11 :
12 : namespace mozilla {
13 : namespace gfx {
14 :
15 0 : NativeFontResourceFontconfig::NativeFontResourceFontconfig(UniquePtr<uint8_t[]>&& aFontData, FT_Face aFace)
16 0 : : mFontData(Move(aFontData)),
17 0 : mFace(aFace)
18 : {
19 0 : }
20 :
21 0 : NativeFontResourceFontconfig::~NativeFontResourceFontconfig()
22 : {
23 0 : if (mFace) {
24 0 : Factory::ReleaseFTFace(mFace);
25 0 : mFace = nullptr;
26 : }
27 0 : }
28 :
29 : already_AddRefed<NativeFontResourceFontconfig>
30 0 : NativeFontResourceFontconfig::Create(uint8_t *aFontData, uint32_t aDataLength, FT_Library aFTLibrary)
31 : {
32 0 : if (!aFontData || !aDataLength) {
33 0 : return nullptr;
34 : }
35 0 : UniquePtr<uint8_t[]> fontData(new uint8_t[aDataLength]);
36 0 : memcpy(fontData.get(), aFontData, aDataLength);
37 :
38 0 : FT_Face face = Factory::NewFTFaceFromData(aFTLibrary, fontData.get(), aDataLength, 0);
39 0 : if (!face) {
40 0 : return nullptr;
41 : }
42 0 : if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != FT_Err_Ok) {
43 0 : Factory::ReleaseFTFace(face);
44 0 : return nullptr;
45 : }
46 :
47 : RefPtr<NativeFontResourceFontconfig> resource =
48 0 : new NativeFontResourceFontconfig(Move(fontData), face);
49 0 : return resource.forget();
50 : }
51 :
52 : already_AddRefed<UnscaledFont>
53 0 : NativeFontResourceFontconfig::CreateUnscaledFont(uint32_t aIndex,
54 : const uint8_t* aInstanceData, uint32_t aInstanceDataLength)
55 : {
56 0 : RefPtr<UnscaledFont> unscaledFont = new UnscaledFontFontconfig(mFace, this);
57 0 : return unscaledFont.forget();
58 : }
59 :
60 : } // gfx
61 : } // mozilla
|