Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: core/src/fxge/ge/fx_ge_font.cpp

Issue 1411833003: XFA: Manually apply changes to fpdf_text.h and fx_font.h from master (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Fix NULL comparisons. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fpdftext/text_int.h ('k') | xfa/src/fdp/src/fde/fde_gedevice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "../../../include/fxge/fx_ge.h" 7 #include "../../../include/fxge/fx_ge.h"
8 #include "../../../include/fxge/fx_freetype.h" 8 #include "../../../include/fxge/fx_freetype.h"
9 #include "text_int.h" 9 #include "text_int.h"
10 10
(...skipping 16 matching lines...) Expand all
27 FXFM_ENCODING_ADOBE_STANDARD, 27 FXFM_ENCODING_ADOBE_STANDARD,
28 FXFM_ENCODING_ADOBE_EXPERT, 28 FXFM_ENCODING_ADOBE_EXPERT,
29 FXFM_ENCODING_ADOBE_CUSTOM, 29 FXFM_ENCODING_ADOBE_CUSTOM,
30 FXFM_ENCODING_ADOBE_LATIN_1, 30 FXFM_ENCODING_ADOBE_LATIN_1,
31 FXFM_ENCODING_OLD_LATIN_2, 31 FXFM_ENCODING_OLD_LATIN_2,
32 FXFM_ENCODING_APPLE_ROMAN, 32 FXFM_ENCODING_APPLE_ROMAN,
33 }; 33 };
34 34
35 CFX_UnicodeEncodingEx* _FXFM_CreateFontEncoding(CFX_Font* pFont, 35 CFX_UnicodeEncodingEx* _FXFM_CreateFontEncoding(CFX_Font* pFont,
36 FX_DWORD nEncodingID) { 36 FX_DWORD nEncodingID) {
37 if (FXFT_Select_Charmap(pFont->m_Face, nEncodingID)) 37 if (FXFT_Select_Charmap(pFont->GetFace(), nEncodingID))
38 return nullptr; 38 return nullptr;
39 return new CFX_UnicodeEncodingEx(pFont, nEncodingID); 39 return new CFX_UnicodeEncodingEx(pFont, nEncodingID);
40 } 40 }
41 41
42 FXFT_Face FT_LoadFont(const uint8_t* pData, int size) { 42 FXFT_Face FT_LoadFont(const uint8_t* pData, int size) {
43 return CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(pData, size, 0); 43 return CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(pData, size, 0);
44 } 44 }
45 45
46 } // namespace 46 } // namespace
47 47
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 226
227 FX_BOOL CFX_Font::LoadEmbedded(const uint8_t* data, FX_DWORD size) { 227 FX_BOOL CFX_Font::LoadEmbedded(const uint8_t* data, FX_DWORD size) {
228 m_pFontDataAllocation = FX_Alloc(uint8_t, size); 228 m_pFontDataAllocation = FX_Alloc(uint8_t, size);
229 FXSYS_memcpy(m_pFontDataAllocation, data, size); 229 FXSYS_memcpy(m_pFontDataAllocation, data, size);
230 m_Face = FT_LoadFont(m_pFontDataAllocation, size); 230 m_Face = FT_LoadFont(m_pFontDataAllocation, size);
231 m_pFontData = m_pFontDataAllocation; 231 m_pFontData = m_pFontDataAllocation;
232 m_bEmbedded = TRUE; 232 m_bEmbedded = TRUE;
233 m_dwSize = size; 233 m_dwSize = size;
234 return m_Face != NULL; 234 return m_Face != NULL;
235 } 235 }
236 FX_BOOL CFX_Font::IsTTFont() { 236 FX_BOOL CFX_Font::IsTTFont() const {
237 if (m_Face == NULL) { 237 if (m_Face == NULL) {
238 return FALSE; 238 return FALSE;
239 } 239 }
240 return FXFT_Is_Face_TT_OT(m_Face) == FXFT_FACE_FLAG_SFNT; 240 return FXFT_Is_Face_TT_OT(m_Face) == FXFT_FACE_FLAG_SFNT;
241 } 241 }
242 int CFX_Font::GetAscent() const { 242 int CFX_Font::GetAscent() const {
243 if (m_Face == NULL) { 243 if (m_Face == NULL) {
244 return 0; 244 return 0;
245 } 245 }
246 int ascent = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), 246 int ascent = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 bbox.top = 314 bbox.top =
315 (FXFT_Get_Glyph_HoriBearingY(m_Face) - FXFT_Get_Glyph_Height(m_Face)) * 315 (FXFT_Get_Glyph_HoriBearingY(m_Face) - FXFT_Get_Glyph_Height(m_Face)) *
316 1000 / em; 316 1000 / em;
317 bbox.right = 317 bbox.right =
318 (FXFT_Get_Glyph_HoriBearingX(m_Face) + FXFT_Get_Glyph_Width(m_Face)) * 318 (FXFT_Get_Glyph_HoriBearingX(m_Face) + FXFT_Get_Glyph_Width(m_Face)) *
319 1000 / em; 319 1000 / em;
320 bbox.bottom = (FXFT_Get_Glyph_HoriBearingY(m_Face)) * 1000 / em; 320 bbox.bottom = (FXFT_Get_Glyph_HoriBearingY(m_Face)) * 1000 / em;
321 } 321 }
322 return TRUE; 322 return TRUE;
323 } 323 }
324 FX_BOOL CFX_Font::IsItalic() { 324 FX_BOOL CFX_Font::IsItalic() const {
325 if (m_Face == NULL) { 325 if (m_Face == NULL) {
326 return FALSE; 326 return FALSE;
327 } 327 }
328 FX_BOOL ret = FXFT_Is_Face_Italic(m_Face) == FXFT_STYLE_FLAG_ITALIC; 328 FX_BOOL ret = FXFT_Is_Face_Italic(m_Face) == FXFT_STYLE_FLAG_ITALIC;
329 if (!ret) { 329 if (!ret) {
330 CFX_ByteString str(FXFT_Get_Face_Style_Name(m_Face)); 330 CFX_ByteString str(FXFT_Get_Face_Style_Name(m_Face));
331 str.MakeLower(); 331 str.MakeLower();
332 if (str.Find("italic") != -1) { 332 if (str.Find("italic") != -1) {
333 ret = TRUE; 333 ret = TRUE;
334 } 334 }
335 } 335 }
336 return ret; 336 return ret;
337 } 337 }
338 FX_BOOL CFX_Font::IsBold() { 338 FX_BOOL CFX_Font::IsBold() const {
339 if (m_Face == NULL) { 339 if (m_Face == NULL) {
340 return FALSE; 340 return FALSE;
341 } 341 }
342 return FXFT_Is_Face_Bold(m_Face) == FXFT_STYLE_FLAG_BOLD; 342 return FXFT_Is_Face_Bold(m_Face) == FXFT_STYLE_FLAG_BOLD;
343 } 343 }
344 FX_BOOL CFX_Font::IsFixedWidth() { 344 FX_BOOL CFX_Font::IsFixedWidth() const {
345 if (m_Face == NULL) { 345 if (m_Face == NULL) {
346 return FALSE; 346 return FALSE;
347 } 347 }
348 return FXFT_Is_Face_fixedwidth(m_Face); 348 return FXFT_Is_Face_fixedwidth(m_Face);
349 } 349 }
350 CFX_WideString CFX_Font::GetPsName() const { 350 CFX_WideString CFX_Font::GetPsName() const {
351 if (m_Face == NULL) { 351 if (m_Face == NULL) {
352 return CFX_WideString(); 352 return CFX_WideString();
353 } 353 }
354 CFX_WideString psName = 354 CFX_WideString psName =
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 bbox.top = FXFT_Get_Face_yMin(m_Face); 396 bbox.top = FXFT_Get_Face_yMin(m_Face);
397 bbox.right = FXFT_Get_Face_xMax(m_Face); 397 bbox.right = FXFT_Get_Face_xMax(m_Face);
398 } else { 398 } else {
399 bbox.left = FXFT_Get_Face_xMin(m_Face) * 1000 / em; 399 bbox.left = FXFT_Get_Face_xMin(m_Face) * 1000 / em;
400 bbox.top = FXFT_Get_Face_yMin(m_Face) * 1000 / em; 400 bbox.top = FXFT_Get_Face_yMin(m_Face) * 1000 / em;
401 bbox.right = FXFT_Get_Face_xMax(m_Face) * 1000 / em; 401 bbox.right = FXFT_Get_Face_xMax(m_Face) * 1000 / em;
402 bbox.bottom = FXFT_Get_Face_yMax(m_Face) * 1000 / em; 402 bbox.bottom = FXFT_Get_Face_yMax(m_Face) * 1000 / em;
403 } 403 }
404 return TRUE; 404 return TRUE;
405 } 405 }
406 int CFX_Font::GetHeight() { 406 int CFX_Font::GetHeight() const {
407 if (m_Face == NULL) { 407 if (m_Face == NULL) {
408 return 0; 408 return 0;
409 } 409 }
410 int height = 410 int height =
411 EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_Height(m_Face)); 411 EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_Height(m_Face));
412 return height; 412 return height;
413 } 413 }
414 int CFX_Font::GetMaxAdvanceWidth() { 414 int CFX_Font::GetMaxAdvanceWidth() const {
415 if (m_Face == NULL) { 415 if (m_Face == NULL) {
416 return 0; 416 return 0;
417 } 417 }
418 int width = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), 418 int width = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
419 FXFT_Get_Face_MaxAdvanceWidth(m_Face)); 419 FXFT_Get_Face_MaxAdvanceWidth(m_Face));
420 return width; 420 return width;
421 } 421 }
422 int CFX_Font::GetULPos() { 422 int CFX_Font::GetULPos() const {
423 if (m_Face == NULL) { 423 if (m_Face == NULL) {
424 return 0; 424 return 0;
425 } 425 }
426 int pos = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), 426 int pos = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
427 FXFT_Get_Face_UnderLinePosition(m_Face)); 427 FXFT_Get_Face_UnderLinePosition(m_Face));
428 return pos; 428 return pos;
429 } 429 }
430 int CFX_Font::GetULthickness() { 430 int CFX_Font::GetULthickness() const {
431 if (m_Face == NULL) { 431 if (m_Face == NULL) {
432 return 0; 432 return 0;
433 } 433 }
434 int thickness = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), 434 int thickness = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
435 FXFT_Get_Face_UnderLineThickness(m_Face)); 435 FXFT_Get_Face_UnderLineThickness(m_Face));
436 return thickness; 436 return thickness;
437 } 437 }
438 438
439 CFX_UnicodeEncoding::CFX_UnicodeEncoding(CFX_Font* pFont) : m_pFont(pFont) { 439 CFX_UnicodeEncoding::CFX_UnicodeEncoding(CFX_Font* pFont) : m_pFont(pFont) {
440 } 440 }
441 441
442 CFX_UnicodeEncoding::~CFX_UnicodeEncoding() { 442 CFX_UnicodeEncoding::~CFX_UnicodeEncoding() {
443 } 443 }
444 444
445 FX_DWORD CFX_UnicodeEncoding::GlyphFromCharCode(FX_DWORD charcode) { 445 FX_DWORD CFX_UnicodeEncoding::GlyphFromCharCode(FX_DWORD charcode) {
446 FXFT_Face face = m_pFont->GetFace(); 446 FXFT_Face face = m_pFont->GetFace();
447 if (!face) 447 if (!face)
448 return charcode; 448 return charcode;
449 449
450 if (FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE) == 0) 450 if (FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE) == 0)
451 return FXFT_Get_Char_Index(face, charcode); 451 return FXFT_Get_Char_Index(face, charcode);
452 452
453 if (m_pFont->m_pSubstFont && m_pFont->m_pSubstFont->m_Charset == 2) { 453 if (m_pFont->GetSubstFont() && m_pFont->GetSubstFont()->m_Charset == 2) {
454 FX_DWORD index = 0; 454 FX_DWORD index = 0;
455 if (FXFT_Select_Charmap(face, FXFT_ENCODING_MS_SYMBOL) == 0) 455 if (FXFT_Select_Charmap(face, FXFT_ENCODING_MS_SYMBOL) == 0)
456 index = FXFT_Get_Char_Index(face, charcode); 456 index = FXFT_Get_Char_Index(face, charcode);
457 if (!index && !FXFT_Select_Charmap(face, FXFT_ENCODING_APPLE_ROMAN)) 457 if (!index && !FXFT_Select_Charmap(face, FXFT_ENCODING_APPLE_ROMAN))
458 return FXFT_Get_Char_Index(face, charcode); 458 return FXFT_Get_Char_Index(face, charcode);
459 } 459 }
460 return charcode; 460 return charcode;
461 } 461 }
462 462
463 CFX_UnicodeEncodingEx::CFX_UnicodeEncodingEx(CFX_Font* pFont, 463 CFX_UnicodeEncodingEx::CFX_UnicodeEncodingEx(CFX_Font* pFont,
(...skipping 30 matching lines...) Expand all
494 } 494 }
495 FXFT_Select_Charmap(face, m_nEncodingID); 495 FXFT_Select_Charmap(face, m_nEncodingID);
496 return 0; 496 return 0;
497 } 497 }
498 498
499 FX_DWORD CFX_UnicodeEncodingEx::CharCodeFromUnicode(FX_WCHAR Unicode) const { 499 FX_DWORD CFX_UnicodeEncodingEx::CharCodeFromUnicode(FX_WCHAR Unicode) const {
500 if (m_nEncodingID == FXFM_ENCODING_UNICODE || 500 if (m_nEncodingID == FXFM_ENCODING_UNICODE ||
501 m_nEncodingID == FXFM_ENCODING_MS_SYMBOL) { 501 m_nEncodingID == FXFM_ENCODING_MS_SYMBOL) {
502 return Unicode; 502 return Unicode;
503 } 503 }
504 FXFT_Face face = m_pFont->m_Face; 504 FXFT_Face face = m_pFont->GetFace();
505 int nmaps = FXFT_Get_Face_CharmapCount(face); 505 int nmaps = FXFT_Get_Face_CharmapCount(face);
506 for (int i = 0; i < nmaps; i++) { 506 for (int i = 0; i < nmaps; i++) {
507 int nEncodingID = 507 int nEncodingID =
508 FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[i]); 508 FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[i]);
509 if (nEncodingID == FXFM_ENCODING_UNICODE || 509 if (nEncodingID == FXFM_ENCODING_UNICODE ||
510 nEncodingID == FXFM_ENCODING_MS_SYMBOL) { 510 nEncodingID == FXFM_ENCODING_MS_SYMBOL) {
511 return Unicode; 511 return Unicode;
512 } 512 }
513 } 513 }
514 return -1; 514 return -1;
515 } 515 }
516 516
517 CFX_UnicodeEncodingEx* FX_CreateFontEncodingEx(CFX_Font* pFont, 517 CFX_UnicodeEncodingEx* FX_CreateFontEncodingEx(CFX_Font* pFont,
518 FX_DWORD nEncodingID) { 518 FX_DWORD nEncodingID) {
519 if (!pFont || !pFont->m_Face) 519 if (!pFont || !pFont->GetFace())
520 return nullptr; 520 return nullptr;
521 521
522 if (nEncodingID != FXFM_ENCODING_NONE) 522 if (nEncodingID != FXFM_ENCODING_NONE)
523 return _FXFM_CreateFontEncoding(pFont, nEncodingID); 523 return _FXFM_CreateFontEncoding(pFont, nEncodingID);
524 524
525 for (size_t i = 0; i < FX_ArraySize(g_EncodingID); ++i) { 525 for (size_t i = 0; i < FX_ArraySize(g_EncodingID); ++i) {
526 CFX_UnicodeEncodingEx* pFontEncoding = 526 CFX_UnicodeEncodingEx* pFontEncoding =
527 _FXFM_CreateFontEncoding(pFont, g_EncodingID[i]); 527 _FXFM_CreateFontEncoding(pFont, g_EncodingID[i]);
528 if (pFontEncoding) { 528 if (pFontEncoding) {
529 return pFontEncoding; 529 return pFontEncoding;
530 } 530 }
531 } 531 }
532 return NULL; 532 return NULL;
533 } 533 }
OLDNEW
« no previous file with comments | « core/src/fpdftext/text_int.h ('k') | xfa/src/fdp/src/fde/fde_gedevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698