| OLD | NEW |
| 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/font/cpdf_font.h" | 7 #include "core/fpdfapi/font/cpdf_font.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 uint32_t CPDF_Font::CharCodeFromUnicode(FX_WCHAR unicode) const { | 159 uint32_t CPDF_Font::CharCodeFromUnicode(FX_WCHAR unicode) const { |
| 160 if (!m_bToUnicodeLoaded) | 160 if (!m_bToUnicodeLoaded) |
| 161 LoadUnicodeMap(); | 161 LoadUnicodeMap(); |
| 162 | 162 |
| 163 return m_pToUnicodeMap ? m_pToUnicodeMap->ReverseLookup(unicode) : 0; | 163 return m_pToUnicodeMap ? m_pToUnicodeMap->ReverseLookup(unicode) : 0; |
| 164 } | 164 } |
| 165 | 165 |
| 166 void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) { | 166 void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) { |
| 167 m_Flags = pFontDesc->GetIntegerFor("Flags", PDFFONT_NONSYMBOLIC); | 167 m_Flags = pFontDesc->GetIntegerFor("Flags", PDFFONT_NONSYMBOLIC); |
| 168 int ItalicAngle = 0; | 168 int ItalicAngle = 0; |
| 169 FX_BOOL bExistItalicAngle = FALSE; | 169 bool bExistItalicAngle = false; |
| 170 if (pFontDesc->KeyExist("ItalicAngle")) { | 170 if (pFontDesc->KeyExist("ItalicAngle")) { |
| 171 ItalicAngle = pFontDesc->GetIntegerFor("ItalicAngle"); | 171 ItalicAngle = pFontDesc->GetIntegerFor("ItalicAngle"); |
| 172 bExistItalicAngle = TRUE; | 172 bExistItalicAngle = true; |
| 173 } | 173 } |
| 174 if (ItalicAngle < 0) { | 174 if (ItalicAngle < 0) { |
| 175 m_Flags |= PDFFONT_ITALIC; | 175 m_Flags |= PDFFONT_ITALIC; |
| 176 m_ItalicAngle = ItalicAngle; | 176 m_ItalicAngle = ItalicAngle; |
| 177 } | 177 } |
| 178 FX_BOOL bExistStemV = FALSE; | 178 bool bExistStemV = false; |
| 179 if (pFontDesc->KeyExist("StemV")) { | 179 if (pFontDesc->KeyExist("StemV")) { |
| 180 m_StemV = pFontDesc->GetIntegerFor("StemV"); | 180 m_StemV = pFontDesc->GetIntegerFor("StemV"); |
| 181 bExistStemV = TRUE; | 181 bExistStemV = true; |
| 182 } | 182 } |
| 183 FX_BOOL bExistAscent = FALSE; | 183 bool bExistAscent = false; |
| 184 if (pFontDesc->KeyExist("Ascent")) { | 184 if (pFontDesc->KeyExist("Ascent")) { |
| 185 m_Ascent = pFontDesc->GetIntegerFor("Ascent"); | 185 m_Ascent = pFontDesc->GetIntegerFor("Ascent"); |
| 186 bExistAscent = TRUE; | 186 bExistAscent = true; |
| 187 } | 187 } |
| 188 FX_BOOL bExistDescent = FALSE; | 188 bool bExistDescent = false; |
| 189 if (pFontDesc->KeyExist("Descent")) { | 189 if (pFontDesc->KeyExist("Descent")) { |
| 190 m_Descent = pFontDesc->GetIntegerFor("Descent"); | 190 m_Descent = pFontDesc->GetIntegerFor("Descent"); |
| 191 bExistDescent = TRUE; | 191 bExistDescent = true; |
| 192 } | 192 } |
| 193 FX_BOOL bExistCapHeight = FALSE; | 193 bool bExistCapHeight = false; |
| 194 if (pFontDesc->KeyExist("CapHeight")) { | 194 if (pFontDesc->KeyExist("CapHeight")) { |
| 195 bExistCapHeight = TRUE; | 195 bExistCapHeight = true; |
| 196 } | 196 } |
| 197 if (bExistItalicAngle && bExistAscent && bExistCapHeight && bExistDescent && | 197 if (bExistItalicAngle && bExistAscent && bExistCapHeight && bExistDescent && |
| 198 bExistStemV) { | 198 bExistStemV) { |
| 199 m_Flags |= PDFFONT_USEEXTERNATTR; | 199 m_Flags |= PDFFONT_USEEXTERNATTR; |
| 200 } | 200 } |
| 201 if (m_Descent > 10) { | 201 if (m_Descent > 10) { |
| 202 m_Descent = -m_Descent; | 202 m_Descent = -m_Descent; |
| 203 } | 203 } |
| 204 CPDF_Array* pBBox = pFontDesc->GetArrayFor("FontBBox"); | 204 CPDF_Array* pBBox = pFontDesc->GetArrayFor("FontBBox"); |
| 205 if (pBBox) { | 205 if (pBBox) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 235 m_FontBBox.right == 0) { | 235 m_FontBBox.right == 0) { |
| 236 FXFT_Face face = m_Font.GetFace(); | 236 FXFT_Face face = m_Font.GetFace(); |
| 237 if (face) { | 237 if (face) { |
| 238 m_FontBBox.left = TT2PDF(FXFT_Get_Face_xMin(face), face); | 238 m_FontBBox.left = TT2PDF(FXFT_Get_Face_xMin(face), face); |
| 239 m_FontBBox.bottom = TT2PDF(FXFT_Get_Face_yMin(face), face); | 239 m_FontBBox.bottom = TT2PDF(FXFT_Get_Face_yMin(face), face); |
| 240 m_FontBBox.right = TT2PDF(FXFT_Get_Face_xMax(face), face); | 240 m_FontBBox.right = TT2PDF(FXFT_Get_Face_xMax(face), face); |
| 241 m_FontBBox.top = TT2PDF(FXFT_Get_Face_yMax(face), face); | 241 m_FontBBox.top = TT2PDF(FXFT_Get_Face_yMax(face), face); |
| 242 m_Ascent = TT2PDF(FXFT_Get_Face_Ascender(face), face); | 242 m_Ascent = TT2PDF(FXFT_Get_Face_Ascender(face), face); |
| 243 m_Descent = TT2PDF(FXFT_Get_Face_Descender(face), face); | 243 m_Descent = TT2PDF(FXFT_Get_Face_Descender(face), face); |
| 244 } else { | 244 } else { |
| 245 FX_BOOL bFirst = TRUE; | 245 bool bFirst = true; |
| 246 for (int i = 0; i < 256; i++) { | 246 for (int i = 0; i < 256; i++) { |
| 247 FX_RECT rect = GetCharBBox(i); | 247 FX_RECT rect = GetCharBBox(i); |
| 248 if (rect.left == rect.right) { | 248 if (rect.left == rect.right) { |
| 249 continue; | 249 continue; |
| 250 } | 250 } |
| 251 if (bFirst) { | 251 if (bFirst) { |
| 252 m_FontBBox = rect; | 252 m_FontBBox = rect; |
| 253 bFirst = FALSE; | 253 bFirst = false; |
| 254 } else { | 254 } else { |
| 255 if (m_FontBBox.top < rect.top) { | 255 if (m_FontBBox.top < rect.top) { |
| 256 m_FontBBox.top = rect.top; | 256 m_FontBBox.top = rect.top; |
| 257 } | 257 } |
| 258 if (m_FontBBox.right < rect.right) { | 258 if (m_FontBBox.right < rect.right) { |
| 259 m_FontBBox.right = rect.right; | 259 m_FontBBox.right = rect.right; |
| 260 } | 260 } |
| 261 if (m_FontBBox.left > rect.left) { | 261 if (m_FontBBox.left > rect.left) { |
| 262 m_FontBBox.left = rect.left; | 262 m_FontBBox.left = rect.left; |
| 263 } | 263 } |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 if (fallbackFont < 0 || | 467 if (fallbackFont < 0 || |
| 468 fallbackFont >= pdfium::CollectionSize<int>(m_FontFallbacks)) { | 468 fallbackFont >= pdfium::CollectionSize<int>(m_FontFallbacks)) { |
| 469 return -1; | 469 return -1; |
| 470 } | 470 } |
| 471 int glyph = | 471 int glyph = |
| 472 FXFT_Get_Char_Index(m_FontFallbacks[fallbackFont]->GetFace(), charcode); | 472 FXFT_Get_Char_Index(m_FontFallbacks[fallbackFont]->GetFace(), charcode); |
| 473 if (glyph == 0 || glyph == 0xffff) | 473 if (glyph == 0 || glyph == 0xffff) |
| 474 return -1; | 474 return -1; |
| 475 return glyph; | 475 return glyph; |
| 476 } | 476 } |
| OLD | NEW |