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/. */
7 #include "UnscaledFontFreeType.h"
9 #include FT_TRUETYPE_TABLES_H
13 #include <sys/types.h>
21 UnscaledFontFreeType::GetFontFileData(FontFileDataOutput aDataCallback
, void* aBaton
)
24 int fd
= open(mFile
.c_str(), O_RDONLY
);
29 if (fstat(fd
, &buf
) < 0 ||
30 // Don't erroneously read directories as files.
31 !S_ISREG(buf
.st_mode
) ||
32 // Verify the file size fits in a uint32_t.
34 off_t(uint32_t(buf
.st_size
)) != buf
.st_size
) {
38 uint32_t length
= buf
.st_size
;
40 reinterpret_cast<uint8_t*>(
41 mmap(nullptr, length
, PROT_READ
, MAP_PRIVATE
, fd
, 0));
43 if (fontData
== MAP_FAILED
) {
46 aDataCallback(fontData
, length
, mIndex
, aBaton
);
47 munmap(fontData
, length
);
53 // Request the SFNT file. This may not always succeed for all font types.
54 if (FT_Load_Sfnt_Table(mFace
, 0, 0, nullptr, &length
) == FT_Err_Ok
) {
55 uint8_t* fontData
= new uint8_t[length
];
56 if (FT_Load_Sfnt_Table(mFace
, 0, 0, fontData
, &length
) == FT_Err_Ok
) {
57 aDataCallback(fontData
, length
, 0, aBaton
);
66 UnscaledFontFreeType::GetFontDescriptor(FontDescriptorOutput aCb
, void* aBaton
)
72 const char* path
= mFile
.c_str();
73 size_t pathLength
= strlen(path
) + 1;
74 aCb(reinterpret_cast<const uint8_t*>(path
), pathLength
, mIndex
, aBaton
);
79 } // namespace mozilla