blob: af8691a3ad58e76a9d6026dc8f11c7fa4213d555 [file] [log] [blame]
kumarashishg826308d2023-06-23 13:21:22 +00001// Copyright 2016 The PDFium Authors
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -07002// 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/cfx_folderfontinfo.h"
8
kumarashishg826308d2023-06-23 13:21:22 +00009#include <iterator>
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070010#include <limits>
11#include <utility>
12
Haibo Huang49cc9302020-04-27 16:14:24 -070013#include "build/build_config.h"
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070014#include "core/fxcrt/fx_codepage.h"
kumarashishg826308d2023-06-23 13:21:22 +000015#include "core/fxcrt/fx_extension.h"
16#include "core/fxcrt/fx_folder.h"
Haibo Huang49cc9302020-04-27 16:14:24 -070017#include "core/fxcrt/fx_memory_wrappers.h"
18#include "core/fxcrt/fx_safe_types.h"
kumarashishg826308d2023-06-23 13:21:22 +000019#include "core/fxcrt/fx_system.h"
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070020#include "core/fxge/cfx_fontmapper.h"
21#include "core/fxge/fx_font.h"
kumarashishg826308d2023-06-23 13:21:22 +000022#include "third_party/base/containers/contains.h"
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070023
24namespace {
25
26const struct {
27 const char* m_pName;
28 const char* m_pSubstName;
29} Base14Substs[] = {
30 {"Courier", "Courier New"},
31 {"Courier-Bold", "Courier New Bold"},
32 {"Courier-BoldOblique", "Courier New Bold Italic"},
33 {"Courier-Oblique", "Courier New Italic"},
34 {"Helvetica", "Arial"},
35 {"Helvetica-Bold", "Arial Bold"},
36 {"Helvetica-BoldOblique", "Arial Bold Italic"},
37 {"Helvetica-Oblique", "Arial Italic"},
38 {"Times-Roman", "Times New Roman"},
39 {"Times-Bold", "Times New Roman Bold"},
40 {"Times-BoldItalic", "Times New Roman Bold Italic"},
41 {"Times-Italic", "Times New Roman Italic"},
42};
43
Haibo Huang49cc9302020-04-27 16:14:24 -070044// Used with std::unique_ptr to automatically call fclose().
45struct FxFileCloser {
46 inline void operator()(FILE* h) const {
47 if (h)
48 fclose(h);
49 }
50};
51
kumarashishg826308d2023-06-23 13:21:22 +000052bool FindFamilyNameMatch(ByteStringView family_name,
53 const ByteString& installed_font_name) {
54 absl::optional<size_t> result = installed_font_name.Find(family_name, 0);
55 if (!result.has_value())
56 return false;
57
58 size_t next_index = result.value() + family_name.GetLength();
59 // Rule out the case that |family_name| is a substring of
60 // |installed_font_name| but their family names are actually different words.
61 // For example: "Univers" and "Universal" are not a match because they have
62 // different family names, but "Univers" and "Univers Bold" are a match.
63 if (installed_font_name.IsValidIndex(next_index) &&
64 FXSYS_IsLowerASCII(installed_font_name[next_index])) {
65 return false;
66 }
67
68 return true;
69}
70
Haibo Huang49cc9302020-04-27 16:14:24 -070071ByteString ReadStringFromFile(FILE* pFile, uint32_t size) {
72 ByteString result;
73 {
74 // Span's lifetime must end before ReleaseBuffer() below.
75 pdfium::span<char> buffer = result.GetBuffer(size);
76 if (!fread(buffer.data(), size, 1, pFile))
77 return ByteString();
78 }
79 result.ReleaseBuffer(size);
80 return result;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070081}
82
Haibo Huang49cc9302020-04-27 16:14:24 -070083ByteString LoadTableFromTT(FILE* pFile,
84 const uint8_t* pTables,
85 uint32_t nTables,
86 uint32_t tag,
kumarashishg826308d2023-06-23 13:21:22 +000087 FX_FILESIZE fileSize) {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070088 for (uint32_t i = 0; i < nTables; i++) {
89 const uint8_t* p = pTables + i * 16;
kumarashishg826308d2023-06-23 13:21:22 +000090 if (FXSYS_UINT32_GET_MSBFIRST(p) == tag) {
91 uint32_t offset = FXSYS_UINT32_GET_MSBFIRST(p + 8);
92 uint32_t size = FXSYS_UINT32_GET_MSBFIRST(p + 12);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070093 if (offset > std::numeric_limits<uint32_t>::max() - size ||
kumarashishg826308d2023-06-23 13:21:22 +000094 static_cast<FX_FILESIZE>(offset + size) > fileSize ||
95 fseek(pFile, offset, SEEK_SET) < 0) {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070096 return ByteString();
97 }
Haibo Huang49cc9302020-04-27 16:14:24 -070098 return ReadStringFromFile(pFile, size);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070099 }
100 }
101 return ByteString();
102}
103
kumarashishg826308d2023-06-23 13:21:22 +0000104uint32_t GetCharset(FX_Charset charset) {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700105 switch (charset) {
kumarashishg826308d2023-06-23 13:21:22 +0000106 case FX_Charset::kShiftJIS:
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700107 return CHARSET_FLAG_SHIFTJIS;
kumarashishg826308d2023-06-23 13:21:22 +0000108 case FX_Charset::kChineseSimplified:
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700109 return CHARSET_FLAG_GB;
kumarashishg826308d2023-06-23 13:21:22 +0000110 case FX_Charset::kChineseTraditional:
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700111 return CHARSET_FLAG_BIG5;
kumarashishg826308d2023-06-23 13:21:22 +0000112 case FX_Charset::kHangul:
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700113 return CHARSET_FLAG_KOREAN;
kumarashishg826308d2023-06-23 13:21:22 +0000114 case FX_Charset::kSymbol:
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700115 return CHARSET_FLAG_SYMBOL;
kumarashishg826308d2023-06-23 13:21:22 +0000116 case FX_Charset::kANSI:
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700117 return CHARSET_FLAG_ANSI;
118 default:
119 break;
120 }
121 return 0;
122}
123
124int32_t GetSimilarValue(int weight,
125 bool bItalic,
126 int pitch_family,
kumarashishg826308d2023-06-23 13:21:22 +0000127 uint32_t style,
128 bool bMatchName,
129 size_t familyNameLength,
130 size_t bsNameLength) {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700131 int32_t iSimilarValue = 0;
kumarashishg826308d2023-06-23 13:21:22 +0000132 if (bMatchName && (familyNameLength == bsNameLength))
133 iSimilarValue += 4;
Haibo Huang49cc9302020-04-27 16:14:24 -0700134 if (FontStyleIsForceBold(style) == (weight > 400))
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700135 iSimilarValue += 16;
136 if (FontStyleIsItalic(style) == bItalic)
137 iSimilarValue += 16;
138 if (FontStyleIsSerif(style) == FontFamilyIsRoman(pitch_family))
139 iSimilarValue += 16;
140 if (FontStyleIsScript(style) == FontFamilyIsScript(pitch_family))
141 iSimilarValue += 8;
142 if (FontStyleIsFixedPitch(style) == FontFamilyIsFixedPitch(pitch_family))
143 iSimilarValue += 8;
144 return iSimilarValue;
145}
146
147} // namespace
148
Haibo Huang49cc9302020-04-27 16:14:24 -0700149CFX_FolderFontInfo::CFX_FolderFontInfo() = default;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700150
Haibo Huang49cc9302020-04-27 16:14:24 -0700151CFX_FolderFontInfo::~CFX_FolderFontInfo() = default;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700152
153void CFX_FolderFontInfo::AddPath(const ByteString& path) {
154 m_PathList.push_back(path);
155}
156
157bool CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper) {
158 m_pMapper = pMapper;
159 for (const auto& path : m_PathList)
160 ScanPath(path);
161 return true;
162}
163
164void CFX_FolderFontInfo::ScanPath(const ByteString& path) {
kumarashishg826308d2023-06-23 13:21:22 +0000165 std::unique_ptr<FX_Folder> handle = FX_Folder::OpenFolder(path);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700166 if (!handle)
167 return;
168
169 ByteString filename;
170 bool bFolder;
kumarashishg826308d2023-06-23 13:21:22 +0000171 while (handle->GetNextFile(&filename, &bFolder)) {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700172 if (bFolder) {
173 if (filename == "." || filename == "..")
174 continue;
175 } else {
Haibo Huang49cc9302020-04-27 16:14:24 -0700176 ByteString ext = filename.Last(4);
177 ext.MakeLower();
178 if (ext != ".ttf" && ext != ".ttc" && ext != ".otf")
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700179 continue;
180 }
181
182 ByteString fullpath = path;
kumarashishg826308d2023-06-23 13:21:22 +0000183#if BUILDFLAG(IS_WIN)
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700184 fullpath += "\\";
185#else
186 fullpath += "/";
187#endif
188
189 fullpath += filename;
190 bFolder ? ScanPath(fullpath) : ScanFile(fullpath);
191 }
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700192}
193
194void CFX_FolderFontInfo::ScanFile(const ByteString& path) {
Haibo Huang49cc9302020-04-27 16:14:24 -0700195 std::unique_ptr<FILE, FxFileCloser> pFile(fopen(path.c_str(), "rb"));
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700196 if (!pFile)
197 return;
198
Haibo Huang49cc9302020-04-27 16:14:24 -0700199 fseek(pFile.get(), 0, SEEK_END);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700200
kumarashishg826308d2023-06-23 13:21:22 +0000201 FX_FILESIZE filesize = ftell(pFile.get());
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700202 uint8_t buffer[16];
Haibo Huang49cc9302020-04-27 16:14:24 -0700203 fseek(pFile.get(), 0, SEEK_SET);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700204
Haibo Huang49cc9302020-04-27 16:14:24 -0700205 size_t readCnt = fread(buffer, 12, 1, pFile.get());
206 if (readCnt != 1)
207 return;
208
kumarashishg826308d2023-06-23 13:21:22 +0000209 if (FXSYS_UINT32_GET_MSBFIRST(buffer) != kTableTTCF) {
Haibo Huang49cc9302020-04-27 16:14:24 -0700210 ReportFace(path, pFile.get(), filesize, 0);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700211 return;
212 }
213
kumarashishg826308d2023-06-23 13:21:22 +0000214 uint32_t nFaces = FXSYS_UINT32_GET_MSBFIRST(buffer + 8);
Haibo Huang49cc9302020-04-27 16:14:24 -0700215 FX_SAFE_SIZE_T safe_face_bytes = nFaces;
216 safe_face_bytes *= 4;
217 if (!safe_face_bytes.IsValid())
218 return;
219
220 const size_t face_bytes = safe_face_bytes.ValueOrDie();
221 std::unique_ptr<uint8_t, FxFreeDeleter> offsets(
222 FX_Alloc(uint8_t, face_bytes));
223 readCnt = fread(offsets.get(), 1, face_bytes, pFile.get());
224 if (readCnt != face_bytes)
225 return;
226
227 auto offsets_span = pdfium::make_span(offsets.get(), face_bytes);
kumarashishg826308d2023-06-23 13:21:22 +0000228 for (uint32_t i = 0; i < nFaces; i++) {
229 ReportFace(path, pFile.get(), filesize,
230 FXSYS_UINT32_GET_MSBFIRST(&offsets_span[i * 4]));
231 }
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700232}
233
234void CFX_FolderFontInfo::ReportFace(const ByteString& path,
235 FILE* pFile,
kumarashishg826308d2023-06-23 13:21:22 +0000236 FX_FILESIZE filesize,
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700237 uint32_t offset) {
238 char buffer[16];
239 if (fseek(pFile, offset, SEEK_SET) < 0 || !fread(buffer, 12, 1, pFile))
240 return;
241
kumarashishg826308d2023-06-23 13:21:22 +0000242 uint32_t nTables = FXSYS_UINT16_GET_MSBFIRST(buffer + 4);
Haibo Huang49cc9302020-04-27 16:14:24 -0700243 ByteString tables = ReadStringFromFile(pFile, nTables * 16);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700244 if (tables.IsEmpty())
245 return;
246
kumarashishg826308d2023-06-23 13:21:22 +0000247 static constexpr uint32_t kNameTag =
248 CFX_FontMapper::MakeTag('n', 'a', 'm', 'e');
Haibo Huang49cc9302020-04-27 16:14:24 -0700249 ByteString names =
kumarashishg826308d2023-06-23 13:21:22 +0000250 LoadTableFromTT(pFile, tables.raw_str(), nTables, kNameTag, filesize);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700251 if (names.IsEmpty())
252 return;
253
Haibo Huang49cc9302020-04-27 16:14:24 -0700254 ByteString facename = GetNameFromTT(names.raw_span(), 1);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700255 if (facename.IsEmpty())
256 return;
257
Haibo Huang49cc9302020-04-27 16:14:24 -0700258 ByteString style = GetNameFromTT(names.raw_span(), 2);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700259 if (style != "Regular")
260 facename += " " + style;
261
kumarashishg826308d2023-06-23 13:21:22 +0000262 if (pdfium::Contains(m_FontList, facename))
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700263 return;
264
kumarashishg826308d2023-06-23 13:21:22 +0000265 auto pInfo =
266 std::make_unique<FontFaceInfo>(path, facename, tables, offset, filesize);
267 static constexpr uint32_t kOs2Tag =
268 CFX_FontMapper::MakeTag('O', 'S', '/', '2');
Haibo Huang49cc9302020-04-27 16:14:24 -0700269 ByteString os2 =
kumarashishg826308d2023-06-23 13:21:22 +0000270 LoadTableFromTT(pFile, tables.raw_str(), nTables, kOs2Tag, filesize);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700271 if (os2.GetLength() >= 86) {
272 const uint8_t* p = os2.raw_str() + 78;
kumarashishg826308d2023-06-23 13:21:22 +0000273 uint32_t codepages = FXSYS_UINT32_GET_MSBFIRST(p);
Haibo Huang49cc9302020-04-27 16:14:24 -0700274 if (codepages & (1U << 17)) {
kumarashishg826308d2023-06-23 13:21:22 +0000275 m_pMapper->AddInstalledFont(facename, FX_Charset::kShiftJIS);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700276 pInfo->m_Charsets |= CHARSET_FLAG_SHIFTJIS;
277 }
Haibo Huang49cc9302020-04-27 16:14:24 -0700278 if (codepages & (1U << 18)) {
kumarashishg826308d2023-06-23 13:21:22 +0000279 m_pMapper->AddInstalledFont(facename, FX_Charset::kChineseSimplified);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700280 pInfo->m_Charsets |= CHARSET_FLAG_GB;
281 }
Haibo Huang49cc9302020-04-27 16:14:24 -0700282 if (codepages & (1U << 20)) {
kumarashishg826308d2023-06-23 13:21:22 +0000283 m_pMapper->AddInstalledFont(facename, FX_Charset::kChineseTraditional);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700284 pInfo->m_Charsets |= CHARSET_FLAG_BIG5;
285 }
Haibo Huang49cc9302020-04-27 16:14:24 -0700286 if ((codepages & (1U << 19)) || (codepages & (1U << 21))) {
kumarashishg826308d2023-06-23 13:21:22 +0000287 m_pMapper->AddInstalledFont(facename, FX_Charset::kHangul);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700288 pInfo->m_Charsets |= CHARSET_FLAG_KOREAN;
289 }
Haibo Huang49cc9302020-04-27 16:14:24 -0700290 if (codepages & (1U << 31)) {
kumarashishg826308d2023-06-23 13:21:22 +0000291 m_pMapper->AddInstalledFont(facename, FX_Charset::kSymbol);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700292 pInfo->m_Charsets |= CHARSET_FLAG_SYMBOL;
293 }
294 }
kumarashishg826308d2023-06-23 13:21:22 +0000295 m_pMapper->AddInstalledFont(facename, FX_Charset::kANSI);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700296 pInfo->m_Charsets |= CHARSET_FLAG_ANSI;
297 pInfo->m_Styles = 0;
298 if (style.Contains("Bold"))
Haibo Huang49cc9302020-04-27 16:14:24 -0700299 pInfo->m_Styles |= FXFONT_FORCE_BOLD;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700300 if (style.Contains("Italic") || style.Contains("Oblique"))
301 pInfo->m_Styles |= FXFONT_ITALIC;
302 if (facename.Contains("Serif"))
303 pInfo->m_Styles |= FXFONT_SERIF;
304
305 m_FontList[facename] = std::move(pInfo);
306}
307
308void* CFX_FolderFontInfo::GetSubstFont(const ByteString& face) {
kumarashishg826308d2023-06-23 13:21:22 +0000309 for (size_t iBaseFont = 0; iBaseFont < std::size(Base14Substs); iBaseFont++) {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700310 if (face == Base14Substs[iBaseFont].m_pName)
311 return GetFont(Base14Substs[iBaseFont].m_pSubstName);
312 }
313 return nullptr;
314}
315
316void* CFX_FolderFontInfo::FindFont(int weight,
317 bool bItalic,
kumarashishg826308d2023-06-23 13:21:22 +0000318 FX_Charset charset,
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700319 int pitch_family,
kumarashishg826308d2023-06-23 13:21:22 +0000320 const ByteString& family,
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700321 bool bMatchName) {
322 FontFaceInfo* pFind = nullptr;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700323
kumarashishg826308d2023-06-23 13:21:22 +0000324 ByteStringView bsFamily = family.AsStringView();
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700325 uint32_t charset_flag = GetCharset(charset);
326 int32_t iBestSimilar = 0;
327 for (const auto& it : m_FontList) {
328 const ByteString& bsName = it.first;
329 FontFaceInfo* pFont = it.second.get();
kumarashishg826308d2023-06-23 13:21:22 +0000330 if (!(pFont->m_Charsets & charset_flag) && charset != FX_Charset::kDefault)
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700331 continue;
332
kumarashishg826308d2023-06-23 13:21:22 +0000333 if (bMatchName && !FindFamilyNameMatch(bsFamily, bsName))
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700334 continue;
335
336 int32_t iSimilarValue =
kumarashishg826308d2023-06-23 13:21:22 +0000337 GetSimilarValue(weight, bItalic, pitch_family, pFont->m_Styles,
338 bMatchName, bsFamily.GetLength(), bsName.GetLength());
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700339 if (iSimilarValue > iBestSimilar) {
340 iBestSimilar = iSimilarValue;
341 pFind = pFont;
342 }
343 }
kumarashishg826308d2023-06-23 13:21:22 +0000344
345 if (pFind) {
346 return pFind;
347 }
348
349 if (charset == FX_Charset::kANSI && FontFamilyIsFixedPitch(pitch_family)) {
350 auto* courier_new = GetFont("Courier New");
351 if (courier_new)
352 return courier_new;
353 }
354
355 return nullptr;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700356}
357
358void* CFX_FolderFontInfo::MapFont(int weight,
359 bool bItalic,
kumarashishg826308d2023-06-23 13:21:22 +0000360 FX_Charset charset,
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700361 int pitch_family,
kumarashishg826308d2023-06-23 13:21:22 +0000362 const ByteString& face) {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700363 return nullptr;
364}
365
kumarashishg826308d2023-06-23 13:21:22 +0000366void* CFX_FolderFontInfo::GetFont(const ByteString& face) {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700367 auto it = m_FontList.find(face);
368 return it != m_FontList.end() ? it->second.get() : nullptr;
369}
370
kumarashishg826308d2023-06-23 13:21:22 +0000371size_t CFX_FolderFontInfo::GetFontData(void* hFont,
372 uint32_t table,
373 pdfium::span<uint8_t> buffer) {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700374 if (!hFont)
375 return 0;
376
377 const FontFaceInfo* pFont = static_cast<FontFaceInfo*>(hFont);
378 uint32_t datasize = 0;
379 uint32_t offset = 0;
380 if (table == 0) {
381 datasize = pFont->m_FontOffset ? 0 : pFont->m_FileSize;
382 } else if (table == kTableTTCF) {
383 datasize = pFont->m_FontOffset ? pFont->m_FileSize : 0;
384 } else {
kumarashishg826308d2023-06-23 13:21:22 +0000385 size_t nTables = pFont->m_FontTables.GetLength() / 16;
386 for (size_t i = 0; i < nTables; i++) {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700387 const uint8_t* p = pFont->m_FontTables.raw_str() + i * 16;
kumarashishg826308d2023-06-23 13:21:22 +0000388 if (FXSYS_UINT32_GET_MSBFIRST(p) == table) {
389 offset = FXSYS_UINT32_GET_MSBFIRST(p + 8);
390 datasize = FXSYS_UINT32_GET_MSBFIRST(p + 12);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700391 }
392 }
393 }
394
Haibo Huang49cc9302020-04-27 16:14:24 -0700395 if (!datasize || buffer.size() < datasize)
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700396 return datasize;
397
Haibo Huang49cc9302020-04-27 16:14:24 -0700398 std::unique_ptr<FILE, FxFileCloser> pFile(
399 fopen(pFont->m_FilePath.c_str(), "rb"));
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700400 if (!pFile)
401 return 0;
402
Haibo Huang49cc9302020-04-27 16:14:24 -0700403 if (fseek(pFile.get(), offset, SEEK_SET) < 0 ||
404 fread(buffer.data(), datasize, 1, pFile.get()) != 1) {
405 return 0;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700406 }
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700407 return datasize;
408}
409
410void CFX_FolderFontInfo::DeleteFont(void* hFont) {}
411
412bool CFX_FolderFontInfo::GetFaceName(void* hFont, ByteString* name) {
413 if (!hFont)
414 return false;
415 *name = static_cast<FontFaceInfo*>(hFont)->m_FaceName;
416 return true;
417}
418
kumarashishg826308d2023-06-23 13:21:22 +0000419bool CFX_FolderFontInfo::GetFontCharset(void* hFont, FX_Charset* charset) {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700420 return false;
421}
422
423CFX_FolderFontInfo::FontFaceInfo::FontFaceInfo(ByteString filePath,
424 ByteString faceName,
425 ByteString fontTables,
426 uint32_t fontOffset,
427 uint32_t fileSize)
428 : m_FilePath(filePath),
429 m_FaceName(faceName),
430 m_FontTables(fontTables),
431 m_FontOffset(fontOffset),
kumarashishg826308d2023-06-23 13:21:22 +0000432 m_FileSize(fileSize) {}