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

Side by Side Diff: core/fxge/ge/cfx_facecache.cpp

Issue 2296193002: Use CheckedNumeric for strength calculation. (Closed)
Patch Set: Fix operation order Created 4 years, 3 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/fxge/include/cfx_facecache.h" 7 #include "core/fxge/include/cfx_facecache.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "core/fxge/ge/fx_text_int.h" 11 #include "core/fxge/ge/fx_text_int.h"
12 #include "core/fxge/include/cfx_fontmgr.h" 12 #include "core/fxge/include/cfx_fontmgr.h"
13 #include "core/fxge/include/cfx_gemodule.h" 13 #include "core/fxge/include/cfx_gemodule.h"
14 #include "core/fxge/include/cfx_pathdata.h" 14 #include "core/fxge/include/cfx_pathdata.h"
15 #include "core/fxge/include/cfx_substfont.h" 15 #include "core/fxge/include/cfx_substfont.h"
16 #include "core/fxge/include/fx_freetype.h" 16 #include "core/fxge/include/fx_freetype.h"
17 #include "third_party/base/numerics/safe_math.h"
17 18
18 #ifdef _SKIA_SUPPORT_ 19 #ifdef _SKIA_SUPPORT_
19 #include "third_party/skia/include/core/SkStream.h" 20 #include "third_party/skia/include/core/SkStream.h"
20 #include "third_party/skia/include/core/SkTypeface.h" 21 #include "third_party/skia/include/core/SkTypeface.h"
21 #endif 22 #endif
22 23
23 namespace { 24 namespace {
24 25
25 void GammaAdjust(uint8_t* pData, 26 void GammaAdjust(uint8_t* pData,
26 int nHeight, 27 int nHeight,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 int weight = 0; 148 int weight = 0;
148 if (bUseCJKSubFont) 149 if (bUseCJKSubFont)
149 weight = pSubstFont->m_WeightCJK; 150 weight = pSubstFont->m_WeightCJK;
150 else 151 else
151 weight = pSubstFont ? pSubstFont->m_Weight : 0; 152 weight = pSubstFont ? pSubstFont->m_Weight : 0;
152 if (pSubstFont && !(pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) && 153 if (pSubstFont && !(pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) &&
153 weight > 400) { 154 weight > 400) {
154 uint32_t index = (weight - 400) / 10; 155 uint32_t index = (weight - 400) / 10;
155 if (index >= CFX_Font::kWeightPowArraySize) 156 if (index >= CFX_Font::kWeightPowArraySize)
156 return nullptr; 157 return nullptr;
157 int level = 0; 158 pdfium::base::CheckedNumeric<signed long> level = 0;
158 if (pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET) { 159 if (pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET)
159 level = 160 level = CFX_Font::s_WeightPow_SHIFTJIS[index] * 2;
160 CFX_Font::s_WeightPow_SHIFTJIS[index] * 2 * 161 else
161 (FXSYS_abs((int)(ft_matrix.xx)) + FXSYS_abs((int)(ft_matrix.xy))) / 162 level = CFX_Font::s_WeightPow_11[index];
162 36655; 163
163 } else { 164 level = level * (FXSYS_abs(static_cast<int>(ft_matrix.xx)) +
164 level = 165 FXSYS_abs(static_cast<int>(ft_matrix.xy))) /
165 CFX_Font::s_WeightPow_11[index] * 166 36655;
166 (FXSYS_abs((int)(ft_matrix.xx)) + FXSYS_abs((int)(ft_matrix.xy))) / 167 FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face),
167 36655; 168 level.ValueOrDefault(0));
168 }
169 FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level);
170 } 169 }
171 FXFT_Library_SetLcdFilter(CFX_GEModule::Get()->GetFontMgr()->GetFTLibrary(), 170 FXFT_Library_SetLcdFilter(CFX_GEModule::Get()->GetFontMgr()->GetFTLibrary(),
172 FT_LCD_FILTER_DEFAULT); 171 FT_LCD_FILTER_DEFAULT);
173 error = FXFT_Render_Glyph(m_Face, anti_alias); 172 error = FXFT_Render_Glyph(m_Face, anti_alias);
174 if (error) 173 if (error)
175 return nullptr; 174 return nullptr;
176 int bmwidth = FXFT_Get_Bitmap_Width(FXFT_Get_Glyph_Bitmap(m_Face)); 175 int bmwidth = FXFT_Get_Bitmap_Width(FXFT_Get_Glyph_Bitmap(m_Face));
177 int bmheight = FXFT_Get_Bitmap_Rows(FXFT_Get_Glyph_Bitmap(m_Face)); 176 int bmheight = FXFT_Get_Bitmap_Rows(FXFT_Get_Glyph_Bitmap(m_Face));
178 if (bmwidth > 2048 || bmheight > 2048) 177 if (bmwidth > 2048 || bmheight > 2048)
179 return nullptr; 178 return nullptr;
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 return it2->second; 374 return it2->second;
376 375
377 CFX_GlyphBitmap* pGlyphBitmap = RenderGlyph(pFont, glyph_index, bFontStyle, 376 CFX_GlyphBitmap* pGlyphBitmap = RenderGlyph(pFont, glyph_index, bFontStyle,
378 pMatrix, dest_width, anti_alias); 377 pMatrix, dest_width, anti_alias);
379 if (!pGlyphBitmap) 378 if (!pGlyphBitmap)
380 return nullptr; 379 return nullptr;
381 380
382 pSizeCache->m_GlyphMap[glyph_index] = pGlyphBitmap; 381 pSizeCache->m_GlyphMap[glyph_index] = pGlyphBitmap;
383 return pGlyphBitmap; 382 return pGlyphBitmap;
384 } 383 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698