Chromium Code Reviews| 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/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 #include "third_party/base/numerics/safe_math.h" | |
| 13 | 14 |
| 14 CPDF_SimpleFont::CPDF_SimpleFont() : m_BaseEncoding(PDFFONT_ENCODING_BUILTIN) { | 15 CPDF_SimpleFont::CPDF_SimpleFont() : m_BaseEncoding(PDFFONT_ENCODING_BUILTIN) { |
| 15 FXSYS_memset(m_CharWidth, 0xff, sizeof(m_CharWidth)); | 16 FXSYS_memset(m_CharWidth, 0xff, sizeof(m_CharWidth)); |
| 16 FXSYS_memset(m_GlyphIndex, 0xff, sizeof(m_GlyphIndex)); | 17 FXSYS_memset(m_GlyphIndex, 0xff, sizeof(m_GlyphIndex)); |
| 17 FXSYS_memset(m_ExtGID, 0xff, sizeof(m_ExtGID)); | 18 FXSYS_memset(m_ExtGID, 0xff, sizeof(m_ExtGID)); |
| 18 for (size_t i = 0; i < FX_ArraySize(m_CharBBox); ++i) | 19 for (size_t i = 0; i < FX_ArraySize(m_CharBBox); ++i) |
| 19 m_CharBBox[i] = FX_RECT(-1, -1, -1, -1); | 20 m_CharBBox[i] = FX_RECT(-1, -1, -1, -1); |
| 20 } | 21 } |
| 21 | 22 |
| 22 CPDF_SimpleFont::~CPDF_SimpleFont() {} | 23 CPDF_SimpleFont::~CPDF_SimpleFont() {} |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 if (width == 0) { | 175 if (width == 0) { |
| 175 width = m_CharWidth[i]; | 176 width = m_CharWidth[i]; |
| 176 } else if (width != m_CharWidth[i]) { | 177 } else if (width != m_CharWidth[i]) { |
| 177 break; | 178 break; |
| 178 } | 179 } |
| 179 } | 180 } |
| 180 if (i == 256 && width) { | 181 if (i == 256 && width) { |
| 181 m_Flags |= PDFFONT_FIXEDPITCH; | 182 m_Flags |= PDFFONT_FIXEDPITCH; |
| 182 } | 183 } |
| 183 } | 184 } |
| 184 int weight = m_StemV < 140 ? m_StemV * 5 : (m_StemV * 4 + 140); | 185 pdfium::base::CheckedNumeric<int> safeStemV(m_StemV); |
|
npm
2016/08/29 19:23:39
Maybe you can also do something similar in CPDF_CI
dsinclair
2016/08/29 19:40:55
Done.
| |
| 185 m_Font.LoadSubst(m_BaseFont, IsTrueTypeFont(), m_Flags, weight, m_ItalicAngle, | 186 if (m_StemV < 140) |
| 186 0); | 187 safeStemV *= 5; |
| 188 else | |
| 189 safeStemV = safeStemV * 5 + 140; | |
| 190 m_Font.LoadSubst(m_BaseFont, IsTrueTypeFont(), m_Flags, | |
| 191 safeStemV.ValueOrDefault(140), m_ItalicAngle, 0); | |
|
dsinclair
2016/08/29 19:15:43
I made up 140 in here as it seemed to be the numbe
| |
| 187 } | 192 } |
| 188 | 193 |
| 189 FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const { | 194 FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const { |
| 190 return m_BaseEncoding != PDFFONT_ENCODING_BUILTIN && | 195 return m_BaseEncoding != PDFFONT_ENCODING_BUILTIN && |
| 191 m_BaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL && | 196 m_BaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL && |
| 192 m_BaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS; | 197 m_BaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS; |
| 193 } | 198 } |
| 194 | 199 |
| 195 CFX_WideString CPDF_SimpleFont::UnicodeFromCharCode(uint32_t charcode) const { | 200 CFX_WideString CPDF_SimpleFont::UnicodeFromCharCode(uint32_t charcode) const { |
| 196 CFX_WideString unicode = CPDF_Font::UnicodeFromCharCode(charcode); | 201 CFX_WideString unicode = CPDF_Font::UnicodeFromCharCode(charcode); |
| 197 if (!unicode.IsEmpty()) | 202 if (!unicode.IsEmpty()) |
| 198 return unicode; | 203 return unicode; |
| 199 FX_WCHAR ret = m_Encoding.UnicodeFromCharCode((uint8_t)charcode); | 204 FX_WCHAR ret = m_Encoding.UnicodeFromCharCode((uint8_t)charcode); |
| 200 if (ret == 0) | 205 if (ret == 0) |
| 201 return CFX_WideString(); | 206 return CFX_WideString(); |
| 202 return ret; | 207 return ret; |
| 203 } | 208 } |
| 204 | 209 |
| 205 uint32_t CPDF_SimpleFont::CharCodeFromUnicode(FX_WCHAR unicode) const { | 210 uint32_t CPDF_SimpleFont::CharCodeFromUnicode(FX_WCHAR unicode) const { |
| 206 uint32_t ret = CPDF_Font::CharCodeFromUnicode(unicode); | 211 uint32_t ret = CPDF_Font::CharCodeFromUnicode(unicode); |
| 207 if (ret) | 212 if (ret) |
| 208 return ret; | 213 return ret; |
| 209 return m_Encoding.CharCodeFromUnicode(unicode); | 214 return m_Encoding.CharCodeFromUnicode(unicode); |
| 210 } | 215 } |
| OLD | NEW |