OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fxge/fx_font.h" | 7 #include "core/fxge/fx_font.h" |
8 | 8 |
9 #include "core/fpdfapi/font/cpdf_font.h" | 9 #include "core/fpdfapi/font/cpdf_font.h" |
10 #include "core/fxge/cfx_facecache.h" | 10 #include "core/fxge/cfx_facecache.h" |
11 #include "core/fxge/cfx_fontcache.h" | 11 #include "core/fxge/cfx_fontcache.h" |
12 #include "core/fxge/cfx_fontmgr.h" | 12 #include "core/fxge/cfx_fontmgr.h" |
13 #include "core/fxge/cfx_gemodule.h" | 13 #include "core/fxge/cfx_gemodule.h" |
14 #include "core/fxge/cfx_pathdata.h" | 14 #include "core/fxge/cfx_pathdata.h" |
15 #include "core/fxge/cfx_substfont.h" | 15 #include "core/fxge/cfx_substfont.h" |
16 #include "core/fxge/fx_freetype.h" | 16 #include "core/fxge/fx_freetype.h" |
17 #include "core/fxge/ge/fx_text_int.h" | 17 #include "core/fxge/ge/fx_text_int.h" |
18 #include "third_party/base/ptr_util.h" | 18 #include "third_party/base/ptr_util.h" |
19 | 19 |
20 #define EM_ADJUST(em, a) (em == 0 ? (a) : (a)*1000 / em) | 20 #define EM_ADJUST(em, a) (em == 0 ? (a) : (a)*1000 / em) |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 typedef struct { | 24 typedef struct { |
25 FX_BOOL m_bCount; | 25 bool m_bCount; |
26 int m_PointCount; | 26 int m_PointCount; |
27 FX_PATHPOINT* m_pPoints; | 27 FX_PATHPOINT* m_pPoints; |
28 int m_CurX; | 28 int m_CurX; |
29 int m_CurY; | 29 int m_CurY; |
30 FX_FLOAT m_CoordUnit; | 30 FX_FLOAT m_CoordUnit; |
31 } OUTLINE_PARAMS; | 31 } OUTLINE_PARAMS; |
32 | 32 |
33 #ifdef PDF_ENABLE_XFA | 33 #ifdef PDF_ENABLE_XFA |
34 | 34 |
35 unsigned long FTStreamRead(FXFT_Stream stream, | 35 unsigned long FTStreamRead(FXFT_Stream stream, |
36 unsigned long offset, | 36 unsigned long offset, |
37 unsigned char* buffer, | 37 unsigned char* buffer, |
38 unsigned long count) { | 38 unsigned long count) { |
39 if (count == 0) | 39 if (count == 0) |
40 return 0; | 40 return 0; |
41 | 41 |
42 IFX_SeekableReadStream* pFile = | 42 IFX_SeekableReadStream* pFile = |
43 static_cast<IFX_SeekableReadStream*>(stream->descriptor.pointer); | 43 static_cast<IFX_SeekableReadStream*>(stream->descriptor.pointer); |
44 return pFile->ReadBlock(buffer, offset, count) ? count : 0; | 44 return pFile->ReadBlock(buffer, offset, count) ? count : 0; |
45 } | 45 } |
46 | 46 |
47 void FTStreamClose(FXFT_Stream stream) {} | 47 void FTStreamClose(FXFT_Stream stream) {} |
48 | 48 |
49 FX_BOOL LoadFileImp(FXFT_Library library, | 49 bool LoadFileImp(FXFT_Library library, |
50 FXFT_Face* Face, | 50 FXFT_Face* Face, |
51 IFX_SeekableReadStream* pFile, | 51 IFX_SeekableReadStream* pFile, |
52 int32_t faceIndex, | 52 int32_t faceIndex, |
53 std::unique_ptr<FXFT_StreamRec>* stream) { | 53 std::unique_ptr<FXFT_StreamRec>* stream) { |
54 std::unique_ptr<FXFT_StreamRec> stream1(new FXFT_StreamRec()); | 54 std::unique_ptr<FXFT_StreamRec> stream1(new FXFT_StreamRec()); |
55 stream1->base = nullptr; | 55 stream1->base = nullptr; |
56 stream1->size = static_cast<unsigned long>(pFile->GetSize()); | 56 stream1->size = static_cast<unsigned long>(pFile->GetSize()); |
57 stream1->pos = 0; | 57 stream1->pos = 0; |
58 stream1->descriptor.pointer = pFile; | 58 stream1->descriptor.pointer = pFile; |
59 stream1->close = FTStreamClose; | 59 stream1->close = FTStreamClose; |
60 stream1->read = FTStreamRead; | 60 stream1->read = FTStreamRead; |
61 FXFT_Open_Args args; | 61 FXFT_Open_Args args; |
62 args.flags = FT_OPEN_STREAM; | 62 args.flags = FT_OPEN_STREAM; |
63 args.stream = stream1.get(); | 63 args.stream = stream1.get(); |
64 if (FXFT_Open_Face(library, &args, faceIndex, Face)) | 64 if (FXFT_Open_Face(library, &args, faceIndex, Face)) |
65 return FALSE; | 65 return false; |
66 if (stream) | 66 if (stream) |
67 *stream = std::move(stream1); | 67 *stream = std::move(stream1); |
68 return TRUE; | 68 return true; |
69 } | 69 } |
70 #endif // PDF_ENABLE_XFA | 70 #endif // PDF_ENABLE_XFA |
71 | 71 |
72 FXFT_Face FT_LoadFont(const uint8_t* pData, int size) { | 72 FXFT_Face FT_LoadFont(const uint8_t* pData, int size) { |
73 return CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(pData, size, 0); | 73 return CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(pData, size, 0); |
74 } | 74 } |
75 | 75 |
76 void Outline_CheckEmptyContour(OUTLINE_PARAMS* param) { | 76 void Outline_CheckEmptyContour(OUTLINE_PARAMS* param) { |
77 if (param->m_PointCount >= 2 && | 77 if (param->m_PointCount >= 2 && |
78 param->m_pPoints[param->m_PointCount - 2].m_Flag == FXPT_MOVETO && | 78 param->m_pPoints[param->m_PointCount - 2].m_Flag == FXPT_MOVETO && |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 m_pGsubData(nullptr), | 233 m_pGsubData(nullptr), |
234 m_dwSize(0), | 234 m_dwSize(0), |
235 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 235 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
236 m_pPlatformFont(nullptr), | 236 m_pPlatformFont(nullptr), |
237 #endif | 237 #endif |
238 m_bEmbedded(false), | 238 m_bEmbedded(false), |
239 m_bVertical(false) { | 239 m_bVertical(false) { |
240 } | 240 } |
241 | 241 |
242 #ifdef PDF_ENABLE_XFA | 242 #ifdef PDF_ENABLE_XFA |
243 FX_BOOL CFX_Font::LoadClone(const CFX_Font* pFont) { | 243 bool CFX_Font::LoadClone(const CFX_Font* pFont) { |
244 if (!pFont) | 244 if (!pFont) |
245 return FALSE; | 245 return false; |
246 | 246 |
247 m_bShallowCopy = true; | 247 m_bShallowCopy = true; |
248 if (pFont->m_pSubstFont) { | 248 if (pFont->m_pSubstFont) { |
249 m_pSubstFont = pdfium::MakeUnique<CFX_SubstFont>(); | 249 m_pSubstFont = pdfium::MakeUnique<CFX_SubstFont>(); |
250 m_pSubstFont->m_Charset = pFont->m_pSubstFont->m_Charset; | 250 m_pSubstFont->m_Charset = pFont->m_pSubstFont->m_Charset; |
251 m_pSubstFont->m_SubstFlags = pFont->m_pSubstFont->m_SubstFlags; | 251 m_pSubstFont->m_SubstFlags = pFont->m_pSubstFont->m_SubstFlags; |
252 m_pSubstFont->m_Weight = pFont->m_pSubstFont->m_Weight; | 252 m_pSubstFont->m_Weight = pFont->m_pSubstFont->m_Weight; |
253 m_pSubstFont->m_Family = pFont->m_pSubstFont->m_Family; | 253 m_pSubstFont->m_Family = pFont->m_pSubstFont->m_Family; |
254 m_pSubstFont->m_ItalicAngle = pFont->m_pSubstFont->m_ItalicAngle; | 254 m_pSubstFont->m_ItalicAngle = pFont->m_pSubstFont->m_ItalicAngle; |
255 } | 255 } |
256 if (pFont->m_OtfFontData.GetSize()) { | 256 if (pFont->m_OtfFontData.GetSize()) { |
257 m_OtfFontData.AttachData(pFont->m_OtfFontData.GetBuffer(), | 257 m_OtfFontData.AttachData(pFont->m_OtfFontData.GetBuffer(), |
258 pFont->m_OtfFontData.GetSize()); | 258 pFont->m_OtfFontData.GetSize()); |
259 } | 259 } |
260 m_Face = pFont->m_Face; | 260 m_Face = pFont->m_Face; |
261 m_bEmbedded = pFont->m_bEmbedded; | 261 m_bEmbedded = pFont->m_bEmbedded; |
262 m_bVertical = pFont->m_bVertical; | 262 m_bVertical = pFont->m_bVertical; |
263 m_dwSize = pFont->m_dwSize; | 263 m_dwSize = pFont->m_dwSize; |
264 m_pFontData = pFont->m_pFontData; | 264 m_pFontData = pFont->m_pFontData; |
265 m_pGsubData = pFont->m_pGsubData; | 265 m_pGsubData = pFont->m_pGsubData; |
266 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 266 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
267 m_pPlatformFont = pFont->m_pPlatformFont; | 267 m_pPlatformFont = pFont->m_pPlatformFont; |
268 #endif | 268 #endif |
269 m_pOwnedStream = pFont->m_pOwnedStream; | 269 m_pOwnedStream = pFont->m_pOwnedStream; |
270 m_FaceCache = pFont->GetFaceCache(); | 270 m_FaceCache = pFont->GetFaceCache(); |
271 return TRUE; | 271 return true; |
272 } | 272 } |
273 | 273 |
274 void CFX_Font::SetFace(FXFT_Face face) { | 274 void CFX_Font::SetFace(FXFT_Face face) { |
275 ClearFaceCache(); | 275 ClearFaceCache(); |
276 m_Face = face; | 276 m_Face = face; |
277 } | 277 } |
278 | 278 |
279 #endif // PDF_ENABLE_XFA | 279 #endif // PDF_ENABLE_XFA |
280 | 280 |
281 CFX_Font::~CFX_Font() { | 281 CFX_Font::~CFX_Font() { |
(...skipping 24 matching lines...) Expand all Loading... |
306 ClearFaceCache(); | 306 ClearFaceCache(); |
307 if (m_bEmbedded) { | 307 if (m_bEmbedded) { |
308 FXFT_Done_Face(m_Face); | 308 FXFT_Done_Face(m_Face); |
309 } else { | 309 } else { |
310 CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face); | 310 CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face); |
311 } | 311 } |
312 m_Face = nullptr; | 312 m_Face = nullptr; |
313 } | 313 } |
314 | 314 |
315 void CFX_Font::LoadSubst(const CFX_ByteString& face_name, | 315 void CFX_Font::LoadSubst(const CFX_ByteString& face_name, |
316 FX_BOOL bTrueType, | 316 bool bTrueType, |
317 uint32_t flags, | 317 uint32_t flags, |
318 int weight, | 318 int weight, |
319 int italic_angle, | 319 int italic_angle, |
320 int CharsetCP, | 320 int CharsetCP, |
321 bool bVertical) { | 321 bool bVertical) { |
322 m_bEmbedded = false; | 322 m_bEmbedded = false; |
323 m_bVertical = bVertical; | 323 m_bVertical = bVertical; |
324 m_pSubstFont = pdfium::MakeUnique<CFX_SubstFont>(); | 324 m_pSubstFont = pdfium::MakeUnique<CFX_SubstFont>(); |
325 m_Face = CFX_GEModule::Get()->GetFontMgr()->FindSubstFont( | 325 m_Face = CFX_GEModule::Get()->GetFontMgr()->FindSubstFont( |
326 face_name, bTrueType, flags, weight, italic_angle, CharsetCP, | 326 face_name, bTrueType, flags, weight, italic_angle, CharsetCP, |
327 m_pSubstFont.get()); | 327 m_pSubstFont.get()); |
328 if (m_Face) { | 328 if (m_Face) { |
329 m_pFontData = FXFT_Get_Face_Stream_Base(m_Face); | 329 m_pFontData = FXFT_Get_Face_Stream_Base(m_Face); |
330 m_dwSize = FXFT_Get_Face_Stream_Size(m_Face); | 330 m_dwSize = FXFT_Get_Face_Stream_Size(m_Face); |
331 } | 331 } |
332 } | 332 } |
333 | 333 |
334 #ifdef PDF_ENABLE_XFA | 334 #ifdef PDF_ENABLE_XFA |
335 FX_BOOL CFX_Font::LoadFile(IFX_SeekableReadStream* pFile, | 335 bool CFX_Font::LoadFile(IFX_SeekableReadStream* pFile, |
336 int nFaceIndex, | 336 int nFaceIndex, |
337 int* pFaceCount) { | 337 int* pFaceCount) { |
338 m_bEmbedded = FALSE; | 338 m_bEmbedded = false; |
339 | 339 |
340 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); | 340 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); |
341 pFontMgr->InitFTLibrary(); | 341 pFontMgr->InitFTLibrary(); |
342 FXFT_Library library = pFontMgr->GetFTLibrary(); | 342 FXFT_Library library = pFontMgr->GetFTLibrary(); |
343 | 343 |
344 std::unique_ptr<FXFT_StreamRec> stream; | 344 std::unique_ptr<FXFT_StreamRec> stream; |
345 if (!LoadFileImp(library, &m_Face, pFile, nFaceIndex, &stream)) | 345 if (!LoadFileImp(library, &m_Face, pFile, nFaceIndex, &stream)) |
346 return FALSE; | 346 return false; |
347 | 347 |
348 if (pFaceCount) | 348 if (pFaceCount) |
349 *pFaceCount = (int)m_Face->num_faces; | 349 *pFaceCount = (int)m_Face->num_faces; |
350 m_pOwnedStream = stream.release(); | 350 m_pOwnedStream = stream.release(); |
351 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); | 351 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); |
352 return TRUE; | 352 return true; |
353 } | 353 } |
354 #endif // PDF_ENABLE_XFA | 354 #endif // PDF_ENABLE_XFA |
355 | 355 |
356 int CFX_Font::GetGlyphWidth(uint32_t glyph_index) { | 356 int CFX_Font::GetGlyphWidth(uint32_t glyph_index) { |
357 if (!m_Face) | 357 if (!m_Face) |
358 return 0; | 358 return 0; |
359 if (m_pSubstFont && (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM)) | 359 if (m_pSubstFont && (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM)) |
360 AdjustMMParams(glyph_index, 0, 0); | 360 AdjustMMParams(glyph_index, 0, 0); |
361 int err = FXFT_Load_Glyph( | 361 int err = FXFT_Load_Glyph( |
362 m_Face, glyph_index, | 362 m_Face, glyph_index, |
363 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); | 363 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); |
364 if (err) | 364 if (err) |
365 return 0; | 365 return 0; |
366 int width = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), | 366 int width = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), |
367 FXFT_Get_Glyph_HoriAdvance(m_Face)); | 367 FXFT_Get_Glyph_HoriAdvance(m_Face)); |
368 return width; | 368 return width; |
369 } | 369 } |
370 | 370 |
371 FX_BOOL CFX_Font::LoadEmbedded(const uint8_t* data, uint32_t size) { | 371 bool CFX_Font::LoadEmbedded(const uint8_t* data, uint32_t size) { |
372 std::vector<uint8_t> temp(data, data + size); | 372 std::vector<uint8_t> temp(data, data + size); |
373 m_pFontDataAllocation.swap(temp); | 373 m_pFontDataAllocation.swap(temp); |
374 m_Face = FT_LoadFont(m_pFontDataAllocation.data(), size); | 374 m_Face = FT_LoadFont(m_pFontDataAllocation.data(), size); |
375 m_pFontData = m_pFontDataAllocation.data(); | 375 m_pFontData = m_pFontDataAllocation.data(); |
376 m_bEmbedded = true; | 376 m_bEmbedded = true; |
377 m_dwSize = size; | 377 m_dwSize = size; |
378 return !!m_Face; | 378 return !!m_Face; |
379 } | 379 } |
380 | 380 |
381 bool CFX_Font::IsTTFont() const { | 381 bool CFX_Font::IsTTFont() const { |
382 if (!m_Face) | 382 if (!m_Face) |
383 return false; | 383 return false; |
384 return FXFT_Is_Face_TT_OT(m_Face) == FXFT_FACE_FLAG_SFNT; | 384 return FXFT_Is_Face_TT_OT(m_Face) == FXFT_FACE_FLAG_SFNT; |
385 } | 385 } |
386 | 386 |
387 int CFX_Font::GetAscent() const { | 387 int CFX_Font::GetAscent() const { |
388 if (!m_Face) | 388 if (!m_Face) |
389 return 0; | 389 return 0; |
390 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), | 390 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), |
391 FXFT_Get_Face_Ascender(m_Face)); | 391 FXFT_Get_Face_Ascender(m_Face)); |
392 } | 392 } |
393 | 393 |
394 int CFX_Font::GetDescent() const { | 394 int CFX_Font::GetDescent() const { |
395 if (!m_Face) | 395 if (!m_Face) |
396 return 0; | 396 return 0; |
397 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), | 397 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), |
398 FXFT_Get_Face_Descender(m_Face)); | 398 FXFT_Get_Face_Descender(m_Face)); |
399 } | 399 } |
400 | 400 |
401 FX_BOOL CFX_Font::GetGlyphBBox(uint32_t glyph_index, FX_RECT& bbox) { | 401 bool CFX_Font::GetGlyphBBox(uint32_t glyph_index, FX_RECT& bbox) { |
402 if (!m_Face) | 402 if (!m_Face) |
403 return FALSE; | 403 return false; |
404 | 404 |
405 if (FXFT_Is_Face_Tricky(m_Face)) { | 405 if (FXFT_Is_Face_Tricky(m_Face)) { |
406 int error = FXFT_Set_Char_Size(m_Face, 0, 1000 * 64, 72, 72); | 406 int error = FXFT_Set_Char_Size(m_Face, 0, 1000 * 64, 72, 72); |
407 if (error) | 407 if (error) |
408 return FALSE; | 408 return false; |
409 error = FXFT_Load_Glyph(m_Face, glyph_index, | 409 error = FXFT_Load_Glyph(m_Face, glyph_index, |
410 FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); | 410 FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); |
411 if (error) | 411 if (error) |
412 return FALSE; | 412 return false; |
413 FXFT_BBox cbox; | 413 FXFT_BBox cbox; |
414 FT_Glyph glyph; | 414 FT_Glyph glyph; |
415 error = FXFT_Get_Glyph(((FXFT_Face)m_Face)->glyph, &glyph); | 415 error = FXFT_Get_Glyph(((FXFT_Face)m_Face)->glyph, &glyph); |
416 if (error) | 416 if (error) |
417 return FALSE; | 417 return false; |
418 FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); | 418 FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); |
419 int pixel_size_x = ((FXFT_Face)m_Face)->size->metrics.x_ppem, | 419 int pixel_size_x = ((FXFT_Face)m_Face)->size->metrics.x_ppem, |
420 pixel_size_y = ((FXFT_Face)m_Face)->size->metrics.y_ppem; | 420 pixel_size_y = ((FXFT_Face)m_Face)->size->metrics.y_ppem; |
421 if (pixel_size_x == 0 || pixel_size_y == 0) { | 421 if (pixel_size_x == 0 || pixel_size_y == 0) { |
422 bbox.left = cbox.xMin; | 422 bbox.left = cbox.xMin; |
423 bbox.right = cbox.xMax; | 423 bbox.right = cbox.xMax; |
424 bbox.top = cbox.yMax; | 424 bbox.top = cbox.yMax; |
425 bbox.bottom = cbox.yMin; | 425 bbox.bottom = cbox.yMin; |
426 } else { | 426 } else { |
427 bbox.left = cbox.xMin * 1000 / pixel_size_x; | 427 bbox.left = cbox.xMin * 1000 / pixel_size_x; |
428 bbox.right = cbox.xMax * 1000 / pixel_size_x; | 428 bbox.right = cbox.xMax * 1000 / pixel_size_x; |
429 bbox.top = cbox.yMax * 1000 / pixel_size_y; | 429 bbox.top = cbox.yMax * 1000 / pixel_size_y; |
430 bbox.bottom = cbox.yMin * 1000 / pixel_size_y; | 430 bbox.bottom = cbox.yMin * 1000 / pixel_size_y; |
431 } | 431 } |
432 if (bbox.top > FXFT_Get_Face_Ascender(m_Face)) | 432 if (bbox.top > FXFT_Get_Face_Ascender(m_Face)) |
433 bbox.top = FXFT_Get_Face_Ascender(m_Face); | 433 bbox.top = FXFT_Get_Face_Ascender(m_Face); |
434 if (bbox.bottom < FXFT_Get_Face_Descender(m_Face)) | 434 if (bbox.bottom < FXFT_Get_Face_Descender(m_Face)) |
435 bbox.bottom = FXFT_Get_Face_Descender(m_Face); | 435 bbox.bottom = FXFT_Get_Face_Descender(m_Face); |
436 FT_Done_Glyph(glyph); | 436 FT_Done_Glyph(glyph); |
437 return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0; | 437 return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0; |
438 } | 438 } |
439 if (FXFT_Load_Glyph( | 439 if (FXFT_Load_Glyph( |
440 m_Face, glyph_index, | 440 m_Face, glyph_index, |
441 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) { | 441 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) { |
442 return FALSE; | 442 return false; |
443 } | 443 } |
444 int em = FXFT_Get_Face_UnitsPerEM(m_Face); | 444 int em = FXFT_Get_Face_UnitsPerEM(m_Face); |
445 if (em == 0) { | 445 if (em == 0) { |
446 bbox.left = FXFT_Get_Glyph_HoriBearingX(m_Face); | 446 bbox.left = FXFT_Get_Glyph_HoriBearingX(m_Face); |
447 bbox.bottom = FXFT_Get_Glyph_HoriBearingY(m_Face); | 447 bbox.bottom = FXFT_Get_Glyph_HoriBearingY(m_Face); |
448 bbox.top = bbox.bottom - FXFT_Get_Glyph_Height(m_Face); | 448 bbox.top = bbox.bottom - FXFT_Get_Glyph_Height(m_Face); |
449 bbox.right = bbox.left + FXFT_Get_Glyph_Width(m_Face); | 449 bbox.right = bbox.left + FXFT_Get_Glyph_Width(m_Face); |
450 } else { | 450 } else { |
451 bbox.left = FXFT_Get_Glyph_HoriBearingX(m_Face) * 1000 / em; | 451 bbox.left = FXFT_Get_Glyph_HoriBearingX(m_Face) * 1000 / em; |
452 bbox.top = | 452 bbox.top = |
453 (FXFT_Get_Glyph_HoriBearingY(m_Face) - FXFT_Get_Glyph_Height(m_Face)) * | 453 (FXFT_Get_Glyph_HoriBearingY(m_Face) - FXFT_Get_Glyph_Height(m_Face)) * |
454 1000 / em; | 454 1000 / em; |
455 bbox.right = | 455 bbox.right = |
456 (FXFT_Get_Glyph_HoriBearingX(m_Face) + FXFT_Get_Glyph_Width(m_Face)) * | 456 (FXFT_Get_Glyph_HoriBearingX(m_Face) + FXFT_Get_Glyph_Width(m_Face)) * |
457 1000 / em; | 457 1000 / em; |
458 bbox.bottom = (FXFT_Get_Glyph_HoriBearingY(m_Face)) * 1000 / em; | 458 bbox.bottom = (FXFT_Get_Glyph_HoriBearingY(m_Face)) * 1000 / em; |
459 } | 459 } |
460 return TRUE; | 460 return true; |
461 } | 461 } |
462 | 462 |
463 bool CFX_Font::IsItalic() const { | 463 bool CFX_Font::IsItalic() const { |
464 if (!m_Face) | 464 if (!m_Face) |
465 return false; | 465 return false; |
466 | 466 |
467 if (FXFT_Is_Face_Italic(m_Face) == FXFT_STYLE_FLAG_ITALIC) | 467 if (FXFT_Is_Face_Italic(m_Face) == FXFT_STYLE_FLAG_ITALIC) |
468 return true; | 468 return true; |
469 CFX_ByteString str(FXFT_Get_Face_Style_Name(m_Face)); | 469 CFX_ByteString str(FXFT_Get_Face_Style_Name(m_Face)); |
470 str.MakeLower(); | 470 str.MakeLower(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 facename = GetFamilyName(); | 510 facename = GetFamilyName(); |
511 if (facename.IsEmpty()) | 511 if (facename.IsEmpty()) |
512 facename = "Untitled"; | 512 facename = "Untitled"; |
513 if (!style.IsEmpty() && style != "Regular") | 513 if (!style.IsEmpty() && style != "Regular") |
514 facename += " " + style; | 514 facename += " " + style; |
515 return facename; | 515 return facename; |
516 } | 516 } |
517 return m_pSubstFont->m_Family; | 517 return m_pSubstFont->m_Family; |
518 } | 518 } |
519 | 519 |
520 FX_BOOL CFX_Font::GetBBox(FX_RECT& bbox) { | 520 bool CFX_Font::GetBBox(FX_RECT& bbox) { |
521 if (!m_Face) | 521 if (!m_Face) |
522 return FALSE; | 522 return false; |
523 int em = FXFT_Get_Face_UnitsPerEM(m_Face); | 523 int em = FXFT_Get_Face_UnitsPerEM(m_Face); |
524 if (em == 0) { | 524 if (em == 0) { |
525 bbox.left = FXFT_Get_Face_xMin(m_Face); | 525 bbox.left = FXFT_Get_Face_xMin(m_Face); |
526 bbox.bottom = FXFT_Get_Face_yMax(m_Face); | 526 bbox.bottom = FXFT_Get_Face_yMax(m_Face); |
527 bbox.top = FXFT_Get_Face_yMin(m_Face); | 527 bbox.top = FXFT_Get_Face_yMin(m_Face); |
528 bbox.right = FXFT_Get_Face_xMax(m_Face); | 528 bbox.right = FXFT_Get_Face_xMax(m_Face); |
529 } else { | 529 } else { |
530 bbox.left = FXFT_Get_Face_xMin(m_Face) * 1000 / em; | 530 bbox.left = FXFT_Get_Face_xMin(m_Face) * 1000 / em; |
531 bbox.top = FXFT_Get_Face_yMin(m_Face) * 1000 / em; | 531 bbox.top = FXFT_Get_Face_yMin(m_Face) * 1000 / em; |
532 bbox.right = FXFT_Get_Face_xMax(m_Face) * 1000 / em; | 532 bbox.right = FXFT_Get_Face_xMax(m_Face) * 1000 / em; |
533 bbox.bottom = FXFT_Get_Face_yMax(m_Face) * 1000 / em; | 533 bbox.bottom = FXFT_Get_Face_yMax(m_Face) * 1000 / em; |
534 } | 534 } |
535 return TRUE; | 535 return true; |
536 } | 536 } |
537 | 537 |
538 int CFX_Font::GetHeight() const { | 538 int CFX_Font::GetHeight() const { |
539 if (!m_Face) | 539 if (!m_Face) |
540 return 0; | 540 return 0; |
541 | 541 |
542 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), | 542 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), |
543 FXFT_Get_Face_Height(m_Face)); | 543 FXFT_Get_Face_Height(m_Face)); |
544 } | 544 } |
545 | 545 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level); | 667 FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level); |
668 } | 668 } |
669 FXFT_Outline_Funcs funcs; | 669 FXFT_Outline_Funcs funcs; |
670 funcs.move_to = Outline_MoveTo; | 670 funcs.move_to = Outline_MoveTo; |
671 funcs.line_to = Outline_LineTo; | 671 funcs.line_to = Outline_LineTo; |
672 funcs.conic_to = Outline_ConicTo; | 672 funcs.conic_to = Outline_ConicTo; |
673 funcs.cubic_to = Outline_CubicTo; | 673 funcs.cubic_to = Outline_CubicTo; |
674 funcs.shift = 0; | 674 funcs.shift = 0; |
675 funcs.delta = 0; | 675 funcs.delta = 0; |
676 OUTLINE_PARAMS params; | 676 OUTLINE_PARAMS params; |
677 params.m_bCount = TRUE; | 677 params.m_bCount = true; |
678 params.m_PointCount = 0; | 678 params.m_PointCount = 0; |
679 FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, ¶ms); | 679 FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, ¶ms); |
680 if (params.m_PointCount == 0) | 680 if (params.m_PointCount == 0) |
681 return nullptr; | 681 return nullptr; |
682 CFX_PathData* pPath = new CFX_PathData; | 682 CFX_PathData* pPath = new CFX_PathData; |
683 pPath->SetPointCount(params.m_PointCount); | 683 pPath->SetPointCount(params.m_PointCount); |
684 params.m_bCount = FALSE; | 684 params.m_bCount = false; |
685 params.m_PointCount = 0; | 685 params.m_PointCount = 0; |
686 params.m_pPoints = pPath->GetPoints(); | 686 params.m_pPoints = pPath->GetPoints(); |
687 params.m_CurX = params.m_CurY = 0; | 687 params.m_CurX = params.m_CurY = 0; |
688 params.m_CoordUnit = 64 * 64.0; | 688 params.m_CoordUnit = 64 * 64.0; |
689 FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, ¶ms); | 689 FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, ¶ms); |
690 Outline_CheckEmptyContour(¶ms); | 690 Outline_CheckEmptyContour(¶ms); |
691 pPath->TrimPoints(params.m_PointCount); | 691 pPath->TrimPoints(params.m_PointCount); |
692 if (params.m_PointCount) | 692 if (params.m_PointCount) |
693 pPath->GetPoints()[params.m_PointCount - 1].m_Flag |= FXPT_CLOSEFIGURE; | 693 pPath->GetPoints()[params.m_PointCount - 1].m_Flag |= FXPT_CLOSEFIGURE; |
694 return pPath; | 694 return pPath; |
695 } | 695 } |
696 | 696 |
697 const CFX_GlyphBitmap* CFX_Font::LoadGlyphBitmap(uint32_t glyph_index, | 697 const CFX_GlyphBitmap* CFX_Font::LoadGlyphBitmap(uint32_t glyph_index, |
698 FX_BOOL bFontStyle, | 698 bool bFontStyle, |
699 const CFX_Matrix* pMatrix, | 699 const CFX_Matrix* pMatrix, |
700 int dest_width, | 700 int dest_width, |
701 int anti_alias, | 701 int anti_alias, |
702 int& text_flags) const { | 702 int& text_flags) const { |
703 return GetFaceCache()->LoadGlyphBitmap(this, glyph_index, bFontStyle, pMatrix, | 703 return GetFaceCache()->LoadGlyphBitmap(this, glyph_index, bFontStyle, pMatrix, |
704 dest_width, anti_alias, text_flags); | 704 dest_width, anti_alias, text_flags); |
705 } | 705 } |
706 | 706 |
707 const CFX_PathData* CFX_Font::LoadGlyphPath(uint32_t glyph_index, | 707 const CFX_PathData* CFX_Font::LoadGlyphPath(uint32_t glyph_index, |
708 int dest_width) const { | 708 int dest_width) const { |
709 return GetFaceCache()->LoadGlyphPath(this, glyph_index, dest_width); | 709 return GetFaceCache()->LoadGlyphPath(this, glyph_index, dest_width); |
710 } | 710 } |
711 | 711 |
712 #ifdef _SKIA_SUPPORT_ | 712 #ifdef _SKIA_SUPPORT_ |
713 CFX_TypeFace* CFX_Font::GetDeviceCache() const { | 713 CFX_TypeFace* CFX_Font::GetDeviceCache() const { |
714 return GetFaceCache()->GetDeviceCache(this); | 714 return GetFaceCache()->GetDeviceCache(this); |
715 } | 715 } |
716 #endif | 716 #endif |
OLD | NEW |