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

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

Issue 2248463002: Get rid of FX_SMALL_RECT. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@fontclean
Patch Set: Created 4 years, 4 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 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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/fpdfapi/fpdf_font/cpdf_simplefont.h" 7 #include "core/fpdfapi/fpdf_font/cpdf_simplefont.h"
8 8
9 #include "core/fpdfapi/fpdf_font/font_int.h" 9 #include "core/fpdfapi/fpdf_font/font_int.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
12 #include "core/fxge/include/fx_freetype.h" 12 #include "core/fxge/include/fx_freetype.h"
13 13
14 CPDF_SimpleFont::CPDF_SimpleFont() : m_BaseEncoding(PDFFONT_ENCODING_BUILTIN) { 14 CPDF_SimpleFont::CPDF_SimpleFont() : m_BaseEncoding(PDFFONT_ENCODING_BUILTIN) {
15 FXSYS_memset(m_CharWidth, 0xff, sizeof(m_CharWidth)); 15 FXSYS_memset(m_CharWidth, 0xff, sizeof(m_CharWidth));
16 FXSYS_memset(m_GlyphIndex, 0xff, sizeof(m_GlyphIndex)); 16 FXSYS_memset(m_GlyphIndex, 0xff, sizeof(m_GlyphIndex));
17 FXSYS_memset(m_ExtGID, 0xff, sizeof(m_ExtGID)); 17 FXSYS_memset(m_ExtGID, 0xff, sizeof(m_ExtGID));
18 for (size_t i = 0; i < FX_ArraySize(m_CharBBox); ++i) {
19 m_CharBBox[i] = FX_RECT(-1, -1, -1, -1);
20 }
dsinclair 2016/08/15 12:48:03 nit: no {}'s
Lei Zhang 2016/08/15 17:05:35 Done.
18 } 21 }
19 22
20 CPDF_SimpleFont::~CPDF_SimpleFont() {} 23 CPDF_SimpleFont::~CPDF_SimpleFont() {}
21 24
22 int CPDF_SimpleFont::GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) { 25 int CPDF_SimpleFont::GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) {
23 if (pVertGlyph) 26 if (pVertGlyph)
24 *pVertGlyph = false; 27 *pVertGlyph = false;
25 28
26 if (charcode > 0xff) 29 if (charcode > 0xff)
27 return -1; 30 return -1;
(...skipping 17 matching lines...) Expand all
45 if (m_bUseFontWidth) { 48 if (m_bUseFontWidth) {
46 m_CharWidth[charcode] = m_CharWidth[32]; 49 m_CharWidth[charcode] = m_CharWidth[32];
47 } 50 }
48 } 51 }
49 return; 52 return;
50 } 53 }
51 FXFT_Face face = m_Font.GetFace(); 54 FXFT_Face face = m_Font.GetFace();
52 int err = FXFT_Load_Glyph( 55 int err = FXFT_Load_Glyph(
53 face, glyph_index, 56 face, glyph_index,
54 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); 57 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
55 if (err) { 58 if (err)
56 return; 59 return;
57 } 60
58 m_CharBBox[charcode] = FX_SMALL_RECT( 61 int iHoriBearingX = FXFT_Get_Glyph_HoriBearingX(face);
59 TT2PDF(FXFT_Get_Glyph_HoriBearingX(face), face), 62 int iHoriBearingY = FXFT_Get_Glyph_HoriBearingY(face);
60 TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face), 63 m_CharBBox[charcode] =
61 TT2PDF(FXFT_Get_Glyph_HoriBearingX(face) + FXFT_Get_Glyph_Width(face), 64 FX_RECT(TT2PDF(iHoriBearingX, face), TT2PDF(iHoriBearingY, face),
62 face), 65 TT2PDF(iHoriBearingX + FXFT_Get_Glyph_Width(face), face),
63 TT2PDF(FXFT_Get_Glyph_HoriBearingY(face) - FXFT_Get_Glyph_Height(face), 66 TT2PDF(iHoriBearingY - FXFT_Get_Glyph_Height(face), face));
64 face));
65 67
66 if (m_bUseFontWidth) { 68 if (m_bUseFontWidth) {
67 int TT_Width = TT2PDF(FXFT_Get_Glyph_HoriAdvance(face), face); 69 int TT_Width = TT2PDF(FXFT_Get_Glyph_HoriAdvance(face), face);
68 if (m_CharWidth[charcode] == 0xffff) { 70 if (m_CharWidth[charcode] == 0xffff) {
69 m_CharWidth[charcode] = TT_Width; 71 m_CharWidth[charcode] = TT_Width;
70 } else if (TT_Width && !IsEmbedded()) { 72 } else if (TT_Width && !IsEmbedded()) {
71 m_CharBBox[charcode].right = 73 m_CharBBox[charcode].right =
72 m_CharBBox[charcode].right * m_CharWidth[charcode] / TT_Width; 74 m_CharBBox[charcode].right * m_CharWidth[charcode] / TT_Width;
73 m_CharBBox[charcode].left = 75 m_CharBBox[charcode].left =
74 m_CharBBox[charcode].left * m_CharWidth[charcode] / TT_Width; 76 m_CharBBox[charcode].left * m_CharWidth[charcode] / TT_Width;
75 } 77 }
76 } 78 }
77 } 79 }
78 80
79 int CPDF_SimpleFont::GetCharWidthF(uint32_t charcode, int level) { 81 int CPDF_SimpleFont::GetCharWidthF(uint32_t charcode, int level) {
80 if (charcode > 0xff) { 82 if (charcode > 0xff)
81 charcode = 0; 83 charcode = 0;
82 } 84
83 if (m_CharWidth[charcode] == 0xffff) { 85 if (m_CharWidth[charcode] == 0xffff) {
84 LoadCharMetrics(charcode); 86 LoadCharMetrics(charcode);
85 if (m_CharWidth[charcode] == 0xffff) { 87 if (m_CharWidth[charcode] == 0xffff) {
86 m_CharWidth[charcode] = 0; 88 m_CharWidth[charcode] = 0;
87 } 89 }
88 } 90 }
89 return (int16_t)m_CharWidth[charcode]; 91 return m_CharWidth[charcode];
90 } 92 }
91 93
92 FX_RECT CPDF_SimpleFont::GetCharBBox(uint32_t charcode, int level) { 94 FX_RECT CPDF_SimpleFont::GetCharBBox(uint32_t charcode, int level) {
93 if (charcode > 0xff) 95 if (charcode > 0xff)
94 charcode = 0; 96 charcode = 0;
95 97
96 if (m_CharBBox[charcode].left == FX_SMALL_RECT::kInvalid) 98 if (m_CharBBox[charcode].left == -1)
97 LoadCharMetrics(charcode); 99 LoadCharMetrics(charcode);
98 100
99 return FX_RECT(m_CharBBox[charcode]); 101 return m_CharBBox[charcode];
100 } 102 }
101 103
102 FX_BOOL CPDF_SimpleFont::LoadCommon() { 104 FX_BOOL CPDF_SimpleFont::LoadCommon() {
103 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictBy("FontDescriptor"); 105 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictBy("FontDescriptor");
104 if (pFontDesc) { 106 if (pFontDesc) {
105 LoadFontDescriptor(pFontDesc); 107 LoadFontDescriptor(pFontDesc);
106 } 108 }
107 CPDF_Array* pWidthArray = m_pFontDict->GetArrayBy("Widths"); 109 CPDF_Array* pWidthArray = m_pFontDict->GetArrayBy("Widths");
108 m_bUseFontWidth = TRUE; 110 m_bUseFontWidth = !pWidthArray;
109 if (pWidthArray) { 111 if (pWidthArray) {
110 m_bUseFontWidth = FALSE;
111 if (pFontDesc && pFontDesc->KeyExist("MissingWidth")) { 112 if (pFontDesc && pFontDesc->KeyExist("MissingWidth")) {
112 int MissingWidth = pFontDesc->GetIntegerBy("MissingWidth"); 113 int MissingWidth = pFontDesc->GetIntegerBy("MissingWidth");
113 for (int i = 0; i < 256; i++) { 114 for (int i = 0; i < 256; i++) {
114 m_CharWidth[i] = MissingWidth; 115 m_CharWidth[i] = MissingWidth;
115 } 116 }
116 } 117 }
117 size_t width_start = m_pFontDict->GetIntegerBy("FirstChar", 0); 118 size_t width_start = m_pFontDict->GetIntegerBy("FirstChar", 0);
118 size_t width_end = m_pFontDict->GetIntegerBy("LastChar", 0); 119 size_t width_end = m_pFontDict->GetIntegerBy("LastChar", 0);
119 if (width_start <= 255) { 120 if (width_start <= 255) {
120 if (width_end == 0 || width_end >= width_start + pWidthArray->GetCount()) 121 if (width_end == 0 || width_end >= width_start + pWidthArray->GetCount())
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 return CFX_WideString(); 202 return CFX_WideString();
202 return ret; 203 return ret;
203 } 204 }
204 205
205 uint32_t CPDF_SimpleFont::CharCodeFromUnicode(FX_WCHAR unicode) const { 206 uint32_t CPDF_SimpleFont::CharCodeFromUnicode(FX_WCHAR unicode) const {
206 uint32_t ret = CPDF_Font::CharCodeFromUnicode(unicode); 207 uint32_t ret = CPDF_Font::CharCodeFromUnicode(unicode);
207 if (ret) 208 if (ret)
208 return ret; 209 return ret;
209 return m_Encoding.CharCodeFromUnicode(unicode); 210 return m_Encoding.CharCodeFromUnicode(unicode);
210 } 211 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698