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

Side by Side Diff: core/src/fpdfapi/fpdf_font/fpdf_font.cpp

Issue 1745683002: Fixup FX_RECT and FX_SMALL_RECT classes. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase, Dan's comments Created 4 years, 9 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
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 "core/src/fpdfapi/fpdf_font/font_int.h" 7 #include "core/src/fpdfapi/fpdf_font/font_int.h"
8 8
9 #include "core/include/fpdfapi/fpdf_module.h" 9 #include "core/include/fpdfapi/fpdf_module.h"
10 #include "core/include/fpdfapi/fpdf_page.h" 10 #include "core/include/fpdfapi/fpdf_page.h"
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 if (face) { 299 if (face) {
300 m_FontBBox.left = TT2PDF(FXFT_Get_Face_xMin(face), face); 300 m_FontBBox.left = TT2PDF(FXFT_Get_Face_xMin(face), face);
301 m_FontBBox.bottom = TT2PDF(FXFT_Get_Face_yMin(face), face); 301 m_FontBBox.bottom = TT2PDF(FXFT_Get_Face_yMin(face), face);
302 m_FontBBox.right = TT2PDF(FXFT_Get_Face_xMax(face), face); 302 m_FontBBox.right = TT2PDF(FXFT_Get_Face_xMax(face), face);
303 m_FontBBox.top = TT2PDF(FXFT_Get_Face_yMax(face), face); 303 m_FontBBox.top = TT2PDF(FXFT_Get_Face_yMax(face), face);
304 m_Ascent = TT2PDF(FXFT_Get_Face_Ascender(face), face); 304 m_Ascent = TT2PDF(FXFT_Get_Face_Ascender(face), face);
305 m_Descent = TT2PDF(FXFT_Get_Face_Descender(face), face); 305 m_Descent = TT2PDF(FXFT_Get_Face_Descender(face), face);
306 } else { 306 } else {
307 FX_BOOL bFirst = TRUE; 307 FX_BOOL bFirst = TRUE;
308 for (int i = 0; i < 256; i++) { 308 for (int i = 0; i < 256; i++) {
309 FX_RECT rect; 309 FX_RECT rect = GetCharBBox(i);
310 GetCharBBox(i, rect);
311 if (rect.left == rect.right) { 310 if (rect.left == rect.right) {
312 continue; 311 continue;
313 } 312 }
314 if (bFirst) { 313 if (bFirst) {
315 m_FontBBox = rect; 314 m_FontBBox = rect;
316 bFirst = FALSE; 315 bFirst = FALSE;
317 } else { 316 } else {
318 if (m_FontBBox.top < rect.top) { 317 if (m_FontBBox.top < rect.top) {
319 m_FontBBox.top = rect.top; 318 m_FontBBox.top = rect.top;
320 } 319 }
321 if (m_FontBBox.right < rect.right) { 320 if (m_FontBBox.right < rect.right) {
322 m_FontBBox.right = rect.right; 321 m_FontBBox.right = rect.right;
323 } 322 }
324 if (m_FontBBox.left > rect.left) { 323 if (m_FontBBox.left > rect.left) {
325 m_FontBBox.left = rect.left; 324 m_FontBBox.left = rect.left;
326 } 325 }
327 if (m_FontBBox.bottom > rect.bottom) { 326 if (m_FontBBox.bottom > rect.bottom) {
328 m_FontBBox.bottom = rect.bottom; 327 m_FontBBox.bottom = rect.bottom;
329 } 328 }
330 } 329 }
331 } 330 }
332 } 331 }
333 } 332 }
334 if (m_Ascent == 0 && m_Descent == 0) { 333 if (m_Ascent == 0 && m_Descent == 0) {
335 FX_RECT rect; 334 FX_RECT rect = GetCharBBox('A');
336 GetCharBBox('A', rect); 335 m_Ascent = rect.bottom == rect.top ? m_FontBBox.top : rect.top;
337 if (rect.bottom == rect.top) { 336 rect = GetCharBBox('g');
338 m_Ascent = m_FontBBox.top; 337 m_Descent = rect.bottom == rect.top ? m_FontBBox.bottom : rect.bottom;
339 } else {
340 m_Ascent = rect.top;
341 }
342 GetCharBBox('g', rect);
343 if (rect.bottom == rect.top) {
344 m_Descent = m_FontBBox.bottom;
345 } else {
346 m_Descent = rect.bottom;
347 }
348 } 338 }
349 } 339 }
350 340
351 void CPDF_Font::LoadUnicodeMap() { 341 void CPDF_Font::LoadUnicodeMap() {
352 m_bToUnicodeLoaded = TRUE; 342 m_bToUnicodeLoaded = TRUE;
353 CPDF_Stream* pStream = m_pFontDict->GetStreamBy("ToUnicode"); 343 CPDF_Stream* pStream = m_pFontDict->GetStreamBy("ToUnicode");
354 if (!pStream) { 344 if (!pStream) {
355 return; 345 return;
356 } 346 }
357 m_pToUnicodeMap = new CPDF_ToUnicodeMap; 347 m_pToUnicodeMap = new CPDF_ToUnicodeMap;
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 FX_BOOL CPDF_Font::IsStandardFont() const { 726 FX_BOOL CPDF_Font::IsStandardFont() const {
737 if (!IsType1Font()) 727 if (!IsType1Font())
738 return FALSE; 728 return FALSE;
739 if (m_pFontFile) 729 if (m_pFontFile)
740 return FALSE; 730 return FALSE;
741 if (AsType1Font()->GetBase14Font() < 0) 731 if (AsType1Font()->GetBase14Font() < 0)
742 return FALSE; 732 return FALSE;
743 return TRUE; 733 return TRUE;
744 } 734 }
745 735
746 CPDF_SimpleFont::CPDF_SimpleFont() { 736 CPDF_SimpleFont::CPDF_SimpleFont()
747 FXSYS_memset(m_CharBBox, 0xff, sizeof m_CharBBox); 737 : m_pCharNames(nullptr), m_BaseEncoding(PDFFONT_ENCODING_BUILTIN) {
748 FXSYS_memset(m_CharWidth, 0xff, sizeof m_CharWidth); 738 FXSYS_memset(m_CharWidth, 0xff, sizeof m_CharWidth);
749 FXSYS_memset(m_GlyphIndex, 0xff, sizeof m_GlyphIndex); 739 FXSYS_memset(m_GlyphIndex, 0xff, sizeof m_GlyphIndex);
750 FXSYS_memset(m_ExtGID, 0xff, sizeof m_ExtGID); 740 FXSYS_memset(m_ExtGID, 0xff, sizeof m_ExtGID);
751 m_pCharNames = NULL;
752 m_BaseEncoding = PDFFONT_ENCODING_BUILTIN;
753 } 741 }
754 742
755 CPDF_SimpleFont::~CPDF_SimpleFont() { 743 CPDF_SimpleFont::~CPDF_SimpleFont() {
756 delete[] m_pCharNames; 744 delete[] m_pCharNames;
757 } 745 }
758 746
759 int CPDF_SimpleFont::GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph) { 747 int CPDF_SimpleFont::GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph) {
760 if (pVertGlyph) { 748 if (pVertGlyph) {
761 *pVertGlyph = FALSE; 749 *pVertGlyph = FALSE;
762 } 750 }
(...skipping 25 matching lines...) Expand all
788 } 776 }
789 return; 777 return;
790 } 778 }
791 FXFT_Face face = m_Font.GetFace(); 779 FXFT_Face face = m_Font.GetFace();
792 int err = FXFT_Load_Glyph( 780 int err = FXFT_Load_Glyph(
793 face, glyph_index, 781 face, glyph_index,
794 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); 782 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
795 if (err) { 783 if (err) {
796 return; 784 return;
797 } 785 }
798 m_CharBBox[charcode].Left = TT2PDF(FXFT_Get_Glyph_HoriBearingX(face), face); 786 m_CharBBox[charcode] = FX_SMALL_RECT(
799 m_CharBBox[charcode].Right = TT2PDF( 787 TT2PDF(FXFT_Get_Glyph_HoriBearingX(face), face),
800 FXFT_Get_Glyph_HoriBearingX(face) + FXFT_Get_Glyph_Width(face), face); 788 TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face),
801 m_CharBBox[charcode].Top = TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face); 789 TT2PDF(FXFT_Get_Glyph_HoriBearingX(face) + FXFT_Get_Glyph_Width(face),
802 m_CharBBox[charcode].Bottom = TT2PDF( 790 face),
803 FXFT_Get_Glyph_HoriBearingY(face) - FXFT_Get_Glyph_Height(face), face); 791 TT2PDF(FXFT_Get_Glyph_HoriBearingY(face) - FXFT_Get_Glyph_Height(face),
792 face));
793
804 if (m_bUseFontWidth) { 794 if (m_bUseFontWidth) {
805 int TT_Width = TT2PDF(FXFT_Get_Glyph_HoriAdvance(face), face); 795 int TT_Width = TT2PDF(FXFT_Get_Glyph_HoriAdvance(face), face);
806 if (m_CharWidth[charcode] == 0xffff) { 796 if (m_CharWidth[charcode] == 0xffff) {
807 m_CharWidth[charcode] = TT_Width; 797 m_CharWidth[charcode] = TT_Width;
808 } else if (TT_Width && !IsEmbedded()) { 798 } else if (TT_Width && !IsEmbedded()) {
809 m_CharBBox[charcode].Right = 799 m_CharBBox[charcode].right =
810 m_CharBBox[charcode].Right * m_CharWidth[charcode] / TT_Width; 800 m_CharBBox[charcode].right * m_CharWidth[charcode] / TT_Width;
811 m_CharBBox[charcode].Left = 801 m_CharBBox[charcode].left =
812 m_CharBBox[charcode].Left * m_CharWidth[charcode] / TT_Width; 802 m_CharBBox[charcode].left * m_CharWidth[charcode] / TT_Width;
813 } 803 }
814 } 804 }
815 } 805 }
816 806
817 int CPDF_SimpleFont::GetCharWidthF(FX_DWORD charcode, int level) { 807 int CPDF_SimpleFont::GetCharWidthF(FX_DWORD charcode, int level) {
818 if (charcode > 0xff) { 808 if (charcode > 0xff) {
819 charcode = 0; 809 charcode = 0;
820 } 810 }
821 if (m_CharWidth[charcode] == 0xffff) { 811 if (m_CharWidth[charcode] == 0xffff) {
822 LoadCharMetrics(charcode); 812 LoadCharMetrics(charcode);
823 if (m_CharWidth[charcode] == 0xffff) { 813 if (m_CharWidth[charcode] == 0xffff) {
824 m_CharWidth[charcode] = 0; 814 m_CharWidth[charcode] = 0;
825 } 815 }
826 } 816 }
827 return (int16_t)m_CharWidth[charcode]; 817 return (int16_t)m_CharWidth[charcode];
828 } 818 }
829 819
830 void CPDF_SimpleFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) { 820 FX_RECT CPDF_SimpleFont::GetCharBBox(FX_DWORD charcode, int level) {
831 if (charcode > 0xff) { 821 if (charcode > 0xff)
832 charcode = 0; 822 charcode = 0;
833 } 823
834 if (m_CharBBox[charcode].Left == (int16_t)0xffff) { 824 if (m_CharBBox[charcode].left == FX_SMALL_RECT::kInvalid)
835 LoadCharMetrics(charcode); 825 LoadCharMetrics(charcode);
836 } 826
837 rect.left = m_CharBBox[charcode].Left; 827 return FX_RECT(m_CharBBox[charcode]);
838 rect.right = m_CharBBox[charcode].Right;
839 rect.bottom = m_CharBBox[charcode].Bottom;
840 rect.top = m_CharBBox[charcode].Top;
841 } 828 }
842 829
843 const FX_CHAR* GetAdobeCharName(int iBaseEncoding, 830 const FX_CHAR* GetAdobeCharName(int iBaseEncoding,
844 const CFX_ByteString* pCharNames, 831 const CFX_ByteString* pCharNames,
845 int charcode) { 832 int charcode) {
846 ASSERT(charcode >= 0 && charcode < 256); 833 ASSERT(charcode >= 0 && charcode < 256);
847 if (charcode < 0 || charcode >= 256) { 834 if (charcode < 0 || charcode >= 256) {
848 return NULL; 835 return NULL;
849 } 836 }
850 const FX_CHAR* name = NULL; 837 const FX_CHAR* name = NULL;
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 if (charcode >= FX_ArraySize(m_CharWidthL)) 1684 if (charcode >= FX_ArraySize(m_CharWidthL))
1698 charcode = 0; 1685 charcode = 0;
1699 1686
1700 if (m_CharWidthL[charcode]) 1687 if (m_CharWidthL[charcode])
1701 return m_CharWidthL[charcode]; 1688 return m_CharWidthL[charcode];
1702 1689
1703 const CPDF_Type3Char* pChar = LoadChar(charcode, level); 1690 const CPDF_Type3Char* pChar = LoadChar(charcode, level);
1704 return pChar ? pChar->m_Width : 0; 1691 return pChar ? pChar->m_Width : 0;
1705 } 1692 }
1706 1693
1707 void CPDF_Type3Font::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) { 1694 FX_RECT CPDF_Type3Font::GetCharBBox(FX_DWORD charcode, int level) {
1708 const CPDF_Type3Char* pChar = LoadChar(charcode, level); 1695 const CPDF_Type3Char* pChar = LoadChar(charcode, level);
1709 if (!pChar) { 1696 return pChar ? pChar->m_BBox : FX_RECT();
1710 rect.left = 0;
1711 rect.right = 0;
1712 rect.top = 0;
1713 rect.bottom = 0;
1714 return;
1715 }
1716 rect = pChar->m_BBox;
1717 } 1697 }
1718 1698
1719 CPDF_Type3Char::CPDF_Type3Char(CPDF_Form* pForm) 1699 CPDF_Type3Char::CPDF_Type3Char(CPDF_Form* pForm)
1720 : m_pForm(pForm), m_pBitmap(nullptr), m_bColored(FALSE) {} 1700 : m_pForm(pForm), m_pBitmap(nullptr), m_bColored(FALSE) {}
1721 1701
1722 CPDF_Type3Char::~CPDF_Type3Char() { 1702 CPDF_Type3Char::~CPDF_Type3Char() {
1723 delete m_pForm; 1703 delete m_pForm;
1724 delete m_pBitmap; 1704 delete m_pBitmap;
1725 } 1705 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698